|
3 | 3 | require "rails_helper"
|
4 | 4 |
|
5 | 5 | RSpec.describe PaymentRequestMailer, type: :mailer do
|
6 |
| - subject(:payment_request_mailer) { described_class } |
| 6 | + subject(:mailer) { described_class.with(payment_request:).requested } |
7 | 7 |
|
8 | 8 | let(:organization) { create(:organization, document_number_prefix: "ORG-123B") }
|
9 | 9 | let(:first_invoice) { create(:invoice, total_amount_cents: 1000, total_paid_amount_cents: 1, organization:) }
|
|
38 | 38 | end
|
39 | 39 |
|
40 | 40 | specify do
|
41 |
| - mailer = payment_request_mailer.with(payment_request:).requested |
42 |
| - |
43 | 41 | expect(mailer.to).to eq([payment_request.email])
|
44 | 42 | expect(mailer.reply_to).to eq([payment_request.organization.email])
|
| 43 | + expect(mailer.bcc).to be_nil |
45 | 44 | expect(mailer.body.encoded).to include(CGI.escapeHTML(first_invoice.number))
|
46 | 45 | expect(mailer.body.encoded).to include(CGI.escapeHTML(second_invoice.number))
|
47 | 46 | expect(mailer.body.encoded).to include(CGI.escapeHTML(MoneyHelper.format(first_invoice.total_due_amount)))
|
48 | 47 | expect(mailer.body.encoded).to include(CGI.escapeHTML(MoneyHelper.format(second_invoice.total_due_amount)))
|
49 | 48 | end
|
50 | 49 |
|
51 | 50 | it "calls the generate payment url service" do
|
52 |
| - mailer = payment_request_mailer.with(payment_request:).requested |
53 | 51 | parsed_body = Nokogiri::HTML(mailer.body.encoded)
|
54 | 52 |
|
55 | 53 | expect(parsed_body.at_css("a#payment_link")["href"]).to eq(payment_url)
|
|
59 | 57 | .with(payable: payment_request)
|
60 | 58 | end
|
61 | 59 |
|
| 60 | + context "when payment request has dunning campaign attached and there are 2 addresses in bcc_emails" do |
| 61 | + |
| 62 | + let(:dunning_campaign) { create(:dunning_campaign, organization:, bcc_emails:) } |
| 63 | + |
| 64 | + before do |
| 65 | + payment_request.update(dunning_campaign:) |
| 66 | + end |
| 67 | + |
| 68 | + it "includes the BCC email addresses in the mailer" do |
| 69 | + expect(mailer.bcc).to match_array(bcc_emails) |
| 70 | + end |
| 71 | + end |
| 72 | + |
62 | 73 | context "when payment request email is nil" do
|
63 | 74 | before { payment_request.update(email: nil) }
|
64 | 75 |
|
65 | 76 | it "returns a mailer with nil values" do
|
66 |
| - mailer = payment_request_mailer.with(payment_request:).requested |
67 | 77 | expect(mailer.to).to be_nil
|
68 | 78 | end
|
69 | 79 | end
|
|
72 | 82 | before { organization.update(email: nil) }
|
73 | 83 |
|
74 | 84 | it "returns a mailer with nil values" do
|
75 |
| - mailer = payment_request_mailer.with(payment_request:).requested |
76 | 85 | expect(mailer.to).to be_nil
|
77 | 86 | end
|
78 | 87 | end
|
|
85 | 94 | end
|
86 | 95 |
|
87 | 96 | it "does not include the payment link" do
|
88 |
| - mailer = payment_request_mailer.with(payment_request:).requested |
89 | 97 | parsed_body = Nokogiri::HTML(mailer.body.encoded)
|
90 | 98 |
|
91 | 99 | expect(parsed_body.css("a#payment_link")).not_to be_present
|
|
0 commit comments