diff --git a/app/controllers/api/v1/registrant/domains_controller.rb b/app/controllers/api/v1/registrant/domains_controller.rb index 44662c673..be755b55c 100644 --- a/app/controllers/api/v1/registrant/domains_controller.rb +++ b/app/controllers/api/v1/registrant/domains_controller.rb @@ -4,12 +4,15 @@ module Api module V1 module Registrant class DomainsController < ActionController::API - def index - render json: { success: true } - end def show - render json: { success: true } + @domain = Domain.find_by(uuid: params[:uuid]) + + if @domain + render json: @domain + else + render json: { errors: ["Domain not found"] }, status: :not_found + end end end end diff --git a/config/application.rb b/config/application.rb index 400e72124..1420d3cd3 100644 --- a/config/application.rb +++ b/config/application.rb @@ -36,7 +36,7 @@ module DomainNameRegistry config.i18n.default_locale = :en config.paths.add File.join('app', 'api'), glob: File.join('**', '*.rb') - config.autoload_paths += Dir[Rails.root.join('app', 'api', '*')] + # config.autoload_paths += Dir[Rails.root.join('app', 'api', '*')] # Autoload all model subdirs config.autoload_paths += Dir[Rails.root.join('app', 'models', '**/')] diff --git a/test/fixtures/domains.yml b/test/fixtures/domains.yml index 38500e9cc..4d6468c92 100644 --- a/test/fixtures/domains.yml +++ b/test/fixtures/domains.yml @@ -45,7 +45,7 @@ metro: hospital: name: hospital.test registrar: goodnames - registrant: william + registrant: john transfer_code: 23118v2 valid_to: 2010-07-05 period: 1 diff --git a/test/system/api/registrant/registrant_api_domains_test.rb b/test/system/api/registrant/registrant_api_domains_test.rb index 6a53f7720..36a9def35 100644 --- a/test/system/api/registrant/registrant_api_domains_test.rb +++ b/test/system/api/registrant/registrant_api_domains_test.rb @@ -4,14 +4,31 @@ class RegistrantApiDomainsTest < ApplicationSystemTestCase def setup super - @registrant = contacts(:william) + @domain = domains(:hospital) + @registrant = @domain.registrant end def teardown super end + def test_get_domain_details_by_uuid + get '/api/v1/registrant/domains/5edda1a5-3548-41ee-8b65-6d60daf85a37' + assert_equal(200, response.status) - def test_can_get_domain_details_by_uuid + domain = JSON.parse(response.body, symbolize_names: true) + assert_equal('hospital.test', domain[:name]) + end + + def test_get_non_existent_domain_details_by_uuid + get '/api/v1/registrant/domains/random-uuid' + assert_equal(404, response.status) + + response_json = JSON.parse(response.body, symbolize_names: true) + assert_equal({errors: ['Domain not found']}, response_json) + end + + def test_get_non_registrar_domain_details_by_uuid + # no op end end