diff --git a/spec/scalingo/regional_database/backups_spec.rb b/spec/scalingo/regional_database/backups_spec.rb index dd48607..e6f0b6c 100644 --- a/spec/scalingo/regional_database/backups_spec.rb +++ b/spec/scalingo/regional_database/backups_spec.rb @@ -1,58 +1,43 @@ require "spec_helper" -RSpec.describe Scalingo::RegionalDatabase::Backups do +RSpec.describe Scalingo::RegionalDatabase::Backups, type: :endpoint do + let(:addon_id) { "the-addon-id" } + before do - scalingo.add_database_token(meta[:addon_id], "the-bearer-token") + scalingo_client.add_database_token(addon_id, "the-bearer-token") end - describe_method "create" do - context "success" do - let(:params) { meta.slice(:addon_id) } - let(:stub_pattern) { "create-201" } + describe "for" do + subject(:response) { instance.for(**arguments) } - it_behaves_like "a singular object response", 201 - end + let(:params) { {addon_id: addon_id} } - context "failure" do - let(:params) { meta.slice(:addon_id) } - let(:stub_pattern) { "create-400" } + include_examples "requires authentication" + include_examples "requires some params", :addon_id - it_behaves_like "a client error" - end + it { is_expected.to have_requested(:get, api_path.merge("/databases/the-addon-id/backups")) } end - describe_method "for" do - context "success" do - let(:params) { meta.slice(:addon_id) } - let(:stub_pattern) { "for-200" } - let(:expected_count) { 3 } + describe "create" do + subject(:response) { instance.create(**arguments) } - it_behaves_like "a collection response" - it_behaves_like "a non-paginated collection" - end + let(:params) { {addon_id: addon_id} } + let(:body) { {field: "value"} } - context "failure" do - let(:params) { meta.slice(:addon_id) } - let(:stub_pattern) { "for-400" } + include_examples "requires authentication" + include_examples "requires some params", :addon_id - it_behaves_like "a client error" - end + it { is_expected.to have_requested(:post, api_path.merge("/databases/the-addon-id/backups")) } end - describe_method "archive" do - context "success" do - let(:params) { meta.slice(:addon_id, :id) } - let(:stub_pattern) { "archive-200" } - let(:expected_keys) { %i[download_url] } + describe "archive" do + subject(:response) { instance.archive(**arguments) } - it_behaves_like "a singular object response" - end + let(:params) { {addon_id: addon_id, id: "backup-id"} } - context "failure" do - let(:params) { meta.slice(:addon_id, :id) } - let(:stub_pattern) { "archive-400" } + include_examples "requires authentication" + include_examples "requires some params", :addon_id, :id - it_behaves_like "a client error" - end + it { is_expected.to have_requested(:get, api_path.merge("/databases/the-addon-id/backups/backup-id/archive")) } end end diff --git a/spec/scalingo/regional_database/databases_spec.rb b/spec/scalingo/regional_database/databases_spec.rb index 21a0e34..283d35b 100644 --- a/spec/scalingo/regional_database/databases_spec.rb +++ b/spec/scalingo/regional_database/databases_spec.rb @@ -1,39 +1,31 @@ require "spec_helper" -RSpec.describe Scalingo::RegionalDatabase::Databases do +RSpec.describe Scalingo::RegionalDatabase::Databases, type: :endpoint do + let(:id) { "database-id" } + before do - scalingo.add_database_token(meta[:id], "the-bearer-token") + scalingo_client.add_database_token(id, "the-bearer-token") 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: id} } - context "failure" do - let(:params) { meta.slice(:id) } - let(:stub_pattern) { "find-400" } + include_examples "requires authentication" + include_examples "requires some params", :id - it_behaves_like "a client error" - end + it { is_expected.to have_requested(:get, api_path.merge("/databases/database-id")) } end - describe_method "upgrade" do - context "success" do - let(:params) { meta.slice(:id) } - let(:stub_pattern) { "upgrade-202" } + describe "upgrade" do + subject(:response) { instance.upgrade(**arguments) } - it_behaves_like "a singular object response", 202 - end + let(:params) { {id: id} } - context "failure" do - let(:params) { meta.slice(:id) } - let(:stub_pattern) { "upgrade-400" } + include_examples "requires authentication" + include_examples "requires some params", :id - it_behaves_like "a client error" - end + it { is_expected.to have_requested(:post, api_path.merge("/databases/database-id/upgrade")) } end end