diff options
Diffstat (limited to 'spec/graphql/resolvers')
8 files changed, 138 insertions, 7 deletions
diff --git a/spec/graphql/resolvers/ci/runner_jobs_resolver_spec.rb b/spec/graphql/resolvers/ci/runner_jobs_resolver_spec.rb index 53b673e255b..ba8a127bec5 100644 --- a/spec/graphql/resolvers/ci/runner_jobs_resolver_spec.rb +++ b/spec/graphql/resolvers/ci/runner_jobs_resolver_spec.rb @@ -12,7 +12,7 @@ RSpec.describe Resolvers::Ci::RunnerJobsResolver do let!(:build_one) { create(:ci_build, :success, name: 'Build One', runner: runner, pipeline: pipeline) } let!(:build_two) { create(:ci_build, :success, name: 'Build Two', runner: runner, pipeline: pipeline) } let!(:build_three) { create(:ci_build, :failed, name: 'Build Three', runner: runner, pipeline: pipeline) } - let!(:irrelevant_build) { create(:ci_build, name: 'Irrelevant Build', pipeline: irrelevant_pipeline)} + let!(:irrelevant_build) { create(:ci_build, name: 'Irrelevant Build', pipeline: irrelevant_pipeline) } let(:args) { {} } let(:runner) { create(:ci_runner, :project, projects: [project]) } 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) diff --git a/spec/graphql/resolvers/group_members/notification_email_resolver_spec.rb b/spec/graphql/resolvers/group_members/notification_email_resolver_spec.rb index 8d0b8f9398d..e1c67bc7c18 100644 --- a/spec/graphql/resolvers/group_members/notification_email_resolver_spec.rb +++ b/spec/graphql/resolvers/group_members/notification_email_resolver_spec.rb @@ -17,7 +17,7 @@ RSpec.describe Resolvers::GroupMembers::NotificationEmailResolver do expect(described_class).to have_nullable_graphql_type(GraphQL::Types::String) end - subject { batch_sync { resolve_notification_email(developer.group_members.first, current_user) }} + subject { batch_sync { resolve_notification_email(developer.group_members.first, current_user) } } context 'when current_user is admin' do let(:current_user) { create(:user, :admin) } diff --git a/spec/graphql/resolvers/project_jobs_resolver_spec.rb b/spec/graphql/resolvers/project_jobs_resolver_spec.rb index bb711a4c857..eb9d31ea7e5 100644 --- a/spec/graphql/resolvers/project_jobs_resolver_spec.rb +++ b/spec/graphql/resolvers/project_jobs_resolver_spec.rb @@ -14,7 +14,7 @@ RSpec.describe Resolvers::ProjectJobsResolver do let_it_be(:failed_build) { create(:ci_build, :failed, name: 'Build Three', pipeline: pipeline) } let_it_be(:pending_build) { create(:ci_build, :pending, name: 'Build Three', pipeline: pipeline) } - let(:irrelevant_build) { create(:ci_build, name: 'Irrelevant Build', pipeline: irrelevant_pipeline)} + let(:irrelevant_build) { create(:ci_build, name: 'Irrelevant Build', pipeline: irrelevant_pipeline) } let(:args) { {} } let(:current_user) { create(:user) } diff --git a/spec/graphql/resolvers/projects/fork_targets_resolver_spec.rb b/spec/graphql/resolvers/projects/fork_targets_resolver_spec.rb new file mode 100644 index 00000000000..ef1b18f0a11 --- /dev/null +++ b/spec/graphql/resolvers/projects/fork_targets_resolver_spec.rb @@ -0,0 +1,49 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Resolvers::Projects::ForkTargetsResolver do + include GraphqlHelpers + + let_it_be(:group) { create(:group, path: 'namespace-group') } + let_it_be(:another_group) { create(:group, path: 'namespace-another-group') } + let_it_be(:project) { create(:project, :private, group: group) } + let_it_be(:user) { create(:user, username: 'namespace-user', maintainer_projects: [project]) } + + let(:args) { { search: 'namespace' } } + + describe '#resolve' do + before_all do + group.add_owner(user) + another_group.add_owner(user) + end + + it 'returns forkable namespaces' do + expect_next_instance_of(ForkTargetsFinder) do |finder| + expect(finder).to receive(:execute).with(args).and_call_original + end + + expect(resolve_targets(args).items).to match_array([user.namespace, project.namespace, another_group]) + end + end + + context 'when a user cannot fork the project' do + let(:user) { create(:user) } + + it 'does not return results' do + project.add_guest(user) + + expect(resolve_targets(args)).to be_nil + end + end + + def resolve_targets(args, opts = {}) + field_options = described_class.field_options.merge( + owner: resolver_parent, + name: 'field_value' + ).merge(opts) + + field = ::Types::BaseField.new(**field_options) + resolve_field(field, project, args: args, ctx: { current_user: user }, object_type: resolver_parent) + end +end diff --git a/spec/graphql/resolvers/projects/grafana_integration_resolver_spec.rb b/spec/graphql/resolvers/projects/grafana_integration_resolver_spec.rb index 854e763fbdd..546b8592546 100644 --- a/spec/graphql/resolvers/projects/grafana_integration_resolver_spec.rb +++ b/spec/graphql/resolvers/projects/grafana_integration_resolver_spec.rb @@ -7,7 +7,7 @@ RSpec.describe Resolvers::Projects::GrafanaIntegrationResolver do let_it_be(:project) { create(:project) } let_it_be(:current_user) { create(:user) } - let_it_be(:grafana_integration) { create(:grafana_integration, project: project)} + let_it_be(:grafana_integration) { create(:grafana_integration, project: project) } describe '#resolve' do context 'when object is not a project' do @@ -19,7 +19,7 @@ RSpec.describe Resolvers::Projects::GrafanaIntegrationResolver do end context 'when object is nil' do - it { expect(resolve_integration(obj: nil)).to eq nil} + it { expect(resolve_integration(obj: nil)).to eq nil } end end diff --git a/spec/graphql/resolvers/projects_resolver_spec.rb b/spec/graphql/resolvers/projects_resolver_spec.rb index 2685115d1a2..453fafb9590 100644 --- a/spec/graphql/resolvers/projects_resolver_spec.rb +++ b/spec/graphql/resolvers/projects_resolver_spec.rb @@ -142,7 +142,7 @@ RSpec.describe Resolvers::ProjectsResolver do context 'when no sort is provided' do it 'returns projects in descending order by id' do - is_expected.to match_array((visible_projecs + named_projects).sort_by { |p| p[:id]}.reverse ) + is_expected.to match_array((visible_projecs + named_projects).sort_by { |p| p[:id] }.reverse ) end end end |