Commit b1cd9add authored by Kamil Trzciński's avatar Kamil Trzciński

Merge branch 'zj-404-slack-error' into 'master'

Add API route slack slash commands

Closes #25954

See merge request !8362
parents aec04a47 dfca704d
...@@ -543,6 +543,13 @@ module API ...@@ -543,6 +543,13 @@ module API
type: String, type: String,
desc: 'The Mattermost token' desc: 'The Mattermost token'
} }
],
'slack-slash-commands' => [
{
name: :token,
type: String,
desc: 'The Slack token'
}
] ]
}.freeze }.freeze
......
...@@ -6,7 +6,7 @@ describe API::Services, api: true do ...@@ -6,7 +6,7 @@ describe API::Services, api: true do
let(:user) { create(:user) } let(:user) { create(:user) }
let(:admin) { create(:admin) } let(:admin) { create(:admin) }
let(:user2) { create(:user) } 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| Service.available_services_names.each do |service|
describe "PUT /projects/:id/services/#{service.dasherize}" do describe "PUT /projects/:id/services/#{service.dasherize}" do
...@@ -92,6 +92,8 @@ describe API::Services, api: true do ...@@ -92,6 +92,8 @@ describe API::Services, api: true do
describe 'POST /projects/:id/services/:slug/trigger' do describe 'POST /projects/:id/services/:slug/trigger' do
let!(:project) { create(:empty_project) } let!(:project) { create(:empty_project) }
describe 'Mattermost Service' do
let(:service_name) { 'mattermost_slash_commands' } let(:service_name) { 'mattermost_slash_commands' }
context 'no service is available' do context 'no service is available' do
...@@ -107,30 +109,30 @@ describe API::Services, api: true do ...@@ -107,30 +109,30 @@ describe API::Services, api: true do
let(:params) { { token: 'token' } } let(:params) { { token: 'token' } }
context 'the service is not active' do context 'the service is not active' do
let!(:inactive_service) do before do
project.create_mattermost_slash_commands_service( project.create_mattermost_slash_commands_service(
active: false, active: false,
properties: { token: 'token' } properties: params
) )
end end
it 'when the service is inactive' do it 'when the service is inactive' do
post api("/projects/#{project.id}/services/mattermost_slash_commands/trigger"), params 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 end
context 'the service is active' do context 'the service is active' do
let!(:active_service) do before do
project.create_mattermost_slash_commands_service( project.create_mattermost_slash_commands_service(
active: true, active: true,
properties: { token: 'token' } properties: params
) )
end end
it 'returns status 200' do it 'returns status 200' do
post api("/projects/#{project.id}/services/mattermost_slash_commands/trigger"), params post api("/projects/#{project.id}/services/#{service_name}/trigger"), params
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
end end
...@@ -138,7 +140,7 @@ describe API::Services, api: true do ...@@ -138,7 +140,7 @@ describe API::Services, api: true do
context 'when the project can not be found' do context 'when the project can not be found' do
it 'returns a generic 404' do it 'returns a generic 404' do
post api("/projects/404/services/mattermost_slash_commands/trigger"), params post api("/projects/404/services/#{service_name}/trigger"), params
expect(response).to have_http_status(404) expect(response).to have_http_status(404)
expect(json_response["message"]).to eq("404 Service Not Found") expect(json_response["message"]).to eq("404 Service Not Found")
...@@ -146,4 +148,23 @@ describe API::Services, api: true do ...@@ -146,4 +148,23 @@ describe API::Services, api: true do
end end
end end
end end
describe 'Slack Service' do
let(:service_name) { 'slack_slash_commands' }
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
end end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment