From 6166c084d3f9da0a5fce24a469c240bda793757c Mon Sep 17 00:00:00 2001 From: mmeest Date: Thu, 19 Jun 2025 12:28:28 +0300 Subject: [PATCH] added new tests for LhvConnectTransactionsController --- .../lhv_connect_transactions_test.rb | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/test/integration/eis_billing/lhv_connect_transactions_test.rb b/test/integration/eis_billing/lhv_connect_transactions_test.rb index 6e89808c8..37769a56f 100644 --- a/test/integration/eis_billing/lhv_connect_transactions_test.rb +++ b/test/integration/eis_billing/lhv_connect_transactions_test.rb @@ -38,4 +38,34 @@ class LhvConnectTransactionsIntegrationTest < ApplicationIntegrationTest end end end + + def test_creates_invoice_and_sends_paid_status + # Use an invoice that already has a payment reference that matches the transaction + paid_invoice = invoices(:one) + spy = Spy.on(EisBilling::SendInvoiceStatus, :send_info).and_return(true) + + transaction = { + 'amount' => paid_invoice.total, + 'currency' => 'EUR', + 'date' => Time.zone.today, + 'payment_reference_number' => paid_invoice.reference_no, + 'payment_description' => 'Makstud arve' + } + + post eis_billing_lhv_connect_transactions_path, + params:{ '_json' => [transaction] }, + headers: { 'HTTP_COOKIE' => 'session=api_bestnames' } + + assert_response :ok + assert_equal 'RECEIVED', JSON.parse(response.body)['message'] + assert spy.calls.length >= 1, "Expected at least 1 call to send_info, got #{spy.calls.length}" + + # Check that at least one of the calls has the correct arguments + # Since both invoices have the same reference_no, the system might use a different invoice + # So we check that send_info is called with status 'paid' and any valid invoice number + call_with_correct_args = spy.calls.any? do |call| + call.args[0][:status] == 'paid' && call.args[0][:invoice_number].present? + end + assert call_with_correct_args, "Expected send_info to be called with status: 'paid' and a valid invoice_number" + end end