From bff1bf026230aac202ba504c11d8ac34778b2c67 Mon Sep 17 00:00:00 2001 From: Kevin Soltysiak Date: Mon, 12 Feb 2024 00:26:51 +0100 Subject: [PATCH] refactor: migrate billing endpoints and specs --- lib/scalingo/billing/profile.rb | 35 +++---------------------- samples/billing/profile/create-400.json | 9 ++----- spec/scalingo/billing/profile_spec.rb | 10 ++++--- 3 files changed, 11 insertions(+), 43 deletions(-) diff --git a/lib/scalingo/billing/profile.rb b/lib/scalingo/billing/profile.rb index 362f3ba..8e21252 100644 --- a/lib/scalingo/billing/profile.rb +++ b/lib/scalingo/billing/profile.rb @@ -2,38 +2,9 @@ module Scalingo class Billing::Profile < API::Endpoint - def show(headers = nil, &block) - data = nil - - connection.get( - "profile", - data, - headers, - &block - ) - end - - def create(payload = {}, headers = nil, &block) - data = {profile: payload} - - connection.post( - "profiles", - data, - headers, - &block - ) - end - - def update(id, payload = {}, headers = nil, &block) - data = {profile: payload} - - connection.put( - "profiles/#{id}", - data, - headers, - &block - ) - end + get :show, "profile" + post :create, "profiles", root_key: :profile + put :update, "profiles/{id}", root_key: :profile alias_method :self, :show end diff --git a/samples/billing/profile/create-400.json b/samples/billing/profile/create-400.json index 5e823fe..f4710a1 100644 --- a/samples/billing/profile/create-400.json +++ b/samples/billing/profile/create-400.json @@ -3,12 +3,7 @@ "method": "post", "request": { "headers": { - "Authorization": "Bearer the-bearer-token", - "Content-Type": "application/json" - }, - "json_body": { - "profile": { - } + "Authorization": "Bearer the-bearer-token" } }, "response": { @@ -24,4 +19,4 @@ "error": "profile is required" } } -} \ No newline at end of file +} diff --git a/spec/scalingo/billing/profile_spec.rb b/spec/scalingo/billing/profile_spec.rb index 1260ea2..dfff233 100644 --- a/spec/scalingo/billing/profile_spec.rb +++ b/spec/scalingo/billing/profile_spec.rb @@ -17,7 +17,7 @@ describe_method "create" do context "success" do - let(:arguments) { meta[:create][:valid] } + let(:body) { meta[:create][:valid] } let(:stub_pattern) { "create-201" } it_behaves_like "a singular object response", 201 @@ -30,7 +30,7 @@ end context "unprocessable" do - let(:arguments) { meta[:create][:invalid] } + let(:body) { meta[:create][:invalid] } let(:stub_pattern) { "create-422" } it_behaves_like "an unprocessable request" @@ -39,14 +39,16 @@ describe_method "update" do context "success" do - let(:arguments) { [meta[:id], meta[:update][:valid]] } + let(:params) { {id: meta[:id]} } + let(:body) { meta[:update][:valid] } let(:stub_pattern) { "update-200" } it_behaves_like "a singular object response" end context "unprocessable" do - let(:arguments) { [meta[:id], meta[:update][:invalid]] } + let(:params) { {id: meta[:id]} } + let(:body) { meta[:update][:invalid] } let(:stub_pattern) { "update-422" } it_behaves_like "an unprocessable request"