summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZ.J. van de Weg <git@zjvandeweg.nl>2016-12-29 10:48:18 +0100
committerZ.J. van de Weg <git@zjvandeweg.nl>2017-01-03 20:34:35 +0100
commitdfca704d6a30db04f4d9bb0d246198dca04a638c (patch)
tree1cc2be226795b502a2a0fdb6c9b2d2e72ca6a23c
parent365612ce3602858c51902e735d0daea6e1987ba8 (diff)
downloadgitlab-ce-zj-404-slack-error.tar.gz
Add API route slack slash commandszj-404-slack-error
-rw-r--r--lib/api/services.rb7
-rw-r--r--spec/requests/api/services_spec.rb93
2 files changed, 64 insertions, 36 deletions
diff --git a/lib/api/services.rb b/lib/api/services.rb
index d11cdce4e18..3a9dfbb237c 100644
--- a/lib/api/services.rb
+++ b/lib/api/services.rb
@@ -543,6 +543,13 @@ module API
type: String,
desc: 'The Mattermost token'
}
+ ],
+ 'slack-slash-commands' => [
+ {
+ name: :token,
+ type: String,
+ desc: 'The Slack token'
+ }
]
}.freeze
diff --git a/spec/requests/api/services_spec.rb b/spec/requests/api/services_spec.rb
index 668e39f9dba..39c9e0505d1 100644
--- a/spec/requests/api/services_spec.rb
+++ b/spec/requests/api/services_spec.rb
@@ -6,7 +6,7 @@ describe API::Services, api: true do
let(:user) { create(:user) }
let(:admin) { create(:admin) }
let(:user2) { create(:user) }
- let(:project) {create(:project, creator_id: user.id, namespace: user.namespace) }
+ let(:project) {create(:empty_project, creator_id: user.id, namespace: user.namespace) }
Service.available_services_names.each do |service|
describe "PUT /projects/:id/services/#{service.dasherize}" do
@@ -92,57 +92,78 @@ describe API::Services, api: true do
describe 'POST /projects/:id/services/:slug/trigger' do
let!(:project) { create(:empty_project) }
- let(:service_name) { 'mattermost_slash_commands' }
- context 'no service is available' do
- it 'returns a not found message' do
- post api("/projects/#{project.id}/services/idonotexist/trigger")
+ describe 'Mattermost Service' do
+ let(:service_name) { 'mattermost_slash_commands' }
- expect(response).to have_http_status(404)
- expect(json_response["error"]).to eq("404 Not Found")
+ context 'no service is available' do
+ it 'returns a not found message' do
+ post api("/projects/#{project.id}/services/idonotexist/trigger")
+
+ expect(response).to have_http_status(404)
+ expect(json_response["error"]).to eq("404 Not Found")
+ end
end
- end
- context 'the service exists' do
- let(:params) { { token: 'token' } }
+ context 'the service exists' do
+ let(:params) { { token: 'token' } }
- context 'the service is not active' do
- let!(:inactive_service) do
- project.create_mattermost_slash_commands_service(
- active: false,
- properties: { token: 'token' }
- )
- end
+ context 'the service is not active' do
+ before do
+ project.create_mattermost_slash_commands_service(
+ active: false,
+ properties: params
+ )
+ end
- it 'when the service is inactive' do
- post api("/projects/#{project.id}/services/mattermost_slash_commands/trigger"), params
+ it 'when the service is inactive' do
+ post api("/projects/#{project.id}/services/#{service_name}/trigger"), params
- expect(response).to have_http_status(404)
+ expect(response).to have_http_status(404)
+ end
end
- end
- context 'the service is active' do
- let!(:active_service) do
- project.create_mattermost_slash_commands_service(
- active: true,
- properties: { token: 'token' }
- )
+ context 'the service is active' do
+ before do
+ project.create_mattermost_slash_commands_service(
+ active: true,
+ properties: params
+ )
+ end
+
+ it 'returns status 200' do
+ post api("/projects/#{project.id}/services/#{service_name}/trigger"), params
+
+ expect(response).to have_http_status(200)
+ end
end
- it 'returns status 200' do
- post api("/projects/#{project.id}/services/mattermost_slash_commands/trigger"), params
+ context 'when the project can not be found' do
+ it 'returns a generic 404' do
+ post api("/projects/404/services/#{service_name}/trigger"), params
- expect(response).to have_http_status(200)
+ expect(response).to have_http_status(404)
+ expect(json_response["message"]).to eq("404 Service Not Found")
+ end
end
end
+ end
- context 'when the project can not be found' do
- it 'returns a generic 404' do
- post api("/projects/404/services/mattermost_slash_commands/trigger"), params
+ describe 'Slack Service' do
+ let(:service_name) { 'slack_slash_commands' }
- expect(response).to have_http_status(404)
- expect(json_response["message"]).to eq("404 Service Not Found")
- end
+ before do
+ project.create_slack_slash_commands_service(
+ active: true,
+ properties: { token: 'token' }
+ )
+ end
+
+ it 'returns status 200' do
+ post api("/projects/#{project.id}/services/#{service_name}/trigger"), token: 'token', text: 'help'
+
+ expect(response).to have_http_status(200)
+ expect(json_response['response_type']).to eq("ephemeral")
end
end
end