diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-10-20 12:40:42 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-10-20 12:40:42 +0300 |
commit | ee664acb356f8123f4f6b00b73c1e1cf0866c7fb (patch) | |
tree | f8479f94a28f66654c6a4f6fb99bad6b4e86a40e /spec/graphql/resolvers | |
parent | 62f7d5c5b69180e82ae8196b7b429eeffc8e7b4f (diff) |
Add latest changes from gitlab-org/gitlab@15-5-stable-eev15.5.0-rc42
Diffstat (limited to 'spec/graphql/resolvers')
4 files changed, 161 insertions, 20 deletions
diff --git a/spec/graphql/resolvers/ci/all_jobs_resolver_spec.rb b/spec/graphql/resolvers/ci/all_jobs_resolver_spec.rb new file mode 100644 index 00000000000..2a7d0a8171b --- /dev/null +++ b/spec/graphql/resolvers/ci/all_jobs_resolver_spec.rb @@ -0,0 +1,52 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Resolvers::Ci::AllJobsResolver do + include GraphqlHelpers + + let_it_be(:successful_job) { create(:ci_build, :success, name: 'Job One') } + let_it_be(:successful_job_two) { create(:ci_build, :success, name: 'Job Two') } + let_it_be(:failed_job) { create(:ci_build, :failed, name: 'Job Three') } + let_it_be(:pending_job) { create(:ci_build, :pending, name: 'Job Three') } + + let(:args) { {} } + let(:current_user) { create(:admin) } + + subject { resolve_jobs(args) } + + describe '#resolve' do + context 'with authorized user' do + context 'with statuses argument' do + let(:args) { { statuses: [Types::Ci::JobStatusEnum.coerce_isolated_input('SUCCESS')] } } + + it { is_expected.to contain_exactly(successful_job, successful_job_two) } + end + + context 'with multiple statuses' do + let(:args) do + { statuses: [Types::Ci::JobStatusEnum.coerce_isolated_input('SUCCESS'), + Types::Ci::JobStatusEnum.coerce_isolated_input('FAILED')] } + end + + it { is_expected.to contain_exactly(successful_job, successful_job_two, failed_job) } + end + + context 'without statuses argument' do + it { is_expected.to contain_exactly(successful_job, successful_job_two, failed_job, pending_job) } + end + end + + context 'with unauthorized user' do + let(:current_user) { nil } + + it { is_expected.to be_empty } + end + end + + private + + def resolve_jobs(args = {}, context = { current_user: current_user }) + resolve(described_class, args: args, ctx: context) + end +end diff --git a/spec/graphql/resolvers/ci/job_token_scope_resolver_spec.rb b/spec/graphql/resolvers/ci/job_token_scope_resolver_spec.rb index 1bfd6fbf6b9..59ece15b745 100644 --- a/spec/graphql/resolvers/ci/job_token_scope_resolver_spec.rb +++ b/spec/graphql/resolvers/ci/job_token_scope_resolver_spec.rb @@ -6,7 +6,7 @@ RSpec.describe Resolvers::Ci::JobTokenScopeResolver do include GraphqlHelpers let_it_be(:current_user) { create(:user) } - let_it_be(:project) { create(:project, ci_job_token_scope_enabled: true).tap(&:save!) } + let_it_be(:project) { create(:project, ci_outbound_job_token_scope_enabled: true).tap(&:save!) } specify do expect(described_class).to have_nullable_graphql_type(::Types::Ci::JobTokenScopeType) @@ -21,7 +21,7 @@ RSpec.describe Resolvers::Ci::JobTokenScopeResolver do end it 'returns the same project in the allow list of projects for the Ci Job Token when scope is not enabled' do - allow(project).to receive(:ci_job_token_scope_enabled?).and_return(false) + allow(project).to receive(:ci_outbound_job_token_scope_enabled?).and_return(false) expect(resolve_scope.all_projects).to contain_exactly(project) end @@ -40,7 +40,7 @@ RSpec.describe Resolvers::Ci::JobTokenScopeResolver do context 'when job token scope is disabled' do before do - project.update!(ci_job_token_scope_enabled: false) + project.update!(ci_outbound_job_token_scope_enabled: false) end it 'resolves projects' do diff --git a/spec/graphql/resolvers/project_pipeline_schedules_resolver_spec.rb b/spec/graphql/resolvers/project_pipeline_schedules_resolver_spec.rb new file mode 100644 index 00000000000..159335adf79 --- /dev/null +++ b/spec/graphql/resolvers/project_pipeline_schedules_resolver_spec.rb @@ -0,0 +1,40 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Resolvers::ProjectPipelineSchedulesResolver do + include GraphqlHelpers + + let_it_be(:developer) { create(:user) } + let_it_be(:user) { create(:user) } + let_it_be(:project) { create(:project, :repository, public_builds: false) } + + before do + project.add_owner(user) + end + + describe 'With filters' do + let(:pipeline_schedule) { create(:ci_pipeline_schedule, project: project, owner: developer) } + + before do + pipeline_schedule.pipelines << build(:ci_pipeline, project: project) + end + + it 'shows active pipeline schedules' do + schedules = resolve_pipeline_schedules + + expect(schedules).to contain_exactly(pipeline_schedule) + end + + it 'shows the inactive pipeline schedules' do + schedules = resolve_pipeline_schedules(args: + { status: ::Types::Ci::PipelineScheduleStatusEnum.values['INACTIVE'].value }) + + expect(schedules).to be_empty + end + end + + def resolve_pipeline_schedules(args: {}) + resolve(described_class, obj: project, ctx: { current_user: user }, args: args) + end +end diff --git a/spec/graphql/resolvers/users/participants_resolver_spec.rb b/spec/graphql/resolvers/users/participants_resolver_spec.rb index 3f04d157410..eb2418b63f4 100644 --- a/spec/graphql/resolvers/users/participants_resolver_spec.rb +++ b/spec/graphql/resolvers/users/participants_resolver_spec.rb @@ -10,18 +10,31 @@ RSpec.describe Resolvers::Users::ParticipantsResolver do let_it_be(:guest) { create(:user) } let_it_be(:project) { create(:project, :public) } let_it_be(:issue) { create(:issue, project: project) } - let_it_be(:note) do - create( - :note, - :system, - :confidential, - project: project, - noteable: issue, - author: create(:user) - ) - end - let_it_be(:note_metadata) { create(:system_note_metadata, note: note) } + let_it_be(:public_note_author) { create(:user) } + let_it_be(:public_reply_author) { create(:user) } + let_it_be(:internal_note_author) { create(:user) } + let_it_be(:internal_reply_author) { create(:user) } + + let_it_be(:public_note) { create(:note, project: project, noteable: issue, author: public_note_author) } + let_it_be(:internal_note) { create(:note, :confidential, project: project, noteable: issue, author: internal_note_author) } + + let_it_be(:public_reply) { create(:note, noteable: issue, in_reply_to: public_note, project: project, author: public_reply_author) } + let_it_be(:internal_reply) { create(:note, :confidential, noteable: issue, in_reply_to: internal_note, project: project, author: internal_reply_author) } + + let_it_be(:note_metadata2) { create(:system_note_metadata, note: public_note) } + + let_it_be(:issue_emoji) { create(:award_emoji, name: 'thumbsup', awardable: issue) } + let_it_be(:note_emoji1) { create(:award_emoji, name: 'thumbsup', awardable: public_note) } + let_it_be(:note_emoji2) { create(:award_emoji, name: 'thumbsup', awardable: internal_note) } + let_it_be(:note_emoji3) { create(:award_emoji, name: 'thumbsup', awardable: public_reply) } + let_it_be(:note_emoji4) { create(:award_emoji, name: 'thumbsup', awardable: internal_reply) } + + let_it_be(:issue_emoji_author) { issue_emoji.user } + let_it_be(:public_note_emoji_author) { note_emoji1.user } + let_it_be(:internal_note_emoji_author) { note_emoji2.user } + let_it_be(:public_reply_emoji_author) { note_emoji3.user } + let_it_be(:internal_reply_emoji_author) { note_emoji4.user } subject(:resolved_items) { resolve(described_class, args: {}, ctx: { current_user: current_user }, obj: issue)&.items } @@ -34,7 +47,16 @@ RSpec.describe Resolvers::Users::ParticipantsResolver do let(:current_user) { nil } it 'returns only publicly visible participants for this user' do - is_expected.to match_array([issue.author]) + is_expected.to match_array( + [ + issue.author, + issue_emoji_author, + public_note_author, + public_note_emoji_author, + public_reply_author, + public_reply_emoji_author + ] + ) end end @@ -42,15 +64,37 @@ RSpec.describe Resolvers::Users::ParticipantsResolver do let(:current_user) { guest } it 'returns only publicly visible participants for this user' do - is_expected.to match_array([issue.author]) + is_expected.to match_array( + [ + issue.author, + issue_emoji_author, + public_note_author, + public_note_emoji_author, + public_reply_author, + public_reply_emoji_author + ] + ) end end - context 'when current user has access to confidential notes' do + context 'when current user has access to internal notes' do let(:current_user) { user } it 'returns all participants for this user' do - is_expected.to match_array([issue.author, note.author]) + is_expected.to match_array( + [ + issue.author, + issue_emoji_author, + public_note_author, + public_note_emoji_author, + public_reply_author, + internal_note_author, + internal_note_emoji_author, + internal_reply_author, + public_reply_emoji_author, + internal_reply_emoji_author + ] + ) end context 'N+1 queries' do @@ -64,9 +108,14 @@ RSpec.describe Resolvers::Users::ParticipantsResolver do it 'does not execute N+1 for project relation' do control_count = ActiveRecord::QueryRecorder.new { query.call } - create(:note, :confidential, project: project, noteable: issue, author: create(:user)) + create(:award_emoji, :upvote, awardable: issue) + internal_note = create(:note, :confidential, project: project, noteable: issue, author: create(:user)) + create(:award_emoji, name: 'thumbsup', awardable: internal_note) + public_note = create(:note, project: project, noteable: issue, author: create(:user)) + create(:award_emoji, name: 'thumbsup', awardable: public_note) - expect { query.call }.not_to exceed_query_limit(control_count) + # 1 extra query per source (3 emojis + 2 notes) to fetch participables collection + expect { query.call }.not_to exceed_query_limit(control_count).with_threshold(5) end it 'does not execute N+1 for system note metadata relation' do |