Merge branch 'master' of https://github.com/internetee/registry into 1857-covered-registry-by-tests

This commit is contained in:
Oleg Hasjanov 2021-03-04 13:22:52 +02:00
commit 853e4c447b
54 changed files with 19 additions and 1803 deletions

View file

@ -1,33 +0,0 @@
require 'application_system_test_case'
class RegistrantAreaContactDetailsTest < ApplicationSystemTestCase
setup do
sign_in users(:registrant)
@domain = domains(:shop)
@contact = contacts(:john)
end
def test_general_data
visit registrant_domain_contact_url(@domain, @contact)
assert_text 'Code john-001'
assert_text 'Name John'
assert_text 'Auth info'
assert_css('[value="cacb5b"]')
assert_text 'Ident 1234'
assert_text 'Email john@inbox.test'
assert_text 'Phone +555.555'
assert_text "Created at #{l Time.zone.parse('2010-07-05')}"
assert_text "Updated at #{l Time.zone.parse('2010-07-06')}"
end
def test_registrant_user_cannot_access_contact_when_given_domain_belongs_to_another_user
suppress(ActiveRecord::RecordNotFound) do
visit registrant_domain_contact_url(domains(:metro), @contact)
assert_response :not_found
assert_no_text 'Name John'
end
end
end

View file

@ -1,172 +0,0 @@
require 'application_system_test_case'
class RegistrantAreaContactUpdateTest < ApplicationIntegrationTest
setup do
@domain = domains(:shop)
@contact = contacts(:john)
sign_in users(:registrant)
@original_address_processing = Setting.address_processing
@original_fax_enabled_setting = ENV['fax_enabled']
@original_registrant_api_base_url_setting = ENV['registrant_api_base_url']
ENV['registrant_api_base_url'] = 'https://api.test'
end
teardown do
Setting.address_processing = @original_address_processing
ENV['fax_enabled'] = @original_fax_enabled_setting
ENV['registrant_api_base_url'] = @original_registrant_api_base_url_setting
end
def test_form_is_pre_populated_with_contact_data
visit edit_registrant_domain_contact_url(@domain, @contact)
assert_field 'Name', with: 'John'
assert_field 'Email', with: 'john@inbox.test'
assert_field 'Phone', with: '+555.555'
end
def test_update_contact
stub_auth_request
request_body = { name: 'new name', email: 'new@inbox.test', phone: '+666.6' }.to_json
headers = { 'Content-Type' => Mime[:json],
'Authorization' => 'Bearer test-access-token' }
url = "https://api.test/api/v1/registrant/contacts/#{@contact.uuid}"
update_request_stub = stub_request(:patch, url).with(body: request_body, headers: headers)
.to_return(body: '{}', status: 200)
visit registrant_domain_contact_url(@domain, @contact)
click_link_or_button 'Edit'
fill_in 'Name', with: 'new name'
fill_in 'Email', with: 'new@inbox.test'
fill_in 'Phone', with: '+666.6'
click_link_or_button 'Update contact'
assert_requested update_request_stub
assert_current_path registrant_domain_contact_path(@domain, @contact)
assert_text 'Contact has been successfully updated'
end
def test_form_is_pre_populated_with_fax_when_enabled
ENV['fax_enabled'] = 'true'
@contact.update!(fax: '+111.1')
visit edit_registrant_domain_contact_url(@domain, @contact)
assert_field 'Fax', with: '+111.1'
end
def test_update_fax_when_enabled
ENV['fax_enabled'] = 'true'
stub_auth_request
request_body = { email: 'john@inbox.test', name: 'John', phone: '+555.555', fax: '+222.2' }
headers = { 'Authorization' => 'Bearer test-access-token' }
url = "https://api.test/api/v1/registrant/contacts/#{@contact.uuid}"
update_request_stub = stub_request(:patch, url).with(body: request_body, headers: headers)
.to_return(body: '{}', status: 200)
visit edit_registrant_domain_contact_url(@domain, @contact)
fill_in 'Fax', with: '+222.2'
click_link_or_button 'Update contact'
assert_requested update_request_stub
assert_current_path registrant_domain_contact_path(@domain, @contact)
assert_text 'Contact has been successfully updated'
end
def test_hide_fax_field_when_disabled
visit edit_registrant_domain_contact_url(@domain, @contact)
assert_no_field 'Fax'
end
def test_form_is_pre_populated_with_address_when_enabled
Setting.address_processing = true
@contact.update!(street: 'Main Street',
zip: '12345',
city: 'New York',
state: 'New York State',
country_code: 'US')
visit edit_registrant_domain_contact_url(@domain, @contact)
assert_field 'Street', with: 'Main Street'
assert_field 'Zip', with: '12345'
assert_field 'City', with: 'New York'
assert_field 'State', with: 'New York State'
assert_select 'Country', selected: 'United States'
end
def test_update_address_when_enabled
Setting.address_processing = true
stub_auth_request
request_body = { name: 'John',
email: 'john@inbox.test',
phone: '+555.555',
address: {
city: 'new city',
street: 'new street',
zip: '93742',
country_code: 'AT',
state: 'new state',
} }.to_json
headers = { 'Content-type' => Mime[:json],
'Authorization' => 'Bearer test-access-token' }
url = "https://api.test/api/v1/registrant/contacts/#{@contact.uuid}"
update_request_stub = stub_request(:patch, url).with(body: request_body, headers: headers)
.to_return(body: '{}', status: 200)
visit edit_registrant_domain_contact_url(@domain, @contact)
fill_in 'Street', with: 'new street'
fill_in 'City', with: 'new city'
fill_in 'State', with: 'new state'
fill_in 'Zip', with: '93742'
select 'Austria', from: 'Country'
click_link_or_button 'Update contact'
assert_requested update_request_stub
assert_current_path registrant_domain_contact_path(@domain, @contact)
assert_text 'Contact has been successfully updated'
end
def test_hide_address_field_when_disabled
visit edit_registrant_domain_contact_url(@domain, @contact)
assert_no_field 'Address'
assert_no_field 'Street'
end
def test_fail_gracefully
stub_auth_request
response_body = { errors: { name: ['Name is invalid'] } }.to_json
headers = { 'Authorization' => 'Bearer test-access-token' }
stub_request(:patch, "https://api.test/api/v1/registrant/contacts/#{@contact.uuid}")
.with(headers: headers)
.to_return(body: response_body, status: 400)
visit edit_registrant_domain_contact_url(@domain, @contact)
fill_in 'Name', with: 'invalid name'
click_link_or_button 'Update contact'
assert_current_path registrant_domain_contact_path(@domain, @contact)
assert_text 'Name is invalid'
assert_field 'Name', with: 'invalid name'
assert_no_text 'Contact has been successfully updated'
end
private
def stub_auth_request
body = { ident: '1234', first_name: 'Registrant', last_name: 'User' }
stub_request(:post, 'https://api.test/api/v1/registrant/auth/eid').with(body: body)
.to_return(body: { access_token: 'test-access-token' }.to_json,
headers: { 'Content-type' => Mime[:json] },
status: 200)
end
end

View file

@ -1,76 +0,0 @@
require 'application_system_test_case'
class RegistrantAreaDomainDetailsTest < ApplicationSystemTestCase
setup do
sign_in users(:registrant)
@domain = domains(:shop)
end
def test_general_data
@domain.update_columns(force_delete_date: '2010-07-08', statuses: [DomainStatus::FORCE_DELETE])
visit registrant_domain_url(@domain)
assert_text 'Name shop.test'
assert_text "Registered at #{l @domain.registered_at}"
assert_link 'Best Names', href: registrant_registrar_path(@domain.registrar)
assert_text 'Transfer code'
assert_css('[value="65078d5"]')
assert_text "Valid to #{l Time.zone.parse('2010-07-05')}"
assert_text "Outzone at #{l Time.zone.parse('2010-07-06')}"
assert_text "Delete date #{l Date.parse('2010-07-07')}"
assert_text "Force delete date #{l Date.parse('2010-07-08')}"
end
def test_registrant
visit registrant_domain_url(@domain)
assert_link 'John', href: registrant_domain_contact_path(@domain, @domain.registrant)
assert_text 'Code john-001'
assert_text 'Ident 1234'
assert_text 'Email john@inbox.test'
assert_text 'Phone +555.555'
end
def test_admin_contacts
visit registrant_domain_url(@domain)
within('.admin-domain-contacts') do
assert_link 'Jane', href: registrant_domain_contact_path(@domain, contacts(:jane))
assert_text 'jane-001'
assert_text 'jane@mail.test'
assert_css '.admin-domain-contact', count: 1
end
end
def test_tech_contacts
visit registrant_domain_url(@domain)
within('.tech-domain-contacts') do
assert_link 'William', href: registrant_domain_contact_path(@domain, contacts(:william))
assert_text 'william-001'
assert_text 'william@inbox.test'
assert_css '.tech-domain-contact', count: 2
end
end
def test_registrant_user_cannot_access_domains_of_other_users
suppress(ActiveRecord::RecordNotFound) do
visit registrant_domain_url(domains(:metro))
assert_response :not_found
assert_no_text 'metro.test'
end
end
def test_confirmation_url
@domain.update!(registrant_verification_token: 'a01',
pending_json: { new_registrant_email: 'any' },
statuses: [DomainStatus::PENDING_UPDATE])
visit registrant_domain_url(@domain)
click_on 'pendingUpdate'
assert_field nil, with: registrant_domain_update_confirm_url(@domain, token: 'a01')
end
end

View file

@ -1,46 +0,0 @@
require 'application_system_test_case'
class DomainDeleteConfirmsTest < ApplicationSystemTestCase
include ActionMailer::TestHelper
setup do
@user = users(:registrant)
sign_in @user
@domain = domains(:shop)
@domain.registrant_verification_asked!('<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n<epp></epp>', @user.id)
@domain.pending_delete!
end
def test_enqueues_approve_job_after_verification
visit registrant_domain_delete_confirm_url(@domain.id, token: @domain.registrant_verification_token)
perform_enqueued_jobs do
click_on 'Confirm domain delete'
end
assert_text 'Domain registrant change has successfully received.'
@domain.reload
assert_includes @domain.statuses, 'serverHold'
end
def test_enqueues_reject_job_after_verification
visit registrant_domain_delete_confirm_url(@domain.id, token: @domain.registrant_verification_token)
perform_enqueued_jobs do
click_on 'Reject domain delete'
end
assert_text 'Domain registrant change has been rejected successfully.'
@domain.reload
assert_equal ['ok'], @domain.statuses
end
def test_saves_whodunnit_info_after_verifivation
visit registrant_domain_delete_confirm_url(@domain.id, token: @domain.registrant_verification_token)
token = @domain.registrant_verification_token
click_on 'Confirm domain delete'
assert_text 'Domain registrant change has successfully received.'
refute RegistrantVerification.find_by(verification_token:token).updator_str.empty?
end
end

View file

@ -1,71 +0,0 @@
require 'application_system_test_case'
CompanyRegisterClientStub = Struct.new(:any_method) do
def representation_rights(citizen_personal_code:, citizen_country_code:)
raise CompanyRegister::NotAvailableError
end
end
class RegistrantAreaDomainListTest < ApplicationSystemTestCase
setup do
@user = users(:registrant)
sign_in @user
@domain = domains(:shop)
end
def test_show_domain_list
visit registrant_domains_url
assert_link 'shop.test', href: registrant_domain_path(@domain)
assert_link 'John', href: registrant_domain_contact_path(@domain, @domain.registrant)
assert_link 'Best Names', href: registrant_registrar_path(@domain.registrar)
assert_text l(Time.zone.parse('2010-07-05'))
assert_css '.domains .domain', count: 4
end
def test_do_not_show_domains_of_other_registrant_users
visit registrant_domains_url
assert_no_text 'metro.test'
end
def test_only_shows_direct_relation_and_or_company_domains
# case https://github.com/internetee/registry/issues/1690
tech_contact = contacts(:registrar_ltd)
# All domains share the same tech contact object
Domain.all.each do |domain|
DomainContact.create(domain: domain, contact: tech_contact, type: TechDomainContact)
end
visit registrant_domains_url
assert_no_text 'Company register is unavailable.'
assert_no_text 'metro.test'
end
def test_notification_when_company_register_is_unavailable
CompanyRegister::Client.stub(:new, CompanyRegisterClientStub.new) do
visit registrant_domains_url
end
assert_text 'Company register is unavailable. Domains and contacts associated via' \
' organizations are not shown.'
end
def test_show_direct_domains_when_company_register_is_unavailable
assert_equal 'US-1234', @user.registrant_ident
contact = contacts(:john)
assert_equal '1234', contact.ident
assert_equal Contact::PRIV, contact.ident_type
assert_equal 'US', contact.ident_country_code
assert_equal contact.becomes(Registrant), @domain.registrant
assert_equal 'shop.test', @domain.name
CompanyRegister::Client.stub(:new, CompanyRegisterClientStub.new) do
visit registrant_domains_url
end
assert_text 'shop.test'
end
end

View file

@ -1,22 +0,0 @@
require 'application_system_test_case'
class RegistrantDomainsTest < ApplicationSystemTestCase
setup do
sign_in users(:registrant)
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,15 +0,0 @@
require 'application_system_test_case'
class RegistrantLayoutTest < ApplicationSystemTestCase
def setup
super
sign_in(users(:registrant))
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,51 +0,0 @@
require 'application_system_test_case'
class RegistrantAreaTaraUsersTest < ApplicationSystemTestCase
def setup
super
OmniAuth.config.test_mode = true
@registrant = users(:registrant)
@existing_user_hash = {
'provider' => 'rant_tara',
'uid' => "US1234",
'info': { 'first_name': 'Registrant', 'last_name': 'User' }
}
@new_user_hash = {
'provider' => 'rant_tara',
'uid' => 'EE51007050604',
'info': { 'first_name': 'New Registrant', 'last_name': 'User'}
}
end
def teardown
super
OmniAuth.config.test_mode = false
OmniAuth.config.mock_auth['rant_tara'] = nil
end
def test_existing_user_gets_signed_in
OmniAuth.config.mock_auth[:rant_tara] = OmniAuth::AuthHash.new(@existing_user_hash)
visit new_registrant_user_session_path
click_link('Sign in')
assert_text('Signed in successfully')
end
def test_new_user_is_created_and_signed_in
OmniAuth.config.mock_auth[:rant_tara] = OmniAuth::AuthHash.new(@new_user_hash)
assert_difference 'RegistrantUser.count' do
visit new_registrant_user_session_path
click_link('Sign in')
assert_equal 'New Registrant User', RegistrantUser.last.username
assert_equal 'EE-51007050604', RegistrantUser.last.registrant_ident
assert_text('Signed in successfully')
end
end
end