Skip to content

Commit d9a08f2

Browse files
author
Petr Gadorek
committed
TMA-690 && TMA-633 tests now verify that synchronize users action fails when supplied with unsupported sync_mode param
1 parent d712ec4 commit d9a08f2

7 files changed

Lines changed: 149 additions & 10 deletions

File tree

lib/gooddata/lcm/actions/synchronize_user_filters.rb

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class SynchronizeUserFilters < BaseAction
1919
param :input_source, instance_of(Type::HashType), required: true
2020

2121
description 'Synchronization Mode (e.g. sync_one_project_based_on_pid)'
22-
param :sync_mode, instance_of(Type::StringType), required: false
22+
param :sync_mode, instance_of(Type::StringType), required: false, default: 'sync_project'
2323

2424
description 'Column That Contains Target Project IDs'
2525
param :multiple_projects_column, instance_of(Type::StringType), required: false
@@ -47,6 +47,17 @@ class SynchronizeUserFilters < BaseAction
4747
end
4848

4949
class << self
50+
MODES = %w(
51+
add_to_organization
52+
sync_project
53+
sync_domain_and_project
54+
sync_multiple_projects_based_on_pid
55+
sync_one_project_based_on_pid
56+
sync_one_project_based_on_custom_id
57+
sync_multiple_projects_based_on_custom_id
58+
sync_domain_client_workspaces
59+
)
60+
5061
def call(params)
5162
client = params.gdc_gd_client
5263
domain_name = params.organization || params.domain
@@ -63,7 +74,10 @@ def call(params)
6374
symbolized_config[:labels] = symbolized_config[:labels].map { |l| GoodData::Helpers.symbolize_keys(l) }
6475
headers_in_options = params.csv_headers == 'false' || true
6576

66-
mode = params.sync_mode || 'sync_project'
77+
mode = params.sync_mode
78+
unless MODES.include?(mode)
79+
fail "The parameter \"sync_mode\" has to have one of the values #{MODES.map(&:to_s).join(', ')} or has to be empty."
80+
end
6781
filters = []
6882

6983
csv_with_headers = if GoodData::UserFilterBuilder.row_based?(symbolized_config)

lib/gooddata/lcm/actions/synchronize_users.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def call(params)
5252
data_source = GoodData::Helpers::DataSource.new(params.input_source)
5353
data_product = params.data_product
5454
mode = params.sync_mode
55-
unless mode.nil? || MODES.include?(mode)
55+
unless MODES.include?(mode)
5656
fail "The parameter \"sync_mode\" has to have one of the values #{MODES.map(&:to_s).join(', ')} or has to be empty."
5757
end
5858

lib/gooddata/lcm/helpers/check_helper.rb

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,10 @@ def check_params(specification, params)
1414
specification.keys.each do |param_name|
1515
value = params.send(param_name)
1616
type = specification[param_name][:type]
17-
18-
if value.nil?
19-
if specification[param_name][:opts][:required]
17+
if value.nil? || (value.is_a?(String) && value.empty?)
18+
if specification[param_name][:opts][:default]
19+
params[param_name] = specification[param_name][:opts][:default]
20+
elsif specification[param_name][:opts][:required]
2021
fail("Mandatory parameter '#{param_name}' of type '#{type}' is not specified")
2122
end
2223
else

spec/unit/actions/shared_examples_for_user_actions.rb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,20 @@
2424
subject.class.call(params)
2525
end
2626
end
27+
28+
shared_examples 'when using unsuported sync_mode' do
29+
before do
30+
allow(project).to receive(:metadata).and_return(
31+
'GOODOT_CUSTOM_PROJECT_ID' => 'project-123'
32+
)
33+
allow(project).to receive(:uri).and_return('project-uri')
34+
allow(data_source).to receive(:realize).and_return('filepath')
35+
allow(File).to receive(:open).and_return("client_id\n123456789")
36+
allow(project).to receive(:add_data_permissions)
37+
allow(domain).to receive(:clients).and_return([])
38+
end
39+
40+
it 'fails' do
41+
expect { subject.class.call(params) }.to raise_error(/sync_mode/)
42+
end
43+
end

spec/unit/actions/synchronize_user_filters_spec.rb

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,11 +162,26 @@
162162
}
163163
GoodData::LCM2.convert_to_smart_hash(params)
164164
end
165-
166165
it 'fails if the MUF set is empty' do
167166
expect(File).to receive(:open)
168167
expect(CSV).to receive(:foreach)
169168
expect { subject.class.call(params) }.to raise_error(/The filter set can not be empty/)
170169
end
171170
end
171+
context 'when using unsuported sync_mode' do
172+
let(:params) do
173+
params = {
174+
filters_config: { labels: [] },
175+
GDC_GD_CLIENT: client,
176+
input_source: 'foo',
177+
domain: 'bar',
178+
multiple_projects_column: 'id_column',
179+
sync_mode: 'unsuported_sync_mode', # sync_one_project_based_on_custom_id
180+
gdc_logger: logger
181+
}
182+
GoodData::LCM2.convert_to_smart_hash(params)
183+
end
184+
185+
it_should_behave_like 'when using unsuported sync_mode'
186+
end
172187
end

spec/unit/actions/synchronize_users_spec.rb

Lines changed: 49 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,11 @@
4646

4747
let(:params) do
4848
params = {
49+
sync_mode: 'sync_one_project_based_on_custom_id',
4950
GDC_GD_CLIENT: client,
5051
input_source: 'foo',
5152
domain: 'bar',
5253
gdc_logger: logger,
53-
sync_mode: 'sync_one_project_based_on_custom_id'
5454
}
5555
GoodData::LCM2.convert_to_smart_hash(params)
5656
end
@@ -75,11 +75,11 @@
7575
context 'when mode requires client_id' do
7676
let(:params) do
7777
params = {
78+
sync_mode: 'sync_one_project_based_on_pid',
7879
GDC_GD_CLIENT: client,
7980
input_source: 'foo',
8081
domain: 'bar',
81-
gdc_logger: logger,
82-
sync_mode: 'sync_one_project_based_on_pid'
82+
gdc_logger: logger
8383
}
8484
GoodData::LCM2.convert_to_smart_hash(params)
8585
end
@@ -130,5 +130,51 @@
130130
let(:message_for_project) { :import_users }
131131
end
132132
end
133+
context 'when using mistyped mode' do
134+
let(:params) do
135+
params = {
136+
GDC_GD_CLIENT: client,
137+
input_source: 'foo',
138+
domain: 'bar',
139+
gdc_logger: logger,
140+
sync_mode: 'unsuported_sync_mode'
141+
}
142+
GoodData::LCM2.convert_to_smart_hash(params)
143+
end
144+
145+
before do
146+
allow(domain).to receive(:clients).and_return(organization)
147+
end
148+
it_should_behave_like 'when using unsuported sync_mode'
149+
end
150+
context 'when using no mode' do
151+
let(:params) do
152+
params = {
153+
GDC_GD_CLIENT: client,
154+
input_source: 'foo',
155+
domain: 'bar',
156+
gdc_logger: logger
157+
}
158+
GoodData::LCM2.convert_to_smart_hash(params)
159+
end
160+
161+
before do
162+
allow(domain).to receive(:clients).and_return(organization)
163+
end
164+
before do
165+
allow(data_source).to receive(:realize).and_return('filepath')
166+
allow(File).to receive(:open).and_return("client_id\n123456789")
167+
allow(project).to receive(:metadata).and_return(
168+
'GOODOT_CUSTOM_PROJECT_ID' => 'project-123'
169+
)
170+
allow(project).to receive(:uri).and_return('project-uri')
171+
allow(project).to receive(:add_data_permissions)
172+
allow(domain).to receive(:clients).and_return([])
173+
end
174+
175+
it 'fails' do
176+
expect { subject.class.call(params) }.to raise_error(/sync_mode/)
177+
end
178+
end
133179
end
134180
end
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
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

Comments
 (0)