Merge pull request #1052 from internetee/switch-tests-to-js-content-type

Switch tests to js content type
This commit is contained in:
Timo Võhmar 2018-12-07 13:11:58 +02:00 committed by GitHub
commit 59db269240
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 57 additions and 60 deletions

View file

@ -53,7 +53,7 @@ Content-Type: application/json
``` ```
## GET /api/v1/registrant/contacts/$UUID ## GET /api/v1/registrant/contacts/$UUID
Returns contacts of the current registrar. Returns contact details.
#### Request #### Request
@ -138,35 +138,7 @@ Content-type: application/json
``` ```
#### Response on success #### Response on success
``` Same as for [GET /api/v1/registrant/contacts/$UUID](#get-apiv1registrantcontactsuuid).
HTTP/1.1 200
Content-Type: application/json
{
"id":"84c62f3d-e56f-40fa-9ca4-dc0137778949",
"name":"Karson Kessler",
"code":"REGISTRAR2:SH022086480",
"ident":{
"code":"37605030299",
"type":"priv",
"country_code":"EE"
},
"email":"foo@bar.baz",
"phone":"+372.12345671",
"fax":"+372.12345672",
"address":{
"street":"Main Street 123",
"zip":"22222",
"city":"New City",
"state":"New state",
"country_code":"LV"
},
"auth_info":"password",
"statuses":[
"ok"
]
}
```
### Response on failure ### Response on failure
``` ```

View file

@ -20,21 +20,30 @@ class RegistrantApiV1ContactUpdateTest < ActionDispatch::IntegrationTest
end end
def test_update_contact def test_update_contact
patch api_v1_registrant_contact_path(@contact.uuid), { name: 'new name', @contact.update!(name: 'John',
email: 'new-email@coldmail.test', email: 'john@shop.test',
phone: '+666.6' }, phone: '+111.1')
'HTTP_AUTHORIZATION' => auth_token
patch api_v1_registrant_contact_path(@contact.uuid), { name: 'William',
email: 'william@shop.test',
phone: '+222.2' }.to_json,
'HTTP_AUTHORIZATION' => auth_token,
'Accept' => Mime::JSON,
'Content-Type' => Mime::JSON.to_s
assert_response :ok assert_response :ok
@contact.reload @contact.reload
assert_equal 'new name', @contact.name
assert_equal 'new-email@coldmail.test', @contact.email assert_equal 'William', @contact.name
assert_equal '+666.6', @contact.phone assert_equal 'william@shop.test', @contact.email
assert_equal '+222.2', @contact.phone
end end
def test_notify_registrar def test_notify_registrar
assert_difference -> { @contact.registrar.notifications.count } do assert_difference -> { @contact.registrar.notifications.count } do
patch api_v1_registrant_contact_path(@contact.uuid), { name: 'new name' }, patch api_v1_registrant_contact_path(@contact.uuid), { name: 'new name' }.to_json,
'HTTP_AUTHORIZATION' => auth_token 'HTTP_AUTHORIZATION' => auth_token,
'Accept' => Mime::JSON,
'Content-Type' => Mime::JSON.to_s
end end
notification = @contact.registrar.notifications.last notification = @contact.registrar.notifications.last
assert_equal 'Contact john-001 has been updated by registrant', notification.text assert_equal 'Contact john-001 has been updated by registrant', notification.text
@ -44,8 +53,10 @@ class RegistrantApiV1ContactUpdateTest < ActionDispatch::IntegrationTest
ENV['fax_enabled'] = 'true' ENV['fax_enabled'] = 'true'
@contact = contacts(:william) @contact = contacts(:william)
patch api_v1_registrant_contact_path(@contact.uuid), { 'fax' => '+777.7' }, patch api_v1_registrant_contact_path(@contact.uuid), { fax: '+777.7' }.to_json,
'HTTP_AUTHORIZATION' => auth_token 'HTTP_AUTHORIZATION' => auth_token,
'Accept' => Mime::JSON,
'Content-Type' => Mime::JSON.to_s
assert_response :ok assert_response :ok
@contact.reload @contact.reload
@ -55,8 +66,10 @@ class RegistrantApiV1ContactUpdateTest < ActionDispatch::IntegrationTest
def test_fax_cannot_be_updated_when_disabled def test_fax_cannot_be_updated_when_disabled
ENV['fax_enabled'] = 'false' ENV['fax_enabled'] = 'false'
patch api_v1_registrant_contact_path(@contact.uuid), { 'fax' => '+823.7' }, patch api_v1_registrant_contact_path(@contact.uuid), { fax: '+823.7' }.to_json,
'HTTP_AUTHORIZATION' => auth_token 'HTTP_AUTHORIZATION' => auth_token,
'Accept' => Mime::JSON,
'Content-Type' => Mime::JSON.to_s
assert_response :bad_request assert_response :bad_request
@contact.reload @contact.reload
@ -70,12 +83,14 @@ class RegistrantApiV1ContactUpdateTest < ActionDispatch::IntegrationTest
def test_update_address_when_enabled def test_update_address_when_enabled
Setting.address_processing = true Setting.address_processing = true
patch api_v1_registrant_contact_path(@contact.uuid), { 'address[city]' => 'new city', patch api_v1_registrant_contact_path(@contact.uuid), { address: { city: 'new city',
'address[street]' => 'new street', street: 'new street',
'address[zip]' => '92837', zip: '92837',
'address[country_code]' => 'RU', country_code: 'RU',
'address[state]' => 'new state' }, state: 'new state' } }.to_json,
'HTTP_AUTHORIZATION' => auth_token 'HTTP_AUTHORIZATION' => auth_token,
'Accept' => Mime::JSON,
'Content-Type' => Mime::JSON.to_s
assert_response :ok assert_response :ok
@contact.reload @contact.reload
@ -87,8 +102,10 @@ class RegistrantApiV1ContactUpdateTest < ActionDispatch::IntegrationTest
@contact = contacts(:william) @contact = contacts(:william)
Setting.address_processing = true Setting.address_processing = true
patch api_v1_registrant_contact_path(@contact.uuid), { 'name' => 'any' }, patch api_v1_registrant_contact_path(@contact.uuid), { name: 'any' }.to_json,
'HTTP_AUTHORIZATION' => auth_token 'HTTP_AUTHORIZATION' => auth_token,
'Accept' => Mime::JSON,
'Content-Type' => Mime::JSON.to_s
assert_response :ok assert_response :ok
end end
@ -98,8 +115,10 @@ class RegistrantApiV1ContactUpdateTest < ActionDispatch::IntegrationTest
@original_address = @contact.address @original_address = @contact.address
Setting.address_processing = false Setting.address_processing = false
patch api_v1_registrant_contact_path(@contact.uuid), { 'address[city]' => 'new city' }, patch api_v1_registrant_contact_path(@contact.uuid), { address: { city: 'new city' } }.to_json,
'HTTP_AUTHORIZATION' => auth_token 'HTTP_AUTHORIZATION' => auth_token,
'Accept' => Mime::JSON,
'Content-Type' => Mime::JSON.to_s
@contact.reload @contact.reload
assert_response :bad_request assert_response :bad_request
@ -111,8 +130,10 @@ class RegistrantApiV1ContactUpdateTest < ActionDispatch::IntegrationTest
end end
def test_return_contact_details def test_return_contact_details
patch api_v1_registrant_contact_path(@contact.uuid), { name: 'new name' }, patch api_v1_registrant_contact_path(@contact.uuid), { name: 'new name' }.to_json,
'HTTP_AUTHORIZATION' => auth_token 'HTTP_AUTHORIZATION' => auth_token,
'Accept' => Mime::JSON,
'Content-Type' => Mime::JSON.to_s
assert_equal ({ id: @contact.uuid, assert_equal ({ id: @contact.uuid,
name: 'new name', name: 'new name',
code: @contact.code, code: @contact.code,
@ -136,8 +157,10 @@ class RegistrantApiV1ContactUpdateTest < ActionDispatch::IntegrationTest
end end
def test_errors def test_errors
patch api_v1_registrant_contact_path(@contact.uuid), { phone: 'invalid' }, patch api_v1_registrant_contact_path(@contact.uuid), { phone: 'invalid' }.to_json,
'HTTP_AUTHORIZATION' => auth_token 'HTTP_AUTHORIZATION' => auth_token,
'Accept' => Mime::JSON,
'Content-Type' => Mime::JSON.to_s
assert_response :bad_request assert_response :bad_request
assert_equal ({ errors: { phone: ['Phone nr is invalid'] } }), JSON.parse(response.body, assert_equal ({ errors: { phone: ['Phone nr is invalid'] } }), JSON.parse(response.body,
@ -147,8 +170,10 @@ class RegistrantApiV1ContactUpdateTest < ActionDispatch::IntegrationTest
def test_contact_of_another_user_cannot_be_updated def test_contact_of_another_user_cannot_be_updated
@contact = contacts(:jack) @contact = contacts(:jack)
patch api_v1_registrant_contact_path(@contact.uuid), { name: 'any' }, patch api_v1_registrant_contact_path(@contact.uuid), { name: 'any' }.to_json,
'HTTP_AUTHORIZATION' => auth_token 'HTTP_AUTHORIZATION' => auth_token,
'Accept' => Mime::JSON,
'Content-Type' => Mime::JSON.to_s
assert_response :not_found assert_response :not_found
@contact.reload @contact.reload
@ -176,4 +201,4 @@ class RegistrantApiV1ContactUpdateTest < ActionDispatch::IntegrationTest
hash = token_creator.token_in_hash hash = token_creator.token_in_hash
"Bearer #{hash[:access_token]}" "Bearer #{hash[:access_token]}"
end end
end end