Welcome to mirror list, hosted at ThFree Co, Russian Federation.

sync_service_spec.rb « jira_connect « services « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: edd0bad70f50ac446127cfb90da20f3660dd74d3 (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
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe JiraConnect::SyncService 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::ProjectServiceLogger)
        .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 an error' do
      it 'logs the response as an error' do
        expect_next(client).to store_info([
          { 'errorMessages' => ['some error message'] },
          { 'errorMessages' => ['x'] }
        ])

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

        subject
      end
    end
  end
end