diff options
Diffstat (limited to 'spec/graphql')
179 files changed, 1149 insertions, 216 deletions
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 a025b3d344a..f8b61c5064a 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,7 @@ require 'spec_helper' -describe Mutations::AlertManagement::Alerts::SetAssignees do +RSpec.describe Mutations::AlertManagement::Alerts::SetAssignees do 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]) } diff --git a/spec/graphql/mutations/alert_management/alerts/todo/create_spec.rb b/spec/graphql/mutations/alert_management/alerts/todo/create_spec.rb new file mode 100644 index 00000000000..11ee40a4c7e --- /dev/null +++ b/spec/graphql/mutations/alert_management/alerts/todo/create_spec.rb @@ -0,0 +1,58 @@ +# frozen_string_literal: true + +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) } + + let_it_be(:alert) { create(:alert_management_alert) } + let_it_be(:project) { alert.project } + let(:current_user) { project.owner } + + let(:args) { { project_path: project.full_path, iid: alert.iid } } + + specify { expect(described_class).to require_graphql_authorizations(:update_alert_management_alert) } + + describe '#resolve' do + subject(:resolve) { mutation.resolve(args) } + + context 'when user does not have permissions' do + let(:current_user) { nil } + + specify { expect { resolve }.to raise_error(Gitlab::Graphql::Errors::ResourceNotAvailable) } + end + + context 'when project is invalid' do + let(:args) { { project_path: 'bunk/path', iid: alert.iid } } + + specify { expect { resolve }.to raise_error(Gitlab::Graphql::Errors::ResourceNotAvailable) } + end + + context 'when alert is invalid' do + let(:args) { { project_path: project.full_path, iid: "-1" } } + + specify { expect { resolve }.to raise_error(Gitlab::Graphql::Errors::ResourceNotAvailable) } + end + + context 'when the create service yields errors' do + let(:error_response) { double(error?: true, message: 'error', payload: { alert: {} }) } + + before do + allow_next_instance_of(::AlertManagement::Alerts::Todo::CreateService) do |service| + allow(service).to receive(:execute).and_return(error_response) + end + end + + specify { expect { resolve }.not_to change(Todo, :count) } + specify { expect(resolve[:errors]).to eq([error_response.message]) } + end + + context 'with valid inputs' do + it 'creates a new todo' do + expect { resolve }.to change { Todo.where(user: current_user, action: Todo::MARKED).count }.by(1) + end + + it { is_expected.to eq(alert: alert, todo: Todo.last, errors: []) } + end + 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 68513c02040..a224b564de9 100644 --- a/spec/graphql/mutations/alert_management/update_alert_status_spec.rb +++ b/spec/graphql/mutations/alert_management/update_alert_status_spec.rb @@ -39,7 +39,7 @@ RSpec.describe Mutations::AlertManagement::UpdateAlertStatus do allow(alert).to receive(:save).and_return(false) allow(alert).to receive(:errors).and_return( - double(full_messages: %w(foo bar)) + double(full_messages: %w(foo bar), :[] => nil) ) expect(resolve).to eq( alert: alert, diff --git a/spec/graphql/mutations/concerns/mutations/resolves_issuable_spec.rb b/spec/graphql/mutations/concerns/mutations/resolves_issuable_spec.rb index 706a54931ea..8af3868ba98 100644 --- a/spec/graphql/mutations/concerns/mutations/resolves_issuable_spec.rb +++ b/spec/graphql/mutations/concerns/mutations/resolves_issuable_spec.rb @@ -3,26 +3,31 @@ require 'spec_helper' RSpec.describe Mutations::ResolvesIssuable do + include GraphqlHelpers + let_it_be(:mutation_class) do Class.new(Mutations::BaseMutation) do include Mutations::ResolvesIssuable end end - let_it_be(:project) { create(:project) } + let_it_be(:project) { create(:project, :empty_repo) } let_it_be(:user) { create(:user) } let_it_be(:context) { { current_user: user } } - let_it_be(:mutation) { mutation_class.new(object: nil, context: context, field: nil) } + let(:mutation) { mutation_class.new(object: nil, context: context, field: nil) } let(:parent) { issuable.project } + let_it_be(:issue) { create(:issue, project: project) } + let_it_be(:merge_request) { create(:merge_request, source_project: project) } + context 'with issues' do - let(:issuable) { create(:issue, project: project) } + let(:issuable) { issue } it_behaves_like 'resolving an issuable in GraphQL', :issue end context 'with merge requests' do - let(:issuable) { create(:merge_request, source_project: project) } + let(:issuable) { merge_request } it_behaves_like 'resolving an issuable in GraphQL', :merge_request end diff --git a/spec/graphql/mutations/container_expiration_policies/update_spec.rb b/spec/graphql/mutations/container_expiration_policies/update_spec.rb index fc90f437576..6aedaab3b53 100644 --- a/spec/graphql/mutations/container_expiration_policies/update_spec.rb +++ b/spec/graphql/mutations/container_expiration_policies/update_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Mutations::ContainerExpirationPolicies::Update do +RSpec.describe Mutations::ContainerExpirationPolicies::Update do using RSpec::Parameterized::TableSyntax let_it_be(:project, reload: true) { create(:project) } diff --git a/spec/graphql/mutations/issues/set_locked_spec.rb b/spec/graphql/mutations/issues/set_locked_spec.rb new file mode 100644 index 00000000000..10438226c17 --- /dev/null +++ b/spec/graphql/mutations/issues/set_locked_spec.rb @@ -0,0 +1,46 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Mutations::Issues::SetLocked do + let_it_be(:issue) { create(:issue) } + let_it_be(:user) { create(:user) } + + subject(:mutation) { described_class.new(object: nil, context: { current_user: user }, field: nil) } + + specify { expect(described_class).to require_graphql_authorizations(:update_issue) } + + describe '#resolve' do + let(:locked) { true } + + subject { mutation.resolve(project_path: issue.project.full_path, iid: issue.iid, locked: locked) } + + it 'raises an error if the resource is not accessible to the user' do + expect { subject }.to raise_error(Gitlab::Graphql::Errors::ResourceNotAvailable) + end + + context 'when the user can update the issue' do + let(:mutated_issue) { subject[:issue] } + + before do + issue.project.add_developer(user) + end + + it 'returns the issue as discussion locked' do + expect(mutated_issue).to eq(issue) + expect(mutated_issue).to be_discussion_locked + expect(subject[:errors]).to be_empty + end + + context 'when passing locked as false' do + let(:locked) { false } + + it 'unlocks the discussion' do + issue.update!(discussion_locked: true) + + expect(mutated_issue).not_to be_discussion_locked + end + end + end + end +end diff --git a/spec/graphql/mutations/issues/update_spec.rb b/spec/graphql/mutations/issues/update_spec.rb index 8c3d01918fd..9a847476e2e 100644 --- a/spec/graphql/mutations/issues/update_spec.rb +++ b/spec/graphql/mutations/issues/update_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Mutations::Issues::Update do +RSpec.describe Mutations::Issues::Update do let(:issue) { create(:issue) } let(:user) { create(:user) } let(:expected_attributes) do diff --git a/spec/graphql/mutations/merge_requests/create_spec.rb b/spec/graphql/mutations/merge_requests/create_spec.rb index 88acd3ed5b6..ae31790f1f9 100644 --- a/spec/graphql/mutations/merge_requests/create_spec.rb +++ b/spec/graphql/mutations/merge_requests/create_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Mutations::MergeRequests::Create do +RSpec.describe Mutations::MergeRequests::Create do subject(:mutation) { described_class.new(object: nil, context: context, field: nil) } let_it_be(:project) { create(:project, :public, :repository) } diff --git a/spec/graphql/mutations/merge_requests/set_assignees_spec.rb b/spec/graphql/mutations/merge_requests/set_assignees_spec.rb index d88c5db05c9..0e7abb849c4 100644 --- a/spec/graphql/mutations/merge_requests/set_assignees_spec.rb +++ b/spec/graphql/mutations/merge_requests/set_assignees_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Mutations::MergeRequests::SetAssignees do +RSpec.describe Mutations::MergeRequests::SetAssignees do let(:merge_request) { create(:merge_request) } let(:user) { create(:user) } diff --git a/spec/graphql/mutations/merge_requests/set_labels_spec.rb b/spec/graphql/mutations/merge_requests/set_labels_spec.rb index 0fd2c20a5c8..62a7f650f84 100644 --- a/spec/graphql/mutations/merge_requests/set_labels_spec.rb +++ b/spec/graphql/mutations/merge_requests/set_labels_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Mutations::MergeRequests::SetLabels do +RSpec.describe Mutations::MergeRequests::SetLabels do let(:merge_request) { create(:merge_request) } let(:user) { create(:user) } diff --git a/spec/graphql/mutations/merge_requests/set_locked_spec.rb b/spec/graphql/mutations/merge_requests/set_locked_spec.rb index d5219c781fd..aca7df5445f 100644 --- a/spec/graphql/mutations/merge_requests/set_locked_spec.rb +++ b/spec/graphql/mutations/merge_requests/set_locked_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Mutations::MergeRequests::SetLocked do +RSpec.describe Mutations::MergeRequests::SetLocked do let(:merge_request) { create(:merge_request) } let(:user) { create(:user) } diff --git a/spec/graphql/mutations/merge_requests/set_milestone_spec.rb b/spec/graphql/mutations/merge_requests/set_milestone_spec.rb index d77ec4de4d0..1c0d655ee83 100644 --- a/spec/graphql/mutations/merge_requests/set_milestone_spec.rb +++ b/spec/graphql/mutations/merge_requests/set_milestone_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Mutations::MergeRequests::SetMilestone do +RSpec.describe Mutations::MergeRequests::SetMilestone do let(:merge_request) { create(:merge_request) } let(:user) { create(:user) } diff --git a/spec/graphql/mutations/merge_requests/set_subscription_spec.rb b/spec/graphql/mutations/merge_requests/set_subscription_spec.rb index cf569a74aa9..20cfed9dd3d 100644 --- a/spec/graphql/mutations/merge_requests/set_subscription_spec.rb +++ b/spec/graphql/mutations/merge_requests/set_subscription_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Mutations::MergeRequests::SetSubscription do +RSpec.describe Mutations::MergeRequests::SetSubscription do let(:merge_request) { create(:merge_request) } let(:project) { merge_request.project } let(:user) { create(:user) } diff --git a/spec/graphql/mutations/merge_requests/set_wip_spec.rb b/spec/graphql/mutations/merge_requests/set_wip_spec.rb index 7255d0fe7d7..b6cb49724fa 100644 --- a/spec/graphql/mutations/merge_requests/set_wip_spec.rb +++ b/spec/graphql/mutations/merge_requests/set_wip_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Mutations::MergeRequests::SetWip do +RSpec.describe Mutations::MergeRequests::SetWip do let(:merge_request) { create(:merge_request) } let(:user) { create(:user) } diff --git a/spec/graphql/mutations/merge_requests/update_spec.rb b/spec/graphql/mutations/merge_requests/update_spec.rb new file mode 100644 index 00000000000..4a1fdf6e74b --- /dev/null +++ b/spec/graphql/mutations/merge_requests/update_spec.rb @@ -0,0 +1,68 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Mutations::MergeRequests::Update do + let(:merge_request) { create(:merge_request) } + let(:user) { create(:user) } + + subject(:mutation) { described_class.new(object: nil, context: { current_user: user }, field: nil) } + + specify { expect(described_class).to require_graphql_authorizations(:update_merge_request) } + + describe '#resolve' do + let(:attributes) { { title: 'new title', description: 'new description', target_branch: 'new-branch' } } + let(:mutated_merge_request) { subject[:merge_request] } + + subject do + mutation.resolve(project_path: merge_request.project.full_path, iid: merge_request.iid, **attributes) + end + + it 'raises an error if the resource is not accessible to the user' do + expect { subject }.to raise_error(Gitlab::Graphql::Errors::ResourceNotAvailable) + end + + context 'when the user can update the merge request' do + before do + merge_request.project.add_developer(user) + end + + it 'applies all attributes' do + expect(mutated_merge_request).to eq(merge_request) + expect(mutated_merge_request).to have_attributes(attributes) + expect(subject[:errors]).to be_empty + end + + context 'the merge request is invalid' do + before do + merge_request.allow_broken = true + merge_request.update!(source_project: nil) + end + + it 'returns error information, and changes were not applied' do + expect(mutated_merge_request).not_to have_attributes(attributes) + expect(subject[:errors]).not_to be_empty + end + end + + context 'our change is invalid' do + let(:attributes) { { target_branch: 'this is not a branch' } } + + it 'returns error information, and changes were not applied' do + expect(mutated_merge_request).not_to have_attributes(attributes) + expect(subject[:errors]).not_to be_empty + end + end + + context 'when passing subset of attributes' do + let(:attributes) { { title: 'no, this title' } } + + it 'only changes the mentioned attributes' do + expect { subject }.not_to change { merge_request.reset.description } + + expect(mutated_merge_request).to have_attributes(attributes) + end + end + end + end +end diff --git a/spec/graphql/mutations/todos/mark_all_done_spec.rb b/spec/graphql/mutations/todos/mark_all_done_spec.rb index 4af00307969..2f167164050 100644 --- a/spec/graphql/mutations/todos/mark_all_done_spec.rb +++ b/spec/graphql/mutations/todos/mark_all_done_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Mutations::Todos::MarkAllDone do +RSpec.describe Mutations::Todos::MarkAllDone do include GraphqlHelpers let_it_be(:current_user) { create(:user) } @@ -21,7 +21,7 @@ describe Mutations::Todos::MarkAllDone do describe '#resolve' do it 'marks all pending todos as done' do - updated_todo_ids = mutation_for(current_user).resolve.dig(:updated_ids) + updated_todo_ids, todos = mutation_for(current_user).resolve.values_at(:updated_ids, :todos) expect(todo1.reload.state).to eq('done') expect(todo2.reload.state).to eq('done') @@ -29,6 +29,7 @@ describe Mutations::Todos::MarkAllDone do expect(other_user_todo.reload.state).to eq('pending') expect(updated_todo_ids).to contain_exactly(global_id_of(todo1), global_id_of(todo3)) + expect(todos).to contain_exactly(todo1, todo3) end it 'behaves as expected if there are no todos for the requesting user' do diff --git a/spec/graphql/mutations/todos/mark_done_spec.rb b/spec/graphql/mutations/todos/mark_done_spec.rb index 44065f83f74..51ad3e1a5d7 100644 --- a/spec/graphql/mutations/todos/mark_done_spec.rb +++ b/spec/graphql/mutations/todos/mark_done_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Mutations::Todos::MarkDone do +RSpec.describe Mutations::Todos::MarkDone do include GraphqlHelpers let_it_be(:current_user) { create(:user) } diff --git a/spec/graphql/mutations/todos/restore_many_spec.rb b/spec/graphql/mutations/todos/restore_many_spec.rb index 8f4a8985f9e..b3b3e057745 100644 --- a/spec/graphql/mutations/todos/restore_many_spec.rb +++ b/spec/graphql/mutations/todos/restore_many_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Mutations::Todos::RestoreMany do +RSpec.describe Mutations::Todos::RestoreMany do let_it_be(:current_user) { create(:user) } let_it_be(:author) { create(:user) } let_it_be(:other_user) { create(:user) } @@ -25,6 +25,8 @@ describe Mutations::Todos::RestoreMany do todo_ids = result[:updated_ids] expect(todo_ids.size).to eq(1) expect(todo_ids.first).to eq(todo1.to_global_id.to_s) + + expect(result[:todos]).to contain_exactly(todo1) end it 'handles a todo which is already pending as expected' do @@ -33,6 +35,7 @@ describe Mutations::Todos::RestoreMany do expect_states_were_not_changed expect(result[:updated_ids]).to eq([]) + expect(result[:todos]).to be_empty end it 'ignores requests for todos which do not belong to the current user' do @@ -56,6 +59,7 @@ describe Mutations::Todos::RestoreMany do returned_todo_ids = result[:updated_ids] expect(returned_todo_ids).to contain_exactly(todo1.to_global_id.to_s, todo4.to_global_id.to_s) + expect(result[:todos]).to contain_exactly(todo1, todo4) expect(todo1.reload.state).to eq('pending') expect(todo2.reload.state).to eq('pending') diff --git a/spec/graphql/mutations/todos/restore_spec.rb b/spec/graphql/mutations/todos/restore_spec.rb index 949ab6a164b..9043d7a44a8 100644 --- a/spec/graphql/mutations/todos/restore_spec.rb +++ b/spec/graphql/mutations/todos/restore_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Mutations::Todos::Restore do +RSpec.describe Mutations::Todos::Restore do let_it_be(:current_user) { create(:user) } let_it_be(:author) { create(:user) } let_it_be(:other_user) { create(:user) } diff --git a/spec/graphql/resolvers/alert_management/alert_resolver_spec.rb b/spec/graphql/resolvers/alert_management/alert_resolver_spec.rb index 6c12f765e69..0c1ba5aab2c 100644 --- a/spec/graphql/resolvers/alert_management/alert_resolver_spec.rb +++ b/spec/graphql/resolvers/alert_management/alert_resolver_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Resolvers::AlertManagement::AlertResolver do +RSpec.describe Resolvers::AlertManagement::AlertResolver do include GraphqlHelpers let_it_be(:current_user) { create(:user) } diff --git a/spec/graphql/resolvers/alert_management/alert_status_counts_resolver_spec.rb b/spec/graphql/resolvers/alert_management/alert_status_counts_resolver_spec.rb index 8eb28c8c945..b72e692f2e8 100644 --- a/spec/graphql/resolvers/alert_management/alert_status_counts_resolver_spec.rb +++ b/spec/graphql/resolvers/alert_management/alert_status_counts_resolver_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Resolvers::AlertManagement::AlertStatusCountsResolver do +RSpec.describe Resolvers::AlertManagement::AlertStatusCountsResolver do include GraphqlHelpers describe '#resolve' do diff --git a/spec/graphql/resolvers/base_resolver_spec.rb b/spec/graphql/resolvers/base_resolver_spec.rb index 6c384349577..40dc2370052 100644 --- a/spec/graphql/resolvers/base_resolver_spec.rb +++ b/spec/graphql/resolvers/base_resolver_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Resolvers::BaseResolver do +RSpec.describe Resolvers::BaseResolver do include GraphqlHelpers let(:resolver) do diff --git a/spec/graphql/resolvers/board_lists_resolver_spec.rb b/spec/graphql/resolvers/board_lists_resolver_spec.rb index 5f6c440a8ed..f662e9a0f62 100644 --- a/spec/graphql/resolvers/board_lists_resolver_spec.rb +++ b/spec/graphql/resolvers/board_lists_resolver_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Resolvers::BoardListsResolver do +RSpec.describe Resolvers::BoardListsResolver do include GraphqlHelpers let_it_be(:user) { create(:user) } diff --git a/spec/graphql/resolvers/boards_resolver_spec.rb b/spec/graphql/resolvers/boards_resolver_spec.rb index 02d6f808118..f121e8a4083 100644 --- a/spec/graphql/resolvers/boards_resolver_spec.rb +++ b/spec/graphql/resolvers/boards_resolver_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Resolvers::BoardsResolver do +RSpec.describe Resolvers::BoardsResolver do include GraphqlHelpers let_it_be(:user) { create(:user) } diff --git a/spec/graphql/resolvers/branch_commit_resolver_spec.rb b/spec/graphql/resolvers/branch_commit_resolver_spec.rb index 22e1de8f375..78d4959c3f9 100644 --- a/spec/graphql/resolvers/branch_commit_resolver_spec.rb +++ b/spec/graphql/resolvers/branch_commit_resolver_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Resolvers::BranchCommitResolver do +RSpec.describe Resolvers::BranchCommitResolver do include GraphqlHelpers subject(:commit) { resolve(described_class, obj: branch) } diff --git a/spec/graphql/resolvers/ci_configuration/sast_resolver_spec.rb b/spec/graphql/resolvers/ci_configuration/sast_resolver_spec.rb new file mode 100644 index 00000000000..de69ad5d450 --- /dev/null +++ b/spec/graphql/resolvers/ci_configuration/sast_resolver_spec.rb @@ -0,0 +1,28 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Resolvers::CiConfiguration::SastResolver do + include GraphqlHelpers + + let_it_be(:user) { create(:user) } + let_it_be(:project) { create(:project) } + + describe '#resolve' do + subject(:sast_config) { resolve(described_class, ctx: { current_user: user }, obj: project) } + + it 'returns global variable informations related to SAST' do + expect(sast_config['global'].first['field']).to eql("SECURE_ANALYZERS_PREFIX") + expect(sast_config['global'].first['label']).to eql("Image prefix") + expect(sast_config['global'].first['type']).to eql("string") + + expect(sast_config['pipeline'].first['field']).to eql("stage") + expect(sast_config['pipeline'].first['label']).to eql("Stage") + expect(sast_config['pipeline'].first['type']).to eql("dropdown") + + expect(sast_config['analyzers'].first['name']).to eql("brakeman") + expect(sast_config['analyzers'].first['label']).to eql("Brakeman") + expect(sast_config['analyzers'].first['enabled']).to be true + end + end +end diff --git a/spec/graphql/resolvers/commit_pipelines_resolver_spec.rb b/spec/graphql/resolvers/commit_pipelines_resolver_spec.rb index 93da877d714..20a0cb842a4 100644 --- a/spec/graphql/resolvers/commit_pipelines_resolver_spec.rb +++ b/spec/graphql/resolvers/commit_pipelines_resolver_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Resolvers::CommitPipelinesResolver do +RSpec.describe Resolvers::CommitPipelinesResolver do include GraphqlHelpers let_it_be(:project) { create(:project) } diff --git a/spec/graphql/resolvers/concerns/looks_ahead_spec.rb b/spec/graphql/resolvers/concerns/looks_ahead_spec.rb index 8b83f887846..f13823085b8 100644 --- a/spec/graphql/resolvers/concerns/looks_ahead_spec.rb +++ b/spec/graphql/resolvers/concerns/looks_ahead_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe LooksAhead do +RSpec.describe LooksAhead do include GraphqlHelpers let_it_be(:the_user) { create(:user) } diff --git a/spec/graphql/resolvers/concerns/resolves_pipelines_spec.rb b/spec/graphql/resolvers/concerns/resolves_pipelines_spec.rb index 03ff1e11d85..3dffda75e08 100644 --- a/spec/graphql/resolvers/concerns/resolves_pipelines_spec.rb +++ b/spec/graphql/resolvers/concerns/resolves_pipelines_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe ResolvesPipelines do +RSpec.describe ResolvesPipelines do include GraphqlHelpers subject(:resolver) do diff --git a/spec/graphql/resolvers/concerns/resolves_project_spec.rb b/spec/graphql/resolvers/concerns/resolves_project_spec.rb index f29f54483d6..1748d8a81a3 100644 --- a/spec/graphql/resolvers/concerns/resolves_project_spec.rb +++ b/spec/graphql/resolvers/concerns/resolves_project_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe ResolvesProject do +RSpec.describe ResolvesProject do include GraphqlHelpers let(:implementing_class) do diff --git a/spec/graphql/resolvers/design_management/design_at_version_resolver_spec.rb b/spec/graphql/resolvers/design_management/design_at_version_resolver_spec.rb index a5054ae3ebf..4bdef49499c 100644 --- a/spec/graphql/resolvers/design_management/design_at_version_resolver_spec.rb +++ b/spec/graphql/resolvers/design_management/design_at_version_resolver_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Resolvers::DesignManagement::DesignAtVersionResolver do +RSpec.describe Resolvers::DesignManagement::DesignAtVersionResolver do include GraphqlHelpers include DesignManagementTestHelpers diff --git a/spec/graphql/resolvers/design_management/design_resolver_spec.rb b/spec/graphql/resolvers/design_management/design_resolver_spec.rb index 857acc3d371..02d7f94612c 100644 --- a/spec/graphql/resolvers/design_management/design_resolver_spec.rb +++ b/spec/graphql/resolvers/design_management/design_resolver_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Resolvers::DesignManagement::DesignResolver do +RSpec.describe Resolvers::DesignManagement::DesignResolver do include GraphqlHelpers include DesignManagementTestHelpers diff --git a/spec/graphql/resolvers/design_management/designs_resolver_spec.rb b/spec/graphql/resolvers/design_management/designs_resolver_spec.rb index 28fc9e2151d..cfa37d34fd9 100644 --- a/spec/graphql/resolvers/design_management/designs_resolver_spec.rb +++ b/spec/graphql/resolvers/design_management/designs_resolver_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Resolvers::DesignManagement::DesignsResolver do +RSpec.describe Resolvers::DesignManagement::DesignsResolver do include GraphqlHelpers include DesignManagementTestHelpers diff --git a/spec/graphql/resolvers/design_management/version/design_at_version_resolver_spec.rb b/spec/graphql/resolvers/design_management/version/design_at_version_resolver_spec.rb index cc9c0436885..850b9f8cc87 100644 --- a/spec/graphql/resolvers/design_management/version/design_at_version_resolver_spec.rb +++ b/spec/graphql/resolvers/design_management/version/design_at_version_resolver_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Resolvers::DesignManagement::Version::DesignAtVersionResolver do +RSpec.describe Resolvers::DesignManagement::Version::DesignAtVersionResolver do include GraphqlHelpers include_context 'four designs in three versions' diff --git a/spec/graphql/resolvers/design_management/version/designs_at_version_resolver_spec.rb b/spec/graphql/resolvers/design_management/version/designs_at_version_resolver_spec.rb index 123b26862d0..c038216ce0b 100644 --- a/spec/graphql/resolvers/design_management/version/designs_at_version_resolver_spec.rb +++ b/spec/graphql/resolvers/design_management/version/designs_at_version_resolver_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Resolvers::DesignManagement::Version::DesignsAtVersionResolver do +RSpec.describe Resolvers::DesignManagement::Version::DesignsAtVersionResolver do include GraphqlHelpers include_context 'four designs in three versions' diff --git a/spec/graphql/resolvers/design_management/version_in_collection_resolver_spec.rb b/spec/graphql/resolvers/design_management/version_in_collection_resolver_spec.rb index ef50598d241..8ad928e9854 100644 --- a/spec/graphql/resolvers/design_management/version_in_collection_resolver_spec.rb +++ b/spec/graphql/resolvers/design_management/version_in_collection_resolver_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Resolvers::DesignManagement::VersionInCollectionResolver do +RSpec.describe Resolvers::DesignManagement::VersionInCollectionResolver do include GraphqlHelpers include DesignManagementTestHelpers diff --git a/spec/graphql/resolvers/design_management/version_resolver_spec.rb b/spec/graphql/resolvers/design_management/version_resolver_spec.rb index e7c09351204..af1e6a73d09 100644 --- a/spec/graphql/resolvers/design_management/version_resolver_spec.rb +++ b/spec/graphql/resolvers/design_management/version_resolver_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Resolvers::DesignManagement::VersionResolver do +RSpec.describe Resolvers::DesignManagement::VersionResolver do include GraphqlHelpers include DesignManagementTestHelpers diff --git a/spec/graphql/resolvers/design_management/versions_resolver_spec.rb b/spec/graphql/resolvers/design_management/versions_resolver_spec.rb index d5bab025e45..5bc1c555e9a 100644 --- a/spec/graphql/resolvers/design_management/versions_resolver_spec.rb +++ b/spec/graphql/resolvers/design_management/versions_resolver_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Resolvers::DesignManagement::VersionsResolver do +RSpec.describe Resolvers::DesignManagement::VersionsResolver do include GraphqlHelpers include DesignManagementTestHelpers diff --git a/spec/graphql/resolvers/echo_resolver_spec.rb b/spec/graphql/resolvers/echo_resolver_spec.rb index 466501a4227..2182ac221f6 100644 --- a/spec/graphql/resolvers/echo_resolver_spec.rb +++ b/spec/graphql/resolvers/echo_resolver_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Resolvers::EchoResolver do +RSpec.describe Resolvers::EchoResolver do include GraphqlHelpers let(:current_user) { create(:user) } diff --git a/spec/graphql/resolvers/environments_resolver_spec.rb b/spec/graphql/resolvers/environments_resolver_spec.rb index 75fd7aff39c..6c999e5d0e7 100644 --- a/spec/graphql/resolvers/environments_resolver_spec.rb +++ b/spec/graphql/resolvers/environments_resolver_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Resolvers::EnvironmentsResolver do +RSpec.describe Resolvers::EnvironmentsResolver do include GraphqlHelpers let_it_be(:current_user) { create(:user) } diff --git a/spec/graphql/resolvers/error_tracking/sentry_detailed_error_resolver_spec.rb b/spec/graphql/resolvers/error_tracking/sentry_detailed_error_resolver_spec.rb index 8b2e33cdfda..7e531910184 100644 --- a/spec/graphql/resolvers/error_tracking/sentry_detailed_error_resolver_spec.rb +++ b/spec/graphql/resolvers/error_tracking/sentry_detailed_error_resolver_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Resolvers::ErrorTracking::SentryDetailedErrorResolver do +RSpec.describe Resolvers::ErrorTracking::SentryDetailedErrorResolver do include GraphqlHelpers let_it_be(:project) { create(:project) } diff --git a/spec/graphql/resolvers/error_tracking/sentry_error_collection_resolver_spec.rb b/spec/graphql/resolvers/error_tracking/sentry_error_collection_resolver_spec.rb index 3bb8a5c389d..02e0420be2a 100644 --- a/spec/graphql/resolvers/error_tracking/sentry_error_collection_resolver_spec.rb +++ b/spec/graphql/resolvers/error_tracking/sentry_error_collection_resolver_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Resolvers::ErrorTracking::SentryErrorCollectionResolver do +RSpec.describe Resolvers::ErrorTracking::SentryErrorCollectionResolver do include GraphqlHelpers let_it_be(:project) { create(:project) } diff --git a/spec/graphql/resolvers/error_tracking/sentry_errors_resolver_spec.rb b/spec/graphql/resolvers/error_tracking/sentry_errors_resolver_spec.rb index 93f89d077d7..554873a6e21 100644 --- a/spec/graphql/resolvers/error_tracking/sentry_errors_resolver_spec.rb +++ b/spec/graphql/resolvers/error_tracking/sentry_errors_resolver_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Resolvers::ErrorTracking::SentryErrorsResolver do +RSpec.describe Resolvers::ErrorTracking::SentryErrorsResolver do include GraphqlHelpers let_it_be(:project) { create(:project) } diff --git a/spec/graphql/resolvers/group_resolver_spec.rb b/spec/graphql/resolvers/group_resolver_spec.rb index 70b1102d363..a03e7854177 100644 --- a/spec/graphql/resolvers/group_resolver_spec.rb +++ b/spec/graphql/resolvers/group_resolver_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Resolvers::GroupResolver do +RSpec.describe Resolvers::GroupResolver do include GraphqlHelpers let_it_be(:group1) { create(:group) } diff --git a/spec/graphql/resolvers/issues_resolver_spec.rb b/spec/graphql/resolvers/issues_resolver_spec.rb index b7cc9bc6d71..eb17e94a450 100644 --- a/spec/graphql/resolvers/issues_resolver_spec.rb +++ b/spec/graphql/resolvers/issues_resolver_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Resolvers::IssuesResolver do +RSpec.describe Resolvers::IssuesResolver do include GraphqlHelpers let(:current_user) { create(:user) } @@ -101,12 +101,10 @@ describe Resolvers::IssuesResolver do end it 'uses project search optimization' do - expected_arguments = { + expected_arguments = a_hash_including( search: 'foo', - attempt_project_search_optimizations: true, - iids: [], - project_id: project.id - } + attempt_project_search_optimizations: true + ) expect(IssuesFinder).to receive(:new).with(anything, expected_arguments).and_call_original resolve_issues(search: 'foo') @@ -217,16 +215,32 @@ describe Resolvers::IssuesResolver do expect(resolve_issues).to contain_exactly(issue1, issue2) end - it 'finds a specific issue with iid' do - expect(resolve_issues(iid: issue1.iid)).to contain_exactly(issue1) + it 'finds a specific issue with iid', :request_store do + result = batch_sync(max_queries: 2) { resolve_issues(iid: issue1.iid) } + + expect(result).to contain_exactly(issue1) + end + + it 'batches queries that only include IIDs', :request_store do + result = batch_sync(max_queries: 2) do + resolve_issues(iid: issue1.iid) + resolve_issues(iids: issue2.iid) + end + + expect(result).to contain_exactly(issue1, issue2) end - it 'finds a specific issue with iids' do - expect(resolve_issues(iids: issue1.iid)).to contain_exactly(issue1) + it 'finds a specific issue with iids', :request_store do + result = batch_sync(max_queries: 2) do + resolve_issues(iids: [issue1.iid]) + end + + expect(result).to contain_exactly(issue1) end it 'finds multiple issues with iids' do - expect(resolve_issues(iids: [issue1.iid, issue2.iid])) + create(:issue, project: project, author: current_user) + + expect(batch_sync { resolve_issues(iids: [issue1.iid, issue2.iid]) }) .to contain_exactly(issue1, issue2) end @@ -238,7 +252,7 @@ describe Resolvers::IssuesResolver do create(:issue, project: another_project, iid: iid) end - expect(resolve_issues(iids: iids)).to contain_exactly(issue1, issue2) + expect(batch_sync { resolve_issues(iids: iids) }).to contain_exactly(issue1, issue2) end end end diff --git a/spec/graphql/resolvers/last_commit_resolver_spec.rb b/spec/graphql/resolvers/last_commit_resolver_spec.rb index 15b09b77a10..5ac6ad59864 100644 --- a/spec/graphql/resolvers/last_commit_resolver_spec.rb +++ b/spec/graphql/resolvers/last_commit_resolver_spec.rb @@ -2,10 +2,12 @@ require 'spec_helper' -describe Resolvers::LastCommitResolver do +RSpec.describe Resolvers::LastCommitResolver do include GraphqlHelpers + include RepoHelpers - let(:repository) { create(:project, :repository).repository } + let(:project) { create(:project, :repository) } + let(:repository) { project.repository } let(:tree) { repository.tree(ref, path) } let(:commit) { resolve(described_class, obj: tree) } @@ -29,6 +31,28 @@ describe Resolvers::LastCommitResolver do end end + context 'last commit for a wildcard pathspec' do + let(:ref) { 'fix' } + let(:path) { 'files/*' } + + it 'returns nil' do + expect(commit).to be_nil + end + end + + context 'last commit with pathspec characters' do + let(:ref) { 'fix' } + let(:path) { ':wq' } + + before do + create_file_in_repo(project, ref, ref, path, 'Test file') + end + + it 'resolves commit' do + expect(commit).to eq(repository.commits(ref, path: path, limit: 1).last) + end + end + context 'last commit does not exist' do let(:ref) { 'master' } let(:path) { 'does-not-exist' } diff --git a/spec/graphql/resolvers/merge_request_pipelines_resolver_spec.rb b/spec/graphql/resolvers/merge_request_pipelines_resolver_spec.rb index b894dce3e17..2fe3e86ec14 100644 --- a/spec/graphql/resolvers/merge_request_pipelines_resolver_spec.rb +++ b/spec/graphql/resolvers/merge_request_pipelines_resolver_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Resolvers::MergeRequestPipelinesResolver do +RSpec.describe Resolvers::MergeRequestPipelinesResolver do include GraphqlHelpers let_it_be(:merge_request) { create(:merge_request) } diff --git a/spec/graphql/resolvers/merge_requests_resolver_spec.rb b/spec/graphql/resolvers/merge_requests_resolver_spec.rb index 6ff7e1ecac6..0a8fd82613a 100644 --- a/spec/graphql/resolvers/merge_requests_resolver_spec.rb +++ b/spec/graphql/resolvers/merge_requests_resolver_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Resolvers::MergeRequestsResolver do +RSpec.describe Resolvers::MergeRequestsResolver do include GraphqlHelpers let_it_be(:project) { create(:project, :repository) } @@ -22,9 +22,12 @@ describe Resolvers::MergeRequestsResolver do before do project.add_developer(current_user) + other_project.add_developer(current_user) end describe '#resolve' do + let(:queries_per_project) { 3 } + context 'no arguments' do it 'returns all merge requests' do result = resolve_mr(project, {}) @@ -40,24 +43,34 @@ describe Resolvers::MergeRequestsResolver do end context 'by iid alone' do - it 'batch-resolves by target project full path and individual IID' do - result = batch_sync(max_queries: 2) do + it 'batch-resolves by target project full path and individual IID', :request_store do + # 1 query for project_authorizations, and 1 for merge_requests + result = batch_sync(max_queries: queries_per_project) do [iid_1, iid_2].map { |iid| resolve_mr_single(project, iid) } end expect(result).to contain_exactly(merge_request_1, merge_request_2) end - it 'batch-resolves by target project full path and IIDS' do - result = batch_sync(max_queries: 2) do + it 'batch-resolves by target project full path and IIDS', :request_store do + result = batch_sync(max_queries: queries_per_project) do resolve_mr(project, iids: [iid_1, iid_2]) end expect(result).to contain_exactly(merge_request_1, merge_request_2) end + it 'batch-resolves by target project full path and IIDS, single or plural', :request_store do + result = batch_sync(max_queries: queries_per_project) do + [resolve_mr_single(project, merge_request_3.iid), *resolve_mr(project, iids: [iid_1, iid_2])] + end + + expect(result).to contain_exactly(merge_request_1, merge_request_2, merge_request_3) + end + it 'can batch-resolve merge requests from different projects' do - result = batch_sync(max_queries: 3) do + # 2 queries for project_authorizations, and 2 for merge_requests + result = batch_sync(max_queries: queries_per_project * 2) do resolve_mr(project, iids: iid_1) + resolve_mr(project, iids: iid_2) + resolve_mr(other_project, iids: other_iid) diff --git a/spec/graphql/resolvers/metadata_resolver_spec.rb b/spec/graphql/resolvers/metadata_resolver_spec.rb index afff9eabb97..20556941de4 100644 --- a/spec/graphql/resolvers/metadata_resolver_spec.rb +++ b/spec/graphql/resolvers/metadata_resolver_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Resolvers::MetadataResolver do +RSpec.describe Resolvers::MetadataResolver do include GraphqlHelpers describe '#resolve' do diff --git a/spec/graphql/resolvers/metrics/dashboard_resolver_spec.rb b/spec/graphql/resolvers/metrics/dashboard_resolver_spec.rb index 6a8eb8a65af..4112e3d4fe6 100644 --- a/spec/graphql/resolvers/metrics/dashboard_resolver_spec.rb +++ b/spec/graphql/resolvers/metrics/dashboard_resolver_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Resolvers::Metrics::DashboardResolver do +RSpec.describe Resolvers::Metrics::DashboardResolver do include GraphqlHelpers let_it_be(:current_user) { create(:user) } diff --git a/spec/graphql/resolvers/metrics/dashboards/annotation_resolver_spec.rb b/spec/graphql/resolvers/metrics/dashboards/annotation_resolver_spec.rb index c06fbef53b6..f90869c52bc 100644 --- a/spec/graphql/resolvers/metrics/dashboards/annotation_resolver_spec.rb +++ b/spec/graphql/resolvers/metrics/dashboards/annotation_resolver_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Resolvers::Metrics::Dashboards::AnnotationResolver do +RSpec.describe Resolvers::Metrics::Dashboards::AnnotationResolver do include GraphqlHelpers describe '#resolve' do diff --git a/spec/graphql/resolvers/milestone_resolver_spec.rb b/spec/graphql/resolvers/milestone_resolver_spec.rb index 8e2c67fdc03..36dd5ef03e2 100644 --- a/spec/graphql/resolvers/milestone_resolver_spec.rb +++ b/spec/graphql/resolvers/milestone_resolver_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Resolvers::MilestoneResolver do +RSpec.describe Resolvers::MilestoneResolver do include GraphqlHelpers describe '#resolve' do diff --git a/spec/graphql/resolvers/namespace_projects_resolver_spec.rb b/spec/graphql/resolvers/namespace_projects_resolver_spec.rb index 639cc69650b..699269b47e0 100644 --- a/spec/graphql/resolvers/namespace_projects_resolver_spec.rb +++ b/spec/graphql/resolvers/namespace_projects_resolver_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Resolvers::NamespaceProjectsResolver do +RSpec.describe Resolvers::NamespaceProjectsResolver do include GraphqlHelpers let(:current_user) { create(:user) } diff --git a/spec/graphql/resolvers/packages_resolver_spec.rb b/spec/graphql/resolvers/packages_resolver_spec.rb new file mode 100644 index 00000000000..9aec2c7e036 --- /dev/null +++ b/spec/graphql/resolvers/packages_resolver_spec.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Resolvers::PackagesResolver do + include GraphqlHelpers + + let_it_be(:user) { create(:user) } + let_it_be(:project) { create(:project) } + let_it_be(:package) { create(:package, project: project) } + + describe '#resolve' do + subject(:packages) { resolve(described_class, ctx: { current_user: user }, obj: project) } + + it { is_expected.to contain_exactly(package) } + end +end diff --git a/spec/graphql/resolvers/project_members_resolver_spec.rb b/spec/graphql/resolvers/project_members_resolver_spec.rb index 3209838850b..602225cf632 100644 --- a/spec/graphql/resolvers/project_members_resolver_spec.rb +++ b/spec/graphql/resolvers/project_members_resolver_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Resolvers::ProjectMembersResolver do +RSpec.describe Resolvers::ProjectMembersResolver do include GraphqlHelpers context "with a group" do diff --git a/spec/graphql/resolvers/project_pipeline_resolver_spec.rb b/spec/graphql/resolvers/project_pipeline_resolver_spec.rb index 72049f16d7d..a659b3bdb6e 100644 --- a/spec/graphql/resolvers/project_pipeline_resolver_spec.rb +++ b/spec/graphql/resolvers/project_pipeline_resolver_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Resolvers::ProjectPipelineResolver do +RSpec.describe Resolvers::ProjectPipelineResolver do include GraphqlHelpers let_it_be(:project) { create(:project) } diff --git a/spec/graphql/resolvers/project_pipelines_resolver_spec.rb b/spec/graphql/resolvers/project_pipelines_resolver_spec.rb index 2a14796fdfa..b2e8fed2441 100644 --- a/spec/graphql/resolvers/project_pipelines_resolver_spec.rb +++ b/spec/graphql/resolvers/project_pipelines_resolver_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Resolvers::ProjectPipelinesResolver do +RSpec.describe Resolvers::ProjectPipelinesResolver do include GraphqlHelpers let_it_be(:project) { create(:project) } diff --git a/spec/graphql/resolvers/project_resolver_spec.rb b/spec/graphql/resolvers/project_resolver_spec.rb index e9e38353156..72a01b1c574 100644 --- a/spec/graphql/resolvers/project_resolver_spec.rb +++ b/spec/graphql/resolvers/project_resolver_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Resolvers::ProjectResolver do +RSpec.describe Resolvers::ProjectResolver do include GraphqlHelpers let_it_be(:project1) { create(:project) } diff --git a/spec/graphql/resolvers/projects/grafana_integration_resolver_spec.rb b/spec/graphql/resolvers/projects/grafana_integration_resolver_spec.rb index 416a90a841f..854e763fbdd 100644 --- a/spec/graphql/resolvers/projects/grafana_integration_resolver_spec.rb +++ b/spec/graphql/resolvers/projects/grafana_integration_resolver_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Resolvers::Projects::GrafanaIntegrationResolver do +RSpec.describe Resolvers::Projects::GrafanaIntegrationResolver do include GraphqlHelpers let_it_be(:project) { create(:project) } diff --git a/spec/graphql/resolvers/projects/jira_imports_resolver_spec.rb b/spec/graphql/resolvers/projects/jira_imports_resolver_spec.rb index 9811075a613..0775c1c31d1 100644 --- a/spec/graphql/resolvers/projects/jira_imports_resolver_spec.rb +++ b/spec/graphql/resolvers/projects/jira_imports_resolver_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Resolvers::Projects::JiraImportsResolver do +RSpec.describe Resolvers::Projects::JiraImportsResolver do include GraphqlHelpers describe '#resolve' do diff --git a/spec/graphql/resolvers/projects/jira_projects_resolver_spec.rb b/spec/graphql/resolvers/projects/jira_projects_resolver_spec.rb index 364e2aa6ca8..4038bcb3e5d 100644 --- a/spec/graphql/resolvers/projects/jira_projects_resolver_spec.rb +++ b/spec/graphql/resolvers/projects/jira_projects_resolver_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Resolvers::Projects::JiraProjectsResolver do +RSpec.describe Resolvers::Projects::JiraProjectsResolver do include GraphqlHelpers describe '#resolve' do @@ -63,7 +63,7 @@ describe Resolvers::Projects::JiraProjectsResolver do context 'when Jira connection is not valid' do before do - WebMock.stub_request(:get, 'https://jira.example.com/rest/api/2/project/search?maxResults=50&query=&startAt=0') + WebMock.stub_request(:get, 'https://jira.example.com/rest/api/2/project') .to_raise(JIRA::HTTPError.new(double(message: 'Some failure.'))) end diff --git a/spec/graphql/resolvers/projects/services_resolver_spec.rb b/spec/graphql/resolvers/projects/services_resolver_spec.rb index 00045442ea0..8b6eff9e8b6 100644 --- a/spec/graphql/resolvers/projects/services_resolver_spec.rb +++ b/spec/graphql/resolvers/projects/services_resolver_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Resolvers::Projects::ServicesResolver do +RSpec.describe Resolvers::Projects::ServicesResolver do include GraphqlHelpers describe '#resolve' do diff --git a/spec/graphql/resolvers/projects/snippets_resolver_spec.rb b/spec/graphql/resolvers/projects/snippets_resolver_spec.rb index 6d301b1c742..b4a5eb8ddb0 100644 --- a/spec/graphql/resolvers/projects/snippets_resolver_spec.rb +++ b/spec/graphql/resolvers/projects/snippets_resolver_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Resolvers::Projects::SnippetsResolver do +RSpec.describe Resolvers::Projects::SnippetsResolver do include GraphqlHelpers describe '#resolve' do diff --git a/spec/graphql/resolvers/projects_resolver_spec.rb b/spec/graphql/resolvers/projects_resolver_spec.rb index 73ff99a2520..db7c9225c84 100644 --- a/spec/graphql/resolvers/projects_resolver_spec.rb +++ b/spec/graphql/resolvers/projects_resolver_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Resolvers::ProjectsResolver do +RSpec.describe Resolvers::ProjectsResolver do include GraphqlHelpers describe '#resolve' do diff --git a/spec/graphql/resolvers/release_resolver_spec.rb b/spec/graphql/resolvers/release_resolver_spec.rb index 71aa4bbb439..666d54fbc3c 100644 --- a/spec/graphql/resolvers/release_resolver_spec.rb +++ b/spec/graphql/resolvers/release_resolver_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Resolvers::ReleaseResolver do +RSpec.describe Resolvers::ReleaseResolver do include GraphqlHelpers let_it_be(:project) { create(:project, :private) } diff --git a/spec/graphql/resolvers/releases_resolver_spec.rb b/spec/graphql/resolvers/releases_resolver_spec.rb index 9de539b417a..ee8b33fc748 100644 --- a/spec/graphql/resolvers/releases_resolver_spec.rb +++ b/spec/graphql/resolvers/releases_resolver_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Resolvers::ReleasesResolver do +RSpec.describe Resolvers::ReleasesResolver do include GraphqlHelpers let_it_be(:project) { create(:project, :private) } diff --git a/spec/graphql/resolvers/snippets_resolver_spec.rb b/spec/graphql/resolvers/snippets_resolver_spec.rb index 89c350020f0..180be8e8624 100644 --- a/spec/graphql/resolvers/snippets_resolver_spec.rb +++ b/spec/graphql/resolvers/snippets_resolver_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Resolvers::SnippetsResolver do +RSpec.describe Resolvers::SnippetsResolver do include GraphqlHelpers describe '#resolve' do diff --git a/spec/graphql/resolvers/todo_resolver_spec.rb b/spec/graphql/resolvers/todo_resolver_spec.rb index 5a09ec40e64..0775cb8dae7 100644 --- a/spec/graphql/resolvers/todo_resolver_spec.rb +++ b/spec/graphql/resolvers/todo_resolver_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Resolvers::TodoResolver do +RSpec.describe Resolvers::TodoResolver do include GraphqlHelpers describe '#resolve' do @@ -10,9 +10,9 @@ describe Resolvers::TodoResolver do let_it_be(:author1) { create(:user) } let_it_be(:author2) { create(:user) } - let_it_be(:todo1) { create(:todo, user: current_user, target_type: 'MergeRequest', state: :pending, action: Todo::MENTIONED, author: author1) } - let_it_be(:todo2) { create(:todo, user: current_user, state: :done, action: Todo::ASSIGNED, author: author2) } - let_it_be(:todo3) { create(:todo, user: current_user, state: :pending, action: Todo::ASSIGNED, author: author1) } + let_it_be(:merge_request_todo_pending) { create(:todo, user: current_user, target_type: 'MergeRequest', state: :pending, action: Todo::MENTIONED, author: author1) } + let_it_be(:issue_todo_done) { create(:todo, user: current_user, state: :done, action: Todo::ASSIGNED, author: author2) } + let_it_be(:issue_todo_pending) { create(:todo, user: current_user, state: :pending, action: Todo::ASSIGNED, author: author1) } it 'calls TodosFinder' do expect_next_instance_of(TodosFinder) do |finder| @@ -23,22 +23,30 @@ describe Resolvers::TodoResolver do end context 'when using no filter' do - it 'returns expected todos' do - expect(resolve_todos).to contain_exactly(todo1, todo3) + it 'returns pending todos' do + expect(resolve_todos).to contain_exactly(merge_request_todo_pending, issue_todo_pending) end end context 'when using filters' do it 'returns the todos for multiple states' do - todos = resolve_todos({ state: [:done, :pending] }) + todos = resolve_todos(state: [:done, :pending]) - expect(todos).to contain_exactly(todo1, todo2, todo3) + expect(todos).to contain_exactly(merge_request_todo_pending, issue_todo_done, issue_todo_pending) end - it 'returns the todos for multiple types' do - todos = resolve_todos({ type: %w[Issue MergeRequest] }) + it 'returns the todos for multiple filters' do + design_todo_pending = create(:todo, target_type: 'DesignManagement::Design', user: current_user, state: :pending, action: Todo::ASSIGNED, author: author1) - expect(todos).to contain_exactly(todo1, todo3) + todos = resolve_todos(type: ['MergeRequest', 'DesignManagement::Design']) + + expect(todos).to contain_exactly(merge_request_todo_pending, design_todo_pending) + end + + it 'returns the todos for single filter' do + todos = resolve_todos(type: 'MergeRequest') + + expect(todos).to contain_exactly(merge_request_todo_pending) end it 'returns the todos for multiple groups' do @@ -53,7 +61,7 @@ describe Resolvers::TodoResolver do todo5 = create(:todo, group: group2, user: current_user, state: :pending, action: Todo::ASSIGNED, author: author1) create(:todo, group: group3, user: current_user, state: :pending, action: Todo::ASSIGNED, author: author1) - todos = resolve_todos({ group_id: [group2.id, group1.id] }) + todos = resolve_todos(group_id: [group2.id, group1.id]) expect(todos).to contain_exactly(todo4, todo5) end @@ -61,20 +69,19 @@ describe Resolvers::TodoResolver do it 'returns the todos for multiple authors' do author3 = create(:user) - todo4 = create(:todo, user: current_user, state: :pending, action: Todo::ASSIGNED, author: author2) create(:todo, user: current_user, state: :pending, action: Todo::ASSIGNED, author: author3) - todos = resolve_todos({ author_id: [author2.id, author1.id] }) + todos = resolve_todos(author_id: [author2.id, author1.id]) - expect(todos).to contain_exactly(todo1, todo3, todo4) + expect(todos).to contain_exactly(merge_request_todo_pending, issue_todo_pending) end it 'returns the todos for multiple actions' do create(:todo, user: current_user, state: :pending, action: Todo::DIRECTLY_ADDRESSED, author: author1) - todos = resolve_todos({ action: [Todo::MENTIONED, Todo::ASSIGNED] }) + todos = resolve_todos(action: [Todo::MENTIONED, Todo::ASSIGNED]) - expect(todos).to contain_exactly(todo1, todo3) + expect(todos).to contain_exactly(merge_request_todo_pending, issue_todo_pending) end it 'returns the todos for multiple projects' do @@ -86,7 +93,7 @@ describe Resolvers::TodoResolver do todo5 = create(:todo, project: project2, user: current_user, state: :pending, action: Todo::ASSIGNED, author: author1) create(:todo, project: project3, user: current_user, state: :pending, action: Todo::ASSIGNED, author: author1) - todos = resolve_todos({ project_id: [project2.id, project1.id] }) + todos = resolve_todos(project_id: [project2.id, project1.id]) expect(todos).to contain_exactly(todo4, todo5) end diff --git a/spec/graphql/resolvers/tree_resolver_spec.rb b/spec/graphql/resolvers/tree_resolver_spec.rb index 0ea4e6eeaad..7818c25fe47 100644 --- a/spec/graphql/resolvers/tree_resolver_spec.rb +++ b/spec/graphql/resolvers/tree_resolver_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Resolvers::TreeResolver do +RSpec.describe Resolvers::TreeResolver do include GraphqlHelpers let(:repository) { create(:project, :repository).repository } diff --git a/spec/graphql/resolvers/user_resolver_spec.rb b/spec/graphql/resolvers/user_resolver_spec.rb index 45a8816bf26..3ee9f63d832 100644 --- a/spec/graphql/resolvers/user_resolver_spec.rb +++ b/spec/graphql/resolvers/user_resolver_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Resolvers::UserResolver do +RSpec.describe Resolvers::UserResolver do include GraphqlHelpers describe '#resolve' do diff --git a/spec/graphql/resolvers/users/snippets_resolver_spec.rb b/spec/graphql/resolvers/users/snippets_resolver_spec.rb index 6412d77e02b..497b6b11b46 100644 --- a/spec/graphql/resolvers/users/snippets_resolver_spec.rb +++ b/spec/graphql/resolvers/users/snippets_resolver_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Resolvers::Users::SnippetsResolver do +RSpec.describe Resolvers::Users::SnippetsResolver do include GraphqlHelpers describe '#resolve' do diff --git a/spec/graphql/resolvers/users_resolver_spec.rb b/spec/graphql/resolvers/users_resolver_spec.rb index e752500d52f..e3d595e0790 100644 --- a/spec/graphql/resolvers/users_resolver_spec.rb +++ b/spec/graphql/resolvers/users_resolver_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Resolvers::UsersResolver do +RSpec.describe Resolvers::UsersResolver do include GraphqlHelpers let_it_be(:user1) { create(:user) } diff --git a/spec/graphql/types/access_level_enum_spec.rb b/spec/graphql/types/access_level_enum_spec.rb index 05a6d6d5545..eeb10a50b7e 100644 --- a/spec/graphql/types/access_level_enum_spec.rb +++ b/spec/graphql/types/access_level_enum_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe GitlabSchema.types['AccessLevelEnum'] do +RSpec.describe GitlabSchema.types['AccessLevelEnum'] do specify { expect(described_class.graphql_name).to eq('AccessLevelEnum') } it 'exposes all the existing access levels' do diff --git a/spec/graphql/types/access_level_type_spec.rb b/spec/graphql/types/access_level_type_spec.rb index b9711a9aa4b..25707ae160d 100644 --- a/spec/graphql/types/access_level_type_spec.rb +++ b/spec/graphql/types/access_level_type_spec.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true require 'spec_helper' -describe GitlabSchema.types['AccessLevel'] do +RSpec.describe GitlabSchema.types['AccessLevel'] do specify { expect(described_class.graphql_name).to eq('AccessLevel') } specify { expect(described_class).to require_graphql_authorizations(nil) } diff --git a/spec/graphql/types/alert_management/alert_status_count_type_spec.rb b/spec/graphql/types/alert_management/alert_status_count_type_spec.rb index 1c56028425e..6372d5dd915 100644 --- a/spec/graphql/types/alert_management/alert_status_count_type_spec.rb +++ b/spec/graphql/types/alert_management/alert_status_count_type_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe GitlabSchema.types['AlertManagementAlertStatusCountsType'] do +RSpec.describe GitlabSchema.types['AlertManagementAlertStatusCountsType'] do specify { expect(described_class.graphql_name).to eq('AlertManagementAlertStatusCountsType') } it 'exposes the expected fields' do diff --git a/spec/graphql/types/alert_management/alert_type_spec.rb b/spec/graphql/types/alert_management/alert_type_spec.rb index 5acbf8ebb7a..45ac673986d 100644 --- a/spec/graphql/types/alert_management/alert_type_spec.rb +++ b/spec/graphql/types/alert_management/alert_type_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe GitlabSchema.types['AlertManagementAlert'] do +RSpec.describe GitlabSchema.types['AlertManagementAlert'] do specify { expect(described_class.graphql_name).to eq('AlertManagementAlert') } specify { expect(described_class).to require_graphql_authorizations(:read_alert_management_alert) } @@ -27,6 +27,7 @@ describe GitlabSchema.types['AlertManagementAlert'] do assignees notes discussions + metrics_dashboard_url ] expect(described_class).to have_graphql_fields(*expected_fields) diff --git a/spec/graphql/types/alert_management/severity_enum_spec.rb b/spec/graphql/types/alert_management/severity_enum_spec.rb index ca5aa826fe5..6c3c962b71d 100644 --- a/spec/graphql/types/alert_management/severity_enum_spec.rb +++ b/spec/graphql/types/alert_management/severity_enum_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe GitlabSchema.types['AlertManagementSeverity'] do +RSpec.describe GitlabSchema.types['AlertManagementSeverity'] do specify { expect(described_class.graphql_name).to eq('AlertManagementSeverity') } it 'exposes all the severity values' do diff --git a/spec/graphql/types/alert_management/status_enum_spec.rb b/spec/graphql/types/alert_management/status_enum_spec.rb index 240d8863c97..ac7a8eb53f6 100644 --- a/spec/graphql/types/alert_management/status_enum_spec.rb +++ b/spec/graphql/types/alert_management/status_enum_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe GitlabSchema.types['AlertManagementStatus'] do +RSpec.describe GitlabSchema.types['AlertManagementStatus'] do specify { expect(described_class.graphql_name).to eq('AlertManagementStatus') } describe 'statuses' do diff --git a/spec/graphql/types/award_emojis/award_emoji_type_spec.rb b/spec/graphql/types/award_emojis/award_emoji_type_spec.rb index 4e06329506d..3c43c5f8e42 100644 --- a/spec/graphql/types/award_emojis/award_emoji_type_spec.rb +++ b/spec/graphql/types/award_emojis/award_emoji_type_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe GitlabSchema.types['AwardEmoji'] do +RSpec.describe GitlabSchema.types['AwardEmoji'] do specify { expect(described_class.graphql_name).to eq('AwardEmoji') } specify { expect(described_class).to require_graphql_authorizations(:read_emoji) } diff --git a/spec/graphql/types/base_enum_spec.rb b/spec/graphql/types/base_enum_spec.rb index 3eadb492cf5..0d0f6346f2d 100644 --- a/spec/graphql/types/base_enum_spec.rb +++ b/spec/graphql/types/base_enum_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Types::BaseEnum do +RSpec.describe Types::BaseEnum do describe '#enum' do let(:enum) do Class.new(described_class) do diff --git a/spec/graphql/types/base_field_spec.rb b/spec/graphql/types/base_field_spec.rb index 3ec33c75803..73bb54e7ad0 100644 --- a/spec/graphql/types/base_field_spec.rb +++ b/spec/graphql/types/base_field_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Types::BaseField do +RSpec.describe Types::BaseField do context 'when considering complexity' do let(:resolver) do Class.new(described_class) do diff --git a/spec/graphql/types/blob_viewers/type_enum_spec.rb b/spec/graphql/types/blob_viewers/type_enum_spec.rb index 09664382af9..57f052a4fd8 100644 --- a/spec/graphql/types/blob_viewers/type_enum_spec.rb +++ b/spec/graphql/types/blob_viewers/type_enum_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Types::BlobViewers::TypeEnum do +RSpec.describe Types::BlobViewers::TypeEnum do specify { expect(described_class.graphql_name).to eq('BlobViewersType') } it 'exposes all tree entry types' do diff --git a/spec/graphql/types/board_list_type_spec.rb b/spec/graphql/types/board_list_type_spec.rb index 69597fc9617..046d1e92bfa 100644 --- a/spec/graphql/types/board_list_type_spec.rb +++ b/spec/graphql/types/board_list_type_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe GitlabSchema.types['BoardList'] do +RSpec.describe GitlabSchema.types['BoardList'] do specify { expect(described_class.graphql_name).to eq('BoardList') } it 'has specific fields' do diff --git a/spec/graphql/types/board_type_spec.rb b/spec/graphql/types/board_type_spec.rb index 5d87a1757b5..b02b342390d 100644 --- a/spec/graphql/types/board_type_spec.rb +++ b/spec/graphql/types/board_type_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe GitlabSchema.types['Board'] do +RSpec.describe GitlabSchema.types['Board'] do specify { expect(described_class.graphql_name).to eq('Board') } specify { expect(described_class).to require_graphql_authorizations(:read_board) } diff --git a/spec/graphql/types/branch_type_spec.rb b/spec/graphql/types/branch_type_spec.rb index f58b514116d..a5838739a80 100644 --- a/spec/graphql/types/branch_type_spec.rb +++ b/spec/graphql/types/branch_type_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe GitlabSchema.types['Branch'] do +RSpec.describe GitlabSchema.types['Branch'] do it { expect(described_class.graphql_name).to eq('Branch') } it { expect(described_class).to have_graphql_fields(:name, :commit) } diff --git a/spec/graphql/types/ci/detailed_status_type_spec.rb b/spec/graphql/types/ci/detailed_status_type_spec.rb index c62c8f23728..67199848df0 100644 --- a/spec/graphql/types/ci/detailed_status_type_spec.rb +++ b/spec/graphql/types/ci/detailed_status_type_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Types::Ci::DetailedStatusType do +RSpec.describe Types::Ci::DetailedStatusType do specify { expect(described_class.graphql_name).to eq('DetailedStatus') } it "has all fields" do diff --git a/spec/graphql/types/ci/pipeline_type_spec.rb b/spec/graphql/types/ci/pipeline_type_spec.rb index d56cff12105..f13f1c9afb2 100644 --- a/spec/graphql/types/ci/pipeline_type_spec.rb +++ b/spec/graphql/types/ci/pipeline_type_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Types::Ci::PipelineType do +RSpec.describe Types::Ci::PipelineType do specify { expect(described_class.graphql_name).to eq('Pipeline') } specify { expect(described_class).to expose_permissions_using(Types::PermissionTypes::Ci::Pipeline) } diff --git a/spec/graphql/types/ci_configuration/sast/analyzers_entity_type_spec.rb b/spec/graphql/types/ci_configuration/sast/analyzers_entity_type_spec.rb new file mode 100644 index 00000000000..34a22feeaf5 --- /dev/null +++ b/spec/graphql/types/ci_configuration/sast/analyzers_entity_type_spec.rb @@ -0,0 +1,11 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe GitlabSchema.types['SastCiConfigurationAnalyzersEntity'] do + let(:fields) { %i[name label enabled description] } + + it { expect(described_class.graphql_name).to eq('SastCiConfigurationAnalyzersEntity') } + + it { expect(described_class).to have_graphql_fields(fields) } +end diff --git a/spec/graphql/types/ci_configuration/sast/entity_type_spec.rb b/spec/graphql/types/ci_configuration/sast/entity_type_spec.rb new file mode 100644 index 00000000000..7c6ad013d4a --- /dev/null +++ b/spec/graphql/types/ci_configuration/sast/entity_type_spec.rb @@ -0,0 +1,11 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe GitlabSchema.types['SastCiConfigurationEntity'] do + let(:fields) { %i[field label description type options default_value value] } + + it { expect(described_class.graphql_name).to eq('SastCiConfigurationEntity') } + + it { expect(described_class).to have_graphql_fields(fields) } +end diff --git a/spec/graphql/types/ci_configuration/sast/options_entity_spec.rb b/spec/graphql/types/ci_configuration/sast/options_entity_spec.rb new file mode 100644 index 00000000000..c60c8b9c84a --- /dev/null +++ b/spec/graphql/types/ci_configuration/sast/options_entity_spec.rb @@ -0,0 +1,11 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe GitlabSchema.types['SastCiConfigurationOptionsEntity'] do + let(:fields) { %i[label value] } + + it { expect(described_class.graphql_name).to eq('SastCiConfigurationOptionsEntity') } + + it { expect(described_class).to have_graphql_fields(fields) } +end diff --git a/spec/graphql/types/ci_configuration/sast/type_spec.rb b/spec/graphql/types/ci_configuration/sast/type_spec.rb new file mode 100644 index 00000000000..e7a8cd436e4 --- /dev/null +++ b/spec/graphql/types/ci_configuration/sast/type_spec.rb @@ -0,0 +1,11 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe GitlabSchema.types['SastCiConfiguration'] do + let(:fields) { %i[global pipeline analyzers] } + + it { expect(described_class.graphql_name).to eq('SastCiConfiguration') } + + it { expect(described_class).to have_graphql_fields(fields) } +end diff --git a/spec/graphql/types/commit_action_mode_enum_spec.rb b/spec/graphql/types/commit_action_mode_enum_spec.rb index 9e1a27ea254..cedd466e292 100644 --- a/spec/graphql/types/commit_action_mode_enum_spec.rb +++ b/spec/graphql/types/commit_action_mode_enum_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe GitlabSchema.types['CommitActionMode'] do +RSpec.describe GitlabSchema.types['CommitActionMode'] do it { expect(described_class.graphql_name).to eq('CommitActionMode') } it 'exposes all the existing commit actions' do diff --git a/spec/graphql/types/commit_encoding_enum_spec.rb b/spec/graphql/types/commit_encoding_enum_spec.rb index 30686a0c712..7acfb73c06d 100644 --- a/spec/graphql/types/commit_encoding_enum_spec.rb +++ b/spec/graphql/types/commit_encoding_enum_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe GitlabSchema.types['CommitEncoding'] do +RSpec.describe GitlabSchema.types['CommitEncoding'] do it { expect(described_class.graphql_name).to eq('CommitEncoding') } it 'exposes all the existing encoding option' do diff --git a/spec/graphql/types/commit_type_spec.rb b/spec/graphql/types/commit_type_spec.rb index 88b450e3924..75984786972 100644 --- a/spec/graphql/types/commit_type_spec.rb +++ b/spec/graphql/types/commit_type_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe GitlabSchema.types['Commit'] do +RSpec.describe GitlabSchema.types['Commit'] do specify { expect(described_class.graphql_name).to eq('Commit') } specify { expect(described_class).to require_graphql_authorizations(:download_code) } diff --git a/spec/graphql/types/container_expiration_policy_cadence_enum_spec.rb b/spec/graphql/types/container_expiration_policy_cadence_enum_spec.rb index 08c777cd365..9bd1fe3ea76 100644 --- a/spec/graphql/types/container_expiration_policy_cadence_enum_spec.rb +++ b/spec/graphql/types/container_expiration_policy_cadence_enum_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe GitlabSchema.types['ContainerExpirationPolicyCadenceEnum'] do +RSpec.describe GitlabSchema.types['ContainerExpirationPolicyCadenceEnum'] do let_it_be(:expected_values) { %w[EVERY_DAY EVERY_WEEK EVERY_TWO_WEEKS EVERY_MONTH EVERY_THREE_MONTHS] } it_behaves_like 'exposing container expiration policy option', :cadence diff --git a/spec/graphql/types/container_expiration_policy_keep_enum_spec.rb b/spec/graphql/types/container_expiration_policy_keep_enum_spec.rb index 1a5b4bdd3bb..35385545fe3 100644 --- a/spec/graphql/types/container_expiration_policy_keep_enum_spec.rb +++ b/spec/graphql/types/container_expiration_policy_keep_enum_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe GitlabSchema.types['ContainerExpirationPolicyKeepEnum'] do +RSpec.describe GitlabSchema.types['ContainerExpirationPolicyKeepEnum'] do let_it_be(:expected_values) { %w[ONE_TAG FIVE_TAGS TEN_TAGS TWENTY_FIVE_TAGS FIFTY_TAGS ONE_HUNDRED_TAGS] } it_behaves_like 'exposing container expiration policy option', :keep_n diff --git a/spec/graphql/types/container_expiration_policy_older_than_enum_spec.rb b/spec/graphql/types/container_expiration_policy_older_than_enum_spec.rb index 47f0ca22522..72ab605f2e6 100644 --- a/spec/graphql/types/container_expiration_policy_older_than_enum_spec.rb +++ b/spec/graphql/types/container_expiration_policy_older_than_enum_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe GitlabSchema.types['ContainerExpirationPolicyOlderThanEnum'] do +RSpec.describe GitlabSchema.types['ContainerExpirationPolicyOlderThanEnum'] do let_it_be(:expected_values) { %w[SEVEN_DAYS FOURTEEN_DAYS THIRTY_DAYS NINETY_DAYS] } it_behaves_like 'exposing container expiration policy option', :older_than diff --git a/spec/graphql/types/container_expiration_policy_type_spec.rb b/spec/graphql/types/container_expiration_policy_type_spec.rb index 8924ab67847..9e9ddaf1cb0 100644 --- a/spec/graphql/types/container_expiration_policy_type_spec.rb +++ b/spec/graphql/types/container_expiration_policy_type_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe GitlabSchema.types['ContainerExpirationPolicy'] do +RSpec.describe GitlabSchema.types['ContainerExpirationPolicy'] do specify { expect(described_class.graphql_name).to eq('ContainerExpirationPolicy') } specify { expect(described_class.description).to eq('A tag expiration policy designed to keep only the images that matter most') } @@ -24,4 +24,20 @@ describe GitlabSchema.types['ContainerExpirationPolicy'] do is_expected.to have_graphql_type(Types::ContainerExpirationPolicyKeepEnum) end end + + describe 'name_regex field' do + subject { described_class.fields['nameRegex'] } + + it 'returns untrusted regexp type' do + is_expected.to have_graphql_type(Types::UntrustedRegexp) + end + end + + describe 'name_regex_keep field' do + subject { described_class.fields['nameRegexKeep'] } + + it 'returns untrusted regexp type' do + is_expected.to have_graphql_type(Types::UntrustedRegexp) + end + end end diff --git a/spec/graphql/types/design_management/design_at_version_type_spec.rb b/spec/graphql/types/design_management/design_at_version_type_spec.rb index 1453d73d59c..5a6292c924a 100644 --- a/spec/graphql/types/design_management/design_at_version_type_spec.rb +++ b/spec/graphql/types/design_management/design_at_version_type_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe GitlabSchema.types['DesignAtVersion'] do +RSpec.describe GitlabSchema.types['DesignAtVersion'] do it_behaves_like 'a GraphQL type with design fields' do let(:extra_design_fields) { %i[version design] } let_it_be(:design) { create(:design, :with_versions) } diff --git a/spec/graphql/types/design_management/design_collection_type_spec.rb b/spec/graphql/types/design_management/design_collection_type_spec.rb index 65150f0971d..6b1d3a87c2d 100644 --- a/spec/graphql/types/design_management/design_collection_type_spec.rb +++ b/spec/graphql/types/design_management/design_collection_type_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe GitlabSchema.types['DesignCollection'] do +RSpec.describe GitlabSchema.types['DesignCollection'] do it { expect(described_class).to require_graphql_authorizations(:read_design) } it 'has the expected fields' do diff --git a/spec/graphql/types/design_management/design_type_spec.rb b/spec/graphql/types/design_management/design_type_spec.rb index 75b4cd66d5e..7a38b397965 100644 --- a/spec/graphql/types/design_management/design_type_spec.rb +++ b/spec/graphql/types/design_management/design_type_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe GitlabSchema.types['Design'] do +RSpec.describe GitlabSchema.types['Design'] do it_behaves_like 'a GraphQL type with design fields' do let(:extra_design_fields) { %i[notes discussions versions] } let_it_be(:design) { create(:design, :with_versions) } diff --git a/spec/graphql/types/design_management/design_version_event_enum_spec.rb b/spec/graphql/types/design_management/design_version_event_enum_spec.rb index a65f1bb5990..06576336231 100644 --- a/spec/graphql/types/design_management/design_version_event_enum_spec.rb +++ b/spec/graphql/types/design_management/design_version_event_enum_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe GitlabSchema.types['DesignVersionEvent'] do +RSpec.describe GitlabSchema.types['DesignVersionEvent'] do it { expect(described_class.graphql_name).to eq('DesignVersionEvent') } it 'exposes the correct event states' do diff --git a/spec/graphql/types/design_management/version_type_spec.rb b/spec/graphql/types/design_management/version_type_spec.rb index 3317c4c6571..017cc1775a1 100644 --- a/spec/graphql/types/design_management/version_type_spec.rb +++ b/spec/graphql/types/design_management/version_type_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe GitlabSchema.types['DesignVersion'] do +RSpec.describe GitlabSchema.types['DesignVersion'] do it { expect(described_class).to require_graphql_authorizations(:read_design) } it 'has the expected fields' do diff --git a/spec/graphql/types/design_management_type_spec.rb b/spec/graphql/types/design_management_type_spec.rb index a6204f20f23..e9162feec74 100644 --- a/spec/graphql/types/design_management_type_spec.rb +++ b/spec/graphql/types/design_management_type_spec.rb @@ -2,6 +2,6 @@ require 'spec_helper' -describe GitlabSchema.types['DesignManagement'] do +RSpec.describe GitlabSchema.types['DesignManagement'] do it { expect(described_class).to have_graphql_fields(:version, :design_at_version) } end diff --git a/spec/graphql/types/diff_refs_type_spec.rb b/spec/graphql/types/diff_refs_type_spec.rb index 3165e642452..894191c55ba 100644 --- a/spec/graphql/types/diff_refs_type_spec.rb +++ b/spec/graphql/types/diff_refs_type_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe GitlabSchema.types['DiffRefs'] do +RSpec.describe GitlabSchema.types['DiffRefs'] do specify { expect(described_class.graphql_name).to eq('DiffRefs') } specify { expect(described_class).to have_graphql_fields(:head_sha, :base_sha, :start_sha).only } diff --git a/spec/graphql/types/environment_type_spec.rb b/spec/graphql/types/environment_type_spec.rb index 0e5cbac05df..f7522cb3e2c 100644 --- a/spec/graphql/types/environment_type_spec.rb +++ b/spec/graphql/types/environment_type_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe GitlabSchema.types['Environment'] do +RSpec.describe GitlabSchema.types['Environment'] do specify { expect(described_class.graphql_name).to eq('Environment') } it 'has the expected fields' do diff --git a/spec/graphql/types/error_tracking/sentry_detailed_error_type_spec.rb b/spec/graphql/types/error_tracking/sentry_detailed_error_type_spec.rb index 0a094e9e188..8723c212486 100644 --- a/spec/graphql/types/error_tracking/sentry_detailed_error_type_spec.rb +++ b/spec/graphql/types/error_tracking/sentry_detailed_error_type_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe GitlabSchema.types['SentryDetailedError'] do +RSpec.describe GitlabSchema.types['SentryDetailedError'] do specify { expect(described_class.graphql_name).to eq('SentryDetailedError') } specify { expect(described_class).to require_graphql_authorizations(:read_sentry_issue) } @@ -31,6 +31,8 @@ describe GitlabSchema.types['SentryDetailedError'] do lastReleaseLastCommit firstReleaseShortVersion lastReleaseShortVersion + firstReleaseVersion + lastReleaseVersion gitlabIssuePath gitlabCommit gitlabCommitPath diff --git a/spec/graphql/types/error_tracking/sentry_error_collection_type_spec.rb b/spec/graphql/types/error_tracking/sentry_error_collection_type_spec.rb index 793da2db960..3a8ff7a73be 100644 --- a/spec/graphql/types/error_tracking/sentry_error_collection_type_spec.rb +++ b/spec/graphql/types/error_tracking/sentry_error_collection_type_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe GitlabSchema.types['SentryErrorCollection'] do +RSpec.describe GitlabSchema.types['SentryErrorCollection'] do specify { expect(described_class.graphql_name).to eq('SentryErrorCollection') } specify { expect(described_class).to require_graphql_authorizations(:read_sentry_issue) } diff --git a/spec/graphql/types/error_tracking/sentry_error_stack_trace_entry_type_spec.rb b/spec/graphql/types/error_tracking/sentry_error_stack_trace_entry_type_spec.rb index b65398fccc9..54d0d8edbc6 100644 --- a/spec/graphql/types/error_tracking/sentry_error_stack_trace_entry_type_spec.rb +++ b/spec/graphql/types/error_tracking/sentry_error_stack_trace_entry_type_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe GitlabSchema.types['SentryErrorStackTraceEntry'] do +RSpec.describe GitlabSchema.types['SentryErrorStackTraceEntry'] do specify { expect(described_class.graphql_name).to eq('SentryErrorStackTraceEntry') } it 'exposes the expected fields' do diff --git a/spec/graphql/types/error_tracking/sentry_error_stack_trace_type_spec.rb b/spec/graphql/types/error_tracking/sentry_error_stack_trace_type_spec.rb index 2cec8865764..07ddbd83d0a 100644 --- a/spec/graphql/types/error_tracking/sentry_error_stack_trace_type_spec.rb +++ b/spec/graphql/types/error_tracking/sentry_error_stack_trace_type_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe GitlabSchema.types['SentryErrorStackTrace'] do +RSpec.describe GitlabSchema.types['SentryErrorStackTrace'] do specify { expect(described_class.graphql_name).to eq('SentryErrorStackTrace') } specify { expect(described_class).to require_graphql_authorizations(:read_sentry_issue) } diff --git a/spec/graphql/types/error_tracking/sentry_error_type_spec.rb b/spec/graphql/types/error_tracking/sentry_error_type_spec.rb index f8cc801e35e..6cbcc8888c6 100644 --- a/spec/graphql/types/error_tracking/sentry_error_type_spec.rb +++ b/spec/graphql/types/error_tracking/sentry_error_type_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe GitlabSchema.types['SentryError'] do +RSpec.describe GitlabSchema.types['SentryError'] do specify { expect(described_class.graphql_name).to eq('SentryError') } it 'exposes the expected fields' do diff --git a/spec/graphql/types/evidence_type_spec.rb b/spec/graphql/types/evidence_type_spec.rb index 4a11f7bcda9..92134e74d51 100644 --- a/spec/graphql/types/evidence_type_spec.rb +++ b/spec/graphql/types/evidence_type_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe GitlabSchema.types['ReleaseEvidence'] do +RSpec.describe GitlabSchema.types['ReleaseEvidence'] do it { expect(described_class).to require_graphql_authorizations(:download_code) } it 'has the expected fields' do diff --git a/spec/graphql/types/global_id_type_spec.rb b/spec/graphql/types/global_id_type_spec.rb new file mode 100644 index 00000000000..2a7b26f66b0 --- /dev/null +++ b/spec/graphql/types/global_id_type_spec.rb @@ -0,0 +1,215 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Types::GlobalIDType do + let_it_be(:project) { create(:project) } + let(:gid) { project.to_global_id } + let(:foreign_gid) { GlobalID.new(::URI::GID.build(app: 'otherapp', model_name: 'Project', model_id: project.id, params: nil)) } + + it 'is has the correct name' do + expect(described_class.to_graphql.name).to eq('GlobalID') + end + + describe '.coerce_result' do + it 'can coerce results' do + expect(described_class.coerce_isolated_result(gid)).to eq(gid.to_s) + end + + it 'rejects integer IDs' do + expect { described_class.coerce_isolated_result(project.id) } + .to raise_error(ArgumentError) + end + + it 'rejects strings' do + expect { described_class.coerce_isolated_result('not a GID') } + .to raise_error(ArgumentError) + end + end + + describe '.coerce_input' do + it 'can coerce valid input' do + coerced = described_class.coerce_isolated_input(gid.to_s) + + expect(coerced).to eq(gid) + end + + it 'handles all valid application GIDs' do + expect { described_class.coerce_isolated_input(build_stubbed(:user).to_global_id.to_s) } + .not_to raise_error + end + + it 'rejects invalid input' do + expect { described_class.coerce_isolated_input('not valid') } + .to raise_error(GraphQL::CoercionError) + end + + it 'rejects nil' do + expect { described_class.coerce_isolated_input(nil) } + .to raise_error(GraphQL::CoercionError) + end + + it 'rejects gids from different apps' do + expect { described_class.coerce_isolated_input(foreign_gid) } + .to raise_error(GraphQL::CoercionError) + end + end + + describe 'a parameterized type' do + let(:type) { ::Types::GlobalIDType[::Project] } + + it 'is has the correct name' do + expect(type.to_graphql.name).to eq('ProjectID') + end + + context 'the GID is appropriate' do + it 'can coerce results' do + expect(type.coerce_isolated_result(gid)).to eq(gid.to_s) + end + + it 'can coerce IDs to a GlobalIDType' do + expect(type.coerce_isolated_result(project.id)).to eq(gid.to_s) + end + + it 'can coerce valid input' do + expect(type.coerce_isolated_input(gid.to_s)).to eq(gid) + end + end + + context 'the GID is not for an appropriate type' do + let(:gid) { build_stubbed(:user).to_global_id } + + it 'raises errors when coercing results' do + expect { type.coerce_isolated_result(gid) }.to raise_error(GraphQL::CoercionError) + end + + it 'will not coerce invalid input, even if its a valid GID' do + expect { type.coerce_isolated_input(gid.to_s) } + .to raise_error(GraphQL::CoercionError) + end + end + end + + describe 'a parameterized type with a namespace' do + let(:type) { ::Types::GlobalIDType[::Ci::Build] } + + it 'is has a valid GraphQL identifier for a name' do + expect(type.to_graphql.name).to eq('CiBuildID') + end + end + + describe 'compatibility' do + # Simplified schema to test compatibility + + def query(doc, vars) + GraphQL::Query.new(schema, document: doc, context: {}, variables: vars) + end + + def run_query(gql_query, vars) + query(GraphQL.parse(gql_query), vars).result + end + + all_types = [::GraphQL::ID_TYPE, ::Types::GlobalIDType, ::Types::GlobalIDType[::Project]] + + shared_examples 'a working query' do + let!(:schema) do + # capture values so they can be closed over + arg_type = argument_type + res_type = result_type + + project = Class.new(GraphQL::Schema::Object) do + graphql_name 'Project' + field :name, String, null: false + field :id, res_type, null: false, resolver_method: :global_id + + def global_id + object.to_global_id + end + end + + Class.new(GraphQL::Schema) do + query(Class.new(GraphQL::Schema::Object) do + graphql_name 'Query' + + field :project_by_id, project, null: true do + argument :id, arg_type, required: true + end + + def project_by_id(id:) + gid = ::Types::GlobalIDType[::Project].coerce_isolated_input(id) + gid.model_class.find(gid.model_id) + end + end) + end + end + + it 'works' do + res = run_query(document, 'projectId' => project.to_global_id.to_s) + + expect(res['errors']).to be_blank + expect(res.dig('data', 'project', 'name')).to eq(project.name) + expect(res.dig('data', 'project', 'id')).to eq(project.to_global_id.to_s) + end + end + + context 'when the argument is declared as ID' do + let(:document) do + <<-GRAPHQL + query($projectId: ID!){ + project: projectById(id: $projectId) { + name, id + } + } + GRAPHQL + end + + let(:argument_type) { ::GraphQL::ID_TYPE } + + where(:result_type) { all_types } + + with_them do + it_behaves_like 'a working query' + end + end + + context 'when the argument is declared as GlobalID' do + let(:document) do + <<-GRAPHQL + query($projectId: GlobalID!) { + project: projectById(id: $projectId) { + name, id + } + } + GRAPHQL + end + + let(:argument_type) { ::Types::GlobalIDType } + + where(:result_type) { all_types } + + with_them do + it_behaves_like 'a working query' + end + end + + context 'when the argument is declared as ProjectID' do + let(:document) do + <<-GRAPHQL + query($projectId: ProjectID!) { + project: projectById(id: $projectId) { + name, id + } + } + GRAPHQL + end + + let(:argument_type) { ::Types::GlobalIDType[::Project] } + + where(:result_type) { all_types } + + with_them do + it_behaves_like 'a working query' + end + end + end +end diff --git a/spec/graphql/types/grafana_integration_type_spec.rb b/spec/graphql/types/grafana_integration_type_spec.rb index 429b5bdffe6..b4658db08d7 100644 --- a/spec/graphql/types/grafana_integration_type_spec.rb +++ b/spec/graphql/types/grafana_integration_type_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe GitlabSchema.types['GrafanaIntegration'] do +RSpec.describe GitlabSchema.types['GrafanaIntegration'] do let(:expected_fields) do %i[ id diff --git a/spec/graphql/types/group_member_type_spec.rb b/spec/graphql/types/group_member_type_spec.rb index 5d09e60d21c..b1cb8e572ad 100644 --- a/spec/graphql/types/group_member_type_spec.rb +++ b/spec/graphql/types/group_member_type_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Types::GroupMemberType do +RSpec.describe Types::GroupMemberType do specify { expect(described_class).to expose_permissions_using(Types::PermissionTypes::Group) } specify { expect(described_class.graphql_name).to eq('GroupMember') } diff --git a/spec/graphql/types/group_type_spec.rb b/spec/graphql/types/group_type_spec.rb index c56cd40ef12..fb79e9bb85b 100644 --- a/spec/graphql/types/group_type_spec.rb +++ b/spec/graphql/types/group_type_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe GitlabSchema.types['Group'] do +RSpec.describe GitlabSchema.types['Group'] do specify { expect(described_class).to expose_permissions_using(Types::PermissionTypes::Group) } specify { expect(described_class.graphql_name).to eq('Group') } diff --git a/spec/graphql/types/issuable_sort_enum_spec.rb b/spec/graphql/types/issuable_sort_enum_spec.rb index 35c42d8194c..e5237256a2b 100644 --- a/spec/graphql/types/issuable_sort_enum_spec.rb +++ b/spec/graphql/types/issuable_sort_enum_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Types::IssuableSortEnum do +RSpec.describe Types::IssuableSortEnum do specify { expect(described_class.graphql_name).to eq('IssuableSort') } it 'exposes all the existing issuable sort values' do diff --git a/spec/graphql/types/issuable_state_enum_spec.rb b/spec/graphql/types/issuable_state_enum_spec.rb index f974ed5f5fb..a63b8cddb14 100644 --- a/spec/graphql/types/issuable_state_enum_spec.rb +++ b/spec/graphql/types/issuable_state_enum_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe GitlabSchema.types['IssuableState'] do +RSpec.describe GitlabSchema.types['IssuableState'] do specify { expect(described_class.graphql_name).to eq('IssuableState') } it_behaves_like 'issuable state' diff --git a/spec/graphql/types/issue_connection_type_spec.rb b/spec/graphql/types/issue_connection_type_spec.rb new file mode 100644 index 00000000000..af34611ecfe --- /dev/null +++ b/spec/graphql/types/issue_connection_type_spec.rb @@ -0,0 +1,11 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe GitlabSchema.types['IssueConnection'] do + it 'has the expected fields' do + expected_fields = %i[count page_info edges nodes] + + expect(described_class).to have_graphql_fields(*expected_fields) + end +end diff --git a/spec/graphql/types/issue_sort_enum_spec.rb b/spec/graphql/types/issue_sort_enum_spec.rb index c496b897cdb..9313d3aee84 100644 --- a/spec/graphql/types/issue_sort_enum_spec.rb +++ b/spec/graphql/types/issue_sort_enum_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe GitlabSchema.types['IssueSort'] do +RSpec.describe GitlabSchema.types['IssueSort'] do specify { expect(described_class.graphql_name).to eq('IssueSort') } it_behaves_like 'common sort values' diff --git a/spec/graphql/types/issue_state_enum_spec.rb b/spec/graphql/types/issue_state_enum_spec.rb index a18c5f5d317..a9dd287e196 100644 --- a/spec/graphql/types/issue_state_enum_spec.rb +++ b/spec/graphql/types/issue_state_enum_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe GitlabSchema.types['IssueState'] do +RSpec.describe GitlabSchema.types['IssueState'] do specify { expect(described_class.graphql_name).to eq('IssueState') } it_behaves_like 'issuable state' diff --git a/spec/graphql/types/issue_type_spec.rb b/spec/graphql/types/issue_type_spec.rb index a8f7edcfe8e..4a86b07ab1c 100644 --- a/spec/graphql/types/issue_type_spec.rb +++ b/spec/graphql/types/issue_type_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe GitlabSchema.types['Issue'] do +RSpec.describe GitlabSchema.types['Issue'] do specify { expect(described_class).to expose_permissions_using(Types::PermissionTypes::Issue) } specify { expect(described_class.graphql_name).to eq('Issue') } @@ -12,7 +12,7 @@ describe GitlabSchema.types['Issue'] do specify { expect(described_class.interfaces).to include(Types::Notes::NoteableType) } it 'has specific fields' do - fields = %i[iid title description state reference author assignees participants labels milestone due_date + fields = %i[id iid title description state reference author assignees participants labels milestone due_date confidential discussion_locked upvotes downvotes user_notes_count web_path web_url relative_position subscribed time_estimate total_time_spent closed_at created_at updated_at task_completion_status designs design_collection] @@ -22,6 +22,104 @@ describe GitlabSchema.types['Issue'] do end end + describe 'pagination and count' do + let_it_be(:user) { create(:user) } + let_it_be(:project) { create(:project, :public) } + let_it_be(:now) { Time.now.change(usec: 0) } + let_it_be(:issues) { create_list(:issue, 10, project: project, created_at: now) } + + let(:count_path) { %w(data project issues count) } + let(:page_size) { 3 } + let(:query) do + <<~GRAPHQL + query project($fullPath: ID!, $first: Int, $after: String) { + project(fullPath: $fullPath) { + issues(first: $first, after: $after) { + count + edges { + node { + iid + } + } + pageInfo { + endCursor + hasNextPage + } + } + } + } + GRAPHQL + end + + subject do + GitlabSchema.execute( + query, + context: { current_user: user }, + variables: { + fullPath: project.full_path, + first: page_size + } + ).to_h + end + + context 'when user does not have the permission' do + it 'returns no data' do + allow(Ability).to receive(:allowed?).with(user, :read_project, project).and_return(false) + + expect(subject.dig(:data, :project)).to eq(nil) + end + end + + context 'count' do + let(:end_cursor) { %w(data project issues pageInfo endCursor) } + let(:issues_edges) { %w(data project issues edges) } + + it 'returns total count' do + expect(subject.dig(*count_path)).to eq(issues.count) + end + + it 'total count does not change between pages' do + old_count = subject.dig(*count_path) + new_cursor = subject.dig(*end_cursor) + + new_page = GitlabSchema.execute( + query, + context: { current_user: user }, + variables: { + fullPath: project.full_path, + first: page_size, + after: new_cursor + } + ).to_h + + new_count = new_page.dig(*count_path) + expect(old_count).to eq(new_count) + end + + context 'pagination' do + let(:page_size) { 9 } + + it 'returns new ids during pagination' do + old_edges = subject.dig(*issues_edges) + new_cursor = subject.dig(*end_cursor) + + new_edges = GitlabSchema.execute( + query, + context: { current_user: user }, + variables: { + fullPath: project.full_path, + first: page_size, + after: new_cursor + } + ).to_h.dig(*issues_edges) + + expect(old_edges.count).to eq(9) + expect(new_edges.count).to eq(1) + end + end + end + end + describe "issue notes" do let(:user) { create(:user) } let(:project) { create(:project, :public) } diff --git a/spec/graphql/types/jira_import_type_spec.rb b/spec/graphql/types/jira_import_type_spec.rb index fa1152aec41..b44525d3304 100644 --- a/spec/graphql/types/jira_import_type_spec.rb +++ b/spec/graphql/types/jira_import_type_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe GitlabSchema.types['JiraImport'] do +RSpec.describe GitlabSchema.types['JiraImport'] do specify { expect(described_class.graphql_name).to eq('JiraImport') } it 'has the expected fields' do diff --git a/spec/graphql/types/jira_user_type_spec.rb b/spec/graphql/types/jira_user_type_spec.rb new file mode 100644 index 00000000000..6e55efb42f4 --- /dev/null +++ b/spec/graphql/types/jira_user_type_spec.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe GitlabSchema.types['JiraUser'] do + specify { expect(described_class.graphql_name).to eq('JiraUser') } + + it 'has the expected fields' do + expect(described_class).to have_graphql_fields( + :jira_account_id, :jira_display_name, :jira_email, :gitlab_id, :gitlab_username, :gitlab_name + ) + end +end diff --git a/spec/graphql/types/label_type_spec.rb b/spec/graphql/types/label_type_spec.rb index 026c63906ef..6a999a2e925 100644 --- a/spec/graphql/types/label_type_spec.rb +++ b/spec/graphql/types/label_type_spec.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true require 'spec_helper' -describe GitlabSchema.types['Label'] do +RSpec.describe GitlabSchema.types['Label'] do it 'has the correct fields' do expected_fields = [:id, :description, :description_html, :title, :color, :text_color] diff --git a/spec/graphql/types/merge_request_state_enum_spec.rb b/spec/graphql/types/merge_request_state_enum_spec.rb index 2abc7b298b1..6fc5803a5d0 100644 --- a/spec/graphql/types/merge_request_state_enum_spec.rb +++ b/spec/graphql/types/merge_request_state_enum_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe GitlabSchema.types['MergeRequestState'] do +RSpec.describe GitlabSchema.types['MergeRequestState'] do specify { expect(described_class.graphql_name).to eq('MergeRequestState') } it_behaves_like 'issuable state' diff --git a/spec/graphql/types/merge_request_type_spec.rb b/spec/graphql/types/merge_request_type_spec.rb index 0f48264c99f..b3dccde8ce3 100644 --- a/spec/graphql/types/merge_request_type_spec.rb +++ b/spec/graphql/types/merge_request_type_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe GitlabSchema.types['MergeRequest'] do +RSpec.describe GitlabSchema.types['MergeRequest'] do specify { expect(described_class).to expose_permissions_using(Types::PermissionTypes::MergeRequest) } specify { expect(described_class).to require_graphql_authorizations(:read_merge_request) } @@ -15,7 +15,8 @@ describe GitlabSchema.types['MergeRequest'] do description_html state created_at updated_at source_project target_project project project_id source_project_id target_project_id source_branch target_branch work_in_progress merge_when_pipeline_succeeds diff_head_sha - merge_commit_sha user_notes_count should_remove_source_branch diff_refs + merge_commit_sha user_notes_count should_remove_source_branch + diff_refs diff_stats diff_stats_summary force_remove_source_branch merge_status in_progress_merge_commit_sha merge_error allow_collaboration should_be_rebased rebase_commit_sha rebase_in_progress merge_commit_message default_merge_commit_message diff --git a/spec/graphql/types/metadata_type_spec.rb b/spec/graphql/types/metadata_type_spec.rb index 75369ec9c3c..a1efb0a03d5 100644 --- a/spec/graphql/types/metadata_type_spec.rb +++ b/spec/graphql/types/metadata_type_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe GitlabSchema.types['Metadata'] do +RSpec.describe GitlabSchema.types['Metadata'] do specify { expect(described_class.graphql_name).to eq('Metadata') } specify { expect(described_class).to require_graphql_authorizations(:read_instance_metadata) } end diff --git a/spec/graphql/types/metrics/dashboard_type_spec.rb b/spec/graphql/types/metrics/dashboard_type_spec.rb index 0dbd0d8b38d..30dccc7c0be 100644 --- a/spec/graphql/types/metrics/dashboard_type_spec.rb +++ b/spec/graphql/types/metrics/dashboard_type_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe GitlabSchema.types['MetricsDashboard'] do +RSpec.describe GitlabSchema.types['MetricsDashboard'] do specify { expect(described_class.graphql_name).to eq('MetricsDashboard') } it 'has the expected fields' do diff --git a/spec/graphql/types/metrics/dashboards/annotation_type_spec.rb b/spec/graphql/types/metrics/dashboards/annotation_type_spec.rb index dbb8b04dbd7..12c5eec937c 100644 --- a/spec/graphql/types/metrics/dashboards/annotation_type_spec.rb +++ b/spec/graphql/types/metrics/dashboards/annotation_type_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe GitlabSchema.types['MetricsDashboardAnnotation'] do +RSpec.describe GitlabSchema.types['MetricsDashboardAnnotation'] do specify { expect(described_class.graphql_name).to eq('MetricsDashboardAnnotation') } it 'has the expected fields' do diff --git a/spec/graphql/types/milestone_stats_type_spec.rb b/spec/graphql/types/milestone_stats_type_spec.rb new file mode 100644 index 00000000000..1ccb275c922 --- /dev/null +++ b/spec/graphql/types/milestone_stats_type_spec.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe GitlabSchema.types['MilestoneStats'] do + it { expect(described_class).to require_graphql_authorizations(:read_milestone) } + + it 'has the expected fields' do + expected_fields = %w[ + total_issues_count closed_issues_count + ] + + expect(described_class).to include_graphql_fields(*expected_fields) + end +end diff --git a/spec/graphql/types/milestone_type_spec.rb b/spec/graphql/types/milestone_type_spec.rb index 4c3d9f50a64..2315c10433b 100644 --- a/spec/graphql/types/milestone_type_spec.rb +++ b/spec/graphql/types/milestone_type_spec.rb @@ -2,8 +2,25 @@ require 'spec_helper' -describe GitlabSchema.types['Milestone'] do +RSpec.describe GitlabSchema.types['Milestone'] do specify { expect(described_class.graphql_name).to eq('Milestone') } specify { expect(described_class).to require_graphql_authorizations(:read_milestone) } + + it 'has the expected fields' do + expected_fields = %w[ + id title description state web_path + due_date start_date created_at updated_at + project_milestone group_milestone subgroup_milestone + stats + ] + + expect(described_class).to have_graphql_fields(*expected_fields) + end + + describe 'stats field' do + subject { described_class.fields['stats'] } + + it { is_expected.to have_graphql_type(Types::MilestoneStatsType) } + end end diff --git a/spec/graphql/types/mutation_type_spec.rb b/spec/graphql/types/mutation_type_spec.rb index a67d83b1edf..41993327577 100644 --- a/spec/graphql/types/mutation_type_spec.rb +++ b/spec/graphql/types/mutation_type_spec.rb @@ -2,8 +2,34 @@ require 'spec_helper' -describe Types::MutationType do +RSpec.describe Types::MutationType do it 'is expected to have the MergeRequestSetWip' do expect(described_class).to have_graphql_mutation(Mutations::MergeRequests::SetWip) end + + describe 'deprecated and aliased mutations' do + using RSpec::Parameterized::TableSyntax + + where(:alias_name, :canonical_name) do + 'AddAwardEmoji' | 'AwardEmojiAdd' + 'RemoveAwardEmoji' | 'AwardEmojiRemove' + 'ToggleAwardEmoji' | 'AwardEmojiToggle' + end + + with_them do + let(:alias_field) { get_field(alias_name) } + let(:canonical_field) { get_field(canonical_name) } + + it { expect(alias_field).to be_present } + it { expect(canonical_field).to be_present } + it { expect(alias_field.deprecation_reason).to be_present } + it { expect(canonical_field.deprecation_reason).not_to be_present } + it { expect(alias_field.resolver.fields).to eq(canonical_field.resolver.fields) } + it { expect(alias_field.resolver.arguments).to eq(canonical_field.resolver.arguments) } + end + + def get_field(name) + described_class.fields[GraphqlHelpers.fieldnamerize(name)] + end + end end diff --git a/spec/graphql/types/namespace_type_spec.rb b/spec/graphql/types/namespace_type_spec.rb index 741698021e7..2ed1ee3e8c4 100644 --- a/spec/graphql/types/namespace_type_spec.rb +++ b/spec/graphql/types/namespace_type_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe GitlabSchema.types['Namespace'] do +RSpec.describe GitlabSchema.types['Namespace'] do specify { expect(described_class.graphql_name).to eq('Namespace') } it 'has the expected fields' do @@ -11,7 +11,7 @@ describe GitlabSchema.types['Namespace'] do lfs_enabled request_access_enabled projects root_storage_statistics ] - expect(described_class).to have_graphql_fields(*expected_fields) + expect(described_class).to include_graphql_fields(*expected_fields) end specify { expect(described_class).to require_graphql_authorizations(:read_namespace) } diff --git a/spec/graphql/types/notes/diff_position_type_spec.rb b/spec/graphql/types/notes/diff_position_type_spec.rb index 87f3810d55c..1515c2f66d7 100644 --- a/spec/graphql/types/notes/diff_position_type_spec.rb +++ b/spec/graphql/types/notes/diff_position_type_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe GitlabSchema.types['DiffPosition'] do +RSpec.describe GitlabSchema.types['DiffPosition'] do it 'exposes the expected fields' do expected_fields = %i[ diff_refs diff --git a/spec/graphql/types/notes/discussion_type_spec.rb b/spec/graphql/types/notes/discussion_type_spec.rb index 177000b01b2..37ed861d069 100644 --- a/spec/graphql/types/notes/discussion_type_spec.rb +++ b/spec/graphql/types/notes/discussion_type_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe GitlabSchema.types['Discussion'] do +RSpec.describe GitlabSchema.types['Discussion'] do it 'exposes the expected fields' do expected_fields = %i[ created_at diff --git a/spec/graphql/types/notes/note_type_spec.rb b/spec/graphql/types/notes/note_type_spec.rb index d6cd0800234..180d13d35d2 100644 --- a/spec/graphql/types/notes/note_type_spec.rb +++ b/spec/graphql/types/notes/note_type_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe GitlabSchema.types['Note'] do +RSpec.describe GitlabSchema.types['Note'] do it 'exposes the expected fields' do expected_fields = %i[ author @@ -19,6 +19,7 @@ describe GitlabSchema.types['Note'] do resolved_at resolved_by system + system_note_icon_name updated_at user_permissions ] diff --git a/spec/graphql/types/notes/noteable_type_spec.rb b/spec/graphql/types/notes/noteable_type_spec.rb index 88d8eae56d1..fad24c6fed4 100644 --- a/spec/graphql/types/notes/noteable_type_spec.rb +++ b/spec/graphql/types/notes/noteable_type_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Types::Notes::NoteableType do +RSpec.describe Types::Notes::NoteableType do it 'exposes the expected fields' do expected_fields = %i[ discussions diff --git a/spec/graphql/types/package_type_enum_spec.rb b/spec/graphql/types/package_type_enum_spec.rb new file mode 100644 index 00000000000..fadec9744ed --- /dev/null +++ b/spec/graphql/types/package_type_enum_spec.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe GitlabSchema.types['PackageTypeEnum'] do + it 'exposes all package types' do + expect(described_class.values.keys).to contain_exactly(*%w[MAVEN NPM CONAN NUGET PYPI COMPOSER]) + end +end diff --git a/spec/graphql/types/package_type_spec.rb b/spec/graphql/types/package_type_spec.rb new file mode 100644 index 00000000000..22048e7a693 --- /dev/null +++ b/spec/graphql/types/package_type_spec.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe GitlabSchema.types['Package'] do + it { expect(described_class.graphql_name).to eq('Package') } + + it 'includes all the package fields' do + expected_fields = %w[ + id name version created_at updated_at package_type + ] + + expect(described_class).to include_graphql_fields(*expected_fields) + end +end diff --git a/spec/graphql/types/permission_types/base_permission_type_spec.rb b/spec/graphql/types/permission_types/base_permission_type_spec.rb index 4c6d5fd369a..2ce02f1520c 100644 --- a/spec/graphql/types/permission_types/base_permission_type_spec.rb +++ b/spec/graphql/types/permission_types/base_permission_type_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Types::PermissionTypes::BasePermissionType do +RSpec.describe Types::PermissionTypes::BasePermissionType do let(:permitable) { double('permittable') } let(:current_user) { build(:user) } let(:context) { { current_user: current_user } } diff --git a/spec/graphql/types/permission_types/issue_spec.rb b/spec/graphql/types/permission_types/issue_spec.rb index a7a3dd00f11..58c5808cbcc 100644 --- a/spec/graphql/types/permission_types/issue_spec.rb +++ b/spec/graphql/types/permission_types/issue_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Types::PermissionTypes::Issue do +RSpec.describe Types::PermissionTypes::Issue do it do expected_permissions = [ :read_issue, :admin_issue, :update_issue, :reopen_issue, diff --git a/spec/graphql/types/permission_types/merge_request_spec.rb b/spec/graphql/types/permission_types/merge_request_spec.rb index e0f8bdd4712..73a178540a6 100644 --- a/spec/graphql/types/permission_types/merge_request_spec.rb +++ b/spec/graphql/types/permission_types/merge_request_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Types::PermissionTypes::MergeRequest do +RSpec.describe Types::PermissionTypes::MergeRequest do it do expected_permissions = [ :read_merge_request, :admin_merge_request, :update_merge_request, diff --git a/spec/graphql/types/permission_types/merge_request_type_spec.rb b/spec/graphql/types/permission_types/merge_request_type_spec.rb index 7e9752cdc46..7dd1d3bca06 100644 --- a/spec/graphql/types/permission_types/merge_request_type_spec.rb +++ b/spec/graphql/types/permission_types/merge_request_type_spec.rb @@ -2,6 +2,6 @@ require 'spec_helper' -describe Types::MergeRequestType do +RSpec.describe Types::MergeRequestType do specify { expect(described_class).to expose_permissions_using(Types::PermissionTypes::MergeRequest) } end diff --git a/spec/graphql/types/permission_types/note_spec.rb b/spec/graphql/types/permission_types/note_spec.rb index a2becb6892b..9769c7b3aa3 100644 --- a/spec/graphql/types/permission_types/note_spec.rb +++ b/spec/graphql/types/permission_types/note_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe GitlabSchema.types['NotePermissions'] do +RSpec.describe GitlabSchema.types['NotePermissions'] do it 'has the expected fields' do expected_permissions = [ :read_note, :create_note, :admin_note, :resolve_note, :award_emoji diff --git a/spec/graphql/types/permission_types/project_spec.rb b/spec/graphql/types/permission_types/project_spec.rb index 2789464d29c..c6853a0eadc 100644 --- a/spec/graphql/types/permission_types/project_spec.rb +++ b/spec/graphql/types/permission_types/project_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Types::PermissionTypes::Project do +RSpec.describe Types::PermissionTypes::Project do it do expected_permissions = [ :change_namespace, :change_visibility_level, :rename_project, :remove_project, :archive_project, diff --git a/spec/graphql/types/permission_types/snippet_spec.rb b/spec/graphql/types/permission_types/snippet_spec.rb index 66e9fa6dfdb..e2caa1c52c2 100644 --- a/spec/graphql/types/permission_types/snippet_spec.rb +++ b/spec/graphql/types/permission_types/snippet_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Types::PermissionTypes::Snippet do +RSpec.describe Types::PermissionTypes::Snippet do it 'returns the snippets permissions' do expected_permissions = [ :create_note, :award_emoji, :read_snippet, :update_snippet, :admin_snippet, :report_snippet diff --git a/spec/graphql/types/permission_types/user_spec.rb b/spec/graphql/types/permission_types/user_spec.rb index 1e8201db568..6f0d380f763 100644 --- a/spec/graphql/types/permission_types/user_spec.rb +++ b/spec/graphql/types/permission_types/user_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Types::PermissionTypes::User do +RSpec.describe Types::PermissionTypes::User do it 'returns user permissions' do expected_permissions = [ :create_snippet diff --git a/spec/graphql/types/project_member_type_spec.rb b/spec/graphql/types/project_member_type_spec.rb index 1b1f6c24a32..65c89557ec1 100644 --- a/spec/graphql/types/project_member_type_spec.rb +++ b/spec/graphql/types/project_member_type_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Types::ProjectMemberType do +RSpec.describe Types::ProjectMemberType do specify { expect(described_class).to expose_permissions_using(Types::PermissionTypes::Project) } specify { expect(described_class.graphql_name).to eq('ProjectMember') } diff --git a/spec/graphql/types/project_statistics_type_spec.rb b/spec/graphql/types/project_statistics_type_spec.rb index fbea780494b..e6cffd407de 100644 --- a/spec/graphql/types/project_statistics_type_spec.rb +++ b/spec/graphql/types/project_statistics_type_spec.rb @@ -2,10 +2,10 @@ require 'spec_helper' -describe GitlabSchema.types['ProjectStatistics'] do - it "has all the required fields" do +RSpec.describe GitlabSchema.types['ProjectStatistics'] do + it 'has all the required fields' do expect(described_class).to have_graphql_fields(:storage_size, :repository_size, :lfs_objects_size, :build_artifacts_size, :packages_size, :commit_count, - :wiki_size) + :wiki_size, :snippets_size) end end diff --git a/spec/graphql/types/project_type_spec.rb b/spec/graphql/types/project_type_spec.rb index 8ee9aa9cf3a..ea88ed6a3f5 100644 --- a/spec/graphql/types/project_type_spec.rb +++ b/spec/graphql/types/project_type_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe GitlabSchema.types['Project'] do +RSpec.describe GitlabSchema.types['Project'] do specify { expect(described_class).to expose_permissions_using(Types::PermissionTypes::Project) } specify { expect(described_class.graphql_name).to eq('Project') } @@ -26,7 +26,7 @@ describe GitlabSchema.types['Project'] do grafanaIntegration autocloseReferencedIssues suggestion_commit_message environments boards jira_import_status jira_imports services releases release alert_management_alerts alert_management_alert alert_management_alert_status_counts - container_expiration_policy + container_expiration_policy sast_ci_configuration service_desk_enabled service_desk_address ] expect(described_class).to include_graphql_fields(*expected_fields) @@ -140,5 +140,93 @@ describe GitlabSchema.types['Project'] do it { is_expected.to have_graphql_type(Types::ContainerExpirationPolicyType) } end + describe 'sast_ci_configuration' do + let_it_be(:project) { create(:project) } + let_it_be(:user) { create(:user) } + let_it_be(:query) do + %( + query { + project(fullPath: "#{project.full_path}") { + sastCiConfiguration { + global { + nodes { + type + options { + nodes { + label + value + } + } + field + label + defaultValue + value + } + } + pipeline { + nodes { + type + options { + nodes { + label + value + } + } + field + label + defaultValue + value + } + } + analyzers { + nodes { + name + label + enabled + } + } + } + } + } + ) + end + + subject { GitlabSchema.execute(query, context: { current_user: user }).as_json } + + before do + project.add_developer(user) + end + + it "returns the project's sast configuration for global variables" do + query_result = subject.dig('data', 'project', 'sastCiConfiguration', 'global', 'nodes') + first_config = query_result.first + fourth_config = query_result[3] + expect(first_config['type']).to eq('string') + expect(first_config['field']).to eq('SECURE_ANALYZERS_PREFIX') + expect(first_config['label']).to eq('Image prefix') + expect(first_config['defaultValue']).to eq('registry.gitlab.com/gitlab-org/security-products/analyzers') + expect(first_config['value']).to eq('') + expect(first_config['options']).to be_nil + expect(fourth_config['options']['nodes']).to match([{ "value" => "true", "label" => "true (disables SAST)" }, + { "value" => "false", "label" => "false (enables SAST)" }]) + end + + it "returns the project's sast configuration for pipeline variables" do + configuration = subject.dig('data', 'project', 'sastCiConfiguration', 'pipeline', 'nodes').first + expect(configuration['type']).to eq('dropdown') + expect(configuration['field']).to eq('stage') + expect(configuration['label']).to eq('Stage') + expect(configuration['defaultValue']).to eq('test') + expect(configuration['value']).to eq('') + end + + it "returns the project's sast configuration for analyzer variables" do + configuration = subject.dig('data', 'project', 'sastCiConfiguration', 'analyzers', 'nodes').first + expect(configuration['name']).to eq('brakeman') + expect(configuration['label']).to eq('Brakeman') + expect(configuration['enabled']).to eq(true) + end + end + it_behaves_like 'a GraphQL type with labels' end diff --git a/spec/graphql/types/projects/base_service_type_spec.rb b/spec/graphql/types/projects/base_service_type_spec.rb index 4fcb9fe1a73..423cea860d7 100644 --- a/spec/graphql/types/projects/base_service_type_spec.rb +++ b/spec/graphql/types/projects/base_service_type_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe GitlabSchema.types['BaseService'] do +RSpec.describe GitlabSchema.types['BaseService'] do specify { expect(described_class.graphql_name).to eq('BaseService') } it 'has basic expected fields' do diff --git a/spec/graphql/types/projects/jira_project_type_spec.rb b/spec/graphql/types/projects/jira_project_type_spec.rb index cbb01117717..60b4c5c5276 100644 --- a/spec/graphql/types/projects/jira_project_type_spec.rb +++ b/spec/graphql/types/projects/jira_project_type_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe GitlabSchema.types['JiraProject'] do +RSpec.describe GitlabSchema.types['JiraProject'] do it { expect(described_class.graphql_name).to eq('JiraProject') } it 'has basic expected fields' do diff --git a/spec/graphql/types/projects/jira_service_type_spec.rb b/spec/graphql/types/projects/jira_service_type_spec.rb index fad0c91caab..9db580ac963 100644 --- a/spec/graphql/types/projects/jira_service_type_spec.rb +++ b/spec/graphql/types/projects/jira_service_type_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe GitlabSchema.types['JiraService'] do +RSpec.describe GitlabSchema.types['JiraService'] do specify { expect(described_class.graphql_name).to eq('JiraService') } it 'has basic expected fields' do diff --git a/spec/graphql/types/projects/service_type_spec.rb b/spec/graphql/types/projects/service_type_spec.rb index f6758d17d18..f110322ac89 100644 --- a/spec/graphql/types/projects/service_type_spec.rb +++ b/spec/graphql/types/projects/service_type_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Types::Projects::ServiceType do +RSpec.describe Types::Projects::ServiceType do specify { expect(described_class).to have_graphql_fields(:type, :active) } describe ".resolve_type" do diff --git a/spec/graphql/types/projects/services_enum_spec.rb b/spec/graphql/types/projects/services_enum_spec.rb index 91e398e8d81..dac1213daf3 100644 --- a/spec/graphql/types/projects/services_enum_spec.rb +++ b/spec/graphql/types/projects/services_enum_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe GitlabSchema.types['ServiceType'] do +RSpec.describe GitlabSchema.types['ServiceType'] do specify { expect(described_class.graphql_name).to eq('ServiceType') } it 'exposes all the existing project services' do diff --git a/spec/graphql/types/query_type_spec.rb b/spec/graphql/types/query_type_spec.rb index 1194391c26a..081f99a8307 100644 --- a/spec/graphql/types/query_type_spec.rb +++ b/spec/graphql/types/query_type_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe GitlabSchema.types['Query'] do +RSpec.describe GitlabSchema.types['Query'] do it 'is called Query' do expect(described_class.graphql_name).to eq('Query') end diff --git a/spec/graphql/types/release_asset_link_type_spec.rb b/spec/graphql/types/release_asset_link_type_spec.rb new file mode 100644 index 00000000000..679431012cf --- /dev/null +++ b/spec/graphql/types/release_asset_link_type_spec.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe GitlabSchema.types['ReleaseAssetLink'] do + it { expect(described_class).to require_graphql_authorizations(:read_release) } + + it 'has the expected fields' do + expected_fields = %w[ + id name url external link_type + ] + + expect(described_class).to include_graphql_fields(*expected_fields) + end +end diff --git a/spec/graphql/types/release_assets_type_spec.rb b/spec/graphql/types/release_assets_type_spec.rb index 58f0f7ee697..0166f87bf47 100644 --- a/spec/graphql/types/release_assets_type_spec.rb +++ b/spec/graphql/types/release_assets_type_spec.rb @@ -2,12 +2,12 @@ require 'spec_helper' -describe GitlabSchema.types['ReleaseAssets'] do +RSpec.describe GitlabSchema.types['ReleaseAssets'] do it { expect(described_class).to require_graphql_authorizations(:read_release) } it 'has the expected fields' do expected_fields = %w[ - assets_count links sources + count links sources ] expect(described_class).to include_graphql_fields(*expected_fields) @@ -16,7 +16,7 @@ describe GitlabSchema.types['ReleaseAssets'] do describe 'links field' do subject { described_class.fields['links'] } - it { is_expected.to have_graphql_type(Types::ReleaseLinkType.connection_type) } + it { is_expected.to have_graphql_type(Types::ReleaseAssetLinkType.connection_type) } end describe 'sources field' do diff --git a/spec/graphql/types/release_links_type_spec.rb b/spec/graphql/types/release_links_type_spec.rb index 49e04e120f4..d505f0a4b5c 100644 --- a/spec/graphql/types/release_links_type_spec.rb +++ b/spec/graphql/types/release_links_type_spec.rb @@ -2,12 +2,15 @@ require 'spec_helper' -describe GitlabSchema.types['ReleaseLink'] do - it { expect(described_class).to require_graphql_authorizations(:read_release) } +RSpec.describe GitlabSchema.types['ReleaseLinks'] do + it { expect(described_class).to require_graphql_authorizations(:download_code) } it 'has the expected fields' do expected_fields = %w[ - id name url external link_type + selfUrl + mergeRequestsUrl + issuesUrl + editUrl ] expect(described_class).to include_graphql_fields(*expected_fields) diff --git a/spec/graphql/types/release_source_type_spec.rb b/spec/graphql/types/release_source_type_spec.rb index e471ac1a5ac..69a1ca30dbc 100644 --- a/spec/graphql/types/release_source_type_spec.rb +++ b/spec/graphql/types/release_source_type_spec.rb @@ -2,8 +2,8 @@ require 'spec_helper' -describe GitlabSchema.types['ReleaseSource'] do - it { expect(described_class).to require_graphql_authorizations(:read_release_sources) } +RSpec.describe GitlabSchema.types['ReleaseSource'] do + it { expect(described_class).to require_graphql_authorizations(:download_code) } it 'has the expected fields' do expected_fields = %w[ diff --git a/spec/graphql/types/release_type_spec.rb b/spec/graphql/types/release_type_spec.rb index feafe5ed519..0c05a68c5a6 100644 --- a/spec/graphql/types/release_type_spec.rb +++ b/spec/graphql/types/release_type_spec.rb @@ -2,14 +2,15 @@ require 'spec_helper' -describe GitlabSchema.types['Release'] do +RSpec.describe GitlabSchema.types['Release'] do it { expect(described_class).to require_graphql_authorizations(:read_release) } it 'has the expected fields' do expected_fields = %w[ tag_name tag_path description description_html - name assets milestones evidences author commit + name milestones evidences author commit + assets links created_at released_at ] @@ -22,6 +23,12 @@ describe GitlabSchema.types['Release'] do it { is_expected.to have_graphql_type(Types::ReleaseAssetsType) } end + describe 'links field' do + subject { described_class.fields['links'] } + + it { is_expected.to have_graphql_type(Types::ReleaseLinksType) } + end + describe 'milestones field' do subject { described_class.fields['milestones'] } @@ -44,6 +51,5 @@ describe GitlabSchema.types['Release'] do subject { described_class.fields['commit'] } it { is_expected.to have_graphql_type(Types::CommitType) } - it { is_expected.to require_graphql_authorizations(:reporter_access) } end end diff --git a/spec/graphql/types/repository_type_spec.rb b/spec/graphql/types/repository_type_spec.rb index fb52839c712..27780476421 100644 --- a/spec/graphql/types/repository_type_spec.rb +++ b/spec/graphql/types/repository_type_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe GitlabSchema.types['Repository'] do +RSpec.describe GitlabSchema.types['Repository'] do specify { expect(described_class.graphql_name).to eq('Repository') } specify { expect(described_class).to require_graphql_authorizations(:download_code) } diff --git a/spec/graphql/types/resolvable_interface_spec.rb b/spec/graphql/types/resolvable_interface_spec.rb index 231287f9969..25370f8d527 100644 --- a/spec/graphql/types/resolvable_interface_spec.rb +++ b/spec/graphql/types/resolvable_interface_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Types::ResolvableInterface do +RSpec.describe Types::ResolvableInterface do it 'exposes the expected fields' do expected_fields = %i[ resolvable diff --git a/spec/graphql/types/root_storage_statistics_type_spec.rb b/spec/graphql/types/root_storage_statistics_type_spec.rb index ebaa5a18623..f01c55cbccb 100644 --- a/spec/graphql/types/root_storage_statistics_type_spec.rb +++ b/spec/graphql/types/root_storage_statistics_type_spec.rb @@ -2,12 +2,12 @@ require 'spec_helper' -describe GitlabSchema.types['RootStorageStatistics'] do +RSpec.describe GitlabSchema.types['RootStorageStatistics'] do specify { expect(described_class.graphql_name).to eq('RootStorageStatistics') } it 'has all the required fields' do expect(described_class).to have_graphql_fields(:storage_size, :repository_size, :lfs_objects_size, - :build_artifacts_size, :packages_size, :wiki_size) + :build_artifacts_size, :packages_size, :wiki_size, :snippets_size) end specify { expect(described_class).to require_graphql_authorizations(:read_statistics) } diff --git a/spec/graphql/types/snippet_type_spec.rb b/spec/graphql/types/snippet_type_spec.rb index f24419ce9cc..0341ca2c733 100644 --- a/spec/graphql/types/snippet_type_spec.rb +++ b/spec/graphql/types/snippet_type_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe GitlabSchema.types['Snippet'] do +RSpec.describe GitlabSchema.types['Snippet'] do let_it_be(:user) { create(:user) } it 'has the correct fields' do diff --git a/spec/graphql/types/snippets/blob_type_spec.rb b/spec/graphql/types/snippets/blob_type_spec.rb index fb8c6896732..bfac08f40d3 100644 --- a/spec/graphql/types/snippets/blob_type_spec.rb +++ b/spec/graphql/types/snippets/blob_type_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe GitlabSchema.types['SnippetBlob'] do +RSpec.describe GitlabSchema.types['SnippetBlob'] do it 'has the correct fields' do expected_fields = [:rich_data, :plain_data, :raw_path, :size, :binary, :name, :path, diff --git a/spec/graphql/types/snippets/blob_viewer_type_spec.rb b/spec/graphql/types/snippets/blob_viewer_type_spec.rb index 841e22451db..8210eb9a95c 100644 --- a/spec/graphql/types/snippets/blob_viewer_type_spec.rb +++ b/spec/graphql/types/snippets/blob_viewer_type_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe GitlabSchema.types['SnippetBlobViewer'] do +RSpec.describe GitlabSchema.types['SnippetBlobViewer'] do let_it_be(:snippet) { create(:personal_snippet, :repository) } let_it_be(:blob) { snippet.repository.blob_at('HEAD', 'files/images/6049019_460s.jpg') } diff --git a/spec/graphql/types/snippets/file_input_action_enum_spec.rb b/spec/graphql/types/snippets/file_input_action_enum_spec.rb index 2ccc8b04b8f..ff9b706240b 100644 --- a/spec/graphql/types/snippets/file_input_action_enum_spec.rb +++ b/spec/graphql/types/snippets/file_input_action_enum_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Types::Snippets::FileInputActionEnum do +RSpec.describe Types::Snippets::FileInputActionEnum do specify { expect(described_class.graphql_name).to eq('SnippetFileInputActionEnum') } it 'exposes all file input action types' do diff --git a/spec/graphql/types/snippets/file_input_type_spec.rb b/spec/graphql/types/snippets/file_input_type_spec.rb index 62e5caf20b7..c7d4909b542 100644 --- a/spec/graphql/types/snippets/file_input_type_spec.rb +++ b/spec/graphql/types/snippets/file_input_type_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Types::Snippets::FileInputType do +RSpec.describe Types::Snippets::FileInputType do specify { expect(described_class.graphql_name).to eq('SnippetFileInputType') } it 'has the correct arguments' do diff --git a/spec/graphql/types/time_type_spec.rb b/spec/graphql/types/time_type_spec.rb index 3c6e191e2fb..68d346766c2 100644 --- a/spec/graphql/types/time_type_spec.rb +++ b/spec/graphql/types/time_type_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe GitlabSchema.types['Time'] do +RSpec.describe GitlabSchema.types['Time'] do let(:iso) { "2018-06-04T15:23:50+02:00" } let(:time) { Time.parse(iso) } diff --git a/spec/graphql/types/todo_type_spec.rb b/spec/graphql/types/todo_type_spec.rb index 87a5405f0e2..15b6195ec5c 100644 --- a/spec/graphql/types/todo_type_spec.rb +++ b/spec/graphql/types/todo_type_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe GitlabSchema.types['Todo'] do +RSpec.describe GitlabSchema.types['Todo'] do it 'has the correct fields' do expected_fields = [:id, :project, :group, :author, :action, :target_type, :body, :state, :created_at] diff --git a/spec/graphql/types/tree/blob_type_spec.rb b/spec/graphql/types/tree/blob_type_spec.rb index 547a03b5edf..73d61d4860c 100644 --- a/spec/graphql/types/tree/blob_type_spec.rb +++ b/spec/graphql/types/tree/blob_type_spec.rb @@ -2,8 +2,8 @@ require 'spec_helper' -describe Types::Tree::BlobType do +RSpec.describe Types::Tree::BlobType do specify { expect(described_class.graphql_name).to eq('Blob') } - specify { expect(described_class).to have_graphql_fields(:id, :sha, :name, :type, :path, :flat_path, :web_url, :lfs_oid) } + specify { expect(described_class).to have_graphql_fields(:id, :sha, :name, :type, :path, :flat_path, :web_url, :lfs_oid, :mode) } end diff --git a/spec/graphql/types/tree/submodule_type_spec.rb b/spec/graphql/types/tree/submodule_type_spec.rb index b5cfe8eb812..ba2b06f1907 100644 --- a/spec/graphql/types/tree/submodule_type_spec.rb +++ b/spec/graphql/types/tree/submodule_type_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Types::Tree::SubmoduleType do +RSpec.describe Types::Tree::SubmoduleType do specify { expect(described_class.graphql_name).to eq('Submodule') } specify { expect(described_class).to have_graphql_fields(:id, :sha, :name, :type, :path, :flat_path, :web_url, :tree_url) } diff --git a/spec/graphql/types/tree/tree_entry_type_spec.rb b/spec/graphql/types/tree/tree_entry_type_spec.rb index 14826d06645..0e5caf66854 100644 --- a/spec/graphql/types/tree/tree_entry_type_spec.rb +++ b/spec/graphql/types/tree/tree_entry_type_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Types::Tree::TreeEntryType do +RSpec.describe Types::Tree::TreeEntryType do specify { expect(described_class.graphql_name).to eq('TreeEntry') } specify { expect(described_class).to have_graphql_fields(:id, :sha, :name, :type, :path, :flat_path, :web_url) } diff --git a/spec/graphql/types/tree/tree_type_spec.rb b/spec/graphql/types/tree/tree_type_spec.rb index 93faebd3602..362ecdfca91 100644 --- a/spec/graphql/types/tree/tree_type_spec.rb +++ b/spec/graphql/types/tree/tree_type_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Types::Tree::TreeType do +RSpec.describe Types::Tree::TreeType do specify { expect(described_class.graphql_name).to eq('Tree') } specify { expect(described_class).to have_graphql_fields(:trees, :submodules, :blobs, :last_commit) } diff --git a/spec/graphql/types/tree/type_enum_spec.rb b/spec/graphql/types/tree/type_enum_spec.rb index dcacd6073f9..f751bcf2a13 100644 --- a/spec/graphql/types/tree/type_enum_spec.rb +++ b/spec/graphql/types/tree/type_enum_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Types::Tree::TypeEnum do +RSpec.describe Types::Tree::TypeEnum do specify { expect(described_class.graphql_name).to eq('EntryType') } it 'exposes all tree entry types' do diff --git a/spec/graphql/types/untrusted_regexp_spec.rb b/spec/graphql/types/untrusted_regexp_spec.rb new file mode 100644 index 00000000000..c801c62fbdc --- /dev/null +++ b/spec/graphql/types/untrusted_regexp_spec.rb @@ -0,0 +1,52 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe GitlabSchema.types['UntrustedRegexp'] do + using RSpec::Parameterized::TableSyntax + + specify { expect(described_class.graphql_name).to eq('UntrustedRegexp') } + + specify { expect(described_class.description).to eq('A regexp containing patterns sourced from user input') } + + describe '.coerce_input' do + subject { described_class.coerce_input(input, nil) } + + where(:input, :expected_result) do + '.*' | '.*' + '(.*)' | '(.*)' + '[test*]+' | '[test*]+' + '*v1' | :raise_error + '[test*' | :raise_error + 'test*+' | :raise_error + end + + with_them do + context "with input #{params[:input]}" do + if params[:expected_result] == :raise_error + it 'raises a coercion error' do + expect { subject }.to raise_error(GraphQL::CoercionError, /#{Regexp.quote(input)} is an invalid regexp/) + end + else + it { expect(subject).to eq(expected_result) } + end + end + end + end + + describe '.coerce_result' do + subject { described_class.coerce_result(input, nil) } + + where(:input, :expected_result) do + '1' | '1' + 1 | '1' + true | 'true' + end + + with_them do + context "with input #{params[:input]}" do + it { expect(subject).to eq(expected_result) } + end + end + end +end diff --git a/spec/graphql/types/user_type_spec.rb b/spec/graphql/types/user_type_spec.rb index 7b34588b0ff..6cc3f7bcaa1 100644 --- a/spec/graphql/types/user_type_spec.rb +++ b/spec/graphql/types/user_type_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe GitlabSchema.types['User'] do +RSpec.describe GitlabSchema.types['User'] do specify { expect(described_class.graphql_name).to eq('User') } specify { expect(described_class).to require_graphql_authorizations(:read_user) } |