From 527f65ebfbe0fc2389593ddbdfd28362a3d2965e Mon Sep 17 00:00:00 2001 From: Martin Lensment Date: Fri, 3 Jul 2015 11:03:45 +0300 Subject: [PATCH] Add some tests #2741 --- spec/epp/domain_spec.rb | 8 ++++++++ spec/models/registrar_spec.rb | 16 ++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/spec/epp/domain_spec.rb b/spec/epp/domain_spec.rb index fae65e7f6..c17440800 100644 --- a/spec/epp/domain_spec.rb +++ b/spec/epp/domain_spec.rb @@ -325,15 +325,21 @@ describe 'EPP Domain', epp: true do end it 'creates a domain with period in days' do + old_balance = @registrar1.balance + old_activities = @registrar1.cash_account.account_activities.count xml = domain_create_xml(period_value: 365, period_unit: 'd') response = epp_plain_request(xml) response[:msg].should == 'Command completed successfully' response[:result_code].should == '1000' Domain.first.valid_to.should be_within(60).of(1.year.since) + @registrar1.balance.should be < old_balance + @registrar1.cash_account.account_activities.count.should == old_activities + 1 end it 'does not create a domain with invalid period' do + old_balance = @registrar1.balance + old_activities = @registrar1.cash_account.account_activities.count xml = domain_create_xml({ period: { value: '367', attrs: { unit: 'd' } } }) @@ -342,6 +348,8 @@ describe 'EPP Domain', epp: true do response[:results][0][:result_code].should == '2306' response[:results][0][:msg].should == 'Period must add up to 1, 2 or 3 years [period]' response[:results][0][:value].should == '367' + @registrar1.balance.should == old_balance + @registrar1.cash_account.account_activities.count.should == old_activities end it 'creates a domain with multiple dnskeys' do diff --git a/spec/models/registrar_spec.rb b/spec/models/registrar_spec.rb index c169a5b73..0cf04b2d2 100644 --- a/spec/models/registrar_spec.rb +++ b/spec/models/registrar_spec.rb @@ -144,5 +144,21 @@ describe Registrar do it 'should not have priv contacts' do @registrar.priv_contacts.size.should == 0 end + + it 'should credit and debit registrar cash account' do + @registrar.credit!(13.32, 'Add money') + @registrar.balance.should == BigDecimal.new('13.32') + @registrar.cash_account.account_activities.count.should == 1 + a = @registrar.cash_account.account_activities.last + a.description.should == 'Add money' + a.sum.should == BigDecimal.new('13.32') + + @registrar.debit!(10.31, 'Remove money') + @registrar.balance.should == BigDecimal.new('3.01') + @registrar.cash_account.account_activities.count.should == 2 + a = @registrar.cash_account.account_activities.last + a.description.should == 'Remove money' + a.sum.should == -BigDecimal.new('10.31') + end end end