mirror of
https://github.com/internetee/registry.git
synced 2025-06-10 06:34:46 +02:00
parent
640faaadb9
commit
42e8f86dae
51 changed files with 1619 additions and 53 deletions
121
test/models/auction_test.rb
Normal file
121
test/models/auction_test.rb
Normal file
|
@ -0,0 +1,121 @@
|
|||
require 'test_helper'
|
||||
|
||||
class AuctionTest < ActiveSupport::TestCase
|
||||
setup do
|
||||
@auction = auctions(:one)
|
||||
end
|
||||
|
||||
def test_fixture_is_valid
|
||||
assert @auction.valid?
|
||||
end
|
||||
|
||||
def test_statuses
|
||||
assert_equal ({ 'started' => 'started',
|
||||
'no_bids' => 'no_bids',
|
||||
'awaiting_payment' => 'awaiting_payment',
|
||||
'payment_received' => 'payment_received',
|
||||
'payment_not_received' => 'payment_not_received',
|
||||
'domain_registered' => 'domain_registered' }), Auction.statuses
|
||||
end
|
||||
|
||||
def test_selling_domain_starts_new_auction
|
||||
domain_name = DNS::DomainName.new('shop.test')
|
||||
|
||||
assert_difference 'Auction.count' do
|
||||
Auction.sell(domain_name)
|
||||
end
|
||||
auction = Auction.last
|
||||
assert_equal domain_name.to_s, auction.domain
|
||||
assert auction.started?
|
||||
end
|
||||
|
||||
def test_pending
|
||||
domain_name = DNS::DomainName.new('auction.test')
|
||||
assert_equal 'auction.test', @auction.domain
|
||||
|
||||
assert @auction.no_bids?
|
||||
assert_nil Auction.pending(domain_name)
|
||||
|
||||
@auction.update!(status: Auction.statuses[:started])
|
||||
assert_equal @auction, Auction.pending(domain_name)
|
||||
|
||||
@auction.update!(status: Auction.statuses[:awaiting_payment])
|
||||
assert_equal @auction, Auction.pending(domain_name)
|
||||
|
||||
@auction.update!(status: Auction.statuses[:payment_received])
|
||||
assert_equal @auction, Auction.pending(domain_name)
|
||||
end
|
||||
|
||||
def test_record_with_invalid_status_cannot_be_saved
|
||||
# ArgumentError is triggered by ActiveRecord::Base.enum
|
||||
assert_raises ArgumentError do
|
||||
@auction.status = 'invalid'
|
||||
@auction.save!
|
||||
end
|
||||
end
|
||||
|
||||
def test_marking_as_no_bids
|
||||
@auction.update!(status: Auction.statuses[:started])
|
||||
|
||||
@auction.mark_as_no_bids
|
||||
@auction.reload
|
||||
|
||||
assert @auction.no_bids?
|
||||
end
|
||||
|
||||
def test_marking_as_payment_received
|
||||
@auction.update!(status: Auction.statuses[:awaiting_payment], registration_code: nil)
|
||||
|
||||
@auction.mark_as_payment_received
|
||||
@auction.reload
|
||||
|
||||
assert @auction.payment_received?
|
||||
assert_not_nil @auction.registration_code
|
||||
end
|
||||
|
||||
def test_marking_as_payment_not_received
|
||||
@auction.update!(status: Auction.statuses[:awaiting_payment], registration_code: nil)
|
||||
|
||||
@auction.mark_as_payment_not_received
|
||||
@auction.reload
|
||||
|
||||
assert @auction.payment_not_received?
|
||||
assert_nil @auction.registration_code
|
||||
end
|
||||
|
||||
def test_restarts_an_auction_when_payment_is_not_received
|
||||
@auction.update!(domain: 'auction.test', status: Auction.statuses[:awaiting_payment])
|
||||
|
||||
assert_difference 'Auction.count' do
|
||||
@auction.mark_as_payment_not_received
|
||||
end
|
||||
|
||||
new_auction = Auction.last
|
||||
assert_equal 'auction.test', new_auction.domain
|
||||
assert new_auction.started?
|
||||
end
|
||||
|
||||
def test_domain_registrable
|
||||
assert @auction.no_bids?
|
||||
assert_not @auction.domain_registrable?
|
||||
|
||||
@auction.status = Auction.statuses[:payment_received]
|
||||
@auction.registration_code = 'auction001'
|
||||
|
||||
assert @auction.domain_registrable?('auction001')
|
||||
end
|
||||
|
||||
def test_domain_unregistrable
|
||||
@auction.status = Auction.statuses[:payment_not_received]
|
||||
@auction.registration_code = 'auction001'
|
||||
|
||||
assert_not @auction.domain_registrable?('auction001')
|
||||
|
||||
@auction.status = Auction.statuses[:payment_received]
|
||||
@auction.registration_code = 'auction001'
|
||||
|
||||
assert_not @auction.domain_registrable?('wrong')
|
||||
assert_not @auction.domain_registrable?(nil)
|
||||
assert_not @auction.domain_registrable?('')
|
||||
end
|
||||
end
|
|
@ -1,6 +1,34 @@
|
|||
require 'test_helper'
|
||||
|
||||
class AuctionDouble
|
||||
def domain_registrable?(_code)
|
||||
true
|
||||
end
|
||||
end
|
||||
|
||||
class AuctionDoubleTest < ActiveSupport::TestCase
|
||||
def test_implements_the_domain_registrable_interface
|
||||
assert_respond_to AuctionDouble.new, :domain_registrable?
|
||||
end
|
||||
end
|
||||
|
||||
class DNS::DomainNameTest < ActiveSupport::TestCase
|
||||
def test_available_when_not_at_auction
|
||||
domain_name = DNS::DomainName.new('auction.test')
|
||||
auctions(:one).update!(domain: 'auction.test', status: Auction.statuses[:domain_registered])
|
||||
|
||||
assert domain_name.available?
|
||||
assert_not domain_name.unavailable?
|
||||
end
|
||||
|
||||
def test_available_with_correct_code
|
||||
domain_name = DNS::DomainName.new('auction.test')
|
||||
|
||||
Auction.stub(:pending, AuctionDouble.new) do
|
||||
assert domain_name.available_with_code?('some')
|
||||
end
|
||||
end
|
||||
|
||||
def test_unavailable_when_registered
|
||||
domain_name = DNS::DomainName.new('shop.test')
|
||||
assert_equal 'shop.test', domains(:shop).name
|
||||
|
@ -24,4 +52,63 @@ class DNS::DomainNameTest < ActiveSupport::TestCase
|
|||
assert domain_name.unavailable?
|
||||
assert_equal :zone_with_same_origin, domain_name.unavailability_reason
|
||||
end
|
||||
|
||||
def test_unavailable_when_at_auction
|
||||
domain_name = DNS::DomainName.new('auction.test')
|
||||
auctions(:one).update!(domain: 'auction.test', status: Auction.statuses[:started])
|
||||
|
||||
assert domain_name.unavailable?
|
||||
assert_not domain_name.available?
|
||||
assert_equal :at_auction, domain_name.unavailability_reason
|
||||
end
|
||||
|
||||
def test_unavailable_when_awaiting_payment
|
||||
domain_name = DNS::DomainName.new('auction.test')
|
||||
auctions(:one).update!(domain: 'auction.test', status: Auction.statuses[:awaiting_payment])
|
||||
|
||||
assert domain_name.unavailable?
|
||||
assert_not domain_name.available?
|
||||
assert_equal :awaiting_payment, domain_name.unavailability_reason
|
||||
end
|
||||
|
||||
def test_sell_at_auction
|
||||
domain_name = DNS::DomainName.new('new-auction.test')
|
||||
assert_not domain_name.at_auction?
|
||||
|
||||
domain_name.sell_at_auction
|
||||
|
||||
assert domain_name.at_auction?
|
||||
end
|
||||
|
||||
def test_selling_at_auction_updates_whois
|
||||
domain_name = DNS::DomainName.new('new-auction.test')
|
||||
assert_not domain_name.at_auction?
|
||||
|
||||
domain_name.sell_at_auction
|
||||
|
||||
assert Whois::Record.find_by(name: 'new-auction.test')
|
||||
end
|
||||
|
||||
def test_at_auction
|
||||
domain_name = DNS::DomainName.new('auction.test')
|
||||
auctions(:one).update!(domain: 'auction.test', status: Auction.statuses[:started])
|
||||
assert domain_name.at_auction?
|
||||
end
|
||||
|
||||
def test_awaiting_payment
|
||||
domain_name = DNS::DomainName.new('auction.test')
|
||||
auctions(:one).update!(domain: 'auction.test', status: Auction.statuses[:awaiting_payment])
|
||||
assert domain_name.awaiting_payment?
|
||||
end
|
||||
|
||||
def test_pending_registration
|
||||
domain_name = DNS::DomainName.new('auction.test')
|
||||
auctions(:one).update!(domain: 'auction.test', status: Auction.statuses[:payment_received])
|
||||
assert domain_name.pending_registration?
|
||||
end
|
||||
|
||||
def test_to_s
|
||||
domain_name = DNS::DomainName.new('shop.test')
|
||||
assert_equal 'shop.test', domain_name.to_s
|
||||
end
|
||||
end
|
||||
|
|
51
test/models/domain/releasable/auctionable_test.rb
Normal file
51
test/models/domain/releasable/auctionable_test.rb
Normal file
|
@ -0,0 +1,51 @@
|
|||
require 'test_helper'
|
||||
|
||||
class DomainReleasableAuctionableTest < ActiveSupport::TestCase
|
||||
setup do
|
||||
@domain = domains(:shop)
|
||||
Domain.release_to_auction = true
|
||||
end
|
||||
|
||||
teardown do
|
||||
Domain.release_to_auction = false
|
||||
end
|
||||
|
||||
def test_sells_domain_at_auction
|
||||
@domain.update!(delete_at: Time.zone.parse('2010-07-05 07:59'))
|
||||
travel_to Time.zone.parse('2010-07-05 08:00')
|
||||
|
||||
Domain.release_domains
|
||||
|
||||
assert @domain.domain_name.at_auction?
|
||||
end
|
||||
|
||||
def test_deletes_registered_domain
|
||||
@domain.update!(delete_at: Time.zone.parse('2010-07-05 07:59'))
|
||||
travel_to Time.zone.parse('2010-07-05 08:00')
|
||||
|
||||
assert_difference 'Domain.count', -1 do
|
||||
Domain.release_domains
|
||||
end
|
||||
end
|
||||
|
||||
def test_ignores_domains_with_delete_at_in_the_future_or_now
|
||||
@domain.update!(delete_at: Time.zone.parse('2010-07-05 08:00'))
|
||||
travel_to Time.zone.parse('2010-07-05 08:00')
|
||||
|
||||
assert_no_difference 'Domain.count' do
|
||||
Domain.release_domains
|
||||
end
|
||||
assert_not @domain.domain_name.at_auction?
|
||||
end
|
||||
|
||||
def test_ignores_domains_with_server_delete_prohibited_status
|
||||
@domain.update!(delete_at: Time.zone.parse('2010-07-05 07:59'),
|
||||
statuses: [DomainStatus::SERVER_DELETE_PROHIBITED])
|
||||
travel_to Time.zone.parse('2010-07-05 08:00')
|
||||
|
||||
assert_no_difference 'Domain.count' do
|
||||
Domain.release_domains
|
||||
end
|
||||
assert_not @domain.domain_name.at_auction?
|
||||
end
|
||||
end
|
53
test/models/domain/releasable/discardable_test.rb
Normal file
53
test/models/domain/releasable/discardable_test.rb
Normal file
|
@ -0,0 +1,53 @@
|
|||
require 'test_helper'
|
||||
|
||||
class DomainReleasableDiscardableTest < ActiveSupport::TestCase
|
||||
setup do
|
||||
@domain = domains(:shop)
|
||||
end
|
||||
|
||||
def test_discards_domains_with_past_delete_at
|
||||
@domain.update!(delete_at: Time.zone.parse('2010-07-05 07:59'))
|
||||
travel_to Time.zone.parse('2010-07-05 08:00')
|
||||
|
||||
Domain.release_domains
|
||||
@domain.reload
|
||||
|
||||
assert @domain.discarded?
|
||||
end
|
||||
|
||||
def test_ignores_domains_with_delete_at_in_the_future_or_now
|
||||
@domain.update!(delete_at: Time.zone.parse('2010-07-05 08:00'))
|
||||
travel_to Time.zone.parse('2010-07-05 08:00')
|
||||
|
||||
Domain.release_domains
|
||||
@domain.reload
|
||||
|
||||
assert_not @domain.discarded?
|
||||
end
|
||||
|
||||
def test_ignores_already_discarded_domains
|
||||
@domain.update!(delete_at: Time.zone.parse('2010-07-05 07:59'))
|
||||
travel_to Time.zone.parse('2010-07-05 08:00')
|
||||
|
||||
Domain.release_domains
|
||||
|
||||
job_count = lambda do
|
||||
QueJob.where("args->>0 = '#{@domain.id}'", job_class: DomainDeleteJob.name).count
|
||||
end
|
||||
|
||||
assert_no_difference job_count, 'A domain should not be discarded again' do
|
||||
Domain.release_domains
|
||||
end
|
||||
end
|
||||
|
||||
def test_ignores_domains_with_server_delete_prohibited_status
|
||||
@domain.update!(delete_at: Time.zone.parse('2010-07-05 07:59'),
|
||||
statuses: [DomainStatus::SERVER_DELETE_PROHIBITED])
|
||||
travel_to Time.zone.parse('2010-07-05 08:00')
|
||||
|
||||
Domain.release_domains
|
||||
@domain.reload
|
||||
|
||||
assert_not @domain.discarded?
|
||||
end
|
||||
end
|
11
test/models/domain/releasable_test.rb
Normal file
11
test/models/domain/releasable_test.rb
Normal file
|
@ -0,0 +1,11 @@
|
|||
require 'test_helper'
|
||||
|
||||
class DomainReleasableTest < ActiveSupport::TestCase
|
||||
setup do
|
||||
@domain = domains(:shop)
|
||||
end
|
||||
|
||||
def test_releasing_a_domain_discards_it_by_default
|
||||
refute Domain.release_to_auction
|
||||
end
|
||||
end
|
|
@ -12,4 +12,9 @@ class DomainTest < ActiveSupport::TestCase
|
|||
def test_invalid_fixture_is_invalid
|
||||
assert domains(:invalid).invalid?
|
||||
end
|
||||
|
||||
def test_domain_name
|
||||
domain = Domain.new(name: 'shop.test')
|
||||
assert_equal 'shop.test', domain.domain_name.to_s
|
||||
end
|
||||
end
|
||||
|
|
67
test/models/whois/record_test.rb
Normal file
67
test/models/whois/record_test.rb
Normal file
|
@ -0,0 +1,67 @@
|
|||
require 'test_helper'
|
||||
|
||||
class Whois::RecordTest < ActiveSupport::TestCase
|
||||
fixtures 'whois/records'
|
||||
|
||||
setup do
|
||||
@original_disclaimer_setting = Setting.registry_whois_disclaimer
|
||||
end
|
||||
|
||||
teardown do
|
||||
Setting.registry_whois_disclaimer = @original_disclaimer_setting
|
||||
end
|
||||
|
||||
def test_reads_disclaimer_from_settings
|
||||
Setting.registry_whois_disclaimer = 'test disclaimer'
|
||||
assert_equal 'test disclaimer', Whois::Record.disclaimer
|
||||
end
|
||||
|
||||
def test_creates_new_whois_record_when_domain_is_at_auction
|
||||
domain_name = DNS::DomainName.new('some.test')
|
||||
Setting.registry_whois_disclaimer = 'disclaimer'
|
||||
|
||||
domain_name.stub(:at_auction?, true) do
|
||||
assert_difference 'Whois::Record.count' do
|
||||
Whois::Record.refresh(domain_name)
|
||||
end
|
||||
end
|
||||
|
||||
whois_record = Whois::Record.last
|
||||
assert_equal 'some.test', whois_record.name
|
||||
assert_equal ({ 'name' => 'some.test',
|
||||
'status' => 'AtAuction',
|
||||
'disclaimer' => 'disclaimer' }), whois_record.json
|
||||
end
|
||||
|
||||
def test_refreshes_whois_record_when_domain_auction_reaches_awaiting_payment_state
|
||||
domain_name = DNS::DomainName.new('some.test')
|
||||
Setting.registry_whois_disclaimer = 'disclaimer'
|
||||
whois_records(:one).update!(name: 'some.test')
|
||||
|
||||
domain_name.stub(:awaiting_payment?, true) do
|
||||
Whois::Record.refresh(domain_name)
|
||||
end
|
||||
|
||||
whois_record = Whois::Record.find_by(name: 'some.test')
|
||||
assert_equal 'some.test', whois_record.name
|
||||
assert_equal ({ 'name' => 'some.test',
|
||||
'status' => 'PendingRegistration',
|
||||
'disclaimer' => 'disclaimer' }), whois_record.json
|
||||
end
|
||||
|
||||
def test_refreshes_whois_record_when_domain_auction_reaches_pending_registration_state
|
||||
domain_name = DNS::DomainName.new('some.test')
|
||||
Setting.registry_whois_disclaimer = 'disclaimer'
|
||||
whois_records(:one).update!(name: 'some.test')
|
||||
|
||||
domain_name.stub(:pending_registration?, true) do
|
||||
Whois::Record.refresh(domain_name)
|
||||
end
|
||||
|
||||
whois_record = Whois::Record.find_by(name: 'some.test')
|
||||
assert_equal 'some.test', whois_record.name
|
||||
assert_equal ({ 'name' => 'some.test',
|
||||
'status' => 'PendingRegistration',
|
||||
'disclaimer' => 'disclaimer' }), whois_record.json
|
||||
end
|
||||
end
|
|
@ -1,6 +1,8 @@
|
|||
require 'test_helper'
|
||||
|
||||
class WhoisRecordTest < ActiveSupport::TestCase
|
||||
fixtures 'whois_records'
|
||||
|
||||
def setup
|
||||
super
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue