2020-01-16 13:08:46 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-24 14:09:03 -04:00
|
|
|
RSpec.describe Sentry::Client::IssueLink do
|
2020-01-16 13:08:46 -05:00
|
|
|
include SentryClientHelpers
|
|
|
|
|
2020-01-22 10:08:48 -05:00
|
|
|
let_it_be(:sentry_url) { 'https://sentrytest.gitlab.com/api/0/projects/sentry-org/sentry-project' }
|
|
|
|
let_it_be(:error_tracking_setting) { create(:project_error_tracking_setting, api_url: sentry_url) }
|
|
|
|
let_it_be(:issue) { create(:issue, project: error_tracking_setting.project) }
|
2020-01-16 13:08:46 -05:00
|
|
|
|
2020-01-22 10:08:48 -05:00
|
|
|
let(:client) { error_tracking_setting.sentry_client }
|
|
|
|
let(:sentry_issue_id) { 11111111 }
|
2020-01-16 13:08:46 -05:00
|
|
|
|
|
|
|
describe '#create_issue_link' do
|
2020-01-22 10:08:48 -05:00
|
|
|
let(:sentry_issue_link_url) { "https://sentrytest.gitlab.com/api/0/groups/#{sentry_issue_id}/integrations/#{integration_id}/" }
|
2020-01-16 13:08:46 -05:00
|
|
|
let(:integration_id) { 44444 }
|
|
|
|
|
2020-04-30 20:09:59 -04:00
|
|
|
let(:issue_link_sample_response) { Gitlab::Json.parse(fixture_file('sentry/global_integration_link_sample_response.json')) }
|
2020-01-16 13:08:46 -05:00
|
|
|
let(:sentry_api_response) { issue_link_sample_response }
|
|
|
|
let!(:sentry_api_request) { stub_sentry_request(sentry_issue_link_url, :put, body: sentry_api_response, status: 201) }
|
|
|
|
|
|
|
|
subject { client.create_issue_link(integration_id, sentry_issue_id, issue) }
|
|
|
|
|
|
|
|
it_behaves_like 'calls sentry api'
|
|
|
|
|
|
|
|
it { is_expected.to be_present }
|
|
|
|
|
|
|
|
context 'redirects' do
|
|
|
|
let(:sentry_api_url) { sentry_issue_link_url }
|
|
|
|
|
|
|
|
it_behaves_like 'no Sentry redirects', :put
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when exception is raised' do
|
|
|
|
let(:sentry_request_url) { sentry_issue_link_url }
|
|
|
|
|
|
|
|
it_behaves_like 'maps Sentry exceptions', :put
|
|
|
|
end
|
2020-01-22 10:08:48 -05:00
|
|
|
|
|
|
|
context 'when integration_id is not provided' do
|
|
|
|
let(:sentry_issue_link_url) { "https://sentrytest.gitlab.com/api/0/issues/#{sentry_issue_id}/plugins/gitlab/link/" }
|
|
|
|
let(:integration_id) { nil }
|
|
|
|
|
2020-04-30 20:09:59 -04:00
|
|
|
let(:issue_link_sample_response) { Gitlab::Json.parse(fixture_file('sentry/plugin_link_sample_response.json')) }
|
2020-01-22 10:08:48 -05:00
|
|
|
let!(:sentry_api_request) { stub_sentry_request(sentry_issue_link_url, :post, body: sentry_api_response) }
|
|
|
|
|
|
|
|
it_behaves_like 'calls sentry api'
|
|
|
|
|
|
|
|
it { is_expected.to be_present }
|
|
|
|
|
|
|
|
context 'redirects' do
|
|
|
|
let(:sentry_api_url) { sentry_issue_link_url }
|
|
|
|
|
|
|
|
it_behaves_like 'no Sentry redirects', :post
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when exception is raised' do
|
|
|
|
let(:sentry_request_url) { sentry_issue_link_url }
|
|
|
|
|
|
|
|
it_behaves_like 'maps Sentry exceptions', :post
|
|
|
|
end
|
|
|
|
end
|
2020-01-16 13:08:46 -05:00
|
|
|
end
|
|
|
|
end
|