diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-01-07 21:07:50 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-01-07 21:07:50 +0000 |
commit | d203316c80aa27cf747aa29df9f7c2d374965b5f (patch) | |
tree | aab5cde76fbf19a2639f6f9f3cb4f2acdc95f803 /spec | |
parent | 8dafc3b65aeb8f50fdfc38fb98d96c3db9e2f607 (diff) | |
download | gitlab-ce-d203316c80aa27cf747aa29df9f7c2d374965b5f.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec')
10 files changed, 301 insertions, 82 deletions
diff --git a/spec/graphql/resolvers/projects/grafana_integration_resolver_spec.rb b/spec/graphql/resolvers/projects/grafana_integration_resolver_spec.rb new file mode 100644 index 00000000000..416a90a841f --- /dev/null +++ b/spec/graphql/resolvers/projects/grafana_integration_resolver_spec.rb @@ -0,0 +1,29 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe Resolvers::Projects::GrafanaIntegrationResolver do + include GraphqlHelpers + + let_it_be(:project) { create(:project) } + let_it_be(:current_user) { create(:user) } + let_it_be(:grafana_integration) { create(:grafana_integration, project: project)} + + describe '#resolve' do + context 'when object is not a project' do + it { expect(resolve_integration(obj: current_user)).to eq nil } + end + + context 'when object is a project' do + it { expect(resolve_integration(obj: project)).to eq grafana_integration } + end + + context 'when object is nil' do + it { expect(resolve_integration(obj: nil)).to eq nil} + end + end + + def resolve_integration(obj: project, context: { current_user: current_user }) + resolve(described_class, obj: obj, ctx: context) + end +end diff --git a/spec/graphql/types/grafana_integration_type_spec.rb b/spec/graphql/types/grafana_integration_type_spec.rb new file mode 100644 index 00000000000..ddfedc5a75c --- /dev/null +++ b/spec/graphql/types/grafana_integration_type_spec.rb @@ -0,0 +1,22 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe GitlabSchema.types['GrafanaIntegration'] do + let(:expected_fields) do + %i[ + id + grafana_url + token + enabled + created_at + updated_at + ] + end + + it { expect(described_class.graphql_name).to eq('GrafanaIntegration') } + + it { expect(described_class).to require_graphql_authorizations(:admin_operations) } + + it { is_expected.to have_graphql_fields(*expected_fields) } +end diff --git a/spec/graphql/types/project_type_spec.rb b/spec/graphql/types/project_type_spec.rb index a3c51f24307..3c16994495d 100644 --- a/spec/graphql/types/project_type_spec.rb +++ b/spec/graphql/types/project_type_spec.rb @@ -23,6 +23,7 @@ describe GitlabSchema.types['Project'] do only_allow_merge_if_all_discussions_are_resolved printing_merge_request_link_enabled namespace group statistics repository merge_requests merge_request issues issue pipelines removeSourceBranchAfterMerge sentryDetailedError snippets + grafanaIntegration ] is_expected.to include_graphql_fields(*expected_fields) @@ -31,45 +32,42 @@ describe GitlabSchema.types['Project'] do describe 'issue field' do subject { described_class.fields['issue'] } - it 'returns issue' do - is_expected.to have_graphql_type(Types::IssueType) - is_expected.to have_graphql_resolver(Resolvers::IssuesResolver.single) - end + it { is_expected.to have_graphql_type(Types::IssueType) } + it { is_expected.to have_graphql_resolver(Resolvers::IssuesResolver.single) } end describe 'issues field' do subject { described_class.fields['issues'] } - it 'returns issue' do - is_expected.to have_graphql_type(Types::IssueType.connection_type) - is_expected.to have_graphql_resolver(Resolvers::IssuesResolver) - end + it { is_expected.to have_graphql_type(Types::IssueType.connection_type) } + it { is_expected.to have_graphql_resolver(Resolvers::IssuesResolver) } end describe 'merge_requests field' do subject { described_class.fields['mergeRequest'] } - it 'returns merge requests' do - is_expected.to have_graphql_type(Types::MergeRequestType) - is_expected.to have_graphql_resolver(Resolvers::MergeRequestsResolver.single) - end + it { is_expected.to have_graphql_type(Types::MergeRequestType) } + it { is_expected.to have_graphql_resolver(Resolvers::MergeRequestsResolver.single) } end describe 'merge_request field' do subject { described_class.fields['mergeRequests'] } - it 'returns merge request' do - is_expected.to have_graphql_type(Types::MergeRequestType.connection_type) - is_expected.to have_graphql_resolver(Resolvers::MergeRequestsResolver) - end + it { is_expected.to have_graphql_type(Types::MergeRequestType.connection_type) } + it { is_expected.to have_graphql_resolver(Resolvers::MergeRequestsResolver) } end describe 'snippets field' do subject { described_class.fields['snippets'] } - it 'returns snippets' do - is_expected.to have_graphql_type(Types::SnippetType.connection_type) - is_expected.to have_graphql_resolver(Resolvers::Projects::SnippetsResolver) - end + it { is_expected.to have_graphql_type(Types::SnippetType.connection_type) } + it { is_expected.to have_graphql_resolver(Resolvers::Projects::SnippetsResolver) } + end + + describe 'grafana_integration field' do + subject { described_class.fields['grafanaIntegration'] } + + it { is_expected.to have_graphql_type(Types::GrafanaIntegrationType) } + it { is_expected.to have_graphql_resolver(Resolvers::Projects::GrafanaIntegrationResolver) } end end diff --git a/spec/lib/gitlab/graphql/connections/externally_paginated_array_connection_spec.rb b/spec/lib/gitlab/graphql/connections/externally_paginated_array_connection_spec.rb new file mode 100644 index 00000000000..83c94ed6260 --- /dev/null +++ b/spec/lib/gitlab/graphql/connections/externally_paginated_array_connection_spec.rb @@ -0,0 +1,87 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe Gitlab::Graphql::Connections::ExternallyPaginatedArrayConnection do + let(:prev_cursor) { 1 } + let(:next_cursor) { 6 } + let(:values) { [2, 3, 4, 5] } + let(:all_nodes) { Gitlab::Graphql::ExternallyPaginatedArray.new(prev_cursor, next_cursor, *values) } + let(:arguments) { {} } + + subject(:connection) do + described_class.new(all_nodes, arguments) + end + + describe '#sliced_nodes' do + let(:sliced_nodes) { connection.sliced_nodes } + + it 'returns all the nodes' do + expect(connection.sliced_nodes).to eq(values) + end + end + + describe '#paged_nodes' do + let(:paged_nodes) { connection.send(:paged_nodes) } + + it_behaves_like "connection with paged nodes" do + let(:paged_nodes_size) { values.size } + end + end + + describe '#start_cursor' do + it 'returns the prev cursor' do + expect(connection.start_cursor).to eq(prev_cursor) + end + + context 'when there is none' do + let(:prev_cursor) { nil } + + it 'returns nil' do + expect(connection.start_cursor).to eq(nil) + end + end + end + + describe '#end_cursor' do + it 'returns the next cursor' do + expect(connection.end_cursor).to eq(next_cursor) + end + + context 'when there is none' do + let(:next_cursor) { nil } + + it 'returns nil' do + expect(connection.end_cursor).to eq(nil) + end + end + end + + describe '#has_next_page' do + it 'returns true when there is a end cursor' do + expect(connection.has_next_page).to eq(true) + end + + context 'there is no end cursor' do + let(:next_cursor) { nil } + + it 'returns false' do + expect(connection.has_next_page).to eq(false) + end + end + end + + describe '#has_previous_page' do + it 'returns true when there is a start cursor' do + expect(connection.has_previous_page).to eq(true) + end + + context 'there is no start cursor' do + let(:prev_cursor) { nil } + + it 'returns false' do + expect(connection.has_previous_page).to eq(false) + end + end + end +end diff --git a/spec/lib/gitlab/graphql/connections/filterable_array_connection_spec.rb b/spec/lib/gitlab/graphql/connections/filterable_array_connection_spec.rb index 20e87daa0d6..b2f0862be62 100644 --- a/spec/lib/gitlab/graphql/connections/filterable_array_connection_spec.rb +++ b/spec/lib/gitlab/graphql/connections/filterable_array_connection_spec.rb @@ -14,7 +14,9 @@ describe Gitlab::Graphql::Connections::FilterableArrayConnection do describe '#paged_nodes' do let(:paged_nodes) { subject.paged_nodes } - it_behaves_like "connection with paged nodes" + it_behaves_like "connection with paged nodes" do + let(:paged_nodes_size) { 3 } + end context 'when callback filters some nodes' do let(:callback) { proc { |nodes| nodes[1..-1] } } diff --git a/spec/lib/gitlab/graphql/connections/keyset/connection_spec.rb b/spec/lib/gitlab/graphql/connections/keyset/connection_spec.rb index bd0fcbbdeb2..f617e8b3ce7 100644 --- a/spec/lib/gitlab/graphql/connections/keyset/connection_spec.rb +++ b/spec/lib/gitlab/graphql/connections/keyset/connection_spec.rb @@ -232,7 +232,9 @@ describe Gitlab::Graphql::Connections::Keyset::Connection do let_it_be(:all_nodes) { create_list(:project, 5) } let(:paged_nodes) { subject.paged_nodes } - it_behaves_like "connection with paged nodes" + it_behaves_like "connection with paged nodes" do + let(:paged_nodes_size) { 3 } + end context 'when both are passed' do let(:arguments) { { first: 2, last: 2 } } diff --git a/spec/lib/sentry/client/event_spec.rb b/spec/lib/sentry/client/event_spec.rb new file mode 100644 index 00000000000..c8604d72ada --- /dev/null +++ b/spec/lib/sentry/client/event_spec.rb @@ -0,0 +1,73 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe Sentry::Client do + include SentryClientHelpers + + let(:sentry_url) { 'https://sentrytest.gitlab.com/api/0/projects/sentry-org/sentry-project' } + let(:token) { 'test-token' } + let(:default_httparty_options) do + { + follow_redirects: false, + headers: { "Authorization" => "Bearer test-token" } + } + end + let(:client) { described_class.new(sentry_url, token) } + + describe '#issue_latest_event' do + let(:sample_response) do + Gitlab::Utils.deep_indifferent_access( + JSON.parse(fixture_file('sentry/issue_latest_event_sample_response.json')) + ) + end + let(:issue_id) { '1234' } + let(:sentry_api_response) { sample_response } + let(:sentry_url) { 'https://sentrytest.gitlab.com/api/0' } + let(:sentry_request_url) { "#{sentry_url}/issues/#{issue_id}/events/latest/" } + let!(:sentry_api_request) { stub_sentry_request(sentry_request_url, body: sentry_api_response) } + + subject { client.issue_latest_event(issue_id: issue_id) } + + it_behaves_like 'calls sentry api' + + it 'has correct return type' do + expect(subject).to be_a(Gitlab::ErrorTracking::ErrorEvent) + end + + shared_examples 'assigns error tracking event correctly' do + using RSpec::Parameterized::TableSyntax + + where(:event_object, :sentry_response) do + :issue_id | :groupID + :date_received | :dateReceived + end + + with_them do + it { expect(subject.public_send(event_object)).to eq(sentry_api_response.dig(*sentry_response)) } + end + end + + context 'error object created from sentry response' do + it_behaves_like 'assigns error tracking event correctly' + + it 'parses the stack trace' do + expect(subject.stack_trace_entries).to be_a Array + expect(subject.stack_trace_entries).not_to be_empty + end + + context 'error without stack trace' do + before do + sample_response['entries'] = [] + stub_sentry_request(sentry_request_url, body: sample_response) + end + + it_behaves_like 'assigns error tracking event correctly' + + it 'returns an empty array for stack_trace_entries' do + expect(subject.stack_trace_entries).to eq [] + end + end + end + end +end diff --git a/spec/lib/sentry/client_spec.rb b/spec/lib/sentry/client_spec.rb index 07547a92fb9..8500f67b8e9 100644 --- a/spec/lib/sentry/client_spec.rb +++ b/spec/lib/sentry/client_spec.rb @@ -218,62 +218,4 @@ describe Sentry::Client do it_behaves_like 'issues has correct length', 1 end end - - describe '#issue_latest_event' do - let(:sample_response) do - Gitlab::Utils.deep_indifferent_access( - JSON.parse(fixture_file('sentry/issue_latest_event_sample_response.json')) - ) - end - - let(:issue_id) { '1234' } - let(:sentry_api_response) { sample_response } - let(:sentry_url) { 'https://sentrytest.gitlab.com/api/0' } - let(:sentry_request_url) { sentry_url + "/issues/#{issue_id}/events/latest/" } - - let!(:sentry_api_request) { stub_sentry_request(sentry_request_url, body: sentry_api_response) } - - subject { client.issue_latest_event(issue_id: issue_id) } - - it_behaves_like 'calls sentry api' - - it 'has correct return type' do - expect(subject).to be_a(Gitlab::ErrorTracking::ErrorEvent) - end - - shared_examples 'assigns error tracking event correctly' do - using RSpec::Parameterized::TableSyntax - - where(:event_object, :sentry_response) do - :issue_id | :groupID - :date_received | :dateReceived - end - - with_them do - it { expect(subject.public_send(event_object)).to eq(sentry_api_response.dig(*sentry_response)) } - end - end - - context 'error object created from sentry response' do - it_behaves_like 'assigns error tracking event correctly' - - it 'parses the stack trace' do - expect(subject.stack_trace_entries).to be_a Array - expect(subject.stack_trace_entries).not_to be_empty - end - - context 'error without stack trace' do - before do - sample_response['entries'] = [] - stub_sentry_request(sentry_request_url, body: sample_response) - end - - it_behaves_like 'assigns error tracking event correctly' - - it 'returns an empty array for stack_trace_entries' do - expect(subject.stack_trace_entries).to eq [] - end - end - end - end end diff --git a/spec/requests/api/graphql/project/grafana_integration_spec.rb b/spec/requests/api/graphql/project/grafana_integration_spec.rb new file mode 100644 index 00000000000..6075efb0cbd --- /dev/null +++ b/spec/requests/api/graphql/project/grafana_integration_spec.rb @@ -0,0 +1,64 @@ +# frozen_string_literal: true +require 'spec_helper' + +describe 'Getting Grafana Integration' do + include GraphqlHelpers + + let_it_be(:project) { create(:project, :repository) } + let_it_be(:current_user) { project.owner } + let_it_be(:grafana_integration) { create(:grafana_integration, project: project) } + + let(:fields) do + <<~QUERY + #{all_graphql_fields_for('GrafanaIntegration'.classify)} + QUERY + end + + let(:query) do + graphql_query_for( + 'project', + { 'fullPath' => project.full_path }, + query_graphql_field('grafanaIntegration', {}, fields) + ) + end + + context 'with grafana integration data' do + let(:integration_data) { graphql_data['project']['grafanaIntegration'] } + + context 'without project admin permissions' do + let(:user) { create(:user) } + + before do + project.add_developer(user) + post_graphql(query, current_user: user) + end + + it_behaves_like 'a working graphql query' + + it { expect(integration_data).to be nil } + end + + context 'with project admin permissions' do + before do + post_graphql(query, current_user: current_user) + end + + it_behaves_like 'a working graphql query' + + it { expect(integration_data['token']).to eql grafana_integration.token } + it { expect(integration_data['grafanaUrl']).to eql grafana_integration.grafana_url } + + it do + expect( + integration_data['createdAt'] + ).to eql grafana_integration.created_at.strftime('%Y-%m-%dT%H:%M:%SZ') + end + + it do + expect( + integration_data['updatedAt'] + ).to eql grafana_integration.updated_at.strftime('%Y-%m-%dT%H:%M:%SZ') + end + end + end +end diff --git a/spec/support/shared_examples/graphql/connection_paged_nodes.rb b/spec/support/shared_examples/graphql/connection_paged_nodes.rb index 830d2d2d4b1..93de7f619f7 100644 --- a/spec/support/shared_examples/graphql/connection_paged_nodes.rb +++ b/spec/support/shared_examples/graphql/connection_paged_nodes.rb @@ -2,7 +2,7 @@ RSpec.shared_examples 'connection with paged nodes' do it 'returns the collection limited to max page size' do - expect(paged_nodes.size).to eq(3) + expect(paged_nodes.size).to eq(paged_nodes_size) end it 'is a loaded memoized array' do @@ -22,7 +22,7 @@ RSpec.shared_examples 'connection with paged nodes' do let(:arguments) { { last: 2 } } it 'returns only the last elements' do - expect(paged_nodes).to contain_exactly(all_nodes[3], all_nodes[4]) + expect(paged_nodes).to contain_exactly(*all_nodes.last(2)) end end end |