mirror of
https://github.com/internetee/registry.git
synced 2025-05-28 16:39:55 +02:00
Add bank transaction spec
This commit is contained in:
parent
f514e50628
commit
f1962b2f64
1 changed files with 71 additions and 0 deletions
71
spec/models/bank_transaction_spec.rb
Normal file
71
spec/models/bank_transaction_spec.rb
Normal file
|
@ -0,0 +1,71 @@
|
|||
require 'rails_helper'
|
||||
|
||||
describe BankTransaction do
|
||||
it { should belong_to(:bank_statement) }
|
||||
it { should have_one(:account_activity) }
|
||||
|
||||
context 'with invalid attribute' do
|
||||
before :all do
|
||||
@bank_transaction = BankTransaction.new
|
||||
end
|
||||
|
||||
it 'should not be valid' do
|
||||
@bank_transaction.valid?
|
||||
@bank_transaction.errors.full_messages.should match_array([
|
||||
])
|
||||
end
|
||||
|
||||
it 'should not have any versions' do
|
||||
@bank_transaction.versions.should == []
|
||||
end
|
||||
end
|
||||
|
||||
context 'with valid attributes' do
|
||||
before :all do
|
||||
@bank_transaction = Fabricate(:bank_transaction)
|
||||
Fabricate(:eis)
|
||||
end
|
||||
|
||||
it 'should be valid' do
|
||||
@bank_transaction.valid?
|
||||
@bank_transaction.errors.full_messages.should match_array([])
|
||||
end
|
||||
|
||||
it 'should be valid twice' do
|
||||
@bank_transaction = Fabricate(:bank_statement)
|
||||
@bank_transaction.valid?
|
||||
@bank_transaction.errors.full_messages.should match_array([])
|
||||
end
|
||||
|
||||
it 'should bind transaction with invoice manually' do
|
||||
r = Fabricate(:registrar_with_no_account_activities, reference_no: 'RF7086666663')
|
||||
invoice = r.issue_prepayment_invoice(200, 'add some money')
|
||||
|
||||
bt = Fabricate(:bank_transaction, { sum: 240 })
|
||||
bt.bind_invoice(invoice.id)
|
||||
|
||||
invoice.receipt_date.should_not be_blank
|
||||
r.cash_account.balance.should == 240.0
|
||||
end
|
||||
|
||||
it 'should not bind transaction with mismatching sums' do
|
||||
r = Fabricate(:registrar_with_no_account_activities, reference_no: 'RF7086666663')
|
||||
invoice = r.issue_prepayment_invoice(200, 'add some money')
|
||||
|
||||
bt = Fabricate(:bank_transaction, { sum: 10 })
|
||||
bt.bind_invoice(invoice.id)
|
||||
|
||||
bt.errors.full_messages.should match_array(["Invoice and transaction sums do not match"])
|
||||
end
|
||||
|
||||
it 'should have one version' do
|
||||
with_versioning do
|
||||
@bank_transaction.versions.should == []
|
||||
@bank_transaction.bank_reference = '123'
|
||||
@bank_transaction.save
|
||||
@bank_transaction.errors.full_messages.should match_array([])
|
||||
@bank_transaction.versions.size.should == 1
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue