Skip to content
Snippets Groups Projects
Commit 7cc68724 authored by GitLab Bot's avatar GitLab Bot
Browse files

Add latest changes from gitlab-org/gitlab@master

parent 46b10c0f
No related branches found
No related tags found
No related merge requests found
# 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
Loading
Loading
@@ -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
Loading
Loading
@@ -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
Loading
Loading
@@ -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
Loading
Loading
@@ -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
Loading
Loading
@@ -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
Loading
Loading
@@ -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
 
Loading
Loading
Loading
Loading
@@ -108,6 +108,12 @@ RSpec::Matchers.define :have_graphql_resolver do |expected|
end
end
 
RSpec::Matchers.define :have_graphql_extension do |expected|
match do |field|
expect(field.metadata[:type_class].extensions).to include(expected)
end
end
RSpec::Matchers.define :expose_permissions_using do |expected|
match do |type|
permission_field = type.fields['userPermissions']
Loading
Loading
# frozen_string_literal: true
RSpec.shared_examples 'setting sentry error data' do
it 'sets the sentry error data correctly' do
aggregate_failures 'testing the sentry error is correct' do
expect(error['id']).to eql sentry_error.to_global_id.to_s
expect(error['sentryId']).to eql sentry_error.id.to_s
expect(error['status']).to eql sentry_error.status.upcase
expect(error['firstSeen']).to eql sentry_error.first_seen
expect(error['lastSeen']).to eql sentry_error.last_seen
end
end
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment