2019-04-15 06:17:05 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-12-20 16:30:06 -05:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-03 14:08:28 -04:00
|
|
|
RSpec.describe Projects::MattermostsController do
|
2017-08-02 15:55:11 -04:00
|
|
|
let!(:project) { create(:project) }
|
2016-12-20 16:30:06 -05:00
|
|
|
let!(:user) { create(:user) }
|
|
|
|
|
|
|
|
before do
|
2018-07-11 10:36:08 -04:00
|
|
|
project.add_maintainer(user)
|
2016-12-20 16:30:06 -05:00
|
|
|
sign_in(user)
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'GET #new' do
|
|
|
|
before do
|
2021-06-03 05:10:18 -04:00
|
|
|
allow_next_instance_of(Integrations::MattermostSlashCommands) do |instance|
|
2019-11-13 22:06:25 -05:00
|
|
|
allow(instance).to receive(:list_teams).and_return([])
|
|
|
|
end
|
2016-12-23 05:13:30 -05:00
|
|
|
end
|
2016-12-21 07:34:24 -05:00
|
|
|
|
2016-12-23 05:13:30 -05:00
|
|
|
it 'accepts the request' do
|
2016-12-20 16:30:06 -05:00
|
|
|
get(:new,
|
2018-12-17 17:52:17 -05:00
|
|
|
params: {
|
|
|
|
namespace_id: project.namespace.to_param,
|
|
|
|
project_id: project
|
|
|
|
})
|
2016-12-20 16:30:06 -05:00
|
|
|
|
2020-01-28 07:08:44 -05:00
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
2016-12-20 16:30:06 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'POST #create' do
|
|
|
|
let(:mattermost_params) { { trigger: 'http://localhost:3000/trigger', team_id: 'abc' } }
|
|
|
|
|
|
|
|
subject do
|
|
|
|
post(:create,
|
2018-12-17 17:52:17 -05:00
|
|
|
params: {
|
|
|
|
namespace_id: project.namespace.to_param,
|
|
|
|
project_id: project,
|
|
|
|
mattermost: mattermost_params
|
|
|
|
})
|
2016-12-20 16:30:06 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'no request can be made to mattermost' do
|
|
|
|
it 'shows the error' do
|
2021-06-03 05:10:18 -04:00
|
|
|
allow_next_instance_of(Integrations::MattermostSlashCommands) do |instance|
|
2019-11-13 22:06:25 -05:00
|
|
|
allow(instance).to receive(:configure).and_return([false, "error message"])
|
|
|
|
end
|
2016-12-21 07:34:24 -05:00
|
|
|
|
2017-06-29 13:06:35 -04:00
|
|
|
expect(subject).to redirect_to(new_project_mattermost_url(project))
|
2016-12-20 16:30:06 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'the request is succesull' do
|
|
|
|
before do
|
2021-05-31 23:10:06 -04:00
|
|
|
allow_next_instance_of(::Mattermost::Command) do |instance|
|
2019-11-13 22:06:25 -05:00
|
|
|
allow(instance).to receive(:create).and_return('token')
|
|
|
|
end
|
2016-12-20 16:30:06 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'redirects to the new page' do
|
|
|
|
subject
|
2021-12-30 13:13:34 -05:00
|
|
|
integration = project.integrations.last
|
2016-12-20 16:30:06 -05:00
|
|
|
|
2022-05-25 14:08:15 -04:00
|
|
|
expect(subject).to redirect_to(edit_project_settings_integration_path(project, integration))
|
2016-12-20 16:30:06 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|