Skip to content

Commit

Permalink
specs: rewrite billing specs
Browse files Browse the repository at this point in the history
  • Loading branch information
ksol committed Feb 17, 2024
1 parent 3d84da5 commit aa199d4
Showing 1 changed file with 22 additions and 38 deletions.
60 changes: 22 additions & 38 deletions spec/scalingo/billing/profile_spec.rb
Original file line number Diff line number Diff line change
@@ -1,57 +1,41 @@
require "spec_helper"

RSpec.describe Scalingo::Billing::Profile do
describe_method "show" do
context "existing" do
let(:stub_pattern) { "show-200" }
RSpec.describe Scalingo::Billing::Profile, type: :endpoint do
describe "create" do
subject(:response) { instance.create(**arguments) }

it_behaves_like "a singular object response"
end
let(:body) { {field: "value"} }

context "not yet created" do
let(:stub_pattern) { "show-404" }
include_examples "requires authentication"

it_behaves_like "a not found response"
end
it { is_expected.to have_requested(:post, api_path.merge("/profiles")).with(body: {profile: body}) }
end

describe_method "create" do
context "success" do
let(:body) { meta[:create][:valid] }
let(:stub_pattern) { "create-201" }
describe "show" do
subject(:response) { instance.show(**arguments) }

it_behaves_like "a singular object response", 201
end
include_examples "requires authentication"

context "already existing" do
let(:stub_pattern) { "create-400" }
it { is_expected.to have_requested(:get, api_path.merge("/profile")) }
end

it_behaves_like "a client error"
end
describe "self" do
subject(:response) { instance.self(**arguments) }

context "unprocessable" do
let(:body) { meta[:create][:invalid] }
let(:stub_pattern) { "create-422" }
include_examples "requires authentication"

it_behaves_like "an unprocessable request"
end
it { is_expected.to have_requested(:get, api_path.merge("/profile")) }
end

describe_method "update" do
context "success" do
let(:params) { {id: meta[: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) { {id: "profile-id"} }
let(:body) { {field: "value"} }

context "unprocessable" do
let(:params) { {id: meta[:id]} }
let(:body) { meta[:update][:invalid] }
let(:stub_pattern) { "update-422" }
include_examples "requires authentication"
include_examples "requires some params", :id

it_behaves_like "an unprocessable request"
end
it { is_expected.to have_requested(:put, api_path.merge("/profiles/profile-id")).with(body: {profile: body}) }
end
end

0 comments on commit aa199d4

Please sign in to comment.