From 8f3f5f7302f83099edb8940287b0a339f77ffdd9 Mon Sep 17 00:00:00 2001 From: Oleg Hasjanov Date: Tue, 20 Apr 2021 14:10:58 +0300 Subject: [PATCH] added test for transaction with binded invoice which already paid --- test/tasks/invoices/process_payments_test.rb | 25 ++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/test/tasks/invoices/process_payments_test.rb b/test/tasks/invoices/process_payments_test.rb index eeaf411cc..3f0cd49e6 100644 --- a/test/tasks/invoices/process_payments_test.rb +++ b/test/tasks/invoices/process_payments_test.rb @@ -13,6 +13,8 @@ class ProcessPaymentsTaskTest < ActiveSupport::TestCase total: payment_amount, currency: @payment_currency, reference_no: @payment_reference_number) + @account_activity = account_activities(:one) + Setting.registry_iban = beneficiary_iban Lhv::ConnectApi.class_eval do @@ -29,6 +31,29 @@ class ProcessPaymentsTaskTest < ActiveSupport::TestCase end end + def test_cannot_create_new_invoice_if_transaction_binded_to_paid_invoice + @invoice.update(total: 10) + assert_not @invoice.paid? + + @account_activity.update(activity_type: "add_credit", bank_transaction: nil) + @invoice.update(account_activity: @account_activity, total: 10) + assert @invoice.paid? + + transaction = BankTransaction.new + transaction.description = "Invoice no. #{@invoice.number}" + transaction.sum = 10 + transaction.reference_no = @invoice.reference_no + transaction.save + assert transaction.valid? + + assert_no_difference 'AccountActivity.count' do + assert_no_difference 'Invoice.count' do + Invoice.create_from_transaction!(transaction) unless transaction.autobindable? + transaction.autobind_invoice + end + end + end + def test_doubles_are_valid assert Lhv::ConnectApi.method_defined?(:credit_debit_notification_messages) assert Lhv::ConnectApi::Messages::CreditDebitNotification.method_defined?(:bank_account_iban)