mirror of
https://github.com/internetee/registry.git
synced 2025-07-30 22:46:22 +02:00
Added additional tests to REPP API
This commit is contained in:
parent
b505de2f0f
commit
b502c2779e
21 changed files with 796 additions and 7 deletions
70
test/integration/repp/v1/account/activities_list_test.rb
Normal file
70
test/integration/repp/v1/account/activities_list_test.rb
Normal file
|
@ -0,0 +1,70 @@
|
|||
require 'test_helper'
|
||||
|
||||
class ReppV1AccountActivitiesListTest < ActionDispatch::IntegrationTest
|
||||
def setup
|
||||
@user = users(:api_bestnames)
|
||||
token = Base64.encode64("#{@user.username}:#{@user.plain_text_password}")
|
||||
token = "Basic #{token}"
|
||||
|
||||
@auth_headers = { 'Authorization' => token }
|
||||
end
|
||||
|
||||
def test_returns_account_activities
|
||||
get repp_v1_account_path, headers: @auth_headers
|
||||
json = JSON.parse(response.body, symbolize_names: true)
|
||||
|
||||
assert_response :ok
|
||||
|
||||
assert_equal @user.registrar.cash_account.activities.count, json[:data][:count]
|
||||
assert_equal @user.registrar.cash_account.activities.count, json[:data][:activities].length
|
||||
|
||||
assert json[:data][:activities][0].is_a? Hash
|
||||
end
|
||||
|
||||
def test_respects_limit
|
||||
get repp_v1_account_path(limit: 1), headers: @auth_headers
|
||||
json = JSON.parse(response.body, symbolize_names: true)
|
||||
|
||||
assert_response :ok
|
||||
|
||||
assert_equal 1, json[:data][:activities].length
|
||||
end
|
||||
|
||||
def test_respects_offset
|
||||
offset = 1
|
||||
get repp_v1_account_path(offset: offset), headers: @auth_headers
|
||||
json = JSON.parse(response.body, symbolize_names: true)
|
||||
|
||||
assert_response :ok
|
||||
|
||||
assert_equal (@user.registrar.cash_account.activities.count - offset), json[:data][:activities].length
|
||||
end
|
||||
|
||||
def test_returns_account_activities_by_search_query
|
||||
search_params = {
|
||||
description_matches: '%renew%',
|
||||
}
|
||||
get repp_v1_account_path(q: search_params), headers: @auth_headers
|
||||
json = JSON.parse(response.body, symbolize_names: true)
|
||||
|
||||
assert_response :ok
|
||||
|
||||
assert_equal json[:data][:activities].length, 1
|
||||
assert json[:data][:activities][0].is_a? Hash
|
||||
end
|
||||
|
||||
def test_returns_account_activities_by_sort_query
|
||||
activity = account_activities(:renew_cash)
|
||||
sort_params = {
|
||||
s: 'activity_type asc',
|
||||
}
|
||||
get repp_v1_account_path(q: sort_params), headers: @auth_headers
|
||||
json = JSON.parse(response.body, symbolize_names: true)
|
||||
|
||||
assert_response :ok
|
||||
|
||||
assert_equal @user.registrar.cash_account.activities.count, json[:data][:count]
|
||||
assert_equal @user.registrar.cash_account.activities.count, json[:data][:activities].length
|
||||
assert_equal json[:data][:activities][0][:description], activity.description
|
||||
end
|
||||
end
|
|
@ -10,6 +10,8 @@ class ReppV1BalanceTest < ActionDispatch::IntegrationTest
|
|||
@auth_headers = { 'Authorization' => token }
|
||||
end
|
||||
|
||||
|
||||
|
||||
def test_can_query_balance
|
||||
get '/repp/v1/account/balance', headers: @auth_headers
|
||||
json = JSON.parse(response.body, symbolize_names: true)
|
||||
|
|
22
test/integration/repp/v1/account/details_test.rb
Normal file
22
test/integration/repp/v1/account/details_test.rb
Normal file
|
@ -0,0 +1,22 @@
|
|||
require 'test_helper'
|
||||
|
||||
class ReppV1AccountDetailsTest < ActionDispatch::IntegrationTest
|
||||
def setup
|
||||
@user = users(:api_bestnames)
|
||||
token = Base64.encode64("#{@user.username}:#{@user.plain_text_password}")
|
||||
token = "Basic #{token}"
|
||||
|
||||
@auth_headers = { 'Authorization' => token }
|
||||
end
|
||||
|
||||
def test_returns_account_details
|
||||
get '/repp/v1/account/details', headers: @auth_headers
|
||||
json = JSON.parse(response.body, symbolize_names: true)
|
||||
|
||||
assert_response :ok
|
||||
assert_equal 1000, json[:code]
|
||||
assert_equal 'Command completed successfully', json[:message]
|
||||
|
||||
assert_equal @user.registrar.billing_email, json[:data][:account][:billing_email]
|
||||
end
|
||||
end
|
|
@ -0,0 +1,69 @@
|
|||
require 'test_helper'
|
||||
|
||||
class ReppV1AccountUpdateAutoReloadBalanceTest < ActionDispatch::IntegrationTest
|
||||
def setup
|
||||
@user = users(:api_bestnames)
|
||||
token = Base64.encode64("#{@user.username}:#{@user.plain_text_password}")
|
||||
token = "Basic #{token}"
|
||||
|
||||
@auth_headers = { 'Authorization' => token }
|
||||
end
|
||||
|
||||
def test_updates_auto_reload_balance
|
||||
amount = 100
|
||||
threshold = 10
|
||||
request_body = {
|
||||
type: {
|
||||
amount: amount,
|
||||
threshold: threshold,
|
||||
},
|
||||
}
|
||||
|
||||
assert_nil @user.registrar.settings['balance_auto_reload']
|
||||
|
||||
post '/repp/v1/account/update_auto_reload_balance', headers: @auth_headers,
|
||||
params: request_body
|
||||
json = JSON.parse(response.body, symbolize_names: true)
|
||||
assert_response :ok
|
||||
assert_equal 1000, json[:code]
|
||||
assert_equal 'Balance Auto-Reload setting has been updated', json[:message]
|
||||
|
||||
@user.registrar.reload
|
||||
|
||||
assert_equal amount, @user.registrar.settings['balance_auto_reload']['type']['amount']
|
||||
assert_equal threshold, @user.registrar.settings['balance_auto_reload']['type']['threshold']
|
||||
end
|
||||
|
||||
def test_returns_error_if_type_has_wrong_attributes
|
||||
min_deposit = 10
|
||||
request_body = {
|
||||
type: {
|
||||
amount: 5,
|
||||
threshold: -1,
|
||||
},
|
||||
}
|
||||
Setting.minimum_deposit = min_deposit
|
||||
|
||||
post '/repp/v1/account/update_auto_reload_balance', headers: @auth_headers,
|
||||
params: request_body
|
||||
json = JSON.parse(response.body, symbolize_names: true)
|
||||
|
||||
assert_response :bad_request
|
||||
amount_error = "Amount must be greater than or equal to #{min_deposit.to_f}"
|
||||
threshold = 'Threshold must be greater than or equal to 0'
|
||||
assert_equal "#{amount_error}, #{threshold}", json[:message]
|
||||
end
|
||||
|
||||
def test_disables_auto_reload_balance
|
||||
get '/repp/v1/account/disable_auto_reload_balance', headers: @auth_headers
|
||||
json = JSON.parse(response.body, symbolize_names: true)
|
||||
|
||||
assert_response :ok
|
||||
assert_equal 1000, json[:code]
|
||||
assert_equal 'Balance Auto-Reload setting has been disabled', json[:message]
|
||||
|
||||
@user.registrar.reload
|
||||
|
||||
assert_nil @user.registrar.settings['balance_auto_reload']
|
||||
end
|
||||
end
|
30
test/integration/repp/v1/account/update_details_test.rb
Normal file
30
test/integration/repp/v1/account/update_details_test.rb
Normal file
|
@ -0,0 +1,30 @@
|
|||
require 'test_helper'
|
||||
|
||||
class ReppV1AccountUpdateDetailsTest < ActionDispatch::IntegrationTest
|
||||
def setup
|
||||
@user = users(:api_bestnames)
|
||||
token = Base64.encode64("#{@user.username}:#{@user.plain_text_password}")
|
||||
token = "Basic #{token}"
|
||||
|
||||
@auth_headers = { 'Authorization' => token }
|
||||
end
|
||||
|
||||
def test_updates_details
|
||||
request_body = {
|
||||
account: {
|
||||
billing_email: 'donaldtrump@yandex.ru',
|
||||
iban: 'GB331111111111111111',
|
||||
},
|
||||
}
|
||||
|
||||
put '/repp/v1/account', headers: @auth_headers, params: request_body
|
||||
json = JSON.parse(response.body, symbolize_names: true)
|
||||
|
||||
assert_response :ok
|
||||
assert_equal 1000, json[:code]
|
||||
assert_equal 'Your account has been updated', json[:message]
|
||||
|
||||
assert_equal(request_body[:account][:billing_email], @user.registrar.billing_email)
|
||||
assert_equal(request_body[:account][:iban], @user.registrar.iban)
|
||||
end
|
||||
end
|
|
@ -12,7 +12,7 @@ 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[:data][:count]
|
||||
|
@ -21,7 +21,6 @@ class ReppV1ContactsListTest < ActionDispatch::IntegrationTest
|
|||
assert json[:data][:contacts][0].is_a? String
|
||||
end
|
||||
|
||||
|
||||
def test_returns_detailed_registrar_contacts
|
||||
get repp_v1_contacts_path(details: true), headers: @auth_headers
|
||||
json = JSON.parse(response.body, symbolize_names: true)
|
||||
|
@ -52,4 +51,32 @@ class ReppV1ContactsListTest < ActionDispatch::IntegrationTest
|
|||
|
||||
assert_equal (@user.registrar.contacts.count - offset), json[:data][:contacts].length
|
||||
end
|
||||
|
||||
def test_returns_detailed_registrar_contacts_by_search_query
|
||||
search_params = {
|
||||
ident_type_eq: 'priv',
|
||||
}
|
||||
get repp_v1_contacts_path(details: true, q: search_params), headers: @auth_headers
|
||||
json = JSON.parse(response.body, symbolize_names: true)
|
||||
|
||||
assert_response :ok
|
||||
|
||||
assert_equal json[:data][:contacts].length, 3
|
||||
assert json[:data][:contacts][0].is_a? Hash
|
||||
end
|
||||
|
||||
def test_returns_detailed_registrar_contacts_by_sort_query
|
||||
contact = contacts(:william)
|
||||
sort_params = {
|
||||
s: 'name desc',
|
||||
}
|
||||
get repp_v1_contacts_path(details: true, q: sort_params), headers: @auth_headers
|
||||
json = JSON.parse(response.body, symbolize_names: true)
|
||||
|
||||
assert_response :ok
|
||||
|
||||
assert_equal @user.registrar.contacts.count, json[:data][:count]
|
||||
assert_equal @user.registrar.contacts.count, json[:data][:contacts].length
|
||||
assert_equal json[:data][:contacts][0][:code], contact.code
|
||||
end
|
||||
end
|
||||
|
|
43
test/integration/repp/v1/contacts/search_test.rb
Normal file
43
test/integration/repp/v1/contacts/search_test.rb
Normal file
|
@ -0,0 +1,43 @@
|
|||
require 'test_helper'
|
||||
|
||||
class ReppV1ContactsSearchTest < ActionDispatch::IntegrationTest
|
||||
def setup
|
||||
@user = users(:api_bestnames)
|
||||
token = Base64.encode64("#{@user.username}:#{@user.plain_text_password}")
|
||||
token = "Basic #{token}"
|
||||
|
||||
@auth_headers = { 'Authorization' => token }
|
||||
end
|
||||
|
||||
def test_searches_all_contacts_by_id
|
||||
contact = contacts(:john)
|
||||
get "/repp/v1/contacts/search/#{contact.code}", headers: @auth_headers
|
||||
json = JSON.parse(response.body, symbolize_names: true)
|
||||
|
||||
assert_response :ok
|
||||
assert json[:data].is_a? Array
|
||||
assert_equal json[:data][0][:value], contact.code
|
||||
assert_equal json[:data][0][:label], "#{contact.code} #{contact.name}"
|
||||
assert_equal json[:data][0][:selected], true
|
||||
end
|
||||
|
||||
def test_searches_all_contacts_by_query
|
||||
get '/repp/v1/contacts/search', headers: @auth_headers, params: { query: 'j' }
|
||||
json = JSON.parse(response.body, symbolize_names: true)
|
||||
|
||||
assert_response :ok
|
||||
assert json[:data].is_a? Array
|
||||
assert_equal json[:data].length, 2
|
||||
assert_equal json[:data][0][:selected], false
|
||||
assert_equal json[:data][1][:selected], false
|
||||
end
|
||||
|
||||
def test_searches_all_contacts_by_wrong_query
|
||||
get '/repp/v1/contacts/search', headers: @auth_headers, params: { query: '000' }
|
||||
json = JSON.parse(response.body, symbolize_names: true)
|
||||
|
||||
assert_response :ok
|
||||
assert json[:data].is_a? Array
|
||||
assert_equal json[:data].length, 0
|
||||
end
|
||||
end
|
|
@ -64,4 +64,32 @@ class ReppV1DomainsListTest < ActionDispatch::IntegrationTest
|
|||
serialized_domain = Serializers::Repp::Domain.new(domain).to_json
|
||||
assert_equal serialized_domain.as_json, json[:data][:domain].as_json
|
||||
end
|
||||
|
||||
def test_returns_detailed_registrar_domains_by_search_query
|
||||
search_params = {
|
||||
name_matches: '%library%',
|
||||
}
|
||||
get repp_v1_domains_path(details: true, q: search_params), headers: @auth_headers
|
||||
json = JSON.parse(response.body, symbolize_names: true)
|
||||
|
||||
assert_response :ok
|
||||
|
||||
assert_equal json[:data][:domains].length, 1
|
||||
assert json[:data][:domains][0].is_a? Hash
|
||||
end
|
||||
|
||||
def test_returns_detailed_registrar_domains_by_sort_query
|
||||
domain = domains(:shop)
|
||||
sort_params = {
|
||||
s: 'name desc',
|
||||
}
|
||||
get repp_v1_domains_path(details: true, q: sort_params), headers: @auth_headers
|
||||
json = JSON.parse(response.body, symbolize_names: true)
|
||||
|
||||
assert_response :ok
|
||||
|
||||
assert_equal @user.registrar.domains.count, json[:data][:count]
|
||||
assert_equal @user.registrar.domains.count, json[:data][:domains].length
|
||||
assert_equal json[:data][:domains][0][:name], domain.name
|
||||
end
|
||||
end
|
||||
|
|
94
test/integration/repp/v1/invoices/add_credit_test.rb
Normal file
94
test/integration/repp/v1/invoices/add_credit_test.rb
Normal file
|
@ -0,0 +1,94 @@
|
|||
require 'test_helper'
|
||||
|
||||
class ReppV1InvoicesAddCreditTest < ActionDispatch::IntegrationTest
|
||||
def setup
|
||||
@user = users(:api_bestnames)
|
||||
token = Base64.encode64("#{@user.username}:#{@user.plain_text_password}")
|
||||
token = "Basic #{token}"
|
||||
|
||||
@auth_headers = { 'Authorization' => token }
|
||||
|
||||
@original_registry_vat_rate = Setting.registry_vat_prc
|
||||
eis_response = OpenStruct.new(body: '{"everypay_link":"https://link.test"}')
|
||||
Spy.on_instance_method(EisBilling::AddDeposits, :send_invoice).and_return(eis_response)
|
||||
Spy.on_instance_method(EisBilling::BaseController, :authorized).and_return(true)
|
||||
end
|
||||
|
||||
teardown do
|
||||
Setting.registry_vat_prc = @original_registry_vat_rate
|
||||
end
|
||||
|
||||
def test_generates_add_credit_invoice_with_billing_system
|
||||
request_body = {
|
||||
invoice: {
|
||||
amount: 100,
|
||||
description: 'Add credit',
|
||||
},
|
||||
}
|
||||
Setting.registry_vat_prc = 0.1
|
||||
ENV['billing_system_integrated'] = 'true'
|
||||
|
||||
if Feature.billing_system_integrated?
|
||||
invoice_n = Invoice.order(number: :desc).last.number
|
||||
stub_request(:post, 'https://eis_billing_system:3000/api/v1/invoice_generator/invoice_number_generator')
|
||||
.to_return(status: 200, body: "{\"invoice_number\":\"#{invoice_n + 3}\"}", headers: {})
|
||||
stub_request(:post, 'https://eis_billing_system:3000/api/v1/e_invoice/e_invoice')
|
||||
.to_return(status: 200, body: '', headers: {})
|
||||
end
|
||||
|
||||
post '/repp/v1/invoices/add_credit', headers: @auth_headers,
|
||||
params: request_body
|
||||
json = JSON.parse(response.body, symbolize_names: true)
|
||||
|
||||
assert_response :ok
|
||||
assert_equal 1000, json[:code]
|
||||
assert_equal 'Command completed successfully', json[:message]
|
||||
|
||||
assert_not json[:data][:invoice][:paid]
|
||||
assert json[:data][:invoice][:payable]
|
||||
assert json[:data][:invoice][:cancellable]
|
||||
assert_equal json[:data][:invoice][:payment_link], 'https://link.test'
|
||||
assert_equal json[:data][:invoice][:total], 110.to_f.to_s
|
||||
end
|
||||
|
||||
def test_generates_add_credit_invoice_without_billing_system
|
||||
request_body = {
|
||||
invoice: {
|
||||
amount: 100,
|
||||
description: 'Add credit',
|
||||
},
|
||||
}
|
||||
Setting.registry_vat_prc = 0.1
|
||||
ENV['billing_system_integrated'] = 'false'
|
||||
|
||||
post '/repp/v1/invoices/add_credit', headers: @auth_headers,
|
||||
params: request_body
|
||||
json = JSON.parse(response.body, symbolize_names: true)
|
||||
|
||||
assert_response :ok
|
||||
assert_equal 1000, json[:code]
|
||||
assert_equal 'Command completed successfully', json[:message]
|
||||
|
||||
assert_not json[:data][:invoice][:paid]
|
||||
assert json[:data][:invoice][:payable]
|
||||
assert json[:data][:invoice][:cancellable]
|
||||
assert_equal json[:data][:invoice][:total], 110.to_f.to_s
|
||||
end
|
||||
|
||||
def test_generates_add_credit_invoice_with_invalid_amount
|
||||
request_body = {
|
||||
invoice: {
|
||||
amount: 0.4,
|
||||
description: 'Add credit',
|
||||
},
|
||||
}
|
||||
Setting.minimum_deposit = 0.5
|
||||
|
||||
post '/repp/v1/invoices/add_credit', headers: @auth_headers,
|
||||
params: request_body
|
||||
json = JSON.parse(response.body, symbolize_names: true)
|
||||
|
||||
assert_response :bad_request
|
||||
assert_equal "Amount is too small. Minimum deposit is #{Setting.minimum_deposit} EUR", json[:message]
|
||||
end
|
||||
end
|
44
test/integration/repp/v1/invoices/cancel_test.rb
Normal file
44
test/integration/repp/v1/invoices/cancel_test.rb
Normal file
|
@ -0,0 +1,44 @@
|
|||
require 'test_helper'
|
||||
|
||||
class ReppV1InvoicesCancelTest < ActionDispatch::IntegrationTest
|
||||
def setup
|
||||
@user = users(:api_bestnames)
|
||||
token = Base64.encode64("#{@user.username}:#{@user.plain_text_password}")
|
||||
token = "Basic #{token}"
|
||||
|
||||
@auth_headers = { 'Authorization' => token }
|
||||
end
|
||||
|
||||
def test_cancels_invoice
|
||||
invoice = invoices(:one)
|
||||
invoice.account_activity = nil
|
||||
assert invoice.cancellable?
|
||||
stub_request(:post, 'https://eis_billing_system:3000/api/v1/invoice_generator/invoice_status')
|
||||
.to_return(status: :ok, headers: {})
|
||||
|
||||
put "/repp/v1/invoices/#{invoice.id}/cancel", headers: @auth_headers
|
||||
json = JSON.parse(response.body, symbolize_names: true)
|
||||
|
||||
assert_response :ok
|
||||
assert_equal 1000, json[:code]
|
||||
assert_equal 'Command completed successfully', json[:message]
|
||||
|
||||
invoice.reload
|
||||
assert invoice.cancelled?
|
||||
assert json[:data][:invoice].is_a? Hash
|
||||
end
|
||||
|
||||
def test_cancels_uncancellable_invoice
|
||||
invoice = invoices(:one)
|
||||
assert_not invoice.cancellable?
|
||||
|
||||
put "/repp/v1/invoices/#{invoice.id}/cancel", headers: @auth_headers
|
||||
json = JSON.parse(response.body, symbolize_names: true)
|
||||
|
||||
assert_response :bad_request
|
||||
assert_equal 'Invoice status prohibits operation', json[:message]
|
||||
|
||||
invoice.reload
|
||||
assert_not invoice.cancelled?
|
||||
end
|
||||
end
|
22
test/integration/repp/v1/invoices/download_test.rb
Normal file
22
test/integration/repp/v1/invoices/download_test.rb
Normal file
|
@ -0,0 +1,22 @@
|
|||
require 'test_helper'
|
||||
|
||||
class ReppV1InvoicesDownloadTest < ActionDispatch::IntegrationTest
|
||||
def setup
|
||||
@user = users(:api_bestnames)
|
||||
token = Base64.encode64("#{@user.username}:#{@user.plain_text_password}")
|
||||
token = "Basic #{token}"
|
||||
|
||||
@auth_headers = { 'Authorization' => token }
|
||||
end
|
||||
|
||||
def test_returns_invoice_as_pdf
|
||||
invoice = @user.registrar.invoices.first
|
||||
|
||||
get "/repp/v1/invoices/#{invoice.id}/download", headers: @auth_headers
|
||||
|
||||
assert_response :ok
|
||||
assert_equal 'application/pdf', response.headers['Content-Type']
|
||||
assert_equal "attachment; filename=\"Invoice-2.pdf\"; filename*=UTF-8''Invoice-2.pdf", response.headers['Content-Disposition']
|
||||
assert_not_empty response.body
|
||||
end
|
||||
end
|
85
test/integration/repp/v1/invoices/list_test.rb
Normal file
85
test/integration/repp/v1/invoices/list_test.rb
Normal file
|
@ -0,0 +1,85 @@
|
|||
require 'test_helper'
|
||||
|
||||
class ReppV1InvoicesListTest < ActionDispatch::IntegrationTest
|
||||
def setup
|
||||
@user = users(:api_bestnames)
|
||||
token = Base64.encode64("#{@user.username}:#{@user.plain_text_password}")
|
||||
token = "Basic #{token}"
|
||||
|
||||
@auth_headers = { 'Authorization' => token }
|
||||
end
|
||||
|
||||
def test_returns_registrar_invoices
|
||||
get repp_v1_invoices_path, headers: @auth_headers
|
||||
json = JSON.parse(response.body, symbolize_names: true)
|
||||
|
||||
assert_response :ok
|
||||
|
||||
assert_equal @user.registrar.invoices.count, json[:data][:count]
|
||||
assert_equal @user.registrar.invoices.count, json[:data][:invoices].length
|
||||
|
||||
assert json[:data][:invoices][0].is_a? Integer
|
||||
end
|
||||
|
||||
def test_returns_detailed_registrar_invoices
|
||||
get repp_v1_invoices_path(details: true), headers: @auth_headers
|
||||
json = JSON.parse(response.body, symbolize_names: true)
|
||||
|
||||
assert_response :ok
|
||||
|
||||
assert_equal @user.registrar.invoices.count, json[:data][:count]
|
||||
assert_equal @user.registrar.invoices.count, json[:data][:invoices].length
|
||||
|
||||
assert json[:data][:invoices][0].is_a? Hash
|
||||
end
|
||||
|
||||
def test_returns_detailed_registrar_invoices_by_search_query
|
||||
invoice = @user.registrar.invoices.last
|
||||
invoice.update(number: 15_008)
|
||||
search_params = {
|
||||
number_gteq: 15_000,
|
||||
}
|
||||
get repp_v1_invoices_path(details: true, q: search_params), headers: @auth_headers
|
||||
json = JSON.parse(response.body, symbolize_names: true)
|
||||
|
||||
assert_response :ok
|
||||
|
||||
assert_equal json[:data][:invoices].length, 1
|
||||
assert json[:data][:invoices][0].is_a? Hash
|
||||
assert_equal json[:data][:invoices][0][:id], invoice.id
|
||||
end
|
||||
|
||||
def test_returns_detailed_registrar_invoices_by_sort_query
|
||||
invoice = invoices(:unpaid)
|
||||
sort_params = {
|
||||
s: 'number desc',
|
||||
}
|
||||
get repp_v1_invoices_path(details: true, q: sort_params), headers: @auth_headers
|
||||
json = JSON.parse(response.body, symbolize_names: true)
|
||||
|
||||
assert_response :ok
|
||||
|
||||
assert_equal @user.registrar.invoices.count, json[:data][:count]
|
||||
assert_equal @user.registrar.invoices.count, json[:data][:invoices].length
|
||||
assert_equal json[:data][:invoices][0][:id], invoice.id
|
||||
end
|
||||
|
||||
def test_respects_limit
|
||||
get repp_v1_invoices_path(details: true, limit: 1), headers: @auth_headers
|
||||
json = JSON.parse(response.body, symbolize_names: true)
|
||||
|
||||
assert_response :ok
|
||||
|
||||
assert_equal 1, json[:data][:invoices].length
|
||||
end
|
||||
|
||||
def test_respects_offset
|
||||
offset = 1
|
||||
get repp_v1_invoices_path(details: true, offset: offset), headers: @auth_headers
|
||||
json = JSON.parse(response.body, symbolize_names: true)
|
||||
|
||||
assert_response :ok
|
||||
|
||||
assert_equal (@user.registrar.invoices.count - offset), json[:data][:invoices].length
|
||||
end
|
||||
end
|
39
test/integration/repp/v1/invoices/send_test.rb
Normal file
39
test/integration/repp/v1/invoices/send_test.rb
Normal file
|
@ -0,0 +1,39 @@
|
|||
require 'test_helper'
|
||||
|
||||
class ReppV1InvoicesSendTest < ActionDispatch::IntegrationTest
|
||||
def setup
|
||||
@user = users(:api_bestnames)
|
||||
token = Base64.encode64("#{@user.username}:#{@user.plain_text_password}")
|
||||
token = "Basic #{token}"
|
||||
|
||||
@auth_headers = { 'Authorization' => token }
|
||||
end
|
||||
|
||||
def test_sends_invoice_to_recipient
|
||||
invoice = invoices(:one)
|
||||
recipient = 'donaldtrump@yandex.ru'
|
||||
request_body = {
|
||||
invoice: {
|
||||
id: invoice.id,
|
||||
recipient: recipient,
|
||||
},
|
||||
}
|
||||
post "/repp/v1/invoices/#{invoice.id}/send_to_recipient", headers: @auth_headers,
|
||||
params: request_body
|
||||
json = JSON.parse(response.body, symbolize_names: true)
|
||||
|
||||
assert_equal 1, invoice.number
|
||||
|
||||
assert_response :ok
|
||||
assert_equal 1000, json[:code]
|
||||
assert_equal 'Command completed successfully', json[:message]
|
||||
|
||||
assert_equal json[:data][:invoice][:id], invoice.id
|
||||
assert_equal json[:data][:invoice][:recipient], recipient
|
||||
email = ActionMailer::Base.deliveries.last
|
||||
assert_emails 1
|
||||
assert_equal [recipient], email.to
|
||||
assert_equal 'Invoice no. 1', email.subject
|
||||
assert email.attachments['invoice-1.pdf']
|
||||
end
|
||||
end
|
33
test/integration/repp/v1/invoices/show_test.rb
Normal file
33
test/integration/repp/v1/invoices/show_test.rb
Normal file
|
@ -0,0 +1,33 @@
|
|||
require 'test_helper'
|
||||
|
||||
class ReppV1InvoicesShowTest < ActionDispatch::IntegrationTest
|
||||
def setup
|
||||
@user = users(:api_bestnames)
|
||||
token = Base64.encode64("#{@user.username}:#{@user.plain_text_password}")
|
||||
token = "Basic #{token}"
|
||||
|
||||
@auth_headers = { 'Authorization' => token }
|
||||
end
|
||||
|
||||
def test_returns_error_when_not_found
|
||||
get repp_v1_invoice_path(id: 'definitelynotexistant'), headers: @auth_headers
|
||||
json = JSON.parse(response.body, symbolize_names: true)
|
||||
|
||||
assert_response :not_found
|
||||
assert_equal 2303, json[:code]
|
||||
assert_equal 'Object does not exist', json[:message]
|
||||
end
|
||||
|
||||
def test_shows_existing_invoice
|
||||
invoice = @user.registrar.invoices.first
|
||||
|
||||
get repp_v1_invoice_path(id: invoice.id), headers: @auth_headers
|
||||
json = JSON.parse(response.body, symbolize_names: true)
|
||||
|
||||
assert_response :ok
|
||||
assert_equal 1000, json[:code]
|
||||
assert_equal 'Command completed successfully', json[:message]
|
||||
|
||||
assert_equal invoice.id, json[:data][:invoice][:id]
|
||||
end
|
||||
end
|
39
test/integration/repp/v1/registrar/auth/check_info_test.rb
Normal file
39
test/integration/repp/v1/registrar/auth/check_info_test.rb
Normal file
|
@ -0,0 +1,39 @@
|
|||
require 'test_helper'
|
||||
|
||||
class ReppV1RegistrarAuthCheckInfoTest < ActionDispatch::IntegrationTest
|
||||
def setup
|
||||
@user = users(:api_bestnames)
|
||||
token = Base64.encode64("#{@user.username}:#{@user.plain_text_password}")
|
||||
token = "Basic #{token}"
|
||||
|
||||
@auth_headers = { 'Authorization' => token }
|
||||
end
|
||||
|
||||
def test_returns_valid_user_auth_values
|
||||
get '/repp/v1/registrar/auth', headers: @auth_headers
|
||||
json = JSON.parse(response.body, symbolize_names: true)
|
||||
|
||||
assert_response :ok
|
||||
assert_equal 1000, json[:code]
|
||||
assert_equal 'Command completed successfully', json[:message]
|
||||
|
||||
assert_equal json[:data][:username], @user.username
|
||||
assert json[:data][:roles].include? 'super'
|
||||
assert_equal json[:data][:registrar_name], 'Best Names'
|
||||
assert_equal json[:data][:balance][:amount].to_f, @user.registrar.cash_account.balance
|
||||
assert json[:data][:abilities].is_a? Hash
|
||||
end
|
||||
|
||||
def test_invalid_user_login
|
||||
token = Base64.encode64("#{@user.username}:0066600")
|
||||
token = "Basic #{token}"
|
||||
|
||||
auth_headers = { 'Authorization' => token }
|
||||
|
||||
get '/repp/v1/registrar/auth', headers: auth_headers
|
||||
json = JSON.parse(response.body, symbolize_names: true)
|
||||
|
||||
assert_response :unauthorized
|
||||
assert_equal json[:message], 'Invalid authorization information'
|
||||
end
|
||||
end
|
52
test/integration/repp/v1/registrar/auth/switch_user_test.rb
Normal file
52
test/integration/repp/v1/registrar/auth/switch_user_test.rb
Normal file
|
@ -0,0 +1,52 @@
|
|||
require 'test_helper'
|
||||
|
||||
class ReppV1RegistrarSwitchUserTest < ActionDispatch::IntegrationTest
|
||||
def setup
|
||||
@user = users(:api_bestnames)
|
||||
token = Base64.encode64("#{@user.username}:#{@user.plain_text_password}")
|
||||
token = "Basic #{token}"
|
||||
|
||||
@auth_headers = { 'Authorization' => token }
|
||||
end
|
||||
|
||||
def test_switches_to_linked_api_user
|
||||
new_user = users(:api_goodnames)
|
||||
new_user.update(identity_code: '1234')
|
||||
request_body = {
|
||||
auth: {
|
||||
new_user_id: new_user.id,
|
||||
},
|
||||
}
|
||||
|
||||
put '/repp/v1/registrar/auth/switch_user', headers: @auth_headers, params: request_body
|
||||
json = JSON.parse(response.body, symbolize_names: true)
|
||||
|
||||
assert_response :ok
|
||||
assert_equal 1000, json[:code]
|
||||
assert_equal "You are now signed in as a user \"#{new_user.username}\"", json[:message]
|
||||
|
||||
user_token = Base64.urlsafe_encode64("#{new_user.username}:#{new_user.plain_text_password}")
|
||||
assert_equal json[:data][:token], user_token
|
||||
assert_equal json[:data][:registrar][:username], new_user.username
|
||||
assert json[:data][:registrar][:roles].include? 'super'
|
||||
assert_equal json[:data][:registrar][:registrar_name], 'Good Names'
|
||||
assert_equal json[:data][:registrar][:balance][:amount].to_f, new_user.registrar.cash_account.balance
|
||||
assert json[:data][:registrar][:abilities].is_a? Hash
|
||||
end
|
||||
|
||||
def test_switches_to_unlinked_api_user
|
||||
new_user = users(:api_goodnames)
|
||||
new_user.update(identity_code: '4444')
|
||||
request_body = {
|
||||
auth: {
|
||||
new_user_id: new_user.id,
|
||||
},
|
||||
}
|
||||
|
||||
put '/repp/v1/registrar/auth/switch_user', headers: @auth_headers, params: request_body
|
||||
json = JSON.parse(response.body, symbolize_names: true)
|
||||
|
||||
assert_response :bad_request
|
||||
assert_equal 'Cannot switch to unlinked user', json[:message]
|
||||
end
|
||||
end
|
|
@ -0,0 +1,46 @@
|
|||
require 'test_helper'
|
||||
|
||||
class ReppV1RegistrarAuthTaraCallbackTest < ActionDispatch::IntegrationTest
|
||||
def setup
|
||||
@user = users(:api_bestnames)
|
||||
username = nil
|
||||
password = nil
|
||||
token = Base64.encode64("#{username}:#{password}")
|
||||
token = "Basic #{token}"
|
||||
|
||||
@auth_headers = { 'Authorization' => token }
|
||||
end
|
||||
|
||||
def test_validates_user_from_omniauth_params
|
||||
request_body = {
|
||||
auth: {
|
||||
uid: 'EE1234',
|
||||
},
|
||||
}
|
||||
|
||||
post '/repp/v1/registrar/auth/tara_callback', headers: @auth_headers, params: request_body
|
||||
json = JSON.parse(response.body, symbolize_names: true)
|
||||
|
||||
assert_response :ok
|
||||
assert_equal 1000, json[:code]
|
||||
assert_equal 'Command completed successfully', json[:message]
|
||||
|
||||
user_token = Base64.urlsafe_encode64("#{@user.username}:#{@user.plain_text_password}")
|
||||
assert_equal json[:data][:username], @user.username
|
||||
assert_equal json[:data][:token], user_token
|
||||
end
|
||||
|
||||
def test_invalidates_user_with_wrong_omniauth_params
|
||||
request_body = {
|
||||
auth: {
|
||||
uid: '33333',
|
||||
},
|
||||
}
|
||||
|
||||
post '/repp/v1/registrar/auth/tara_callback', headers: @auth_headers, params: request_body
|
||||
json = JSON.parse(response.body, symbolize_names: true)
|
||||
|
||||
assert_response :bad_request
|
||||
assert_equal 'No such user', json[:message]
|
||||
end
|
||||
end
|
44
test/integration/repp/v1/registrar/summary_test.rb
Normal file
44
test/integration/repp/v1/registrar/summary_test.rb
Normal file
|
@ -0,0 +1,44 @@
|
|||
require 'test_helper'
|
||||
|
||||
class ReppV1RegistrarSummaryTest < ActionDispatch::IntegrationTest
|
||||
def setup
|
||||
@user = users(:api_bestnames)
|
||||
token = Base64.encode64("#{@user.username}:#{@user.plain_text_password}")
|
||||
token = "Basic #{token}"
|
||||
|
||||
@auth_headers = { 'Authorization' => token }
|
||||
end
|
||||
|
||||
def test_checks_user_summary_info
|
||||
get '/repp/v1/registrar/summary', headers: @auth_headers
|
||||
json = JSON.parse(response.body, symbolize_names: true)
|
||||
|
||||
assert_response :ok
|
||||
assert_equal 1000, json[:code]
|
||||
assert_equal 'Command completed successfully', json[:message]
|
||||
|
||||
assert_equal json[:data][:username], @user.username
|
||||
assert_equal json[:data][:registrar_name], 'Best Names'
|
||||
assert_equal json[:data][:domains], @user.registrar.domains.count
|
||||
assert_equal json[:data][:contacts], @user.registrar.contacts.count
|
||||
assert json[:data][:notification].is_a? Hash
|
||||
assert_equal json[:data][:notifications_count], @user.unread_notifications.count
|
||||
end
|
||||
|
||||
def test_checks_limited_user_summary_info
|
||||
@user.update(roles: ['billing'])
|
||||
get '/repp/v1/registrar/summary', headers: @auth_headers
|
||||
json = JSON.parse(response.body, symbolize_names: true)
|
||||
|
||||
assert_response :ok
|
||||
assert_equal 1000, json[:code]
|
||||
assert_equal 'Command completed successfully', json[:message]
|
||||
|
||||
assert_equal json[:data][:username], @user.username
|
||||
assert_equal json[:data][:registrar_name], 'Best Names'
|
||||
assert_nil json[:data][:domains]
|
||||
assert_nil json[:data][:contacts]
|
||||
assert_nil json[:data][:notification]
|
||||
assert_nil json[:data][:notifications_count]
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue