From 177ee6f24a35bf2c45064876bf455397d6e2b689 Mon Sep 17 00:00:00 2001 From: Giovanni Capuano Date: Mon, 31 Jul 2017 13:51:26 +0200 Subject: [PATCH] Add tests for client#update_application --- .../cassettes/client/update_application.yml | 44 +++++++++++++++++++ ...pdate_application_invalid_candidate_id.yml | 42 ++++++++++++++++++ ...pdate_application_invalid_on_behalf_of.yml | 42 ++++++++++++++++++ spec/greenhouse_io/api/client_spec.rb | 44 +++++++++++++++++++ 4 files changed, 172 insertions(+) create mode 100644 spec/fixtures/cassettes/client/update_application.yml create mode 100644 spec/fixtures/cassettes/client/update_application_invalid_candidate_id.yml create mode 100644 spec/fixtures/cassettes/client/update_application_invalid_on_behalf_of.yml diff --git a/spec/fixtures/cassettes/client/update_application.yml b/spec/fixtures/cassettes/client/update_application.yml new file mode 100644 index 0000000..ad3d170 --- /dev/null +++ b/spec/fixtures/cassettes/client/update_application.yml @@ -0,0 +1,44 @@ +--- +http_interactions: +- request: + method: patch + uri: https://123FakeToken:@harvest.greenhouse.io/v1/applications/64087658 + body: + encoding: UTF-8 + string: '{"source_id":130370}' + headers: + On-Behalf-Of: + - '509925' + response: + status: + code: 200 + message: OK + headers: + Content-Type: + - application/json;charset=utf-8 + Date: + - Mon, 31 Jul 2017 11:42:38 GMT + Server: + - nginx + Status: + - 200 OK + X-Content-Type-Options: + - nosniff + X-Gh-Proxy: + - 'true' + X-Ratelimit-Limit: + - '50' + X-Ratelimit-Remaining: + - '49' + Content-Length: + - '505' + Connection: + - keep-alive + body: + encoding: UTF-8 + string: '{"id":64087658,"candidate_id":52865001,"prospect":false,"applied_at":"2017-07-31T10:36:03.316Z","rejected_at":null,"last_activity_at":"2017-07-31T10:59:50.698Z","source":{"id":130370,"public_name":"Honeypot"},"credited_to":null,"rejection_reason":null,"rejection_details":null,"jobs":[{"id":474298,"name":"Data + Engineer (f/m) "}],"status":"active","current_stage":{"id":3458762,"name":"Application + Review"},"answers":[],"prospect_detail":{"prospect_pool":null,"prospect_stage":null,"prospect_owner":null}}' + http_version: + recorded_at: Mon, 31 Jul 2017 11:42:39 GMT +recorded_with: VCR 3.0.3 diff --git a/spec/fixtures/cassettes/client/update_application_invalid_candidate_id.yml b/spec/fixtures/cassettes/client/update_application_invalid_candidate_id.yml new file mode 100644 index 0000000..83ccbbe --- /dev/null +++ b/spec/fixtures/cassettes/client/update_application_invalid_candidate_id.yml @@ -0,0 +1,42 @@ +--- +http_interactions: +- request: + method: patch + uri: https://123FakeToken:@harvest.greenhouse.io/v1/applications/1010101 + body: + encoding: UTF-8 + string: '{"source_id":130370}' + headers: + On-Behalf-Of: + - '509925' + response: + status: + code: 403 + message: Forbidden + headers: + Content-Type: + - application/json;charset=utf-8 + Date: + - Mon, 31 Jul 2017 11:45:59 GMT + Server: + - nginx + Status: + - 403 Forbidden + X-Content-Type-Options: + - nosniff + X-Gh-Proxy: + - 'true' + X-Ratelimit-Limit: + - '50' + X-Ratelimit-Remaining: + - '48' + Content-Length: + - '51' + Connection: + - keep-alive + body: + encoding: UTF-8 + string: '{"message":"You do not have access to that record"}' + http_version: + recorded_at: Mon, 31 Jul 2017 11:45:59 GMT +recorded_with: VCR 3.0.3 diff --git a/spec/fixtures/cassettes/client/update_application_invalid_on_behalf_of.yml b/spec/fixtures/cassettes/client/update_application_invalid_on_behalf_of.yml new file mode 100644 index 0000000..213ba86 --- /dev/null +++ b/spec/fixtures/cassettes/client/update_application_invalid_on_behalf_of.yml @@ -0,0 +1,42 @@ +--- +http_interactions: +- request: + method: patch + uri: https://123FakeToken:@harvest.greenhouse.io/v1/applications/64087658 + body: + encoding: UTF-8 + string: '{"source_id":130370}' + headers: + On-Behalf-Of: + - '101010' + response: + status: + code: 403 + message: Forbidden + headers: + Content-Type: + - application/json;charset=utf-8 + Date: + - Mon, 31 Jul 2017 11:45:58 GMT + Server: + - nginx + Status: + - 403 Forbidden + X-Content-Type-Options: + - nosniff + X-Gh-Proxy: + - 'true' + X-Ratelimit-Limit: + - '50' + X-Ratelimit-Remaining: + - '49' + Content-Length: + - '51' + Connection: + - keep-alive + body: + encoding: UTF-8 + string: '{"message":"You do not have access to that record"}' + http_version: + recorded_at: Mon, 31 Jul 2017 11:45:58 GMT +recorded_with: VCR 3.0.3 diff --git a/spec/greenhouse_io/api/client_spec.rb b/spec/greenhouse_io/api/client_spec.rb index 7209013..336b143 100644 --- a/spec/greenhouse_io/api/client_spec.rb +++ b/spec/greenhouse_io/api/client_spec.rb @@ -367,6 +367,50 @@ end end + describe "#update_application" do + it "update the specified application" do + VCR.use_cassette('client/update_application') do + update_application = @client.update_application( + 64087658, + { + source_id: 130370 + }, + 509925 + ) + expect(update_application).to_not be_nil + expect(update_application[:source][:id]).to eq 130370 + end + end + + it "errors when given invalid On-Behalf-Of id" do + VCR.use_cassette('client/update_application_invalid_on_behalf_of') do + expect { + @client.update_application( + 64087658, + { + source_id: 130370 + }, + 101010 + ) + }.to raise_error(GreenhouseIo::Error) + end + end + + it "errors when given an invalid application id" do + VCR.use_cassette('client/update_application_invalid_candidate_id') do + expect { + @client.update_application( + 1010101, + { + source_id: 130370 + }, + 509925 + ) + }.to raise_error(GreenhouseIo::Error) + end + end + end + describe "#scorecards" do before do VCR.use_cassette('client/scorecards') do