summaryrefslogtreecommitdiff
path: root/spec/controllers/admin/services_controller_spec.rb
blob: 8e78cc75369360b694a15fe2330d70624e3d7dd7 (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
65
66
67
68
69
70
71
72
73
74
75
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Admin::ServicesController do
  let(:admin) { create(:admin) }

  before do
    sign_in(admin)
  end

  describe 'GET #edit' do
    let(:service) do
      create(:jira_service, :template)
    end

    it 'successfully displays the template' do
      get :edit, params: { id: service.id }

      expect(response).to have_gitlab_http_status(:ok)
    end

    context 'when integration does not exists' do
      it 'redirects to the admin application integration page' do
        get :edit, params: { id: 'invalid' }

        expect(response).to redirect_to(admin_application_settings_services_path)
      end
    end

    context 'when instance integration exists' do
      before do
        create(:jira_service, :instance)
      end

      it 'redirects to the admin application integration page' do
        get :edit, params: { id: service.id }

        expect(response).to redirect_to(admin_application_settings_services_path)
      end
    end
  end

  describe "#update" do
    let(:project) { create(:project) }
    let!(:service_template) do
      RedmineService.create(
        project: nil,
        active: false,
        template: true,
        properties: {
          project_url: 'http://abc',
          issues_url: 'http://abc',
          new_issue_url: 'http://abc'
        }
      )
    end

    it 'calls the propagation worker when service is active' do
      expect(PropagateServiceTemplateWorker).to receive(:perform_async).with(service_template.id)

      put :update, params: { id: service_template.id, service: { active: true } }

      expect(response).to have_gitlab_http_status(:found)
    end

    it 'does not call the propagation worker when service is not active' do
      expect(PropagateServiceTemplateWorker).not_to receive(:perform_async)

      put :update, params: { id: service_template.id, service: { properties: {} } }

      expect(response).to have_gitlab_http_status(:found)
    end
  end
end