implement api endpoint for record results

This commit is contained in:
Oleg Hasjanov 2021-08-06 12:26:41 +03:00 committed by olegphenomenon
parent d56c61bf84
commit 8a1967bdb9
5 changed files with 104 additions and 57 deletions

View file

@ -15,7 +15,9 @@ class ReppV1AccreditationInfoTest < ActionDispatch::IntegrationTest
assert_response :ok
assert_equal json[:data][:username], @user.username
assert_equal json[:data][:identity_code], @user.identity_code
assert json[:data][:roles].include? 'super'
assert_equal json[:data][:registrar_name], 'Best Names'
assert_equal json[:data][:registrar_reg_no], '1234'
end
def test_invalid_login

View file

@ -0,0 +1,49 @@
require 'test_helper'
class ReppV1AccreditationResultsTest < ActionDispatch::IntegrationTest
TEMPARY_SECRET_KEY = 'tempary-secret-key'.freeze
def setup
@user = users(:api_bestnames)
token = "Basic #{TEMPARY_SECRET_KEY}"
@auth_headers = { 'Authorization' => token }
end
def test_should_return_valid_response
post '/repp/v1/registrar/accreditation/push_results',
headers: @auth_headers,
params: {accreditation_result: {username: @user.username, result: true} }
json = JSON.parse(response.body, symbolize_names: true)
assert_response :ok
assert_equal json[:data][:user][:username], @user.username
assert_equal json[:data][:result], "true"
assert_equal json[:data][:message], "Accreditation info successfully added"
end
def test_should_return_valid_response_invalid_authorization
post '/repp/v1/registrar/accreditation/push_results',
headers: { 'Authorization' => 'Basic tempary-secret-ke'},
params: {accreditation_result: {username: @user.username, result: true} }
json = JSON.parse(response.body, symbolize_names: true)
assert_response :unauthorized
assert_equal json[:code], 2202
assert_equal json[:message], 'Invalid authorization information'
end
def test_should_return_valid_response_record_exception
post '/repp/v1/registrar/accreditation/push_results',
headers: @auth_headers,
params: {accreditation_result: { username: "chungachanga", result: true} }
json = JSON.parse(response.body, symbolize_names: true)
assert_response :ok
assert_equal json[:code], 2303
assert_equal json[:message], "Object 'chungachanga' does not exist"
end
end