add spec to subscription confirm job

This commit is contained in:
Andy Brett
2020-12-15 12:24:38 -08:00
parent 484576d1ac
commit 934f4f278e

View File

@@ -134,6 +134,48 @@ describe SubscriptionConfirmJob do
expect(job).to receive(:record_order)
end
context "when Stripe payments need to be processed" do
let(:charge_response_mock) do
{ status: 200, body: JSON.generate(id: "ch_1234", object: "charge", amount: 2000) }
end
before do
allow(order).to receive(:payment_required?) { true }
expect(job).to receive(:setup_payment!) { true }
stub_request(:post, "https://api.stripe.com/v1/charges")
.with(body: /amount/)
.to_return(charge_response_mock)
end
context "Stripe SCA" do
let(:stripe_sca_payment_method) { create(:stripe_sca_payment_method) }
let(:stripe_sca_payment) { create(:payment, amount: 10, payment_method: stripe_sca_payment_method) }
before do
allow(order).to receive(:pending_payments) { [stripe_sca_payment] }
expect(stripe_sca_payment_method).to receive(:charge_offline)
end
it "runs the charges in offline mode" do
job.send(:confirm_order!, order)
end
end
context "Stripe Connect" do
let(:stripe_connect_payment_method) { create(:stripe_connect_payment_method) }
let(:stripe_connect_payment) { create(:payment, amount: 10, payment_method: stripe_connect_payment_method) }
before do
allow(order).to receive(:pending_payments) { [stripe_connect_payment] }
expect(stripe_connect_payment_method).to receive(:charge_offline)
end
it "runs the charges in offline mode" do
job.send(:confirm_order!, order)
end
end
end
context "when payments need to be processed" do
let(:payment_method) { create(:payment_method) }
let(:payment) { create(:payment, amount: 10) }