diff options
Diffstat (limited to 'spec/graphql/resolvers/crm')
-rw-r--r-- | spec/graphql/resolvers/crm/organization_state_counts_resolver_spec.rb | 61 | ||||
-rw-r--r-- | spec/graphql/resolvers/crm/organizations_resolver_spec.rb | 14 |
2 files changed, 74 insertions, 1 deletions
diff --git a/spec/graphql/resolvers/crm/organization_state_counts_resolver_spec.rb b/spec/graphql/resolvers/crm/organization_state_counts_resolver_spec.rb new file mode 100644 index 00000000000..c6ad4beeee0 --- /dev/null +++ b/spec/graphql/resolvers/crm/organization_state_counts_resolver_spec.rb @@ -0,0 +1,61 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Resolvers::Crm::OrganizationStateCountsResolver do + include GraphqlHelpers + + let_it_be(:user) { create(:user) } + let_it_be(:group) { create(:group, :crm_enabled) } + + before_all do + create(:organization, group: group, name: "ABC Corp") + create(:organization, group: group, name: "123 Corp", state: 'inactive') + create_list(:organization, 3, group: group) + create_list(:organization, 2, group: group, state: 'inactive') + end + + describe '#resolve' do + context 'with unauthorized user' do + it 'does not raise an error and returns nil' do + expect { resolve_counts(group) }.not_to raise_error + expect(resolve_counts(group)).to be_nil + end + end + + context 'with authorized user' do + before do + group.add_reporter(user) + end + + context 'without parent' do + it 'returns nil' do + expect(resolve_counts(nil)).to be_nil + end + end + + context 'with a group' do + context 'when no filter is provided' do + it 'returns the count of all organizations' do + counts = resolve_counts(group) + 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: "Corp" }) + + expect(counts['active']).to eq(1) + expect(counts['inactive']).to eq(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/organizations_resolver_spec.rb b/spec/graphql/resolvers/crm/organizations_resolver_spec.rb index 323f134ffc3..d5980bf3c41 100644 --- a/spec/graphql/resolvers/crm/organizations_resolver_spec.rb +++ b/spec/graphql/resolvers/crm/organizations_resolver_spec.rb @@ -55,11 +55,23 @@ RSpec.describe Resolvers::Crm::OrganizationsResolver do end context 'when no filter is provided' do - it 'returns all the organizations in the correct order' do + it 'returns all the organizations in the default order' do expect(resolve_organizations(group)).to eq([organization_a, organization_b]) end end + context 'when a sort is provided' do + it 'returns all the organizations in the correct order' do + expect(resolve_organizations(group, { sort: 'NAME_DESC' })).to eq([organization_b, organization_a]) + end + end + + context 'when filtering for all states' do + it 'returns all the organizations' do + expect(resolve_organizations(group, { state: 'all' })).to contain_exactly(organization_a, organization_b) + end + end + context 'when search term is provided' do it 'returns the correct organizations' do expect(resolve_organizations(group, { search: "def" })).to contain_exactly(organization_b) |