2016-11-21 07:43:31 -05:00
|
|
|
|
require 'spec_helper'
|
|
|
|
|
|
2017-02-15 08:49:14 -05:00
|
|
|
|
feature 'Setup Mattermost slash commands', :feature, :js do
|
2016-11-21 07:43:31 -05:00
|
|
|
|
let(:user) { create(:user) }
|
2016-12-20 14:56:46 -05:00
|
|
|
|
let(:project) { create(:empty_project) }
|
2016-11-21 07:43:31 -05:00
|
|
|
|
let(:service) { project.create_mattermost_slash_commands_service }
|
2016-12-20 14:56:46 -05:00
|
|
|
|
let(:mattermost_enabled) { true }
|
2016-11-21 07:43:31 -05:00
|
|
|
|
|
|
|
|
|
before do
|
2017-03-28 08:12:32 -04:00
|
|
|
|
stub_mattermost_setting(enabled: mattermost_enabled)
|
2016-11-21 07:43:31 -05:00
|
|
|
|
project.team << [user, :master]
|
2017-06-21 19:44:10 -04:00
|
|
|
|
sign_in(user)
|
2017-07-06 12:20:50 -04:00
|
|
|
|
visit edit_project_service_path(project, service)
|
2016-11-21 07:43:31 -05:00
|
|
|
|
end
|
|
|
|
|
|
2017-01-08 09:19:19 -05:00
|
|
|
|
describe 'user visits the mattermost slash command config page' do
|
2016-11-21 07:43:31 -05:00
|
|
|
|
it 'shows a help message' do
|
2017-01-08 09:19:19 -05:00
|
|
|
|
expect(page).to have_content("This service allows users to perform common")
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it 'shows a token placeholder' do
|
|
|
|
|
token_placeholder = find_field('service_token')['placeholder']
|
2016-11-21 07:43:31 -05:00
|
|
|
|
|
2017-01-08 09:19:19 -05:00
|
|
|
|
expect(token_placeholder).to eq('XXxxXXxxXXxxXXxxXXxxXXxx')
|
2016-11-21 07:43:31 -05:00
|
|
|
|
end
|
|
|
|
|
|
2017-05-22 06:07:12 -04:00
|
|
|
|
it 'redirects to the integrations page after saving but not activating' do
|
2016-12-19 11:54:14 -05:00
|
|
|
|
token = ('a'..'z').to_a.join
|
2016-11-21 07:43:31 -05:00
|
|
|
|
|
|
|
|
|
fill_in 'service_token', with: token
|
2017-05-26 06:50:52 -04:00
|
|
|
|
click_on 'Save changes'
|
2016-11-21 07:43:31 -05:00
|
|
|
|
|
2017-07-06 12:20:50 -04:00
|
|
|
|
expect(current_path).to eq(project_settings_integrations_path(project))
|
2017-05-22 06:07:12 -04:00
|
|
|
|
expect(page).to have_content('Mattermost slash commands settings saved, but not activated.')
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it 'redirects to the integrations page after activating' do
|
|
|
|
|
token = ('a'..'z').to_a.join
|
|
|
|
|
|
|
|
|
|
fill_in 'service_token', with: token
|
|
|
|
|
check 'service_active'
|
2017-05-26 06:50:52 -04:00
|
|
|
|
click_on 'Save changes'
|
2016-11-21 07:43:31 -05:00
|
|
|
|
|
2017-07-06 12:20:50 -04:00
|
|
|
|
expect(current_path).to eq(project_settings_integrations_path(project))
|
2017-05-26 06:50:52 -04:00
|
|
|
|
expect(page).to have_content('Mattermost slash commands activated.')
|
2016-11-21 07:43:31 -05:00
|
|
|
|
end
|
|
|
|
|
|
2016-12-22 15:20:12 -05:00
|
|
|
|
it 'shows the add to mattermost button' do
|
|
|
|
|
expect(page).to have_link('Add to Mattermost')
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it 'shows an explanation if user is a member of no teams' do
|
|
|
|
|
stub_teams(count: 0)
|
|
|
|
|
|
|
|
|
|
click_link 'Add to Mattermost'
|
|
|
|
|
|
|
|
|
|
expect(page).to have_content('You aren’t a member of any team on the Mattermost instance')
|
|
|
|
|
expect(page).to have_link('join a team', href: "#{Gitlab.config.mattermost.host}/select_team")
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it 'shows an explanation if user is a member of 1 team' do
|
|
|
|
|
stub_teams(count: 1)
|
|
|
|
|
|
|
|
|
|
click_link 'Add to Mattermost'
|
|
|
|
|
|
|
|
|
|
expect(page).to have_content('The team where the slash commands will be used in')
|
|
|
|
|
expect(page).to have_content('This is the only available team.')
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it 'shows a disabled prefilled select if user is a member of 1 team' do
|
|
|
|
|
teams = stub_teams(count: 1)
|
|
|
|
|
|
|
|
|
|
click_link 'Add to Mattermost'
|
|
|
|
|
|
2017-02-15 08:49:14 -05:00
|
|
|
|
team_name = teams.first['display_name']
|
|
|
|
|
select_element = find('#mattermost_team_id')
|
2016-12-22 15:20:12 -05:00
|
|
|
|
selected_option = select_element.find('option[selected]')
|
|
|
|
|
|
2017-02-15 08:49:14 -05:00
|
|
|
|
expect(select_element['disabled']).to be(true)
|
2016-12-22 15:20:12 -05:00
|
|
|
|
expect(selected_option).to have_content(team_name.to_s)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it 'has a hidden input for the prefilled value if user is a member of 1 team' do
|
|
|
|
|
teams = stub_teams(count: 1)
|
|
|
|
|
|
|
|
|
|
click_link 'Add to Mattermost'
|
|
|
|
|
|
2017-02-15 08:49:14 -05:00
|
|
|
|
expect(find('input#mattermost_team_id', visible: false).value).to eq(teams.first['id'])
|
2016-12-22 15:20:12 -05:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it 'shows an explanation user is a member of multiple teams' do
|
|
|
|
|
stub_teams(count: 2)
|
|
|
|
|
|
|
|
|
|
click_link 'Add to Mattermost'
|
|
|
|
|
|
|
|
|
|
expect(page).to have_content('Select the team where the slash commands will be used in')
|
|
|
|
|
expect(page).to have_content('The list shows all available teams.')
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it 'shows a select with team options user is a member of multiple teams' do
|
|
|
|
|
stub_teams(count: 2)
|
|
|
|
|
|
|
|
|
|
click_link 'Add to Mattermost'
|
|
|
|
|
|
2017-02-15 08:49:14 -05:00
|
|
|
|
select_element = find('#mattermost_team_id')
|
2016-12-22 15:20:12 -05:00
|
|
|
|
|
2017-02-15 08:49:14 -05:00
|
|
|
|
expect(select_element['disabled']).to be(false)
|
2016-12-22 15:20:12 -05:00
|
|
|
|
expect(select_element.all('option').count).to eq(3)
|
|
|
|
|
end
|
|
|
|
|
|
2017-01-24 12:54:30 -05:00
|
|
|
|
it 'shows an error alert with the error message if there is an error requesting teams' do
|
2017-01-30 08:59:13 -05:00
|
|
|
|
allow_any_instance_of(MattermostSlashCommandsService).to receive(:list_teams) { [[], 'test mattermost error message'] }
|
2017-01-24 12:54:30 -05:00
|
|
|
|
|
|
|
|
|
click_link 'Add to Mattermost'
|
|
|
|
|
|
|
|
|
|
expect(page).to have_selector('.alert')
|
|
|
|
|
expect(page).to have_content('test mattermost error message')
|
|
|
|
|
end
|
|
|
|
|
|
2017-02-15 08:49:14 -05:00
|
|
|
|
it 'enables the submit button if the required fields are provided', :js do
|
|
|
|
|
stub_teams(count: 1)
|
|
|
|
|
|
|
|
|
|
click_link 'Add to Mattermost'
|
|
|
|
|
|
|
|
|
|
expect(find('input[type="submit"]')['disabled']).not_to be(true)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it 'disables the submit button if the required fields are not provided', :js do
|
|
|
|
|
stub_teams(count: 1)
|
|
|
|
|
|
|
|
|
|
click_link 'Add to Mattermost'
|
|
|
|
|
|
|
|
|
|
fill_in('mattermost_trigger', with: '')
|
|
|
|
|
|
|
|
|
|
expect(find('input[type="submit"]')['disabled']).to be(true)
|
|
|
|
|
end
|
|
|
|
|
|
2016-12-22 15:20:12 -05:00
|
|
|
|
def stub_teams(count: 0)
|
|
|
|
|
teams = create_teams(count)
|
|
|
|
|
|
2017-02-15 08:49:14 -05:00
|
|
|
|
allow_any_instance_of(MattermostSlashCommandsService).to receive(:list_teams) { [teams, nil] }
|
2016-12-22 15:20:12 -05:00
|
|
|
|
|
|
|
|
|
teams
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def create_teams(count = 0)
|
2017-02-15 08:49:14 -05:00
|
|
|
|
teams = []
|
2016-12-22 15:20:12 -05:00
|
|
|
|
|
|
|
|
|
count.times do |i|
|
2017-02-15 08:49:14 -05:00
|
|
|
|
teams.push({ "id" => "x#{i}", "display_name" => "x#{i}-name" })
|
2016-12-19 11:54:14 -05:00
|
|
|
|
end
|
2016-12-22 15:20:12 -05:00
|
|
|
|
|
|
|
|
|
teams
|
2016-12-19 11:54:14 -05:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
describe 'mattermost service is not enabled' do
|
2016-12-20 14:56:46 -05:00
|
|
|
|
let(:mattermost_enabled) { false }
|
2016-12-19 11:54:14 -05:00
|
|
|
|
|
|
|
|
|
it 'shows the correct trigger url' do
|
|
|
|
|
value = find_field('request_url').value
|
2016-11-21 07:43:31 -05:00
|
|
|
|
|
2017-07-18 16:32:40 -04:00
|
|
|
|
expect(value).to match("api/v4/projects/#{project.id}/services/mattermost_slash_commands/trigger")
|
2016-12-19 11:54:14 -05:00
|
|
|
|
end
|
2017-01-08 09:19:19 -05:00
|
|
|
|
|
|
|
|
|
it 'shows a token placeholder' do
|
|
|
|
|
token_placeholder = find_field('service_token')['placeholder']
|
|
|
|
|
|
|
|
|
|
expect(token_placeholder).to eq('XXxxXXxxXXxxXXxxXXxxXXxx')
|
|
|
|
|
end
|
2016-11-21 07:43:31 -05:00
|
|
|
|
end
|
|
|
|
|
end
|
2016-12-29 04:58:27 -05:00
|
|
|
|
|
|
|
|
|
describe 'stable logo url' do
|
|
|
|
|
it 'shows a publicly available logo' do
|
|
|
|
|
expect(File.exist?(Rails.root.join('public/slash-command-logo.png')))
|
|
|
|
|
end
|
|
|
|
|
end
|
2016-11-21 07:43:31 -05:00
|
|
|
|
end
|