diff --git a/spec/domain/ptime/client_spec.rb b/spec/domain/ptime/client_spec.rb index 166499d4f..42d727b07 100644 --- a/spec/domain/ptime/client_spec.rb +++ b/spec/domain/ptime/client_spec.rb @@ -6,12 +6,20 @@ expect(fetched_employees).to eq(ptime_employees_data) end - it 'should not raise PTimeClientError if LAST_PTIME_ERROR is less than 5 minutes ago' do + it 'should not raise PTimeClientError if LAST_PTIME_ERROR is more than 5 minutes ago' do stub_env_var("LAST_PTIME_ERROR", 6.minutes.ago.to_s) fetched_employees = Ptime::Client.new.request(:get, "employees", { per_page: 1000 }) expect(fetched_employees).to eq(ptime_employees_data) end + it 'should raise PTimeClientError page is unreachable' do + stub_env_var("PTIME_BASE_URL", "irgend.oepp.is") + stub_ptime_request(ptime_employees.to_json, "employees?per_page=1000", 404) + expect { + Ptime::Client.new.request(:get, "employees", { per_page: 1000 }) + }.to raise_error(CustomExceptions::PTimeClientError) + end + it 'should raise PTimeClientError if LAST_PTIME_ERROR is less than 5 minutes ago' do stub_env_var("LAST_PTIME_ERROR", 4.minutes.ago.to_s) expect { diff --git a/spec/support/ptime_helpers.rb b/spec/support/ptime_helpers.rb index cc339ee3c..72da9c69b 100644 --- a/spec/support/ptime_helpers.rb +++ b/spec/support/ptime_helpers.rb @@ -14,13 +14,13 @@ def ptime_employees_data fixture_data("all_ptime_employees")[:data] end - def stub_ptime_request(return_body, path =nil) + def stub_ptime_request(return_body, path =nil, status = 200) path ||= "employees?per_page=1000" url = "http://#{ENV["PTIME_BASE_URL"]}/api/v1/#{path}" content_type = "application/vnd.api+json; charset=utf-8" stub_request(:get, url) - .to_return(body: return_body, headers: { 'content-type': content_type }, status: 200) + .to_return(body: return_body, headers: { 'content-type': content_type }, status: status) .with(basic_auth: [ENV["PTIME_API_USERNAME"], ENV["PTIME_API_PASSWORD"]]) end