diff --git a/test/fixtures/bank_statements.yml b/test/fixtures/bank_statements.yml index 36ed23cf1..327601bf2 100644 --- a/test/fixtures/bank_statements.yml +++ b/test/fixtures/bank_statements.yml @@ -1,3 +1,8 @@ one: bank_code: '1234' - iban: GB33BUKB20201555555555 \ No newline at end of file + iban: GB33BUKB20201555555555 + +two: + bank_code: '4321' + iban: GB82WEST12345698765432 + \ No newline at end of file diff --git a/test/fixtures/bank_transactions.yml b/test/fixtures/bank_transactions.yml index 70b3b6651..3bd41a12b 100644 --- a/test/fixtures/bank_transactions.yml +++ b/test/fixtures/bank_transactions.yml @@ -3,3 +3,10 @@ one: currency: EUR description: Order nr 1 from registrar 1234567 second number 2345678 iban: US75512108001245126199 + +with_statement: + bank_statement: two + sum: 1 + currency: EUR + description: Order nr 1 from registrar 1234567 second number 2345678 + iban: US75512108001245126199 diff --git a/test/integration/admin_area/bank_transactions_test.rb b/test/integration/admin_area/bank_transactions_test.rb new file mode 100644 index 000000000..7825e5f60 --- /dev/null +++ b/test/integration/admin_area/bank_transactions_test.rb @@ -0,0 +1,63 @@ +require 'test_helper' + +class AdminAreaBankTransactionsIntegrationTest < ActionDispatch::IntegrationTest + include Devise::Test::IntegrationHelpers + + setup do + sign_in users(:admin) + @bank_statement = bank_statements(:one) + @bank_transaction = bank_transactions(:with_statement) + end + + def test_new_page_accessible + get new_admin_bank_statement_bank_transaction_path(@bank_statement) + assert_response :success + end + + def test_creates_bank_transaction + params = { + bank_transaction: { + description: 'Payment for invoice', + sum: '50.00', + currency: 'EUR' + } + } + + assert_difference 'BankTransaction.count', +1 do + post admin_bank_statement_bank_transactions_path(@bank_statement), params: params + end + + transaction = BankTransaction.last + assert_redirected_to admin_bank_transaction_path(transaction) + follow_redirect! + assert_response :success + assert_includes flash[:notice], I18n.t('record_created') + end + + def test_bind_invoice_sets_flash_when_invoice_not_found + patch bind_admin_bank_transaction_path(@bank_transaction), params: { invoice_no: 'INVALID123' } + + assert_response :success + assert_equal I18n.t('failed_to_create_record'), flash[:alert] + end + + def test_updates_bank_transaction + new_description = 'Updated description' + + patch admin_bank_transaction_path(@bank_transaction), params: { + bank_transaction: { + description: new_description, + sum: '1,50' + } + } + + assert_redirected_to admin_bank_transaction_path(@bank_transaction) + follow_redirect! + assert_response :success + assert_equal I18n.t('record_updated'), flash[:notice] + + @bank_transaction.reload + assert_equal new_description, @bank_transaction.description + assert_in_delta 1.5, @bank_transaction.sum.to_f, 0.0001 + end +end