mattermosts_controller_spec.rb 1.49 KB
Newer Older
Z.J. van de Weg's avatar
Z.J. van de Weg committed
1
2
3
require 'spec_helper'

describe Projects::MattermostsController do
4
  let!(:project) { create(:project) }
Z.J. van de Weg's avatar
Z.J. van de Weg committed
5
6
7
  let!(:user) { create(:user) }

  before do
8
    project.add_maintainer(user)
Z.J. van de Weg's avatar
Z.J. van de Weg committed
9
10
11
12
13
    sign_in(user)
  end

  describe 'GET #new' do
    before do
14
15
      allow_any_instance_of(MattermostSlashCommandsService)
        .to receive(:list_teams).and_return([])
Z.J. van de Weg's avatar
Z.J. van de Weg committed
16
    end
Z.J. van de Weg's avatar
Z.J. van de Weg committed
17

Z.J. van de Weg's avatar
Z.J. van de Weg committed
18
    it 'accepts the request' do
Z.J. van de Weg's avatar
Z.J. van de Weg committed
19
20
      get(:new,
          namespace_id: project.namespace.to_param,
21
          project_id: project)
Z.J. van de Weg's avatar
Z.J. van de Weg committed
22

23
      expect(response).to have_gitlab_http_status(200)
Z.J. van de Weg's avatar
Z.J. van de Weg committed
24
25
26
27
28
29
30
31
32
    end
  end

  describe 'POST #create' do
    let(:mattermost_params) { { trigger: 'http://localhost:3000/trigger', team_id: 'abc' } }

    subject do
      post(:create,
           namespace_id: project.namespace.to_param,
33
           project_id: project,
Z.J. van de Weg's avatar
Z.J. van de Weg committed
34
35
36
37
38
           mattermost: mattermost_params)
    end

    context 'no request can be made to mattermost' do
      it 'shows the error' do
Z.J. van de Weg's avatar
Z.J. van de Weg committed
39
40
        allow_any_instance_of(MattermostSlashCommandsService).to receive(:configure).and_return([false, "error message"])

41
        expect(subject).to redirect_to(new_project_mattermost_url(project))
Z.J. van de Weg's avatar
Z.J. van de Weg committed
42
43
44
45
46
47
48
49
50
51
52
53
      end
    end

    context 'the request is succesull' do
      before do
        allow_any_instance_of(Mattermost::Command).to receive(:create).and_return('token')
      end

      it 'redirects to the new page' do
        subject
        service = project.services.last

54
        expect(subject).to redirect_to(edit_project_service_url(project, service))
Z.J. van de Weg's avatar
Z.J. van de Weg committed
55
56
57
58
      end
    end
  end
end