debian-mirror-gitlab/spec/lib/mattermost/command_spec.rb

65 lines
1.8 KiB
Ruby
Raw Normal View History

2019-12-04 20:38:33 +05:30
# frozen_string_literal: true
2017-08-17 22:00:37 +05:30
require 'spec_helper'
2020-07-28 23:09:34 +05:30
RSpec.describe Mattermost::Command do
2017-08-17 22:00:37 +05:30
let(:params) { { 'token' => 'token', team_id: 'abc' } }
before do
2018-03-26 14:24:53 +05:30
session = Mattermost::Session.new(nil)
session.base_uri = 'http://mattermost.example.com'
2017-08-17 22:00:37 +05:30
2017-09-10 17:25:29 +05:30
allow_any_instance_of(Mattermost::Client).to receive(:with_session)
2018-03-26 14:24:53 +05:30
.and_yield(session)
2017-08-17 22:00:37 +05:30
end
describe '#create' do
let(:params) do
{ team_id: 'abc',
trigger: 'gitlab' }
end
2021-04-29 21:17:54 +05:30
subject { described_class.new(nil).create(params) } # rubocop:disable Rails/SaveBang
2017-08-17 22:00:37 +05:30
context 'for valid trigger word' do
before do
2018-11-08 19:23:39 +05:30
stub_request(:post, 'http://mattermost.example.com/api/v4/commands')
2017-09-10 17:25:29 +05:30
.with(body: {
2017-08-17 22:00:37 +05:30
team_id: 'abc',
trigger: 'gitlab'
2017-09-10 17:25:29 +05:30
}.to_json)
.to_return(
2018-11-08 19:23:39 +05:30
status: 201,
2017-08-17 22:00:37 +05:30
headers: { 'Content-Type' => 'application/json' },
body: { token: 'token' }.to_json
)
end
it 'returns a token' do
is_expected.to eq('token')
end
end
context 'for error message' do
before do
2018-11-08 19:23:39 +05:30
stub_request(:post, 'http://mattermost.example.com/api/v4/commands')
2017-09-10 17:25:29 +05:30
.to_return(
2018-11-08 19:23:39 +05:30
status: 400,
2017-08-17 22:00:37 +05:30
headers: { 'Content-Type' => 'application/json' },
body: {
id: 'api.command.duplicate_trigger.app_error',
message: 'This trigger word is already in use. Please choose another word.',
detailed_error: '',
request_id: 'obc374man7bx5r3dbc1q5qhf3r',
2018-11-08 19:23:39 +05:30
status_code: 400
2017-08-17 22:00:37 +05:30
}.to_json
)
end
it 'raises an error with message' do
expect { subject }.to raise_error(Mattermost::Error, 'This trigger word is already in use. Please choose another word.')
end
end
end
end