diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-01-20 21:08:44 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-01-20 21:08:44 +0300 |
commit | e0ab7eda1b1013e3246b0db28689b0749158f0bf (patch) | |
tree | c0b4fa77a0a781f0e0e868133293053ae75c2aff /spec/workers/error_tracking_issue_link_worker_spec.rb | |
parent | 364f6f2e33e6f5eafe63b25d9256b88e72141b1c (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/workers/error_tracking_issue_link_worker_spec.rb')
-rw-r--r-- | spec/workers/error_tracking_issue_link_worker_spec.rb | 96 |
1 files changed, 96 insertions, 0 deletions
diff --git a/spec/workers/error_tracking_issue_link_worker_spec.rb b/spec/workers/error_tracking_issue_link_worker_spec.rb new file mode 100644 index 00000000000..cf16e4a0803 --- /dev/null +++ b/spec/workers/error_tracking_issue_link_worker_spec.rb @@ -0,0 +1,96 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe ErrorTrackingIssueLinkWorker do + let_it_be(:error_tracking) { create(:project_error_tracking_setting) } + let_it_be(:project) { error_tracking.project } + let_it_be(:issue) { create(:issue, project: project) } + let_it_be(:sentry_issue) { create(:sentry_issue, issue: issue) } + + let(:repo) do + Gitlab::ErrorTracking::Repo.new( + status: 'active', + integration_id: 66666, + project_id: project.id + ) + end + + subject { described_class.new.perform(issue.id) } + + describe '#perform' do + it 'creates a link between an issue and a Sentry issue in Sentry' do + expect_next_instance_of(Sentry::Client) do |client| + expect(client).to receive(:repos).with('sentry-org').and_return([repo]) + expect(client) + .to receive(:create_issue_link) + .with(66666, sentry_issue.sentry_issue_identifier, issue) + .and_return(true) + end + + expect(subject).to be true + end + + shared_examples_for 'makes no external API requests' do + it 'takes no action' do + expect_any_instance_of(Sentry::Client).not_to receive(:repos) + expect_any_instance_of(Sentry::Client).not_to receive(:create_issue_link) + + expect(subject).to be nil + end + end + + shared_examples_for 'terminates after one API request' do + it 'takes no action' do + expect_next_instance_of(Sentry::Client) do |client| + expect(client).to receive(:repos).with('sentry-org').and_return([repo]) + end + expect_any_instance_of(Sentry::Client).not_to receive(:create_issue_link) + + expect(subject).to be nil + end + end + + context 'when issue is unavailable' do + let(:issue) { double('issue', id: -3) } + + it_behaves_like 'makes no external API requests' + end + + context 'when project does not have error tracking configured' do + let(:issue) { build(:project) } + + it_behaves_like 'makes no external API requests' + end + + context 'when the issue is not linked to a Sentry issue in GitLab' do + let(:issue) { build(:issue, project: project) } + + it_behaves_like 'makes no external API requests' + end + + context 'when Sentry disabled the GitLab integration' do + let(:repo) do + Gitlab::ErrorTracking::Repo.new( + status: 'inactive', + integration_id: 66666, + project_id: project.id + ) + end + + it_behaves_like 'terminates after one API request' + end + + context 'when Sentry the GitLab integration is for another project' do + let(:repo) do + Gitlab::ErrorTracking::Repo.new( + status: 'active', + integration_id: 66666, + project_id: -3 + ) + end + + it_behaves_like 'terminates after one API request' + end + end +end |