mirror of
https://github.com/internetee/registry.git
synced 2025-06-09 06:04:56 +02:00
Add update endpoint for ContactRequests
This commit is contained in:
parent
1bbacbf56c
commit
b708cebbfd
5 changed files with 61 additions and 9 deletions
|
@ -4,20 +4,22 @@ class ApiV1ContactRequestTest < ActionDispatch::IntegrationTest
|
|||
def setup
|
||||
@api_key = "Basic #{ENV['api_shared_key']}"
|
||||
@headers = { "Authorization": "#{@api_key}" }
|
||||
@json_body = { "contact_request": valid_contact_request_body }.as_json
|
||||
@json_create = { "contact_request": valid_contact_request_create }.as_json
|
||||
@json_update = { "contact_request": valid_contact_request_update }.as_json
|
||||
@contact_request = contact_requests(:new)
|
||||
end
|
||||
|
||||
def test_authorizes_api_request
|
||||
post api_v1_contact_requests_path, params: @json_body, headers: @headers
|
||||
post api_v1_contact_requests_path, params: @json_create, headers: @headers
|
||||
assert_response :created
|
||||
|
||||
invalid_headers = { "Authorization": "Basic invalid_api_key" }
|
||||
post api_v1_contact_requests_path, params: @json_body, headers: invalid_headers
|
||||
post api_v1_contact_requests_path, params: @json_create, headers: invalid_headers
|
||||
assert_response :unauthorized
|
||||
end
|
||||
|
||||
def test_saves_new_contact_request
|
||||
request_body = @json_body.dup
|
||||
request_body = @json_create.dup
|
||||
random_mail = "#{rand(10000..99999)}@registry.test"
|
||||
request_body['contact_request']['email'] = random_mail
|
||||
|
||||
|
@ -29,11 +31,38 @@ class ApiV1ContactRequestTest < ActionDispatch::IntegrationTest
|
|||
assert ContactRequest::STATUS_NEW, contact_request.status
|
||||
end
|
||||
|
||||
def valid_contact_request_body
|
||||
def test_updates_existing_contact_request
|
||||
request_body = @json_update.dup
|
||||
|
||||
put api_v1_contact_request_path(@contact_request.id), params: request_body, headers: @headers
|
||||
assert_response :ok
|
||||
|
||||
@contact_request.reload
|
||||
assert ContactRequest::STATUS_CONFIRMED, @contact_request.status
|
||||
end
|
||||
|
||||
def test_not_updates_if_status_error
|
||||
request_body = @json_update.dup
|
||||
request_body['contact_request']['status'] = 'some_error_status'
|
||||
|
||||
put api_v1_contact_request_path(@contact_request.id), params: request_body, headers: @headers
|
||||
assert_response 400
|
||||
|
||||
@contact_request.reload
|
||||
assert ContactRequest::STATUS_NEW, @contact_request.status
|
||||
end
|
||||
|
||||
def valid_contact_request_create
|
||||
{
|
||||
"email": "aaa@bbb.com",
|
||||
"whois_record_id": "1",
|
||||
"name": "test"
|
||||
}.as_json
|
||||
end
|
||||
|
||||
def valid_contact_request_update
|
||||
{
|
||||
"status": "#{ContactRequest::STATUS_CONFIRMED}",
|
||||
}.as_json
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue