mirror of
https://github.com/internetee/registry.git
synced 2025-05-18 18:29:40 +02:00
parent
39d7c6ad1d
commit
ad0220088a
30 changed files with 697 additions and 59 deletions
5
spec/factories/admin_domain_contact.rb
Normal file
5
spec/factories/admin_domain_contact.rb
Normal file
|
@ -0,0 +1,5 @@
|
|||
FactoryGirl.define do
|
||||
factory :admin_domain_contact, parent: :domain_contact, class: AdminDomainContact do
|
||||
|
||||
end
|
||||
end
|
16
spec/factories/contact.rb
Normal file
16
spec/factories/contact.rb
Normal file
|
@ -0,0 +1,16 @@
|
|||
FactoryGirl.define do
|
||||
factory :contact do
|
||||
name 'test'
|
||||
sequence(:code) { |n| "test#{n}" }
|
||||
phone '+123.456789'
|
||||
email 'test@test.com'
|
||||
street 'test'
|
||||
city 'test'
|
||||
zip 12345
|
||||
country_code 'EE'
|
||||
ident '37605030299'
|
||||
ident_type 'priv'
|
||||
ident_country_code 'EE'
|
||||
registrar
|
||||
end
|
||||
end
|
15
spec/factories/dnskey.rb
Normal file
15
spec/factories/dnskey.rb
Normal file
|
@ -0,0 +1,15 @@
|
|||
FactoryGirl.define do
|
||||
factory :dnskey do
|
||||
alg Dnskey::ALGORITHMS.first
|
||||
flags Dnskey::FLAGS.first
|
||||
protocol Dnskey::PROTOCOLS.first
|
||||
ds_digest_type 2
|
||||
domain
|
||||
public_key 'AwEAAaOf5+lz3ftsL+0CCvfJbhUF/NVsNh8BKo61oYs5fXVbuWDiH872 '\
|
||||
'LC8uKDO92TJy7Q4TF9XMAKMMlf1GMAxlRspD749SOCTN00sqfWx1OMTu '\
|
||||
'a28L1PerwHq7665oDJDKqR71btcGqyLKhe2QDvCdA0mENimF1NudX1BJ '\
|
||||
'DDFi6oOZ0xE/0CuveB64I3ree7nCrwLwNs56kXC4LYoX3XdkOMKiJLL/ '\
|
||||
'MAhcxXa60CdZLoRtTEW3z8/oBq4hEAYMCNclpbd6y/exScwBxFTdUfFk '\
|
||||
'KsdNcmvai1lyk9vna0WQrtpYpHKMXvY9LFHaJxCOLR4umfeQ42RuTd82 lqfU6ClMeXs='
|
||||
end
|
||||
end
|
15
spec/factories/domain.rb
Normal file
15
spec/factories/domain.rb
Normal file
|
@ -0,0 +1,15 @@
|
|||
FactoryGirl.define do
|
||||
factory :domain do
|
||||
sequence(:name) { |n| "test#{n}.com" }
|
||||
period 1
|
||||
period_unit 'y' # Year
|
||||
registrar
|
||||
registrant
|
||||
|
||||
after :build do |domain|
|
||||
domain.nameservers << FactoryGirl.build_pair(:nameserver)
|
||||
domain.admin_domain_contacts << FactoryGirl.build(:admin_domain_contact)
|
||||
domain.tech_domain_contacts << FactoryGirl.build(:tech_domain_contact)
|
||||
end
|
||||
end
|
||||
end
|
5
spec/factories/domain_contact.rb
Normal file
5
spec/factories/domain_contact.rb
Normal file
|
@ -0,0 +1,5 @@
|
|||
FactoryGirl.define do
|
||||
factory :domain_contact do
|
||||
contact
|
||||
end
|
||||
end
|
6
spec/factories/nameserver.rb
Normal file
6
spec/factories/nameserver.rb
Normal file
|
@ -0,0 +1,6 @@
|
|||
FactoryGirl.define do
|
||||
factory :nameserver do
|
||||
sequence(:hostname) { |n| "ns.test#{n}.ee" }
|
||||
ipv4 '192.168.1.1'
|
||||
end
|
||||
end
|
5
spec/factories/registrant.rb
Normal file
5
spec/factories/registrant.rb
Normal file
|
@ -0,0 +1,5 @@
|
|||
FactoryGirl.define do
|
||||
factory :registrant, parent: :contact, class: Registrant do
|
||||
name 'test'
|
||||
end
|
||||
end
|
13
spec/factories/registrar.rb
Normal file
13
spec/factories/registrar.rb
Normal file
|
@ -0,0 +1,13 @@
|
|||
FactoryGirl.define do
|
||||
factory :registrar do
|
||||
sequence(:name) { |n| "test#{n}" }
|
||||
sequence(:code) { |n| "test#{n}" }
|
||||
sequence(:reg_no) { |n| "test#{n}" }
|
||||
street 'test'
|
||||
city 'test'
|
||||
state 'test'
|
||||
zip 'test'
|
||||
email 'test@test.com'
|
||||
country_code 'EE'
|
||||
end
|
||||
end
|
5
spec/factories/tech_domain_contact.rb
Normal file
5
spec/factories/tech_domain_contact.rb
Normal file
|
@ -0,0 +1,5 @@
|
|||
FactoryGirl.define do
|
||||
factory :tech_domain_contact, parent: :domain_contact, class: TechDomainContact do
|
||||
|
||||
end
|
||||
end
|
40
spec/jobs/domain_expiration_email_job_spec.rb
Normal file
40
spec/jobs/domain_expiration_email_job_spec.rb
Normal file
|
@ -0,0 +1,40 @@
|
|||
require 'rails_helper'
|
||||
|
||||
RSpec.describe DomainExpirationEmailJob do
|
||||
it 'queues the job' do
|
||||
expect { described_class.perform_later }.to have_enqueued_job(described_class)
|
||||
end
|
||||
|
||||
describe '#perform' do
|
||||
let(:domain) { instance_double(Domain) }
|
||||
|
||||
before :example do
|
||||
expect(Domain).to receive(:find).and_return(domain)
|
||||
end
|
||||
|
||||
context 'when domain is expired' do
|
||||
let(:message) { instance_double(ActionMailer::MessageDelivery) }
|
||||
|
||||
before :example do
|
||||
allow(domain).to receive(:registered?).and_return(false)
|
||||
end
|
||||
|
||||
it 'sends email notification' do
|
||||
expect(DomainMailer).to receive(:expiration).with(domain: domain).and_return(message)
|
||||
expect(message).to receive(:deliver!)
|
||||
described_class.perform_now(domain_id: 1)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when domain is registered' do
|
||||
before :example do
|
||||
allow(domain).to receive(:registered?).and_return(true)
|
||||
end
|
||||
|
||||
it 'does not send email notification' do
|
||||
expect(DomainMailer).to_not receive(:expiration)
|
||||
described_class.perform_now(domain_id: 1)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
38
spec/mailers/domain_mailer_spec.rb
Normal file
38
spec/mailers/domain_mailer_spec.rb
Normal file
|
@ -0,0 +1,38 @@
|
|||
require 'rails_helper'
|
||||
|
||||
RSpec.describe DomainMailer do
|
||||
describe '#expiration' do
|
||||
let(:domain) { instance_spy(Domain,
|
||||
name: 'test.com',
|
||||
registrant_email: 'registrant@test.com',
|
||||
admin_contact_emails: ['admin.contact.email@test.com']
|
||||
) }
|
||||
let(:domain_presenter) { instance_spy(DomainPresenter) }
|
||||
let(:registrar_presenter) { instance_spy(RegistrarPresenter) }
|
||||
subject(:message) { described_class.expiration(domain: domain) }
|
||||
|
||||
before :example do
|
||||
expect(DomainPresenter).to receive(:new).and_return(domain_presenter)
|
||||
expect(RegistrarPresenter).to receive(:new).and_return(registrar_presenter)
|
||||
end
|
||||
|
||||
it 'has valid sender' do
|
||||
message.deliver!
|
||||
expect(message.from).to eq(['noreply@internet.ee'])
|
||||
end
|
||||
|
||||
it 'has registrant and administrative contacts as recipient' do
|
||||
message.deliver!
|
||||
expect(message.to).to match_array(['registrant@test.com', 'admin.contact.email@test.com'])
|
||||
end
|
||||
|
||||
it 'has valid subject' do
|
||||
message.deliver!
|
||||
expect(message.subject).to eq('The test.com domain has expired')
|
||||
end
|
||||
|
||||
it 'sends message' do
|
||||
expect { message.deliver! }.to change { ActionMailer::Base.deliveries.count }.by(1)
|
||||
end
|
||||
end
|
||||
end
|
57
spec/models/concerns/domain/expirable_spec.rb
Normal file
57
spec/models/concerns/domain/expirable_spec.rb
Normal file
|
@ -0,0 +1,57 @@
|
|||
require 'rails_helper'
|
||||
|
||||
RSpec.describe Domain, db: false do
|
||||
it { is_expected.to alias_attribute(:expire_time, :valid_to) }
|
||||
|
||||
describe '::expired', db: true do
|
||||
before :example do
|
||||
travel_to Time.zone.parse('05.07.2010 00:00')
|
||||
|
||||
FactoryGirl.create(:domain, id: 1, expire_time: Time.zone.parse('04.07.2010 23:59'))
|
||||
FactoryGirl.create(:domain, id: 2, expire_time: Time.zone.parse('05.07.2010 00:00'))
|
||||
FactoryGirl.create(:domain, id: 3, expire_time: Time.zone.parse('05.07.2010 00:01'))
|
||||
end
|
||||
|
||||
it 'returns expired domains' do
|
||||
expect(described_class.expired.ids).to eq([1, 2])
|
||||
end
|
||||
end
|
||||
|
||||
describe '#registered?' do
|
||||
before :example do
|
||||
travel_to Time.zone.parse('05.07.2010 00:00')
|
||||
end
|
||||
|
||||
context 'when :valid_to is in the future' do
|
||||
let(:domain) { described_class.new(expire_time: Time.zone.parse('06.07.2010 00:01')) }
|
||||
|
||||
specify { expect(domain).to be_registered }
|
||||
end
|
||||
|
||||
context 'when :valid_to is the same as current time' do
|
||||
let(:domain) { described_class.new(expire_time: Time.zone.parse('05.07.2010 00:00')) }
|
||||
|
||||
specify { expect(domain).to_not be_registered }
|
||||
end
|
||||
|
||||
context 'when :valid_to is in the past' do
|
||||
let(:domain) { described_class.new(expire_time: Time.zone.parse('04.07.2010 23:59')) }
|
||||
|
||||
specify { expect(domain).to_not be_registered }
|
||||
end
|
||||
end
|
||||
|
||||
describe '#expired?' do
|
||||
context 'when :statuses contains expired status' do
|
||||
let(:domain) { described_class.new(statuses: [DomainStatus::EXPIRED]) }
|
||||
|
||||
specify { expect(domain).to be_expired }
|
||||
end
|
||||
|
||||
context 'when :statuses does not contain expired status' do
|
||||
let(:domain) { described_class.new(statuses: [DomainStatus::CLIENT_HOLD]) }
|
||||
|
||||
specify { expect(domain).to_not be_expired }
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,28 +1,8 @@
|
|||
require 'rails_helper'
|
||||
|
||||
describe Contact do
|
||||
RSpec.describe Contact do
|
||||
before :example do
|
||||
Setting.ds_algorithm = 2
|
||||
Setting.ds_data_allowed = true
|
||||
Setting.ds_data_with_key_allowed = true
|
||||
Setting.key_data_allowed = true
|
||||
|
||||
Setting.dnskeys_min_count = 0
|
||||
Setting.dnskeys_max_count = 9
|
||||
Setting.ns_min_count = 2
|
||||
Setting.ns_max_count = 11
|
||||
|
||||
Setting.transfer_wait_time = 0
|
||||
|
||||
Setting.admin_contacts_min_count = 1
|
||||
Setting.admin_contacts_max_count = 10
|
||||
Setting.tech_contacts_min_count = 0
|
||||
Setting.tech_contacts_max_count = 10
|
||||
|
||||
Setting.client_side_status_editing_enabled = true
|
||||
|
||||
Fabricate(:zonefile_setting, origin: 'ee')
|
||||
@api_user = Fabricate(:api_user)
|
||||
end
|
||||
|
||||
context 'about class' do
|
||||
|
|
|
@ -928,29 +928,4 @@ RSpec.describe Domain, db: false do
|
|||
expect(domain.nameserver_hostnames).to eq('hostnames')
|
||||
end
|
||||
end
|
||||
|
||||
describe '#registered?' do
|
||||
before :example do
|
||||
travel_to Time.zone.parse('05.07.2010 00:00:01')
|
||||
end
|
||||
|
||||
context 'when :valid_to is in the future' do
|
||||
let(:domain) { described_class.new(valid_to: Time.zone.parse('06.07.2010')) }
|
||||
|
||||
specify { expect(domain).to be_registered }
|
||||
end
|
||||
|
||||
context 'when :valid_to is the same as current time' do
|
||||
let(:domain) { described_class.new(valid_to: Time.zone.parse('05.07.2010 00:00:01')) }
|
||||
|
||||
|
||||
specify { expect(domain).to be_registered }
|
||||
end
|
||||
|
||||
context 'when :valid_to is in the past' do
|
||||
let(:domain) { described_class.new(valid_to: Time.zone.parse('04.07.2010 23:59:59')) }
|
||||
|
||||
specify { expect(domain).to_not be_registered }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
96
spec/presenters/domain_presenter_spec.rb
Normal file
96
spec/presenters/domain_presenter_spec.rb
Normal file
|
@ -0,0 +1,96 @@
|
|||
require 'rails_helper'
|
||||
|
||||
RSpec.describe DomainPresenter do
|
||||
let(:presenter) { described_class.new(domain: domain, view: view) }
|
||||
|
||||
describe '#on_hold_date' do
|
||||
subject(:on_hold_date) { presenter.on_hold_date }
|
||||
|
||||
context 'when present' do
|
||||
let(:domain) { instance_double(Domain, on_hold_time: '05.07.2010') }
|
||||
|
||||
it 'returns localized date' do
|
||||
expect(view).to receive(:l).with('05.07.2010', format: :date).and_return('on hold date')
|
||||
expect(on_hold_date).to eq('on hold date')
|
||||
end
|
||||
end
|
||||
|
||||
context 'when absent' do
|
||||
let(:domain) { instance_double(Domain, on_hold_time: nil) }
|
||||
|
||||
specify { expect(on_hold_date).to be_nil }
|
||||
end
|
||||
end
|
||||
|
||||
describe '#delete_date' do
|
||||
subject(:delete_date) { presenter.delete_date }
|
||||
|
||||
context 'when present' do
|
||||
let(:domain) { instance_double(Domain, delete_time: '05.07.2010') }
|
||||
|
||||
it 'returns localized date' do
|
||||
expect(view).to receive(:l).with('05.07.2010', format: :date).and_return('delete date')
|
||||
expect(delete_date).to eq('delete date')
|
||||
end
|
||||
end
|
||||
|
||||
context 'when absent' do
|
||||
let(:domain) { instance_double(Domain, delete_time: nil) }
|
||||
|
||||
specify { expect(delete_date).to be_nil }
|
||||
end
|
||||
end
|
||||
|
||||
describe '#admin_contact_names' do
|
||||
let(:domain) { instance_double(Domain) }
|
||||
|
||||
before :example do
|
||||
expect(domain).to receive(:admin_contact_names).and_return(%w(test1 test2 test3))
|
||||
end
|
||||
|
||||
it 'returns admin contact names' do
|
||||
expect(presenter.admin_contact_names).to eq('test1, test2, test3')
|
||||
end
|
||||
end
|
||||
|
||||
describe '#tech_contact_names' do
|
||||
let(:domain) { instance_double(Domain) }
|
||||
|
||||
before :example do
|
||||
expect(domain).to receive(:tech_contact_names).and_return(%w(test1 test2 test3))
|
||||
end
|
||||
|
||||
it 'returns technical contact names' do
|
||||
expect(presenter.tech_contact_names).to eq('test1, test2, test3')
|
||||
end
|
||||
end
|
||||
|
||||
describe '#nameserver_names' do
|
||||
let(:domain) { instance_double(Domain) }
|
||||
|
||||
before :example do
|
||||
expect(domain).to receive(:nameserver_hostnames).and_return(%w(test1 test2 test3))
|
||||
end
|
||||
|
||||
it 'returns nameserver names' do
|
||||
expect(presenter.nameserver_names).to eq('test1, test2, test3')
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
domain_delegatable_attributes = %i(
|
||||
name
|
||||
registrant_name
|
||||
)
|
||||
|
||||
domain_delegatable_attributes.each do |attribute_name|
|
||||
describe "##{attribute_name}" do
|
||||
let(:domain) { instance_spy(Domain) }
|
||||
|
||||
it 'delegates to domain' do
|
||||
presenter.send(attribute_name)
|
||||
expect(domain).to have_received(attribute_name)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
34
spec/presenters/registrar_presenter_spec.rb
Normal file
34
spec/presenters/registrar_presenter_spec.rb
Normal file
|
@ -0,0 +1,34 @@
|
|||
require 'rails_helper'
|
||||
|
||||
RSpec.describe RegistrarPresenter do
|
||||
let(:registrar) { instance_double(Registrar) }
|
||||
let(:presenter) { described_class.new(registrar: registrar, view: nil) }
|
||||
|
||||
describe '#name' do
|
||||
it 'returns name' do
|
||||
expect(registrar).to receive(:name).and_return('test name')
|
||||
expect(presenter.name).to eq('test name')
|
||||
end
|
||||
end
|
||||
|
||||
describe '#email' do
|
||||
it 'returns email' do
|
||||
expect(registrar).to receive(:email).and_return('test email')
|
||||
expect(presenter.email).to eq('test email')
|
||||
end
|
||||
end
|
||||
|
||||
describe '#phone' do
|
||||
it 'returns phone' do
|
||||
expect(registrar).to receive(:phone).and_return('test phone')
|
||||
expect(presenter.phone).to eq('test phone')
|
||||
end
|
||||
end
|
||||
|
||||
describe '#url' do
|
||||
it 'returns url' do
|
||||
expect(registrar).to receive(:url).and_return('test url')
|
||||
expect(presenter.url).to eq('test url')
|
||||
end
|
||||
end
|
||||
end
|
36
spec/views/mailers/domain_mailer/expiration.html.erb_spec.rb
Normal file
36
spec/views/mailers/domain_mailer/expiration.html.erb_spec.rb
Normal file
|
@ -0,0 +1,36 @@
|
|||
require 'rails_helper'
|
||||
|
||||
RSpec.describe 'mailers/domain_mailer/expiration.html.erb' do
|
||||
let(:domain) { instance_spy(DomainPresenter) }
|
||||
let(:registrar) { instance_spy(RegistrarPresenter) }
|
||||
let(:lang_count) { 3 }
|
||||
|
||||
before :example do
|
||||
assign(:domain, domain)
|
||||
assign(:registrar, registrar)
|
||||
end
|
||||
|
||||
it 'has registrar name' do
|
||||
mention_count = 2 * lang_count
|
||||
expect(registrar).to receive(:name).exactly(mention_count).times.and_return('test registrar name')
|
||||
render
|
||||
expect(rendered).to have_text('test registrar name', count: mention_count)
|
||||
end
|
||||
|
||||
attributes = %i(
|
||||
on_hold_date
|
||||
delete_date
|
||||
registrant_name
|
||||
admin_contact_names
|
||||
tech_contact_names
|
||||
nameserver_names
|
||||
)
|
||||
|
||||
attributes.each do |attr_name|
|
||||
it "has :#{attr_name}" do
|
||||
expect(domain).to receive(attr_name).exactly(lang_count).times.and_return(attr_name.to_s)
|
||||
render
|
||||
expect(rendered).to have_text(attr_name.to_s, count: lang_count)
|
||||
end
|
||||
end
|
||||
end
|
36
spec/views/mailers/domain_mailer/expiration.text.erb_spec.rb
Normal file
36
spec/views/mailers/domain_mailer/expiration.text.erb_spec.rb
Normal file
|
@ -0,0 +1,36 @@
|
|||
require 'rails_helper'
|
||||
|
||||
RSpec.describe 'mailers/domain_mailer/expiration.text.erb' do
|
||||
let(:domain) { instance_spy(DomainPresenter) }
|
||||
let(:registrar) { instance_spy(RegistrarPresenter) }
|
||||
let(:lang_count) { 3 }
|
||||
|
||||
before :example do
|
||||
assign(:domain, domain)
|
||||
assign(:registrar, registrar)
|
||||
end
|
||||
|
||||
it 'has registrar name' do
|
||||
mention_count = 2 * lang_count
|
||||
expect(registrar).to receive(:name).exactly(mention_count).times.and_return('test registrar name')
|
||||
render
|
||||
expect(rendered).to have_text('test registrar name', count: mention_count)
|
||||
end
|
||||
|
||||
attributes = %i(
|
||||
on_hold_date
|
||||
delete_date
|
||||
registrant_name
|
||||
admin_contact_names
|
||||
tech_contact_names
|
||||
nameserver_names
|
||||
)
|
||||
|
||||
attributes.each do |attr_name|
|
||||
it "has :#{attr_name}" do
|
||||
expect(domain).to receive(attr_name).exactly(lang_count).times.and_return(attr_name.to_s)
|
||||
render
|
||||
expect(rendered).to have_text(attr_name.to_s, count: lang_count)
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue