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