From 67cbfa12c313a37ea868a6b092310184f1b332a9 Mon Sep 17 00:00:00 2001 From: Kevin Soltysiak Date: Sat, 17 Feb 2024 17:21:54 +0100 Subject: [PATCH] specs: rewrite regional specs --- lib/scalingo/regional/collaborators.rb | 2 +- lib/scalingo/regional/environment.rb | 2 +- lib/scalingo/regional/logs.rb | 3 +- spec/scalingo/regional/addons_spec.rb | 185 +++++------------- spec/scalingo/regional/apps_spec.rb | 169 +++++----------- spec/scalingo/regional/autoscalers_spec.rb | 105 ++++------ spec/scalingo/regional/collaborators_spec.rb | 80 +++----- spec/scalingo/regional/containers_spec.rb | 77 +++----- spec/scalingo/regional/deployments_spec.rb | 62 +++--- spec/scalingo/regional/domains_spec.rb | 101 ++++------ spec/scalingo/regional/environment_spec.rb | 108 +++++----- spec/scalingo/regional/events_spec.rb | 74 +++---- spec/scalingo/regional/logs_spec.rb | 83 +++++--- spec/scalingo/regional/metrics_spec.rb | 48 ++--- spec/scalingo/regional/notifiers_spec.rb | 134 +++++-------- spec/scalingo/regional/operations_spec.rb | 37 ++-- spec/scalingo/regional/scm_repo_links_spec.rb | 114 +++++++---- 17 files changed, 561 insertions(+), 823 deletions(-) diff --git a/lib/scalingo/regional/collaborators.rb b/lib/scalingo/regional/collaborators.rb index 315654f..3f1f0ee 100644 --- a/lib/scalingo/regional/collaborators.rb +++ b/lib/scalingo/regional/collaborators.rb @@ -3,7 +3,7 @@ module Scalingo class Regional::Collaborators < API::Endpoint get :for, "apps/{app_id}/collaborators" - get :accept, "apps/collaboration", root_key: "token" + get :accept, "apps/collaboration?token={token}" post :invite, "apps/{app_id}/collaborators", root_key: "collaborator" delete :destroy, "apps/{app_id}/collaborators/{id}" end diff --git a/lib/scalingo/regional/environment.rb b/lib/scalingo/regional/environment.rb index c57bd27..44fc4f1 100644 --- a/lib/scalingo/regional/environment.rb +++ b/lib/scalingo/regional/environment.rb @@ -7,6 +7,6 @@ class Regional::Environment < API::Endpoint patch :update, "apps/{app_id}/variables/{id}", root_key: :variable put :bulk_update, "apps/{app_id}/variables", root_key: :variables delete :destroy, "apps/{app_id}/variables/{id}" - delete :bulk_destroy, "apps/{app_id}/variables", root_key: :variable_ids + delete :bulk_destroy, "apps/{app_id}/variables", root_key: :variable_ids, params_as_body: true end end diff --git a/lib/scalingo/regional/logs.rb b/lib/scalingo/regional/logs.rb index 61e2739..4eed59b 100644 --- a/lib/scalingo/regional/logs.rb +++ b/lib/scalingo/regional/logs.rb @@ -11,7 +11,8 @@ def get(url, **params, &block) ## Helper method to avoid having to manually chain two operations def for(**params, &block) - logs_response = scalingo.apps.logs_url(**params) + params[:id] = params.delete(:app_id) if params[:app_id].present? + logs_response = client.apps.logs_url(**params) return logs_response unless logs_response.success? diff --git a/spec/scalingo/regional/addons_spec.rb b/spec/scalingo/regional/addons_spec.rb index 22c9cb0..93db21a 100644 --- a/spec/scalingo/regional/addons_spec.rb +++ b/spec/scalingo/regional/addons_spec.rb @@ -1,175 +1,96 @@ require "spec_helper" -RSpec.describe Scalingo::Regional::Addons do - describe_method "categories" do - context "guest" do - let(:params) { {connected: false} } - let(:expected_count) { 2 } - let(:stub_pattern) { "categories-guest" } - - it_behaves_like "a collection response" - it_behaves_like "a non-paginated collection" - end - - context "logged" do - let(:params) { {connected: true} } - let(:expected_count) { 2 } - let(:stub_pattern) { "categories-logged" } - - it_behaves_like "a collection response" - it_behaves_like "a non-paginated collection" - end - end - - describe_method "providers" do - context "guest" do - let(:params) { {connected: false} } - let(:expected_count) { 9 } - let(:stub_pattern) { "providers-guest" } - - it_behaves_like "a collection response" - it_behaves_like "a non-paginated collection" - end +RSpec.describe Scalingo::Regional::Addons, type: :endpoint do + let(:app_id) { "my-app-id" } - context "logged" do - let(:params) { {connected: true} } - let(:expected_count) { 11 } - let(:stub_pattern) { "providers-logged" } + describe "providers" do + subject(:response) { instance.providers(**arguments) } - it_behaves_like "a collection response" - it_behaves_like "a non-paginated collection" - end + it { is_expected.to have_requested(:get, api_path.merge("/addon_providers")) } end - describe_method "provision" do - context "success" do - let(:params) { meta.slice(:app_id) } - let(:body) { meta[:provision][:valid] } - let(:stub_pattern) { "provision-201" } - let(:expected_keys) { %i[addon message] } + describe "categories" do + subject(:response) { instance.categories(**arguments) } - it_behaves_like "a singular object response", 201 - end + it { is_expected.to have_requested(:get, api_path.merge("/addon_categories")) } + end - context "failure" do - let(:params) { meta.slice(:app_id) } - let(:body) { meta[:provision][:invalid] } - let(:stub_pattern) { "provision-400" } + describe "for" do + subject(:response) { instance.for(**arguments) } - it_behaves_like "a client error" - end - end + let(:params) { {app_id: app_id} } - describe_method "for" do - context "success" do - let(:params) { meta.slice(:app_id) } - let(:stub_pattern) { "for-200" } + include_examples "requires authentication" + include_examples "requires some params", :app_id - it_behaves_like "a collection response" - it_behaves_like "a non-paginated collection" - end + it { is_expected.to have_requested(:get, api_path.merge("/apps/my-app-id/addons")) } end - describe_method "find" do - context "success" do - let(:params) { meta.slice(:app_id, :id) } - let(:stub_pattern) { "find-200" } + describe "provision" do + subject(:response) { instance.provision(**arguments) } - it_behaves_like "a singular object response" - end + let(:params) { {app_id: app_id} } + let(:body) { {field: "value"} } - context "not found" do - let(:params) { meta.slice(:app_id).merge(id: meta[:not_found_id]) } - let(:stub_pattern) { "find-404" } + include_examples "requires authentication" + include_examples "requires some params", :app_id - it_behaves_like "a not found response" - end + it { is_expected.to have_requested(:post, api_path.merge("/apps/my-app-id/addons")).with(body: {addon: body}) } end - describe_method "sso" do - context "success" do - let(:params) { meta.slice(:app_id, :id) } - let(:stub_pattern) { "sso-200" } + describe "find" do + subject(:response) { instance.find(**arguments) } - it_behaves_like "a singular object response" - end + let(:params) { {app_id: app_id, id: "addon-id"} } - context "not found" do - let(:params) { meta.slice(:app_id).merge(id: meta[:not_found_id]) } - let(:stub_pattern) { "sso-404" } + include_examples "requires authentication" + include_examples "requires some params", :app_id, :id - it_behaves_like "a not found response" - end + it { is_expected.to have_requested(:get, api_path.merge("/apps/my-app-id/addons/addon-id")) } end - describe_method "token" do - context "success" do - let(:params) { meta.slice(:app_id, :id) } - let(:stub_pattern) { "token-200" } + describe "update" do + subject(:response) { instance.update(**arguments) } - it_behaves_like "a singular object response" - end + let(:params) { {app_id: app_id, id: "addon-id"} } + let(:body) { {field: "value"} } - context "not found" do - let(:params) { meta.slice(:app_id).merge(id: meta[:not_found_id]) } - let(:stub_pattern) { "token-404" } + include_examples "requires authentication" + include_examples "requires some params", :app_id, :id - it_behaves_like "a not found response" - end + it { is_expected.to have_requested(:patch, api_path.merge("/apps/my-app-id/addons/addon-id")).with(body: {addon: body}) } end - describe_method "authenticate!" do - context "success" do - let(:params) { meta.slice(:app_id, :id) } - let(:stub_pattern) { "token-200" } + describe "sso" do + subject(:response) { instance.sso(**arguments) } - it_behaves_like "a singular object response" - it "authenticates" do - response - expect(scalingo.authenticated_for_database?(meta[:id])).to be true - end - end + let(:params) { {app_id: app_id, id: "addon-id"} } - context "not found" do - let(:params) { meta.slice(:app_id).merge(id: meta[:not_found_id]) } - let(:stub_pattern) { "token-404" } + include_examples "requires authentication" + include_examples "requires some params", :app_id, :id - it_behaves_like "a not found response" - end + it { is_expected.to have_requested(:get, api_path.merge("/apps/my-app-id/addons/addon-id/sso")) } end - describe_method "update" do - context "success" do - let(:params) { meta.slice(:app_id, :id) } - let(:body) { meta[:update][:valid] } - let(:stub_pattern) { "update-200" } - let(:expected_keys) { %i[addon message] } + describe "token" do + subject(:response) { instance.token(**arguments) } - it_behaves_like "a singular object response" - end + let(:params) { {app_id: app_id, id: "addon-id"} } - context "failure" do - let(:params) { meta.slice(:app_id, :id) } - let(:body) { meta[:update][:invalid] } - let(:stub_pattern) { "update-404" } + include_examples "requires authentication" + include_examples "requires some params", :app_id, :id - it_behaves_like "a not found response" - end + it { is_expected.to have_requested(:post, api_path.merge("/apps/my-app-id/addons/addon-id/token")) } end - describe_method "destroy" do - context "success" do - let(:params) { meta.slice(:app_id, :id) } - let(:stub_pattern) { "destroy-204" } + describe "destroy" do + subject(:response) { instance.destroy(**arguments) } - it_behaves_like "an empty response" - end + let(:params) { {app_id: app_id, id: "addon-id"} } - context "not found" do - let(:params) { meta.slice(:app_id).merge(id: meta[:not_found_id]) } - let(:stub_pattern) { "destroy-404" } + include_examples "requires authentication" + include_examples "requires some params", :app_id, :id - it_behaves_like "a not found response" - end + it { is_expected.to have_requested(:delete, api_path.merge("/apps/my-app-id/addons/addon-id")) } end end diff --git a/spec/scalingo/regional/apps_spec.rb b/spec/scalingo/regional/apps_spec.rb index 0533e0e..ae81006 100644 --- a/spec/scalingo/regional/apps_spec.rb +++ b/spec/scalingo/regional/apps_spec.rb @@ -1,157 +1,96 @@ require "spec_helper" -RSpec.describe Scalingo::Regional::Apps do - describe_method "all" do - let(:expected_count) { 2 } - let(:stub_pattern) { "all" } +RSpec.describe Scalingo::Regional::Apps, type: :endpoint do + describe "all" do + subject(:response) { instance.all(**arguments) } - it_behaves_like "a collection response" - it_behaves_like "a non-paginated collection" + include_examples "requires authentication" + + it { is_expected.to have_requested(:get, api_path.merge("/apps")) } end - describe_method "create" do - context "success" do - let(:body) { meta[:create][:valid] } - let(:stub_pattern) { "create-201" } + describe "create" do + subject(:response) { instance.create(**arguments) } - it_behaves_like "a singular object response", 201 - end + let(:body) { {field: "value"} } - context "dry run" do - let(:params) { {dry_run: true} } - let(:body) { meta[:create][:valid] } - let(:stub_pattern) { "create-201-dry-run" } + include_examples "requires authentication" - it_behaves_like "a singular object response", 201 - end + it { is_expected.to have_requested(:post, api_path.merge("/apps")).with(body: {app: body}) } - context "failure" do - let(:body) { meta[:create][:invalid] } - let(:stub_pattern) { "create-422" } + context "when dry-running" do + let(:params) { {dry_run: true} } - it_behaves_like "an unprocessable request" + it { is_expected.to have_requested(:post, api_path.merge("/apps")).with(headers: {"X-Dry-Run" => true}, body: {app: body}) } end end - describe_method "find" do - context "success" do - let(:params) { meta.slice(:id) } - let(:stub_pattern) { "find-200" } + describe "find" do + subject(:response) { instance.find(**arguments) } - it_behaves_like "a singular object response" - end + let(:params) { {id: "my-app-id"} } - context "not found" do - let(:params) { {id: meta[:not_found_id]} } - let(:stub_pattern) { "find-404" } + include_examples "requires authentication" + include_examples "requires some params", :id - it_behaves_like "a not found response" - end + it { is_expected.to have_requested(:get, api_path.merge("/apps/my-app-id")) } end - describe_method "update" do - context "success" do - let(:params) { meta.slice(:id) } - let(:body) { meta[:update][:valid] } - let(:stub_pattern) { "update-200" } + describe "logs_url" do + subject(:response) { instance.logs_url(**arguments) } - it_behaves_like "a singular object response" - end + let(:params) { {id: "my-app-id"} } - context "invalid stack" do - let(:params) { meta.slice(:id) } - let(:body) { meta[:update][:invalid] } - let(:stub_pattern) { "update-stack-404" } + include_examples "requires authentication" + include_examples "requires some params", :id - it_behaves_like "a not found response" - end + it { is_expected.to have_requested(:get, api_path.merge("/apps/my-app-id/logs")) } end - describe_method "logs_url" do - context "success" do - let(:params) { meta.slice(:id) } - let(:stub_pattern) { "logs_url" } - let(:expected_keys) { %i[app logs_url] } + describe "update" do + subject(:response) { instance.update(**arguments) } - it_behaves_like "a singular object response" - end - end + let(:params) { {id: "my-app-id"} } + let(:body) { {field: "value"} } - describe_method "destroy" do - context "success" do - let(:params) { meta.slice(:id) } - let(:body) { meta[:destroy][:valid] } - let(:stub_pattern) { "destroy-204" } + include_examples "requires authentication" + include_examples "requires some params", :id - it_behaves_like "an empty response" - end + it { is_expected.to have_requested(:patch, api_path.merge("/apps/my-app-id")).with(body: {app: body}) } + end - context "not found" do - let(:params) { {id: meta[:not_found_id]} } - let(:body) { meta[:destroy][:valid] } - let(:stub_pattern) { "destroy-404" } + describe "rename" do + subject(:response) { instance.rename(**arguments) } - it_behaves_like "a not found response" - end + let(:params) { {id: "my-app-id"} } + let(:body) { {field: "value"} } - context "unprocessable" do - let(:params) { meta.slice(:id) } - let(:body) { meta[:destroy][:invalid] } - let(:stub_pattern) { "destroy-422" } + include_examples "requires authentication" + include_examples "requires some params", :id - it_behaves_like "an unprocessable request" - end + it { is_expected.to have_requested(:post, api_path.merge("/apps/my-app-id/rename")).with(body: body) } end - describe_method "rename" do - context "success" do - let(:params) { meta.slice(:id) } - let(:body) { meta[:rename][:valid] } - let(:stub_pattern) { "rename-200" } - - it_behaves_like "a singular object response" - end - - context "not found" do - let(:params) { {id: meta[:not_found_id]} } - let(:body) { meta[:rename][:valid] } - let(:stub_pattern) { "rename-404" } + describe "transfer" do + subject(:response) { instance.transfer(**arguments) } - it_behaves_like "a not found response" - end + let(:params) { {id: "my-app-id"} } + let(:body) { {field: "value"} } - context "unprocessable" do - let(:params) { meta.slice(:id) } - let(:body) { meta[:rename][:invalid] } - let(:stub_pattern) { "rename-422" } + include_examples "requires authentication" + include_examples "requires some params", :id - it_behaves_like "an unprocessable request" - end + it { is_expected.to have_requested(:patch, api_path.merge("/apps/my-app-id")).with(body: body) } end - describe_method "transfer" do - context "success" do - let(:params) { meta.slice(:id) } - let(:body) { meta[:transfer][:valid] } - let(:stub_pattern) { "transfer-200" } - - it_behaves_like "a singular object response" - end - - context "not found" do - let(:params) { {id: meta[:not_found_id]} } - let(:body) { meta[:transfer][:valid] } - let(:stub_pattern) { "transfer-404" } + describe "destroy" do + subject(:response) { instance.destroy(**arguments) } - it_behaves_like "a not found response" - end + let(:params) { {id: "my-app-id"} } - context "unprocessable" do - let(:params) { meta.slice(:id) } - let(:body) { meta[:transfer][:invalid] } - let(:stub_pattern) { "transfer-422" } + include_examples "requires authentication" + include_examples "requires some params", :id - it_behaves_like "an unprocessable request" - end + it { is_expected.to have_requested(:delete, api_path.merge("/apps/my-app-id")) } end end diff --git a/spec/scalingo/regional/autoscalers_spec.rb b/spec/scalingo/regional/autoscalers_spec.rb index c6b6fa3..f1549ca 100644 --- a/spec/scalingo/regional/autoscalers_spec.rb +++ b/spec/scalingo/regional/autoscalers_spec.rb @@ -1,89 +1,62 @@ require "spec_helper" -RSpec.describe Scalingo::Regional::Autoscalers do - describe_method "create" do - context "success" do - let(:params) { meta.slice(:app_id) } - let(:body) { meta[:create][:valid] } - let(:stub_pattern) { "create-201" } - - it_behaves_like "a singular object response", 201 - end - - context "failure" do - let(:params) { meta.slice(:app_id) } - let(:body) { meta[:create][:invalid] } - let(:stub_pattern) { "create-500" } - - it_behaves_like "a server error" - end - end +RSpec.describe Scalingo::Regional::Autoscalers, type: :endpoint do + let(:app_id) { "my-app-id" } + + describe "for" do + subject(:response) { instance.for(**arguments) } + + let(:params) { {app_id: app_id} } - describe_method "for" do - context "success" do - let(:params) { meta.slice(:app_id) } - let(:stub_pattern) { "for-200" } + include_examples "requires authentication" + include_examples "requires some params", :app_id - it_behaves_like "a collection response" - it_behaves_like "a non-paginated collection" - end + it { is_expected.to have_requested(:get, api_path.merge("/apps/my-app-id/autoscalers")) } end - describe_method "find" do - context "success" do - let(:params) { meta.slice(:app_id, :id) } - let(:stub_pattern) { "find-200" } + describe "create" do + subject(:response) { instance.create(**arguments) } - it_behaves_like "a singular object response" - end + let(:params) { {app_id: app_id} } + let(:body) { {field: "value"} } - context "not found" do - let(:params) { meta.slice(:app_id).merge(id: meta[:not_found_id]) } - let(:stub_pattern) { "find-404" } + include_examples "requires authentication" + include_examples "requires some params", :app_id - it_behaves_like "a not found response" - end + it { is_expected.to have_requested(:post, api_path.merge("/apps/my-app-id/autoscalers")).with(body: {autoscaler: body}) } end - describe_method "update" do - context "success" do - let(:params) { meta.slice(:app_id, :id) } - let(:body) { meta[:update][:valid] } - let(:stub_pattern) { "update-200" } + describe "find" do + subject(:response) { instance.find(**arguments) } - it_behaves_like "a singular object response" - end + let(:params) { {app_id: app_id, id: "autoscaler-id"} } + + include_examples "requires authentication" + include_examples "requires some params", :app_id, :id + + it { is_expected.to have_requested(:get, api_path.merge("/apps/my-app-id/autoscalers/autoscaler-id")) } + end - context "failure" do - let(:params) { meta.slice(:app_id, :id) } - let(:body) { meta[:update][:invalid] } - let(:stub_pattern) { "update-500" } + describe "update" do + subject(:response) { instance.update(**arguments) } - it_behaves_like "a server error" - end + let(:params) { {app_id: app_id, id: "autoscaler-id"} } + let(:body) { {field: "value"} } - context "not found" do - let(:params) { meta.slice(:app_id).merge(id: meta[:not_found_id]) } - let(:body) { meta[:update][:valid] } - let(:stub_pattern) { "update-404" } + include_examples "requires authentication" + include_examples "requires some params", :app_id, :id - it_behaves_like "a not found response" - end + it { is_expected.to have_requested(:patch, api_path.merge("/apps/my-app-id/autoscalers/autoscaler-id")).with(body: {autoscaler: body}) } end - describe_method "destroy" do - context "success" do - let(:params) { meta.slice(:app_id, :id) } - let(:stub_pattern) { "destroy-204" } + describe "destroy" do + subject(:response) { instance.destroy(**arguments) } - it_behaves_like "an empty response" - end + let(:params) { {app_id: app_id, id: "autoscaler-id"} } - context "not found" do - let(:params) { meta.slice(:app_id).merge(id: meta[:not_found_id]) } - let(:stub_pattern) { "destroy-404" } + include_examples "requires authentication" + include_examples "requires some params", :app_id, :id - it_behaves_like "a not found response" - end + it { is_expected.to have_requested(:delete, api_path.merge("/apps/my-app-id/autoscalers/autoscaler-id")) } end end diff --git a/spec/scalingo/regional/collaborators_spec.rb b/spec/scalingo/regional/collaborators_spec.rb index 96b253a..4360d28 100644 --- a/spec/scalingo/regional/collaborators_spec.rb +++ b/spec/scalingo/regional/collaborators_spec.rb @@ -1,70 +1,50 @@ require "spec_helper" -RSpec.describe Scalingo::Regional::Collaborators do - describe_method "for" do - context "success" do - let(:params) { meta.slice(:app_id) } - let(:stub_pattern) { "for-200" } - - it_behaves_like "a collection response" - it_behaves_like "a non-paginated collection" - end - end +RSpec.describe Scalingo::Regional::Collaborators, type: :endpoint do + let(:app_id) { "my-app-id" } - describe_method "invite" do - context "success" do - let(:params) { meta.slice(:app_id) } - let(:body) { meta[:invite][:valid] } - let(:stub_pattern) { "invite-201" } + describe "for" do + subject(:response) { instance.for(**arguments) } - it_behaves_like "a singular object response", 201 - end + let(:params) { {app_id: app_id} } - context "failure" do - let(:params) { meta.slice(:app_id) } - let(:body) { meta[:invite][:invalid] } - let(:stub_pattern) { "invite-422" } + include_examples "requires authentication" + include_examples "requires some params", :app_id - it_behaves_like "an unprocessable request" - end + it { is_expected.to have_requested(:get, api_path.merge("/apps/my-app-id/collaborators")) } end - describe_method "accept" do - context "success" do - let(:body) { meta[:accept][:valid] } - let(:stub_pattern) { "accept-200" } + describe "accept" do + subject(:response) { instance.accept(**arguments) } + + let(:params) { {app_id: app_id, token: "some-token"} } - it_behaves_like "a singular object response" - end + include_examples "requires authentication" + include_examples "requires some params", :token + + it { is_expected.to have_requested(:get, api_path.merge("/apps/collaboration?token=some-token")) } + end - context "already collaborating" do - let(:body) { meta[:accept][:valid] } - let(:stub_pattern) { "accept-400" } + describe "invite" do + subject(:response) { instance.invite(**arguments) } - it_behaves_like "a client error" - end + let(:params) { {app_id: app_id} } + let(:body) { {field: "value"} } - context "not found" do - let(:body) { meta[:accept][:invalid] } - let(:stub_pattern) { "accept-404" } + include_examples "requires authentication" + include_examples "requires some params", :app_id - it_behaves_like "a not found response" - end + it { is_expected.to have_requested(:post, api_path.merge("/apps/my-app-id/collaborators")).with(body: {collaborator: body}) } end - describe_method "destroy" do - context "success" do - let(:params) { meta.slice(:app_id, :id) } - let(:stub_pattern) { "destroy-204" } + describe "destroy" do + subject(:response) { instance.destroy(**arguments) } - it_behaves_like "an empty response" - end + let(:params) { {app_id: app_id, id: "collaborator-id"} } - context "not found" do - let(:params) { meta.slice(:app_id).merge(id: meta[:not_found_id]) } - let(:stub_pattern) { "destroy-404" } + include_examples "requires authentication" + include_examples "requires some params", :app_id, :id - it_behaves_like "a not found response" - end + it { is_expected.to have_requested(:delete, api_path.merge("/apps/my-app-id/collaborators/collaborator-id")) } end end diff --git a/spec/scalingo/regional/containers_spec.rb b/spec/scalingo/regional/containers_spec.rb index f2e92b0..cd04f2f 100644 --- a/spec/scalingo/regional/containers_spec.rb +++ b/spec/scalingo/regional/containers_spec.rb @@ -1,71 +1,46 @@ require "spec_helper" -RSpec.describe Scalingo::Regional::Containers do - describe_method "sizes" do - context "guest" do - let(:params) { {connected: false} } +RSpec.describe Scalingo::Regional::Containers, type: :endpoint do + let(:app_id) { "my-app-id" } - let(:expected_count) { 7 } - let(:stub_pattern) { "sizes-guest" } + describe "sizes" do + subject(:response) { instance.sizes(**arguments) } - it_behaves_like "a collection response" - it_behaves_like "a non-paginated collection" - end + it { is_expected.to have_requested(:get, api_path.merge("/features/container_sizes")) } + end - context "logged" do - let(:expected_count) { 7 } - let(:stub_pattern) { "sizes-logged" } + describe "for" do + subject(:response) { instance.for(**arguments) } - it_behaves_like "a collection response" - it_behaves_like "a non-paginated collection" - end - end + let(:params) { {app_id: app_id} } - describe_method "for" do - context "success" do - let(:params) { meta.slice(:app_id) } - let(:expected_count) { 2 } - let(:expected_keys) { %i[name] } - let(:stub_pattern) { "for-200" } + include_examples "requires authentication" + include_examples "requires some params", :app_id - it_behaves_like "a collection response" - it_behaves_like "a non-paginated collection" - end + it { is_expected.to have_requested(:get, api_path.merge("/apps/my-app-id/containers")) } end - describe_method "restart" do - context "success" do - let(:params) { meta.slice(:app_id) } - let(:body) { meta[:restart][:valid] } - let(:stub_pattern) { "restart-202" } + describe "scale" do + subject(:response) { instance.scale(**arguments) } - it_behaves_like "a singular object response", 202 - end + let(:params) { {app_id: app_id} } + let(:body) { {field: "value"} } - context "success" do - let(:params) { meta.slice(:app_id) } - let(:body) { meta[:restart][:invalid] } - let(:stub_pattern) { "restart-422" } + include_examples "requires authentication" + include_examples "requires some params", :app_id - it_behaves_like "an unprocessable request" - end + it { is_expected.to have_requested(:post, api_path.merge("/apps/my-app-id/scale")).with(body: {containers: body}) } end - describe_method "scale" do - context "success" do - let(:params) { meta.slice(:app_id) } - let(:body) { meta[:scale][:valid] } - let(:stub_pattern) { "scale-202" } + describe "restart" do + subject(:response) { instance.restart(**arguments) } - it_behaves_like "a singular object response", 202 - end + let(:params) { {app_id: app_id} } + let(:body) { {field: "value"} } - context "success" do - let(:params) { meta.slice(:app_id) } - let(:body) { meta[:scale][:invalid] } - let(:stub_pattern) { "scale-422" } + include_examples "requires authentication" + include_examples "requires some params", :app_id - it_behaves_like "an unprocessable request" - end + it { is_expected.to have_requested(:post, api_path.merge("/apps/my-app-id/restart")).with(body: {scope: body}) } end end diff --git a/spec/scalingo/regional/deployments_spec.rb b/spec/scalingo/regional/deployments_spec.rb index 3fbd60a..5534cfd 100644 --- a/spec/scalingo/regional/deployments_spec.rb +++ b/spec/scalingo/regional/deployments_spec.rb @@ -1,56 +1,44 @@ require "spec_helper" -RSpec.describe Scalingo::Regional::Deployments do - describe_method "for" do - context "success" do - let(:params) { meta.slice(:app_id) } +RSpec.describe Scalingo::Regional::Deployments, type: :endpoint do + let(:app_id) { "my-app-id" } - context "with pages" do - let(:params) { meta.slice(:app_id).merge(query: {page: 3}) } - let(:stub_pattern) { "for-with-pages" } + describe "for" do + subject(:response) { instance.for(**arguments) } - it_behaves_like "a collection response" - it_behaves_like "a paginated collection" - end + let(:params) { {app_id: app_id} } - context "without pages" do - let(:stub_pattern) { "for-without-pages" } + include_examples "requires authentication" + include_examples "requires some params", :app_id - it_behaves_like "a collection response" - it_behaves_like "a paginated collection" - end + it { is_expected.to have_requested(:get, api_path.merge("/apps/my-app-id/deployments")) } + + context "with query params" do + let(:params) { {app_id: app_id, query: {page: 2}} } + + it { is_expected.to have_requested(:get, api_path.merge("/apps/my-app-id/deployments?page=2")) } end end - describe_method "find" do - context "success" do - let(:params) { meta.slice(:app_id, :id) } - let(:stub_pattern) { "find-200" } + describe "find" do + subject(:response) { instance.find(**arguments) } - it_behaves_like "a singular object response" - end + let(:params) { {app_id: app_id, id: "deployment-id"} } - context "failure" do - let(:params) { meta.slice(:app_id).merge(id: meta[:not_found_id]) } - let(:stub_pattern) { "find-404" } + include_examples "requires authentication" + include_examples "requires some params", :app_id, :id - it_behaves_like "a not found response" - end + it { is_expected.to have_requested(:get, api_path.merge("/apps/my-app-id/deployments/deployment-id")) } end - describe_method "logs" do - context "success" do - let(:params) { meta.slice(:app_id, :id) } - let(:stub_pattern) { "logs-200" } + describe "logs" do + subject(:response) { instance.logs(**arguments) } - it_behaves_like "a singular object response" - end + let(:params) { {app_id: app_id, id: "deployment-id"} } - context "failure" do - let(:params) { meta.slice(:app_id).merge(id: meta[:not_found_id]) } - let(:stub_pattern) { "logs-404" } + include_examples "requires authentication" + include_examples "requires some params", :app_id, :id - it_behaves_like "a not found response" - end + it { is_expected.to have_requested(:get, api_path.merge("/apps/my-app-id/deployments/deployment-id/output")) } end end diff --git a/spec/scalingo/regional/domains_spec.rb b/spec/scalingo/regional/domains_spec.rb index a6f927a..9342079 100644 --- a/spec/scalingo/regional/domains_spec.rb +++ b/spec/scalingo/regional/domains_spec.rb @@ -1,89 +1,62 @@ require "spec_helper" -RSpec.describe Scalingo::Regional::Domains do - describe_method "for" do - context "success" do - let(:params) { meta.slice(:app_id) } - let(:stub_pattern) { "for-200" } - - it_behaves_like "a collection response" - it_behaves_like "a non-paginated collection" - end - end +RSpec.describe Scalingo::Regional::Domains, type: :endpoint do + let(:app_id) { "my-app-id" } - describe_method "find" do - context "success" do - let(:params) { meta.slice(:app_id, :id) } - let(:stub_pattern) { "find-200" } + describe "for" do + subject(:response) { instance.for(**arguments) } - it_behaves_like "a singular object response" - end + let(:params) { {app_id: app_id} } - context "not found" do - let(:params) { meta.slice(:app_id).merge(id: meta[:not_found_id]) } - let(:stub_pattern) { "find-404" } + include_examples "requires authentication" + include_examples "requires some params", :app_id - it_behaves_like "a not found response" - end + it { is_expected.to have_requested(:get, api_path.merge("/apps/my-app-id/domains")) } end - describe_method "create" do - context "success" do - let(:params) { meta.slice(:app_id) } - let(:body) { meta[:create][:valid] } - let(:stub_pattern) { "create-201" } + describe "create" do + subject(:response) { instance.create(**arguments) } - it_behaves_like "a singular object response", 201 - end + let(:params) { {app_id: app_id} } + let(:body) { {field: "value"} } - context "failure" do - let(:params) { meta.slice(:app_id) } - let(:body) { meta[:create][:invalid] } - let(:stub_pattern) { "create-422" } + include_examples "requires authentication" + include_examples "requires some params", :app_id - it_behaves_like "an unprocessable request" - end + it { is_expected.to have_requested(:post, api_path.merge("/apps/my-app-id/domains")).with(body: {domain: body}) } end - describe_method "update" do - context "success" do - let(:params) { meta.slice(:app_id, :id) } - let(:body) { meta[:update][:valid] } - let(:stub_pattern) { "update-200" } + describe "find" do + subject(:response) { instance.find(**arguments) } + + let(:params) { {app_id: app_id, id: "domain-id"} } - it_behaves_like "a singular object response" - end + include_examples "requires authentication" + include_examples "requires some params", :app_id, :id + + it { is_expected.to have_requested(:get, api_path.merge("/apps/my-app-id/domains/domain-id")) } + end - context "not found" do - let(:params) { meta.slice(:app_id).merge(id: meta[:not_found_id]) } - let(:body) { meta[:update][:valid] } - let(:stub_pattern) { "update-404" } + describe "update" do + subject(:response) { instance.update(**arguments) } - it_behaves_like "a not found response" - end + let(:params) { {app_id: app_id, id: "domain-id"} } + let(:body) { {field: "value"} } - context "failure" do - let(:params) { meta.slice(:app_id, :id) } - let(:body) { meta[:update][:invalid] } - let(:stub_pattern) { "update-422" } + include_examples "requires authentication" + include_examples "requires some params", :app_id, :id - it_behaves_like "an unprocessable request" - end + it { is_expected.to have_requested(:patch, api_path.merge("/apps/my-app-id/domains/domain-id")).with(body: {domain: body}) } end - describe_method "destroy" do - context "success" do - let(:params) { meta.slice(:app_id, :id) } - let(:stub_pattern) { "destroy-204" } + describe "destroy" do + subject(:response) { instance.destroy(**arguments) } - it_behaves_like "an empty response" - end + let(:params) { {app_id: app_id, id: "domain-id"} } - context "not found" do - let(:params) { meta.slice(:app_id).merge(id: meta[:not_found_id]) } - let(:stub_pattern) { "destroy-404" } + include_examples "requires authentication" + include_examples "requires some params", :app_id, :id - it_behaves_like "a not found response" - end + it { is_expected.to have_requested(:delete, api_path.merge("/apps/my-app-id/domains/domain-id")) } end end diff --git a/spec/scalingo/regional/environment_spec.rb b/spec/scalingo/regional/environment_spec.rb index 2d12da8..fa8b6ce 100644 --- a/spec/scalingo/regional/environment_spec.rb +++ b/spec/scalingo/regional/environment_spec.rb @@ -1,83 +1,75 @@ require "spec_helper" -RSpec.describe Scalingo::Regional::Environment do - describe_method "for" do - context "success" do - let(:params) { meta.slice(:app_id) } - let(:stub_pattern) { "for-200" } - - it_behaves_like "a collection response" - it_behaves_like "a non-paginated collection" - end +RSpec.describe Scalingo::Regional::Environment, type: :endpoint do + let(:app_id) { "my-app-id" } + + describe "for" do + subject(:response) { instance.for(**arguments) } + + let(:params) { {app_id: app_id} } + + include_examples "requires authentication" + include_examples "requires some params", :app_id + + it { is_expected.to have_requested(:get, api_path.merge("/apps/my-app-id/variables")) } end - describe_method "create" do - context "success" do - let(:params) { meta.slice(:app_id) } - let(:body) { meta[:create][:valid] } - let(:stub_pattern) { "create-201" } + describe "create" do + subject(:response) { instance.create(**arguments) } - it_behaves_like "a singular object response", 201 - end + let(:params) { {app_id: app_id} } + let(:body) { {field: "value"} } - context "failure" do - let(:params) { meta.slice(:app_id) } - let(:body) { meta[:create][:invalid] } - let(:stub_pattern) { "create-422" } + include_examples "requires authentication" + include_examples "requires some params", :app_id - it_behaves_like "an unprocessable request" - end + it { is_expected.to have_requested(:post, api_path.merge("/apps/my-app-id/variables")).with(body: {variable: body}) } end - describe_method "update" do - context "success" do - let(:params) { meta.slice(:app_id, :id) } - let(:body) { meta[:update][:valid] } - let(:stub_pattern) { "update-200" } + describe "update" do + subject(:response) { instance.update(**arguments) } - it_behaves_like "a singular object response" - end + let(:params) { {app_id: app_id, id: "variable-id"} } + let(:body) { {field: "value"} } - context "not found" do - let(:params) { meta.slice(:app_id).merge(id: meta[:not_found_id]) } - let(:body) { meta[:update][:valid] } - let(:stub_pattern) { "update-404" } + include_examples "requires authentication" + include_examples "requires some params", :app_id, :id - it_behaves_like "a not found response" - end + it { is_expected.to have_requested(:patch, api_path.merge("/apps/my-app-id/variables/variable-id")).with(body: {variable: body}) } end - describe_method "bulk_update" do - let(:params) { meta.slice(:app_id) } - let(:body) { meta[:update][:bulk] } - let(:expected_count) { 4 } - let(:stub_pattern) { "bulk-update-200" } + describe "bulk_update" do + subject(:response) { instance.bulk_update(**arguments) } - it_behaves_like "a collection response" - it_behaves_like "a non-paginated collection" + let(:params) { {app_id: app_id} } + let(:body) { [{field: "value"}] } + + include_examples "requires authentication" + include_examples "requires some params", :app_id + + it { is_expected.to have_requested(:put, api_path.merge("/apps/my-app-id/variables")).with(body: {variables: body}) } end - describe_method "destroy" do - context "success" do - let(:params) { meta.slice(:app_id, :id) } - let(:stub_pattern) { "destroy-204" } + describe "destroy" do + subject(:response) { instance.destroy(**arguments) } - it_behaves_like "an empty response" - end + let(:params) { {app_id: app_id, id: "variable-id"} } - context "not found" do - let(:params) { meta.slice(:app_id).merge(id: meta[:not_found_id]) } - let(:stub_pattern) { "destroy-404" } + include_examples "requires authentication" + include_examples "requires some params", :app_id, :id - it_behaves_like "a not found response" - end + it { is_expected.to have_requested(:delete, api_path.merge("/apps/my-app-id/variables/variable-id")) } end - describe_method "bulk_destroy" do - let(:params) { meta.slice(:app_id) } - let(:body) { meta[:destroy][:bulk] } - let(:stub_pattern) { "bulk-destroy-204" } + describe "bulk_destroy" do + subject(:response) { instance.bulk_destroy(**arguments) } + + let(:params) { {app_id: app_id} } + let(:body) { [1, 2, 3] } + + include_examples "requires authentication" + include_examples "requires some params", :app_id - it_behaves_like "an empty response" + it { is_expected.to have_requested(:delete, api_path.merge("/apps/my-app-id/variables")).with(body: {variable_ids: body}) } end end diff --git a/spec/scalingo/regional/events_spec.rb b/spec/scalingo/regional/events_spec.rb index 154956e..75a3217 100644 --- a/spec/scalingo/regional/events_spec.rb +++ b/spec/scalingo/regional/events_spec.rb @@ -1,67 +1,47 @@ require "spec_helper" -RSpec.describe Scalingo::Regional::Events do - describe_method "categories" do - context "guest" do - let(:params) { {connected: false} } +RSpec.describe Scalingo::Regional::Events, type: :endpoint do + describe "types" do + subject(:response) { instance.types(**arguments) } - let(:expected_count) { 7 } - let(:stub_pattern) { "categories-guest" } - - it_behaves_like "a collection response" - it_behaves_like "a non-paginated collection" - end - - context "logged" do - let(:params) { {connected: true} } + it { is_expected.to have_requested(:get, api_path.merge("/event_types")) } + end - let(:expected_count) { 7 } - let(:stub_pattern) { "categories-logged" } + describe "categories" do + subject(:response) { instance.categories(**arguments) } - it_behaves_like "a collection response" - it_behaves_like "a non-paginated collection" - end + it { is_expected.to have_requested(:get, api_path.merge("/event_categories")) } end - describe_method "types" do - context "guest" do - let(:params) { {connected: false} } + describe "all" do + subject(:response) { instance.all(**arguments) } - let(:expected_count) { 33 } - let(:stub_pattern) { "types-guest" } + include_examples "requires authentication" - it_behaves_like "a collection response" - it_behaves_like "a non-paginated collection" - end + it { is_expected.to have_requested(:get, api_path.merge("/events")) } - context "logged" do - let(:params) { {connected: true} } - let(:expected_count) { 33 } - let(:stub_pattern) { "types-logged" } + context "with query string" do + let(:params) { {query: {page: 2}} } - it_behaves_like "a collection response" - it_behaves_like "a non-paginated collection" + it { is_expected.to have_requested(:get, api_path.merge("/events?page=2")) } end end - describe_method "all" do - context "success" do - let(:expected_count) { 30 } - let(:stub_pattern) { "all-200" } + describe "for" do + subject(:response) { instance.for(**arguments) } - it_behaves_like "a collection response" - it_behaves_like "a paginated collection" - end - end + let(:app_id) { "my-app-id" } + let(:params) { {app_id: app_id} } + + include_examples "requires authentication" + include_examples "requires some params", :app_id + + it { is_expected.to have_requested(:get, api_path.merge("/apps/my-app-id/events")) } - describe_method "for" do - context "success" do - let(:params) { meta.slice(:app_id) } - let(:expected_count) { 18 } - let(:stub_pattern) { "for-200" } + context "with query string" do + let(:params) { {app_id: app_id, query: {page: 2}} } - it_behaves_like "a collection response" - it_behaves_like "a paginated collection" + it { is_expected.to have_requested(:get, api_path.merge("/apps/my-app-id/events?page=2")) } end end end diff --git a/spec/scalingo/regional/logs_spec.rb b/spec/scalingo/regional/logs_spec.rb index 5000613..50edb46 100644 --- a/spec/scalingo/regional/logs_spec.rb +++ b/spec/scalingo/regional/logs_spec.rb @@ -1,40 +1,71 @@ require "spec_helper" -RSpec.describe Scalingo::Regional::Logs do - describe_method "get" do - context "guest" do - let(:arguments) { meta[:urls][:guest] } - let(:params) { {connected: false} } - let(:stub_pattern) { "get-guest-200" } - - it_behaves_like "a singular object response" - end +RSpec.describe Scalingo::Regional::Logs, type: :endpoint do + let(:app_id) { "my-app-id" } - context "logged" do - let(:arguments) { meta[:urls][:logged] } - let(:params) { {connected: true} } - let(:stub_pattern) { "get-logged-200" } + describe "archives" do + subject(:response) { instance.archives(**arguments) } - it_behaves_like "a singular object response" - end + let(:params) { {app_id: app_id} } + + include_examples "requires authentication" + include_examples "requires some params", :app_id + + it { is_expected.to have_requested(:get, api_path.merge("/apps/my-app-id/logs_archives")) } + end + + describe "get" do + subject(:response) { instance.get("http://localhost/any-url", **arguments) } + + include_examples "requires authentication" + + it { is_expected.to have_requested(:get, "http://localhost/any-url") } context "with limit" do - let(:arguments) { meta[:urls][:with_limit] } - let(:params) { meta[:options] } - let(:stub_pattern) { "get-with-limit-200" } + let(:params) { {n: 3} } - it_behaves_like "a singular object response" + it { is_expected.to have_requested(:get, "http://localhost/any-url?n=3") } + end + + context "with other params" do + let(:params) { {z: 7} } + + it { is_expected.to have_requested(:get, "http://localhost/any-url") } end end - describe_method "archives" do - context "success" do - let(:params) { meta.slice(:app_id) } - let(:expected_count) { 0 } - let(:stub_pattern) { "archives-200" } + describe "for" do + subject(:response) { instance.for(**arguments) } + + include_examples "requires authentication" + include_examples "requires some params", :app_id + + let(:params) { {app_id: app_id} } + + context "with a successful call for the logs url" do + before do + stub_request(:get, api_path.merge("/apps/my-app-id/logs")).to_return( + status: 200, + body: "http://localhost/signed-url" + ) + end + + it { is_expected.to have_requested(:get, "http://localhost/signed-url") } + end + + context "with a failed call for the logs url" do + before do + stub_request(:get, api_path.merge("/apps/my-app-id/logs")).to_return( + status: 404, + body: "http://localhost/signed-url" + ) + end - it_behaves_like "a collection response" - it_behaves_like "a cursor paginated collection" + it "returns the first response" do + expect(subject).not_to have_requested(:get, "http://localhost/signed-url") + expect(subject.status).to eq 404 + expect(subject.env.url).to eq api_path.merge("/apps/my-app-id/logs") + end end end end diff --git a/spec/scalingo/regional/metrics_spec.rb b/spec/scalingo/regional/metrics_spec.rb index 793b520..29c42ec 100644 --- a/spec/scalingo/regional/metrics_spec.rb +++ b/spec/scalingo/regional/metrics_spec.rb @@ -1,46 +1,34 @@ require "spec_helper" -RSpec.describe Scalingo::Regional::Metrics do - describe_method "types" do - context "guest" do - let(:connected) { false } - let(:stub_pattern) { "types-guest" } +RSpec.describe Scalingo::Regional::Metrics, type: :endpoint do + let(:app_id) { "my-app-id" } - it_behaves_like "a singular object response" - end - - context "logged" do - let(:connected) { true } - let(:stub_pattern) { "types-logged" } + describe "types" do + subject(:response) { instance.types(**arguments) } - it_behaves_like "a singular object response" - end + it { is_expected.to have_requested(:get, api_path.merge("/features/metrics")) } end - describe_method "for" do - let(:expected_keys) { %i[time value] } + describe "for" do + subject(:response) { instance.for(**arguments) } - context "cpu" do - let(:params) { meta.slice(:app_id).merge(meta[:for][:valid_cpu]) } - let(:expected_count) { 181 } - let(:stub_pattern) { "for-valid-cpu-200" } + let(:params) { {app_id: app_id, metric: "some-metric"} } - it_behaves_like "a collection response" - it_behaves_like "a non-paginated collection" - end + include_examples "requires authentication" + include_examples "requires some params", :app_id, :metric + + it { is_expected.to have_requested(:get, api_path.merge("/apps/my-app-id/stats/some-metric")) } - context "router" do - let(:params) { meta.slice(:app_id).merge(meta[:for][:valid_router]) } - let(:stub_pattern) { "for-valid-router-404" } + context "with container type" do + let(:params) { {app_id: app_id, metric: "some-metric", container_type: "web"} } - it_behaves_like "a not found response" + it { is_expected.to have_requested(:get, api_path.merge("/apps/my-app-id/stats/some-metric/web")) } end - context "invalid" do - let(:params) { meta.slice(:app_id).merge(meta[:for][:invalid]) } - let(:stub_pattern) { "for-invalid-400" } + context "with container type and index" do + let(:params) { {app_id: app_id, metric: "some-metric", container_type: "web", container_index: "7"} } - it_behaves_like "a client error" + it { is_expected.to have_requested(:get, api_path.merge("/apps/my-app-id/stats/some-metric/web/7")) } end end end diff --git a/spec/scalingo/regional/notifiers_spec.rb b/spec/scalingo/regional/notifiers_spec.rb index d928a46..45dd60a 100644 --- a/spec/scalingo/regional/notifiers_spec.rb +++ b/spec/scalingo/regional/notifiers_spec.rb @@ -1,117 +1,79 @@ require "spec_helper" -RSpec.describe Scalingo::Regional::Notifiers do - describe_method "platforms" do - context "guest" do - let(:params) { {connected: false} } - let(:expected_count) { 4 } - let(:stub_pattern) { "platforms-guest" } - - it_behaves_like "a collection response" - it_behaves_like "a non-paginated collection" - end - - context "logged" do - let(:params) { {connected: true} } - let(:expected_count) { 4 } - let(:stub_pattern) { "platforms-logged" } - - it_behaves_like "a collection response" - it_behaves_like "a non-paginated collection" - end - end +RSpec.describe Scalingo::Regional::Notifiers, type: :endpoint do + let(:app_id) { "my-app-id" } - describe_method "for" do - context "success" do - let(:params) { meta.slice(:app_id) } - let(:stub_pattern) { "for-200" } + describe "platforms" do + subject(:response) { instance.platforms(**arguments) } - it_behaves_like "a collection response" - it_behaves_like "a non-paginated collection" - end + it { is_expected.to have_requested(:get, api_path.merge("/notification_platforms")) } end - describe_method "find" do - context "success" do - let(:params) { meta.slice(:app_id, :id) } - let(:stub_pattern) { "find-200" } + describe "for" do + subject(:response) { instance.for(**arguments) } - it_behaves_like "a singular object response" - end + let(:params) { {app_id: app_id} } - context "not found" do - let(:params) { meta.slice(:app_id).merge(id: meta[:not_found_id]) } - let(:stub_pattern) { "find-404" } + include_examples "requires authentication" + include_examples "requires some params", :app_id - it_behaves_like "a not found response" - end + it { is_expected.to have_requested(:get, api_path.merge("/apps/my-app-id/notifiers")) } end - describe_method "create" do - context "success" do - let(:params) { meta.slice(:app_id) } - let(:body) { meta[:create][:valid] } - let(:stub_pattern) { "create-201" } + describe "create" do + subject(:response) { instance.create(**arguments) } + + let(:params) { {app_id: app_id} } + let(:body) { {field: "value"} } + + include_examples "requires authentication" + include_examples "requires some params", :app_id - it_behaves_like "a singular object response", 201 - end + it { is_expected.to have_requested(:post, api_path.merge("/apps/my-app-id/notifiers")).with(body: {notifier: body}) } + end - context "not found" do - let(:params) { meta.slice(:app_id) } - let(:body) { meta[:create][:not_found] } - let(:stub_pattern) { "create-404" } + describe "find" do + subject(:response) { instance.find(**arguments) } - it_behaves_like "a not found response" - end + let(:params) { {app_id: app_id, id: "notifier-id"} } - context "failure" do - let(:params) { meta.slice(:app_id) } - let(:body) { meta[:create][:invalid] } - let(:stub_pattern) { "create-422" } + include_examples "requires authentication" + include_examples "requires some params", :app_id, :id - it_behaves_like "an unprocessable request" - end + it { is_expected.to have_requested(:get, api_path.merge("/apps/my-app-id/notifiers/notifier-id")) } end - describe_method "test" do - context "success" do - let(:params) { meta.slice(:app_id, :id) } - let(:stub_pattern) { "test-200" } + describe "update" do + subject(:response) { instance.update(**arguments) } - it_behaves_like "a singular object response" - end + let(:params) { {app_id: app_id, id: "notifier-id"} } + let(:body) { {field: "value"} } - context "not found" do - let(:params) { meta.slice(:app_id).merge(id: meta[:not_found_id]) } - let(:stub_pattern) { "test-404" } + include_examples "requires authentication" + include_examples "requires some params", :app_id, :id - it_behaves_like "a not found response" - end + it { is_expected.to have_requested(:patch, api_path.merge("/apps/my-app-id/notifiers/notifier-id")).with(body: {notifier: body}) } end - describe_method "update" do - context "success" do - let(:params) { meta.slice(:app_id, :id) } - let(:body) { meta[:update][:valid] } - let(:stub_pattern) { "update-200" } + describe "test" do + subject(:response) { instance.test(**arguments) } + + let(:params) { {app_id: app_id, id: "notifier-id"} } + + include_examples "requires authentication" + include_examples "requires some params", :app_id, :id - it_behaves_like "a singular object response" - end + it { is_expected.to have_requested(:post, api_path.merge("/apps/my-app-id/notifiers/notifier-id/test")) } end - describe_method "destroy" do - context "success" do - let(:params) { meta.slice(:app_id, :id) } - let(:stub_pattern) { "destroy-204" } + describe "destroy" do + subject(:response) { instance.destroy(**arguments) } - it_behaves_like "an empty response" - end + let(:params) { {app_id: app_id, id: "notifier-id"} } - context "not found" do - let(:params) { meta.slice(:app_id).merge(id: meta[:not_found_id]) } - let(:stub_pattern) { "destroy-404" } + include_examples "requires authentication" + include_examples "requires some params", :app_id, :id - it_behaves_like "a not found response" - end + it { is_expected.to have_requested(:delete, api_path.merge("/apps/my-app-id/notifiers/notifier-id")) } end end diff --git a/spec/scalingo/regional/operations_spec.rb b/spec/scalingo/regional/operations_spec.rb index 616c668..27371e0 100644 --- a/spec/scalingo/regional/operations_spec.rb +++ b/spec/scalingo/regional/operations_spec.rb @@ -1,35 +1,24 @@ require "spec_helper" -RSpec.describe Scalingo::Regional::Operations do - describe_method "find" do - context "success" do - let(:params) { meta.slice(:app_id, :id) } - let(:stub_pattern) { "find-200" } +RSpec.describe Scalingo::Regional::Operations, type: :endpoint do + let(:app_id) { "my-app-id" } - it_behaves_like "a singular object response" - end + describe "find" do + subject(:response) { instance.find(**arguments) } - context "not found" do - let(:params) { meta.slice(:app_id).merge(id: meta[:not_found_id]) } - let(:stub_pattern) { "find-404" } + let(:params) { {app_id: app_id, id: "op-id"} } - it_behaves_like "a not found response" - end - end + include_examples "requires authentication" + include_examples "requires some params", :app_id, :id - describe_method "get" do - context "success" do - let(:arguments) { "apps/#{meta[:app_id]}/operations/#{meta[:id]}" } - let(:stub_pattern) { "find-200" } + it { is_expected.to have_requested(:get, api_path.merge("/apps/my-app-id/operations/op-id")) } + end - it_behaves_like "a singular object response" - end + describe "get" do + subject(:response) { instance.get("http://localhost/any-url") } - context "failure" do - let(:arguments) { "apps/#{meta[:app_id]}/operations/#{meta[:not_found_id]}" } - let(:stub_pattern) { "find-404" } + include_examples "requires authentication" - it_behaves_like "a not found response" - end + it { is_expected.to have_requested(:get, "http://localhost/any-url") } end end diff --git a/spec/scalingo/regional/scm_repo_links_spec.rb b/spec/scalingo/regional/scm_repo_links_spec.rb index 3cc15c0..679a1c7 100644 --- a/spec/scalingo/regional/scm_repo_links_spec.rb +++ b/spec/scalingo/regional/scm_repo_links_spec.rb @@ -1,51 +1,97 @@ require "spec_helper" -RSpec.describe Scalingo::Regional::ScmRepoLinks do - describe_method "show" do - context "success" do - let(:params) { meta.slice(:app_id) } - let(:stub_pattern) { "show-200" } +RSpec.describe Scalingo::Regional::ScmRepoLinks, type: :endpoint do + let(:app_id) { "my-app-id" } - it_behaves_like "a singular object response" - end + describe "show" do + subject(:response) { instance.show(**arguments) } + + let(:params) { {app_id: app_id} } + + include_examples "requires authentication" + include_examples "requires some params", :app_id + + it { is_expected.to have_requested(:get, api_path.merge("/apps/my-app-id/scm_repo_link")) } + end + + describe "branches" do + subject(:response) { instance.branches(**arguments) } + + let(:params) { {app_id: app_id} } + + include_examples "requires authentication" + include_examples "requires some params", :app_id + + it { is_expected.to have_requested(:get, api_path.merge("/apps/my-app-id/scm_repo_link/branches")) } + end + + describe "pulls" do + subject(:response) { instance.pulls(**arguments) } + + let(:params) { {app_id: app_id} } + + include_examples "requires authentication" + include_examples "requires some params", :app_id + + it { is_expected.to have_requested(:get, api_path.merge("/apps/my-app-id/scm_repo_link/pulls")) } end - describe_method "create" do - context "success" do - let(:params) { meta.slice(:app_id) } - let(:body) { meta[:create][:valid] } - let(:stub_pattern) { "create-201" } + describe "create" do + subject(:response) { instance.create(**arguments) } - it_behaves_like "a singular object response", 201 - end + let(:params) { {app_id: app_id} } + let(:body) { {field: "value"} } + + include_examples "requires authentication" + include_examples "requires some params", :app_id + + it { is_expected.to have_requested(:post, api_path.merge("/apps/my-app-id/scm_repo_link")).with(body: {scm_repo_link: body}) } end - describe_method "update" do - context "success" do - let(:params) { meta.slice(:app_id) } - let(:body) { meta[:update][:valid] } - let(:stub_pattern) { "update-200" } + describe "deploy" do + subject(:response) { instance.deploy(**arguments) } + + let(:params) { {app_id: app_id} } + let(:body) { {field: "value"} } + + include_examples "requires authentication" + include_examples "requires some params", :app_id - it_behaves_like "a singular object response" - end + it { is_expected.to have_requested(:post, api_path.merge("/apps/my-app-id/scm_repo_link/manual_deploy")).with(body: body) } end - describe_method "deploy" do - context "success" do - let(:params) { meta.slice(:app_id) } - let(:body) { meta[:deploy][:valid] } - let(:stub_pattern) { "manual-deploy-200" } + describe "review_app" do + subject(:response) { instance.review_app(**arguments) } - it_behaves_like "a singular object response" - end + let(:params) { {app_id: app_id} } + let(:body) { {field: "value"} } + + include_examples "requires authentication" + include_examples "requires some params", :app_id + + it { is_expected.to have_requested(:post, api_path.merge("/apps/my-app-id/scm_repo_link/manual_review_app")).with(body: body) } end - describe_method "destroy" do - context "success" do - let(:params) { meta.slice(:app_id) } - let(:stub_pattern) { "destroy-204" } + describe "update" do + subject(:response) { instance.update(**arguments) } + + let(:params) { {app_id: app_id} } + let(:body) { {field: "value"} } + + include_examples "requires authentication" + include_examples "requires some params", :app_id + + it { is_expected.to have_requested(:patch, api_path.merge("/apps/my-app-id/scm_repo_link")).with(body: {scm_repo_link: body}) } + end + + describe "destroy" do + subject(:response) { instance.destroy(**arguments) } + + let(:params) { {app_id: app_id} } + + include_examples "requires authentication" + include_examples "requires some params", :app_id - it_behaves_like "an empty response" - end + it { is_expected.to have_requested(:delete, api_path.merge("/apps/my-app-id/scm_repo_link")) } end end