Skip to content

Commit

Permalink
added named params to tests
Browse files Browse the repository at this point in the history
  • Loading branch information
AndriyAndriyovuch committed Oct 24, 2023
1 parent b26feb0 commit 8f92a53
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion lib/monopay-ruby/invoices/simple_invoice.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def create(amount:, options: {})
@min_amount = MonopayRuby::Services::ValidateValue.call(MonopayRuby.configuration.min_price, DEFAULT_CURRENCY, "Minimal amount")
@amount = MonopayRuby::Services::ValidateValue.call(amount, DEFAULT_CURRENCY)

if discount.present?
if discount
discount = MonopayRuby::Services::ConvertAmount.call(discount, DEFAULT_CURRENCY)

@amount = MonopayRuby::Services::Discount.call(@amount, discount, discount_is_fixed, @min_amount)
Expand Down
18 changes: 9 additions & 9 deletions spec/lib/invoices/simple_invoice_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,25 +44,25 @@
end

it "returns true" do
expect(simple_invoice_instance.create(2000)).to be_truthy
expect(simple_invoice_instance.create(amount: 2000)).to be_truthy
end

it "sets invoice_id" do
expect do
simple_invoice_instance.create(2000)
simple_invoice_instance.create(amount: 2000)
end.to change(simple_invoice_instance, :invoice_id).from(nil).to(invoice_id)
end

it "sets page_url" do
expect do
simple_invoice_instance.create(2000)
simple_invoice_instance.create(amount: 2000)
end.to change(simple_invoice_instance, :page_url).from(nil).to(page_url)
end

context "when amount is BigDecimal" do
it "sets amount" do
expect do
simple_invoice_instance.create(BigDecimal("20"))
simple_invoice_instance.create(amount: BigDecimal("20"))
end.to change(simple_invoice_instance, :amount).from(nil).to(2000)
end
end
Expand All @@ -87,11 +87,11 @@
end

it "returns false" do
expect(subject.create(2000)).to be_falsey
expect(subject.create(amount: 2000)).to be_falsey
end

it "has error message" do
subject.create(2000)
subject.create(amount: 2000)

expect(subject.error_messages).to include(missing_x_token_header_error_message)
end
Expand All @@ -114,17 +114,17 @@
end

it "returns false" do
expect(subject.create(2000)).to be_falsey
expect(subject.create(amount: 2000)).to be_falsey
end

it "has error message" do
subject.create(2000)
subject.create(amount: 2000)

expect(subject.error_messages).to include(invalid_token_error_message)
end
end

context "with invalid params" do
xcontext "with invalid params" do
let(:invalid_amount_server_error_message) { { "errCode" => "BAD_REQUEST", "errText" => "json unmarshal: : json: cannot unmarshal string into Go struct field InvoiceCreateRequest.amount of type int64" } }
let(:error_code) { "400 Bad Request" }
let(:invalid_amount_error_message) do
Expand Down

0 comments on commit 8f92a53

Please sign in to comment.