|
| 1 | +# frozen_string_literal: true |
| 2 | + |
| 3 | +RSpec.describe MonopayRuby::Invoices::AdvancedInvoice do |
| 4 | + describe "#new" do |
| 5 | + let!(:redirect_url) { "https://redirect.example.com" } |
| 6 | + let!(:webhook_url) { "https://webhook.example.com" } |
| 7 | + |
| 8 | + context "with keyword parameters" do |
| 9 | + subject { described_class.new(redirect_url: redirect_url, webhook_url: webhook_url) } |
| 10 | + |
| 11 | + it "initializes with correct redirect_url" do |
| 12 | + expect(subject.redirect_url).to eq(redirect_url) |
| 13 | + end |
| 14 | + |
| 15 | + it "initializes with correct webhook_url" do |
| 16 | + expect(subject.webhook_url).to eq(webhook_url) |
| 17 | + end |
| 18 | + end |
| 19 | + |
| 20 | + context "without keyword parameters" do |
| 21 | + subject { described_class.new(redirect_url, webhook_url) } |
| 22 | + |
| 23 | + it "raises an ArgumentError" do |
| 24 | + expect { subject }.to raise_error(ArgumentError) |
| 25 | + end |
| 26 | + end |
| 27 | + |
| 28 | + context "without parameters" do |
| 29 | + subject { described_class.new } |
| 30 | + |
| 31 | + it { is_expected.to be_a(described_class) } |
| 32 | + end |
| 33 | + end |
| 34 | + |
| 35 | + describe "#create" do |
| 36 | + context "when request is successful" do |
| 37 | + let(:simple_invoice_instance) { described_class.new } |
| 38 | + let(:invoice_id) { "p2_9ZgpZVsl3" } |
| 39 | + let(:page_url) { "https://pay.mbnk.biz/p2_9ZgpZVsl3" } |
| 40 | + let(:basket_order) { { name: "product", qty: 1 } } |
| 41 | + let(:other_params) { { ccy: 9 } } |
| 42 | + let(:response_example) { { "invoiceId": invoice_id, "pageUrl": page_url } } |
| 43 | + |
| 44 | + before do |
| 45 | + allow(RestClient).to receive(:post).and_return(double(body: response_example.to_json)) |
| 46 | + end |
| 47 | + |
| 48 | + it "returns true" do |
| 49 | + expect(simple_invoice_instance.create(2000, basketOrder: basket_order, otherParams: other_params)).to be_truthy |
| 50 | + end |
| 51 | + end |
| 52 | + end |
| 53 | +end |
0 commit comments