1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
|
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Projects::ServiceDeskController do
let_it_be(:project) do
create(:project, :private, :custom_repo,
service_desk_enabled: true,
files: { '.gitlab/issue_templates/service_desk.md' => 'template' })
end
let_it_be(:user) { create(:user) }
before do
allow(Gitlab::Email::IncomingEmail).to receive(:enabled?) { true }
allow(Gitlab::Email::IncomingEmail).to receive(:supports_wildcard?) { true }
project.add_maintainer(user)
sign_in(user)
end
describe 'GET service desk properties' do
it 'returns service_desk JSON data' do
get :show, params: { namespace_id: project.namespace.to_param, project_id: project }, format: :json
expect(json_response["service_desk_address"]).to match(/\A[^@]+@[^@]+\z/)
expect(json_response["service_desk_enabled"]).to be_truthy
expect(response).to have_gitlab_http_status(:ok)
end
context 'when user is not project maintainer' do
let(:guest) { create(:user) }
it 'renders 404' do
project.add_guest(guest)
sign_in(guest)
get :show, params: { namespace_id: project.namespace.to_param, project_id: project }, format: :json
expect(response).to have_gitlab_http_status(:not_found)
end
end
context 'when issue template is present' do
it 'returns template_file_missing as false' do
create(:service_desk_setting, project: project, issue_template_key: 'service_desk')
get :show, params: { namespace_id: project.namespace.to_param, project_id: project }, format: :json
response_hash = Gitlab::Json.parse(response.body)
expect(response_hash['template_file_missing']).to eq(false)
end
end
context 'when issue template file becomes outdated' do
it 'returns template_file_missing as true' do
service = ServiceDeskSetting.new(project_id: project.id, issue_template_key: 'deleted')
service.save!(validate: false)
get :show, params: { namespace_id: project.namespace.to_param, project_id: project }, format: :json
expect(json_response['template_file_missing']).to eq(true)
end
end
end
describe 'PUT service desk properties' do
it 'toggles services desk incoming email' do
project.update!(service_desk_enabled: false)
put :update, params: { namespace_id: project.namespace.to_param,
project_id: project,
service_desk_enabled: true }, format: :json
expect(json_response["service_desk_address"]).to be_present
expect(json_response["service_desk_enabled"]).to be_truthy
expect(response).to have_gitlab_http_status(:ok)
end
it 'sets issue_template_key' do
put :update, params: { namespace_id: project.namespace.to_param,
project_id: project,
issue_template_key: 'service_desk' }, format: :json
settings = project.service_desk_setting
expect(settings).to be_present
expect(settings.issue_template_key).to eq('service_desk')
expect(json_response['template_file_missing']).to eq(false)
expect(json_response['issue_template_key']).to eq('service_desk')
end
it 'returns an error when update of service desk settings fails' do
put :update, params: { namespace_id: project.namespace.to_param,
project_id: project,
issue_template_key: 'invalid key' }, format: :json
expect(response).to have_gitlab_http_status(:unprocessable_entity)
expect(json_response['message']).to eq('Issue template key is empty or does not exist')
end
context 'when user cannot admin the project' do
let(:other_user) { create(:user) }
it 'renders 404' do
sign_in(other_user)
put :update, params: { namespace_id: project.namespace.to_param, project_id: project, service_desk_enabled: true }, format: :json
expect(response).to have_gitlab_http_status(:not_found)
end
end
end
end
|