diff --git a/spec/domain/ptime/update_people_data_spec.rb b/spec/domain/ptime/update_people_data_spec.rb index 7ddb8904f..45d6fd365 100644 --- a/spec/domain/ptime/update_people_data_spec.rb +++ b/spec/domain/ptime/update_people_data_spec.rb @@ -7,84 +7,102 @@ ENV["PTIME_API_PASSWORD"] = ptime_api_test_password describe Ptime::UpdatePeopleData do - employees_json = { - 'data': [ - { - 'id': 33, - 'type': 'employee', - 'attributes': { - 'shortname': 'LSM', - 'firstname': 'Longmax', - 'lastname': 'Smith', - 'email': 'longmax@example.com', - 'marital_status': 'single', - 'nationalities': [ - 'ZW' - ], - 'graduation': 'BSc in Architecture', - 'department_shortname': 'SYS', - 'employment_roles': [] - } - }, - { - 'id': 21, - 'type': 'employee', - 'attributes': { - 'shortname': 'AMA', - 'firstname': 'Alice', - 'lastname': 'Mante', - 'email': 'alice@example.com', - 'marital_status': 'single', - 'nationalities': [ - 'AU' - ], - 'graduation': 'MSc in writing', - 'department_shortname': 'SYS', - 'employment_roles': [] - } - }, - { - 'id': 45, - 'type': 'employee', - 'attributes': { - 'shortname': 'CFO', - 'firstname': 'Charlie', - 'lastname': 'Ford', - 'email': 'charlie@example.com', - 'marital_status': 'married', - 'nationalities': [ - 'GB' - ], - 'graduation': 'MSc in networking', - 'department_shortname': 'SYS', - 'employment_roles': [] - } - }, - ] - }.to_json - before(:each) do ENV["PTIME_BASE_URL"] = ptime_base_test_url end it 'should update the data of existing people after mapping' do + employees = { + 'data': [ + { + 'id': 33, + 'type': 'employee', + 'attributes': { + 'shortname': 'LSM', + 'firstname': 'Longmax', + 'lastname': 'Smith', + 'email': 'longmax@example.com', + 'marital_status': 'single', + 'nationalities': [ + 'ZW' + ], + 'graduation': 'BSc in Architecture', + 'department_shortname': 'SYS', + 'employment_roles': [] + } + }, + { + 'id': 21, + 'type': 'employee', + 'attributes': { + 'shortname': 'AMA', + 'firstname': 'Alice', + 'lastname': 'Mante', + 'email': 'alice@example.com', + 'marital_status': 'single', + 'nationalities': [ + 'AU' + ], + 'graduation': 'MSc in writing', + 'department_shortname': 'SYS', + 'employment_roles': [] + } + }, + { + 'id': 45, + 'type': 'employee', + 'attributes': { + 'shortname': 'CFO', + 'firstname': 'Charlie', + 'lastname': 'Ford', + 'email': 'charlie@example.com', + 'marital_status': 'married', + 'nationalities': [ + 'GB' + ], + 'graduation': 'MSc in networking', + 'department_shortname': 'SYS', + 'employment_roles': [] + } + }, + { + 'id': 50, + 'type': 'employee', + 'attributes': { + 'shortname': 'WAL', + 'firstname': 'Wally', + 'lastname': 'Allround', + 'email': 'wally@example.com', + 'marital_status': 'married', + 'nationalities': [ + 'US' + ], + 'graduation': 'Full-Stack Developer', + 'department_shortname': 'SYS', + 'employment_roles': [] + } + }, + ] + } + stub_request(:get, "#{ptime_base_test_url}/api/v1/employees?per_page=1000"). - to_return(body: employees_json, headers: { 'content-type': "application/vnd.api+json; charset=utf-8" }, status: 200) + to_return(body: employees.to_json, headers: { 'content-type': "application/vnd.api+json; charset=utf-8" }, status: 200) .with(basic_auth: [ptime_api_test_username, ptime_api_test_password]) person_longmax = people(:longmax) person_alice = people(:alice) person_charlie = people(:charlie) + person_wally = people(:wally) Ptime::AssignEmployeeIds.new.run(should_map: true) - parsed_employees_json = JSON.parse(employees_json) - parsed_employees_json['data'].first["attributes"]["email"] = "changedmax@example.com" - parsed_employees_json['data'].second["attributes"]["graduation"] = "MSc in some other field" - parsed_employees_json['data'].last["attributes"]["firstname"] = "Claudius" + employees[:data].first[:attributes][:email] = "changedmax@example.com" + employees[:data].second[:attributes][:graduation] = "MSc in some other field" + employees[:data].third[:attributes][:firstname] = "Claudius" + employees[:data].fourth[:attributes][:marital_status] = "single" stub_request(:get, "#{ptime_base_test_url}/api/v1/employees?per_page=1000"). - to_return(body: parsed_employees_json.to_json, headers: { 'content-type': "application/vnd.api+json; charset=utf-8" }, status: 200) + to_return(body: employees.to_json, headers: { 'content-type': "application/vnd.api+json; charset=utf-8" }, status: 200) .with(basic_auth: [ptime_api_test_username, ptime_api_test_password]) Ptime::UpdatePeopleData.new.run @@ -92,6 +110,7 @@ expect(person_longmax.reload.email).to eq("changedmax@example.com") expect(person_alice.reload.title).to eq("MSc in some other field") expect(person_charlie.reload.name).to eq("Claudius Ford") + expect(person_wally.reload.marital_status).to eq("single") end it 'should create new person when person does not exist' do