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/lib/sentry/client | |
parent | 8dafc3b65aeb8f50fdfc38fb98d96c3db9e2f607 (diff) | |
download | gitlab-ce-d203316c80aa27cf747aa29df9f7c2d374965b5f.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/lib/sentry/client')
-rw-r--r-- | spec/lib/sentry/client/event_spec.rb | 73 |
1 files changed, 73 insertions, 0 deletions
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 |