mirror of
https://github.com/internetee/registry.git
synced 2025-06-06 04:37:30 +02:00
refactoring
This commit is contained in:
parent
a87fd6a8b7
commit
ece988fca1
6 changed files with 95 additions and 53 deletions
|
@ -1,4 +1,4 @@
|
|||
require 'serializers/repp/domain'
|
||||
require 'serializers/repp/contact'
|
||||
|
||||
module Api
|
||||
module V1
|
||||
|
@ -9,7 +9,8 @@ module Api
|
|||
|
||||
if @contact
|
||||
render json: { contact: Serializers::Repp::Contact.new(@contact,
|
||||
show_address: false).to_json }, status: :found
|
||||
show_address: false).to_json },
|
||||
status: :found
|
||||
else
|
||||
render json: { errors: 'Contact not found' }, status: :not_found
|
||||
end
|
||||
|
|
|
@ -9,7 +9,8 @@ module Api
|
|||
|
||||
if @domain
|
||||
render json: { domain: Serializers::Repp::Domain.new(@domain,
|
||||
sponsored: true).to_json }, status: :found
|
||||
sponsored: true).to_json },
|
||||
status: :found
|
||||
else
|
||||
render json: { errors: 'Domain not found' }, status: :not_found
|
||||
end
|
||||
|
|
33
test/integration/api/accreditation_center/auth_test.rb
Normal file
33
test/integration/api/accreditation_center/auth_test.rb
Normal file
|
@ -0,0 +1,33 @@
|
|||
require 'test_helper'
|
||||
|
||||
class AuthTest < ApplicationIntegrationTest
|
||||
def setup
|
||||
super
|
||||
|
||||
@user = users(:api_bestnames)
|
||||
@header = { 'Authorization' => "Basic #{generate_base64}" }
|
||||
end
|
||||
|
||||
def test_should_return_successful
|
||||
get 'https://registry.test/api/v1/accreditation_center/auth', headers: @header
|
||||
|
||||
json = JSON.parse(response.body, symbolize_names: true)
|
||||
assert_equal json[:code], 1000
|
||||
assert_equal json[:message], 'Command completed successfully'
|
||||
end
|
||||
|
||||
def test_should_return_failed
|
||||
get 'https://registry.test/api/v1/accreditation_center/auth', headers: { 'Authorization' => "Basic LAHSDHDSAFSF#@" }
|
||||
|
||||
json = JSON.parse(response.body, symbolize_names: true)
|
||||
|
||||
assert_equal json[:code], 2202
|
||||
assert_equal json[:message], 'Invalid authorization information'
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def generate_base64
|
||||
Base64.encode64("#{@user.username}:#{@user.plain_text_password}")
|
||||
end
|
||||
end
|
|
@ -8,9 +8,16 @@ class ContactsTest < ApplicationIntegrationTest
|
|||
end
|
||||
|
||||
def test_return_code_error_if_valid_domain_name
|
||||
get "/api/v1/accreditation_center/contacts/?id=Alyosha"
|
||||
get '/api/v1/accreditation_center/contacts/?id=Alyosha'
|
||||
json = JSON.parse(response.body, symbolize_names: true)
|
||||
|
||||
assert_equal json[:errors], "Contact not found"
|
||||
assert_equal json[:errors], 'Contact not found'
|
||||
end
|
||||
|
||||
def test_return_code_error_if_sdfsdf
|
||||
get "/api/v1/accreditation_center/contacts/?id=#{@contact.code}"
|
||||
json = JSON.parse(response.body, symbolize_names: true)
|
||||
|
||||
assert_equal json[:contact][:name], 'John'
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue