|
| 1 | +# encoding: UTF-8 |
| 2 | +# |
| 3 | +# Copyright (c) 2010-2017 GoodData Corporation. All rights reserved. |
| 4 | +# This source code is licensed under the BSD-style license found in the |
| 5 | +# LICENSE file in the root directory of this source tree. |
| 6 | +require 'gooddata/lcm/actions/base_action' |
| 7 | +require 'gooddata/lcm/helpers/check_helper' |
| 8 | +require 'gooddata/lcm/types/types' |
| 9 | + |
| 10 | +describe 'GoodData::LCM2::Helpers::Checkout' do |
| 11 | + let(:params) do |
| 12 | + params = { |
| 13 | + test_param_two: 'Testing param two', |
| 14 | + test_param_three: 'Testing param three', |
| 15 | + test_param_four: 4 |
| 16 | + } |
| 17 | + GoodData::LCM2.convert_to_smart_hash(params) |
| 18 | + end |
| 19 | + it 'verifies required' do |
| 20 | + PARAMS = GoodData::LCM2::BaseAction.define_params(self) do |
| 21 | + description 'Testing param one' |
| 22 | + param :test_param_one, instance_of(GoodData::LCM2::Type::StringType), required: true |
| 23 | + end |
| 24 | + expect { GoodData::LCM2::Helpers.check_params(PARAMS, params) }.to raise_error(/Mandatory/) |
| 25 | + end |
| 26 | + |
| 27 | + it 'fills default' do |
| 28 | + PARAMS_2 = GoodData::LCM2::BaseAction.define_params(self) do |
| 29 | + description 'Testing param one' |
| 30 | + param :test_param_one, instance_of(GoodData::LCM2::Type::StringType), required: true, default: 'filled_default_value' |
| 31 | + |
| 32 | + description 'Testing param two' |
| 33 | + param :test_param_two, instance_of(GoodData::LCM2::Type::StringType), required: false |
| 34 | + end |
| 35 | + GoodData::LCM2::Helpers.check_params(PARAMS_2, params) |
| 36 | + expect(params[:test_param_one]).to match(/filled_default_value/) |
| 37 | + end |
| 38 | + |
| 39 | + it 'checks types' do |
| 40 | + PARAMS_3 = GoodData::LCM2::BaseAction.define_params(self) do |
| 41 | + description 'Testing param four' |
| 42 | + param :test_param_four, instance_of(GoodData::LCM2::Type::StringType), required: false |
| 43 | + end |
| 44 | + expect { GoodData::LCM2::Helpers.check_params(PARAMS_3, params) }.to raise_error(/has invalid type/) |
| 45 | + end |
| 46 | +end |
0 commit comments