diff --git a/app/controllers/api/v1/registrant/domains_controller.rb b/app/controllers/api/v1/registrant/domains_controller.rb index a416aaec0..4e5c8bb28 100644 --- a/app/controllers/api/v1/registrant/domains_controller.rb +++ b/app/controllers/api/v1/registrant/domains_controller.rb @@ -1,3 +1,5 @@ +require 'serializers/registrant_api/domain' + module Api module V1 module Registrant @@ -17,7 +19,13 @@ module Api end @domains = associated_domains(current_registrant_user).limit(limit).offset(offset) - render json: @domains + + serialized_domains = @domains.map do |item| + serializer = Serializers::RegistrantApi::Domain.new(item) + serializer.to_json + end + + render json: serialized_domains end def show @@ -25,7 +33,8 @@ module Api @domain = domain_pool.find_by(uuid: params[:uuid]) if @domain - render json: @domain + serializer = Serializers::RegistrantApi::Domain.new(@domain) + render json: serializer.to_json else render json: { errors: [{ base: ['Domain not found'] }] }, status: :not_found end diff --git a/app/controllers/api/v1/registrant/registry_locks_controller.rb b/app/controllers/api/v1/registrant/registry_locks_controller.rb index 27c98cc9f..d431b5cd0 100644 --- a/app/controllers/api/v1/registrant/registry_locks_controller.rb +++ b/app/controllers/api/v1/registrant/registry_locks_controller.rb @@ -1,3 +1,5 @@ +require 'serializers/registrant_api/domain' + module Api module V1 module Registrant @@ -7,7 +9,7 @@ module Api def create if @domain.apply_registry_lock - render json: @domain + render json: serialized_domain(@domain) else render json: { errors: [{ base: ['Domain cannot be locked'] }] }, status: :unprocessable_entity @@ -16,7 +18,7 @@ module Api def destroy if @domain.remove_registry_lock - render json: @domain + render json: serialized_domain(@domain) else render json: { errors: [{ base: ['Domain is not locked'] }] }, status: :unprocessable_entity @@ -42,6 +44,11 @@ module Api ] }, status: :unauthorized and return end + + def serialized_domain(domain) + serializer = Serializers::RegistrantApi::Domain.new(domain) + serializer.to_json + end end end end diff --git a/db/migrate/20181002090319_remove_domain_status_field.rb b/db/migrate/20181002090319_remove_domain_status_field.rb new file mode 100644 index 000000000..29c4db931 --- /dev/null +++ b/db/migrate/20181002090319_remove_domain_status_field.rb @@ -0,0 +1,5 @@ +class RemoveDomainStatusField < ActiveRecord::Migration + def change + remove_column :domains, :status + end +end diff --git a/db/structure.sql b/db/structure.sql index 21d39236e..e9b0e7f43 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -885,7 +885,6 @@ CREATE TABLE public.domains ( name character varying, registrar_id integer NOT NULL, registered_at timestamp without time zone, - status character varying, valid_to timestamp without time zone NOT NULL, registrant_id integer NOT NULL, transfer_code character varying NOT NULL, @@ -4778,3 +4777,5 @@ INSERT INTO schema_migrations (version) VALUES ('20180824092855'); INSERT INTO schema_migrations (version) VALUES ('20180824102834'); +INSERT INTO schema_migrations (version) VALUES ('20181002090319'); + diff --git a/doc/registrant-api/v1/domain.md b/doc/registrant-api/v1/domain.md index 09495220d..eeb1bfccc 100644 --- a/doc/registrant-api/v1/domain.md +++ b/doc/registrant-api/v1/domain.md @@ -11,63 +11,108 @@ Returns domains of the current registrant. | ---------- | -------- | ---- | -------------- | ----------- | | limit | false | Integer | [1..200] | How many domains to show | | offset | false | Integer | | Domain number to start at | -| details | false | String | ["true", "false"] | Whether to include details | - -#### Request -``` -GET api/v1/registrant/domains?limit=1&details=true HTTP/1.1 -Accept: application/json -Authorization: Bearer Z2l0bGFiOmdoeXQ5ZTRmdQ== -Content-Type: application/json -``` #### Response ``` HTTP/1.1 200 Content-Type: application/json -{ - "domains": [ - { - "uuid": "98d1083a-8863-4153-93e4-caee4a013535", - "name": "domain0.ee", - "registrar_id": 2, - "registered_at": "2015-09-09T09:11:14.861Z", - "status": null, - "valid_from": "2015-09-09T09:11:14.861Z", - "valid_to": "2016-09-09T09:11:14.861Z", - "registrant_id": 1, - "transfer_code": "98oiewslkfkd", - "created_at": "2015-09-09T09:11:14.861Z", - "updated_at": "2015-09-09T09:11:14.860Z", - "name_dirty": "domain0.ee", - "name_puny": "domain0.ee", - "period": 1, - "period_unit": "y", - "creator_str": null, - "updator_str": null, - "legacy_id": null, - "legacy_registrar_id": null, - "legacy_registrant_id": null, - "outzone_at": "2016-09-24T09:11:14.861Z", - "delete_at": "2016-10-24T09:11:14.861Z", - "registrant_verification_asked_at": null, - "registrant_verification_token": null, - "pending_json": { +[ + { + "id":"98d1083a-8863-4153-93e4-caee4a013535", + "name":"domain0.ee", + "registrar":{ + "name":"Best Names", + "website":"example.com" + }, + "valid_to":"2016-09-09T09:11:14.861Z", + "registered_at":"2015-09-09T09:11:14.861Z", + "registrant":{ + "name":"John Smith", + "id":"acadf23e-47c4-4606-8f67-76e071a1cca2" + }, + "admin_contacts":[ + { + "name":"John Smith", + "id":"62015e7d-42c8-4d68-8164-e9b71680fd95" }, - "force_delete_at": null, - "statuses": [ - "ok" - ], - "reserved": false, - "status_notes": { + { + "name":"William Smith", + "id":"a041c5b6-7772-4fac-83cd-fbce3b2c8867" + } + ], + "tech_contacts":[ + { + "name":"John Smith", + "id":"62015e7d-42c8-4d68-8164-e9b71680fd95" }, - "statuses_backup": [ - ] - } - ], - "total_number_of_records": 2 -} + { + "name":"William Smith", + "id":"a041c5b6-7772-4fac-83cd-fbce3b2c8867" + } + ], + "transfer_code":"98oiewslkfkd", + "created_at":"2015-09-09T09:11:14.861Z", + "updated_at":"2015-09-09T09:11:14.860Z", + "name_dirty":"domain0.ee", + "name_puny":"domain0.ee", + "period":1, + "period_unit":"y", + "creator_str":null, + "updator_str":null, + "legacy_id":null, + "legacy_registrar_id":null, + "legacy_registrant_id":null, + "outzone_at":"2016-09-24T09:11:14.861Z", + "delete_at":"2016-10-24T09:11:14.861Z", + "registrant_verification_asked_at":null, + "registrant_verification_token":null, + "locked_by_registrant_at":"2015-09-09T09:11:14.861Z", + "pending_json":{ + + }, + "force_delete_at":null, + "statuses":[ + "ok" + ], + "nameservers":[ + { + "hostname":"ns1.bestnames.test", + "ipv4":[ + "173.245.58.41" + ], + "ipv6":[ + "2400:cb00:2049:1::adf5:3a33" + ] + }, + { + "hostname":"ns1.bestnames.test", + "ipv4":[ + "173.245.58.51" + ], + "ipv6":[ + "2400:cb00:2049:1::adf5:3b29" + ] + }, + + ], + "reserved":false, + "status_notes":{ + + }, + "statuses_backup":[ + + ] + } +] +``` + +#### Request +``` +GET api/v1/registrant/domains HTTP/1.1 +Accept: application/json +Authorization: Bearer Z2l0bGFiOmdoeXQ5ZTRmdQ== +Content-Type: application/json ``` ## GET api/v1/registrant/domains @@ -77,7 +122,7 @@ Returns domain names with offset. #### Request ``` -GET api/v1/registrant/domains?offset=1 HTTP/1.1 +GET api/v1/registrant/domains?offset=1&limit=1 HTTP/1.1 Accept: application/json Authorization: Bearer Z2l0bGFiOmdoeXQ5ZTRmdQ== Content-Type: application/json @@ -88,12 +133,94 @@ Content-Type: application/json HTTP/1.1 200 Content-Type: application/json -{ - "domains": [ - "domain1.ee" - ], - "total_number_of_records": 2 -} +[ + { + "id":"98d1083a-8863-4153-93e4-caee4a013535", + "name":"domain0.ee", + "registrar":{ + "name":"Best Names", + "website":"example.com" + }, + "valid_to":"2016-09-09T09:11:14.861Z", + "registered_at":"2015-09-09T09:11:14.861Z", + "registrant":{ + "name":"John Smith", + "id":"acadf23e-47c4-4606-8f67-76e071a1cca2" + }, + "admin_contacts":[ + { + "name":"John Smith", + "id":"62015e7d-42c8-4d68-8164-e9b71680fd95" + }, + { + "name":"William Smith", + "id":"a041c5b6-7772-4fac-83cd-fbce3b2c8867" + } + ], + "tech_contacts":[ + { + "name":"John Smith", + "id":"62015e7d-42c8-4d68-8164-e9b71680fd95" + }, + { + "name":"William Smith", + "id":"a041c5b6-7772-4fac-83cd-fbce3b2c8867" + } + ], + "transfer_code":"98oiewslkfkd", + "created_at":"2015-09-09T09:11:14.861Z", + "updated_at":"2015-09-09T09:11:14.860Z", + "name_dirty":"domain0.ee", + "name_puny":"domain0.ee", + "period":1, + "period_unit":"y", + "creator_str":null, + "updator_str":null, + "legacy_id":null, + "legacy_registrar_id":null, + "legacy_registrant_id":null, + "outzone_at":"2016-09-24T09:11:14.861Z", + "delete_at":"2016-10-24T09:11:14.861Z", + "registrant_verification_asked_at":null, + "registrant_verification_token":null, + "locked_by_registrant_at":"2015-09-09T09:11:14.861Z", + "pending_json":{ + + }, + "force_delete_at":null, + "statuses":[ + "ok" + ], + "nameservers":[ + { + "hostname":"ns1.bestnames.test", + "ipv4":[ + "173.245.58.41" + ], + "ipv6":[ + "2400:cb00:2049:1::adf5:3a33" + ] + }, + { + "hostname":"ns1.bestnames.test", + "ipv4":[ + "173.245.58.51" + ], + "ipv6":[ + "2400:cb00:2049:1::adf5:3b29" + ] + }, + + ], + "reserved":false, + "status_notes":{ + + }, + "statuses_backup":[ + + ] + } +] ``` ## GET api/v1/registrant/domains/$UUID @@ -116,38 +243,89 @@ HTTP/1.1 200 Content-Type: application/json { - "uuid": "98d1083a-8863-4153-93e4-caee4a013535", - "name": "domain0.ee", - "registrar_id": 2, - "registered_at": "2015-09-09T09:11:14.861Z", - "status": null, - "valid_from": "2015-09-09T09:11:14.861Z", - "valid_to": "2016-09-09T09:11:14.861Z", - "registrant_id": 1, - "transfer_code": "98oiewslkfkd", - "created_at": "2015-09-09T09:11:14.861Z", - "updated_at": "2015-09-09T09:11:14.860Z", - "name_dirty": "domain0.ee", - "name_puny": "domain0.ee", - "period": 1, - "period_unit": "y", - "creator_str": null, - "updator_str": null, - "legacy_id": null, - "legacy_registrar_id": null, - "legacy_registrant_id": null, - "outzone_at": "2016-09-24T09:11:14.861Z", - "delete_at": "2016-10-24T09:11:14.861Z", - "registrant_verification_asked_at": null, - "registrant_verification_token": null, - "pending_json": {}, - "force_delete_at": null, - "statuses": [ + "id":"98d1083a-8863-4153-93e4-caee4a013535", + "name":"domain0.ee", + "registrar":{ + "name":"Best Names", + "website":"example.com" + }, + "valid_to":"2016-09-09T09:11:14.861Z", + "registered_at":"2015-09-09T09:11:14.861Z", + "registrant":{ + "name":"John Smith", + "id":"acadf23e-47c4-4606-8f67-76e071a1cca2" + }, + "admin_contacts":[ + { + "name":"John Smith", + "id":"62015e7d-42c8-4d68-8164-e9b71680fd95" + }, + { + "name":"William Smith", + "id":"a041c5b6-7772-4fac-83cd-fbce3b2c8867" + } + ], + "tech_contacts":[ + { + "name":"John Smith", + "id":"62015e7d-42c8-4d68-8164-e9b71680fd95" + }, + { + "name":"William Smith", + "id":"a041c5b6-7772-4fac-83cd-fbce3b2c8867" + } + ], + "transfer_code":"98oiewslkfkd", + "created_at":"2015-09-09T09:11:14.861Z", + "updated_at":"2015-09-09T09:11:14.860Z", + "name_dirty":"domain0.ee", + "name_puny":"domain0.ee", + "period":1, + "period_unit":"y", + "creator_str":null, + "updator_str":null, + "legacy_id":null, + "legacy_registrar_id":null, + "legacy_registrant_id":null, + "outzone_at":"2016-09-24T09:11:14.861Z", + "delete_at":"2016-10-24T09:11:14.861Z", + "registrant_verification_asked_at":null, + "registrant_verification_token":null, + "locked_by_registrant_at":"2015-09-09T09:11:14.861Z", + "pending_json":{ + + }, + "force_delete_at":null, + "statuses":[ "ok" ], - "reserved": false, - "status_notes": {}, - "statuses_backup": [] + "nameservers":[ + { + "hostname":"ns1.bestnames.test", + "ipv4":[ + "173.245.58.41" + ], + "ipv6":[ + "2400:cb00:2049:1::adf5:3a33" + ] + }, + { + "hostname":"ns1.bestnames.test", + "ipv4":[ + "173.245.58.51" + ], + "ipv6":[ + "2400:cb00:2049:1::adf5:3b29" + ] + } + ], + "reserved":false, + "status_notes":{ + + }, + "statuses_backup":[ + + ] } ``` diff --git a/doc/registrant-api/v1/registry_lock.md b/doc/registrant-api/v1/registry_lock.md index b8d440554..553c7b28e 100644 --- a/doc/registrant-api/v1/registry_lock.md +++ b/doc/registrant-api/v1/registry_lock.md @@ -19,40 +19,91 @@ HTTP/1.1 200 Content-Type: application/json { - "uuid": "98d1083a-8863-4153-93e4-caee4a013535", - "name": "domain0.ee", - "registrar_id": 2, - "registered_at": "2015-09-09T09:11:14.861Z", - "status": null, - "valid_from": "2015-09-09T09:11:14.861Z", - "valid_to": "2016-09-09T09:11:14.861Z", - "registrant_id": 1, - "transfer_code": "98oiewslkfkd", - "created_at": "2015-09-09T09:11:14.861Z", - "updated_at": "2015-09-09T09:11:14.860Z", - "name_dirty": "domain0.ee", - "name_puny": "domain0.ee", - "period": 1, - "period_unit": "y", - "creator_str": null, - "updator_str": null, - "legacy_id": null, - "legacy_registrar_id": null, - "legacy_registrant_id": null, - "outzone_at": "2016-09-24T09:11:14.861Z", - "delete_at": "2016-10-24T09:11:14.861Z", - "registrant_verification_asked_at": null, - "registrant_verification_token": null, - "pending_json": {}, - "force_delete_at": null, - "statuses": [ + "id":"98d1083a-8863-4153-93e4-caee4a013535", + "name":"domain0.ee", + "registrar":{ + "name":"Best Names", + "website":"example.com" + }, + "registrant":{ + "name":"John Smith", + "id":"acadf23e-47c4-4606-8f67-76e071a1cca2" + }, + "admin_contacts":[ + { + "name":"John Smith", + "id":"62015e7d-42c8-4d68-8164-e9b71680fd95" + }, + { + "name":"William Smith", + "id":"a041c5b6-7772-4fac-83cd-fbce3b2c8867" + } + ], + "tech_contacts":[ + { + "name":"John Smith", + "id":"62015e7d-42c8-4d68-8164-e9b71680fd95" + }, + { + "name":"William Smith", + "id":"a041c5b6-7772-4fac-83cd-fbce3b2c8867" + } + ], + "registered_at":"2015-09-09T09:11:14.861Z", + "valid_to":"2016-09-09T09:11:14.861Z", + "transfer_code":"98oiewslkfkd", + "created_at":"2015-09-09T09:11:14.861Z", + "updated_at":"2015-09-09T09:11:14.860Z", + "name_dirty":"domain0.ee", + "name_puny":"domain0.ee", + "period":1, + "period_unit":"y", + "creator_str":null, + "updator_str":null, + "legacy_id":null, + "legacy_registrar_id":null, + "legacy_registrant_id":null, + "outzone_at":"2016-09-24T09:11:14.861Z", + "delete_at":"2016-10-24T09:11:14.861Z", + "registrant_verification_asked_at":null, + "registrant_verification_token":null, + "locked_by_registrant_at":"2015-09-09T09:11:14.861Z", + "pending_json":{ + + }, + "force_delete_at":null, + "statuses":[ "serverUpdateProhibited", "serverDeleteProhibited", "serverTransferProhibited" ], - "reserved": false, - "status_notes": {}, - "statuses_backup": [] + "nameservers":[ + { + "hostname":"ns1.bestnames.test", + "ipv4":[ + "173.245.58.41" + ], + "ipv6":[ + "2400:cb00:2049:1::adf5:3a33" + ] + }, + { + "hostname":"ns1.bestnames.test", + "ipv4":[ + "173.245.58.51" + ], + "ipv6":[ + "2400:cb00:2049:1::adf5:3b29" + ] + } + ], + "reserved":false, + "status_notes":{ + + }, + "statuses_backup":[ + + ] } ``` @@ -113,38 +164,89 @@ HTTP/1.1 200 Content-Type: application/json { - "uuid": "98d1083a-8863-4153-93e4-caee4a013535", - "name": "domain0.ee", - "registrar_id": 2, - "registered_at": "2015-09-09T09:11:14.861Z", - "status": null, - "valid_from": "2015-09-09T09:11:14.861Z", - "valid_to": "2016-09-09T09:11:14.861Z", - "registrant_id": 1, - "transfer_code": "98oiewslkfkd", - "created_at": "2015-09-09T09:11:14.861Z", - "updated_at": "2015-09-09T09:11:14.860Z", - "name_dirty": "domain0.ee", - "name_puny": "domain0.ee", - "period": 1, - "period_unit": "y", - "creator_str": null, - "updator_str": null, - "legacy_id": null, - "legacy_registrar_id": null, - "legacy_registrant_id": null, - "outzone_at": "2016-09-24T09:11:14.861Z", - "delete_at": "2016-10-24T09:11:14.861Z", - "registrant_verification_asked_at": null, - "registrant_verification_token": null, - "pending_json": {}, - "force_delete_at": null, - "statuses": [ + "id":"98d1083a-8863-4153-93e4-caee4a013535", + "name":"domain0.ee", + "registrar":{ + "name":"Best Names", + "website":"example.com" + }, + "registered_at":"2015-09-09T09:11:14.861Z", + "valid_to":"2016-09-09T09:11:14.861Z", + "registrant":{ + "name":"John Smith", + "id":"acadf23e-47c4-4606-8f67-76e071a1cca2" + }, + "admin_contacts":[ + { + "name":"John Smith", + "id":"62015e7d-42c8-4d68-8164-e9b71680fd95" + }, + { + "name":"William Smith", + "id":"a041c5b6-7772-4fac-83cd-fbce3b2c8867" + } + ], + "tech_contacts":[ + { + "name":"John Smith", + "id":"62015e7d-42c8-4d68-8164-e9b71680fd95" + }, + { + "name":"William Smith", + "id":"a041c5b6-7772-4fac-83cd-fbce3b2c8867" + } + ], + "transfer_code":"98oiewslkfkd", + "created_at":"2015-09-09T09:11:14.861Z", + "updated_at":"2015-09-09T09:11:14.860Z", + "name_dirty":"domain0.ee", + "name_puny":"domain0.ee", + "period":1, + "period_unit":"y", + "creator_str":null, + "updator_str":null, + "legacy_id":null, + "legacy_registrar_id":null, + "legacy_registrant_id":null, + "outzone_at":"2016-09-24T09:11:14.861Z", + "delete_at":"2016-10-24T09:11:14.861Z", + "registrant_verification_asked_at":null, + "registrant_verification_token":null, + "locked_by_registrant_at":null, + "pending_json":{ + + }, + "force_delete_at":null, + "statuses":[ "ok" ], - "reserved": false, - "status_notes": {}, - "statuses_backup": [] + "nameservers":[ + { + "hostname":"ns1.bestnames.test", + "ipv4":[ + "173.245.58.41" + ], + "ipv6":[ + "2400:cb00:2049:1::adf5:3a33" + ] + }, + { + "hostname":"ns1.bestnames.test", + "ipv4":[ + "173.245.58.51" + ], + "ipv6":[ + "2400:cb00:2049:1::adf5:3b29" + ] + } + ], + "reserved":false, + "status_notes":{ + + }, + "statuses_backup":[ + + ] } ``` diff --git a/lib/serializers/registrant_api/domain.rb b/lib/serializers/registrant_api/domain.rb new file mode 100644 index 000000000..d6adf61ee --- /dev/null +++ b/lib/serializers/registrant_api/domain.rb @@ -0,0 +1,83 @@ +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: { + name: domain.registrar.name, + website: domain.registrar.website, + }, + registered_at: domain.registered_at, + valid_to: domain.valid_to, + created_at: domain.created_at, + updated_at: domain.updated_at, + registrant: { + name: domain.registrant.name, + id: domain.registrant.uuid, + }, + tech_contacts: contacts(:tech), + admin_contacts: contacts(:admin), + 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: nameservers, + } + end + + private + + def contacts(type) + contact_pool = begin + if type == :tech + domain.tech_contacts + elsif type == :admin + domain.admin_contacts + end + end + + array_of_contacts = [] + contact_pool.map do |contact| + array_of_contacts.push(name: contact.name, id: contact.uuid) + end + + array_of_contacts + end + + def nameservers + array_of_nameservers = [] + + domain.nameservers.map do |nameserver| + array_of_nameservers.push(hostname: nameserver.hostname, ipv4: nameserver.ipv4, + ipv6: nameserver.ipv6) + end + + array_of_nameservers + end + end + end +end diff --git a/test/fixtures/domains.yml b/test/fixtures/domains.yml index 5c4744e49..792953bbd 100644 --- a/test/fixtures/domains.yml +++ b/test/fixtures/domains.yml @@ -48,6 +48,7 @@ metro: hospital: name: hospital.test + name_dirty: hospital.test registrar: goodnames registrant: john transfer_code: 23118v2 diff --git a/test/fixtures/nameservers.yml b/test/fixtures/nameservers.yml index 344f7894d..97e2a3c1c 100644 --- a/test/fixtures/nameservers.yml +++ b/test/fixtures/nameservers.yml @@ -16,10 +16,20 @@ shop_ns2: airport_ns1: hostname: ns1.bestnames.test + ipv4: + - 192.0.2.2 + ipv6: + - 2001:db8::2 domain: airport airport_ns2: hostname: ns2.bestnames.test + ipv4: + - 192.0.2.0 + - 192.0.2.3 + - 192.0.2.1 + ipv6: + - 2001:db8::1 domain: airport metro_ns1: diff --git a/test/fixtures/registrars.yml b/test/fixtures/registrars.yml index d3d6b1c20..038046220 100644 --- a/test/fixtures/registrars.yml +++ b/test/fixtures/registrars.yml @@ -11,6 +11,7 @@ bestnames: accounting_customer_code: bestnames language: en billing_email: billing@example.com + website: bestnames.test goodnames: name: Good Names @@ -41,4 +42,4 @@ complete: language: en vat_no: US12345 vat_rate: 0.05 - billing_email: billing@bestnames.test \ No newline at end of file + billing_email: billing@bestnames.test diff --git a/test/integration/api/registrant/registrant_api_domains_test.rb b/test/integration/api/registrant/registrant_api_domains_test.rb index 0764db3aa..9720373a1 100644 --- a/test/integration/api/registrant/registrant_api_domains_test.rb +++ b/test/integration/api/registrant/registrant_api_domains_test.rb @@ -27,7 +27,17 @@ class RegistrantApiDomainsTest < ApplicationIntegrationTest assert_equal(200, response.status) domain = JSON.parse(response.body, symbolize_names: true) + assert_equal('hospital.test', domain[:name]) + assert_equal('5edda1a5-3548-41ee-8b65-6d60daf85a37', domain[:id]) + assert_equal({name: 'John', id: 'eb2f2766-b44c-4e14-9f16-32ab1a7cb957'}, domain[:registrant]) + assert_equal([{name: 'John', id: 'eb2f2766-b44c-4e14-9f16-32ab1a7cb957'}], + domain[:admin_contacts]) + assert_equal([{name: 'John', id: 'eb2f2766-b44c-4e14-9f16-32ab1a7cb957'}], + domain[:tech_contacts]) + assert_equal({ name: 'Good Names', website: nil }, domain[:registrar]) + assert_equal([], domain[:nameservers]) + assert(domain.has_key?(:locked_by_registrant_at)) end def test_get_non_existent_domain_details_by_uuid @@ -45,6 +55,9 @@ class RegistrantApiDomainsTest < ApplicationIntegrationTest response_json = JSON.parse(response.body, symbolize_names: true) array_of_domain_names = response_json.map { |x| x[:name] } assert(array_of_domain_names.include?('hospital.test')) + + array_of_domain_registrars = response_json.map { |x| x[:registrar] } + assert(array_of_domain_registrars.include?({name: 'Good Names', website: nil})) end def test_root_accepts_limit_and_offset_parameters diff --git a/test/integration/api/registrant/registrant_api_registry_locks_test.rb b/test/integration/api/registrant/registrant_api_registry_locks_test.rb index bb50bdc1b..d35952a73 100644 --- a/test/integration/api/registrant/registrant_api_registry_locks_test.rb +++ b/test/integration/api/registrant/registrant_api_registry_locks_test.rb @@ -77,6 +77,7 @@ class RegistrantApiRegistryLocksTest < ApplicationIntegrationTest response_json = JSON.parse(response.body, symbolize_names: true) assert(response_json[:statuses].include?(DomainStatus::OK)) + refute(response_json[:locked_by_registrant_at]) @domain.reload refute(@domain.locked_by_registrant?) end @@ -121,6 +122,26 @@ class RegistrantApiRegistryLocksTest < ApplicationIntegrationTest assert(response_json[:statuses].include?(DomainStatus::SERVER_UPDATE_PROHIBITED)) end + def test_locking_domains_returns_serialized_domain_object + post '/api/v1/registrant/domains/1b3ee442-e8fe-4922-9492-8fcb9dccc69c/registry_lock', + {}, @auth_headers + + assert_equal(200, response.status) + response_json = JSON.parse(response.body, symbolize_names: true) + + assert_equal({ name: 'Best Names', website: 'bestnames.test' }, response_json[:registrar]) + assert_equal({name: 'John', id: 'eb2f2766-b44c-4e14-9f16-32ab1a7cb957'}, response_json[:registrant]) + assert_equal([{name: 'Jane', id: '9db3de62-2414-4487-bee2-d5c155567768'}], response_json[:admin_contacts]) + assert_equal([{name: 'William', id: '0aa54704-d6f7-4ca9-b8ca-2827d9a4e4eb'}, + {name: 'Acme Ltd', id: 'f1dd365c-5be9-4b3d-a44e-3fa002465e4d'}], + response_json[:tech_contacts]) + assert_equal( + [{hostname: 'ns1.bestnames.test', ipv4: ['192.0.2.1'], ipv6: ['2001:db8::1']}, + {hostname: 'ns2.bestnames.test', ipv4: ['192.0.2.2'], ipv6: ['2001:db8::2']}].to_set, + response_json[:nameservers].to_set) + assert_equal(Time.zone.parse('2010-07-05'), response_json[:locked_by_registrant_at]) + end + private def auth_token diff --git a/test/lib/serializers/registrant_api/domain_test.rb b/test/lib/serializers/registrant_api/domain_test.rb new file mode 100644 index 000000000..bddb0efd7 --- /dev/null +++ b/test/lib/serializers/registrant_api/domain_test.rb @@ -0,0 +1,78 @@ +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({name: 'Best Names', website: 'bestnames.test' }, @json[:registrar]) + end + + def test_returns_registrant_name_and_uuid + assert_equal({name: 'John', id: 'eb2f2766-b44c-4e14-9f16-32ab1a7cb957'}, + @json[:registrant]) + end + + def test_returns_contacts_name_and_uuid + assert_equal([{name: 'John', id: 'eb2f2766-b44c-4e14-9f16-32ab1a7cb957'}, + {name: 'William', id: '0aa54704-d6f7-4ca9-b8ca-2827d9a4e4eb'}].to_set, + @json[:admin_contacts].to_set) + + assert_equal([{name: 'William', id: '0aa54704-d6f7-4ca9-b8ca-2827d9a4e4eb'}].to_set, + @json[:tech_contacts].to_set) + end + + def test_returns_nameserver_hostnames_or_an_empty_array + expected_nameserver_1 = { + hostname: 'ns1.bestnames.test', + ipv4: ['192.0.2.2'], + ipv6: ['2001:db8::2'] + } + + expected_nameserver_2 = { + hostname: 'ns2.bestnames.test', + ipv4: ['192.0.2.0', '192.0.2.3', '192.0.2.1'], + ipv6: ['2001:db8::1'] + } + + assert(@json[:nameservers].include?(expected_nameserver_1)) + assert(@json[:nameservers].include?(expected_nameserver_2)) + + 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 tech_contacts admin_contacts 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] + + assert_equal(keys, @json.keys & keys) + end +end