Merge branch 'zj-display-error-team-fetch' into 'master'
Fix inconsistent return type Closes #27150 See merge request !8290
This commit is contained in:
commit
e4bcdddfa7
6 changed files with 21 additions and 11 deletions
|
@ -34,7 +34,7 @@ class Projects::MattermostsController < Projects::ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
def teams
|
def teams
|
||||||
@teams ||= @service.list_teams(current_user)
|
@teams, @teams_error_message = @service.list_teams(current_user)
|
||||||
end
|
end
|
||||||
|
|
||||||
def service
|
def service
|
||||||
|
|
|
@ -28,8 +28,8 @@ class MattermostSlashCommandsService < ChatSlashCommandsService
|
||||||
[false, e.message]
|
[false, e.message]
|
||||||
end
|
end
|
||||||
|
|
||||||
def list_teams(user)
|
def list_teams(current_user)
|
||||||
Mattermost::Team.new(user).all
|
[Mattermost::Team.new(current_user).all, nil]
|
||||||
rescue Mattermost::Error => e
|
rescue Mattermost::Error => e
|
||||||
[[], e.message]
|
[[], e.message]
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,3 +1,7 @@
|
||||||
|
- if @teams_error_message
|
||||||
|
= content_for :flash_message do
|
||||||
|
.alert.alert-danger= @teams_error_message
|
||||||
|
|
||||||
%p
|
%p
|
||||||
You aren’t a member of any team on the Mattermost instance at
|
You aren’t a member of any team on the Mattermost instance at
|
||||||
%strong= Gitlab.config.mattermost.host
|
%strong= Gitlab.config.mattermost.host
|
||||||
|
|
|
@ -13,13 +13,13 @@ describe Projects::MattermostsController do
|
||||||
before do
|
before do
|
||||||
allow_any_instance_of(MattermostSlashCommandsService).
|
allow_any_instance_of(MattermostSlashCommandsService).
|
||||||
to receive(:list_teams).and_return([])
|
to receive(:list_teams).and_return([])
|
||||||
|
|
||||||
get(:new,
|
|
||||||
namespace_id: project.namespace.to_param,
|
|
||||||
project_id: project.to_param)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'accepts the request' do
|
it 'accepts the request' do
|
||||||
|
get(:new,
|
||||||
|
namespace_id: project.namespace.to_param,
|
||||||
|
project_id: project.to_param)
|
||||||
|
|
||||||
expect(response).to have_http_status(200)
|
expect(response).to have_http_status(200)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -99,6 +99,15 @@ feature 'Setup Mattermost slash commands', feature: true do
|
||||||
expect(select_element.all('option').count).to eq(3)
|
expect(select_element.all('option').count).to eq(3)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'shows an error alert with the error message if there is an error requesting teams' do
|
||||||
|
allow_any_instance_of(MattermostSlashCommandsService).to receive(:list_teams) { [[], 'test mattermost error message'] }
|
||||||
|
|
||||||
|
click_link 'Add to Mattermost'
|
||||||
|
|
||||||
|
expect(page).to have_selector('.alert')
|
||||||
|
expect(page).to have_content('test mattermost error message')
|
||||||
|
end
|
||||||
|
|
||||||
def stub_teams(count: 0)
|
def stub_teams(count: 0)
|
||||||
teams = create_teams(count)
|
teams = create_teams(count)
|
||||||
|
|
||||||
|
|
|
@ -113,10 +113,7 @@ describe MattermostSlashCommandsService, :models do
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'shows error messages' do
|
it 'shows error messages' do
|
||||||
teams, message = subject
|
expect(subject).to eq([[], "Failed to get team list."])
|
||||||
|
|
||||||
expect(teams).to be_empty
|
|
||||||
expect(message).to eq('Failed to get team list.')
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue