Skip to content

Commit

Permalink
Test if marital status can be changed in specs
Browse files Browse the repository at this point in the history
  • Loading branch information
RandomTannenbaum committed Jun 28, 2024
1 parent 5ac5585 commit 8c8e0e4
Showing 1 changed file with 81 additions and 62 deletions.
143 changes: 81 additions & 62 deletions spec/domain/ptime/update_people_data_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,91 +7,110 @@
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': '[email protected]',
'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': '[email protected]',
'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': '[email protected]',
'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': '[email protected]',
'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': '[email protected]',
'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': '[email protected]',
'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': '[email protected]',
'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"] = "[email protected]"
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] = "[email protected]"
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

expect(person_longmax.reload.email).to eq("[email protected]")
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
Expand Down

0 comments on commit 8c8e0e4

Please sign in to comment.