mirror of
https://github.com/internetee/registry.git
synced 2025-07-29 14:06:21 +02:00
added more tests
This commit is contained in:
parent
6ff5e55a24
commit
61497deb2a
6 changed files with 520 additions and 1 deletions
|
@ -1,10 +1,13 @@
|
|||
require 'test_helper'
|
||||
|
||||
Company = Struct.new(:registration_number, :company_name, :status)
|
||||
|
||||
class ReppV1ContactsCreateTest < ActionDispatch::IntegrationTest
|
||||
def setup
|
||||
@user = users(:api_bestnames)
|
||||
token = Base64.encode64("#{@user.username}:#{@user.plain_text_password}")
|
||||
token = "Basic #{token}"
|
||||
@company_register_stub = CompanyRegister::Client.new
|
||||
|
||||
@auth_headers = { 'Authorization' => token }
|
||||
|
||||
|
@ -184,4 +187,70 @@ class ReppV1ContactsCreateTest < ActionDispatch::IntegrationTest
|
|||
ENV['shunter_default_threshold'] = '10000'
|
||||
ENV['shunter_enabled'] = 'false'
|
||||
end
|
||||
|
||||
def test_returns_error_response_if_company_not_existed
|
||||
original_new_method = CompanyRegister::Client.method(:new)
|
||||
CompanyRegister::Client.define_singleton_method(:new) do
|
||||
object = original_new_method.call
|
||||
def object.simple_data(registration_number:)
|
||||
[Company.new('1234567', 'ACME Ltd', 'K')]
|
||||
end
|
||||
object
|
||||
end
|
||||
|
||||
request_body = {
|
||||
"contact": {
|
||||
"name": 'Donald Trump',
|
||||
"phone": '+372.51111112',
|
||||
"email": 'donald@trumptower.com',
|
||||
"ident": {
|
||||
"ident_type": 'org',
|
||||
"ident_country_code": 'EE',
|
||||
"ident": '70000313',
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
post '/repp/v1/contacts', headers: @auth_headers, params: request_body
|
||||
json = JSON.parse(response.body, symbolize_names: true)
|
||||
|
||||
assert_response :bad_request
|
||||
assert_equal 2003, json[:code]
|
||||
puts json[:message]
|
||||
assert json[:message].include? 'Company is not registered'
|
||||
|
||||
CompanyRegister::Client.define_singleton_method(:new, original_new_method)
|
||||
end
|
||||
|
||||
def test_contact_created_with_existed_company
|
||||
original_new_method = CompanyRegister::Client.method(:new)
|
||||
CompanyRegister::Client.define_singleton_method(:new) do
|
||||
object = original_new_method.call
|
||||
def object.simple_data(registration_number:)
|
||||
[Company.new('1234567', 'ACME Ltd', 'R')]
|
||||
end
|
||||
object
|
||||
end
|
||||
|
||||
request_body = {
|
||||
"contact": {
|
||||
"name": 'Donald Trump',
|
||||
"phone": '+372.51111112',
|
||||
"email": 'donald@trumptower.com',
|
||||
"ident": {
|
||||
"ident_type": 'org',
|
||||
"ident_country_code": 'EE',
|
||||
"ident": '70000313',
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
post '/repp/v1/contacts', headers: @auth_headers, params: request_body
|
||||
json = JSON.parse(response.body, symbolize_names: true)
|
||||
|
||||
assert_response :ok
|
||||
assert_equal 1000, json[:code]
|
||||
|
||||
CompanyRegister::Client.define_singleton_method(:new, original_new_method)
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue