Skip to content

Commit

Permalink
Clean up and fix specs, fix create_person method in update_person_dat…
Browse files Browse the repository at this point in the history
…a class
  • Loading branch information
RandomTannenbaum committed Jul 30, 2024
1 parent 193f80a commit 61541a7
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 99 deletions.
2 changes: 1 addition & 1 deletion app/domain/ptime/update_person_data.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ def create_person(ptime_employee_id)
person = Person.find_by(ptime_employee_id: ptime_employee_id)
return person unless person.nil?

update_person_data(person)
update_person_data(Person.new(ptime_employee_id: ptime_employee_id))
end

# rubocop:disable Metrics
Expand Down
28 changes: 10 additions & 18 deletions spec/domain/ptime/update_person_data_spec.rb
Original file line number Diff line number Diff line change
@@ -1,24 +1,17 @@
require 'rails_helper'

ptime_base_test_url = "www.ptime.example.com"
ptime_api_test_username = "test username"
ptime_api_test_password = "test password"
ENV["PTIME_BASE_URL"] = ptime_base_test_url
ENV["PTIME_API_USERNAME"] = ptime_api_test_username
ENV["PTIME_API_PASSWORD"] = ptime_api_test_password

describe Ptime::UpdatePersonData do
it 'should raise error when no ptime_employee_id is passed to new action' do
expect{ Ptime::UpdatePersonData.new.create_person(nil) }.to raise_error(RuntimeError, 'No ptime_employee_id provided')
ptime_base_test_url = "www.ptime.example.com"
ptime_api_test_username = "test username"
ptime_api_test_password = "test password"
before(:each) do
ENV["PTIME_BASE_URL"] = ptime_base_test_url
ENV["PTIME_API_USERNAME"] = ptime_api_test_username
ENV["PTIME_API_PASSWORD"] = ptime_api_test_password
end

it 'should create default person if ptime_employee_id doesnt already exist' do
default_person = Person.create(name: 'Default name', company: Company.first, birthdate: '1.1.1970',
nationality: 'CH', location: 'Bern', title: 'Default title',
email: 'default@example.com', ptime_employee_id: 123)

new_person = Ptime::UpdatePersonData.new.create_person(123)
expect(default_person.attributes.except(*%w[created_at updated_at])).to eql(new_person.attributes.except(*%w[created_at updated_at]))
it 'should raise error when no ptime_employee_id is passed to new action' do
expect{ Ptime::UpdatePersonData.new.create_person(nil) }.to raise_error(RuntimeError, 'No ptime_employee_id provided')
end

it 'should return person if it has the given ptime_employee_id' do
Expand All @@ -38,7 +31,6 @@
person_wally = people(:wally)
person_wally.ptime_employee_id = 50
person_wally.save!

expect{ Ptime::UpdatePersonData.new.update_person_data(person_wally) }.to raise_error(RuntimeError, 'Ptime_employee with id 50 not found')
expect{ Ptime::UpdatePersonData.new.update_person_data(person_wally) }.to raise_error(RuntimeError, 'Ptime_employee with ptime_employee_id 50 not found')
end
end
89 changes: 9 additions & 80 deletions spec/features/update_person_data_spec.rb
Original file line number Diff line number Diff line change
@@ -1,86 +1,15 @@
require 'rails_helper'

ptime_base_test_url = "www.ptime.example.com"
ptime_api_test_username = "test username"
ptime_api_test_password = "test password"
ENV["PTIME_BASE_URL"] = ptime_base_test_url
ENV["PTIME_API_USERNAME"] = ptime_api_test_username
ENV["PTIME_API_PASSWORD"] = ptime_api_test_password

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': []
}
},
]
}

describe Ptime::UpdatePersonData do
ptime_base_test_url = "www.ptime.example.com"
ptime_api_test_username = "test username"
ptime_api_test_password = "test password"
before(:each) do
ENV["PTIME_BASE_URL"] = ptime_base_test_url
ENV["PTIME_API_USERNAME"] = ptime_api_test_username
ENV["PTIME_API_PASSWORD"] = ptime_api_test_password
end

describe 'Update or create person', type: :feature, js: true do
before(:each) do
sign_in auth_users(:user), scope: :auth_user
Expand Down

0 comments on commit 61541a7

Please sign in to comment.