From 5c419ae8be7a6f0628f32329be8e7b3a218665ba Mon Sep 17 00:00:00 2001 From: Alex Sherman Date: Wed, 6 May 2020 15:17:20 +0500 Subject: [PATCH] Update whois record with auction registration_deadline if any --- app/controllers/api/v1/auctions_controller.rb | 2 ++ app/models/auction.rb | 11 +++++++++- app/models/whois/record.rb | 3 ++- test/models/whois/record_test.rb | 20 ++++++++++++++----- 4 files changed, 29 insertions(+), 7 deletions(-) diff --git a/app/controllers/api/v1/auctions_controller.rb b/app/controllers/api/v1/auctions_controller.rb index bf92be930..de8e94442 100644 --- a/app/controllers/api/v1/auctions_controller.rb +++ b/app/controllers/api/v1/auctions_controller.rb @@ -30,6 +30,8 @@ module Api raise "Invalid status #{params[:status]}" end + auction.mark_deadline(params[:registration_deadline]) if params[:registration_deadline] + if auction.payment_not_received? || auction.domain_not_registered? update_whois_from_auction(Auction.pending(auction.domain)) else diff --git a/app/models/auction.rb b/app/models/auction.rb index 6ddd8e394..c4b9f6130 100644 --- a/app/models/auction.rb +++ b/app/models/auction.rb @@ -23,10 +23,19 @@ class Auction < ApplicationRecord save! end + def whois_deadline + registration_deadline.to_s + end + def mark_as_no_bids no_bids! end + def mark_deadline(registration_deadline) + self.registration_deadline = registration_deadline + save! + end + def mark_as_payment_received self.status = self.class.statuses[:payment_received] generate_registration_code @@ -69,4 +78,4 @@ class Auction < ApplicationRecord def registration_code_matches?(code) registration_code == code end -end \ No newline at end of file +end diff --git a/app/models/whois/record.rb b/app/models/whois/record.rb index ae7422403..1d827e22a 100644 --- a/app/models/whois/record.rb +++ b/app/models/whois/record.rb @@ -16,7 +16,8 @@ module Whois elsif auction.awaiting_payment? || auction.payment_received? update!(json: { name: auction.domain, status: ['PendingRegistration'], - disclaimer: self.class.disclaimer }) + disclaimer: self.class.disclaimer, + registration_deadline: auction.whois_deadline }) end end end diff --git a/test/models/whois/record_test.rb b/test/models/whois/record_test.rb index 5f2454105..64e8a894a 100644 --- a/test/models/whois/record_test.rb +++ b/test/models/whois/record_test.rb @@ -40,24 +40,34 @@ class Whois::RecordTest < ActiveSupport::TestCase end 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_from_auction(@auction) @whois_record.reload assert_equal ({ 'name' => 'domain.test', 'status' => ['PendingRegistration'], - 'disclaimer' => 'disclaimer' }), @whois_record.json + 'disclaimer' => 'disclaimer', + 'registration_deadline' => registration_deadline.to_s }), @whois_record.json end 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_from_auction(@auction) @whois_record.reload assert_equal ({ 'name' => 'domain.test', 'status' => ['PendingRegistration'], - 'disclaimer' => 'disclaimer' }), @whois_record.json + 'disclaimer' => 'disclaimer', + 'registration_deadline' => registration_deadline.to_s }), @whois_record.json end -end \ No newline at end of file + + def registration_deadline + Time.zone.now + 10.days + end +end