diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-11-19 21:12:50 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-11-19 21:12:50 +0300 |
commit | 78f7d2e7266a80502f91d5c3aeb5689c72f156a2 (patch) | |
tree | bd7dca46bb745b27d30ff9e0fab2c5aa92b37c69 /spec/models | |
parent | 03a3b1a4caac4c04e81ee592fdb3b9c47dbb9623 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/models')
-rw-r--r-- | spec/models/customer_relations/contact_spec.rb | 23 | ||||
-rw-r--r-- | spec/models/customer_relations/issue_contact_spec.rb | 28 |
2 files changed, 48 insertions, 3 deletions
diff --git a/spec/models/customer_relations/contact_spec.rb b/spec/models/customer_relations/contact_spec.rb index 3a2d4e2d0ca..7e26d324ac2 100644 --- a/spec/models/customer_relations/contact_spec.rb +++ b/spec/models/customer_relations/contact_spec.rb @@ -36,4 +36,27 @@ RSpec.describe CustomerRelations::Contact, type: :model do expect(contact.phone).to eq('123456') end end + + describe '#self.find_ids_by_emails' do + let_it_be(:group) { create(:group) } + let_it_be(:group_contacts) { create_list(:contact, 2, group: group) } + let_it_be(:other_contacts) { create_list(:contact, 2) } + + it 'returns ids of contacts from group' do + contact_ids = described_class.find_ids_by_emails(group.id, group_contacts.pluck(:email)) + + expect(contact_ids).to match_array(group_contacts.pluck(:id)) + end + + it 'does not return ids of contacts from other groups' do + contact_ids = described_class.find_ids_by_emails(group.id, other_contacts.pluck(:email)) + + expect(contact_ids).to be_empty + end + + it 'raises ArgumentError when called with too many emails' do + too_many_emails = described_class::MAX_PLUCK + 1 + expect { described_class.find_ids_by_emails(group.id, Array(0..too_many_emails)) }.to raise_error(ArgumentError) + end + end end diff --git a/spec/models/customer_relations/issue_contact_spec.rb b/spec/models/customer_relations/issue_contact_spec.rb index 3747d159833..474455a9884 100644 --- a/spec/models/customer_relations/issue_contact_spec.rb +++ b/spec/models/customer_relations/issue_contact_spec.rb @@ -4,6 +4,9 @@ require 'spec_helper' RSpec.describe CustomerRelations::IssueContact do let_it_be(:issue_contact, reload: true) { create(:issue_customer_relations_contact) } + let_it_be(:group) { create(:group) } + let_it_be(:project) { create(:project, group: group) } + let_it_be(:issue) { create(:issue, project: project) } subject { issue_contact } @@ -19,9 +22,6 @@ RSpec.describe CustomerRelations::IssueContact do let(:stubbed) { build_stubbed(:issue_customer_relations_contact) } let(:created) { create(:issue_customer_relations_contact) } - let(:group) { build(:group) } - let(:project) { build(:project, group: group) } - let(:issue) { build(:issue, project: project) } let(:contact) { build(:contact, group: group) } let(:for_issue) { build(:issue_customer_relations_contact, :for_issue, issue: issue) } let(:for_contact) { build(:issue_customer_relations_contact, :for_contact, contact: contact) } @@ -45,4 +45,26 @@ RSpec.describe CustomerRelations::IssueContact do expect(built).not_to be_valid end end + + describe '#self.find_contact_ids_by_emails' do + let_it_be(:for_issue) { create_list(:issue_customer_relations_contact, 2, :for_issue, issue: issue) } + let_it_be(:not_for_issue) { create_list(:issue_customer_relations_contact, 2) } + + it 'returns ids of contacts from issue' do + contact_ids = described_class.find_contact_ids_by_emails(issue.id, for_issue.map(&:contact).pluck(:email)) + + expect(contact_ids).to match_array(for_issue.pluck(:contact_id)) + end + + it 'does not return ids of contacts from other issues' do + contact_ids = described_class.find_contact_ids_by_emails(issue.id, not_for_issue.map(&:contact).pluck(:email)) + + expect(contact_ids).to be_empty + end + + it 'raises ArgumentError when called with too many emails' do + too_many_emails = described_class::MAX_PLUCK + 1 + expect { described_class.find_contact_ids_by_emails(issue.id, Array(0..too_many_emails)) }.to raise_error(ArgumentError) + end + end end |