Add paid flag to email subject, check receipt date in tests

This commit is contained in:
Alex Sherman 2021-05-28 13:53:14 +05:00
parent 82c048b316
commit 235ef9ba3e
5 changed files with 32 additions and 5 deletions

View file

@ -1,9 +1,10 @@
class InvoiceMailer < ApplicationMailer
def invoice_email(invoice:, recipient:)
def invoice_email(invoice:, recipient:, paid: false)
@invoice = invoice
subject = default_i18n_subject(invoice_number: invoice.number)
subject << I18n.t('invoice.already_paid') if paid
attachments["invoice-#{invoice.number}.pdf"] = invoice.as_pdf
mail(to: recipient, subject: subject)
end
end
end

View file

@ -101,7 +101,8 @@ class Registrar < ApplicationRecord
)
unless payable
InvoiceMailer.invoice_email(invoice: invoice, recipient: billing_email).deliver_now
InvoiceMailer.invoice_email(invoice: invoice, recipient: billing_email, paid: !payable)
.deliver_later(wait: 1.minute)
end
SendEInvoiceJob.perform_later(invoice.id, payable)

View file

@ -470,7 +470,8 @@ en:
price: 'Price'
total: 'Total'
paid_at: 'Paid at'
invoice: 'Invoice'
invoice:
already_paid: " (already paid)"
bank_statements: 'Bank statements'
back_to_bank_statements: 'Back to bank statements'
back_to_bank_statement: 'Back to bank statement'

View file

@ -6,3 +6,5 @@ et:
# Don't forget the nil at the beginning; there's no such thing as a 0th month
month_names: [~, Jaanuar, Veebruar, Märts, Aprill, Mai, Juuni, Juuli, August, September, Oktoober, November, Detsember]
emails: "Meillaadressid"
invoice:
already_paid: " (juba makstud)"

View file

@ -1,6 +1,6 @@
require 'test_helper'
class ProcessPaymentsTaskTest < ActiveSupport::TestCase
class ProcessPaymentsTaskTest < ActiveJob::TestCase
setup do
@payment_amount = payment_amount = 0.1
@payment_currency = payment_currency = 'EUR'
@ -162,6 +162,28 @@ class ProcessPaymentsTaskTest < ActiveSupport::TestCase
assert_equal 0.1, registrar.invoices.last.total
end
def test_topup_creates_invoice_and_send_it_as_paid
registrar = registrars(:bestnames)
@invoice.payment_orders.destroy_all
@invoice.destroy
perform_enqueued_jobs do
run_task
end
invoice = Invoice.last
assert invoice.paid?
assert_not invoice.e_invoice_sent_at.blank?
pdf_source = Invoice::PdfGenerator.new(invoice)
pdf_source.send(:invoice_html).include?('Receipt date')
email= ActionMailer::Base.deliveries.last
assert email.subject.include?('already paid')
assert_equal 0.1, registrar.invoices.last.total
end
def test_output
assert_output "Transactions processed: 1\n" do
run_task