summaryrefslogtreecommitdiff
path: root/spec/services/jira_connect/sync_service_spec.rb
blob: 7457cdca13cc83ec5c473ae6b14ec8cff1c277d2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe JiraConnect::SyncService, feature_category: :integrations do
  include AfterNextHelpers

  describe '#execute' do
    let_it_be(:project) { create(:project, :repository) }

    let(:client) { Atlassian::JiraConnect::Client }
    let(:info) { { a: 'Some', b: 'Info' } }

    subject do
      described_class.new(project).execute(**info)
    end

    before do
      create(:jira_connect_subscription, namespace: project.namespace)
    end

    def store_info(return_values = [{ 'status': 'success' }])
      receive(:send_info).with(project: project, **info).and_return(return_values)
    end

    def expect_log(type, message)
      expect(Gitlab::IntegrationsLogger)
        .to receive(type).with(
          {
            message: 'response from jira dev_info api',
            integration: 'JiraConnect',
            project_id: project.id,
            project_path: project.full_path,
            jira_response: message&.to_json
          }
        )
    end

    it 'calls Atlassian::JiraConnect::Client#store_dev_info and logs the response' do
      expect_next(client).to store_info

      expect_log(:info, { 'status': 'success' })

      subject
    end

    context 'when a request returns errors' do
      it 'logs each response as an error' do
        expect_next(client).to store_info(
          [
            { 'errorMessages' => ['some error message'] },
            { 'errorMessage' => 'a single error message' },
            { 'errorMessages' => [] },
            { 'errorMessage' => '' }
          ])

        expect_log(:error, { 'errorMessages' => ['some error message'] })
        expect_log(:error, { 'errorMessage' => 'a single error message' })

        subject
      end
    end
  end
end