Updated REPP API for new registrar portal

This commit is contained in:
Sergei Tsõganov 2022-06-06 13:43:30 +03:00
parent e17b21436d
commit a5ffce290d
61 changed files with 1269 additions and 408 deletions

View file

@ -11,7 +11,7 @@ class ReppV1BalanceTest < ActionDispatch::IntegrationTest
end
def test_can_query_balance
get '/repp/v1/accounts/balance', headers: @auth_headers
get '/repp/v1/account/balance', headers: @auth_headers
json = JSON.parse(response.body, symbolize_names: true)
assert_response :ok
@ -28,7 +28,7 @@ class ReppV1BalanceTest < ActionDispatch::IntegrationTest
started_from = "2010-07-05"
end_to = DateTime.current.to_date.to_s(:db)
get "/repp/v1/accounts/balance?detailed=true", headers: @auth_headers
get "/repp/v1/account/balance?detailed=true", headers: @auth_headers
json = JSON.parse(response.body, symbolize_names: true)
assert_response :ok
@ -44,8 +44,8 @@ class ReppV1BalanceTest < ActionDispatch::IntegrationTest
assert_equal @registrar.registrar.cash_account.account_activities.last.new_balance.to_s, entry[:balance]
json[:data][:transactions].map do |trans|
assert trans[:created_at].to_date.to_s(:db) >= started_from
assert trans[:created_at].to_date.to_s(:db) >= end_to
assert trans[:created_at].to_date.to_s(:db) >= started_from
assert trans[:created_at].to_date.to_s(:db) >= end_to
end
end
end

View file

@ -11,16 +11,16 @@ class ReppV1ContactsCreateTest < ActionDispatch::IntegrationTest
def test_creates_new_contact
request_body = {
"contact": {
"name": "Donald Trump",
"phone": "+372.51111112",
"email": "donald@trumptower.com",
"ident": {
"ident_type": "priv",
"ident_country_code": "EE",
"ident": "39708290069"
}
}
contact: {
name: 'Donald Trump',
phone: '+372.51111112',
email: 'donald@trumptower.com',
ident: {
ident_type: 'priv',
ident_country_code: 'EE',
ident: '39708290069',
},
},
}
post '/repp/v1/contacts', headers: @auth_headers, params: request_body
@ -30,7 +30,7 @@ class ReppV1ContactsCreateTest < ActionDispatch::IntegrationTest
assert_equal 1000, json[:code]
assert_equal 'Command completed successfully', json[:message]
contact = Contact.find_by(code: json[:data][:contact][:id])
contact = Contact.find_by(code: json[:data][:contact][:code])
assert contact.present?
assert_equal(request_body[:contact][:name], contact.name)
@ -42,21 +42,21 @@ class ReppV1ContactsCreateTest < ActionDispatch::IntegrationTest
end
def test_removes_postal_info_when_contact_created
request_body = {
"contact": {
"name": "Donald Trump",
"phone": "+372.51111111",
"email": "donald@trump.com",
"ident": {
"ident_type": "priv",
"ident_country_code": "EE",
"ident": "39708290069"
request_body = {
contact: {
name: 'Donald Trump',
phone: '+372.51111111',
email: 'donald@trump.com',
ident: {
ident_type: 'priv',
ident_country_code: 'EE',
ident: '39708290069',
},
"addr": {
"city": "Tallinn",
"street": "Wismari 13",
"zip": "12345",
"country_code": "EE"
addr: {
city: 'Tallinn',
street: 'Wismari 13',
zip: '12345',
country_code: 'EE',
}
}
}
@ -68,7 +68,7 @@ class ReppV1ContactsCreateTest < ActionDispatch::IntegrationTest
assert_equal 1100, json[:code]
assert_equal 'Command completed successfully; Postal address data discarded', json[:message]
contact = Contact.find_by(code: json[:data][:contact][:id])
contact = Contact.find_by(code: json[:data][:contact][:code])
assert contact.present?
assert_nil contact.city
@ -126,21 +126,21 @@ class ReppV1ContactsCreateTest < ActionDispatch::IntegrationTest
end
def test_attaches_legaldoc_if_present
request_body = {
"contact": {
"name": "Donald Trump",
"phone": "+372.51111112",
"email": "donald@trumptower.com",
"ident": {
"ident_type": "priv",
"ident_country_code": "EE",
"ident": "39708290069"
request_body = {
contact: {
name: 'Donald Trump',
phone: '+372.51111112',
email: 'donald@trumptower.com',
ident: {
ident_type: 'priv',
ident_country_code: 'EE',
ident: '39708290069',
},
legal_document: {
type: 'pdf',
body: ('test' * 2000).to_s,
},
},
"legal_document": {
"type": "pdf",
"body": "#{'test' * 2000}"
}
}
post '/repp/v1/contacts', headers: @auth_headers, params: request_body
@ -150,7 +150,7 @@ class ReppV1ContactsCreateTest < ActionDispatch::IntegrationTest
assert_equal 1000, json[:code]
assert_equal 'Command completed successfully', json[:message]
contact = Contact.find_by(code: json[:data][:contact][:id])
contact = Contact.find_by(code: json[:data][:contact][:code])
assert contact.legal_documents.any?
end
end

View file

@ -12,13 +12,13 @@ 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[:total_number_of_records]
assert_equal @user.registrar.contacts.count, json[:contacts].length
assert_equal @user.registrar.contacts.count, json[:data][:count]
assert_equal @user.registrar.contacts.count, json[:data][:contacts].length
assert json[:contacts][0].is_a? String
assert json[:data][:contacts][0].is_a? String
end
@ -28,10 +28,10 @@ class ReppV1ContactsListTest < ActionDispatch::IntegrationTest
assert_response :ok
assert_equal @user.registrar.contacts.count, json[:total_number_of_records]
assert_equal @user.registrar.contacts.count, json[:contacts].length
assert_equal @user.registrar.contacts.count, json[:data][:count]
assert_equal @user.registrar.contacts.count, json[:data][:contacts].length
assert json[:contacts][0].is_a? Hash
assert json[:data][:contacts][0].is_a? Hash
end
def test_respects_limit
@ -40,7 +40,7 @@ class ReppV1ContactsListTest < ActionDispatch::IntegrationTest
assert_response :ok
assert_equal 2, json[:contacts].length
assert_equal 2, json[:data][:contacts].length
end
def test_respects_offset
@ -50,6 +50,6 @@ class ReppV1ContactsListTest < ActionDispatch::IntegrationTest
assert_response :ok
assert_equal (@user.registrar.contacts.count - offset), json[:contacts].length
assert_equal (@user.registrar.contacts.count - offset), json[:data][:contacts].length
end
end

View file

@ -28,7 +28,7 @@ class ReppV1ContactsShowTest < ActionDispatch::IntegrationTest
assert_equal 1000, json[:code]
assert_equal 'Command completed successfully', json[:message]
assert_equal contact.code, json[:data][:id]
assert_equal contact.code, json[:data][:contact][:code]
end
def test_can_not_access_out_of_scope_contacts

View file

@ -24,14 +24,14 @@ class ReppV1ContactsUpdateTest < ActionDispatch::IntegrationTest
assert_equal 1000, json[:code]
assert_equal 'Command completed successfully', json[:message]
contact = Contact.find_by(code: json[:data][:contact][:id])
contact = Contact.find_by(code: json[:data][:contact][:code])
assert contact.present?
assert_equal(request_body[:contact][:email], contact.email)
end
def test_removes_postal_info_when_updated
request_body = {
request_body = {
"contact": {
"addr": {
"city": "Tallinn",
@ -49,7 +49,7 @@ class ReppV1ContactsUpdateTest < ActionDispatch::IntegrationTest
assert_equal 1100, json[:code]
assert_equal 'Command completed successfully; Postal address data discarded', json[:message]
contact = Contact.find_by(code: json[:data][:contact][:id])
contact = Contact.find_by(code: json[:data][:contact][:code])
assert contact.present?
assert_nil contact.city
@ -81,14 +81,14 @@ class ReppV1ContactsUpdateTest < ActionDispatch::IntegrationTest
end
def test_attaches_legaldoc_if_present
request_body = {
"contact": {
"email": "donaldtrump@yandex.ru"
request_body = {
contact: {
email: 'donaldtrump@yandex.ru',
legal_document: {
type: 'pdf',
body: ('test' * 2000).to_s,
},
},
"legal_document": {
"type": "pdf",
"body": "#{'test' * 2000}"
}
}
put "/repp/v1/contacts/#{@contact.code}", headers: @auth_headers, params: request_body
@ -103,9 +103,11 @@ class ReppV1ContactsUpdateTest < ActionDispatch::IntegrationTest
end
def test_returns_error_if_ident_wrong_format
request_body = {
"contact": {
"ident": "123"
request_body = {
contact: {
ident: {
ident: '123',
}
}
}

View file

@ -15,7 +15,7 @@ class ReppV1DomainsContactReplacementTest < ActionDispatch::IntegrationTest
payload = {
"current_contact_id": replaceable_contact.code,
"new_contact_id": replacing_contact.code
"new_contact_id": replacing_contact.code,
}
patch '/repp/v1/domains/contacts', headers: @auth_headers, params: payload
@ -37,7 +37,7 @@ class ReppV1DomainsContactReplacementTest < ActionDispatch::IntegrationTest
payload = {
"current_contact_id": replaceable_contact.code,
"new_contact_id": replacing_contact.code
"new_contact_id": replacing_contact.code,
}
patch '/repp/v1/domains/contacts', headers: @auth_headers, params: payload
@ -51,7 +51,7 @@ class ReppV1DomainsContactReplacementTest < ActionDispatch::IntegrationTest
def test_contact_codes_must_be_valid
payload = {
"current_contact_id": 'dfgsdfg',
"new_contact_id": 'vvv'
"new_contact_id": 'vvv',
}
patch '/repp/v1/domains/contacts', headers: @auth_headers, params: payload
@ -61,5 +61,4 @@ class ReppV1DomainsContactReplacementTest < ActionDispatch::IntegrationTest
assert_equal 2303, json[:code]
assert_equal 'Object does not exist', json[:message]
end
end

View file

@ -15,9 +15,11 @@ class ReppV1DomainsDeleteTest < ActionDispatch::IntegrationTest
@auth_headers['Content-Type'] = 'application/json'
payload = {
delete: {
verified: false
}
domain: {
delete: {
verified: false,
},
},
}
delete "/repp/v1/domains/#{@domain.name}", headers: @auth_headers, params: payload.to_json
@ -36,9 +38,11 @@ class ReppV1DomainsDeleteTest < ActionDispatch::IntegrationTest
@auth_headers['Content-Type'] = 'application/json'
payload = {
delete: {
verified: true
}
domain: {
delete: {
verified: true,
},
},
}
delete "/repp/v1/domains/#{@domain.name}", headers: @auth_headers, params: payload.to_json

View file

@ -15,7 +15,7 @@ class ReppV1DomainsListTest < ActionDispatch::IntegrationTest
assert_response :ok
assert_equal @user.registrar.domains.count, json[:data][:total_number_of_records]
assert_equal @user.registrar.domains.count, json[:data][:count]
assert_equal @user.registrar.domains.count, json[:data][:domains].length
assert json[:data][:domains][0].is_a? String
@ -27,7 +27,7 @@ class ReppV1DomainsListTest < ActionDispatch::IntegrationTest
assert_response :ok
assert_equal @user.registrar.domains.count, json[:data][:total_number_of_records]
assert_equal @user.registrar.domains.count, json[:data][:count]
assert_equal @user.registrar.domains.count, json[:data][:domains].length
assert json[:data][:domains][0].is_a? Hash

View file

@ -18,7 +18,7 @@ class ReppV1DomainsRenewsTest < ActionDispatch::IntegrationTest
:prepare_renewed_expire_time).and_call_through
@auth_headers['Content-Type'] = 'application/json'
payload = { renew: { period: 1, period_unit: 'y', exp_date: original_valid_to } }
payload = { renews: { period: 1, period_unit: 'y', exp_date: original_valid_to } }
post "/repp/v1/domains/#{@domain.name}/renew", headers: @auth_headers, params: payload.to_json
json = JSON.parse(response.body, symbolize_names: true)
@ -36,7 +36,7 @@ class ReppV1DomainsRenewsTest < ActionDispatch::IntegrationTest
travel_to Time.zone.parse('2010-07-05')
@auth_headers['Content-Type'] = 'application/json'
payload = { renew: { period: 10, period_unit: 'y', exp_date: original_valid_to } }
payload = { renews: { period: 10, period_unit: 'y', exp_date: original_valid_to } }
post "/repp/v1/domains/#{@domain.name}/renew", headers: @auth_headers, params: payload.to_json
json = JSON.parse(response.body, symbolize_names: true)
@ -60,7 +60,7 @@ class ReppV1DomainsRenewsTest < ActionDispatch::IntegrationTest
one_year.reload
@auth_headers['Content-Type'] = 'application/json'
payload = { renew: { period: 1, period_unit: 'y', exp_date: original_valid_to } }
payload = { renews: { period: 1, period_unit: 'y', exp_date: original_valid_to } }
post "/repp/v1/domains/#{@domain.name}/renew", headers: @auth_headers, params: payload.to_json
json = JSON.parse(response.body, symbolize_names: true)

View file

@ -16,8 +16,8 @@ class ReppV1DomainsUpdateTest < ActionDispatch::IntegrationTest
payload = {
domain: {
auth_code: new_auth_code
}
auth_code: new_auth_code,
},
}
put "/repp/v1/domains/#{@domain.name}", headers: @auth_headers, params: payload.to_json
@ -40,9 +40,9 @@ class ReppV1DomainsUpdateTest < ActionDispatch::IntegrationTest
payload = {
domain: {
registrant: {
code: new_registrant.code
}
}
code: new_registrant.code,
},
},
}
put "/repp/v1/domains/#{@domain.name}", headers: @auth_headers, params: payload.to_json
@ -67,13 +67,14 @@ class ReppV1DomainsUpdateTest < ActionDispatch::IntegrationTest
domain: {
registrant: {
code: new_registrant.code,
verified: true
}
}
verified: true,
},
},
}
put "/repp/v1/domains/#{@domain.name}", headers: @auth_headers, params: payload.to_json
@domain.reload
json = JSON.parse(response.body, symbolize_names: true)
assert_response :ok
assert_equal 1000, json[:code]