Update whois record with auction registration_deadline if any

This commit is contained in:
Alex Sherman 2020-05-06 15:17:20 +05:00
parent c6fd78b4cd
commit 5c419ae8be
4 changed files with 29 additions and 7 deletions

View file

@ -30,6 +30,8 @@ module Api
raise "Invalid status #{params[:status]}" raise "Invalid status #{params[:status]}"
end end
auction.mark_deadline(params[:registration_deadline]) if params[:registration_deadline]
if auction.payment_not_received? || auction.domain_not_registered? if auction.payment_not_received? || auction.domain_not_registered?
update_whois_from_auction(Auction.pending(auction.domain)) update_whois_from_auction(Auction.pending(auction.domain))
else else

View file

@ -23,10 +23,19 @@ class Auction < ApplicationRecord
save! save!
end end
def whois_deadline
registration_deadline.to_s
end
def mark_as_no_bids def mark_as_no_bids
no_bids! no_bids!
end end
def mark_deadline(registration_deadline)
self.registration_deadline = registration_deadline
save!
end
def mark_as_payment_received def mark_as_payment_received
self.status = self.class.statuses[:payment_received] self.status = self.class.statuses[:payment_received]
generate_registration_code generate_registration_code
@ -69,4 +78,4 @@ class Auction < ApplicationRecord
def registration_code_matches?(code) def registration_code_matches?(code)
registration_code == code registration_code == code
end end
end end

View file

@ -16,7 +16,8 @@ module Whois
elsif auction.awaiting_payment? || auction.payment_received? elsif auction.awaiting_payment? || auction.payment_received?
update!(json: { name: auction.domain, update!(json: { name: auction.domain,
status: ['PendingRegistration'], status: ['PendingRegistration'],
disclaimer: self.class.disclaimer }) disclaimer: self.class.disclaimer,
registration_deadline: auction.whois_deadline })
end end
end end
end end

View file

@ -40,24 +40,34 @@ class Whois::RecordTest < ActiveSupport::TestCase
end end
def test_updates_whois_record_from_auction_when_awaiting_payment def test_updates_whois_record_from_auction_when_awaiting_payment
@auction.update!(domain: 'domain.test', status: Auction.statuses[:awaiting_payment]) @auction.update!(domain: 'domain.test',
status: Auction.statuses[:awaiting_payment],
registration_deadline: registration_deadline)
@whois_record.update!(name: 'domain.test') @whois_record.update!(name: 'domain.test')
@whois_record.update_from_auction(@auction) @whois_record.update_from_auction(@auction)
@whois_record.reload @whois_record.reload
assert_equal ({ 'name' => 'domain.test', assert_equal ({ 'name' => 'domain.test',
'status' => ['PendingRegistration'], 'status' => ['PendingRegistration'],
'disclaimer' => 'disclaimer' }), @whois_record.json 'disclaimer' => 'disclaimer',
'registration_deadline' => registration_deadline.to_s }), @whois_record.json
end end
def test_updates_whois_record_from_auction_when_payment_received def test_updates_whois_record_from_auction_when_payment_received
@auction.update!(domain: 'domain.test', status: Auction.statuses[:payment_received]) @auction.update!(domain: 'domain.test',
status: Auction.statuses[:payment_received],
registration_deadline: registration_deadline)
@whois_record.update!(name: 'domain.test') @whois_record.update!(name: 'domain.test')
@whois_record.update_from_auction(@auction) @whois_record.update_from_auction(@auction)
@whois_record.reload @whois_record.reload
assert_equal ({ 'name' => 'domain.test', assert_equal ({ 'name' => 'domain.test',
'status' => ['PendingRegistration'], 'status' => ['PendingRegistration'],
'disclaimer' => 'disclaimer' }), @whois_record.json 'disclaimer' => 'disclaimer',
'registration_deadline' => registration_deadline.to_s }), @whois_record.json
end end
end
def registration_deadline
Time.zone.now + 10.days
end
end