Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-01-29 15:09:08 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2020-01-29 15:09:08 +0300
commit7cc6872401eb487ed20dbb9d455f8bb9c97d9e39 (patch)
tree63f6ed5d4e6c5cec31c43363626d9f5b178eddf8 /spec/requests
parent46b10c0fc884400941c17e2777b242ac54d111e5 (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/requests')
-rw-r--r--spec/requests/api/graphql/project/error_tracking/sentry_errors_request_spec.rb191
-rw-r--r--spec/requests/self_monitoring_project_spec.rb17
2 files changed, 202 insertions, 6 deletions
diff --git a/spec/requests/api/graphql/project/error_tracking/sentry_errors_request_spec.rb b/spec/requests/api/graphql/project/error_tracking/sentry_errors_request_spec.rb
new file mode 100644
index 00000000000..e68025bf01b
--- /dev/null
+++ b/spec/requests/api/graphql/project/error_tracking/sentry_errors_request_spec.rb
@@ -0,0 +1,191 @@
+# frozen_string_literal: true
+require 'spec_helper'
+
+describe 'sentry errors requests' do
+ include GraphqlHelpers
+ let_it_be(:project) { create(:project, :repository) }
+ let_it_be(:project_setting) { create(:project_error_tracking_setting, project: project) }
+ let_it_be(:current_user) { project.owner }
+
+ let(:query) do
+ graphql_query_for(
+ 'project',
+ { 'fullPath' => project.full_path },
+ query_graphql_field('sentryErrors', {}, fields)
+ )
+ end
+
+ describe 'getting a detailed sentry error' do
+ let_it_be(:sentry_detailed_error) { build(:detailed_error_tracking_error) }
+ let(:sentry_gid) { sentry_detailed_error.to_global_id.to_s }
+
+ let(:detailed_fields) do
+ all_graphql_fields_for('SentryDetailedError'.classify)
+ end
+
+ let(:fields) do
+ query_graphql_field('detailedError', { id: sentry_gid }, detailed_fields)
+ end
+
+ let(:error_data) { graphql_data.dig('project', 'sentryErrors', 'detailedError') }
+
+ it_behaves_like 'a working graphql query' do
+ before do
+ post_graphql(query, current_user: current_user)
+ end
+ end
+
+ context 'when data is loading via reactive cache' do
+ before do
+ post_graphql(query, current_user: current_user)
+ end
+
+ it "is expected to return an empty error" do
+ expect(error_data).to eq nil
+ end
+ end
+
+ context 'reactive cache returns data' do
+ before do
+ allow_any_instance_of(ErrorTracking::ProjectErrorTrackingSetting)
+ .to receive(:issue_details)
+ .and_return({ issue: sentry_detailed_error })
+
+ post_graphql(query, current_user: current_user)
+ end
+
+ let(:sentry_error) { sentry_detailed_error }
+ let(:error) { error_data }
+
+ it_behaves_like 'setting sentry error data'
+
+ it 'is expected to return the frequency correctly' do
+ aggregate_failures 'it returns the frequency correctly' do
+ expect(error_data['frequency'].count).to eql sentry_detailed_error.frequency.count
+
+ first_frequency = error_data['frequency'].first
+ expect(Time.parse(first_frequency['time'])).to eql Time.at(sentry_detailed_error.frequency[0][0], in: 0)
+ expect(first_frequency['count']).to eql sentry_detailed_error.frequency[0][1]
+ end
+ end
+
+ context 'user does not have permission' do
+ let(:current_user) { create(:user) }
+
+ it "is expected to return an empty error" do
+ expect(error_data).to eq nil
+ end
+ end
+ end
+
+ context 'sentry api returns an error' do
+ before do
+ expect_any_instance_of(ErrorTracking::ProjectErrorTrackingSetting)
+ .to receive(:issue_details)
+ .and_return({ error: 'error message' })
+
+ post_graphql(query, current_user: current_user)
+ end
+
+ it 'is expected to handle the error and return nil' do
+ expect(error_data).to eq nil
+ end
+ end
+ end
+
+ describe 'getting an errors list' do
+ let_it_be(:sentry_error) { build(:error_tracking_error) }
+ let_it_be(:pagination) do
+ {
+ 'next' => { 'cursor' => '2222' },
+ 'previous' => { 'cursor' => '1111' }
+ }
+ end
+
+ let(:fields) do
+ <<~QUERY
+ errors {
+ nodes {
+ #{all_graphql_fields_for('SentryError'.classify)}
+ }
+ pageInfo {
+ hasNextPage
+ hasPreviousPage
+ startCursor
+ endCursor
+ }
+ }
+ QUERY
+ end
+
+ let(:error_data) { graphql_data.dig('project', 'sentryErrors', 'errors', 'nodes') }
+ let(:pagination_data) { graphql_data.dig('project', 'sentryErrors', 'errors', 'pageInfo') }
+
+ it_behaves_like 'a working graphql query' do
+ before do
+ post_graphql(query, current_user: current_user)
+ end
+ end
+
+ context 'when data is loading via reactive cache' do
+ before do
+ post_graphql(query, current_user: current_user)
+ end
+
+ it "is expected to return nil" do
+ expect(error_data).to eq nil
+ end
+ end
+
+ context 'reactive cache returns data' do
+ before do
+ expect_any_instance_of(ErrorTracking::ProjectErrorTrackingSetting)
+ .to receive(:list_sentry_issues)
+ .and_return({ issues: [sentry_error], pagination: pagination })
+
+ post_graphql(query, current_user: current_user)
+ end
+
+ let(:error) { error_data.first }
+
+ it 'is expected to return an array of data' do
+ expect(error_data).to be_a Array
+ expect(error_data.count).to eq 1
+ end
+
+ it_behaves_like 'setting sentry error data'
+
+ it 'sets the pagination correctly' do
+ expect(pagination_data['startCursor']).to eq(pagination['previous']['cursor'])
+ expect(pagination_data['endCursor']).to eq(pagination['next']['cursor'])
+ end
+
+ it 'is expected to return the frequency correctly' do
+ aggregate_failures 'it returns the frequency correctly' do
+ error = error_data.first
+
+ expect(error['frequency'].count).to eql sentry_error.frequency.count
+
+ first_frequency = error['frequency'].first
+
+ expect(Time.parse(first_frequency['time'])).to eql Time.at(sentry_error.frequency[0][0], in: 0)
+ expect(first_frequency['count']).to eql sentry_error.frequency[0][1]
+ end
+ end
+ end
+
+ context "sentry api itself errors out" do
+ before do
+ expect_any_instance_of(ErrorTracking::ProjectErrorTrackingSetting)
+ .to receive(:list_sentry_issues)
+ .and_return({ error: 'error message' })
+
+ post_graphql(query, current_user: current_user)
+ end
+
+ it 'is expected to handle the error and return nil' do
+ expect(error_data).to eq nil
+ end
+ end
+ end
+end
diff --git a/spec/requests/self_monitoring_project_spec.rb b/spec/requests/self_monitoring_project_spec.rb
index 1da0be882d0..5e46645e7a0 100644
--- a/spec/requests/self_monitoring_project_spec.rb
+++ b/spec/requests/self_monitoring_project_spec.rb
@@ -68,6 +68,8 @@ describe 'Self-Monitoring project requests' do
let(:job_id) { nil }
it 'returns bad_request' do
+ create(:application_setting)
+
subject
aggregate_failures do
@@ -81,11 +83,10 @@ describe 'Self-Monitoring project requests' do
end
context 'when self-monitoring project exists' do
- let(:project) { build(:project) }
+ let(:project) { create(:project) }
before do
- stub_application_setting(self_monitoring_project_id: 1)
- stub_application_setting(self_monitoring_project: project)
+ create(:application_setting, self_monitoring_project_id: project.id)
end
it 'does not need job_id' do
@@ -94,7 +95,7 @@ describe 'Self-Monitoring project requests' do
aggregate_failures do
expect(response).to have_gitlab_http_status(:success)
expect(json_response).to eq(
- 'project_id' => 1,
+ 'project_id' => project.id,
'project_full_path' => project.full_path
)
end
@@ -106,7 +107,7 @@ describe 'Self-Monitoring project requests' do
aggregate_failures do
expect(response).to have_gitlab_http_status(:success)
expect(json_response).to eq(
- 'project_id' => 1,
+ 'project_id' => project.id,
'project_full_path' => project.full_path
)
end
@@ -179,7 +180,7 @@ describe 'Self-Monitoring project requests' do
context 'when self-monitoring project exists and job does not exist' do
before do
- stub_application_setting(self_monitoring_project_id: 1)
+ create(:application_setting, self_monitoring_project_id: create(:project).id)
end
it 'returns bad_request' do
@@ -196,6 +197,10 @@ describe 'Self-Monitoring project requests' do
end
context 'when self-monitoring project does not exist' do
+ before do
+ create(:application_setting)
+ end
+
it 'does not need job_id' do
get status_delete_self_monitoring_project_admin_application_settings_path