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