mirror of
https://github.com/internetee/registry.git
synced 2025-08-06 01:35:10 +02:00
refactored method which display count of contact
This commit is contained in:
parent
db012dd7da
commit
71655c4292
2 changed files with 35 additions and 9 deletions
|
@ -31,15 +31,8 @@ class RegistrantUser < User
|
|||
|
||||
counter = 0
|
||||
companies.each do |company|
|
||||
contacts = Contact.where(ident: company.registration_number, ident_country_code: 'EE')
|
||||
|
||||
next if contacts.blank?
|
||||
|
||||
contacts.each do |contact|
|
||||
next if company.company_name == contact.name
|
||||
|
||||
counter += 1
|
||||
end
|
||||
counter += Contact.where(ident: company.registration_number, ident_country_code: 'EE')&.
|
||||
reject { |contact| contact.name == company.company_name }.size
|
||||
end
|
||||
|
||||
return { result: true, counter: counter } if counter.positive?
|
||||
|
|
|
@ -61,6 +61,39 @@ class RegistrantUserTest < ActiveSupport::TestCase
|
|||
company_register.verify
|
||||
end
|
||||
|
||||
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
|
||||
|
||||
company_one = Company.new(org.ident, 'Acme Ltd')
|
||||
|
||||
Spy.on(@user, :companies).and_return([company_one])
|
||||
response = @user.do_need_update_contact?
|
||||
org.reload
|
||||
|
||||
assert_equal response[:counter], 0
|
||||
end
|
||||
|
||||
def test_should_return_count_of_contact_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
|
||||
|
||||
company_one = Company.new(org.ident, 'ace')
|
||||
company_two = Company.new(org.ident, 'acer')
|
||||
|
||||
Spy.on(@user, :companies).and_return([company_one, company_two])
|
||||
response = @user.do_need_update_contact?
|
||||
org.reload
|
||||
|
||||
assert_equal response[:counter], 2
|
||||
end
|
||||
|
||||
def test_returns_contacts
|
||||
Contact.stub(:registrant_user_contacts, %w(john jane)) do
|
||||
assert_equal %w(john jane), @user.contacts
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue