Merge branch 'master' into 2334-remove-que

This commit is contained in:
Thiago Youssef 2022-09-28 07:40:02 -03:00
commit a6a3f72032
240 changed files with 5827 additions and 1432 deletions

View file

@ -12,6 +12,7 @@ shop:
period: 1
period_unit: m
uuid: 1b3ee442-e8fe-4922-9492-8fcb9dccc69c
created_at: <%= 2.days.ago.to_s :db %>
airport:
name: airport.test
@ -24,6 +25,7 @@ airport:
period: 1
period_unit: m
uuid: 2df2c1a1-8f6a-490a-81be-8bdf29866880
created_at: <%= 2.days.ago.to_s :db %>
library:
name: library.test
@ -36,6 +38,7 @@ library:
period: 1
period_unit: m
uuid: 647bcc48-8d5e-4a04-8ce5-2a3cd17b6eab
created_at: <%= 2.days.ago.to_s :db %>
metro:
name: metro.test
@ -48,6 +51,7 @@ metro:
period: 1
period_unit: m
uuid: ef97cb80-333b-4893-b9df-163f2b452798
created_at: <%= 2.days.ago.to_s :db %>
hospital:
name: hospital.test

View file

@ -0,0 +1,3 @@
name
tere.test
chao.test
1 name
2 tere.test
3 chao.test

View file

@ -0,0 +1,4 @@
name
tere.test
chao.test
cha.chacha
1 name
2 tere.test
3 chao.test
4 cha.chacha

View file

@ -7,7 +7,7 @@ class AdminAreaAccountActivitiesIntegrationTest < ApplicationSystemTestCase
sign_in users(:admin)
@original_default_language = Setting.default_language
end
def test_show_account_activities_page
account_activities(:one).update(sum: "123.00")
visit admin_account_activities_path
@ -19,7 +19,7 @@ class AdminAreaAccountActivitiesIntegrationTest < ApplicationSystemTestCase
visit admin_root_path
click_link_or_button 'Settings', match: :first
find(:xpath, "//ul/li/a[text()='Account activities']").click
assert has_current_path?(admin_account_activities_path(created_after: 'today'))
end

View file

@ -0,0 +1,173 @@
require 'test_helper'
require 'application_system_test_case'
class AdminAreaAuctionIntegrationTest < ApplicationSystemTestCase
setup do
sign_in users(:admin)
@original_default_language = Setting.default_language
end
def test_should_open_index_page
visit admin_root_path
click_link_or_button 'Settings', match: :first
find(:xpath, "//ul/li/a[text()='Auctions']").click
assert_text 'Auctions'
end
def test_search_domains
visit admin_auctions_path
auction = auctions(:one)
fill_in 'domain_matches', :with => auction.domain
find(:xpath, ".//button[./span[contains(@class, 'glyphicon-search')]]", match: :first).click
assert_text auction.domain
assert_text 'auto'
assert_text 'no_bids'
end
def test_filter_no_bids_auction
auction_one = auctions(:one)
auction_two = auctions(:idn)
visit admin_auctions_path
select "no_bids", :from => "statuses_contains"
find(:xpath, ".//button[./span[contains(@class, 'glyphicon-search')]]", match: :first).click
assert_text auction_one.domain
assert_text auction_two.domain
end
def test_manually_create_auction
visit admin_auctions_path
fill_in 'domain', :with => 'new-awesome-auction.test'
find(:id, "new-auction-btn", match: :first).click
assert_text 'new-awesome-auction.test'
assert_text 'manual'
assert_text 'started'
end
def test_manually_create_auction_with_punycode
visit admin_auctions_path
fill_in 'domain', :with => 'xn--phimtte-10ad.test'
find(:id, "new-auction-btn", match: :first).click
assert_text 'xn--phimtte-10ad.test'
assert_text 'manual'
assert_text 'started'
end
def test_raise_error_if_try_to_add_auction_with_invalid_zone
visit admin_auctions_path
fill_in 'domain', :with => 'new-awesome-auction.chuchacha'
find(:id, "new-auction-btn", match: :first).click
assert_no_text 'new-awesome-auction.chuchacha'
assert_text 'Cannot generate domain. Reason: invalid format'
end
def test_raise_error_if_try_to_add_auction_with_invalid_format
visit admin_auctions_path
fill_in 'domain', :with => '#de$er.test'
find(:id, "new-auction-btn", match: :first).click
assert_no_text '#de$er.test'
assert_text 'Cannot generate domain. Reason: invalid format'
end
def test_raise_error_if_try_to_add_same_domain
visit admin_auctions_path
fill_in 'domain', :with => 'new-awesome-auction.test'
find(:id, "new-auction-btn", match: :first).click
fill_in 'domain', :with => 'new-awesome-auction.test'
find(:id, "new-auction-btn", match: :first).click
assert_text 'Adding new-awesome-auction.test failed - domain registered or regsitration is blocked'
end
def test_raise_error_if_try_to_add_registred_domain
visit admin_auctions_path
domain = domains(:shop)
fill_in 'domain', :with => domain.name
find(:id, "new-auction-btn", match: :first).click
assert_text "Adding #{domain.name} failed - domain registered or regsitration is blocked"
end
def test_raise_error_if_try_to_add_blocked_domain
visit admin_auctions_path
domain = blocked_domains(:one)
fill_in 'domain', :with => domain.name
find(:id, "new-auction-btn", match: :first).click
assert_text "Adding #{domain.name} failed - domain registered or regsitration is blocked"
end
def test_raise_error_if_try_to_add_disputed_domain
visit admin_auctions_path
domain = disputes(:active)
fill_in 'domain', :with => domain.domain_name
find(:id, "new-auction-btn", match: :first).click
assert_text "Adding #{domain.domain_name} failed - domain registered or regsitration is blocked"
end
def test_upload_invalid_csv_file
visit admin_auctions_path
attach_file(:q_file, Rails.root.join('test', 'fixtures', 'files', 'mass_actions', 'invalid_mass_force_delete_list.csv').to_s)
click_link_or_button 'Upload csv'
assert_text "Invalid CSV format. Should be column with 'name' where is the list of name of domains!"
end
def test_upload_valid_csv_file
visit admin_auctions_path
attach_file(:q_file, Rails.root.join('test', 'fixtures', 'files', 'auction_domains_list.csv').to_s)
click_link_or_button 'Upload csv'
assert_text "tere.test"
assert_text "chao.test"
end
def test_upload_valid_csv_file_with_invalid_item
visit admin_auctions_path
attach_file(:q_file, Rails.root.join('test', 'fixtures', 'files', 'auction_domains_list_with_invalid_item.csv').to_s)
click_link_or_button 'Upload csv'
assert_text "tere.test"
assert_text "chao.test"
assert_text "These domains were ignored: cha.chacha"
end
def test_should_remove_domain_from_reserved_if_it_added_to_auction
visit admin_auctions_path
domain = reserved_domains(:one)
fill_in 'domain', :with => domain.name
find(:id, "new-auction-btn", match: :first).click
assert_text domain.name
assert_text 'manual'
assert_text 'started'
visit admin_reserved_domains_path
assert_no_text domain.name
end
def test_should_open_reserved_page_in_modal_window
visit admin_auctions_path
find(:id, "reserved-modal", match: :first).click
assert_text 'Reserved domains'
end
end

View file

@ -24,6 +24,20 @@ class AdminAreaInvoicesIntegrationTest < ApplicationIntegrationTest
end
def test_create_new_invoice
invoice_n = Invoice.order(number: :desc).last.number
stub_request(:post, "https://eis_billing_system:3000/api/v1/invoice_generator/invoice_generator").
to_return(status: 200, body: "{\"everypay_link\":\"http://link.test\"}", headers: {})
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(:put, "https://registry:3000/eis_billing/e_invoice_response").
to_return(status: 200, body: "{\"invoice_number\":\"#{invoice_n + 3}\"}, {\"date\":\"#{Time.zone.now-10.minutes}\"}", headers: {})
stub_request(:post, "https://eis_billing_system:3000/api/v1/e_invoice/e_invoice").
to_return(status: 200, body: "", headers: {})
visit new_admin_invoice_path
assert_text 'Create new invoice'

View file

@ -18,19 +18,21 @@ class APIDomainAdminContactsTest < ApplicationIntegrationTest
ident_country_code: 'LV')
patch '/repp/v1/domains/admin_contacts', params: { current_contact_id: @admin_current.code,
new_contact_id: @admin_new.code },
headers: { 'HTTP_AUTHORIZATION' => http_auth_key }
new_contact_id: @admin_new.code },
headers: { 'HTTP_AUTHORIZATION' => http_auth_key }
assert_response :bad_request
assert_equal ({ code: 2304, message: 'Admin contacts must be identical', data: {} }),
assert_equal ({ code: 2304,
message: 'New and current admin contacts ident data must be identical',
data: {} }),
JSON.parse(response.body, symbolize_names: true)
end
def test_replace_all_admin_contacts_of_the_current_registrar
assert @admin_new.identical_to?(@admin_current)
patch '/repp/v1/domains/admin_contacts', params: { current_contact_id: @admin_current.code,
new_contact_id: @admin_new.code },
headers: { 'HTTP_AUTHORIZATION' => http_auth_key }
new_contact_id: @admin_new.code },
headers: { 'HTTP_AUTHORIZATION' => http_auth_key }
assert_nil domains(:shop).admin_contacts.find_by(code: @admin_current.code)
assert domains(:shop).admin_contacts.find_by(code: @admin_new.code)
@ -41,8 +43,8 @@ class APIDomainAdminContactsTest < ApplicationIntegrationTest
domains(:airport).update!(statuses: [DomainStatus::SERVER_UPDATE_PROHIBITED])
patch '/repp/v1/domains/admin_contacts', params: { current_contact_id: @admin_current.code,
new_contact_id: @admin_new.code },
headers: { 'HTTP_AUTHORIZATION' => http_auth_key }
new_contact_id: @admin_new.code },
headers: { 'HTTP_AUTHORIZATION' => http_auth_key }
assert domains(:airport).admin_contacts.find_by(code: @admin_current.code)
end
@ -51,12 +53,13 @@ class APIDomainAdminContactsTest < ApplicationIntegrationTest
domain = domains(:airport)
domain.admin_contacts = [@admin_current]
patch '/repp/v1/domains/admin_contacts', params: { current_contact_id: @admin_current.code,
new_contact_id: @admin_new.code },
headers: { 'HTTP_AUTHORIZATION' => http_auth_key }
new_contact_id: @admin_new.code },
headers: { 'HTTP_AUTHORIZATION' => http_auth_key }
assert_response :ok
assert_equal ({ code: 1000, message: 'Command completed successfully', data: { affected_domains: %w[airport.test shop.test],
skipped_domains: [] }}),
assert_equal ({ code: 1000, message: 'Command completed successfully',
data: { affected_domains: %w[airport.test shop.test],
skipped_domains: [] } }),
JSON.parse(response.body, symbolize_names: true)
end

View file

@ -20,8 +20,8 @@ class ApiV1AuctionDetailsTest < ActionDispatch::IntegrationTest
assert_response :ok
assert_equal ({ 'id' => '1b3ee442-e8fe-4922-9492-8fcb9dccc69c',
'domain' => 'auction.test',
'status' => Auction.statuses[:no_bids] }), ActiveSupport::JSON
.decode(response.body)
'status' => Auction.statuses[:no_bids],
'platform' => nil }), ActiveSupport::JSON.decode(response.body)
end
def test_auction_not_found

View file

@ -15,8 +15,8 @@ class ApiV1AuctionListTest < ActionDispatch::IntegrationTest
assert_response :ok
assert_equal ([{ 'id' => '1b3ee442-e8fe-4922-9492-8fcb9dccc69c',
'domain' => 'auction.test',
'status' => Auction.statuses[:started] }]), ActiveSupport::JSON
.decode(response.body)
'status' => Auction.statuses[:started],
'platform' => nil }]), ActiveSupport::JSON.decode(response.body)
end
def test_does_not_return_finished_auctions

View file

@ -27,8 +27,8 @@ class ApiV1AuctionUpdateTest < ActionDispatch::IntegrationTest
assert_response :ok
assert_equal ({ 'id' => '1b3ee442-e8fe-4922-9492-8fcb9dccc69c',
'domain' => 'auction.test',
'status' => Auction.statuses[:awaiting_payment] }), ActiveSupport::JSON
.decode(response.body)
'status' => Auction.statuses[:awaiting_payment],
'platform' => nil }), ActiveSupport::JSON.decode(response.body)
end
def test_marks_as_awaiting_payment

View file

@ -0,0 +1,39 @@
require 'test_helper'
class DirectoResponseTest < ApplicationIntegrationTest
setup do
sign_in users(:api_bestnames)
@invoice = invoices(:one)
@response_xml = "<?xml version='1.0' encoding='UTF-8'?><results><Result Type='0' Desc='OK' docid='#{@invoice.number}' doctype='ARVE' submit='Invoices'/></results>"
Spy.on_instance_method(EisBilling::BaseController, :authorized).and_return(true)
end
def test_should_created_directo_instance
directo_response_from_billing = {
response: @response_xml,
month: true
}
assert_difference 'Directo.count', 1 do
put eis_billing_directo_response_path, params: JSON.parse(directo_response_from_billing.to_json),
headers: { 'HTTP_COOKIE' => 'session=api_bestnames' }
end
end
def test_should_update_related_invoice
directo_response_from_billing = {
response: @response_xml
}
refute @invoice.in_directo
assert_difference 'Directo.count', 1 do
put eis_billing_directo_response_path, params: JSON.parse(directo_response_from_billing.to_json),
headers: { 'HTTP_COOKIE' => 'session=api_bestnames' }
end
@invoice.reload
assert @invoice.in_directo
end
end

View file

@ -0,0 +1,17 @@
require 'test_helper'
class EInvoiceResponseTest < ApplicationIntegrationTest
setup do
sign_in users(:api_bestnames)
@invoice = invoices(:one)
Spy.on_instance_method(EisBilling::BaseController, :authorized).and_return(true)
end
def test_invoice_should_be_mark_as_sent
assert_nil @invoice.e_invoice_sent_at
put eis_billing_e_invoice_response_path, params: { invoice_number: @invoice.number}
@invoice.reload
assert_not_nil @invoice.e_invoice_sent_at
end
end

View file

@ -0,0 +1,41 @@
require 'test_helper'
class LhvConnectTransactionsIntegrationTest < ApplicationIntegrationTest
setup do
@invoice = invoices(:unpaid)
sign_in users(:api_bestnames)
Spy.on_instance_method(EisBilling::BaseController, :authorized).and_return(true)
end
def test_should_saved_transaction_data
test_transaction_1 = OpenStruct.new(amount: 0.1,
currency: 'EUR',
date: Time.zone.today,
payment_reference_number: '2199812',
payment_description: 'description 2199812')
test_transaction_2 = OpenStruct.new(amount: 0.1,
currency: 'EUR',
date: Time.zone.today,
payment_reference_number: '2199813',
payment_description: 'description 2199813')
test_transaction_3 = OpenStruct.new(amount: 0.1,
currency: 'EUR',
date: Time.zone.today,
payment_reference_number: '2199814',
payment_description: 'description 2199814')
lhv_transactions = []
lhv_transactions << test_transaction_1
lhv_transactions << test_transaction_2
lhv_transactions << test_transaction_3
assert_difference 'BankStatement.count', 1 do
assert_difference 'BankTransaction.count', 3 do
post eis_billing_lhv_connect_transactions_path, params: { '_json' => JSON.parse(lhv_transactions.to_json) },
headers: { 'HTTP_COOKIE' => 'session=api_bestnames' }
end
end
end
end

View file

@ -0,0 +1,32 @@
require 'test_helper'
class PaymentStatusTest < ApplicationIntegrationTest
setup do
sign_in users(:api_bestnames)
@invoice = invoices(:one)
@unpaid = invoices(:unpaid)
@registrar = registrars(:bestnames)
Spy.on_instance_method(EisBilling::BaseController, :authorized).and_return(true)
end
def shoudl_update_buyer_balance
assert @invoice.paid?
assert_equal @invoice.buyer.balance.to_f, 100.0
payload = {
payment_state: 'settled',
order_reference: @unpaid.number,
standing_amount: @unpaid.total,
transaction_time: Time.zone.now,
}
put eis_billing_payment_status_path, params: payload
@invoice.reload
@invoice.buyer.reload
@registrar.reload
assert @invoice.paid?
assert_equal @invoice.buyer.balance.to_f, 100.0
end
end

View file

@ -142,42 +142,42 @@ class EppContactCreateBaseTest < EppTestCase
assert_epp_response :parameter_value_syntax_error
end
def test_responces_error_with_email_error
name = 'new'
email = 'new@registrar@test'
phone = '+1.2'
# def test_responces_error_with_email_error
# name = 'new'
# email = 'new@registrar@test'
# phone = '+1.2'
request_xml = <<-XML
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<epp xmlns="#{Xsd::Schema.filename(for_prefix: 'epp-ee', for_version: '1.0')}">
<command>
<create>
<contact:create xmlns:contact="#{Xsd::Schema.filename(for_prefix: 'contact-ee', for_version: '1.1')}">
<contact:postalInfo>
<contact:name>#{name}</contact:name>
</contact:postalInfo>
<contact:voice>#{phone}</contact:voice>
<contact:email>#{email}</contact:email>
</contact:create>
</create>
<extension>
<eis:extdata xmlns:eis="#{Xsd::Schema.filename(for_prefix: 'eis', for_version: '1.0')}">
<eis:ident type="priv" cc="US">any</eis:ident>
</eis:extdata>
</extension>
</command>
</epp>
XML
# request_xml = <<-XML
# <?xml version="1.0" encoding="UTF-8" standalone="no"?>
# <epp xmlns="#{Xsd::Schema.filename(for_prefix: 'epp-ee', for_version: '1.0')}">
# <command>
# <create>
# <contact:create xmlns:contact="#{Xsd::Schema.filename(for_prefix: 'contact-ee', for_version: '1.1')}">
# <contact:postalInfo>
# <contact:name>#{name}</contact:name>
# </contact:postalInfo>
# <contact:voice>#{phone}</contact:voice>
# <contact:email>#{email}</contact:email>
# </contact:create>
# </create>
# <extension>
# <eis:extdata xmlns:eis="#{Xsd::Schema.filename(for_prefix: 'eis', for_version: '1.0')}">
# <eis:ident type="priv" cc="US">any</eis:ident>
# </eis:extdata>
# </extension>
# </command>
# </epp>
# XML
assert_no_difference 'Contact.count' do
post epp_create_path, params: { frame: request_xml },
headers: { 'HTTP_COOKIE' => 'session=api_bestnames' }
end
# assert_no_difference 'Contact.count' do
# post epp_create_path, params: { frame: request_xml },
# headers: { 'HTTP_COOKIE' => 'session=api_bestnames' }
# end
response_xml = Nokogiri::XML(response.body)
assert_correct_against_schema response_xml
assert_epp_response :parameter_value_syntax_error
end
# response_xml = Nokogiri::XML(response.body)
# assert_correct_against_schema response_xml
# assert_epp_response :parameter_value_syntax_error
# end
def test_respects_custom_code
name = 'new'

View file

@ -80,6 +80,35 @@ class EppContactUpdateBaseTest < EppTestCase
assert_emails 1
end
def test_destroy_old_validation_when_email_is_changed
@contact.verify_email
old_validation_event = @contact.validation_events.first
@contact.update_columns(code: @contact.code.upcase)
request_xml = <<-XML
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<epp xmlns="#{Xsd::Schema.filename(for_prefix: 'epp-ee', for_version: '1.0')}">
<command>
<update>
<contact:update xmlns:contact="#{Xsd::Schema.filename(for_prefix: 'contact-ee', for_version: '1.1')}">
<contact:id>john-001</contact:id>
<contact:chg>
<contact:email>john-new@inbox.test</contact:email>
</contact:chg>
</contact:update>
</update>
</command>
</epp>
XML
post epp_update_path, params: { frame: request_xml },
headers: { 'HTTP_COOKIE' => 'session=api_bestnames' }
assert_raises(ActiveRecord::RecordNotFound) do
ValidationEvent.find(old_validation_event.id)
end
end
def test_skips_notifying_contact_when_email_is_not_changed
assert_equal 'john-001', @contact.code
assert_equal 'john@inbox.test', @contact.email

View file

@ -717,52 +717,6 @@ class EppDomainUpdateBaseTest < EppTestCase
assert_no_emails
end
# COMMENT OU REASON: FOR EXPIRED DOMAIN SHOULD NOT SET FD
# def test_makes_update_if_was_forcedelete
# contact = @domain.contacts.first
# contact.update_attribute(:email, '`@outlook.test')
# contact.verify_email
# assert contact.email_verification_failed?
# @domain.reload
#
# assert @domain.force_delete_scheduled?
#
# @domain.update_attribute(:statuses_before_force_delete, nil)
#
# Setting.request_confirmation_on_registrant_change_enabled = true
# new_registrant = contacts(:william).becomes(Registrant)
# assert_not_equal new_registrant, @domain.registrant
#
# request_xml = <<-XML
# <?xml version="1.0" encoding="UTF-8" standalone="no"?>
# <epp xmlns="#{Xsd::Schema.filename(for_prefix: 'epp-ee', for_version: '1.0')}">
# <command>
# <update>
# <domain:update xmlns:domain="#{Xsd::Schema.filename(for_prefix: 'domain-ee', for_version: '1.2')}">
# <domain:name>#{@domain.name}</domain:name>
# <domain:chg>
# <domain:registrant verified="yes">#{new_registrant.code}</domain:registrant>
# </domain:chg>
# </domain:update>
# </update>
# <extension>
# <eis:extdata xmlns:eis="#{Xsd::Schema.filename(for_prefix: 'eis', for_version: '1.0')}">
# <eis:legalDocument type="pdf">#{'test' * 2000}</eis:legalDocument>
# </eis:extdata>
# </extension>
# </command>
# </epp>
# XML
#
# post epp_update_path, params: { frame: request_xml },
# headers: { 'HTTP_COOKIE' => 'session=api_bestnames' }
# @domain.reload
#
# response_xml = Nokogiri::XML(response.body)
# assert_correct_against_schema response_xml
# assert_epp_response :completed_successfully
# end
def test_clears_force_delete_when_registrar_changed
Setting.request_confirmation_on_registrant_change_enabled = true
new_registrant = contacts(:william).becomes(Registrant)

View file

@ -56,7 +56,7 @@ class EppPollTest < EppTestCase
bulk_action = actions(:contacts_update_bulk_action)
@notification.update!(action: bulk_action,
attached_obj_id: bulk_action.id,
attached_obj_type: 'BulkAction')
attached_obj_type: 'ContactUpdateAction')
post epp_poll_path, params: { frame: request_req_xml },
headers: { 'HTTP_COOKIE' => 'session=api_bestnames' }

View file

@ -1,14 +0,0 @@
require 'test_helper'
class ApplicationHelperTest < ActionView::TestCase
def test_env_style_when_pic_present
assert_dom_equal %{<body style={"background-image: url(#{image_path("registrar/bg-#{unstable_env}.png")});"}>},
%{<body style={"#{env_style}"}>}
end
def test_env_style_return_nil
env_style = ''
assert_dom_equal %{<body style=''>},
%{<body style={"#{env_style}"}>}
end
end

View file

@ -0,0 +1,70 @@
require 'test_helper'
class ReppV1AccountsActivitiesListTest < 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_accounts_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_accounts_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_accounts_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_accounts_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_accounts_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

View file

@ -10,6 +10,8 @@ class ReppV1BalanceTest < ActionDispatch::IntegrationTest
@auth_headers = { 'Authorization' => token }
end
def test_can_query_balance
get '/repp/v1/accounts/balance', headers: @auth_headers
json = JSON.parse(response.body, symbolize_names: true)
@ -44,8 +46,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

@ -0,0 +1,22 @@
require 'test_helper'
class ReppV1AccountsDetailsTest < 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/accounts/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

View file

@ -0,0 +1,51 @@
require 'test_helper'
class ReppV1AccountsSwitchUserTest < 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 = {
account: {
new_user_id: new_user.id,
},
}
put '/repp/v1/accounts/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 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 = {
account: {
new_user_id: new_user.id,
},
}
put '/repp/v1/accounts/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

View file

@ -0,0 +1,69 @@
require 'test_helper'
class ReppV1AccountsUpdateAutoReloadBalanceTest < 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/accounts/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/accounts/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/accounts/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

View file

@ -0,0 +1,30 @@
require 'test_helper'
class ReppV1AccountsUpdateDetailsTest < 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/accounts', 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

View file

@ -14,7 +14,7 @@ class ReppV1ContactsCheckTest < ActionDispatch::IntegrationTest
json = JSON.parse(response.body, symbolize_names: true)
assert_response :ok
assert_equal 'nonexistant:code', json[:data][:contact][:id]
assert_equal 'nonexistant:code', json[:data][:contact][:code]
assert_equal true, json[:data][:contact][:available]
end
@ -24,7 +24,7 @@ class ReppV1ContactsCheckTest < ActionDispatch::IntegrationTest
json = JSON.parse(response.body, symbolize_names: true)
assert_response :ok
assert_equal contact.code, json[:data][:contact][:id]
assert_equal contact.code, json[:data][:contact][:code]
assert_equal false, json[:data][:contact][:available]
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

@ -15,23 +15,22 @@ 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? String
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)
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 +39,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 +49,34 @@ 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
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

View 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

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

@ -52,6 +52,8 @@ class ReppV1DomainsContactsTest < ActionDispatch::IntegrationTest
end
def test_can_remove_admin_contacts
Spy.on_instance_method(Actions::DomainUpdate, :validate_email).and_return(true)
contact = contacts(:john)
payload = { contacts: [ { code: contact.code, type: 'admin' } ] }
post "/repp/v1/domains/#{@domain.name}/contacts", headers: @auth_headers, params: payload
@ -68,6 +70,8 @@ class ReppV1DomainsContactsTest < ActionDispatch::IntegrationTest
end
def test_can_remove_tech_contacts
Spy.on_instance_method(Actions::DomainUpdate, :validate_email).and_return(true)
contact = contacts(:john)
payload = { contacts: [ { code: contact.code, type: 'tech' } ] }
post "/repp/v1/domains/#{@domain.name}/contacts", headers: @auth_headers, params: payload
@ -77,6 +81,9 @@ class ReppV1DomainsContactsTest < ActionDispatch::IntegrationTest
delete "/repp/v1/domains/#{@domain.name}/contacts", headers: @auth_headers, params: payload
json = JSON.parse(response.body, symbolize_names: true)
@domain.reload
contact.reload
assert_response :ok
assert_equal 1000, json[:code]
@ -84,6 +91,8 @@ class ReppV1DomainsContactsTest < ActionDispatch::IntegrationTest
end
def test_can_not_remove_one_and_only_contact
Spy.on_instance_method(Actions::DomainUpdate, :validate_email).and_return(true)
contact = @domain.admin_contacts.last
payload = { contacts: [ { code: contact.code, type: 'admin' } ] }
@ -96,5 +105,4 @@ class ReppV1DomainsContactsTest < ActionDispatch::IntegrationTest
assert @domain.admin_contacts.any?
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
@ -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

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]

View file

@ -0,0 +1,104 @@
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)
invoice = Invoice.last
msg = {
invoice_number: invoice.number + 3
}
stub_request(:post, "https://eis_billing_system:3000/api/v1/invoice_generator/invoice_number_generator")
.to_return(status: 200, body: msg.to_json, headers: {})
msg2 = {
message: 'success'
}
stub_request(:post, "https://eis_billing_system:3000/api/v1/e_invoice/e_invoice").to_return(status: 200, body: msg2.to_json, headers: {})
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'
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: {})
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

View 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

View 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

View 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

View 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

View 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

View file

@ -0,0 +1,38 @@
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 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

View file

@ -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 :unauthorized
assert_equal 'No such user', json[:message]
end
end

View file

@ -0,0 +1,43 @@
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_equal json[:data][:balance][:amount].to_f, @user.registrar.cash_account.balance
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][:notification]
assert_nil json[:data][:notifications_count]
end
end

View file

@ -0,0 +1,45 @@
require 'test_helper'
class ReppV1StatsMarketShareTest < ActionDispatch::IntegrationTest
def setup
@user = users(:api_bestnames)
token = Base64.encode64("#{@user.username}:#{@user.plain_text_password}")
token = "Basic #{token}"
@auth_headers = { 'Authorization' => token }
@today = Time.zone.today.strftime('%m.%y')
end
def test_shows_market_share_distribution_data
get '/repp/v1/stats/market_share_distribution', headers: @auth_headers,
params: { q: { end_date: @today } }
json = JSON.parse(response.body, symbolize_names: true)
assert_response :ok
assert_equal 1000, json[:code]
assert_equal 'Command completed successfully', json[:message]
assert json[:data].is_a? Array
assert json[:data][0].is_a? Hash
assert_equal json[:data][0][:name], 'Best Names'
assert json[:data][0][:selected]
end
def test_shows_market_share_growth_rate_data
prev_date = Time.zone.today.last_month.strftime('%m.%y')
get '/repp/v1/stats/market_share_growth_rate', headers: @auth_headers,
params: { q: { end_date: @today,
compare_to_date: prev_date } }
json = JSON.parse(response.body, symbolize_names: true)
assert_response :ok
assert_equal 1000, json[:code]
assert_equal 'Command completed successfully', json[:message]
data = json[:data]
assert data[:data].is_a? Hash
assert data[:prev_data].is_a? Hash
assert_equal data[:data][:name], @today
assert data[:data][:domains].is_a? Array
end
end

View file

@ -11,32 +11,23 @@ class DoRequestTest < ActiveSupport::TestCase
@domain = domains(:shop)
@user = users(:api_bestnames)
@request.body = { data: { type: 'nameserver', id: @nameserver.hostname,
domains: ["shop.test"],
attributes: { hostname: 'new-ns.bestnames.test',
ipv4: '192.0.2.55',
ipv6: '2001:db8::55' } } }.to_json
@request.body = { data: { type: 'nameserver',
id: @nameserver.hostname,
domains: ['shop.test'],
attributes: { hostname: 'new-ns.bestnames.test',
ipv4: '192.0.2.55',
ipv6: '2001:db8::55' } } }.to_json
@request.basic_auth(@user.username, @user.plain_text_password)
end
def test_request_occurs
stub_request(:put, "http://epp:3000/repp/v1/registrar/nameservers").
with(
body: "{\"data\":{\"type\":\"nameserver\",\"id\":\"ns1.bestnames.test\",\"domains\":[\"shop.test\"],\"attributes\":{\"hostname\":\"new-ns.bestnames.test\",\"ipv4\":\"192.0.2.55\",\"ipv6\":\"2001:db8::55\"}}}",
headers: {
'Accept'=>'*/*',
'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
'Authorization'=>'Basic dGVzdF9iZXN0bmFtZXM6dGVzdHRlc3Q=',
'Content-Type'=>'application/json',
'Host'=>'epp:3000',
'User-Agent'=>'Ruby'
}).
to_return(status: 200, body: ["shop.test"], headers: {})
stub_request(:put, "#{ENV['repp_url']}registrar/nameservers")
.to_return(status: 200, body: ['shop.test'], headers: {})
action = Actions::DoRequest.new(@request, @uri)
response = action.call
assert_equal response.body, ["shop.test"]
assert_equal response.code, "200"
assert_equal response.body, ['shop.test']
assert_equal response.code, '200'
end
end

View file

@ -1,6 +1,6 @@
require "test_helper"
class DirectoInvoiceForwardJobTest < ActiveSupport::TestCase
class DirectoInvoiceForwardLegacyJobTest < ActiveSupport::TestCase
setup do
@invoice = invoices(:one)
@user = registrars(:bestnames)
@ -8,9 +8,9 @@ class DirectoInvoiceForwardJobTest < ActiveSupport::TestCase
end
def teardown
Setting.directo_monthly_number_min = 309901
Setting.directo_monthly_number_max = 309999
Setting.directo_monthly_number_last = 309901
Setting.directo_monthly_number_min = 309_901
Setting.directo_monthly_number_max = 309_999
Setting.directo_monthly_number_last = 309_901
end
def test_directo_json_sends_customer_as_hash
@ -38,7 +38,7 @@ class DirectoInvoiceForwardJobTest < ActiveSupport::TestCase
end.to_return(status: 200, body: response)
assert_nothing_raised do
DirectoInvoiceForwardJob.perform_now(monthly: false, dry: false)
DirectoInvoiceForwardLegacyJob.perform_now(monthly: false, dry: false)
end
assert_not_empty @invoice.directo_records.first.request
@ -49,10 +49,10 @@ class DirectoInvoiceForwardJobTest < ActiveSupport::TestCase
price = billing_prices(:create_one_year)
activity.update!(activity_type: 'create', price: price)
Setting.directo_monthly_number_max = 30991
Setting.directo_monthly_number_max = 30_991
assert_raises 'RuntimeError' do
DirectoInvoiceForwardJob.perform_now(monthly: true, dry: false)
DirectoInvoiceForwardLegacyJob.perform_now(monthly: true, dry: false)
end
end
@ -78,7 +78,7 @@ class DirectoInvoiceForwardJobTest < ActiveSupport::TestCase
end.to_return(status: 200, body: response)
assert_difference 'Setting.directo_monthly_number_last' do
DirectoInvoiceForwardJob.perform_now(monthly: true, dry: false)
DirectoInvoiceForwardLegacyJob.perform_now(monthly: true, dry: false)
end
end
@ -103,7 +103,7 @@ class DirectoInvoiceForwardJobTest < ActiveSupport::TestCase
end.to_return(status: 200, body: response)
assert_difference 'Setting.directo_monthly_number_last' do
DirectoInvoiceForwardJob.perform_now(monthly: true, dry: false)
DirectoInvoiceForwardLegacyJob.perform_now(monthly: true, dry: false)
end
end
@ -126,7 +126,7 @@ class DirectoInvoiceForwardJobTest < ActiveSupport::TestCase
end.to_return(status: 200, body: response)
assert_difference 'Setting.directo_monthly_number_last' do
DirectoInvoiceForwardJob.perform_now(monthly: true, dry: false)
DirectoInvoiceForwardLegacyJob.perform_now(monthly: true, dry: false)
end
end
@ -148,7 +148,7 @@ class DirectoInvoiceForwardJobTest < ActiveSupport::TestCase
end.to_return(status: 200, body: response)
assert_difference 'Setting.directo_monthly_number_last' do
DirectoInvoiceForwardJob.perform_now(monthly: true, dry: false)
DirectoInvoiceForwardLegacyJob.perform_now(monthly: true, dry: false)
end
end
@ -186,7 +186,7 @@ class DirectoInvoiceForwardJobTest < ActiveSupport::TestCase
(body.include? 'StartDate') && (body.include? 'EndDate') && (body.include? 'goodnames')
end.to_return(status: 200, body: response)
DirectoInvoiceForwardJob.perform_now(monthly: true, dry: false)
DirectoInvoiceForwardLegacyJob.perform_now(monthly: true, dry: false)
assert_requested first_registrar_stub
assert_requested second_registrar_stub

View file

@ -13,7 +13,8 @@ class NameserverRecordValidationJobTest < ActiveSupport::TestCase
def test_nameserver_should_validate_succesfully_and_set_validation_datetime
mock_dns_response = OpenStruct.new
answer = OpenStruct.new
answer.serial = '12343'
answer.instance_variable_set(:@serial, '12345')
mock_dns_response.answer = [ answer ]
Spy.on_instance_method(NameserverValidator, :setup_resolver).and_return(Dnsruby::Resolver.new)
@ -26,6 +27,8 @@ class NameserverRecordValidationJobTest < ActiveSupport::TestCase
NameserverRecordValidationJob.perform_now(domain_name: @domain.name)
@nameserver.reload
p @nameserver
assert_not_nil @nameserver.validation_datetime
assert_nil @nameserver.validation_counter
assert_nil @nameserver.failed_validation_reason
@ -47,7 +50,7 @@ class NameserverRecordValidationJobTest < ActiveSupport::TestCase
assert_nil @nameserver.validation_datetime
assert @nameserver.validation_counter, 1
assert @nameserver.failed_validation_reason.include? "No any answer comes from **#{@nameserver.hostname}**"
assert @nameserver.failed_validation_reason.include? "DNS Server **#{@nameserver.hostname}**"
end
def test_should_return_failed_validation_with_serial_reason
@ -68,13 +71,14 @@ class NameserverRecordValidationJobTest < ActiveSupport::TestCase
assert_nil @nameserver.validation_datetime
assert @nameserver.validation_counter, 1
assert @nameserver.failed_validation_reason.include? "Serial number for nameserver hostname **#{@nameserver.hostname}** doesn't present. SOA validation failed."
assert @nameserver.failed_validation_reason.include? "Serial number for nameserver hostname **#{@nameserver.hostname}** of #{@nameserver.domain.name} doesn't present in zone. SOA validation failed."
end
def test_after_third_invalid_times_nameserver_should_be_invalid
mock_dns_response = OpenStruct.new
answer = OpenStruct.new
answer.some_field = '12343'
answer.type = 'SOA'
mock_dns_response.answer = [ answer ]
Spy.on_instance_method(NameserverValidator, :setup_resolver).and_return(Dnsruby::Resolver.new)
@ -89,9 +93,12 @@ class NameserverRecordValidationJobTest < ActiveSupport::TestCase
end
@nameserver.reload
p @nameserver.failed_validation_reason
assert_nil @nameserver.validation_datetime
assert @nameserver.validation_counter, 1
assert @nameserver.failed_validation_reason.include? "Serial number for nameserver hostname **#{@nameserver.hostname}** doesn't present. SOA validation failed."
assert @nameserver.failed_validation_reason.include? "Serial number for nameserver hostname **#{@nameserver.hostname}** of #{@nameserver.domain.name} doesn't present in zone. SOA validation failed."
assert @nameserver.failed_validation?
end

View file

@ -1,10 +1,14 @@
require 'test_helper'
class SendEInvoiceJobTest < ActiveJob::TestCase
class SendEInvoiceLegacyJobTest < ActiveJob::TestCase
def teardown
EInvoice.provider = EInvoice::Providers::TestProvider.new
EInvoice::Providers::TestProvider.deliveries.clear
msg = { message: 'success' }
stub_request(:post, "https://eis_billing_system:3000/api/v1/e_invoice/e_invoice")
.to_return(status: 200, body: msg.to_json, headers: {})
end
def test_if_invoice_is_sent
@ -15,7 +19,7 @@ class SendEInvoiceJobTest < ActiveJob::TestCase
assert_nothing_raised do
perform_enqueued_jobs do
SendEInvoiceJob.perform_now(@invoice.id, payable: true)
SendEInvoiceLegacyJob.perform_now(@invoice.id, payable: true)
end
end
@invoice.reload

View file

@ -0,0 +1,279 @@
require 'test_helper'
class SendMonthlyInvoicesJobTest < ActiveSupport::TestCase
include ActionMailer::TestHelper
setup do
@user = registrars(:bestnames)
@date = Time.zone.parse('2010-08-06')
travel_to @date
ActionMailer::Base.deliveries.clear
EInvoice.provider = EInvoice::Providers::TestProvider.new
EInvoice::Providers::TestProvider.deliveries.clear
response = { message: 'sucess' }
stub_request(:post, "https://eis_billing_system:3000/api/v1/e_invoice/e_invoice")
.to_return(status: 200, body: response.to_json, headers: {})
end
def teardown
Setting.directo_monthly_number_min = 309_901
Setting.directo_monthly_number_max = 309_999
Setting.directo_monthly_number_last = 309_901
EInvoice.provider = EInvoice::Providers::TestProvider.new
EInvoice::Providers::TestProvider.deliveries.clear
end
def test_fails_if_directo_bounds_exceedable
activity = account_activities(:one)
price = billing_prices(:create_one_year)
activity.update!(activity_type: 'create', price: price)
Setting.directo_monthly_number_max = 30_991
assert_no_difference 'Directo.count' do
assert_raises 'RuntimeError' do
SendMonthlyInvoicesJob.perform_now
end
end
assert_nil Invoice.find_by_monthly_invoice(true)
assert_emails 0
assert_equal 0, EInvoice::Providers::TestProvider.deliveries.count
end
def test_monthly_summary_is_not_delivered_if_dry
activity = account_activities(:one)
price = billing_prices(:create_one_year)
activity.update!(activity_type: 'create', price: price)
@user.update(language: 'et')
assert_difference 'Setting.directo_monthly_number_last' do
assert_no_difference 'Directo.count' do
SendMonthlyInvoicesJob.perform_now(dry: true)
end
end
invoice = Invoice.last
assert_equal 309_902, invoice.number
refute invoice.in_directo
assert invoice.e_invoice_sent_at.blank?
assert_emails 0
assert_equal 0, EInvoice::Providers::TestProvider.deliveries.count
end
def test_monthly_summary_is_delivered_if_invoice_already_exists
@monthly_invoice = invoices(:one)
@monthly_invoice.update(number: 309_902, monthly_invoice: true,
issue_date: @date.last_month.end_of_month,
due_date: @date.last_month.end_of_month,
metadata: metadata,
in_directo: false,
e_invoice_sent_at: nil)
activity = account_activities(:one)
price = billing_prices(:create_one_year)
activity.update!(activity_type: 'create', price: price)
@user.update(language: 'et')
response = <<-XML
<?xml version="1.0" encoding="UTF-8"?>
<results>
<Result Type="0" Desc="OK" docid="309902" doctype="ARVE" submit="Invoices"/>
</results>
XML
stub_request(:post, ENV['directo_invoice_url']).with do |request|
body = CGI.unescape(request.body)
(body.include? '.test registreerimine: 1 aasta(t)') &&
(body.include? 'Domeenide ettemaks') &&
(body.include? '309902')
end.to_return(status: 200, body: response)
assert_no_difference 'Setting.directo_monthly_number_last' do
assert_difference('Directo.count', 1) do
SendMonthlyInvoicesJob.perform_now
end
end
perform_enqueued_jobs
invoice = Invoice.last
assert_equal 309_902, invoice.number
assert invoice.in_directo
assert_not invoice.e_invoice_sent_at.blank?
assert_emails 1
email = ActionMailer::Base.deliveries.last
assert_equal ['billing@bestnames.test'], email.to
assert_equal 'Invoice no. 309902 (monthly invoice)', email.subject
assert email.attachments['invoice-309902.pdf']
# assert_equal 1, EInvoice::Providers::TestProvider.deliveries.count
end
def test_monthly_summary_is_delivered_in_estonian
activity = account_activities(:one)
price = billing_prices(:create_one_month)
activity.update!(activity_type: 'create', price: price)
@user.update(language: 'et')
response = <<-XML
<?xml version="1.0" encoding="UTF-8"?>
<results>
<Result Type="0" Desc="OK" docid="309902" doctype="ARVE" submit="Invoices"/>
</results>
XML
stub_request(:post, ENV['directo_invoice_url']).with do |request|
body = CGI.unescape(request.body)
(body.include? '.test registreerimine: 3 kuu(d)') &&
(body.include? 'Domeenide ettemaks') &&
(body.include? '309902')
end.to_return(status: 200, body: response)
assert_difference 'Setting.directo_monthly_number_last' do
assert_difference('Directo.count', 1) do
SendMonthlyInvoicesJob.perform_now
end
end
perform_enqueued_jobs
invoice = Invoice.last
assert_equal 309_902, invoice.number
assert invoice.in_directo
assert_not invoice.e_invoice_sent_at.blank?
assert_emails 1
email = ActionMailer::Base.deliveries.last
assert_equal ['billing@bestnames.test'], email.to
assert_equal 'Invoice no. 309902 (monthly invoice)', email.subject
assert email.attachments['invoice-309902.pdf']
# assert_equal 1, EInvoice::Providers::TestProvider.deliveries.count
end
def test_multi_year_purchases_have_duration_assigned
activity = account_activities(:one)
price = billing_prices(:create_one_year)
price.update(duration: 3.years)
activity.update(activity_type: 'create', price: price)
response = <<-XML
<?xml version="1.0" encoding="UTF-8"?>
<results>
<Result Type="0" Desc="OK" docid="309902" doctype="ARVE" submit="Invoices"/>
</results>
XML
stub_request(:post, ENV['directo_invoice_url']).with do |request|
body = CGI.unescape(request.body)
(body.include? 'StartDate') && (body.include? 'EndDate')
end.to_return(status: 200, body: response)
assert_difference 'Setting.directo_monthly_number_last' do
SendMonthlyInvoicesJob.perform_now
end
perform_enqueued_jobs
invoice = Invoice.last
assert_equal 309_902, invoice.number
assert invoice.in_directo
assert_not invoice.e_invoice_sent_at.blank?
end
def test_monthly_duration_products_are_present_in_summary
activity = account_activities(:one)
price = billing_prices(:create_one_month)
activity.update(activity_type: 'create', price: price)
response = <<-XML
<?xml version="1.0" encoding="UTF-8"?>
<results>
<Result Type="0" Desc="OK" docid="309902" doctype="ARVE" submit="Invoices"/>
</results>
XML
stub_request(:post, ENV['directo_invoice_url']).with do |request|
body = CGI.unescape(request.body)
body.include? 'month(s)'
end.to_return(status: 200, body: response)
assert_difference 'Setting.directo_monthly_number_last' do
SendMonthlyInvoicesJob.perform_now
end
perform_enqueued_jobs
invoice = Invoice.last
assert_equal 309_902, invoice.number
assert invoice.in_directo
assert_not invoice.e_invoice_sent_at.blank?
end
def test_sends_each_monthly_invoice_separately
WebMock.reset!
activity = account_activities(:one)
price = billing_prices(:create_one_year)
price.update(duration: 3.years)
activity.update(activity_type: 'create', price: price)
# Creating account activity for second action
another_activity = activity.dup
another_activity.account = accounts(:two)
AccountActivity.skip_callback(:create, :after, :update_balance)
another_activity.created_at = Time.zone.parse('2010-07-05 10:00')
another_activity.save
AccountActivity.set_callback(:create, :after, :update_balance)
response = <<-XML
<?xml version="1.0" encoding="UTF-8"?>
<results>
<Result Type="0" Desc="OK" docid="309902" doctype="ARVE" submit="Invoices"/>
</results>
XML
first_registrar_stub = stub_request(:post, ENV['directo_invoice_url']).with do |request|
body = CGI.unescape(request.body)
(body.include? 'StartDate') && (body.include? 'EndDate') && (body.include? 'bestnames')
end.to_return(status: 200, body: response)
second_registrar_stub = stub_request(:post, ENV['directo_invoice_url']).with do |request|
body = CGI.unescape(request.body)
(body.include? 'StartDate') && (body.include? 'EndDate') && (body.include? 'goodnames')
end.to_return(status: 200, body: response)
assert_difference('Invoice.count', 2) do
assert_difference('Directo.count', 2) do
SendMonthlyInvoicesJob.perform_now
end
end
perform_enqueued_jobs
assert_requested first_registrar_stub
assert_requested second_registrar_stub
assert_emails 2
assert_equal 2, EInvoice::Providers::TestProvider.deliveries.count
end
private
def metadata
{
"items" => [
{ "description" => "Domeenide registreerimine - Juuli 2010" },
{ "product_id" => nil, "quantity" => 1, "unit" => "tk", "price" => 10.0, "description" => ".test registreerimine: 1 aasta(t)" },
{ "product_id" => "ETTEM06", "description" => "Domeenide ettemaks", "quantity" => -1, "price" => 10.0, "unit" => "tk" },
],
}
end
end

View file

@ -0,0 +1,17 @@
require 'test_helper'
require 'serializers/repp/domain'
class SerializersReppDomainTest < ActiveSupport::TestCase
def setup
@domain = domains(:airport)
end
def test_returns_status_notes
status_notes = { 'serverForceDelete' => '`@internet2.ee' }
@domain.update!(statuses: %w[serverForceDelete], status_notes: status_notes)
@serializer = Serializers::Repp::Domain.new(@domain)
@json = @serializer.to_json
assert_equal(status_notes, @json[:statuses])
end
end

View file

@ -73,4 +73,21 @@ class DomainDeleteMailerTest < ActionMailer::TestCase
' / Domain shop.test is in deletion process' \
' / Домен shop.test в процессе удаления', email.subject
end
def test_forced_invalid_email
@domain.update(template_name: 'invalid_email')
@domain.reload
email = DomainDeleteMailer.forced(domain: @domain,
registrar: @domain.registrar,
registrant: @domain.registrant,
template_name: @domain.template_name).deliver_now
assert_emails 1
assert_equal ['legal@registry.test'], email.from
assert @domain.force_delete_contact_emails.sort == email.to.sort
assert_equal 'Domeen shop.test on kustutusmenetluses' \
' / Domain shop.test is in deletion process' \
' / Домен shop.test в процессе удаления', email.subject
end
end

View file

@ -28,33 +28,4 @@ class DomainExpireMailerTest < ActionMailer::TestCase
assert_equal I18n.t("domain_expire_mailer.expired_soft.subject", domain_name: domain.name),
email.subject
end
# COMMENT OU REASON: FOR EXPIRED DOMAIN SHOULD NOT SET FD
# def test_delivers_domain_expiration_soft_email_if_auto_fd
# domain = domains(:shop)
# email_address = domain.registrar.email
# assert_not domain.force_delete_scheduled?
# travel_to Time.zone.parse('2010-07-05')
# email = '`@internet.ee'
#
# Truemail.configure.default_validation_type = :regex
#
# contact = domain.admin_contacts.first
# contact.update_attribute(:email, email)
# contact.verify_email
#
# assert contact.email_verification_failed?
#
# domain.reload
#
# assert_no domain.force_delete_scheduled?
#
# email = DomainExpireMailer.expired_soft(domain: domain,
# registrar: domain.registrar,
# email: email_address).deliver_now
#
# assert_emails 1
# assert_equal I18n.t("domain_expire_mailer.expired_soft.subject", domain_name: domain.name),
# email.subject
# end
end

View file

@ -4,6 +4,12 @@ class BankTransactionTest < ActiveSupport::TestCase
setup do
@registrar = registrars(:bestnames)
@invoice = invoices(:one)
response_message = {
message: 'got it'
}
stub_request(:post, 'https://eis_billing_system:3000/api/v1/invoice_generator/invoice_status')
.to_return(status: 200, body: response_message.to_json, headers: {})
end
def test_matches_against_invoice_nubmber_and_reference_number
@ -16,6 +22,9 @@ class BankTransactionTest < ActiveSupport::TestCase
end
def test_binds_if_this_sum_invoice_already_present
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: {})
create_payable_invoice(number: '2222', total: 10, reference_no: '1234567')
another_invoice = @invoice.dup
another_invoice.save(validate: false)
@ -40,11 +49,13 @@ class BankTransactionTest < ActiveSupport::TestCase
end
def test_binds_if_this_sum_cancelled_invoice_already_present
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: {})
create_payable_invoice(number: '2222', total: 10, reference_no: '1234567')
another_invoice = @invoice.dup
another_invoice.save(validate: false)
another_item = @invoice.items.first.dup
another_item.invoice = another_invoice
@ -61,6 +72,9 @@ class BankTransactionTest < ActiveSupport::TestCase
end
def test_marks_the_first_one_as_paid_if_same_sum
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: {})
create_payable_invoice(number: '2222', total: 10, reference_no: '1234567')
another_invoice = @invoice.dup
another_invoice.save(validate: false)
@ -177,7 +191,7 @@ class BankTransactionTest < ActiveSupport::TestCase
def test_parsed_ref_no_returns_nil_if_ref_not_found
statement = BankTransaction.new
statement.description = "all invalid 12 123 55 77777 --"
statement.description = 'all invalid 12 123 55 77777 --'
assert_nil statement.parsed_ref_number
end
@ -193,6 +207,7 @@ class BankTransactionTest < ActiveSupport::TestCase
transaction.bind_invoice('2222')
end
end
private
def create_payable_invoice(attributes)

View file

@ -7,6 +7,9 @@ class ReferenceNoTest < ActiveSupport::TestCase
end
def test_generated_reference_number_conforms_to_format
stub_request(:post, "https://eis_billing_system:3000/api/v1/invoice_generator/reference_number_generator")
.to_return(status: 200, body: "{\"reference_number\":\"12332\"}", headers: {})
reference_no = Billing::ReferenceNo.generate
assert_match Billing::ReferenceNo::REGEXP, reference_no
end

View file

@ -137,9 +137,8 @@ class BouncedMailAddressTest < ActiveSupport::TestCase
bounced_mail = BouncedMailAddress.last
registrant = domains(:shop).registrant
registrant.verify_email(check_level: 'smtp')
assert_equal registrant.email, bounced_mail.email
assert registrant.email_verification_failed?
end
def sns_bounce_payload

View file

@ -1,39 +0,0 @@
require 'test_helper'
class ContactDisclosableTest < ActiveSupport::TestCase
setup do
@contact = contacts(:john)
@original_disclosable_attributes = Contact.disclosable_attributes
end
teardown do
Contact.disclosable_attributes = @original_disclosable_attributes
end
def test_no_disclosed_attributes_by_default
assert_empty Contact.new.disclosed_attributes
end
def test_disclosable_attributes
assert_equal %w[name email], Contact.disclosable_attributes
end
def test_valid_without_disclosed_attributes
@contact.disclosed_attributes = []
assert @contact.valid?
end
def test_invalid_when_attribute_is_not_disclosable
Contact.disclosable_attributes = %w[some disclosable]
@contact.disclosed_attributes = %w[some undisclosable]
assert @contact.invalid?
assert_includes @contact.errors[:disclosed_attributes], 'contain unsupported attribute(s)'
end
def test_valid_when_attribute_is_disclosable
Contact.disclosable_attributes = %w[some disclosable]
@contact.disclosed_attributes = %w[disclosable]
assert @contact.valid?
end
end

View file

@ -90,14 +90,14 @@ class ContactTest < ActiveJob::TestCase
assert contact.valid?
end
def test_email_verification_regex_error
Truemail.configure.default_validation_type = :regex
# def test_email_verification_regex_error
# Truemail.configure.default_validation_type = :regex
contact = valid_contact
contact.email = '`@internet.ee'
assert contact.invalid?
assert_equal I18n.t('activerecord.errors.models.contact.attributes.email.email_regex_check_error'), contact.errors.messages[:email].first
end
# contact = valid_contact
# contact.email = '`@internet.ee'
# assert contact.invalid?
# assert_equal I18n.t('activerecord.errors.models.contact.attributes.email.email_regex_check_error'), contact.errors.messages[:email].first
# end
def test_invalid_without_phone
contact = valid_contact

View file

@ -1,6 +1,8 @@
require 'test_helper'
class ForceDeleteTest < ActionMailer::TestCase
include ActiveJob::TestHelper
setup do
@domain = domains(:shop)
Setting.redemption_grace_period = 30
@ -126,13 +128,6 @@ class ForceDeleteTest < ActionMailer::TestCase
assert_empty @domain.statuses & statuses_to_be_removed, 'Pending actions should be stopped'
end
def test_scheduling_force_delete_preserves_current_statuses
@domain.statuses = %w[test1 test2]
@domain.schedule_force_delete(type: :fast_track)
@domain.reload
assert_equal %w[test1 test2], @domain.statuses_before_force_delete
end
def test_scheduling_force_delete_bypasses_validation
@domain = domains(:invalid)
@domain.schedule_force_delete(type: :fast_track)
@ -356,7 +351,6 @@ class ForceDeleteTest < ActionMailer::TestCase
@domain.reload
assert @domain.force_delete_scheduled?
assert_equal 'invalid_email', @domain.template_name
assert_equal Date.parse('2010-09-19'), @domain.force_delete_date.to_date
assert_equal Date.parse('2010-08-05'), @domain.force_delete_start.to_date
notification = @domain.registrar.notifications.last
@ -375,7 +369,6 @@ class ForceDeleteTest < ActionMailer::TestCase
@domain.reload
assert @domain.force_delete_scheduled?
assert_equal 'invalid_email', @domain.template_name
assert_equal Date.parse('2010-09-19'), @domain.force_delete_date.to_date
assert_equal Date.parse('2010-08-05'), @domain.force_delete_start.to_date
notification = @domain.registrar.notifications.last
@ -398,12 +391,10 @@ class ForceDeleteTest < ActionMailer::TestCase
contact.verify_email
end
assert contact.email_verification_failed?
perform_check_force_delete_job(contact.id)
@domain.reload
assert @domain.force_delete_scheduled?
assert_equal 'invalid_email', @domain.template_name
assert_equal Date.parse('2010-09-19'), @domain.force_delete_date.to_date
assert_equal Date.parse('2010-08-05'), @domain.force_delete_start.to_date
assert_equal @domain.status_notes[DomainStatus::FORCE_DELETE], email
@ -433,11 +424,12 @@ class ForceDeleteTest < ActionMailer::TestCase
contact_first.verify_email
end
perform_check_force_delete_job(contact_first.id)
domain.reload
assert_equal domain.status_notes[DomainStatus::FORCE_DELETE], invalid_emails
notification = domain.registrar.notifications.last
assert notification.text.include? asserted_text
assert_not notification.text.include? asserted_text
end
def test_remove_invalid_email_from_domain_status_notes
@ -460,6 +452,8 @@ class ForceDeleteTest < ActionMailer::TestCase
travel_to Time.zone.parse('2010-07-05 0:00:03')
contact_first.verify_email
perform_check_force_delete_job(contact_first.id)
domain.reload
assert_equal domain.status_notes[DomainStatus::FORCE_DELETE], invalid_email
@ -477,19 +471,20 @@ class ForceDeleteTest < ActionMailer::TestCase
contact_one = @domain.admin_contacts.first
contact_one.update_attribute(:email, email_one)
contact_one.verify_email
perform_check_force_delete_job(contact_one.id)
assert contact_one.need_to_start_force_delete?
contact_two = @domain.admin_contacts.first
contact_two.update_attribute(:email, email_two)
contact_two.verify_email
perform_check_force_delete_job(contact_two.id)
assert contact_two.need_to_start_force_delete?
@domain.reload
assert @domain.force_delete_scheduled?
assert_equal 'invalid_email', @domain.template_name
assert_equal Date.parse('2010-09-19'), @domain.force_delete_date.to_date
assert_equal Date.parse('2010-08-05'), @domain.force_delete_start.to_date
assert @domain.status_notes[DomainStatus::FORCE_DELETE].include? email_one
@ -508,7 +503,6 @@ class ForceDeleteTest < ActionMailer::TestCase
@domain.reload
assert @domain.force_delete_scheduled?
assert_equal 'invalid_email', @domain.template_name
assert_equal Date.parse('2010-09-19'), @domain.force_delete_date.to_date
assert_equal Date.parse('2010-08-05'), @domain.force_delete_start.to_date
notification = @domain.registrar.notifications.last
@ -534,4 +528,12 @@ class ForceDeleteTest < ActionMailer::TestCase
@bounced_mail.diagnostic = 'smtp; 550 5.1.1 user unknown'
@bounced_mail.save!
end
private
def perform_check_force_delete_job(contact_id)
perform_enqueued_jobs do
CheckForceDeleteJob.perform_now([contact_id])
end
end
end

View file

@ -1,53 +1,4 @@
require 'test_helper'
class FeatureTest < ActiveSupport::TestCase
# setup do
# @domain = domains(:shop)
# @domain.apply_registry_lock(extensions_prohibited: false)
# end
#
# def test_if_obj_and_extensions_prohibited_enabled
# ENV['obj_and_extensions_prohibited'] = 'true'
#
# assert Feature.obj_and_extensions_statuses_enabled?
#
# statuses = DomainStatus.admin_statuses
# assert statuses.include? DomainStatus::SERVER_OBJ_UPDATE_PROHIBITED
# end
#
# def test_if_obj_and_extensions_prohibited_is_nil
# ENV['obj_and_extensions_prohibited'] = nil
#
# assert_not Feature.obj_and_extensions_statuses_enabled?
#
# statuses = DomainStatus.admin_statuses
# assert_not statuses.include? DomainStatus::SERVER_OBJ_UPDATE_PROHIBITED
# end
#
# def test_if_obj_and_extensions_prohibited_is_false
# ENV['obj_and_extensions_prohibited'] = 'false'
#
# assert_not Feature.obj_and_extensions_statuses_enabled?
#
# statuses = DomainStatus.admin_statuses
# assert_not statuses.include? DomainStatus::SERVER_OBJ_UPDATE_PROHIBITED
# end
#
# def test_if_enable_lock_domain_with_new_statuses_is_nil
# ENV['enable_lock_domain_with_new_statuses'] = nil
#
# assert_not Feature.enable_lock_domain_with_new_statuses?
#
# assert_equal @domain.statuses, ["serverObjUpdateProhibited", "serverDeleteProhibited", "serverTransferProhibited"]
# assert @domain.locked_by_registrant?
# end
#
# def test_if_enable_lock_domain_with_new_statuses_is_false
# ENV['enable_lock_domain_with_new_statuses'] = 'false'
#
# assert_not Feature.enable_lock_domain_with_new_statuses?
#
# assert_equal @domain.statuses, ["serverObjUpdateProhibited", "serverDeleteProhibited", "serverTransferProhibited"]
# assert @domain.locked_by_registrant?
# end
end

View file

@ -5,6 +5,7 @@ class InvoiceTest < ActiveSupport::TestCase
setup do
@invoice = invoices(:one)
Spy.on_instance_method(EisBilling::BaseController, :authorized).and_return(true)
end
def test_fixture_is_valid
@ -79,6 +80,10 @@ class InvoiceTest < ActiveSupport::TestCase
end
def test_buyer_vat_no_is_taken_from_registrar_by_default
invoice_n = Invoice.order(number: :desc).last.number
response = OpenStruct.new(body: "{\"invoice_number\":\"#{invoice_n + 3}\"}")
Spy.on(EisBilling::GetInvoiceNumber, :send_invoice).and_return(response)
registrar = registrars(:bestnames)
registrar.vat_no = 'US1234'
invoice = @invoice.dup
@ -118,24 +123,58 @@ class InvoiceTest < ActiveSupport::TestCase
transaction.reference_no = registrar.reference_no
transaction.sum = 250
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/invoice_generator/invoice_generator")
.to_return(status: 200, body: "{\"everypay_link\":\"http://link.test\"}", headers: {})
stub_request(:put, "https://registry:3000/eis_billing/e_invoice_response").
to_return(status: 200, body: "{\"invoice_number\":\"#{invoice_n + 3}\"}, {\"date\":\"#{Time.zone.now-10.minutes}\"}", headers: {})
stub_request(:post, "https://eis_billing_system:3000/api/v1/e_invoice/e_invoice").
to_return(status: 200, body: "", headers: {})
invoice = Invoice.create_from_transaction!(transaction)
assert_equal 250, invoice.total
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 + 4}\"}", headers: {})
transaction.sum = 146.88
invoice = Invoice.create_from_transaction!(transaction)
assert_equal 146.88, invoice.total
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 + 5}\"}", headers: {})
transaction.sum = 0.99
invoice = Invoice.create_from_transaction!(transaction)
assert_equal 0.99, invoice.total
end
def test_emails_invoice_after_creating_topup_invoice
invoice_n = Invoice.order(number: :desc).last.number
stub_request(:post, "https://eis_billing_system:3000/api/v1/invoice_generator/invoice_generator").
to_return(status: 200, body: "{\"everypay_link\":\"http://link.test\"}", headers: {})
stub_request(:put, "https://registry:3000/eis_billing/e_invoice_response").
to_return(status: 200, body: "{\"invoice_number\":\"#{invoice_n + 3}\"}, {\"date\":\"#{Time.zone.now-10.minutes}\"}", headers: {})
stub_request(:post, "https://eis_billing_system:3000/api/v1/e_invoice/e_invoice").
to_return(status: 200, body: "", headers: {})
registrar = registrars(:bestnames)
transaction = bank_transactions(:one).dup
transaction.reference_no = registrar.reference_no
transaction.sum = 250
response = OpenStruct.new(body: "{\"invoice_number\":\"#{invoice_n + 3}\"}")
Spy.on(EisBilling::GetInvoiceNumber, :send_invoice).and_return(response)
assert_emails 1 do
Invoice.create_from_transaction!(transaction)
end

View file

@ -60,6 +60,8 @@ class RegistrantUserTest < ActiveSupport::TestCase
end
bulk_action = @user.actions.where(operation: :bulk_update).last
single_action = @user.actions.find_by(operation: :update,
contact_id: contacts(:identical_to_william).id)
assert_equal 4, bulk_action.subactions.size
@ -67,14 +69,14 @@ class RegistrantUserTest < ActiveSupport::TestCase
notification = r.notifications.unread.order('created_at DESC').take
if r == registrars(:bestnames)
assert_equal '4 contacts have been updated by registrant', notification.text
assert_equal 'BulkAction', notification.attached_obj_type
assert_equal 'ContactUpdateAction', notification.attached_obj_type
assert_equal bulk_action.id, notification.attached_obj_id
assert_equal bulk_action.id, notification.action_id
else
assert_equal 'Contact william-002 has been updated by registrant', notification.text
refute notification.action_id
refute notification.attached_obj_id
refute notification.attached_obj_type
assert_equal 'ContactUpdateAction', notification.attached_obj_type
assert_equal single_action.id, notification.attached_obj_id
assert_equal single_action.id, notification.action_id
end
end
end

View file

@ -6,6 +6,7 @@ class RegistrarTest < ActiveJob::TestCase
@original_default_language = Setting.default_language
@original_days_to_keep_invoices_active = Setting.days_to_keep_invoices_active
@old_validation_type = Truemail.configure.default_validation_type
Spy.on_instance_method(EisBilling::BaseController, :authorized).and_return(true)
end
teardown do
@ -48,16 +49,16 @@ class RegistrarTest < ActiveJob::TestCase
assert registrar.valid?
end
def test_email_verification_regex_error
Truemail.configure.default_validation_type = :regex
# def test_email_verification_regex_error
# Truemail.configure.default_validation_type = :regex
registrar = valid_registrar
registrar.email = '`@internet.ee'
registrar.billing_email = nil
# registrar = valid_registrar
# registrar.email = '`@internet.ee'
# registrar.billing_email = nil
assert registrar.invalid?
assert_equal I18n.t('activerecord.errors.models.contact.attributes.email.email_regex_check_error'), registrar.errors.messages[:email].first
end
# assert registrar.invalid?
# assert_equal I18n.t('activerecord.errors.models.contact.attributes.email.email_regex_check_error'), registrar.errors.messages[:email].first
# end
def test_billing_email_verification_valid
registrar = valid_registrar
@ -66,15 +67,15 @@ class RegistrarTest < ActiveJob::TestCase
assert registrar.valid?
end
def test_billing_email_verification_regex_error
Truemail.configure.default_validation_type = :regex
# def test_billing_email_verification_regex_error
# Truemail.configure.default_validation_type = :regex
registrar = valid_registrar
registrar.billing_email = '`@strangesentence@internet.ee'
# registrar = valid_registrar
# registrar.billing_email = '`@strangesentence@internet.ee'
assert registrar.invalid?
assert_equal I18n.t('activerecord.errors.models.contact.attributes.email.email_regex_check_error'), registrar.errors.messages[:billing_email].first
end
# assert registrar.invalid?
# assert_equal I18n.t('activerecord.errors.models.contact.attributes.email.email_regex_check_error'), registrar.errors.messages[:billing_email].first
# end
def test_invalid_without_accounting_customer_code
registrar = valid_registrar
@ -144,6 +145,19 @@ class RegistrarTest < ActiveJob::TestCase
end
def test_issues_new_invoice
stub_request(:post, "https://eis_billing_system:3000/api/v1/invoice_generator/invoice_generator").
to_return(status: 200, body: "{\"everypay_link\":\"http://link.test\"}", headers: {})
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(:put, "https://registry:3000/eis_billing/e_invoice_response").
to_return(status: 200, body: "{\"invoice_number\":\"#{invoice_n + 3}\"}, {\"date\":\"#{Time.zone.now-10.minutes}\"}", headers: {})
stub_request(:post, "https://eis_billing_system:3000/api/v1/e_invoice/e_invoice").
to_return(status: 200, body: "", headers: {})
travel_to Time.zone.parse('2010-07-05')
Setting.days_to_keep_invoices_active = 10
@ -154,13 +168,24 @@ class RegistrarTest < ActiveJob::TestCase
end
def test_issues_e_invoice_along_with_invoice
stub_request(:post, "https://eis_billing_system:3000/api/v1/invoice_generator/invoice_generator").
to_return(status: 200, body: "{\"everypay_link\":\"http://link.test\"}", headers: {})
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(:put, "https://registry:3000/eis_billing/e_invoice_response").
to_return(status: 200, body: "{\"invoice_number\":\"#{invoice_n + 3}\"}, {\"date\":\"#{Time.zone.now-10.minutes}\"}", headers: {})
stub_request(:post, "https://eis_billing_system:3000/api/v1/e_invoice/e_invoice").
to_return(status: 200, body: "", headers: {})
EInvoice::Providers::TestProvider.deliveries.clear
perform_enqueued_jobs do
@registrar.issue_prepayment_invoice(100)
end
assert_equal 1, EInvoice::Providers::TestProvider.deliveries.count
end
def test_invalid_without_address_street

View file

@ -0,0 +1,15 @@
require 'test_helper'
class SendDataToDirectoTest < ActiveSupport::TestCase
setup do
Spy.on_instance_method(EisBilling::BaseController, :authorized).and_return(true)
end
def test_should_send_data_to_billing_directo
stub_request(:post, "https://eis_billing_system:3000/api/v1/directo/directo").
to_return(status: 200, body: "ok", headers: {})
res = EisBilling::SendDataToDirecto.send_request(object_data: [], monthly: true, dry: true)
assert_equal res.body, "ok"
end
end

View file

@ -6,6 +6,10 @@ class AdminAreaBankStatementTest < ApplicationSystemTestCase
travel_to Time.zone.parse('2010-07-05 00:30:00')
@invoice = invoices(:one)
Spy.on_instance_method(EisBilling::BaseController, :authorized).and_return(true)
response_message = { message: 'got it' }
stub_request(:post, 'https://eis_billing_system:3000/api/v1/invoice_generator/invoice_status')
.to_return(status: 200, body: response_message.to_json, headers: {})
end
def test_update_bank_statement
@ -54,7 +58,20 @@ class AdminAreaBankStatementTest < ApplicationSystemTestCase
end
def test_can_bind_statement_transactions
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: {})
registrar = registrars(:bestnames)
stub_request(:post, "https://eis_billing_system:3000/api/v1/invoice_generator/invoice_generator")
.to_return(status: 200, body: "{\"everypay_link\":\"http://link.test\"}", headers: {})
stub_request(:put, "https://registry:3000/eis_billing/e_invoice_response")
.to_return(status: 200, body: "{\"invoice_number\":\"#{invoice_n + 3}\"}, {\"date\":\"#{Time.zone.now-10.minutes}\"}", headers: {})
stub_request(:post, "https://eis_billing_system:3000/api/v1/e_invoice/e_invoice")
.to_return(status: 200, body: "", headers: {})
registrar.issue_prepayment_invoice(500)
invoice = registrar.invoices.last

View file

@ -11,6 +11,7 @@ class AdminAreaInvoicesTest < ApplicationSystemTestCase
end
def test_cancels_an_invoice
Spy.on(EisBilling::SendInvoiceStatus, :send_info).and_return(true)
@invoice.account_activity = nil
assert @invoice.cancellable?

View file

@ -14,6 +14,9 @@ class AdminRegistrarsSystemTest < ApplicationSystemTestCase
end
def test_creates_new_registrar
stub_request(:post, "https://eis_billing_system:3000/api/v1/invoice_generator/reference_number_generator").
to_return(status: 200, body: "{\"reference_number\":\"12332\"}", headers: {})
assert_nil Registrar.find_by(name: 'Acme Ltd')
visit admin_registrars_path

View file

@ -0,0 +1,12 @@
require 'application_system_test_case'
class AddDepositsTest < ApplicationSystemTestCase
include ActionMailer::TestHelper
setup do
sign_in users(:api_bestnames)
@invoice = invoices(:one)
ActionMailer::Base.deliveries.clear
end
end

View file

@ -4,6 +4,10 @@ class BalanceTopUpTest < ApplicationSystemTestCase
setup do
sign_in users(:api_bestnames)
@original_registry_vat_rate = Setting.registry_vat_prc
eis_response = OpenStruct.new(body: "{\"payment_link\":\"http://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
@ -11,6 +15,16 @@ class BalanceTopUpTest < ApplicationSystemTestCase
end
def test_creates_new_invoice
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(:put, "https://registry:3000/eis_billing/e_invoice_response")
.to_return(status: 200, body: "{\"invoice_number\":\"#{invoice_n + 3}\"}, {\"date\":\"#{Time.zone.now-10.minutes}\"}", headers: {})
stub_request(:post, "https://eis_billing_system:3000/api/v1/e_invoice/e_invoice")
.to_return(status: 200, body: "", headers: {})
Setting.registry_vat_prc = 0.1
visit registrar_invoices_url

View file

@ -3,6 +3,8 @@ require 'application_system_test_case'
class NewInvoicePaymentTest < ApplicationSystemTestCase
def setup
super
eis_response = OpenStruct.new(body: "{\"payment_link\":\"http://link.test\"}")
Spy.on_instance_method(EisBilling::AddDeposits, :send_invoice).and_return(eis_response)
@original_vat_prc = Setting.registry_vat_prc
Setting.registry_vat_prc = 0.2
@ -23,26 +25,4 @@ class NewInvoicePaymentTest < ApplicationSystemTestCase
fill_in 'Description', with: 'My first invoice'
click_link_or_button 'Add'
end
def test_create_new_SEB_payment
create_invoice_and_visit_its_page
click_link_or_button 'seb'
form = page.find('form')
assert_equal('https://www.seb.ee/cgi-bin/dv.sh/ipank.r', form['action'])
assert_equal('post', form['method'])
assert_equal('240.00', form.find_by_id('VK_AMOUNT', visible: false).value)
end
def test_create_new_Every_Pay_payment
create_invoice_and_visit_its_page
click_link_or_button 'every_pay'
expected_hmac_fields = 'account_id,amount,api_username,callback_url,' +
'customer_url,hmac_fields,nonce,order_reference,timestamp,transaction_type'
form = page.find('form')
assert_equal('https://igw-demo.every-pay.com/transactions/', form['action'])
assert_equal('post', form['method'])
assert_equal(expected_hmac_fields, form.find_by_id('hmac_fields', visible: false).value)
assert_equal('240.00', form.find_by_id('amount', visible: false).value)
end
end

View file

@ -6,6 +6,9 @@ class NewInvoiceTest < ApplicationSystemTestCase
@user = users(:api_bestnames)
sign_in @user
eis_response = OpenStruct.new(body: "{\"payment_link\":\"http://link.test\"}")
Spy.on_instance_method(EisBilling::AddDeposits, :send_invoice).and_return(eis_response)
end
def test_show_balance
@ -14,6 +17,16 @@ class NewInvoiceTest < ApplicationSystemTestCase
end
def test_create_new_invoice_with_positive_amount
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(:put, "https://registry:3000/eis_billing/e_invoice_response").
to_return(status: 200, body: "{\"invoice_number\":\"#{invoice_n + 3}\"}, {\"date\":\"#{Time.zone.now-10.minutes}\"}", headers: {})
stub_request(:post, "https://eis_billing_system:3000/api/v1/e_invoice/e_invoice").
to_return(status: 200, body: "", headers: {})
visit registrar_invoices_path
click_link_or_button 'Add deposit'
fill_in 'Amount', with: '200.00'
@ -24,12 +37,22 @@ class NewInvoiceTest < ApplicationSystemTestCase
end
assert_text 'Please pay the following invoice'
assert_text 'Invoice no. 131050'
assert_text "Invoice no. #{invoice_n + 3}"
assert_text 'Subtotal 200,00 €'
assert_text 'Pay invoice'
end
def test_create_new_invoice_with_comma_in_number
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(:put, "https://registry:3000/eis_billing/e_invoice_response").
to_return(status: 200, body: "{\"invoice_number\":\"#{invoice_n + 3}\"}, {\"date\":\"#{Time.zone.now-10.minutes}\"}", headers: {})
stub_request(:post, "https://eis_billing_system:3000/api/v1/e_invoice/e_invoice").
to_return(status: 200, body: "", headers: {})
visit registrar_invoices_path
click_link_or_button 'Add deposit'
fill_in 'Amount', with: '200,00'
@ -40,7 +63,7 @@ class NewInvoiceTest < ApplicationSystemTestCase
end
assert_text 'Please pay the following invoice'
assert_text 'Invoice no. 131050'
assert_text "Invoice no. #{invoice_n + 3}"
assert_text 'Subtotal 200,00 €'
assert_text 'Pay invoice'
end

View file

@ -8,9 +8,13 @@ class RegistrarAreaInvoicesTest < ApplicationSystemTestCase
@invoice = invoices(:one)
ActionMailer::Base.deliveries.clear
eis_response = OpenStruct.new(body: "{\"payment_link\":\"http://link.test\"}")
Spy.on_instance_method(EisBilling::AddDeposits, :send_invoice).and_return(eis_response)
end
def test_cancels_an_invoice
Spy.on(EisBilling::SendInvoiceStatus, :send_info).and_return(true)
@invoice.account_activity = nil
assert @invoice.cancellable?
@ -40,4 +44,18 @@ class RegistrarAreaInvoicesTest < ApplicationSystemTestCase
assert_current_path registrar_invoice_path(@invoice)
assert_text 'Invoice has been sent'
end
end
def test_if_invoice_unpaid_and_not_generated_link_comes_then_should_render_no_everypay_link
invoice = invoices(:unpaid)
visit registrar_invoice_url(invoice)
assert_text 'No everypay link'
end
def test_if_invoice_aldready_paid_there_should_not_any_everypay_link
visit registrar_invoice_url(@invoice)
assert_no_text 'No everypay link'
assert_no_text 'Everypay link'
end
end

View file

@ -0,0 +1,66 @@
require 'test_helper'
class CheckForceDeleteTaskTest < ActiveSupport::TestCase
include ActiveJob::TestHelper
def setup
@contact = contacts(:john)
@invalid_contact = contacts(:invalid_email)
end
def test_enque_force_delete_when_three_invalid_records_by_mx
trumail_results = OpenStruct.new(success: false,
email: @contact.email,
domain: 'box.tests',
errors: { mx: 'target host(s) not found' })
Spy.on_instance_method(Actions::EmailCheck, :check_email).and_return(trumail_results)
Spy.on_instance_method(Actions::AAndAaaaEmailValidation, :call).and_return([])
action = Actions::EmailCheck.new(email: @contact.email,
validation_eventable: @contact,
check_level: 'mx')
3.times do
action.call
end
run_task
assert_enqueued_jobs 1
assert_enqueued_with(job: CheckForceDeleteJob, args: [[@contact.id]])
end
def test_enque_force_delete_when_invalid_record_by_regex
@invalid_contact.verify_email
run_task
assert_enqueued_jobs 1
assert_enqueued_with(job: CheckForceDeleteJob, args: [[@invalid_contact.id]])
end
def test_not_enque_force_delete
trumail_results = OpenStruct.new(success: false,
email: @contact.email,
domain: 'box.tests',
errors: { mx: 'target host(s) not found' })
Spy.on_instance_method(Actions::EmailCheck, :check_email).and_return(trumail_results)
Spy.on_instance_method(Actions::AAndAaaaEmailValidation, :call).and_return([])
action = Actions::EmailCheck.new(email: @contact.email,
validation_eventable: @contact,
check_level: 'mx')
2.times do
action.call
end
run_task
assert_enqueued_jobs 0
end
private
def run_task
Rake::Task['check_force_delete'].execute
end
end

View file

@ -116,13 +116,32 @@ class VerifyEmailTaskTest < ActiveJob::TestCase
)
Spy.on_instance_method(Actions::EmailCheck, :check_email).and_return(trumail_results)
1.times do
run_task
end
run_task
assert contact.domains.last.force_delete_scheduled?
end
def test_should_remove_old_validation_records
trumail_results = OpenStruct.new(success: false,
email: @contact.email,
domain: 'box.tests',
errors: { mx: 'target host(s) not found' })
Spy.on_instance_method(Actions::EmailCheck, :check_email).and_return(trumail_results)
Spy.on_instance_method(Actions::AAndAaaaEmailValidation, :call).and_return([true])
Actions::EmailCheck.new(email: @contact.email,
validation_eventable: @contact,
check_level: 'regex').call
travel_to(Time.zone.now + ::ValidationEvent::VALIDATION_PERIOD + 1.minute)
assert_equal ValidationEvent.old_records.count, 1
run_task
assert_predicate ValidationEvent.old_records.count, :zero?
end
def run_task
perform_enqueued_jobs do
Rake::Task['verify_email:check_all'].execute

View file

@ -16,6 +16,12 @@ class ProcessPaymentsTaskTest < ActiveJob::TestCase
@account_activity = account_activities(:one)
@account = accounts(:cash)
response_message = {
message: 'got it'
}
stub_request(:post, 'https://eis_billing_system:3000/api/v1/invoice_generator/invoice_status')
.to_return(status: 200, body: response_message.to_json, headers: {})
Setting.registry_iban = beneficiary_iban
Lhv::ConnectApi.class_eval do
@ -63,7 +69,8 @@ class ProcessPaymentsTaskTest < ActiveJob::TestCase
def test_cannot_create_new_invoice_if_transaction_binded_to_paid_invoice
assert_not @invoice.paid?
@account_activity.update(activity_type: "add_credit", bank_transaction: nil, created_at: Time.zone.today - 1.day, creator_str: 'AdminUser')
@account_activity.update(activity_type: 'add_credit', bank_transaction: nil,
created_at: Time.zone.today - 1.day, creator_str: 'AdminUser')
@invoice.update(account_activity: @account_activity, total: @payment_amount)
assert @invoice.paid?
@ -77,9 +84,26 @@ class ProcessPaymentsTaskTest < ActiveJob::TestCase
end
def test_if_invoice_is_overdue_than_48_hours
invoice_n = Invoice.order(number: :desc).last.number
Spy.on_instance_method(SendEInvoiceJob, :perform_now).and_return(true)
stub_request(:post, 'https://eis_billing_system:3000/api/v1/e_invoice/e_invoice')
.to_return(status: 200, body: '', headers: {})
stub_request(:put, 'https://registry:3000/eis_billing/e_invoice_response')
.to_return(status: 200, body: "{\"invoice_number\":\"#{invoice_n + 3}\"}, {\"date\":\"#{Time.zone.now-10.minutes}\"}", headers: {})
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/invoice_generator/invoice_generator')
.to_return(status: 200, body: "{\"everypay_link\":\"http://link.test\"}", headers: {})
assert_not @invoice.paid?
@account_activity.update(activity_type: "add_credit", bank_transaction: nil, created_at: Time.zone.today - 3.days, creator_str: 'AdminUser')
@account_activity.update(activity_type: 'add_credit', bank_transaction: nil,
created_at: Time.zone.today - 3.days, creator_str: 'AdminUser')
@invoice.update(account_activity: @account_activity, total: @payment_amount)
assert @invoice.paid?
@ -143,7 +167,24 @@ class ProcessPaymentsTaskTest < ActiveJob::TestCase
assert payment_order.failed?
end
def test_credits_registrar_account_without_invoice_beforehand
def test_credits_registrar_athout_invoice_beforehand
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}\"}")
stub_request(:post, 'https://eis_billing_system:3000/api/v1/invoice_generator/invoice_generator')
.to_return(status: 200, body: "{\"everypay_link\":\"http://link.test\"}", headers: {})
Spy.on_instance_method(SendEInvoiceJob, :perform_now).and_return(true)
stub_request(:post, 'https://eis_billing_system:3000/api/v1/e_invoice/e_invoice')
.to_return(status: 200, body: '', headers: {})
stub_request(:put, 'https://registry:3000/eis_billing/e_invoice_response')
.to_return(status: 200,
body: "{\"invoice_number\":\"#{invoice_n + 3}\"}, {\"date\":\"#{Time.zone.now-10.minutes}\"}",
headers: {})
registrar = registrars(:bestnames)
assert_changes -> { registrar.accounts.first.balance } do
@ -163,6 +204,21 @@ class ProcessPaymentsTaskTest < ActiveJob::TestCase
end
def test_topup_creates_invoice_and_send_it_as_paid
stub_request(:post, 'https://eis_billing_system:3000/api/v1/e_invoice/e_invoice')
.to_return(status: 200, body: '', headers: {})
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/invoice_generator/invoice_generator')
.to_return(status: 200, body: "{\"everypay_link\":\"http://link.test\"}", headers: {})
stub_request(:put, 'https://registry:3000/eis_billing/e_invoice_response')
.to_return(status: 200,
body: "{\"invoice_number\":\"#{invoice_n + 3}\"}, {\"date\":\"#{Time.zone.now - 10.minutes}\"}",
headers: {})
registrar = registrars(:bestnames)
@invoice.payment_orders.destroy_all
@invoice.destroy
@ -178,7 +234,7 @@ class ProcessPaymentsTaskTest < ActiveJob::TestCase
pdf_source = Invoice::PdfGenerator.new(invoice)
pdf_source.send(:invoice_html).include?('Receipt date')
email= ActionMailer::Base.deliveries.last
email = ActionMailer::Base.deliveries.last
assert email.subject.include?('already paid')
assert_equal 0.1, registrar.invoices.last.total

View file

@ -5,6 +5,7 @@ class ReloadBalanceTaskTest < ActiveSupport::TestCase
setup do
@registrar = registrars(:bestnames)
Spy.on_instance_method(EisBilling::BaseController, :authorized).and_return(true)
end
def test_issues_invoice_when_auto_reload_is_enabled_and_threshold_reached
@ -20,6 +21,19 @@ class ReloadBalanceTaskTest < ActiveSupport::TestCase
end
def test_issues_invoice_when_auto_reload_is_enabled_and_threshold_reached
stub_request(:post, "https://eis_billing_system:3000/api/v1/invoice_generator/invoice_generator").
to_return(status: 200, body: "{\"everypay_link\":\"http://link.test\"}", headers: {})
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(:put, "https://registry:3000/eis_billing/e_invoice_response").
to_return(status: 200, body: "{\"invoice_number\":\"#{invoice_n + 3}\"}, {\"date\":\"#{Time.zone.now-10.minutes}\"}", headers: {})
stub_request(:post, "https://eis_billing_system:3000/api/v1/e_invoice/e_invoice").
to_return(status: 200, body: "", headers: {})
reload_amount = 100
registrar = registrar_with_auto_reload_enabled_and_threshold_reached(reload_amount)
@ -50,6 +64,19 @@ class ReloadBalanceTaskTest < ActiveSupport::TestCase
end
def test_marks_registrar_as_pending_balance_reload
stub_request(:post, "https://eis_billing_system:3000/api/v1/invoice_generator/invoice_generator").
to_return(status: 200, body: "{\"everypay_link\":\"http://link.test\"}", headers: {})
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(:put, "https://registry:3000/eis_billing/e_invoice_response").
to_return(status: 200, body: "{\"invoice_number\":\"#{invoice_n + 3}\"}, {\"date\":\"#{Time.zone.now-10.minutes}\"}", headers: {})
stub_request(:post, "https://eis_billing_system:3000/api/v1/e_invoice/e_invoice").
to_return(status: 200, body: "", headers: {})
registrar = registrar_with_auto_reload_enabled_and_threshold_reached
capture_io { run_task }
@ -59,6 +86,19 @@ class ReloadBalanceTaskTest < ActiveSupport::TestCase
end
def test_output
stub_request(:post, "https://eis_billing_system:3000/api/v1/invoice_generator/invoice_generator").
to_return(status: 200, body: "{\"everypay_link\":\"http://link.test\"}", headers: {})
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(:put, "https://registry:3000/eis_billing/e_invoice_response").
to_return(status: 200, body: "{\"invoice_number\":\"#{invoice_n + 3}\"}, {\"date\":\"#{Time.zone.now-10.minutes}\"}", headers: {})
stub_request(:post, "https://eis_billing_system:3000/api/v1/e_invoice/e_invoice").
to_return(status: 200, body: "", headers: {})
reload_amount = 100
registrar = registrar_with_auto_reload_enabled_and_threshold_reached(reload_amount)
assert_equal 'Best Names', registrar.name