diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-10-27 15:11:10 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-10-27 15:11:10 +0300 |
commit | 71329edee6b7c2af838e07189dfeef8a41cd66ec (patch) | |
tree | 53965603a181b9f85beb6d1d2b3aeb80c81680e3 /spec/requests | |
parent | 563240e444eab70551083c6114fc0726df412e52 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/requests')
-rw-r--r-- | spec/requests/api/graphql/abuse_report_spec.rb | 131 | ||||
-rw-r--r-- | spec/requests/api/graphql/mutations/ci/catalog/resources/create_spec.rb | 2 |
2 files changed, 103 insertions, 30 deletions
diff --git a/spec/requests/api/graphql/abuse_report_spec.rb b/spec/requests/api/graphql/abuse_report_spec.rb index 7d0b8b35763..f74b1fb4061 100644 --- a/spec/requests/api/graphql/abuse_report_spec.rb +++ b/spec/requests/api/graphql/abuse_report_spec.rb @@ -2,49 +2,122 @@ require 'spec_helper' -RSpec.describe 'abuse_report', feature_category: :insider_threat do +RSpec.describe 'Querying an Abuse Report', feature_category: :insider_threat do include GraphqlHelpers let_it_be(:current_user) { create(:admin) } - let_it_be(:label) { create(:abuse_report_label, title: 'Uno') } - let_it_be(:report) { create(:abuse_report, labels: [label]) } - - let(:report_gid) { Gitlab::GlobalId.build(report, id: report.id).to_s } - - let(:fields) do - <<~GRAPHQL - labels { - nodes { - id - title - description - color - textColor - } - } - GRAPHQL - end + let_it_be(:abuse_report) { create(:abuse_report) } - let(:arguments) { { id: report_gid } } - let(:query) { graphql_query_for('abuseReport', arguments, fields) } + let(:global_id) { abuse_report.to_gid.to_s } + let(:abuse_report_fields) { all_graphql_fields_for('AbuseReport', max_depth: 2) } + let(:abuse_report_data) { graphql_data['abuseReport'] } + + let(:query) do + graphql_query_for('abuseReport', { 'id' => global_id }, abuse_report_fields) + end before do post_graphql(query, current_user: current_user) end - it_behaves_like 'a working graphql query that returns data' + context 'when the user is an admin' do + it_behaves_like 'a working graphql query that returns data' - it 'returns abuse report with labels' do - expect(graphql_data_at('abuseReport', 'labels', 'nodes', 0)).to match(a_graphql_entity_for(label)) + it 'returns all fields' do + expect(abuse_report_data).to include( + 'id' => global_id, + 'userPermissions' => { + 'readAbuseReport' => true, + 'createNote' => true + } + ) + end end - context 'when current user is not an admin' do - let_it_be(:current_user) { create(:user) } + context 'when the user is not an admin' do + let(:current_user) { create(:user) } + + it 'returns nil' do + expect(abuse_report_data).to be_nil + end + end - it_behaves_like 'a working graphql query' + describe 'labels' do + let_it_be(:abuse_report_label) { create(:abuse_report_label, title: 'Label') } + let_it_be(:abuse_report) { create(:abuse_report, labels: [abuse_report_label]) } + + let(:labels_response) do + graphql_data_at(:abuse_report, :labels, :nodes) + end + + let(:abuse_report_fields) do + <<~GRAPHQL + labels { + nodes { + id + title + description + color + textColor + } + } + GRAPHQL + end + + it 'returns labels' do + expect(labels_response).to contain_exactly( + a_graphql_entity_for(abuse_report_label) + ) + end + end + + describe 'notes' do + let_it_be(:note) { create(:note, noteable: abuse_report, author: current_user) } + + let(:notes_response) do + graphql_data_at(:abuse_report, :notes, :nodes) + end + + let(:abuse_report_fields) do + <<~GRAPHQL + notes { + nodes { + #{all_graphql_fields_for('Note', max_depth: 2)} + } + } + GRAPHQL + end + + it 'returns notes' do + expect(notes_response).to contain_exactly( + a_graphql_entity_for(note) + ) + end + end + + describe 'discussions' do + let_it_be(:discussion) do + create(:discussion_note_on_abuse_report, noteable: abuse_report, author: current_user).to_discussion + end + + let(:discussions_response) do + graphql_data_at(:abuse_report, :discussions, :nodes) + end + + let(:abuse_report_fields) do + <<~GRAPHQL + discussions { + nodes { + #{all_graphql_fields_for('Discussion', max_depth: 2)} + } + } + GRAPHQL + end - it 'does not contain any data' do - expect(graphql_data_at('abuseReportLabel')).to be_nil + it 'returns discussions' do + expect(discussions_response).to contain_exactly( + a_graphql_entity_for(discussion) + ) end end end diff --git a/spec/requests/api/graphql/mutations/ci/catalog/resources/create_spec.rb b/spec/requests/api/graphql/mutations/ci/catalog/resources/create_spec.rb index 3fab8815a1a..e46b614f02e 100644 --- a/spec/requests/api/graphql/mutations/ci/catalog/resources/create_spec.rb +++ b/spec/requests/api/graphql/mutations/ci/catalog/resources/create_spec.rb @@ -6,7 +6,7 @@ RSpec.describe 'CatalogResourcesCreate', feature_category: :pipeline_composition include GraphqlHelpers let_it_be(:current_user) { create(:user) } - let_it_be(:project) { create(:project, :repository, description: 'our components') } + let_it_be(:project) { create(:project, :catalog_resource_with_components) } let(:mutation) do variables = { |