mirror of
https://github.com/internetee/registry.git
synced 2025-07-22 18:56:05 +02:00
Test valid invoice sums when created by bank transaction
This commit is contained in:
parent
1a56fcf179
commit
3decec8b02
4 changed files with 25 additions and 5 deletions
|
@ -117,10 +117,10 @@ class Invoice < ApplicationRecord
|
|||
return unless registrar_user
|
||||
|
||||
vat = VatRateCalculator.new(registrar: registrar_user).calculate
|
||||
wo_vat = transaction.sum / (1 + (vat / 100))
|
||||
registrar_user.issue_prepayment_invoice(amount: wo_vat,
|
||||
description: 'Direct top-up via bank transfer',
|
||||
payable: false)
|
||||
wo_vat = (transaction.sum / (1 + (vat / 100)))
|
||||
|
||||
registrar_user.issue_prepayment_invoice(wo_vat, 'Direct top-up via bank transfer',
|
||||
payable: false, total: transaction.sum)
|
||||
end
|
||||
|
||||
private
|
||||
|
|
|
@ -54,7 +54,7 @@ class Registrar < ApplicationRecord
|
|||
end
|
||||
end
|
||||
|
||||
def issue_prepayment_invoice(amount, description = nil, payable: true)
|
||||
def issue_prepayment_invoice(amount, description = nil, payable: true, total: nil)
|
||||
vat_rate = ::Invoice::VatRateCalculator.new(registrar: self).calculate
|
||||
|
||||
invoice = invoices.create!(
|
||||
|
@ -90,6 +90,7 @@ class Registrar < ApplicationRecord
|
|||
buyer_email: email,
|
||||
reference_no: reference_no,
|
||||
vat_rate: vat_rate,
|
||||
total: total,
|
||||
items_attributes: [
|
||||
{
|
||||
description: 'prepayment',
|
||||
|
|
|
@ -109,4 +109,16 @@ class InvoiceTest < ActiveSupport::TestCase
|
|||
seller_zip: nil)
|
||||
assert_equal 'street, city, state', invoice.seller_address
|
||||
end
|
||||
|
||||
def test_assumes_correct_sum_amount_when_created_by_transaction
|
||||
registrar = registrars(:bestnames)
|
||||
|
||||
bank_transaction = bank_transactions(:one).dup
|
||||
bank_transaction.reference_no = registrar.reference_no
|
||||
bank_transaction.sum = 5
|
||||
bank_transaction.save
|
||||
|
||||
invoice = Invoice.create_from_transaction!(bank_transaction)
|
||||
assert_equal 5, invoice.total
|
||||
end
|
||||
end
|
||||
|
|
|
@ -94,6 +94,13 @@ class ProcessPaymentsTaskTest < ActiveSupport::TestCase
|
|||
end
|
||||
end
|
||||
|
||||
def test_topup_creates_invoice_with_total_of_transactioned_amount
|
||||
registrar = registrars(:bestnames)
|
||||
run_task
|
||||
|
||||
assert_equal 0.1, registrar.invoices.last.total
|
||||
end
|
||||
|
||||
def test_output
|
||||
assert_output "Transactions processed: 1\n" do
|
||||
run_task
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue