-
Notifications
You must be signed in to change notification settings - Fork 100
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Deliver email when gocardless payment fails
- Loading branch information
Showing
4 changed files
with
75 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 25 additions & 3 deletions
28
spec/jobs/payment_requests/payments/gocardless_create_job_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,44 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'rails_helper' | ||
require "rails_helper" | ||
|
||
RSpec.describe PaymentRequests::Payments::GocardlessCreateJob, type: :job do | ||
let(:payment_request) { create(:payment_request) } | ||
|
||
let(:gocardless_service) { instance_double(PaymentRequests::Payments::GocardlessService) } | ||
let(:service_result) { BaseService::Result.new } | ||
|
||
it 'calls the stripe create service' do | ||
before do | ||
allow(PaymentRequests::Payments::GocardlessService).to receive(:new) | ||
.with(payment_request) | ||
.and_return(gocardless_service) | ||
allow(gocardless_service).to receive(:create) | ||
.and_return(BaseService::Result.new) | ||
.and_return(service_result) | ||
end | ||
|
||
it "calls the stripe create service" do | ||
described_class.perform_now(payment_request) | ||
|
||
expect(PaymentRequests::Payments::GocardlessService).to have_received(:new) | ||
expect(gocardless_service).to have_received(:create) | ||
end | ||
|
||
it "does not send a payment requested email" do | ||
expect { described_class.perform_now(payment_request) } | ||
.not_to have_enqueued_mail(PaymentRequestMailer, :requested) | ||
end | ||
|
||
context "when the payment fails" do | ||
let(:service_result) do | ||
BaseService::Result.new.tap do |result| | ||
result.payable = instance_double(PaymentRequest, payment_failed?: true) | ||
end | ||
end | ||
|
||
it "sends a payment requested email" do | ||
expect { described_class.perform_now(payment_request) } | ||
.to have_enqueued_mail(PaymentRequestMailer, :requested) | ||
.with(params: {payment_request:}, args: []) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters