From 38a9e5d9c51377a975a63313aab0bbcb64c7a5ae Mon Sep 17 00:00:00 2001 From: Kevin Soltysiak Date: Sun, 11 Feb 2024 17:43:43 +0100 Subject: [PATCH] refactor: update specs to reflect the changes in internal API --- spec/scalingo/auth/tokens_spec.rb | 4 +-- spec/scalingo/client_spec.rb | 2 +- spec/scalingo/regional/addons_spec.rb | 2 ++ spec/scalingo/regional/apps_spec.rb | 1 + spec/scalingo/regional/collaborators_spec.rb | 1 - spec/scalingo/regional/logs_spec.rb | 2 +- spec/support/shared.rb | 26 ++++++++++++-------- 7 files changed, 23 insertions(+), 15 deletions(-) diff --git a/spec/scalingo/auth/tokens_spec.rb b/spec/scalingo/auth/tokens_spec.rb index fa64a88..de798b3 100644 --- a/spec/scalingo/auth/tokens_spec.rb +++ b/spec/scalingo/auth/tokens_spec.rb @@ -9,8 +9,8 @@ let(:stub_pattern) { "exchange-200" } it "is successful" do - expect(response).to be_successful - expect(response.data[:token]).to be_present + expect(response).to be_success + expect(response.body).to be_present end end diff --git a/spec/scalingo/client_spec.rb b/spec/scalingo/client_spec.rb index 7ae6d31..0f44f6f 100644 --- a/spec/scalingo/client_spec.rb +++ b/spec/scalingo/client_spec.rb @@ -52,7 +52,7 @@ it "is successful with valid token" do fake_response = OpenStruct.new( successful?: true, - data: {token: "response token"} + data: "response token" ) expect(subject.auth.tokens).to receive(:exchange).and_return(fake_response) diff --git a/spec/scalingo/regional/addons_spec.rb b/spec/scalingo/regional/addons_spec.rb index 0491c9c..ac6ed2f 100644 --- a/spec/scalingo/regional/addons_spec.rb +++ b/spec/scalingo/regional/addons_spec.rb @@ -45,6 +45,7 @@ context "success" do let(:arguments) { [meta[:app_id], meta[:provision][:valid]] } let(:stub_pattern) { "provision-201" } + let(:expected_keys) { %i[addon message] } it_behaves_like "a singular object response", 201 end @@ -139,6 +140,7 @@ context "success" do let(:arguments) { [meta[:app_id], meta[:id], meta[:update][:valid]] } let(:stub_pattern) { "update-200" } + let(:expected_keys) { %i[addon message] } it_behaves_like "a singular object response" end diff --git a/spec/scalingo/regional/apps_spec.rb b/spec/scalingo/regional/apps_spec.rb index 316acbf..5c6bb17 100644 --- a/spec/scalingo/regional/apps_spec.rb +++ b/spec/scalingo/regional/apps_spec.rb @@ -61,6 +61,7 @@ context "success" do let(:arguments) { meta[:id] } let(:stub_pattern) { "logs_url" } + let(:expected_keys) { %i[app logs_url] } it_behaves_like "a singular object response" end diff --git a/spec/scalingo/regional/collaborators_spec.rb b/spec/scalingo/regional/collaborators_spec.rb index b304476..e2285d3 100644 --- a/spec/scalingo/regional/collaborators_spec.rb +++ b/spec/scalingo/regional/collaborators_spec.rb @@ -31,7 +31,6 @@ context "success" do let(:arguments) { meta[:accept][:valid] } let(:stub_pattern) { "accept-200" } - let(:expected_keys) { %i[app] } it_behaves_like "a singular object response" end diff --git a/spec/scalingo/regional/logs_spec.rb b/spec/scalingo/regional/logs_spec.rb index 99b5f2f..51ad0ef 100644 --- a/spec/scalingo/regional/logs_spec.rb +++ b/spec/scalingo/regional/logs_spec.rb @@ -33,7 +33,7 @@ let(:stub_pattern) { "archives-200" } it_behaves_like "a collection response" - it_behaves_like "a non-paginated collection" + it_behaves_like "a cursor paginated collection" end end end diff --git a/spec/support/shared.rb b/spec/support/shared.rb index 1c4428a..771fc70 100644 --- a/spec/support/shared.rb +++ b/spec/support/shared.rb @@ -32,30 +32,30 @@ end end -RSpec.shared_examples "a not found response" do - it "cannot be found" do - expect(response).not_to be_successful - expect(response.status).to eq 404 - end -end - RSpec.shared_examples "a client error" do it "is a generic client error" do - expect(response).not_to be_successful + expect(response).to be_client_error expect(response.status).to eq 400 end end RSpec.shared_examples "a server error" do it "is a generic server error" do - expect(response).not_to be_successful + expect(response).to be_server_error expect(response.status).to eq 500 end end +RSpec.shared_examples "a not found response" do + it "cannot be found" do + expect(response).to be_client_error + expect(response.status).to eq 404 + end +end + RSpec.shared_examples "an unprocessable request" do it "cannot be found" do - expect(response).not_to be_successful + expect(response).to be_client_error expect(response.status).to eq 422 end end @@ -119,6 +119,12 @@ end end +RSpec.shared_examples "a cursor paginated collection" do |code = 200| + it "is cursor paginated" do + expect(response).to be_cursor_paginated + end +end + RSpec.shared_examples "a non-paginated collection" do |code = 200| it "is not paginated" do expect(response).not_to be_paginated