mirror of
https://github.com/internetee/registry.git
synced 2025-06-07 13:15:40 +02:00
Add serializer for domain objects
This commit is contained in:
parent
8f8e86c09a
commit
bbd5421d5f
2 changed files with 99 additions and 0 deletions
45
lib/serializers/registrant_api/domain.rb
Normal file
45
lib/serializers/registrant_api/domain.rb
Normal file
|
@ -0,0 +1,45 @@
|
||||||
|
module Serializers
|
||||||
|
module RegistrantApi
|
||||||
|
class Domain
|
||||||
|
attr_reader :domain
|
||||||
|
|
||||||
|
def initialize(domain)
|
||||||
|
@domain = domain
|
||||||
|
end
|
||||||
|
|
||||||
|
def to_json
|
||||||
|
{
|
||||||
|
id: @domain.uuid,
|
||||||
|
name: @domain.name,
|
||||||
|
registrar: @domain.registrar.name,
|
||||||
|
registered_at: @domain.registered_at,
|
||||||
|
valid_to: @domain.valid_to,
|
||||||
|
created_at: @domain.created_at,
|
||||||
|
updated_at: @domain.updated_at,
|
||||||
|
registrant: @domain.registrant_name,
|
||||||
|
transfer_code: @domain.transfer_code,
|
||||||
|
name_dirty: @domain.name_dirty,
|
||||||
|
name_puny: @domain.name_puny,
|
||||||
|
period: @domain.period,
|
||||||
|
period_unit: @domain.period_unit,
|
||||||
|
creator_str: @domain.creator_str,
|
||||||
|
updator_str: @domain.updator_str,
|
||||||
|
legacy_id: @domain.legacy_id,
|
||||||
|
legacy_registrar_id: @domain.legacy_registrar_id,
|
||||||
|
legacy_registrant_id: @domain.legacy_registrant_id,
|
||||||
|
outzone_at: @domain.outzone_at,
|
||||||
|
delete_at: @domain.delete_at,
|
||||||
|
registrant_verification_asked_at: @domain.registrant_verification_asked_at,
|
||||||
|
registrant_verification_token: @domain.registrant_verification_token,
|
||||||
|
pending_json: @domain.pending_json,
|
||||||
|
force_delete_at: @domain.force_delete_at,
|
||||||
|
statuses: @domain.statuses,
|
||||||
|
locked_by_registrant_at: @domain.locked_by_registrant_at,
|
||||||
|
reserved: @domain.reserved,
|
||||||
|
status_notes: @domain.status_notes,
|
||||||
|
nameservers: @domain.nameservers.map(&:hostname),
|
||||||
|
}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
54
test/lib/serializers/registrant_api/domain_test.rb
Normal file
54
test/lib/serializers/registrant_api/domain_test.rb
Normal file
|
@ -0,0 +1,54 @@
|
||||||
|
require 'test_helper'
|
||||||
|
require 'serializers/registrant_api/domain'
|
||||||
|
|
||||||
|
class SerializersRegistrantApiDomainTest < ApplicationIntegrationTest
|
||||||
|
def setup
|
||||||
|
@domain = domains(:airport)
|
||||||
|
@serializer = Serializers::RegistrantApi::Domain.new(@domain)
|
||||||
|
@json = @serializer.to_json
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_returns_uuid_as_id
|
||||||
|
assert_equal(@domain.uuid, @json[:id])
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_returns_domain_locked_by_registrant_time_or_nil
|
||||||
|
assert_not(@json[:locked_by_registrant_at])
|
||||||
|
|
||||||
|
travel_to Time.zone.parse('2010-07-05 10:30')
|
||||||
|
@domain.apply_registry_lock
|
||||||
|
serializer_for_locked_domain = Serializers::RegistrantApi::Domain.new(@domain.reload)
|
||||||
|
new_json = serializer_for_locked_domain.to_json
|
||||||
|
|
||||||
|
assert_equal(Time.zone.parse('2010-07-05 10:30'), new_json[:locked_by_registrant_at])
|
||||||
|
travel_back
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_returns_registrar_name
|
||||||
|
assert_equal('Best Names', @json[:registrar])
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_returns_nameserver_hostnames_or_an_empty_array
|
||||||
|
expected_nameservers = ['ns1.bestnames.test', 'ns2.bestnames.test']
|
||||||
|
assert_equal(expected_nameservers.to_set, @json[:nameservers].to_set)
|
||||||
|
|
||||||
|
other_domain = domains(:hospital)
|
||||||
|
other_serializer = Serializers::RegistrantApi::Domain.new(other_domain)
|
||||||
|
new_json = other_serializer.to_json
|
||||||
|
|
||||||
|
assert_equal([], new_json[:nameservers])
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_other_fields_are_also_present
|
||||||
|
keys = %i[id name registrar registered_at valid_to created_at updated_at
|
||||||
|
registrant transfer_code name_dirty name_puny period period_unit
|
||||||
|
creator_str updator_str legacy_id legacy_registrar_id legacy_registrant_id
|
||||||
|
outzone_at delete_at registrant_verification_asked_at
|
||||||
|
registrant_verification_token pending_json force_delete_at statuses
|
||||||
|
locked_by_registrant_at reserved status_notes nameservers]
|
||||||
|
|
||||||
|
pp @json
|
||||||
|
|
||||||
|
assert_equal(keys, @json.keys & keys)
|
||||||
|
end
|
||||||
|
end
|
Loading…
Add table
Add a link
Reference in a new issue