Skip to content

Commit

Permalink
refactor: migrate billing endpoints and specs
Browse files Browse the repository at this point in the history
  • Loading branch information
ksol committed Feb 12, 2024
1 parent 2b2998b commit bff1bf0
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 43 deletions.
35 changes: 3 additions & 32 deletions lib/scalingo/billing/profile.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 2 additions & 7 deletions samples/billing/profile/create-400.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand All @@ -24,4 +19,4 @@
"error": "profile is required"
}
}
}
}
10 changes: 6 additions & 4 deletions spec/scalingo/billing/profile_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"
Expand All @@ -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"
Expand Down

0 comments on commit bff1bf0

Please sign in to comment.