summaryrefslogtreecommitdiff
path: root/spec/services/admin/propagate_service_template_spec.rb
blob: d95d31ceaeacbb14ccb6414c1bc56266c9f2ca56 (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
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Admin::PropagateServiceTemplate do
  describe '.propagate' do
    let_it_be(:project) { create(:project) }
    let!(:service_template) do
      PushoverService.create!(
        template: true,
        active: true,
        push_events: false,
        properties: {
          device: 'MyDevice',
          sound: 'mic',
          priority: 4,
          user_key: 'asdf',
          api_key: '123456789'
        }
      )
    end

    it 'calls to PropagateIntegrationProjectWorker' do
      expect(PropagateIntegrationProjectWorker).to receive(:perform_async)
        .with(service_template.id, project.id, project.id)

      described_class.propagate(service_template)
    end

    context 'with a project that has another service' do
      before do
        BambooService.create!(
          active: true,
          project: project,
          properties: {
            bamboo_url: 'http://gitlab.com',
            username: 'mic',
            password: 'password',
            build_key: 'build'
          }
        )
      end

      it 'calls to PropagateIntegrationProjectWorker' do
        expect(PropagateIntegrationProjectWorker).to receive(:perform_async)
          .with(service_template.id, project.id, project.id)

        described_class.propagate(service_template)
      end
    end

    it 'does not create the service if it exists already' do
      Service.build_from_integration(service_template, project_id: project.id).save!

      expect { described_class.propagate(service_template) }
        .not_to change { Service.count }
    end
  end
end