stackone_migration 1.2.1 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 764e6b26eb6bf1d91be9ef1c94bc5c86eec039f268bccc2a06bad4096e7211c9
4
- data.tar.gz: 863ff416beda7f5984cd037648a88be4fede27e9ecef4871dad7af27447e1aaa
3
+ metadata.gz: daa32597a9e8c833693f8b94f572af6fee65310b673ede6e67a99f6772ee0d87
4
+ data.tar.gz: fc23f733389cce570bb07754170e84f59d7f065f6b69931e8ddb941b25002fad
5
5
  SHA512:
6
- metadata.gz: 3b74cf2823822fa167ec101c7198ecabd34d931a06af69919d62915c7ed76c144f9b3a09cc811b6d104f52e86a4f54b92461b3b0523998793090f1c982a617e8
7
- data.tar.gz: d5144d115eef1dd54f0dd098fa43eaa6e34ef5c0bb796270aa363df9757de0456989a42dcc9926006c311f4c8d948e6e88b114b46003b744711c5750a9645995
6
+ metadata.gz: 149a32da85baab2c457cda99adb372a5bdb520927f8f28768f1c9a365a9cd878d9817029313f710f4e908ad49860db43ec9ec17f981ecf0d259664a52ea40124
7
+ data.tar.gz: 1598674e96bb4bd3724e087382cc5ad53c183c83ad3826d7d224ca56c0764d0da49b3f1f13bb46ff3d96112acdf108a8f10960ba434deb0d4ca958d19ce44421
data/Gemfile CHANGED
@@ -11,4 +11,4 @@ group :development, :test do
11
11
  end
12
12
 
13
13
  gem 'merge_hris_client', '~> 3.0'
14
- gem 'stackone_hris_client', '~> 1.3.1'
14
+ gem 'stackone_hris_client', '~> 1.4.0'
data/Gemfile.lock CHANGED
@@ -1,9 +1,9 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- stackone_migration (1.2.1)
4
+ stackone_migration (1.3.0)
5
5
  merge_hris_client (~> 3.0)
6
- stackone_hris_client (~> 1.3.1)
6
+ stackone_hris_client (~> 1.4.0)
7
7
 
8
8
  GEM
9
9
  remote: https://rubygems.org/
@@ -58,7 +58,7 @@ GEM
58
58
  rubocop-ast (1.27.0)
59
59
  parser (>= 3.2.1.0)
60
60
  ruby-progressbar (1.13.0)
61
- stackone_hris_client (1.3.1)
61
+ stackone_hris_client (1.4.0)
62
62
  typhoeus (~> 1.0, >= 1.0.1)
63
63
  typhoeus (1.4.0)
64
64
  ethon (>= 0.9.0)
@@ -73,7 +73,7 @@ DEPENDENCIES
73
73
  rake (~> 13.0.1)
74
74
  rspec (~> 3.6, >= 3.6.0)
75
75
  rubocop (~> 1.48.0)
76
- stackone_hris_client (~> 1.3.1)
76
+ stackone_hris_client (~> 1.4.0)
77
77
  stackone_migration!
78
78
 
79
79
  BUNDLED WITH
@@ -101,52 +101,50 @@ module StackOneMigration
101
101
  :personal_email => employee.personal_email,
102
102
  :work_email => employee.work_email,
103
103
  :mobile_phone_number => employee.personal_phone_number,
104
- :gender => MergeHRISClient::GenderEnum.build_from_hash(gender_enum_hash[employee.gender&.to_sym]),
104
+ :gender => MergeHRISClient::GenderEnum.build_from_hash(map_enum(gender_enum_hash,employee.gender)),
105
105
  :date_of_birth => employee.date_of_birth,
106
106
  :start_date => employee.start_date,
107
107
  :manager => employee.manager_id,
108
- :ethnicity => MergeHRISClient::EthnicityEnum.build_from_hash(ethnicity_enum_hash[employee.ethnicity&.to_sym]),
109
- :marital_status => MergeHRISClient::MaritalStatusEnum.build_from_hash(marital_status_enum_hash[employee.marital_status&.to_sym]),
108
+ :ethnicity => MergeHRISClient::EthnicityEnum.build_from_hash(map_enum(ethnicity_enum_hash, employee.ethnicity)),
109
+ :marital_status => MergeHRISClient::MaritalStatusEnum.build_from_hash(map_enum(marital_status_enum_hash, employee.marital_status)),
110
110
  :hire_date => employee.hire_date,
111
- :employment_status => MergeHRISClient::EmploymentStatusEnum.build_from_hash(employment_status_enum_hash[employee.employment_status&.to_sym]),
111
+ :employment_status => MergeHRISClient::EmploymentStatusEnum.build_from_hash(map_enum(employment_status_enum_hash, employee.employment_status)),
112
112
  :termination_date => employee.termination_date,
113
- :company => json_str_to_hash(employee.company),
114
- :home_location => json_str_to_hash(employee.home_location),
115
- :work_location => json_str_to_hash(employee.work_location),
113
+ :home_location => map_to_location_model(employee.home_location),
114
+ :work_location => map_to_location_model(employee.work_location),
116
115
  :employments => map_employments(employee.employments),
117
116
  )
118
117
  end
119
118
 
120
- def self.json_str_to_hash(hash_string)
121
- begin
122
- return nil if hash_string.nil?
123
-
124
- new_str = hash_string
125
- .gsub(/:(\w+)/, '"\1"')
126
- .gsub('=>', ':')
127
- .gsub('nil', 'null')
128
-
129
- hash = JSON.parse(new_str)
130
-
131
- hash.transform_keys(&:to_sym)
132
- rescue JSON::ParserError => e
133
- puts "Error parsing JSON string: #{e.message}"
134
-
135
- hash_string
136
- end
119
+ def self.map_to_location_model(location)
120
+ return nil if location.nil?
121
+
122
+ MergeHRISClient::Location.new(
123
+ :id => location.id,
124
+ :remote_id => location.id,
125
+ :name => location.name,
126
+ :phone_number => location.phone_number,
127
+ :street_1 => location.street_1,
128
+ :street_2 => location.street_2,
129
+ :city => location.city,
130
+ :state => location.state,
131
+ :zip_code => location.zip_code,
132
+ :country => MergeHRISClient::CountryEnum.build_from_hash(location.country),
133
+ :location_type => MergeHRISClient::LocationTypeEnum.build_from_hash(map_enum(location_type_enum_hash, location.location_type)),
134
+ )
137
135
  end
138
136
 
139
137
  def self.map_to_employment_model(employment)
140
138
  return nil if employment.nil?
141
139
 
142
140
  MergeHRISClient::Employment.new(
143
- :job_title => employment[:job_title],
144
- :pay_rate => employment[:pay_rate],
145
- :pay_period => MergeHRISClient::PayPeriodEnum.build_from_hash(pay_period_enum_hash[employment[:pay_period]&.to_sym]),
146
- :pay_frequency => MergeHRISClient::PayFrequencyEnum.build_from_hash(pay_frequency_enum_hash[employment[:pay_frequency]&.to_sym]),
147
- :pay_currency => MergeHRISClient::PayCurrencyEnum.build_from_hash(employment[:pay_currency]&.to_s.upcase),
148
- :effective_date => employment[:effective_date],
149
- :employment_type => MergeHRISClient::EmploymentTypeEnum.build_from_hash(employment_type_enum_hash[employment[:employment_type]&.to_sym]),
141
+ :job_title => employment.job_title,
142
+ :pay_rate => employment.pay_rate,
143
+ :pay_period => MergeHRISClient::PayPeriodEnum.build_from_hash(map_enum(pay_period_enum_hash, employment.pay_period)),
144
+ :pay_frequency => MergeHRISClient::PayFrequencyEnum.build_from_hash(map_enum(pay_frequency_enum_hash, employment.pay_frequency)),
145
+ :pay_currency => MergeHRISClient::PayCurrencyEnum.build_from_hash(employment.pay_currency&.to_s&.upcase),
146
+ :effective_date => employment.effective_date,
147
+ :employment_type => MergeHRISClient::EmploymentTypeEnum.build_from_hash(map_enum(employment_type_enum_hash, employment.employment_type)),
150
148
  )
151
149
  end
152
150
 
@@ -189,5 +187,14 @@ module StackOneMigration
189
187
  :previous => nil
190
188
  )
191
189
  end
190
+
191
+ def self.map_enum(enum_hash, enum)
192
+ return nil if enum.nil? || enum.value.nil?
193
+
194
+ mapped_enum = enum_hash[enum&.value&.to_sym]
195
+ return mapped_enum unless mapped_enum.nil? || mapped_enum == 'MERGE_NONSTANDARD_VALUE'
196
+
197
+ enum.source_value
198
+ end
192
199
  end
193
200
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module StackOneMigration
4
- VERSION = '1.2.1'
4
+ VERSION = '1.3.0'
5
5
  end
@@ -14,39 +14,38 @@ describe StackOneMigration::EmployeesMapper do
14
14
  :personal_email => 'ija@egje.wf',
15
15
  :work_email => 'kota@efpiphi.kw',
16
16
  :personal_phone_number => '(715) 658-9486',
17
- :gender => 'female',
17
+ :gender => StackOneHRIS::GenderEnum.new(value: 'female', source_value: 'female'),
18
18
  :date_of_birth => '1990-01-01',
19
19
  :start_date => '2018-01-01',
20
20
  :manager_id => '417b5e62-e011-5e69-a906-0aefade9ded1',
21
- :ethnicity => 'white',
22
- :marital_status => 'married',
23
- :employment_status => 'terminated',
21
+ :ethnicity => StackOneHRIS::EthnicityEnum.new(value: 'white', source_value: 'white'),
22
+ :marital_status => StackOneHRIS::MaritalStatusEnum.new(value: 'married', source_value: 'married'),
23
+ :employment_status => StackOneHRIS::EmploymentStatusEnum.new(value: 'terminated', source_value: 'terminated'),
24
24
  :work_phone_number => '(456) 787-3508',
25
25
  :job_title => 'Manager',
26
26
  :department => 'Human Resources',
27
- :home_location => "{
28
- :phone_number => \"(456) 787-3508\",
29
- :street_1 => \"123 Main' St\",
30
- :street_2 => \"Apt 1\",
31
- :city => \"San Francisco\",
32
- :state => \"CA\",
33
- :zip_code => \"94105\",
34
- :country => \"US\"
35
- }",
27
+ :home_location =>
28
+ StackOneHRIS::Location.new(
29
+ :phone_number => "(456) 787-3508",
30
+ :street_1 => "123 Main' St",
31
+ :street_2 => "Apt 1",
32
+ :city => "San Francisco",
33
+ :state => "CA",
34
+ :zip_code => "94105",
35
+ :country => "US",
36
+ :location_type => StackOneHRIS::LocationTypeEnum.new(value: 'home', source_value: 'home'),
37
+ ),
36
38
  :work_location => nil,
37
- :company => "{
38
- \"display_name\": \"StackOne\"
39
- }",
40
39
  :employments => [
41
- {
42
- job_title: 'Manager',
43
- pay_rate: 100000,
44
- pay_period: 'yearly',
45
- pay_frequency: 'weekly',
46
- pay_currency: 'USD',
47
- effective_date: '2018-01-01',
48
- employee_type: 'full_time',
49
- }
40
+ StackOneHRIS::Employment.new(
41
+ :job_title => 'Manager',
42
+ :pay_rate => 100000,
43
+ :pay_period => StackOneHRIS::PayPeriodEnum.new(value: 'year', source_value: 'year'),
44
+ :pay_frequency => StackOneHRIS::PayFrequencyEnum.new(value: 'weekly', source_value: 'weekly'),
45
+ :pay_currency => 'USD',
46
+ :effective_date => '2018-01-01',
47
+ :employment_type => StackOneHRIS::EmploymentTypeEnum.new(value: 'full_time', source_value: 'full_time'),
48
+ )
50
49
  ]
51
50
  )
52
51
  }
@@ -61,7 +60,7 @@ describe StackOneMigration::EmployeesMapper do
61
60
  :personal_email => 'ija@egje.wf',
62
61
  :work_email => 'kota@efpiphi.kw',
63
62
  :personal_phone_number => '(715) 658-9486',
64
- :gender => 'female',
63
+ :gender => StackOneHRIS::GenderEnum.new(value: 'female', source_value: 'female'),
65
64
  :date_of_birth => '1990-01-01',
66
65
  :start_date => '2018-01-01',
67
66
  :manager_id => '417b5e62-e011-5e69-a906-0aefade9ded1',
@@ -94,19 +93,8 @@ describe StackOneMigration::EmployeesMapper do
94
93
  :date_of_birth => '1990-01-01',
95
94
  :start_date => '2018-01-01',
96
95
  :manager => '417b5e62-e011-5e69-a906-0aefade9ded1',
97
- :home_location => {
98
- phone_number: '(456) 787-3508',
99
- street_1: '123 Main\' St',
100
- street_2: 'Apt 1',
101
- city: 'San Francisco',
102
- state: 'CA',
103
- zip_code: '94105',
104
- country: 'US',
105
- },
106
96
  :work_location => nil,
107
- :company => {
108
- display_name: 'StackOne',
109
- },
97
+ :company => nil,
110
98
  )
111
99
  expect(target_model.gender).to have_attributes(:value => 'FEMALE')
112
100
  expect(target_model.ethnicity).to have_attributes(:value => 'WHITE')
@@ -123,33 +111,80 @@ describe StackOneMigration::EmployeesMapper do
123
111
  end
124
112
  end
125
113
 
114
+ context '.map_to_location_model' do
115
+ it 'maps a location to correct class' do
116
+ sample_location = StackOneHRIS::Location.new(
117
+ :phone_number => "(456) 787-3508",
118
+ :street_1 => "123 Main' St",
119
+ :street_2 => "Apt 1",
120
+ :city => "San Francisco",
121
+ :state => "CA",
122
+ :zip_code => "94105",
123
+ :country => "US"
124
+ )
125
+
126
+ target_model = described_class.map_to_location_model(sample_location)
127
+
128
+ expect(target_model).to be_a(MergeHRISClient::Location)
129
+ end
130
+
131
+ it 'maps a location with the right attributes' do
132
+ sample_location = StackOneHRIS::Location.new(
133
+ :id => '123',
134
+ :name => 'David Leonard',
135
+ :phone_number => "(456) 787-3508",
136
+ :street_1 => "123 Main' St",
137
+ :street_2 => "Apt 1",
138
+ :city => "San Francisco",
139
+ :state => "CA",
140
+ :zip_code => "94105",
141
+ :country => "US",
142
+ :location_type => StackOneHRIS::LocationTypeEnum.new(value: 'home', source_value: 'home'),
143
+ )
144
+
145
+ target_model = described_class.map_to_location_model(sample_location)
146
+
147
+ expect(target_model.id).to eq('123')
148
+ expect(target_model.remote_id).to eq('123')
149
+ expect(target_model.name).to eq('David Leonard')
150
+ expect(target_model.phone_number).to eq('(456) 787-3508')
151
+ expect(target_model.street_1).to eq("123 Main' St")
152
+ expect(target_model.street_2).to eq("Apt 1")
153
+ expect(target_model.city).to eq("San Francisco")
154
+ expect(target_model.state).to eq("CA")
155
+ expect(target_model.zip_code).to eq("94105")
156
+ expect(target_model.country).to have_attributes(:raw_value => 'US')
157
+ expect(target_model.location_type).to have_attributes(:value => 'HOME')
158
+ end
159
+ end
160
+
126
161
  context '.map_to_employment_model' do
127
- it 'maps a employeement hash to correct class' do
128
- sample_employment = {
129
- job_title: 'Manager',
130
- pay_rate: 100000,
131
- pay_period: 'yearly',
132
- pay_frequency: 'weekly',
133
- pay_currency: 'USD',
134
- effective_date: '2018-01-01',
135
- employment_type: 'full_time',
136
- }
162
+ it 'maps a employeement to correct class' do
163
+ sample_employment = StackOneHRIS::Employment.new(
164
+ :job_title => 'Manager',
165
+ :pay_rate => 100000,
166
+ :pay_period => StackOneHRIS::PayPeriodEnum.new(value: 'year', source_value: 'year'),
167
+ :pay_frequency => StackOneHRIS::PayFrequencyEnum.new(value: 'weekly', source_value: 'weekly'),
168
+ :pay_currency => 'USD',
169
+ :effective_date => '2018-01-01',
170
+ :employment_type => StackOneHRIS::EmploymentTypeEnum.new(value: 'full_time', source_value: 'full_time'),
171
+ )
137
172
 
138
173
  target_model = described_class.map_to_employment_model(sample_employment)
139
174
 
140
175
  expect(target_model).to be_a(MergeHRISClient::Employment)
141
176
  end
142
177
 
143
- it 'maps a employeement hash with the right attributes' do
144
- sample_employment = {
145
- job_title: 'Manager',
146
- pay_rate: 100000,
147
- pay_period: 'year',
148
- pay_frequency: 'weekly',
149
- pay_currency: 'usd',
150
- effective_date: '2018-01-01',
151
- employment_type: 'full_time',
152
- }
178
+ it 'maps a employeement with the right attributes' do
179
+ sample_employment = StackOneHRIS::Employment.new(
180
+ :job_title => 'Manager',
181
+ :pay_rate => 100000,
182
+ :pay_period => StackOneHRIS::PayPeriodEnum.new(value: 'year', source_value: 'year'),
183
+ :pay_frequency => StackOneHRIS::PayFrequencyEnum.new(value: 'weekly', source_value: 'weekly'),
184
+ :pay_currency => 'USD',
185
+ :effective_date => '2018-01-01',
186
+ :employment_type => StackOneHRIS::EmploymentTypeEnum.new(value: 'full_time', source_value: 'full_time'),
187
+ )
153
188
 
154
189
  target_model = described_class.map_to_employment_model(sample_employment)
155
190
 
@@ -232,4 +267,59 @@ describe StackOneMigration::EmployeesMapper do
232
267
  end
233
268
  end
234
269
  end
270
+
271
+ context '.map_enum' do
272
+ it 'returns the mapped enum' do
273
+ target_value = described_class.map_enum(
274
+ described_class.pay_period_enum_hash,
275
+ StackOneHRIS::PayPeriodEnum.new(value: 'year', source_value: 'year')
276
+ )
277
+
278
+ expect(target_value).to eq('YEAR')
279
+ end
280
+
281
+ context 'when the enum is nil' do
282
+ it 'returns nil' do
283
+ target_value = described_class.map_enum(
284
+ described_class.pay_period_enum_hash,
285
+ nil
286
+ )
287
+
288
+ expect(target_value).to be_nil
289
+ end
290
+ end
291
+
292
+ context 'when the enum value is nil' do
293
+ it 'returns nil' do
294
+ target_value = described_class.map_enum(
295
+ described_class.pay_period_enum_hash,
296
+ StackOneHRIS::PayPeriodEnum.new(value: nil, source_value: 'year')
297
+ )
298
+
299
+ expect(target_value).to be_nil
300
+ end
301
+ end
302
+
303
+ context 'when the enum value is an unmapped value' do
304
+ it 'returns the source value' do
305
+ target_value = described_class.map_enum(
306
+ described_class.pay_period_enum_hash,
307
+ StackOneHRIS::PayPeriodEnum.new(value: 'unmapped_value', source_value: 'year_custom_value')
308
+ )
309
+
310
+ expect(target_value).to eq('year_custom_value')
311
+ end
312
+ end
313
+
314
+ context 'when the enum value maps to a MERGE_NONSTANDARD_VALUE' do
315
+ it 'returns the mapped enum' do
316
+ target_value = described_class.map_enum(
317
+ described_class.marital_status_enum_hash,
318
+ StackOneHRIS::MaritalStatusEnum.new(value: 'other', source_value: 'other_status')
319
+ )
320
+
321
+ expect(target_value).to eq('other_status')
322
+ end
323
+ end
324
+ end
235
325
  end
@@ -16,7 +16,7 @@ Gem::Specification.new do |s|
16
16
  s.required_ruby_version = '>= 2.7'
17
17
 
18
18
  s.add_runtime_dependency 'merge_hris_client', '~> 3.0'
19
- s.add_runtime_dependency 'stackone_hris_client', '~> 1.3.1'
19
+ s.add_runtime_dependency 'stackone_hris_client', '~> 1.4.0'
20
20
 
21
21
  s.add_development_dependency 'rspec', '~> 3.6', '>= 3.6.0'
22
22
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stackone_migration
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.1
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - StackOne
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-04-21 00:00:00.000000000 Z
11
+ date: 2023-05-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: merge_hris_client
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: 1.3.1
33
+ version: 1.4.0
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: 1.3.1
40
+ version: 1.4.0
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rspec
43
43
  requirement: !ruby/object:Gem::Requirement