2016-12-20 16:30:06 -05:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
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
|
|
|
|
project.team << [user, :master]
|
|
|
|
sign_in(user)
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'GET #new' do
|
|
|
|
before do
|
2017-06-21 09:48:12 -04:00
|
|
|
allow_any_instance_of(MattermostSlashCommandsService)
|
|
|
|
.to receive(:list_teams).and_return([])
|
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,
|
|
|
|
namespace_id: project.namespace.to_param,
|
2017-02-23 18:55:01 -05:00
|
|
|
project_id: project)
|
2016-12-20 16:30:06 -05:00
|
|
|
|
|
|
|
expect(response).to have_http_status(200)
|
|
|
|
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,
|
2017-02-23 18:55:01 -05:00
|
|
|
project_id: project,
|
2016-12-20 16:30:06 -05:00
|
|
|
mattermost: mattermost_params)
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'no request can be made to mattermost' do
|
|
|
|
it 'shows the error' do
|
2016-12-21 07:34:24 -05:00
|
|
|
allow_any_instance_of(MattermostSlashCommandsService).to receive(:configure).and_return([false, "error message"])
|
|
|
|
|
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
|
|
|
|
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
|
|
|
|
|
2017-06-29 13:06:35 -04:00
|
|
|
expect(subject).to redirect_to(edit_project_service_url(project, service))
|
2016-12-20 16:30:06 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|