diff options
Diffstat (limited to 'spec/graphql/resolvers/crm')
-rw-r--r-- | spec/graphql/resolvers/crm/contact_state_counts_resolver_spec.rb | 63 | ||||
-rw-r--r-- | spec/graphql/resolvers/crm/contacts_resolver_spec.rb | 21 |
2 files changed, 83 insertions, 1 deletions
diff --git a/spec/graphql/resolvers/crm/contact_state_counts_resolver_spec.rb b/spec/graphql/resolvers/crm/contact_state_counts_resolver_spec.rb new file mode 100644 index 00000000000..0128ec792b3 --- /dev/null +++ b/spec/graphql/resolvers/crm/contact_state_counts_resolver_spec.rb @@ -0,0 +1,63 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Resolvers::Crm::ContactStateCountsResolver do + include GraphqlHelpers + + let_it_be(:user) { create(:user) } + let_it_be(:group) { create(:group, :crm_enabled) } + + before_all do + create(:contact, group: group, email: "x@test.com") + create(:contact, group: group, email: "y@test.com", state: 'inactive') + create_list(:contact, 3, group: group) + create_list(:contact, 2, group: group, state: 'inactive') + end + + describe '#resolve' do + context 'with unauthorized user' do + it 'does not raise an error and returns no counts' do + expect { resolve_counts(group) }.not_to raise_error + expect(resolve_counts(group).all).to be(0) + end + end + + context 'with authorized user' do + before do + group.add_reporter(user) + end + + context 'without parent' do + it 'returns no counts' do + expect(resolve_counts(nil).all).to be(0) + end + end + + context 'with a group' do + context 'when no filter is provided' do + it 'returns the count of all contacts' do + counts = resolve_counts(group) + expect(counts.all).to eq(7) + expect(counts.active).to eq(4) + expect(counts.inactive).to eq(3) + end + end + + context 'when search term is provided' do + it 'returns the correct counts' do + counts = resolve_counts(group, { search: "@test.com" }) + + expect(counts.all).to be(2) + expect(counts.active).to be(1) + expect(counts.inactive).to be(1) + end + end + end + end + end + + def resolve_counts(parent, args = {}, context = { current_user: user }) + resolve(described_class, obj: parent, args: args, ctx: context) + end +end diff --git a/spec/graphql/resolvers/crm/contacts_resolver_spec.rb b/spec/graphql/resolvers/crm/contacts_resolver_spec.rb index 98da4aeac28..c7c2d11e114 100644 --- a/spec/graphql/resolvers/crm/contacts_resolver_spec.rb +++ b/spec/graphql/resolvers/crm/contacts_resolver_spec.rb @@ -16,6 +16,7 @@ RSpec.describe Resolvers::Crm::ContactsResolver do last_name: "DEF", email: "ghi@test.com", description: "LMNO", + organization: create(:organization, group: group), state: "inactive" ) end @@ -61,11 +62,29 @@ RSpec.describe Resolvers::Crm::ContactsResolver do end context 'when no filter is provided' do - it 'returns all the contacts in the correct order' do + it 'returns all the contacts in the default order' do expect(resolve_contacts(group)).to eq([contact_a, contact_b]) end end + context 'when a sort is provided' do + it 'returns all the contacts in the correct order' do + expect(resolve_contacts(group, { sort: 'EMAIL_DESC' })).to eq([contact_b, contact_a]) + end + end + + context 'when a sort is provided needing offset_pagination' do + it 'returns all the contacts in the correct order' do + expect(resolve_contacts(group, { sort: 'ORGANIZATION_ASC' })).to eq([contact_a, contact_b]) + end + end + + context 'when filtering for all states' do + it 'returns all the contacts in the correct order' do + expect(resolve_contacts(group, { state: 'all' })).to eq([contact_a, contact_b]) + end + end + context 'when search term is provided' do it 'returns the correct contacts' do expect(resolve_contacts(group, { search: "x@test.com" })).to contain_exactly(contact_b) |