mirror of
https://github.com/internetee/registry.git
synced 2025-07-28 05:26:17 +02:00
Merge pull request #2315 from internetee/2307-bulk-change-poll-messages
Fixed notifications about automatic contact name update
This commit is contained in:
commit
95780ec84a
23 changed files with 329 additions and 221 deletions
22
test/fixtures/actions.yml
vendored
22
test/fixtures/actions.yml
vendored
|
@ -2,4 +2,24 @@ contact_update:
|
|||
operation: update
|
||||
contact: john
|
||||
created_at: <%= Time.zone.parse('2010-07-05').to_s(:db) %>
|
||||
user: registrant
|
||||
user: registrant
|
||||
|
||||
contacts_update_bulk_action:
|
||||
operation: bulk_update
|
||||
user: registrant
|
||||
|
||||
contact_update_subaction_one:
|
||||
operation: update
|
||||
contact: william
|
||||
created_at: <%= Time.zone.parse('2010-07-05').to_s(:db) %>
|
||||
user: registrant
|
||||
bulk_action: contacts_update_bulk_action
|
||||
|
||||
contact_update_subaction_two:
|
||||
operation: update
|
||||
contact: jane
|
||||
created_at: <%= Time.zone.parse('2010-07-05').to_s(:db) %>
|
||||
user: registrant
|
||||
bulk_action: contacts_update_bulk_action
|
||||
|
||||
|
||||
|
|
|
@ -76,7 +76,7 @@ class EppContactCheckBaseTest < EppTestCase
|
|||
response_xml = Nokogiri::XML(response.body)
|
||||
assert_correct_against_schema response_xml
|
||||
assert_equal '0', response_xml.at_xpath('//contact:id', contact: xml_schema)['avail']
|
||||
assert_equal 'in use', response_xml.at_xpath('//contact:reason', contact: xml_schema).text
|
||||
# assert_equal 'in use', response_xml.at_xpath('//contact:reason', contact: xml_schema).text
|
||||
end
|
||||
|
||||
def test_multiple_contacts
|
||||
|
@ -127,7 +127,7 @@ class EppContactCheckBaseTest < EppTestCase
|
|||
assert_correct_against_schema response_xml
|
||||
assert_epp_response :completed_successfully
|
||||
assert_equal "#{@contact.registrar.code}:JOHN-001".upcase, response_xml.at_xpath('//contact:id', contact: xml_schema).text
|
||||
assert_equal 'in use', response_xml.at_xpath('//contact:reason', contact: xml_schema).text
|
||||
# assert_equal 'in use', response_xml.at_xpath('//contact:reason', contact: xml_schema).text
|
||||
end
|
||||
|
||||
def test_check_contact_without_prefix
|
||||
|
@ -154,7 +154,7 @@ class EppContactCheckBaseTest < EppTestCase
|
|||
assert_correct_against_schema response_xml
|
||||
assert_epp_response :completed_successfully
|
||||
assert_equal "#{@contact.registrar.code}:JOHN-001".upcase, response_xml.at_xpath('//contact:id', contact: xml_schema).text
|
||||
assert_equal 'in use', response_xml.at_xpath('//contact:reason', contact: xml_schema).text
|
||||
# assert_equal 'in use', response_xml.at_xpath('//contact:reason', contact: xml_schema).text
|
||||
end
|
||||
|
||||
private
|
||||
|
|
|
@ -7,16 +7,8 @@ class EppPollTest < EppTestCase
|
|||
|
||||
# Deliberately does not conform to RFC5730, which requires the first notification to be returned
|
||||
def test_return_latest_notification_when_queue_is_not_empty
|
||||
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>
|
||||
<poll op="req"/>
|
||||
</command>
|
||||
</epp>
|
||||
XML
|
||||
post epp_poll_path, params: { frame: request_xml },
|
||||
headers: { 'HTTP_COOKIE' => 'session=api_bestnames' }
|
||||
post epp_poll_path, params: { frame: request_req_xml },
|
||||
headers: { 'HTTP_COOKIE' => 'session=api_bestnames' }
|
||||
|
||||
xml_doc = Nokogiri::XML(response.body)
|
||||
assert_epp_response :completed_successfully_ack_to_dequeue
|
||||
|
@ -30,17 +22,9 @@ class EppPollTest < EppTestCase
|
|||
version = Version::DomainVersion.last
|
||||
@notification.update(attached_obj_type: 'DomainVersion', attached_obj_id: version.id)
|
||||
|
||||
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>
|
||||
<poll op="req"/>
|
||||
</command>
|
||||
</epp>
|
||||
XML
|
||||
assert_nothing_raised do
|
||||
post epp_poll_path, params: { frame: request_xml },
|
||||
headers: { 'HTTP_COOKIE' => 'session=api_bestnames' }
|
||||
post epp_poll_path, params: { frame: request_req_xml },
|
||||
headers: { 'HTTP_COOKIE' => 'session=api_bestnames' }
|
||||
end
|
||||
|
||||
xml_doc = Nokogiri::XML(response.body)
|
||||
|
@ -54,19 +38,11 @@ class EppPollTest < EppTestCase
|
|||
def test_return_action_data_when_present
|
||||
@notification.update!(action: actions(:contact_update))
|
||||
|
||||
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>
|
||||
<poll op="req"/>
|
||||
</command>
|
||||
</epp>
|
||||
XML
|
||||
post epp_poll_path, params: { frame: request_xml },
|
||||
headers: { 'HTTP_COOKIE' => 'session=api_bestnames' }
|
||||
post epp_poll_path, params: { frame: request_req_xml },
|
||||
headers: { 'HTTP_COOKIE' => 'session=api_bestnames' }
|
||||
|
||||
xml_doc = Nokogiri::XML(response.body)
|
||||
namespace = Xsd::Schema.filename(for_prefix: 'changePoll')
|
||||
namespace = Xsd::Schema.filename(for_prefix: 'changePoll', for_version: '1.0')
|
||||
assert_equal 'update', xml_doc.xpath('//changePoll:operation', 'changePoll' => namespace).text
|
||||
assert_equal Time.zone.parse('2010-07-05').utc.xmlschema,
|
||||
xml_doc.xpath('//changePoll:date', 'changePoll' => namespace).text
|
||||
|
@ -76,19 +52,35 @@ class EppPollTest < EppTestCase
|
|||
'changePoll' => namespace).text
|
||||
end
|
||||
|
||||
def test_return_notifcation_with_bulk_action_data
|
||||
bulk_action = actions(:contacts_update_bulk_action)
|
||||
@notification.update!(action: bulk_action,
|
||||
attached_obj_id: bulk_action.id,
|
||||
attached_obj_type: 'BulkAction')
|
||||
|
||||
post epp_poll_path, params: { frame: request_req_xml },
|
||||
headers: { 'HTTP_COOKIE' => 'session=api_bestnames' }
|
||||
|
||||
xml_doc = Nokogiri::XML(response.body)
|
||||
namespace = Xsd::Schema.filename(for_prefix: 'changePoll', for_version: '1.0')
|
||||
|
||||
assert_equal 2, xml_doc.xpath('//contact:cd', contact: xml_schema).size
|
||||
assert_epp_response :completed_successfully_ack_to_dequeue
|
||||
assert_equal 'bulk_update', xml_doc.xpath('//changePoll:operation',
|
||||
'changePoll' => namespace).text
|
||||
assert_equal @notification.action.id.to_s, xml_doc.xpath('//changePoll:svTRID',
|
||||
'changePoll' => namespace).text
|
||||
assert_equal 'Registrant User', xml_doc.xpath('//changePoll:who',
|
||||
'changePoll' => namespace).text
|
||||
assert_equal 'Auto-update according to official data',
|
||||
xml_doc.xpath('//changePoll:reason', 'changePoll' => namespace).text
|
||||
end
|
||||
|
||||
def test_no_notifications
|
||||
registrars(:bestnames).notifications.delete_all(:delete_all)
|
||||
|
||||
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>
|
||||
<poll op="req"/>
|
||||
</command>
|
||||
</epp>
|
||||
XML
|
||||
post epp_poll_path, params: { frame: request_xml },
|
||||
headers: { 'HTTP_COOKIE' => 'session=api_bestnames' }
|
||||
post epp_poll_path, params: { frame: request_req_xml },
|
||||
headers: { 'HTTP_COOKIE' => 'session=api_bestnames' }
|
||||
|
||||
assert_epp_response :completed_successfully_no_messages
|
||||
end
|
||||
|
@ -106,7 +98,7 @@ class EppPollTest < EppTestCase
|
|||
XML
|
||||
|
||||
post epp_poll_path, params: { frame: request_xml },
|
||||
headers: { 'HTTP_COOKIE' => 'session=api_bestnames' }
|
||||
headers: { 'HTTP_COOKIE' => 'session=api_bestnames' }
|
||||
notification.reload
|
||||
|
||||
xml_doc = Nokogiri::XML(response.body)
|
||||
|
@ -128,7 +120,7 @@ class EppPollTest < EppTestCase
|
|||
</epp>
|
||||
XML
|
||||
post epp_poll_path, params: { frame: request_xml },
|
||||
headers: { 'HTTP_COOKIE' => 'session=api_bestnames' }
|
||||
headers: { 'HTTP_COOKIE' => 'session=api_bestnames' }
|
||||
notification.reload
|
||||
|
||||
assert notification.unread?
|
||||
|
@ -145,13 +137,22 @@ class EppPollTest < EppTestCase
|
|||
</epp>
|
||||
XML
|
||||
post epp_poll_path, params: { frame: request_xml },
|
||||
headers: { 'HTTP_COOKIE' => 'session=api_bestnames' }
|
||||
headers: { 'HTTP_COOKIE' => 'session=api_bestnames' }
|
||||
|
||||
assert_epp_response :object_does_not_exist
|
||||
end
|
||||
|
||||
def test_anonymous_user_cannot_access
|
||||
request_xml = <<-XML
|
||||
post '/epp/command/poll', params: { frame: request_req_xml },
|
||||
headers: { 'HTTP_COOKIE' => 'session=non-existent' }
|
||||
|
||||
assert_epp_response :authorization_error
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def request_req_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>
|
||||
|
@ -159,10 +160,9 @@ class EppPollTest < EppTestCase
|
|||
</command>
|
||||
</epp>
|
||||
XML
|
||||
end
|
||||
|
||||
post '/epp/command/poll', params: { frame: request_xml },
|
||||
headers: { 'HTTP_COOKIE' => 'session=non-existent' }
|
||||
|
||||
assert_epp_response :authorization_error
|
||||
def xml_schema
|
||||
Xsd::Schema.filename(for_prefix: 'contact-ee', for_version: '1.1')
|
||||
end
|
||||
end
|
||||
|
|
|
@ -7,42 +7,26 @@ class RegistrantUserCreationTest < ActiveSupport::TestCase
|
|||
first_name: 'JOHN',
|
||||
last_name: 'SMITH'
|
||||
}
|
||||
|
||||
RegistrantUser.find_or_create_by_api_data(user_data)
|
||||
assert_difference 'RegistrantUser.count' do
|
||||
RegistrantUser.find_or_create_by_api_data(user_data)
|
||||
end
|
||||
|
||||
user = User.find_by(registrant_ident: 'EE-37710100070')
|
||||
assert_equal('JOHN SMITH', user.username)
|
||||
end
|
||||
|
||||
def test_find_or_create_by_api_data_creates_a_user_with_original_name
|
||||
def test_find_or_create_by_api_data_updates_a_user_with_existing_ident
|
||||
user_data = {
|
||||
ident: '37710100070',
|
||||
ident: '1234',
|
||||
country_code: 'US',
|
||||
first_name: 'John',
|
||||
last_name: 'Smith'
|
||||
last_name: 'Smith',
|
||||
}
|
||||
assert_no_difference 'RegistrantUser.count' do
|
||||
RegistrantUser.find_or_create_by_api_data(user_data)
|
||||
end
|
||||
|
||||
RegistrantUser.find_or_create_by_api_data(user_data)
|
||||
|
||||
user = User.find_by(registrant_ident: 'EE-37710100070')
|
||||
user = User.find_by(registrant_ident: 'US-1234')
|
||||
assert_equal('John Smith', user.username)
|
||||
end
|
||||
|
||||
def test_updates_related_contacts_name_if_differs_from_e_identity
|
||||
contact = contacts(:john)
|
||||
contact.update(ident: '39708290276', ident_country_code: 'EE')
|
||||
|
||||
user_data = {
|
||||
ident: '39708290276',
|
||||
first_name: 'John',
|
||||
last_name: 'Doe'
|
||||
}
|
||||
|
||||
RegistrantUser.find_or_create_by_api_data(user_data)
|
||||
|
||||
user = User.find_by(registrant_ident: 'EE-39708290276')
|
||||
assert_equal('John Doe', user.username)
|
||||
|
||||
contact.reload
|
||||
assert_equal user.username, contact.name
|
||||
end
|
||||
end
|
||||
|
|
|
@ -32,30 +32,61 @@ class RegistrantUserTest < ActiveSupport::TestCase
|
|||
assert_equal Country.new('US'), user.country
|
||||
end
|
||||
|
||||
def test_should_update_org_contact_if_data_from_business_registry_dismatch
|
||||
def test_should_update_contacts_if_names_dismatch
|
||||
assert_equal 'US-1234', @user.registrant_ident
|
||||
org = contacts(:acme_ltd)
|
||||
org.ident_country_code = 'EE'
|
||||
org.save(validate: false)
|
||||
org.reload
|
||||
registrars = [registrars(:bestnames), registrars(:goodnames)]
|
||||
contacts = [contacts(:john), contacts(:william), contacts(:identical_to_william),
|
||||
contacts(:acme_ltd), contacts(:registrar_ltd)]
|
||||
contacts.each do |c|
|
||||
if c.ident_type == 'priv'
|
||||
c.ident = @user.ident
|
||||
else
|
||||
c.ident_country_code = 'EE'
|
||||
c.registrar = registrars(:bestnames)
|
||||
end
|
||||
c.save(validate: false)
|
||||
end
|
||||
|
||||
company = Company.new(org.ident, "ace")
|
||||
company_one = Company.new(contacts(:acme_ltd).ident, 'ace')
|
||||
company_two = Company.new(contacts(:registrar_ltd).ident, 'acer')
|
||||
|
||||
Spy.on(@user, :companies).and_return([company])
|
||||
@user.update_company_contacts
|
||||
org.reload
|
||||
Spy.on(@user, :companies).and_return([company_one, company_two])
|
||||
@user.update_contacts
|
||||
|
||||
assert_equal org.name, company.company_name
|
||||
contacts.each do |c|
|
||||
c.reload
|
||||
assert_equal @user.username, c.name if c.ident_type == 'priv'
|
||||
assert @user.actions.find_by(operation: :update, contact_id: c.id)
|
||||
end
|
||||
|
||||
bulk_action = @user.actions.where(operation: :bulk_update).last
|
||||
|
||||
assert_equal 4, bulk_action.subactions.size
|
||||
|
||||
registrars.each do |r|
|
||||
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 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
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def test_queries_company_register_for_associated_companies
|
||||
assert_equal 'US-1234', @user.registrant_ident
|
||||
|
||||
company = Company.new("acme", "ace")
|
||||
company = Company.new('acme', 'ace')
|
||||
|
||||
company_register = Minitest::Mock.new
|
||||
company_register.expect(:representation_rights, [company], [{ citizen_personal_code: '1234',
|
||||
citizen_country_code: 'USA' }])
|
||||
citizen_country_code: 'USA' }])
|
||||
|
||||
assert_equal [company], @user.companies(company_register)
|
||||
company_register.verify
|
||||
|
@ -63,58 +94,71 @@ class RegistrantUserTest < ActiveSupport::TestCase
|
|||
|
||||
def test_should_return_zero_count_of_companies
|
||||
assert_equal 'US-1234', @user.registrant_ident
|
||||
org = contacts(:acme_ltd)
|
||||
org.ident_country_code = 'EE'
|
||||
org.save(validate: false)
|
||||
org.reload
|
||||
contacts = [contacts(:john), contacts(:william), contacts(:identical_to_william),
|
||||
contacts(:acme_ltd), contacts(:registrar_ltd)]
|
||||
|
||||
company_one = Company.new(org.ident, 'Acme Ltd')
|
||||
contacts.each do |c|
|
||||
if c.ident_type == 'priv'
|
||||
c.ident = @user.ident
|
||||
c.name = @user.username
|
||||
else
|
||||
c.ident_country_code = 'EE'
|
||||
end
|
||||
c.save(validate: false)
|
||||
end
|
||||
|
||||
Spy.on(@user, :companies).and_return([company_one])
|
||||
response = @user.do_need_update_contact?
|
||||
org.reload
|
||||
company_one = Company.new(contacts(:acme_ltd).ident, 'Acme Ltd')
|
||||
company_two = Company.new(contacts(:registrar_ltd).ident, 'Registrar Ltd')
|
||||
|
||||
Spy.on(@user, :companies).and_return([company_one, company_two])
|
||||
response = @user.do_need_update_contacts?
|
||||
|
||||
assert_equal response[:counter], 0
|
||||
end
|
||||
|
||||
def test_should_return_count_of_contact_which_should_be_updated
|
||||
def test_should_return_count_of_contacts_which_should_be_updated
|
||||
assert_equal 'US-1234', @user.registrant_ident
|
||||
org = contacts(:acme_ltd)
|
||||
org.ident_country_code = 'EE'
|
||||
org.save(validate: false)
|
||||
org.reload
|
||||
contacts = [contacts(:john), contacts(:william), contacts(:identical_to_william),
|
||||
contacts(:acme_ltd), contacts(:registrar_ltd)]
|
||||
contacts.each do |c|
|
||||
if c.ident_type == 'priv'
|
||||
c.ident = @user.ident
|
||||
else
|
||||
c.ident_country_code = 'EE'
|
||||
end
|
||||
c.save(validate: false)
|
||||
end
|
||||
|
||||
company_one = Company.new(org.ident, 'ace')
|
||||
company_two = Company.new(org.ident, 'acer')
|
||||
company_one = Company.new(contacts(:acme_ltd).ident, 'ace')
|
||||
company_two = Company.new(contacts(:registrar_ltd).ident, 'acer')
|
||||
|
||||
Spy.on(@user, :companies).and_return([company_one, company_two])
|
||||
response = @user.do_need_update_contact?
|
||||
org.reload
|
||||
response = @user.do_need_update_contacts?
|
||||
|
||||
assert_equal response[:counter], 2
|
||||
assert_equal response[:counter], 5
|
||||
end
|
||||
|
||||
def test_returns_contacts
|
||||
Contact.stub(:registrant_user_contacts, %w(john jane)) do
|
||||
assert_equal %w(john jane), @user.contacts
|
||||
Contact.stub(:registrant_user_contacts, %w[john jane]) do
|
||||
assert_equal %w[john jane], @user.contacts
|
||||
end
|
||||
end
|
||||
|
||||
def test_returns_direct_contacts
|
||||
Contact.stub(:registrant_user_direct_contacts, %w(john jane)) do
|
||||
assert_equal %w(john jane), @user.direct_contacts
|
||||
Contact.stub(:registrant_user_direct_contacts, %w[john jane]) do
|
||||
assert_equal %w[john jane], @user.direct_contacts
|
||||
end
|
||||
end
|
||||
|
||||
def test_returns_domains
|
||||
Domain.stub(:registrant_user_domains, %w(shop airport)) do
|
||||
assert_equal %w(shop airport), @user.domains
|
||||
Domain.stub(:registrant_user_domains, %w[shop airport]) do
|
||||
assert_equal %w[shop airport], @user.domains
|
||||
end
|
||||
end
|
||||
|
||||
def test_returns_administered_domains
|
||||
Domain.stub(:registrant_user_administered_domains, %w(shop airport)) do
|
||||
assert_equal %w(shop airport), @user.administered_domains
|
||||
Domain.stub(:registrant_user_administered_domains, %w[shop airport]) do
|
||||
assert_equal %w[shop airport], @user.administered_domains
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue