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
Returns contacts of the current registrar.
Returns contact details.
#### Request
@ -138,35 +138,7 @@ Content-type: application/json
```
#### Response on success
```
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"
]
}
```
Same as for [GET /api/v1/registrant/contacts/$UUID](#get-apiv1registrantcontactsuuid).
### Response on failure
```

View file

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