From c8392a6a38cc03a4539f451852abdbfec1496af5 Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Sat, 10 Nov 2018 18:50:37 +0200 Subject: [PATCH] Improve `WhoisRecord` tests --- test/models/whois_record_test.rb | 55 ++++++++++++++++++++++++++++++-- 1 file changed, 52 insertions(+), 3 deletions(-) diff --git a/test/models/whois_record_test.rb b/test/models/whois_record_test.rb index e86deafd9..cd796742d 100644 --- a/test/models/whois_record_test.rb +++ b/test/models/whois_record_test.rb @@ -18,9 +18,6 @@ class WhoisRecordTest < ActiveSupport::TestCase expected_partial_hash = { disclaimer: expected_disclaimer_text, name: 'shop.test', - registrant: 'John', - registrant_kind: 'priv', - email: 'john@inbox.test', expire: '2010-07-05', registrar_address: 'Main Street, New York, New York, 12345', dnssec_keys: [], @@ -60,4 +57,56 @@ class WhoisRecordTest < ActiveSupport::TestCase refute_match(/Search results may not be used for commercial/, @record.body) end end + + def test_generates_json_with_registrant + registrant = contacts(:john).becomes(Registrant) + registrant.update!(name: 'John', kind: 'priv', email: 'john@shop.test', + updated_at: Time.zone.parse('2010-07-05')) + + domain = domains(:shop) + domain.update!(registrant: registrant) + + whois_record = whois_records(:shop) + whois_record.update!(json: {}) + + generated_json = whois_record.generate_json + assert_equal 'John', generated_json[:registrant] + assert_equal 'priv', generated_json[:registrant_kind] + assert_equal 'john@shop.test', generated_json[:email] + assert_equal '2010-07-05T00:00:00+03:00', generated_json[:registrant_changed] + end + + def test_generates_json_with_admin_contacts + contact = contacts(:john) + contact.update!(name: 'John', email: 'john@shop.test', + updated_at: Time.zone.parse('2010-07-05')) + + domain = domains(:shop) + domain.admin_contacts = [contact] + + whois_record = whois_records(:shop) + whois_record.update!(json: {}) + + admin_contact_json = whois_record.generate_json[:admin_contacts].first + assert_equal 'John', admin_contact_json[:name] + assert_equal 'john@shop.test', admin_contact_json[:email] + assert_equal '2010-07-05T00:00:00+03:00', admin_contact_json[:changed] + end + + def test_generates_json_with_tech_contacts + contact = contacts(:john) + contact.update!(name: 'John', email: 'john@shop.test', + updated_at: Time.zone.parse('2010-07-05')) + + domain = domains(:shop) + domain.tech_contacts = [contact] + + whois_record = whois_records(:shop) + whois_record.update!(json: {}) + + tech_contact_json = whois_record.generate_json[:tech_contacts].first + assert_equal 'John', tech_contact_json[:name] + assert_equal 'john@shop.test', tech_contact_json[:email] + assert_equal '2010-07-05T00:00:00+03:00', tech_contact_json[:changed] + end end