Validate period for invalid values, refactor optional attribute validator, tests #2763

This commit is contained in:
Martin Lensment 2015-07-16 17:19:16 +03:00
parent 92e25cb61e
commit 7a8c7dd39e
4 changed files with 83 additions and 6 deletions

View file

@ -2243,6 +2243,73 @@ describe 'EPP Domain', epp: true do
Setting.days_to_renew_domain_before_expire = 90
end
it 'renews a domain with no period specified' do
Setting.days_to_renew_domain_before_expire = 0
old_balance = @registrar1.balance
old_activities = @registrar1.cash_account.account_activities.count
exp_date = domain.valid_to
xml = @epp_xml.domain.renew(
name: { value: domain.name },
curExpDate: { value: exp_date.to_date.to_s },
period: nil
)
response = epp_plain_request(xml)
response[:results][0][:msg].should == 'Command completed successfully'
response[:results][0][:result_code].should == '1000'
ex_date = response[:parsed].css('renData exDate').text
name = response[:parsed].css('renData name').text
ex_date.should == "#{(exp_date + 1.year).to_s(:iso8601)}"
name.should == domain.name
domain.reload
domain.valid_to.should be_within(1).of(exp_date + 1.year)
domain.outzone_at.should be_within(1).of(exp_date + 1.year + Setting.expire_warning_period.days)
domain.delete_at.should be_within(1).of(
exp_date + 1.year + Setting.expire_warning_period.days + Setting.redemption_grace_period.days
)
@registrar1.balance.should == old_balance - 15.0
@registrar1.cash_account.account_activities.count.should == old_activities + 1
a = @registrar1.cash_account.account_activities.last
a.description.should == "Renew #{Domain.last.name}"
a.sum.should == -BigDecimal.new('15.0')
a.activity_type = AccountActivity::RENEW
a.log_pricelist_id.should == @pricelist_renew_1_year.id
Setting.days_to_renew_domain_before_expire = 90
end
it 'does not renew domain with invalid period' do
Setting.days_to_renew_domain_before_expire = 0
old_balance = @registrar1.balance
old_activities = @registrar1.cash_account.account_activities.count
exp_date = domain.valid_to
xml = @epp_xml.domain.renew(
name: { value: domain.name },
curExpDate: { value: exp_date.to_date.to_s },
period: { value: '1', attrs: { unit: '' } }
)
response = epp_plain_request(xml, validate_input: false)
response[:results][0][:msg].should == 'Attribute is invalid: unit'
response[:results][0][:result_code].should == '2306'
xml = @epp_xml.domain.renew(
name: { value: domain.name },
curExpDate: { value: exp_date.to_date.to_s },
period: { value: '1', attrs: { unit: 'bla' } }
)
response = epp_plain_request(xml, validate_input: false)
response[:results][0][:msg].should == 'Attribute is invalid: unit'
response[:results][0][:result_code].should == '2306'
Setting.days_to_renew_domain_before_expire = 90
end
it 'renews a domain with 2 year period' do
old_balance = @registrar1.balance
old_activities = @registrar1.cash_account.account_activities.count