Added additional tests to REPP API

This commit is contained in:
Sergei Tsõganov 2022-06-08 12:07:21 +03:00
parent b505de2f0f
commit b502c2779e
21 changed files with 796 additions and 7 deletions

View file

@ -12,7 +12,7 @@ class ReppV1ContactsListTest < ActionDispatch::IntegrationTest
def test_returns_registrar_contacts
get repp_v1_contacts_path, headers: @auth_headers
json = JSON.parse(response.body, symbolize_names: true)
assert_response :ok
assert_equal @user.registrar.contacts.count, json[:data][:count]
@ -21,7 +21,6 @@ class ReppV1ContactsListTest < ActionDispatch::IntegrationTest
assert json[:data][:contacts][0].is_a? String
end
def test_returns_detailed_registrar_contacts
get repp_v1_contacts_path(details: true), headers: @auth_headers
json = JSON.parse(response.body, symbolize_names: true)
@ -52,4 +51,32 @@ class ReppV1ContactsListTest < ActionDispatch::IntegrationTest
assert_equal (@user.registrar.contacts.count - offset), json[:data][:contacts].length
end
def test_returns_detailed_registrar_contacts_by_search_query
search_params = {
ident_type_eq: 'priv',
}
get repp_v1_contacts_path(details: true, q: search_params), headers: @auth_headers
json = JSON.parse(response.body, symbolize_names: true)
assert_response :ok
assert_equal json[:data][:contacts].length, 3
assert json[:data][:contacts][0].is_a? Hash
end
def test_returns_detailed_registrar_contacts_by_sort_query
contact = contacts(:william)
sort_params = {
s: 'name desc',
}
get repp_v1_contacts_path(details: true, q: sort_params), headers: @auth_headers
json = JSON.parse(response.body, symbolize_names: true)
assert_response :ok
assert_equal @user.registrar.contacts.count, json[:data][:count]
assert_equal @user.registrar.contacts.count, json[:data][:contacts].length
assert_equal json[:data][:contacts][0][:code], contact.code
end
end

View file

@ -0,0 +1,43 @@
require 'test_helper'
class ReppV1ContactsSearchTest < ActionDispatch::IntegrationTest
def setup
@user = users(:api_bestnames)
token = Base64.encode64("#{@user.username}:#{@user.plain_text_password}")
token = "Basic #{token}"
@auth_headers = { 'Authorization' => token }
end
def test_searches_all_contacts_by_id
contact = contacts(:john)
get "/repp/v1/contacts/search/#{contact.code}", headers: @auth_headers
json = JSON.parse(response.body, symbolize_names: true)
assert_response :ok
assert json[:data].is_a? Array
assert_equal json[:data][0][:value], contact.code
assert_equal json[:data][0][:label], "#{contact.code} #{contact.name}"
assert_equal json[:data][0][:selected], true
end
def test_searches_all_contacts_by_query
get '/repp/v1/contacts/search', headers: @auth_headers, params: { query: 'j' }
json = JSON.parse(response.body, symbolize_names: true)
assert_response :ok
assert json[:data].is_a? Array
assert_equal json[:data].length, 2
assert_equal json[:data][0][:selected], false
assert_equal json[:data][1][:selected], false
end
def test_searches_all_contacts_by_wrong_query
get '/repp/v1/contacts/search', headers: @auth_headers, params: { query: '000' }
json = JSON.parse(response.body, symbolize_names: true)
assert_response :ok
assert json[:data].is_a? Array
assert_equal json[:data].length, 0
end
end