Commit 2ae8a1e7 authored by Alex Kalderimis's avatar Alex Kalderimis

Rename mattermost slack commands integration

Rename project association from mattermost_slash_commands_service to
mattermost_slash_commands_integration
parent 80c120dc
......@@ -175,7 +175,7 @@ class Project < ApplicationRecord
has_one :jenkins_service, class_name: 'Integrations::Jenkins'
has_one :jira_service, class_name: 'Integrations::Jira'
has_one :mattermost_integration, class_name: 'Integrations::Mattermost'
has_one :mattermost_slash_commands_service, class_name: 'Integrations::MattermostSlashCommands'
has_one :mattermost_slash_commands_integration, class_name: 'Integrations::MattermostSlashCommands'
has_one :microsoft_teams_service, class_name: 'Integrations::MicrosoftTeams'
has_one :mock_ci_service, class_name: 'Integrations::MockCi'
has_one :packagist_integration, class_name: 'Integrations::Packagist'
......
......@@ -368,7 +368,7 @@ project:
- drone_ci_integration
- emails_on_push_integration
- pipelines_email_integration
- mattermost_slash_commands_service
- mattermost_slash_commands_integration
- slack_slash_commands_service
- irker_integration
- packagist_integration
......
......@@ -5,27 +5,30 @@ require 'spec_helper'
RSpec.describe Integrations::MattermostSlashCommands do
it_behaves_like Integrations::BaseSlashCommands
context 'Mattermost API' do
describe 'Mattermost API' do
let(:project) { create(:project) }
let(:service) { project.build_mattermost_slash_commands_service }
let(:integration) { project.build_mattermost_slash_commands_integration }
let(:user) { create(:user) }
before do
session = ::Mattermost::Session.new(nil)
session.base_uri = 'http://mattermost.example.com'
allow_any_instance_of(::Mattermost::Client).to receive(:with_session)
.and_yield(session)
allow_next_instance_of(::Mattermost::Client) do |client|
allow(client).to receive(:with_session).and_yield(session)
end
end
describe '#configure' do
subject do
service.configure(user, team_id: 'abc',
trigger: 'gitlab', url: 'http://trigger.url',
integration.configure(user,
team_id: 'abc',
trigger: 'gitlab',
url: 'http://trigger.url',
icon_url: 'http://icon.url/icon.png')
end
context 'the requests succeeds' do
context 'when the request succeeds' do
before do
stub_request(:post, 'http://mattermost.example.com/api/v4/commands')
.with(body: {
......@@ -48,18 +51,18 @@ RSpec.describe Integrations::MattermostSlashCommands do
)
end
it 'saves the service' do
it 'saves the integration' do
expect { subject }.to change { project.integrations.count }.by(1)
end
it 'saves the token' do
subject
expect(service.reload.token).to eq('token')
expect(integration.reload.token).to eq('token')
end
end
context 'an error is received' do
context 'when an error is received' do
before do
stub_request(:post, 'http://mattermost.example.com/api/v4/commands')
.to_return(
......@@ -86,10 +89,10 @@ RSpec.describe Integrations::MattermostSlashCommands do
describe '#list_teams' do
subject do
service.list_teams(user)
integration.list_teams(user)
end
context 'the requests succeeds' do
context 'when the request succeeds' do
before do
stub_request(:get, 'http://mattermost.example.com/api/v4/users/me/teams')
.to_return(
......@@ -104,7 +107,7 @@ RSpec.describe Integrations::MattermostSlashCommands do
end
end
context 'an error is received' do
context 'when an error is received' do
before do
stub_request(:get, 'http://mattermost.example.com/api/v4/users/me/teams')
.to_return(
......
......@@ -56,7 +56,7 @@ RSpec.describe Project, factory_default: :keep do
it { is_expected.to have_one(:flowdock_integration) }
it { is_expected.to have_one(:assembla_integration) }
it { is_expected.to have_one(:slack_slash_commands_service) }
it { is_expected.to have_one(:mattermost_slash_commands_service) }
it { is_expected.to have_one(:mattermost_slash_commands_integration) }
it { is_expected.to have_one(:buildkite_integration) }
it { is_expected.to have_one(:bamboo_integration) }
it { is_expected.to have_one(:teamcity_service) }
......
......@@ -179,10 +179,10 @@ RSpec.describe API::Services do
end
describe 'POST /projects/:id/services/:slug/trigger' do
describe 'Mattermost Service' do
let(:service_name) { 'mattermost_slash_commands' }
describe 'Mattermost integration' do
let(:integration_name) { 'mattermost_slash_commands' }
context 'no service is available' do
context 'when no integration is available' do
it 'returns a not found message' do
post api("/projects/#{project.id}/services/idonotexist/trigger")
......@@ -191,34 +191,34 @@ RSpec.describe API::Services do
end
end
context 'the service exists' do
context 'when the integration exists' do
let(:params) { { token: 'token' } }
context 'the service is not active' do
context 'when the integration is not active' do
before do
project.create_mattermost_slash_commands_service(
project.create_mattermost_slash_commands_integration(
active: false,
properties: params
)
end
it 'when the service is inactive' do
post api("/projects/#{project.id}/services/#{service_name}/trigger"), params: params
it 'when the integration is inactive' do
post api("/projects/#{project.id}/services/#{integration_name}/trigger"), params: params
expect(response).to have_gitlab_http_status(:not_found)
end
end
context 'the service is active' do
context 'when the integration is active' do
before do
project.create_mattermost_slash_commands_service(
project.create_mattermost_slash_commands_integration(
active: true,
properties: params
)
end
it 'returns status 200' do
post api("/projects/#{project.id}/services/#{service_name}/trigger"), params: params
post api("/projects/#{project.id}/services/#{integration_name}/trigger"), params: params
expect(response).to have_gitlab_http_status(:ok)
end
......@@ -226,7 +226,7 @@ RSpec.describe API::Services do
context 'when the project can not be found' do
it 'returns a generic 404' do
post api("/projects/404/services/#{service_name}/trigger"), params: params
post api("/projects/404/services/#{integration_name}/trigger"), params: params
expect(response).to have_gitlab_http_status(:not_found)
expect(json_response["message"]).to eq("404 Service Not Found")
......
......@@ -66,14 +66,14 @@ RSpec.shared_examples Integrations::BaseSlashCommands do
}
end
let(:service) do
project.create_mattermost_slash_commands_service(
let(:integration) do
project.create_mattermost_slash_commands_integration(
properties: { token: 'token' }
)
end
it 'generates the url' do
response = service.trigger(params)
response = integration.trigger(params)
expect(response[:text]).to start_with(':wave: Hi there!')
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