Integrate auction

Closes #874
This commit is contained in:
Artur Beljajev 2018-11-29 15:08:22 +02:00
parent 640faaadb9
commit 42e8f86dae
51 changed files with 1619 additions and 53 deletions

4
test/fixtures/auctions.yml vendored Normal file
View file

@ -0,0 +1,4 @@
one:
domain: auction.test
status: <%= Auction.statuses[:no_bids] %>
uuid: 1b3ee442-e8fe-4922-9492-8fcb9dccc69c

4
test/fixtures/whois/records.yml vendored Normal file
View file

@ -0,0 +1,4 @@
one:
name: shop.test
json:
name: shop.test

View file

@ -0,0 +1,26 @@
require 'test_helper'
class ApiV1AuctionDetailsTest < ActionDispatch::IntegrationTest
setup do
@auction = auctions(:one)
ENV['auction_api_allowed_ips'] = '127.0.0.1'
end
teardown do
ENV['auction_api_allowed_ips'] = ''
end
def test_returns_auction_details
assert_equal '1b3ee442-e8fe-4922-9492-8fcb9dccc69c', @auction.uuid
assert_equal 'auction.test', @auction.domain
assert_equal Auction.statuses[:no_bids], @auction.status
get api_v1_auction_path(@auction.uuid), nil, 'Content-Type' => Mime::JSON.to_s
assert_response :ok
assert_equal ({ 'id' => '1b3ee442-e8fe-4922-9492-8fcb9dccc69c',
'domain' => 'auction.test',
'status' => Auction.statuses[:no_bids] }), ActiveSupport::JSON
.decode(response.body)
end
end

View file

@ -0,0 +1,30 @@
require 'test_helper'
class ApiV1AuctionListTest < ActionDispatch::IntegrationTest
setup do
@auction = auctions(:one)
end
def test_returns_started_auctions_without_authentication
@auction.update!(uuid: '1b3ee442-e8fe-4922-9492-8fcb9dccc69c',
domain: 'auction.test',
status: Auction.statuses[:started])
get api_v1_auctions_path, nil, 'Content-Type' => Mime::JSON.to_s
assert_response :ok
assert_equal ([{ 'id' => '1b3ee442-e8fe-4922-9492-8fcb9dccc69c',
'domain' => 'auction.test',
'status' => Auction.statuses[:started] }]), ActiveSupport::JSON
.decode(response.body)
end
def test_does_not_return_finished_auctions
@auction.update!(domain: 'auction.test', status: Auction.statuses[:awaiting_payment])
get api_v1_auctions_path, nil, 'Content-Type' => Mime::JSON.to_s
assert_response :ok
assert_empty ActiveSupport::JSON.decode(response.body)
end
end

View file

@ -0,0 +1,100 @@
require 'test_helper'
class ApiV1AuctionUpdateTest < ActionDispatch::IntegrationTest
fixtures :auctions, 'whois/records'
setup do
@auction = auctions(:one)
@original_auction_api_allowed_ips_setting = ENV['auction_api_allowed_ips']
ENV['auction_api_allowed_ips'] = '127.0.0.1'
end
teardown do
ENV['auction_api_allowed_ips'] = @original_auction_api_allowed_ips_setting
end
def test_returns_auction_details
assert_equal '1b3ee442-e8fe-4922-9492-8fcb9dccc69c', @auction.uuid
assert_equal 'auction.test', @auction.domain
patch api_v1_auction_path(@auction.uuid), { status: Auction.statuses[:awaiting_payment] }
.to_json, 'Content-Type' => Mime::JSON.to_s
assert_response :ok
assert_equal ({ 'id' => '1b3ee442-e8fe-4922-9492-8fcb9dccc69c',
'domain' => 'auction.test',
'status' => Auction.statuses[:awaiting_payment] }), ActiveSupport::JSON
.decode(response.body)
end
def test_marks_as_awaiting_payment
patch api_v1_auction_path(@auction.uuid), { status: Auction.statuses[:awaiting_payment] }
.to_json, 'Content-Type' => Mime::JSON.to_s
@auction.reload
assert @auction.awaiting_payment?
end
def test_marks_as_no_bids
assert_equal 'auction.test', @auction.domain
whois_records(:one).update!(name: 'auction.test')
patch api_v1_auction_path(@auction.uuid), { status: Auction.statuses[:no_bids] }
.to_json, 'Content-Type' => Mime::JSON.to_s
@auction.reload
assert @auction.no_bids?
end
def test_marks_as_payment_received
patch api_v1_auction_path(@auction.uuid), { status: Auction.statuses[:payment_received] }
.to_json, 'Content-Type' => Mime::JSON.to_s
@auction.reload
assert @auction.payment_received?
end
def test_marks_as_payment_not_received
patch api_v1_auction_path(@auction.uuid), { status: Auction.statuses[:payment_not_received] }
.to_json, 'Content-Type' => Mime::JSON.to_s
@auction.reload
assert @auction.payment_not_received?
end
def test_reveals_registration_code_when_payment_is_received
@auction.update!(registration_code: 'auction-001',
status: Auction.statuses[:awaiting_payment])
patch api_v1_auction_path(@auction.uuid), { status: Auction.statuses[:payment_received] }
.to_json, 'Content-Type' => Mime::JSON.to_s
response_json = ActiveSupport::JSON.decode(response.body)
assert_not_nil response_json['registration_code']
end
def test_conceals_registration_code_when_payment_is_not_received
@auction.update!(status: Auction.statuses[:awaiting_payment])
patch api_v1_auction_path(@auction.uuid), { status: Auction.statuses[:payment_not_received] }
.to_json, 'Content-Type' => Mime::JSON.to_s
response_json = ActiveSupport::JSON.decode(response.body)
assert_nil response_json['registration_code']
end
def test_restarts_an_auction_when_the_payment_is_not_received
@auction.update!(domain: 'auction.test', status: Auction.statuses[:awaiting_payment])
patch api_v1_auction_path(@auction.uuid), { status: Auction.statuses[:payment_not_received] }
.to_json, 'Content-Type' => Mime::JSON.to_s
assert DNS::DomainName.new('auction.test').at_auction?
end
def test_inaccessible_when_ip_address_is_not_allowed
ENV['auction_api_allowed_ips'] = ''
patch api_v1_auction_path(@auction.uuid), { status: 'any' }.to_json,
'Content-Type' => Mime::JSON.to_s
assert_response :unauthorized
end
end

View file

@ -0,0 +1,87 @@
require 'test_helper'
class EppDomainCheckAuctionTest < ApplicationIntegrationTest
setup do
@auction = auctions(:one)
Domain.release_to_auction = true
end
teardown do
Domain.release_to_auction = false
end
def test_domain_is_unavailable_when_at_auction
@auction.update!(status: Auction.statuses[:started])
request_xml = <<-XML
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<epp xmlns="https://epp.tld.ee/schema/epp-ee-1.0.xsd">
<command>
<check>
<domain:check xmlns:domain="https://epp.tld.ee/schema/domain-eis-1.0.xsd">
<domain:name>auction.test</domain:name>
</domain:check>
</check>
</command>
</epp>
XML
post '/epp/command/check', { frame: request_xml }, 'HTTP_COOKIE' => 'session=api_bestnames'
response_xml = Nokogiri::XML(response.body)
assert_equal '1000', response_xml.at_css('result')[:code]
assert_equal 1, response_xml.css('result').size
assert_equal '0', response_xml.at_xpath('//domain:name', 'domain' => 'https://epp.tld.ee/schema/domain-eis-1.0.xsd')['avail']
assert_equal 'Domain is at auction', response_xml.at_xpath('//domain:reason', 'domain' => 'https://epp.tld.ee/schema/domain-eis-1.0.xsd').text
end
def test_domain_is_unavailable_when_awaiting_payment
@auction.update!(status: Auction.statuses[:awaiting_payment])
request_xml = <<-XML
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<epp xmlns="https://epp.tld.ee/schema/epp-ee-1.0.xsd">
<command>
<check>
<domain:check xmlns:domain="https://epp.tld.ee/schema/domain-eis-1.0.xsd">
<domain:name>auction.test</domain:name>
</domain:check>
</check>
</command>
</epp>
XML
post '/epp/command/check', { frame: request_xml }, 'HTTP_COOKIE' => 'session=api_bestnames'
response_xml = Nokogiri::XML(response.body)
assert_equal '1000', response_xml.at_css('result')[:code]
assert_equal 1, response_xml.css('result').size
assert_equal '0', response_xml.at_xpath('//domain:name', 'domain' => 'https://epp.tld.ee/schema/domain-eis-1.0.xsd')['avail']
assert_equal 'Awaiting payment', response_xml.at_xpath('//domain:reason', 'domain' => 'https://epp.tld.ee/schema/domain-eis-1.0.xsd').text
end
def test_domain_is_available_when_payment_received
@auction.update!(status: Auction.statuses[:payment_received])
request_xml = <<-XML
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<epp xmlns="https://epp.tld.ee/schema/epp-ee-1.0.xsd">
<command>
<check>
<domain:check xmlns:domain="https://epp.tld.ee/schema/domain-eis-1.0.xsd">
<domain:name>auction.test</domain:name>
</domain:check>
</check>
</command>
</epp>
XML
post '/epp/command/check', { frame: request_xml }, 'HTTP_COOKIE' => 'session=api_bestnames'
response_xml = Nokogiri::XML(response.body)
assert_equal '1000', response_xml.at_css('result')[:code]
assert_equal 1, response_xml.css('result').size
assert_equal '1', response_xml.at_xpath('//domain:name', 'domain' => 'https://epp.tld.ee/schema/domain-eis-1.0.xsd')['avail']
assert_nil response_xml.at_xpath('//domain:reason', 'domain' => 'https://epp.tld.ee/schema/domain-eis-1.0.xsd')
end
end

View file

@ -0,0 +1,248 @@
require 'test_helper'
class EppDomainCreateAuctionTest < ApplicationIntegrationTest
setup do
@auction = auctions(:one)
Domain.release_to_auction = true
end
teardown do
Domain.release_to_auction = false
end
def test_registers_domain_without_registration_code_when_not_at_auction
request_xml = <<-XML
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<epp xmlns="https://epp.tld.ee/schema/epp-ee-1.0.xsd">
<command>
<create>
<domain:create xmlns:domain="https://epp.tld.ee/schema/domain-eis-1.0.xsd">
<domain:name>not-at-auction.test</domain:name>
<domain:registrant>#{contacts(:john).code}</domain:registrant>
</domain:create>
</create>
<extension>
<eis:extdata xmlns:eis="https://epp.tld.ee/schema/eis-1.0.xsd">
<eis:legalDocument type="pdf">#{'test' * 2000}</eis:legalDocument>
</eis:extdata>
</extension>
</command>
</epp>
XML
assert_difference 'Domain.count' do
post '/epp/command/create', { frame: request_xml }, 'HTTP_COOKIE' => 'session=api_bestnames'
end
response_xml = Nokogiri::XML(response.body)
assert_equal '1000', response_xml.at_css('result')[:code]
assert_equal 1, Nokogiri::XML(response.body).css('result').size
end
def test_registers_domain_with_correct_registration_code_after_another_auction_when_payment_is_received
@auction.update!(status: Auction.statuses[:domain_registered], registration_code: 'some')
another_auction = @auction.dup
another_auction.uuid = nil
another_auction.status = Auction.statuses[:payment_received]
another_auction.registration_code = 'auction002'
another_auction.save!
request_xml = <<-XML
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<epp xmlns="https://epp.tld.ee/schema/epp-ee-1.0.xsd">
<command>
<create>
<domain:create xmlns:domain="https://epp.tld.ee/schema/domain-eis-1.0.xsd">
<domain:name>auction.test</domain:name>
<domain:registrant>#{contacts(:john).code}</domain:registrant>
</domain:create>
</create>
<extension>
<eis:extdata xmlns:eis="https://epp.tld.ee/schema/eis-1.0.xsd">
<eis:legalDocument type="pdf">#{'test' * 2000}</eis:legalDocument>
<eis:reserved>
<eis:pw>auction002</eis:pw>
</eis:reserved>
</eis:extdata>
</extension>
</command>
</epp>
XML
assert_difference 'Domain.count' do
post '/epp/command/create', { frame: request_xml }, 'HTTP_COOKIE' => 'session=api_bestnames'
end
response_xml = Nokogiri::XML(response.body)
assert_equal '1000', response_xml.at_css('result')[:code]
assert_equal 1, Nokogiri::XML(response.body).css('result').size
end
def test_registers_domain_with_correct_registration_code_when_payment_is_received
@auction.update!(status: Auction.statuses[:payment_received],
registration_code: 'auction001')
request_xml = <<-XML
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<epp xmlns="https://epp.tld.ee/schema/epp-ee-1.0.xsd">
<command>
<create>
<domain:create xmlns:domain="https://epp.tld.ee/schema/domain-eis-1.0.xsd">
<domain:name>auction.test</domain:name>
<domain:registrant>#{contacts(:john).code}</domain:registrant>
</domain:create>
</create>
<extension>
<eis:extdata xmlns:eis="https://epp.tld.ee/schema/eis-1.0.xsd">
<eis:legalDocument type="pdf">#{'test' * 2000}</eis:legalDocument>
<eis:reserved>
<eis:pw>auction001</eis:pw>
</eis:reserved>
</eis:extdata>
</extension>
</command>
</epp>
XML
assert_difference 'Domain.count' do
post '/epp/command/create', { frame: request_xml }, 'HTTP_COOKIE' => 'session=api_bestnames'
end
@auction.reload
assert @auction.domain_registered?
response_xml = Nokogiri::XML(response.body)
assert_equal '1000', response_xml.at_css('result')[:code]
assert_equal 1, Nokogiri::XML(response.body).css('result').size
end
def test_domain_cannot_be_registered_without_registration_code
@auction.update!(status: Auction.statuses[:payment_received],
registration_code: 'auction001')
request_xml = <<-XML
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<epp xmlns="https://epp.tld.ee/schema/epp-ee-1.0.xsd">
<command>
<create>
<domain:create xmlns:domain="https://epp.tld.ee/schema/domain-eis-1.0.xsd">
<domain:name>auction.test</domain:name>
<domain:registrant>#{contacts(:john).code}</domain:registrant>
</domain:create>
</create>
<extension>
<eis:extdata xmlns:eis="https://epp.tld.ee/schema/eis-1.0.xsd">
<eis:legalDocument type="pdf">#{'test' * 2000}</eis:legalDocument>
</eis:extdata>
</extension>
</command>
</epp>
XML
assert_no_difference 'Domain.count' do
post '/epp/command/create', { frame: request_xml }, 'HTTP_COOKIE' => 'session=api_bestnames'
end
response_xml = Nokogiri::XML(response.body)
assert_equal '2003', response_xml.at_css('result')[:code]
assert_equal 'Required parameter missing; reserved>pw element is required',
response_xml.at_css('result msg').text
end
def test_domain_cannot_be_registered_with_wrong_registration_code
@auction.update!(status: Auction.statuses[:payment_received],
registration_code: 'auction001')
request_xml = <<-XML
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<epp xmlns="https://epp.tld.ee/schema/epp-ee-1.0.xsd">
<command>
<create>
<domain:create xmlns:domain="https://epp.tld.ee/schema/domain-eis-1.0.xsd">
<domain:name>auction.test</domain:name>
<domain:registrant>#{contacts(:john).code}</domain:registrant>
</domain:create>
</create>
<extension>
<eis:extdata xmlns:eis="https://epp.tld.ee/schema/eis-1.0.xsd">
<eis:legalDocument type="pdf">#{'test' * 2000}</eis:legalDocument>
<eis:reserved>
<eis:pw>wrong</eis:pw>
</eis:reserved>
</eis:extdata>
</extension>
</command>
</epp>
XML
assert_no_difference 'Domain.count' do
post '/epp/command/create', { frame: request_xml }, 'HTTP_COOKIE' => 'session=api_bestnames'
end
response_xml = Nokogiri::XML(response.body)
assert_equal '2202', response_xml.at_css('result')[:code]
assert_equal 'Invalid authorization information; invalid reserved>pw value',
response_xml.at_css('result msg').text
end
def test_domain_cannot_be_registered_when_payment_is_not_received
@auction.update!(status: Auction.statuses[:awaiting_payment])
request_xml = <<-XML
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<epp xmlns="https://epp.tld.ee/schema/epp-ee-1.0.xsd">
<command>
<create>
<domain:create xmlns:domain="https://epp.tld.ee/schema/domain-eis-1.0.xsd">
<domain:name>auction.test</domain:name>
<domain:registrant>#{contacts(:john).code}</domain:registrant>
</domain:create>
</create>
<extension>
<eis:extdata xmlns:eis="https://epp.tld.ee/schema/eis-1.0.xsd">
<eis:legalDocument type="pdf">#{'test' * 2000}</eis:legalDocument>
<eis:reserved>
<eis:pw>test</eis:pw>
</eis:reserved>
</eis:extdata>
</extension>
</command>
</epp>
XML
assert_no_difference 'Domain.count' do
post '/epp/command/create', { frame: request_xml }, 'HTTP_COOKIE' => 'session=api_bestnames'
end
response_xml = Nokogiri::XML(response.body)
assert_equal '2003', response_xml.at_css('result')[:code]
assert_equal 'Required parameter missing; reserved>pw element required for reserved domains',
response_xml.at_css('result msg').text
end
def test_domain_cannot_be_registered_when_at_auction
@auction.update!(status: Auction.statuses[:started])
request_xml = <<-XML
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<epp xmlns="https://epp.tld.ee/schema/epp-ee-1.0.xsd">
<command>
<create>
<domain:create xmlns:domain="https://epp.tld.ee/schema/domain-eis-1.0.xsd">
<domain:name>auction.test</domain:name>
</domain:create>
</create>
<extension>
<eis:extdata xmlns:eis="https://epp.tld.ee/schema/eis-1.0.xsd">
<eis:legalDocument type="pdf">test</eis:legalDocument>
</eis:extdata>
</extension>
</command>
</epp>
XML
assert_no_difference 'Domain.count' do
post '/epp/command/create', { frame: request_xml }, 'HTTP_COOKIE' => 'session=api_bestnames'
end
response_xml = Nokogiri::XML(response.body)
assert_equal '2306', response_xml.at_css('result')[:code]
assert_equal 'Parameter value policy error: domain is at auction',
response_xml.at_css('result msg').text
end
end

View file

@ -0,0 +1,87 @@
require 'test_helper'
class EppDomainInfoAuctionTest < ApplicationIntegrationTest
setup do
@auction = auctions(:one)
Domain.release_to_auction = true
end
teardown do
Domain.release_to_auction = false
end
def test_domain_is_unavailable_when_at_auction
@auction.update!(status: Auction.statuses[:started])
request_xml = <<-XML
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<epp xmlns="https://epp.tld.ee/schema/epp-ee-1.0.xsd">
<command>
<info>
<domain:info xmlns:domain="https://epp.tld.ee/schema/domain-eis-1.0.xsd">
<domain:name>auction.test</domain:name>
</domain:info>
</info>
</command>
</epp>
XML
post '/epp/command/info', { frame: request_xml }, 'HTTP_COOKIE' => 'session=api_bestnames'
response_xml = Nokogiri::XML(response.body)
assert_equal '1000', response_xml.at_css('result')[:code]
assert_equal 1, response_xml.css('result').size
assert_equal 'auction.test', response_xml.at_xpath('//domain:name', 'domain' => 'https://epp.tld.ee/schema/domain-eis-1.0.xsd').text
assert_equal 'At auction', response_xml.at_xpath('//domain:status', 'domain' => 'https://epp.tld.ee/schema/domain-eis-1.0.xsd')['s']
end
def test_domain_is_reserved_when_awaiting_payment
@auction.update!(status: Auction.statuses[:awaiting_payment])
request_xml = <<-XML
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<epp xmlns="https://epp.tld.ee/schema/epp-ee-1.0.xsd">
<command>
<info>
<domain:info xmlns:domain="https://epp.tld.ee/schema/domain-eis-1.0.xsd">
<domain:name>auction.test</domain:name>
</domain:info>
</info>
</command>
</epp>
XML
post '/epp/command/info', { frame: request_xml }, 'HTTP_COOKIE' => 'session=api_bestnames'
response_xml = Nokogiri::XML(response.body)
assert_equal '1000', response_xml.at_css('result')[:code]
assert_equal 1, response_xml.css('result').size
assert_equal 'auction.test', response_xml.at_xpath('//domain:name', 'domain' => 'https://epp.tld.ee/schema/domain-eis-1.0.xsd').text
assert_equal 'Awaiting payment', response_xml.at_xpath('//domain:status', 'domain' => 'https://epp.tld.ee/schema/domain-eis-1.0.xsd')['s']
end
def test_domain_is_reserved_when_payment_received
@auction.update!(status: Auction.statuses[:payment_received])
request_xml = <<-XML
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<epp xmlns="https://epp.tld.ee/schema/epp-ee-1.0.xsd">
<command>
<info>
<domain:info xmlns:domain="https://epp.tld.ee/schema/domain-eis-1.0.xsd">
<domain:name>auction.test</domain:name>
</domain:info>
</info>
</command>
</epp>
XML
post '/epp/command/info', { frame: request_xml }, 'HTTP_COOKIE' => 'session=api_bestnames'
response_xml = Nokogiri::XML(response.body)
assert_equal '1000', response_xml.at_css('result')[:code]
assert_equal 1, response_xml.css('result').size
assert_equal 'auction.test', response_xml.at_xpath('//domain:name', 'domain' => 'https://epp.tld.ee/schema/domain-eis-1.0.xsd').text
assert_equal 'Reserved', response_xml.at_xpath('//domain:status', 'domain' => 'https://epp.tld.ee/schema/domain-eis-1.0.xsd')['s']
end
end

121
test/models/auction_test.rb Normal file
View 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

View file

@ -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

View 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

View file

@ -1,51 +1,53 @@
require 'test_helper'
class DiscardDomainTaskTest < TaskTestCase
class DomainReleasableDiscardableTest < ActiveSupport::TestCase
setup do
travel_to Time.zone.parse('2010-07-05 08:00')
@domain = domains(:shop)
end
def test_discard_domains_with_past_delete_at
def test_discards_domains_with_past_delete_at
@domain.update!(delete_at: Time.zone.parse('2010-07-05 07:59'))
Rake::Task['domain:discard'].execute
travel_to Time.zone.parse('2010-07-05 08:00')
Domain.release_domains
@domain.reload
assert @domain.discarded?
end
def test_ignore_domains_with_delete_at_in_the_future_or_now
def test_ignores_domains_with_delete_at_in_the_future_or_now
@domain.update!(delete_at: Time.zone.parse('2010-07-05 08:00'))
Rake::Task['domain:discard'].execute
travel_to Time.zone.parse('2010-07-05 08:00')
Domain.release_domains
@domain.reload
refute @domain.discarded?
assert_not @domain.discarded?
end
def test_ignore_already_discarded_domains
def test_ignores_already_discarded_domains
@domain.update!(delete_at: Time.zone.parse('2010-07-05 07:59'))
@domain.discard
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
Rake::Task['domain:discard'].execute
Domain.release_domains
end
end
def test_ignore_domains_with_server_delete_prohibited_status
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])
Rake::Task['domain:discard'].execute
travel_to Time.zone.parse('2010-07-05 08:00')
Domain.release_domains
@domain.reload
refute @domain.discarded?
end
def test_show_results
@domain.update!(delete_at: Time.zone.parse('2010-07-05 07:59'))
$stdout = StringIO.new
Rake::Task['domain:discard'].execute
assert_equal "shop.test is discarded\nDiscarded total: 1\n", $stdout.string
assert_not @domain.discarded?
end
end
end

View 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

View file

@ -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

View 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

View file

@ -1,6 +1,8 @@
require 'test_helper'
class WhoisRecordTest < ActiveSupport::TestCase
fixtures 'whois_records'
def setup
super

View file

@ -0,0 +1,19 @@
require 'test_helper'
class ReleaseDomainsTaskTest < ActiveSupport::TestCase
setup do
@domain = domains(:shop)
end
def test_output
@domain.update!(delete_at: Time.zone.parse('2010-07-05 07:59'))
travel_to Time.zone.parse('2010-07-05 08:00')
assert_output("shop.test is released\nReleased total: 1\n") { run_task }
end
private
def run_task
Rake::Task['domains:release'].execute
end
end