diff --git a/spec/graphql/mutations/achievements/award_spec.rb b/spec/graphql/mutations/achievements/award_spec.rb index 1bfad46a616766f5218a42008248eb3cfde054ad..293b65a43d85c8a05a962583d91b93c34478914d 100644 --- a/spec/graphql/mutations/achievements/award_spec.rb +++ b/spec/graphql/mutations/achievements/award_spec.rb @@ -13,7 +13,7 @@ describe '#resolve' do subject(:resolve_mutation) do - described_class.new(object: nil, context: { current_user: current_user }, field: nil).resolve( + described_class.new(object: nil, context: query_context, field: nil).resolve( achievement_id: achievement&.to_global_id, user_id: recipient&.to_global_id ) end diff --git a/spec/graphql/mutations/achievements/create_spec.rb b/spec/graphql/mutations/achievements/create_spec.rb index 12b8ff67549b5713395efb72c63d36bb796a443e..f31f48fbcbeea0547eaf271165484b816ff4a603 100644 --- a/spec/graphql/mutations/achievements/create_spec.rb +++ b/spec/graphql/mutations/achievements/create_spec.rb @@ -5,7 +5,7 @@ RSpec.describe Mutations::Achievements::Create, feature_category: :user_profile do include GraphqlHelpers - let_it_be(:user) { create(:user) } + let_it_be(:current_user) { create(:user) } let(:group) { create(:group) } let(:valid_params) do @@ -14,7 +14,7 @@ describe '#resolve' do subject(:resolve_mutation) do - described_class.new(object: nil, context: { current_user: user }, field: nil).resolve( + described_class.new(object: nil, context: query_context, field: nil).resolve( **valid_params, namespace_id: group.to_global_id ) @@ -22,7 +22,7 @@ context 'when the user does not have permission' do before do - group.add_developer(user) + group.add_developer(current_user) end it 'raises an error' do @@ -33,7 +33,7 @@ context 'when the user has permission' do before do - group.add_maintainer(user) + group.add_maintainer(current_user) end context 'when the params are invalid' do diff --git a/spec/graphql/mutations/achievements/delete_spec.rb b/spec/graphql/mutations/achievements/delete_spec.rb index 0eb6f5a2e6f9b29952473432f4b9dd5cdab925ef..f72706a3efafd0677949cbdf54beced1ec1d8f60 100644 --- a/spec/graphql/mutations/achievements/delete_spec.rb +++ b/spec/graphql/mutations/achievements/delete_spec.rb @@ -14,7 +14,7 @@ describe '#resolve' do subject(:resolve_mutation) do - described_class.new(object: nil, context: { current_user: current_user }, field: nil).resolve( + described_class.new(object: nil, context: query_context, field: nil).resolve( achievement_id: achievement&.to_global_id ) end diff --git a/spec/graphql/mutations/achievements/delete_user_achievement_spec.rb b/spec/graphql/mutations/achievements/delete_user_achievement_spec.rb index d36b93bd3ead4d3bbac82170e2c52cb9cb703a7a..9040d7f2179ad97db016d316c9902a4a812ea522 100644 --- a/spec/graphql/mutations/achievements/delete_user_achievement_spec.rb +++ b/spec/graphql/mutations/achievements/delete_user_achievement_spec.rb @@ -13,7 +13,7 @@ describe '#resolve' do subject(:resolve_mutation) do - described_class.new(object: nil, context: { current_user: current_user }, field: nil).resolve( + described_class.new(object: nil, context: query_context, field: nil).resolve( user_achievement_id: user_achievement&.to_global_id ) end diff --git a/spec/graphql/mutations/achievements/revoke_spec.rb b/spec/graphql/mutations/achievements/revoke_spec.rb index 0c221b492afba6a44d49e19b1c552ef156b5c085..02813a4a89e3f27940ec3f0df3ce7b2f2a2b1fff 100644 --- a/spec/graphql/mutations/achievements/revoke_spec.rb +++ b/spec/graphql/mutations/achievements/revoke_spec.rb @@ -14,7 +14,7 @@ describe '#resolve' do subject(:resolve_mutation) do - described_class.new(object: nil, context: { current_user: current_user }, field: nil).resolve( + described_class.new(object: nil, context: query_context, field: nil).resolve( user_achievement_id: user_achievement&.to_global_id ) end diff --git a/spec/graphql/mutations/achievements/update_spec.rb b/spec/graphql/mutations/achievements/update_spec.rb index b69c8bef478326b3a5783555467ef2ad44cadb98..fe6916122596d330fe9d8ce19eee359542d5b940 100644 --- a/spec/graphql/mutations/achievements/update_spec.rb +++ b/spec/graphql/mutations/achievements/update_spec.rb @@ -15,7 +15,7 @@ describe '#resolve' do subject(:resolve_mutation) do - described_class.new(object: nil, context: { current_user: current_user }, field: nil).resolve( + described_class.new(object: nil, context: query_context, field: nil).resolve( achievement_id: achievement&.to_global_id, name: name ) end diff --git a/spec/graphql/mutations/alert_management/alerts/set_assignees_spec.rb b/spec/graphql/mutations/alert_management/alerts/set_assignees_spec.rb index da5531d2b93f172c767c91e3bbdd8e85ad0baacb..0ea72e2c7432b60f9e1d3e3205539c590cdadded 100644 --- a/spec/graphql/mutations/alert_management/alerts/set_assignees_spec.rb +++ b/spec/graphql/mutations/alert_management/alerts/set_assignees_spec.rb @@ -2,7 +2,9 @@ require 'spec_helper' -RSpec.describe Mutations::AlertManagement::Alerts::SetAssignees do +RSpec.describe Mutations::AlertManagement::Alerts::SetAssignees, feature_category: :api do + include GraphqlHelpers + let_it_be(:starting_assignee) { create(:user) } let_it_be(:unassigned_user) { create(:user) } let_it_be(:alert) { create(:alert_management_alert, assignees: [starting_assignee]) } @@ -170,7 +172,7 @@ end end - def mutation_for(project, user) - described_class.new(object: project, context: { current_user: user }, field: nil) + def mutation_for(project, _user) + described_class.new(object: project, context: query_context, field: nil) end end diff --git a/spec/graphql/mutations/alert_management/alerts/todo/create_spec.rb b/spec/graphql/mutations/alert_management/alerts/todo/create_spec.rb index 8ba1e785b63097f3d710f74ea5336c6b80388b61..8876398ae1134057bc4cd86b1e9b64b0d941ceec 100644 --- a/spec/graphql/mutations/alert_management/alerts/todo/create_spec.rb +++ b/spec/graphql/mutations/alert_management/alerts/todo/create_spec.rb @@ -2,18 +2,19 @@ require 'spec_helper' -RSpec.describe Mutations::AlertManagement::Alerts::Todo::Create do - subject(:mutation) { described_class.new(object: project, context: { current_user: current_user }, field: nil) } +RSpec.describe Mutations::AlertManagement::Alerts::Todo::Create, feature_category: :api do + include GraphqlHelpers let_it_be(:alert) { create(:alert_management_alert) } let_it_be(:project) { alert.project } let(:current_user) { project.first_owner } - let(:args) { { project_path: project.full_path, iid: alert.iid } } specify { expect(described_class).to require_graphql_authorizations(:update_alert_management_alert) } + subject(:mutation) { described_class.new(object: project, context: query_context, field: nil) } + describe '#resolve' do subject(:resolve) { mutation.resolve(args) } diff --git a/spec/graphql/mutations/alert_management/create_alert_issue_spec.rb b/spec/graphql/mutations/alert_management/create_alert_issue_spec.rb index f86046bb0d6912cad2faa5bb3bc9b194913a7fd9..dc560364b6427ca5ae714ffc6328278546cc54a2 100644 --- a/spec/graphql/mutations/alert_management/create_alert_issue_spec.rb +++ b/spec/graphql/mutations/alert_management/create_alert_issue_spec.rb @@ -2,7 +2,9 @@ require 'spec_helper' -RSpec.describe Mutations::AlertManagement::CreateAlertIssue do +RSpec.describe Mutations::AlertManagement::CreateAlertIssue, feature_category: :api do + include GraphqlHelpers + let_it_be(:current_user) { create(:user) } let_it_be(:project) { create(:project) } let_it_be(:alert) { create(:alert_management_alert, project: project, status: 'triggered') } @@ -74,7 +76,7 @@ private - def mutation_for(project, user) - described_class.new(object: project, context: { current_user: user }, field: nil) + def mutation_for(project, _user) + described_class.new(object: project, context: query_context, field: nil) end end diff --git a/spec/graphql/mutations/alert_management/http_integration/create_spec.rb b/spec/graphql/mutations/alert_management/http_integration/create_spec.rb index be6c627e37629f408ec2f647e63558c5a9fe39e0..ca0ab385e0377f93128107eeba2dc0d55a880bc6 100644 --- a/spec/graphql/mutations/alert_management/http_integration/create_spec.rb +++ b/spec/graphql/mutations/alert_management/http_integration/create_spec.rb @@ -2,10 +2,11 @@ require 'spec_helper' -RSpec.describe Mutations::AlertManagement::HttpIntegration::Create do +RSpec.describe Mutations::AlertManagement::HttpIntegration::Create, feature_category: :api do + include GraphqlHelpers + let_it_be(:current_user) { create(:user) } let_it_be(:project) { create(:project) } - let(:args) { { project_path: project.full_path, active: true, name: 'HTTP Integration' } } specify { expect(described_class).to require_graphql_authorizations(:admin_operations) } @@ -52,7 +53,7 @@ private - def mutation_for(project, user) - described_class.new(object: project, context: { current_user: user }, field: nil) + def mutation_for(project, _user) + described_class.new(object: project, context: query_context, field: nil) end end diff --git a/spec/graphql/mutations/alert_management/http_integration/destroy_spec.rb b/spec/graphql/mutations/alert_management/http_integration/destroy_spec.rb index 1aeeba1009ed0c30ad50f1f656a8dbb199270f62..028d17565bcca62e05807bb2cdd8207cbbf80a10 100644 --- a/spec/graphql/mutations/alert_management/http_integration/destroy_spec.rb +++ b/spec/graphql/mutations/alert_management/http_integration/destroy_spec.rb @@ -2,7 +2,9 @@ require 'spec_helper' -RSpec.describe Mutations::AlertManagement::HttpIntegration::Destroy do +RSpec.describe Mutations::AlertManagement::HttpIntegration::Destroy, feature_category: :api do + include GraphqlHelpers + let_it_be(:current_user) { create(:user) } let_it_be(:project) { create(:project) } @@ -53,7 +55,7 @@ private - def mutation_for(project, user) - described_class.new(object: project, context: { current_user: user }, field: nil) + def mutation_for(project, _user) + described_class.new(object: project, context: query_context, field: nil) end end diff --git a/spec/graphql/mutations/alert_management/http_integration/reset_token_spec.rb b/spec/graphql/mutations/alert_management/http_integration/reset_token_spec.rb index 5a2af9e0be809676898fb1974621f609843b7d1b..17db68e466f775ad3c419fc150136b864e7ad197 100644 --- a/spec/graphql/mutations/alert_management/http_integration/reset_token_spec.rb +++ b/spec/graphql/mutations/alert_management/http_integration/reset_token_spec.rb @@ -2,7 +2,9 @@ require 'spec_helper' -RSpec.describe Mutations::AlertManagement::HttpIntegration::ResetToken do +RSpec.describe Mutations::AlertManagement::HttpIntegration::ResetToken, feature_category: :api do + include GraphqlHelpers + let_it_be(:current_user) { create(:user) } let_it_be(:project) { create(:project) } let_it_be(:integration) { create(:alert_management_http_integration, project: project) } @@ -53,7 +55,7 @@ private - def mutation_for(project, user) - described_class.new(object: project, context: { current_user: user }, field: nil) + def mutation_for(project, _user) + described_class.new(object: project, context: query_context, field: nil) end end diff --git a/spec/graphql/mutations/alert_management/http_integration/update_spec.rb b/spec/graphql/mutations/alert_management/http_integration/update_spec.rb index 805996bf9e92faab0e238bc6c6d092eb4df7f14d..51b8fb90f09258f155838ea6a51acace0bf0bdde 100644 --- a/spec/graphql/mutations/alert_management/http_integration/update_spec.rb +++ b/spec/graphql/mutations/alert_management/http_integration/update_spec.rb @@ -2,7 +2,9 @@ require 'spec_helper' -RSpec.describe Mutations::AlertManagement::HttpIntegration::Update do +RSpec.describe Mutations::AlertManagement::HttpIntegration::Update, feature_category: :api do + include GraphqlHelpers + let_it_be(:current_user) { create(:user) } let_it_be(:project) { create(:project) } let_it_be(:integration) { create(:alert_management_http_integration, project: project) } @@ -53,7 +55,7 @@ private - def mutation_for(project, user) - described_class.new(object: project, context: { current_user: user }, field: nil) + def mutation_for(project, _user) + described_class.new(object: project, context: query_context, field: nil) end end diff --git a/spec/graphql/mutations/alert_management/prometheus_integration/create_spec.rb b/spec/graphql/mutations/alert_management/prometheus_integration/create_spec.rb index c92aeb43f51ca86c3b7f9f2aff58e562df13f7d2..13575b7676b0de41c4883dff953a2fa4bae82754 100644 --- a/spec/graphql/mutations/alert_management/prometheus_integration/create_spec.rb +++ b/spec/graphql/mutations/alert_management/prometheus_integration/create_spec.rb @@ -2,7 +2,8 @@ require 'spec_helper' -RSpec.describe Mutations::AlertManagement::PrometheusIntegration::Create do +RSpec.describe Mutations::AlertManagement::PrometheusIntegration::Create, feature_category: :api do + include GraphqlHelpers let_it_be(:current_user) { create(:user) } let_it_be(:project) { create(:project) } @@ -76,7 +77,7 @@ private - def mutation_for(project, user) - described_class.new(object: project, context: { current_user: user }, field: nil) + def mutation_for(project, _user) + described_class.new(object: project, context: query_context, field: nil) end end diff --git a/spec/graphql/mutations/alert_management/prometheus_integration/reset_token_spec.rb b/spec/graphql/mutations/alert_management/prometheus_integration/reset_token_spec.rb index be07c142f4e0d68445f8136838238ce517f49029..1da4e644c31f3f20d76a62d4197ca2cfff746aac 100644 --- a/spec/graphql/mutations/alert_management/prometheus_integration/reset_token_spec.rb +++ b/spec/graphql/mutations/alert_management/prometheus_integration/reset_token_spec.rb @@ -2,7 +2,9 @@ require 'spec_helper' -RSpec.describe Mutations::AlertManagement::PrometheusIntegration::ResetToken do +RSpec.describe Mutations::AlertManagement::PrometheusIntegration::ResetToken, feature_category: :api do + include GraphqlHelpers + let_it_be(:current_user) { create(:user) } let_it_be(:project) { create(:project) } let_it_be(:integration) { create(:prometheus_integration, project: project) } @@ -53,7 +55,7 @@ private - def mutation_for(project, user) - described_class.new(object: project, context: { current_user: user }, field: nil) + def mutation_for(project, _user) + described_class.new(object: project, context: query_context, field: nil) end end diff --git a/spec/graphql/mutations/alert_management/prometheus_integration/update_spec.rb b/spec/graphql/mutations/alert_management/prometheus_integration/update_spec.rb index 81d057c6ae22de4a4e22ca2df0b9bf0b31cf7a7e..3bba889b9a05647f4e7f8c6562b7ea81a5a3addc 100644 --- a/spec/graphql/mutations/alert_management/prometheus_integration/update_spec.rb +++ b/spec/graphql/mutations/alert_management/prometheus_integration/update_spec.rb @@ -2,7 +2,9 @@ require 'spec_helper' -RSpec.describe Mutations::AlertManagement::PrometheusIntegration::Update do +RSpec.describe Mutations::AlertManagement::PrometheusIntegration::Update, feature_category: :api do + include GraphqlHelpers + let_it_be(:current_user) { create(:user) } let_it_be(:project) { create(:project) } let_it_be(:integration) { create(:prometheus_integration, project: project) } @@ -53,7 +55,7 @@ private - def mutation_for(project, user) - described_class.new(object: project, context: { current_user: user }, field: nil) + def mutation_for(project, _user) + described_class.new(object: project, context: query_context, field: nil) end end diff --git a/spec/graphql/mutations/alert_management/update_alert_status_spec.rb b/spec/graphql/mutations/alert_management/update_alert_status_spec.rb index 8e1b2d9011788600492f9c0a598c22424f24e779..2a57df1f5dfb6174b02e839ee400ded8feb1d25a 100644 --- a/spec/graphql/mutations/alert_management/update_alert_status_spec.rb +++ b/spec/graphql/mutations/alert_management/update_alert_status_spec.rb @@ -2,7 +2,9 @@ require 'spec_helper' -RSpec.describe Mutations::AlertManagement::UpdateAlertStatus do +RSpec.describe Mutations::AlertManagement::UpdateAlertStatus, feature_category: :api do + include GraphqlHelpers + let_it_be(:current_user) { create(:user) } let_it_be(:alert) { create(:alert_management_alert, :triggered) } let_it_be(:project) { alert.project } @@ -80,7 +82,7 @@ private - def mutation_for(project, user) - described_class.new(object: project, context: { current_user: user }, field: nil) + def mutation_for(project, _user) + described_class.new(object: project, context: query_context, field: nil) end end diff --git a/spec/graphql/mutations/boards/update_spec.rb b/spec/graphql/mutations/boards/update_spec.rb index 4785bc94624e11ce6bbb7fa2b8d20f5f37ad8f67..f967b35f514ab65c67c4c7d340ebb1b97a919ac5 100644 --- a/spec/graphql/mutations/boards/update_spec.rb +++ b/spec/graphql/mutations/boards/update_spec.rb @@ -2,12 +2,14 @@ require 'spec_helper' -RSpec.describe Mutations::Boards::Update do +RSpec.describe Mutations::Boards::Update, feature_category: :api do + include GraphqlHelpers + let_it_be(:project) { create(:project) } - let_it_be(:user) { create(:user) } + let_it_be(:current_user) { create(:user) } let_it_be(:board) { create(:board, project: project) } - let(:mutation) { described_class.new(object: nil, context: { current_user: user }, field: nil) } + let(:mutation) { described_class.new(object: nil, context: query_context, field: nil) } let(:mutated_board) { subject[:board] } let(:mutation_params) do @@ -31,7 +33,7 @@ context 'when user can update board' do before do - board.resource_parent.add_reporter(user) + board.resource_parent.add_reporter(current_user) end it 'updates board with correct values' do diff --git a/spec/graphql/mutations/branches/create_spec.rb b/spec/graphql/mutations/branches/create_spec.rb index c2a27d9228d5bb907a401861031e43966b494c14..6bfbb1a0072bf4b2cd3ff87de2ce7c9b59276d12 100644 --- a/spec/graphql/mutations/branches/create_spec.rb +++ b/spec/graphql/mutations/branches/create_spec.rb @@ -2,20 +2,13 @@ require 'spec_helper' -RSpec.describe Mutations::Branches::Create do +RSpec.describe Mutations::Branches::Create, feature_category: :api do include GraphqlHelpers - subject(:mutation) { described_class.new(object: nil, context: context, field: nil) } - let_it_be(:project) { create(:project, :public, :repository) } - let_it_be(:user) { create(:user) } + let_it_be(:current_user) { create(:user) } - let(:context) do - GraphQL::Query::Context.new( - query: query_double(schema: nil), - values: { current_user: user } - ) - end + subject(:mutation) { described_class.new(object: nil, context: query_context, field: nil) } describe '#resolve' do subject { mutation.resolve(project_path: project.full_path, name: branch, ref: ref) } @@ -30,9 +23,9 @@ context 'when the user can create a branch' do before do - project.add_developer(user) + project.add_developer(current_user) - allow_next_instance_of(::Branches::CreateService, project, user) do |create_service| + allow_next_instance_of(::Branches::CreateService, project, current_user) do |create_service| allow(create_service).to receive(:execute).with(branch, ref) { service_result } end end diff --git a/spec/graphql/mutations/ci/job_token_scope/add_group_or_project_spec.rb b/spec/graphql/mutations/ci/job_token_scope/add_group_or_project_spec.rb index 1c8c8e9c2908ed3a689dd417041dbd1c8fa181c9..ab716f92e3cc7bdc15445939e89356dd3690218e 100644 --- a/spec/graphql/mutations/ci/job_token_scope/add_group_or_project_spec.rb +++ b/spec/graphql/mutations/ci/job_token_scope/add_group_or_project_spec.rb @@ -3,8 +3,10 @@ require 'spec_helper' RSpec.describe Mutations::Ci::JobTokenScope::AddGroupOrProject, feature_category: :continuous_integration do + include GraphqlHelpers + let(:mutation) do - described_class.new(object: nil, context: { current_user: current_user }, field: nil) + described_class.new(object: nil, context: query_context, field: nil) end describe '#resolve' do diff --git a/spec/graphql/mutations/ci/job_token_scope/add_project_spec.rb b/spec/graphql/mutations/ci/job_token_scope/add_project_spec.rb index 54da3061323322081d19cf63b9746ed44c8876ac..33ef691a77b0e8f918f0f8f2e90a12411d5ceb59 100644 --- a/spec/graphql/mutations/ci/job_token_scope/add_project_spec.rb +++ b/spec/graphql/mutations/ci/job_token_scope/add_project_spec.rb @@ -2,8 +2,10 @@ require 'spec_helper' RSpec.describe Mutations::Ci::JobTokenScope::AddProject, feature_category: :continuous_integration do + include GraphqlHelpers + let(:mutation) do - described_class.new(object: nil, context: { current_user: current_user }, field: nil) + described_class.new(object: nil, context: query_context, field: nil) end describe '#resolve' do diff --git a/spec/graphql/mutations/ci/job_token_scope/remove_group_spec.rb b/spec/graphql/mutations/ci/job_token_scope/remove_group_spec.rb index f17b34ba2d8374eb61ccd3f034a41a254a1f4bcc..2225c54e7727f0ce13b954a36c552d481db269d9 100644 --- a/spec/graphql/mutations/ci/job_token_scope/remove_group_spec.rb +++ b/spec/graphql/mutations/ci/job_token_scope/remove_group_spec.rb @@ -3,8 +3,10 @@ require 'spec_helper' RSpec.describe Mutations::Ci::JobTokenScope::RemoveGroup, feature_category: :continuous_integration do + include GraphqlHelpers + let(:mutation) do - described_class.new(object: nil, context: { current_user: current_user }, field: nil) + described_class.new(object: nil, context: query_context, field: nil) end describe '#resolve' do diff --git a/spec/graphql/mutations/ci/job_token_scope/remove_project_spec.rb b/spec/graphql/mutations/ci/job_token_scope/remove_project_spec.rb index 5385b6ca1cfd28d7b2e9db1de174a1c801557b14..f98ff5f47032bbd1d9afde5186ad9370ec12a27f 100644 --- a/spec/graphql/mutations/ci/job_token_scope/remove_project_spec.rb +++ b/spec/graphql/mutations/ci/job_token_scope/remove_project_spec.rb @@ -2,8 +2,10 @@ require 'spec_helper' RSpec.describe Mutations::Ci::JobTokenScope::RemoveProject, feature_category: :continuous_integration do + include GraphqlHelpers + let(:mutation) do - described_class.new(object: nil, context: { current_user: current_user }, field: nil) + described_class.new(object: nil, context: query_context, field: nil) end describe '#resolve' do diff --git a/spec/graphql/mutations/design_management/delete_spec.rb b/spec/graphql/mutations/design_management/delete_spec.rb index 1ab01c9cf4e0f09a459d1d632c007da9b8d50f4c..b9d933779a06c5bd3bb8d1b00a6b38a07607d55b 100644 --- a/spec/graphql/mutations/design_management/delete_spec.rb +++ b/spec/graphql/mutations/design_management/delete_spec.rb @@ -2,26 +2,27 @@ require 'spec_helper' -RSpec.describe Mutations::DesignManagement::Delete do +RSpec.describe Mutations::DesignManagement::Delete, feature_category: :api do include DesignManagementTestHelpers + include GraphqlHelpers let(:issue) { create(:issue) } let(:current_designs) { issue.designs.current } - let(:user) { issue.author } + let(:current_user) { issue.author } let(:project) { issue.project } let(:design_a) { create(:design, :with_file, issue: issue) } let(:design_b) { create(:design, :with_file, issue: issue) } let(:design_c) { create(:design, :with_file, issue: issue) } let(:filenames) { [design_a, design_b, design_c].map(&:filename) } - let(:mutation) { described_class.new(object: nil, context: { current_user: user }, field: nil) } + let(:mutation) { described_class.new(object: nil, context: context, field: nil) } before do stub_const('Errors', Gitlab::Graphql::Errors, transfer_nested_constants: true) end def run_mutation - mutation = described_class.new(object: nil, context: { current_user: user }, field: nil) + mutation = described_class.new(object: nil, context: query_context, field: nil) mutation.resolve(project_path: project.full_path, iid: issue.iid, filenames: filenames) end @@ -54,7 +55,7 @@ def run_mutation end context "when the user is not allowed to delete designs" do - let(:user) { create(:user) } + let(:current_user) { create(:user) } it_behaves_like "resource not available" end diff --git a/spec/graphql/mutations/design_management/move_spec.rb b/spec/graphql/mutations/design_management/move_spec.rb index c805dcc9389fc7dc5d64da31809ed4311489cdaa..1791002336d80f073f93ea07cafbd2b178deb1aa 100644 --- a/spec/graphql/mutations/design_management/move_spec.rb +++ b/spec/graphql/mutations/design_management/move_spec.rb @@ -2,16 +2,17 @@ require 'spec_helper' -RSpec.describe Mutations::DesignManagement::Move do +RSpec.describe Mutations::DesignManagement::Move, feature_category: :api do include DesignManagementTestHelpers + include GraphqlHelpers let_it_be(:issue) { create(:issue) } let_it_be(:designs) { create_list(:design, 3, issue: issue) } let_it_be(:developer) { create(:user, developer_of: issue.project) } - let(:user) { developer } + let(:current_user) { developer } - let(:mutation) { described_class.new(object: nil, context: { current_user: user }, field: nil) } + let(:mutation) { described_class.new(object: nil, context: query_context, field: nil) } let(:current_design) { designs.first } let(:previous_design) { designs.second } diff --git a/spec/graphql/mutations/design_management/upload_spec.rb b/spec/graphql/mutations/design_management/upload_spec.rb index 1a84d9c9b4a031fdd7bfbd15a7b4e21f712db150..27fed0ab24baea5373e85cc0c3dbedfd1c128791 100644 --- a/spec/graphql/mutations/design_management/upload_spec.rb +++ b/spec/graphql/mutations/design_management/upload_spec.rb @@ -1,20 +1,21 @@ # frozen_string_literal: true require 'spec_helper' -RSpec.describe Mutations::DesignManagement::Upload do +RSpec.describe Mutations::DesignManagement::Upload, feature_category: :api do include DesignManagementTestHelpers include ConcurrentHelpers + include GraphqlHelpers let(:issue) { create(:issue) } - let(:user) { issue.author } + let(:current_user) { issue.author } let(:project) { issue.project } subject(:mutation) do - described_class.new(object: nil, context: { current_user: user }, field: nil) + described_class.new(object: nil, context: query_context, field: nil) end def run_mutation(files_to_upload = files, project_path = project.full_path, iid = issue.iid) - mutation = described_class.new(object: nil, context: { current_user: user }, field: nil) + mutation = described_class.new(object: nil, context: query_context, field: nil) Gitlab::ExclusiveLease.skipping_transaction_check do mutation.resolve(project_path: project_path, iid: iid, files: files_to_upload) end @@ -87,8 +88,8 @@ def creates_designs(&block) describe 'running requests in parallel on different issues' do it 'does not cause errors' do creates_designs do - issues = create_list(:issue, files.size, author: user) - issues.each { |i| i.project.add_developer(user) } + issues = create_list(:issue, files.size, author: current_user) + issues.each { |i| i.project.add_developer(current_user) } blocks = files.zip(issues).map do |(f, i)| -> { run_mutation([f], i.project.full_path, i.iid) } end @@ -110,7 +111,7 @@ def creates_designs(&block) end context "when the user is not allowed to upload designs" do - let(:user) { create(:user) } + let(:current_user) { create(:user) } it_behaves_like "resource not available" end diff --git a/spec/support/helpers/graphql_helpers.rb b/spec/support/helpers/graphql_helpers.rb index 88124139454b349031f5f3e6d018f8ad736b5264..e208a5cb8ed399f64ad285ce21fa97fd8472aad9 100644 --- a/spec/support/helpers/graphql_helpers.rb +++ b/spec/support/helpers/graphql_helpers.rb @@ -167,6 +167,13 @@ def resolve_field( end end end + + # create a valid query context object + def query_context(user: current_user) + query = GraphQL::Query.new(empty_schema, document: nil, context: {}, variables: {}) + GraphQL::Query::Context.new(query: query, values: { current_user: user }) + end + # rubocop:enable Metrics/ParameterLists # Pros: diff --git a/spec/support/shared_examples/graphql/mutations/boards/update_list_shared_examples.rb b/spec/support/shared_examples/graphql/mutations/boards/update_list_shared_examples.rb index 4385cd519be8ed20a44ce63a503bde9444bfbc8b..dceb68ae10d507b2579e91c5776e44a306ec271e 100644 --- a/spec/support/shared_examples/graphql/mutations/boards/update_list_shared_examples.rb +++ b/spec/support/shared_examples/graphql/mutations/boards/update_list_shared_examples.rb @@ -1,8 +1,10 @@ # frozen_string_literal: true RSpec.shared_examples 'update board list mutation' do + include GraphqlHelpers + describe '#resolve' do - let(:mutation) { described_class.new(object: nil, context: { current_user: current_user }, field: nil) } + let(:mutation) { described_class.new(object: nil, context: query_context, field: nil) } let(:list_update_params) { { position: 1, collapsed: true } } subject { mutation.resolve(list: list, **list_update_params) } diff --git a/spec/support/shared_examples/graphql/mutations/boards_list_create_shared_examples.rb b/spec/support/shared_examples/graphql/mutations/boards_list_create_shared_examples.rb index eb58cb97a7524d3a2f543f5f441eaf5cd524ebac..3f31e40ab3a6dfe8d6c8a6d04600559294b6a7bb 100644 --- a/spec/support/shared_examples/graphql/mutations/boards_list_create_shared_examples.rb +++ b/spec/support/shared_examples/graphql/mutations/boards_list_create_shared_examples.rb @@ -5,9 +5,9 @@ RSpec.shared_examples 'board lists create mutation' do include GraphqlHelpers - let_it_be(:user) { create(:user) } + let_it_be(:current_user) { create(:user) } - let(:mutation) { described_class.new(object: nil, context: { current_user: user }, field: nil) } + let(:mutation) { described_class.new(object: nil, context: query_context, field: nil) } let(:list_create_params) { {} } subject { mutation.resolve(board_id: board.to_global_id, **list_create_params) } @@ -27,7 +27,7 @@ describe '#resolve' do context 'with proper permissions' do before_all do - group.add_reporter(user) + group.add_reporter(current_user) end describe 'backlog list' do @@ -76,7 +76,7 @@ context 'without proper permissions' do before_all do - group.add_guest(user) + group.add_guest(current_user) end it 'raises an error' do