Merge branch 'master' into registry-790

# Conflicts:
#	test/integration/epp/domain/domain_delete_test.rb
#	test/integration/epp/domain/domain_update_test.rb
#	test/integration/epp/domain/transfer/request_test.rb
#	test/system/admin_area/domains_test.rb
This commit is contained in:
Artur Beljajev 2018-08-09 15:01:23 +03:00
commit 1d79f6548d
61 changed files with 731 additions and 84 deletions

View file

@ -1,60 +0,0 @@
require 'test_helper'
class ContactVersionsTest < ActionDispatch::IntegrationTest
def setup
super
create_contact_with_history
sign_in users(:admin)
end
def teardown
super
delete_objects_once_done
end
def create_contact_with_history
sql = <<-SQL.squish
INSERT INTO registrars (id, name, reg_no, email, country_code, code,
accounting_customer_code, language)
VALUES (75, 'test_registrar', 'test123', 'test@test.com', 'EE', 'TEST123',
'test123', 'en');
INSERT INTO contacts (id, code, auth_info, registrar_id)
VALUES (75, 'test_code', '8b4d462aa04194ca78840a', 75);
INSERT INTO log_contacts (item_type, item_id, event, whodunnit, object,
object_changes, created_at, session, children, ident_updated_at, uuid)
VALUES ('Contact', 75, 'update', '1-AdminUser',
'{"id": 75, "code": "test_code", "auth_info": "8b4d462aa04194ca78840a", "registrar_id": 75, "old_field": "value"}',
'{"other_made_up_field": "value"}',
'2018-04-23 15:50:48.113491', '2018-04-23 12:44:56',
'{"legal_documents":[null]}', null, null
)
SQL
ActiveRecord::Base.connection.execute(sql)
end
def delete_objects_once_done
ActiveRecord::Base.connection.execute('DELETE from log_contacts where item_id = 75')
Domain.destroy_all
Contact.destroy_all
Registrar.destroy_all
end
def test_removed_fields_are_not_causing_errors_in_index_view
visit admin_contact_versions_path
assert_text 'test_registrar'
assert_text 'update 23.04.18, 18:50'
end
def test_removed_fields_are_not_causing_errors_in_details_view
version_id = Contact.find(75).versions.last
visit admin_contact_version_path(version_id)
assert_text 'test_registrar'
assert_text '23.04.18, 18:50 update 1-AdminUser'
end
end

View file

@ -1,25 +0,0 @@
require 'test_helper'
class AdminContactsTest < ActionDispatch::IntegrationTest
def setup
super
@contact = contacts(:william)
sign_in users(:admin)
end
def test_display_list
visit admin_contacts_path
assert_text('william-001')
assert_text('william-002')
assert_text('acme-ltd-001')
end
def test_display_details
visit admin_contact_path(@contact)
assert_text('Street Main Street City New York Postcode 12345 ' \
'State New York Country United States of America')
end
end

View file

@ -1,65 +0,0 @@
require 'test_helper'
class DomainVersionsTest < ActionDispatch::IntegrationTest
def setup
super
create_domain_with_history
sign_in users(:admin)
end
def teardown
super
delete_objects_once_done
end
def create_domain_with_history
sql = <<-SQL.squish
INSERT INTO registrars (id, name, reg_no, email, country_code, code,
accounting_customer_code, language)
VALUES (54, 'test_registrar', 'test123', 'test@test.com', 'EE', 'TEST123',
'test123', 'en');
INSERT INTO contacts (id, code, auth_info, registrar_id)
VALUES (54, 'test_code', '8b4d462aa04194ca78840a', 54);
INSERT INTO domains (id, registrar_id, valid_to, registrant_id,
transfer_code)
VALUES (54, 54, '2018-06-23T12:14:02.732+03:00', 54, 'transfer_code');
INSERT INTO log_domains (item_type, item_id, event, whodunnit, object,
object_changes, created_at, nameserver_ids, tech_contact_ids,
admin_contact_ids, session, children)
VALUES ('Domain', 54, 'update', '1-AdminUser',
'{"id": 54, "registrar_id": 54, "valid_to": "2018-07-23T12:14:05.583+03:00", "registrant_id": 54, "transfer_code": "transfer_code", "valid_from": "2017-07-23T12:14:05.583+03:00"}',
'{"foo": "bar", "other_made_up_field": "value"}',
'2018-04-23 15:50:48.113491', '{}', '{}', '{}', '2018-04-23 12:44:56',
'{"null_fracdmin_contacts":[108],"tech_contacts":[109],"nameservers":[],"dnskeys":[],"legal_documents":[null],"registrant":[1]}'
)
SQL
ActiveRecord::Base.connection.execute(sql)
end
def delete_objects_once_done
ActiveRecord::Base.connection.execute('DELETE FROM log_domains where item_id = 54')
Domain.destroy_all
Contact.destroy_all
Registrar.destroy_all
end
def test_removed_fields_are_not_causing_errors_in_index_view
visit admin_domain_versions_path
assert_text 'test_registrar'
assert_text 'test_registrar update 23.04.18, 18:50'
end
def test_removed_fields_are_not_causing_errors_in_details_view
version_id = Domain.find(54).versions.last
visit admin_domain_version_path(version_id)
assert_text 'test_registrar'
assert_text '23.04.18, 18:50 update 1-AdminUser'
end
end

View file

@ -1,21 +0,0 @@
require 'test_helper'
class AdminAreaDomainDetailsTest < ActionDispatch::IntegrationTest
setup do
sign_in users(:admin)
@domain = domains(:shop)
end
def test_discarded_domain_has_corresponding_label
travel_to Time.zone.parse('2010-07-05 10:30')
@domain.delete_at = Time.zone.parse('2010-07-05 10:00')
visit admin_domain_url(@domain)
assert_no_css 'span.label.label-warning', text: 'deleteCandidate'
@domain.discard
visit admin_domain_url(@domain)
assert_css 'span.label.label-warning', text: 'deleteCandidate'
end
end

View file

@ -1,58 +0,0 @@
require 'test_helper'
class AdminAreaDomainForceDeleteTest < ActionDispatch::IntegrationTest
include ActionMailer::TestHelper
setup do
sign_in users(:admin)
@domain = domains(:shop)
ActionMailer::Base.deliveries.clear
end
def test_schedules_domain_force_delete
refute @domain.force_delete_scheduled?
visit edit_admin_domain_url(@domain)
click_link_or_button 'Force delete domain'
@domain.reload
assert @domain.force_delete_scheduled?
assert_current_path edit_admin_domain_path(@domain)
assert_text 'Force delete procedure has been scheduled'
end
def test_notifies_registrar
assert_difference '@domain.registrar.messages.size' do
visit edit_admin_domain_url(@domain)
click_link_or_button 'Force delete domain'
end
end
def test_notifies_registrant_and_admin_contacts_by_email_by_default
assert_emails 1 do
visit edit_admin_domain_url(@domain)
click_link_or_button 'Force delete domain'
end
end
def test_allows_to_skip_notifying_registrant_and_admin_contacts_by_email
assert_no_emails do
visit edit_admin_domain_url(@domain)
uncheck 'notify_by_email'
click_link_or_button 'Force delete domain'
end
end
def test_cancels_scheduled_domain_force_delete
@domain.discard
@domain.schedule_force_delete
visit edit_admin_domain_url(@domain)
click_link_or_button 'Cancel force delete'
@domain.reload
refute @domain.force_delete_scheduled?
assert_current_path edit_admin_domain_path(@domain)
assert_text 'Force delete procedure has been cancelled'
end
end

View file

@ -1,31 +0,0 @@
require 'test_helper'
class AdminDomainsTestTest < ActionDispatch::IntegrationTest
def setup
sign_in users(:admin)
@domain = domains(:shop)
end
def teardown
travel_back
end
def test_shows_details
visit admin_domain_path(@domain)
assert_field nil, with: @domain.transfer_code
end
def test_keep_a_domain
travel_to Time.zone.parse('2010-07-05 10:30')
@domain.delete_at = Time.zone.parse('2010-07-05 10:00')
@domain.discard
visit edit_admin_domain_url(@domain)
click_link_or_button 'Remove deleteCandidate status'
@domain.reload
assert_not @domain.discarded?
assert_text 'deleteCandidate status has been removed'
assert_no_link 'Remove deleteCandidate status'
end
end

View file

@ -1,14 +0,0 @@
require 'test_helper'
class AdminAreaNewMailTemplateTest < ActionDispatch::IntegrationTest
setup do
sign_in users(:admin)
end
def test_new_mail_template_does_not_throw_template_error
visit admin_mail_templates_url
click_link_or_button 'New'
assert_text "HTML body"
assert_text "New mail template"
end
end

View file

@ -1,30 +0,0 @@
require 'test_helper'
class AdminAreaDeleteRegistrarTest < ActionDispatch::IntegrationTest
setup do
sign_in users(:admin)
end
def test_can_be_deleted_when_not_in_use
visit admin_registrar_url(registrars(:not_in_use))
assert_difference 'Registrar.count', -1 do
click_link_or_button 'Delete'
end
assert_current_path admin_registrars_path
assert_text 'Registrar has been successfully deleted'
end
def test_cannot_be_deleted_when_in_use
registrar = registrars(:bestnames)
visit admin_registrar_url(registrar)
assert_no_difference 'Registrar.count' do
click_link_or_button 'Delete'
end
assert_current_path admin_registrar_path(registrar)
assert_text 'Cannot delete record because dependent domains exist'
end
end

View file

@ -1,18 +0,0 @@
require 'test_helper'
class AdminAreaRegistrarDetailsTest < ActionDispatch::IntegrationTest
include ActionView::Helpers::NumberHelper
setup do
sign_in users(:admin)
@registrar = registrars(:complete)
end
def test_registrar_details
visit admin_registrar_path(@registrar)
assert_text 'Accounting customer code US0001'
assert_text 'VAT number US12345'
assert_text 'VAT rate 5.0%'
assert_text 'Language English'
end
end

View file

@ -1,69 +0,0 @@
require 'test_helper'
class AdminAreaEditRegistrarTest < ActionDispatch::IntegrationTest
setup do
sign_in users(:admin)
@registrar = registrars(:bestnames)
end
def test_attributes_update
visit admin_registrar_path(@registrar)
click_link_or_button 'Edit'
fill_in 'Name', with: 'new name'
fill_in 'Reg no', with: '4727673'
fill_in 'Contact phone', with: '2570937'
fill_in 'Website', with: 'http://new.example.com'
fill_in 'Contact e-mail', with: 'new@example.com'
fill_in 'Street', with: 'new street'
fill_in 'Zip', with: 'new zip'
fill_in 'City', with: 'new city'
fill_in 'State / Province', with: 'new state'
select 'Germany', from: 'Country'
fill_in 'VAT number', with: '2386449'
fill_in 'Accounting customer code', with: '866477'
fill_in 'Billing email', with: 'new-billing@example.com'
select 'Estonian', from: 'Language'
click_link_or_button 'Update registrar'
@registrar.reload
assert_equal 'new name', @registrar.name
assert_equal '4727673', @registrar.reg_no
assert_equal '2570937', @registrar.phone
assert_equal 'http://new.example.com', @registrar.website
assert_equal 'new@example.com', @registrar.email
assert_equal 'new street', @registrar.street
assert_equal 'new zip', @registrar.zip
assert_equal 'new city', @registrar.city
assert_equal 'new state', @registrar.state
assert_equal Country.new('DE'), @registrar.country
assert_equal '2386449', @registrar.vat_no
assert_equal '866477', @registrar.accounting_customer_code
assert_equal 'new-billing@example.com', @registrar.billing_email
assert_equal 'et', @registrar.language
assert_current_path admin_registrar_path(@registrar)
assert_text 'Registrar has been successfully updated'
end
def test_code_cannot_be_changed
visit admin_registrar_path(@registrar)
click_link_or_button 'Edit'
assert_no_field 'Code'
end
def test_fails_gracefully
visit admin_registrar_path(@registrar)
click_link_or_button 'Edit'
fill_in 'Name', with: 'Good Names'
click_link_or_button 'Update registrar'
assert_field 'Name', with: 'Good Names'
assert_text 'Name has already been taken'
end
end

View file

@ -1,50 +0,0 @@
require 'test_helper'
class AdminAreaNewRegistrarTest < ActionDispatch::IntegrationTest
setup do
sign_in users(:admin)
end
def test_new_registrar_creation_with_required_params
visit admin_registrars_url
click_link_or_button 'New registrar'
fill_in 'Name', with: 'Brand new names'
fill_in 'Reg no', with: '55555555'
fill_in 'Contact e-mail', with: 'test@example.com'
select 'United States', from: 'Country'
fill_in 'Accounting customer code', with: 'test'
fill_in 'Code', with: 'test'
assert_difference 'Registrar.count' do
click_link_or_button 'Create registrar'
end
assert_current_path admin_registrar_path(Registrar.last)
assert_text 'Registrar has been successfully created'
end
def test_fails_gracefully
visit admin_registrars_url
click_link_or_button 'New registrar'
fill_in 'Name', with: 'Best Names'
fill_in 'Reg no', with: '55555555'
fill_in 'Contact e-mail', with: 'test@example.com'
fill_in 'Accounting customer code', with: 'test'
fill_in 'Code', with: 'test'
assert_no_difference 'Registrar.count' do
click_link_or_button 'Create registrar'
end
assert_field 'Name', with: 'Best Names'
assert_text 'Name has already been taken'
end
def test_pre_populated_default_language
Setting.default_language = 'en'
visit admin_registrars_url
click_link_or_button 'New registrar'
assert_field 'Language', with: 'en'
end
end

View file

@ -1,6 +1,6 @@
require 'test_helper'
class APIDomainContactsTest < ActionDispatch::IntegrationTest
class APIDomainContactsTest < ApplicationIntegrationTest
def test_replace_all_tech_contacts_of_the_current_registrar
patch '/repp/v1/domains/contacts', { current_contact_id: 'william-001',
new_contact_id: 'john-001' },

View file

@ -1,6 +1,6 @@
require 'test_helper'
class APIDomainTransfersTest < ActionDispatch::IntegrationTest
class APIDomainTransfersTest < ApplicationIntegrationTest
setup do
@domain = domains(:shop)
@new_registrar = registrars(:goodnames)

View file

@ -1,6 +1,6 @@
require 'test_helper'
class APINameserversPutTest < ActionDispatch::IntegrationTest
class APINameserversPutTest < ApplicationIntegrationTest
def test_replaces_registrar_nameservers
old_nameserver_ids = [nameservers(:shop_ns1).id,
nameservers(:airport_ns1).id,

View file

@ -0,0 +1,58 @@
require 'test_helper'
class RegistrantApiAuthenticationTest < ApplicationIntegrationTest
def setup
super
@user_hash = { ident: '37010100049', first_name: 'Adam', last_name: 'Baker' }
@existing_user = RegistrantUser.find_or_create_by_api_data(@user_hash)
end
def teardown
super
end
def test_request_creates_user_when_one_does_not_exist
params = {
ident: '30110100103',
first_name: 'John',
last_name: 'Smith',
}
post '/api/v1/registrant/auth/eid', params
assert(User.find_by(registrant_ident: 'EE-30110100103'))
json = JSON.parse(response.body, symbolize_names: true)
assert_equal([:access_token, :expires_at, :type], json.keys)
end
def test_request_returns_existing_user
assert_no_changes User.count do
post '/api/v1/registrant/auth/eid', @user_hash
end
end
def test_request_returns_401_from_a_not_whitelisted_ip
params = { foo: :bar, test: :test }
@original_whitelist_ip = ENV['registrant_api_auth_allowed_ips']
ENV['registrant_api_auth_allowed_ips'] = '1.2.3.4'
post '/api/v1/registrant/auth/eid', params
assert_equal(401, response.status)
json_body = JSON.parse(response.body, symbolize_names: true)
assert_equal({ errors: [base: ['Not authorized']] }, json_body)
ENV['registrant_api_auth_allowed_ips'] = @original_whitelist_ip
end
def test_request_documented_parameters_are_required
params = { foo: :bar, test: :test }
post '/api/v1/registrant/auth/eid', params
json = JSON.parse(response.body, symbolize_names: true)
assert_equal({ errors: [{ ident: ['parameter is required'] }] }, json)
assert_equal(422, response.status)
end
end

View file

@ -0,0 +1,102 @@
require 'test_helper'
require 'auth_token/auth_token_creator'
class RegistrantApiDomainsTest < ApplicationIntegrationTest
def setup
super
@original_registry_time = Setting.days_to_keep_business_registry_cache
Setting.days_to_keep_business_registry_cache = 1
travel_to Time.zone.parse('2010-07-05')
@domain = domains(:hospital)
@registrant = @domain.registrant
@user = users(:registrant)
@auth_headers = { 'HTTP_AUTHORIZATION' => auth_token }
end
def teardown
super
Setting.days_to_keep_business_registry_cache = @original_registry_time
travel_back
end
def test_get_domain_details_by_uuid
get '/api/v1/registrant/domains/5edda1a5-3548-41ee-8b65-6d60daf85a37', {}, @auth_headers
assert_equal(200, response.status)
domain = JSON.parse(response.body, symbolize_names: true)
assert_equal('hospital.test', domain[:name])
end
def test_get_non_existent_domain_details_by_uuid
get '/api/v1/registrant/domains/random-uuid', {}, @auth_headers
assert_equal(404, response.status)
response_json = JSON.parse(response.body, symbolize_names: true)
assert_equal({ errors: [base: ['Domain not found']] }, response_json)
end
def test_root_returns_domain_list
get '/api/v1/registrant/domains', {}, @auth_headers
assert_equal(200, response.status)
response_json = JSON.parse(response.body, symbolize_names: true)
array_of_domain_names = response_json.map { |x| x[:name] }
assert(array_of_domain_names.include?('hospital.test'))
end
def test_root_accepts_limit_and_offset_parameters
get '/api/v1/registrant/domains', { 'limit' => 2, 'offset' => 0 }, @auth_headers
response_json = JSON.parse(response.body, symbolize_names: true)
assert_equal(200, response.status)
assert_equal(2, response_json.count)
get '/api/v1/registrant/domains', {}, @auth_headers
response_json = JSON.parse(response.body, symbolize_names: true)
assert_equal(5, response_json.count)
end
def test_root_does_not_accept_limit_higher_than_200
get '/api/v1/registrant/domains', { 'limit' => 400, 'offset' => 0 }, @auth_headers
assert_equal(400, response.status)
response_json = JSON.parse(response.body, symbolize_names: true)
assert_equal({ errors: [{ limit: ['parameter is out of range'] }] }, response_json)
end
def test_root_does_not_accept_offset_lower_than_0
get '/api/v1/registrant/domains', { 'limit' => 200, 'offset' => "-10" }, @auth_headers
assert_equal(400, response.status)
response_json = JSON.parse(response.body, symbolize_names: true)
assert_equal({ errors: [{ offset: ['parameter is out of range'] }] }, response_json)
end
def test_root_returns_401_without_authorization
get '/api/v1/registrant/domains', {}, {}
assert_equal(401, response.status)
json_body = JSON.parse(response.body, symbolize_names: true)
assert_equal({ errors: [base: ['Not authorized']] }, json_body)
end
def test_details_returns_401_without_authorization
get '/api/v1/registrant/domains/5edda1a5-3548-41ee-8b65-6d60daf85a37', {}, {}
assert_equal(401, response.status)
json_body = JSON.parse(response.body, symbolize_names: true)
assert_equal({ errors: [base: ['Not authorized']] }, json_body)
end
private
def auth_token
token_creator = AuthTokenCreator.create_with_defaults(@user)
hash = token_creator.token_in_hash
"Bearer #{hash[:access_token]}"
end
end

View file

@ -1,6 +1,6 @@
require 'test_helper'
class EppDomainCreateNameserversTest < ActionDispatch::IntegrationTest
class EppDomainCreateNameserversTest < ApplicationIntegrationTest
# Glue record requirement
def test_nameserver_ip_address_is_required_if_hostname_is_under_the_same_domain
request_xml = <<-XML

View file

@ -1,6 +1,6 @@
require 'test_helper'
class EppDomainCreateTransferCodeTest < ActionDispatch::IntegrationTest
class EppDomainCreateTransferCodeTest < ApplicationIntegrationTest
setup do
travel_to Time.zone.parse('2010-07-05')
end

View file

@ -1,6 +1,6 @@
require 'test_helper'
class EppDomainDeleteTest < ActionDispatch::IntegrationTest
class EppDomainDeleteTest < ApplicationIntegrationTest
def setup
@domain = domains(:shop)
end

View file

@ -1,6 +1,6 @@
require 'test_helper'
class EppDomainRenewTest < ActionDispatch::IntegrationTest
class EppDomainRenewTest < ApplicationIntegrationTest
self.use_transactional_fixtures = false
setup do

View file

@ -1,6 +1,6 @@
require 'test_helper'
class EppDomainUpdateTest < ActionDispatch::IntegrationTest
class EppDomainUpdateTest < ApplicationIntegrationTest
def setup
@domain = domains(:shop)
end

View file

@ -1,6 +1,6 @@
require 'test_helper'
class EppDomainTransferBaseTest < ActionDispatch::IntegrationTest
class EppDomainTransferBaseTest < ApplicationIntegrationTest
def test_non_existent_domain
request_xml = <<-XML
<?xml version="1.0" encoding="UTF-8" standalone="no"?>

View file

@ -1,6 +1,6 @@
require 'test_helper'
class EppDomainTransferQueryTest < ActionDispatch::IntegrationTest
class EppDomainTransferQueryTest < ApplicationIntegrationTest
def test_returns_domain_transfer_details
post '/epp/command/transfer', { frame: request_xml }, { 'HTTP_COOKIE' => 'session=api_bestnames' }
xml_doc = Nokogiri::XML(response.body)

View file

@ -1,6 +1,6 @@
require 'test_helper'
class EppDomainTransferRequestTest < ActionDispatch::IntegrationTest
class EppDomainTransferRequestTest < ApplicationIntegrationTest
def setup
@domain = domains(:shop)
@new_registrar = registrars(:goodnames)

View file

@ -1,6 +1,6 @@
require 'test_helper'
class EppLoginCredentialsTest < ActionDispatch::IntegrationTest
class EppLoginCredentialsTest < ApplicationIntegrationTest
def test_correct_credentials
request_xml = <<-XML
<?xml version="1.0" encoding="UTF-8" standalone="no"?>

View file

@ -1,6 +1,6 @@
require 'test_helper'
class EppLoginSessionLimitTest < ActionDispatch::IntegrationTest
class EppLoginSessionLimitTest < ApplicationIntegrationTest
setup do
travel_to Time.zone.parse('2010-07-05')
EppSession.delete_all

View file

@ -1,6 +1,6 @@
require 'test_helper'
class EppLogoutTest < ActionDispatch::IntegrationTest
class EppLogoutTest < ApplicationIntegrationTest
def test_success_response
post '/epp/session/logout', { frame: request_xml }, { 'HTTP_COOKIE' => 'session=api_bestnames' }
assert Nokogiri::XML(response.body).at_css('result[code="1500"]')

View file

@ -1,6 +1,6 @@
require 'test_helper'
class EppPollTest < ActionDispatch::IntegrationTest
class EppPollTest < ApplicationIntegrationTest
def test_messages
post '/epp/command/poll', { frame: request_xml }, { 'HTTP_COOKIE' => 'session=api_bestnames' }
assert_equal '1301', Nokogiri::XML(response.body).at_css('result')[:code]

View file

@ -1,25 +0,0 @@
require 'test_helper'
class RegistrantDomainsTest < ActionDispatch::IntegrationTest
setup do
sign_in users(:registrant)
Setting.days_to_keep_business_registry_cache = 1
travel_to Time.zone.parse('2010-07-05')
end
def test_shows_domains_where_current_user_is_registrant
visit registrant_domains_url
assert_text 'shop.test'
end
def test_shows_domains_where_current_user_is_contact_person
visit registrant_domains_url
assert_text 'airport.test'
end
def test_shows_domains_where_current_user_has_associated_organizations
visit registrant_domains_url
assert_text 'library.test'
end
end

View file

@ -1,24 +0,0 @@
require 'test_helper'
class RegistrantLayoutTest < ActionDispatch::IntegrationTest
def setup
super
sign_in(users(:registrant))
Setting.days_to_keep_business_registry_cache = 1
travel_to Time.zone.parse('2010-07-05')
end
def teardown
super
travel_back
end
def test_has_link_to_rest_whois_and_internet_ee
visit registrant_domains_url
assert(has_link?('Internet.ee', href: 'https://internet.ee'))
assert(has_link?('WHOIS', href: 'https://whois.internet.ee'))
end
end

View file

@ -1,28 +0,0 @@
require 'test_helper'
class BalanceTopUpTest < ActionDispatch::IntegrationTest
setup do
sign_in users(:api_bestnames)
end
def test_creates_new_invoice
original_vat_prc = Setting.registry_vat_prc
Setting.registry_vat_prc = 0.1
visit registrar_invoices_url
click_link_or_button 'Add deposit'
fill_in 'Amount', with: '25.5'
assert_difference 'Invoice.count' do
click_link_or_button 'Add'
end
invoice = Invoice.last
assert_equal BigDecimal(10), invoice.vat_rate
assert_equal BigDecimal('28.05'), invoice.total
assert_text 'Please pay the following invoice'
Setting.registry_vat_prc = original_vat_prc
end
end

View file

@ -1,42 +0,0 @@
require 'test_helper'
class RegistrarAreaBulkTransferTest < ActionDispatch::IntegrationTest
setup do
sign_in users(:api_goodnames)
end
def test_transfer_multiple_domains_in_bulk
request_body = { data: { domainTransfers: [{ domainName: 'shop.test', transferCode: '65078d5' }] } }
headers = { 'Content-type' => 'application/json' }
request_stub = stub_request(:post, /domain_transfers/).with(body: request_body,
headers: headers,
basic_auth: ['test_goodnames', 'testtest'])
.to_return(body: { data: [{
type: 'domain_transfer'
}] }.to_json, status: 200)
visit registrar_domains_url
click_link 'Bulk change'
click_link 'Bulk transfer'
attach_file 'Batch file', Rails.root.join('test', 'fixtures', 'files', 'valid_domains_for_transfer.csv').to_s
click_button 'Transfer'
assert_requested request_stub
assert_current_path registrar_domains_path
assert_text '1 domains have been successfully transferred'
end
def test_fail_gracefully
body = { errors: [{ title: 'epic fail' }] }.to_json
headers = { 'Content-type' => 'application/json' }
stub_request(:post, /domain_transfers/).to_return(status: 400, body: body, headers: headers)
visit registrar_domains_url
click_link 'Bulk change'
click_link 'Bulk transfer'
attach_file 'Batch file', Rails.root.join('test', 'fixtures', 'files', 'valid_domains_for_transfer.csv').to_s
click_button 'Transfer'
assert_text 'epic fail'
end
end

View file

@ -1,59 +0,0 @@
require 'test_helper'
class RegistrarAreaNameserverBulkChangeTest < ActionDispatch::IntegrationTest
setup do
sign_in users(:api_goodnames)
end
def test_replaces_current_registrar_nameservers
request_body = { data: { type: 'nameserver',
id: 'ns1.bestnames.test',
attributes: { hostname: 'new-ns.bestnames.test',
ipv4: %w[192.0.2.55 192.0.2.56],
ipv6: %w[2001:db8::55 2001:db8::56] } } }
request_stub = stub_request(:put, /registrar\/nameservers/).with(body: request_body,
headers: { 'Content-type' => 'application/json' },
basic_auth: ['test_goodnames', 'testtest'])
.to_return(body: { data: [{
type: 'nameserver',
id: 'new-ns.bestnames.test'}],
affected_domains: ["airport.test", "shop.test"]}.to_json, status: 200)
visit registrar_domains_url
click_link 'Bulk change'
click_link 'Nameserver'
fill_in 'Old hostname', with: 'ns1.bestnames.test'
fill_in 'New hostname', with: 'new-ns.bestnames.test'
fill_in 'ipv4', with: "192.0.2.55\n192.0.2.56"
fill_in 'ipv6', with: "2001:db8::55\n2001:db8::56"
click_on 'Replace nameserver'
assert_requested request_stub
assert_current_path registrar_domains_path
assert_text 'Nameserver have been successfully replaced'
assert_text 'Affected domains: airport.test, shop.test'
end
def test_fails_gracefully
stub_request(:put, /registrar\/nameservers/).to_return(status: 400,
body: { errors: [{ title: 'epic fail' }] }.to_json,
headers: { 'Content-type' => 'application/json' })
visit registrar_domains_url
click_link 'Bulk change'
click_link 'Nameserver'
fill_in 'Old hostname', with: 'old hostname'
fill_in 'New hostname', with: 'new hostname'
fill_in 'ipv4', with: 'ipv4'
fill_in 'ipv6', with: 'ipv6'
click_on 'Replace nameserver'
assert_text 'epic fail'
assert_field 'Old hostname', with: 'old hostname'
assert_field 'New hostname', with: 'new hostname'
assert_field 'ipv4', with: 'ipv4'
assert_field 'ipv6', with: 'ipv6'
end
end

View file

@ -1,47 +0,0 @@
require 'test_helper'
class RegistrarAreaTechContactBulkChangeTest < ActionDispatch::IntegrationTest
setup do
sign_in users(:api_bestnames)
end
def test_replace_domain_contacts_of_current_registrar
request_stub = stub_request(:patch, /domains\/contacts/)
.with(body: { current_contact_id: 'william-001', new_contact_id: 'john-001' },
basic_auth: ['test_bestnames', 'testtest'])
.to_return(body: { affected_domains: %w[foo.test bar.test],
skipped_domains: %w[baz.test qux.test] }.to_json,
status: 200)
visit registrar_domains_url
click_link 'Bulk change'
fill_in 'Current contact ID', with: 'william-001'
fill_in 'New contact ID', with: 'john-001'
click_on 'Replace technical contacts'
assert_requested request_stub
assert_current_path registrar_domains_path
assert_text 'Technical contacts have been successfully replaced'
assert_text 'Affected domains: foo.test, bar.test'
assert_text 'Skipped domains: baz.test, qux.test'
end
def test_fails_gracefully
stub_request(:patch, /domains\/contacts/)
.to_return(status: 400,
body: { error: { message: 'epic fail' } }.to_json,
headers: { 'Content-type' => 'application/json' })
visit registrar_domains_url
click_link 'Bulk change'
fill_in 'Current contact ID', with: 'william-001'
fill_in 'New contact ID', with: 'john-001'
click_on 'Replace technical contacts'
assert_text 'epic fail'
assert_field 'Current contact ID', with: 'william-001'
assert_field 'New contact ID', with: 'john-001'
end
end

View file

@ -1,21 +0,0 @@
require 'test_helper'
class RegistrarDomainsTest < ActionDispatch::IntegrationTest
def test_downloads_domain_list_as_csv
sign_in users(:api_bestnames)
travel_to Time.zone.parse('2010-07-05 10:30')
expected_csv = <<-CSV.strip_heredoc
Domain,Transfer code,Registrant name,Registrant code,Date of expiry
library.test,45118f5,Acme Ltd,acme-ltd-001,2010-07-05
shop.test,65078d5,John,john-001,2010-07-05
invalid.test,1438d6,any,invalid,2010-07-05
airport.test,55438j5,John,john-001,2010-07-05
CSV
visit registrar_domains_url
click_button 'Download as CSV'
assert_equal 'attachment; filename="Domains_2010-07-05_10.30.csv"', response_headers['Content-Disposition']
assert_equal expected_csv, page.body
end
end

View file

@ -1,28 +0,0 @@
require 'test_helper'
class ListInvoicesTest < ActionDispatch::IntegrationTest
def setup
super
@user = users(:api_bestnames)
@registrar_invoices = @user.registrar.invoices
sign_in @user
end
def test_show_balance
visit registrar_invoices_path
assert_text "Your current account balance is 100,00 EUR"
end
def test_show_multiple_invoices
@invoices = invoices
@registrar_invoices = []
@invoices.each do |invoice|
@registrar_invoices << invoice
end
visit registrar_invoices_path
assert_text "Unpaid", count: 5
assert_text "Invoice no.", count: 7
end
end

View file

@ -1,48 +0,0 @@
require 'test_helper'
class NewInvoicePaymentTest < ActionDispatch::IntegrationTest
def setup
super
@original_vat_prc = Setting.registry_vat_prc
Setting.registry_vat_prc = 0.2
@user = users(:api_bestnames)
sign_in @user
end
def teardown
super
Setting.registry_vat_prc = @original_vat_prc
end
def create_invoice_and_visit_its_page
visit registrar_invoices_path
click_link_or_button 'Add deposit'
fill_in 'Amount', with: '200.00'
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

@ -1,48 +0,0 @@
require 'test_helper'
class NewInvoiceTest < ActionDispatch::IntegrationTest
def setup
super
@user = users(:api_bestnames)
sign_in @user
end
def test_show_balance
visit registrar_invoices_path
assert_text "Your current account balance is 100,00 EUR"
end
def test_create_new_invoice_with_positive_amount
visit registrar_invoices_path
click_link_or_button 'Add deposit'
fill_in 'Amount', with: '200.00'
fill_in 'Description', with: 'My first invoice'
assert_difference 'Invoice.count', 1 do
click_link_or_button 'Add'
end
assert_text 'Please pay the following invoice'
assert_text 'Invoice no. 131050'
assert_text 'Subtotal 200,00 €'
assert_text 'Pay invoice'
end
# This test case should fail once issue #651 gets fixed
def test_create_new_invoice_with_amount_0_goes_through
visit registrar_invoices_path
click_link_or_button 'Add deposit'
fill_in 'Amount', with: '0.00'
fill_in 'Description', with: 'My first invoice'
assert_difference 'Invoice.count', 1 do
click_link_or_button 'Add'
end
assert_text 'Please pay the following invoice'
assert_text 'Invoice no. 131050'
assert_text 'Subtotal 0,00 €'
assert_text 'Pay invoice'
end
end

View file

@ -1,49 +0,0 @@
require 'test_helper'
class PaymentCallbackTest < ActionDispatch::IntegrationTest
def setup
super
@user = users(:api_bestnames)
sign_in @user
end
def create_invoice_with_items
@invoice = invoices(:for_payments_test)
invoice_item = invoice_items(:one)
@invoice.invoice_items << invoice_item
@invoice.invoice_items << invoice_item
@user.registrar.invoices << @invoice
end
def every_pay_request_params
{
nonce: "392f2d7748bc8cb0d14f263ebb7b8932",
timestamp: "1524136727",
api_username: "ca8d6336dd750ddb",
transaction_result: "completed",
payment_reference: "fd5d27b59a1eb597393cd5ff77386d6cab81ae05067e18d530b10f3802e30b56",
payment_state: "settled",
amount: "12.00",
order_reference: "e468a2d59a731ccc546f2165c3b1a6",
account_id: "EUR3D1",
cc_type: "master_card",
cc_last_four_digits: "0487",
cc_month: "10",
cc_year: "2018",
cc_holder_name: "John Doe",
hmac_fields: "account_id,amount,api_username,cc_holder_name,cc_last_four_digits,cc_month,cc_type,cc_year,hmac_fields,nonce,order_reference,payment_reference,payment_state,timestamp,transaction_result",
hmac: "efac1c732835668cd86023a7abc140506c692f0d",
invoice_id: "12900000",
payment_method: "every_pay"
}
end
def test_every_pay_callback_returns_status_200
create_invoice_with_items
request_params = every_pay_request_params.merge(invoice_id: @invoice.id)
post "/registrar/pay/callback/every_pay", request_params
assert_equal(200, response.status)
end
end

View file

@ -1,100 +0,0 @@
require 'test_helper'
class PaymentReturnTest < ActionDispatch::IntegrationTest
def setup
super
@user = users(:api_bestnames)
sign_in @user
end
def create_invoice_with_items
@invoice = invoices(:for_payments_test)
invoice_item = invoice_items(:one)
@invoice.invoice_items << invoice_item
@invoice.invoice_items << invoice_item
@user.registrar.invoices << @invoice
end
def every_pay_request_params
{
nonce: "392f2d7748bc8cb0d14f263ebb7b8932",
timestamp: "1524136727",
api_username: "ca8d6336dd750ddb",
transaction_result: "completed",
payment_reference: "fd5d27b59a1eb597393cd5ff77386d6cab81ae05067e18d530b10f3802e30b56",
payment_state: "settled",
amount: "12.00",
order_reference: "e468a2d59a731ccc546f2165c3b1a6",
account_id: "EUR3D1",
cc_type: "master_card",
cc_last_four_digits: "0487",
cc_month: "10",
cc_year: "2018",
cc_holder_name: "John Doe",
hmac_fields: "account_id,amount,api_username,cc_holder_name,cc_last_four_digits,cc_month,cc_type,cc_year,hmac_fields,nonce,order_reference,payment_reference,payment_state,timestamp,transaction_result",
hmac: "efac1c732835668cd86023a7abc140506c692f0d",
invoice_id: "12900000",
payment_method: "every_pay"
}
end
def bank_link_request_params
{
"VK_SERVICE": "1111",
"VK_VERSION": "008",
"VK_SND_ID": "testvpos",
"VK_REC_ID": "seb",
"VK_STAMP": 1,
"VK_T_NO": "1",
"VK_AMOUNT": "12.00",
"VK_CURR": "EUR",
"VK_REC_ACC": "1234",
"VK_REC_NAME": "Eesti Internet",
"VK_SND_ACC": "1234",
"VK_SND_NAME": "John Doe",
"VK_REF": "",
"VK_MSG": "Order nr 1",
"VK_T_DATETIME": "2018-04-01T00:30:00+0300",
"VK_MAC": "CZZvcptkxfuOxRR88JmT4N+Lw6Hs4xiQfhBWzVYldAcRTQbcB/lPf9MbJzBE4e1/HuslQgkdCFt5g1xW2lJwrVDBQTtP6DAHfvxU3kkw7dbk0IcwhI4whUl68/QCwlXEQTAVDv1AFnGVxXZ40vbm/aLKafBYgrirB5SUe8+g9FE=",
"VK_ENCODING": "UTF-8",
"VK_LANG": "ENG",
payment_method: "seb"
}
end
def test_every_pay_return_creates_activity_redirects_to_invoice_path
create_invoice_with_items
request_params = every_pay_request_params.merge(invoice_id: @invoice.id)
post "/registrar/pay/return/every_pay", request_params
assert_equal(302, response.status)
assert_redirected_to(registrar_invoice_path(@invoice))
end
def test_Every_Pay_return_raises_RecordNotFound
create_invoice_with_items
request_params = every_pay_request_params.merge(invoice_id: "178907")
assert_raises(ActiveRecord::RecordNotFound) do
post "/registrar/pay/return/every_pay", request_params
end
end
def test_bank_link_return_redirects_to_invoice_paths
create_invoice_with_items
request_params = bank_link_request_params.merge(invoice_id: @invoice.id)
post "/registrar/pay/return/seb", request_params
assert_equal(302, response.status)
assert_redirected_to(registrar_invoice_path(@invoice))
end
def test_bank_link_return
create_invoice_with_items
request_params = bank_link_request_params.merge(invoice_id: "178907")
assert_raises(ActiveRecord::RecordNotFound) do
post "/registrar/pay/return/seb", request_params
end
end
end