2019-02-20 16:29:48 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-24 05:08:32 -04:00
|
|
|
RSpec.describe Gitlab::Chat::Command do
|
2019-02-20 16:29:48 -05:00
|
|
|
let(:chat_name) { create(:chat_name) }
|
|
|
|
|
|
|
|
let(:command) do
|
|
|
|
described_class.new(
|
|
|
|
project: project,
|
|
|
|
chat_name: chat_name,
|
|
|
|
name: 'spinach',
|
|
|
|
arguments: 'foo',
|
|
|
|
channel: '123',
|
|
|
|
response_url: 'http://example.com'
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#try_create_pipeline' do
|
|
|
|
let(:project) { create(:project) }
|
|
|
|
|
|
|
|
it 'returns nil when the command is not valid' do
|
|
|
|
expect(command)
|
|
|
|
.to receive(:valid?)
|
|
|
|
.and_return(false)
|
|
|
|
|
|
|
|
expect(command.try_create_pipeline).to be_nil
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'tries to create the pipeline when a command is valid' do
|
|
|
|
expect(command)
|
|
|
|
.to receive(:valid?)
|
|
|
|
.and_return(true)
|
|
|
|
|
|
|
|
expect(command)
|
|
|
|
.to receive(:create_pipeline)
|
|
|
|
|
|
|
|
command.try_create_pipeline
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#create_pipeline' do
|
|
|
|
let(:project) { create(:project, :test_repo) }
|
|
|
|
let(:pipeline) { command.create_pipeline }
|
|
|
|
|
|
|
|
before do
|
2021-08-25 20:09:31 -04:00
|
|
|
stub_ci_pipeline_to_return_yaml_file
|
2019-02-20 16:29:48 -05:00
|
|
|
|
|
|
|
project.add_developer(chat_name.user)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'creates the pipeline' do
|
|
|
|
expect(pipeline).to be_persisted
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'creates the chat data for the pipeline' do
|
|
|
|
expect(pipeline.chat_data).to be_an_instance_of(Ci::PipelineChatData)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'stores the chat name ID in the chat data' do
|
|
|
|
expect(pipeline.chat_data.chat_name_id).to eq(chat_name.id)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'stores the response URL in the chat data' do
|
|
|
|
expect(pipeline.chat_data.response_url).to eq('http://example.com')
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'creates the environment variables for the pipeline' do
|
|
|
|
vars = pipeline.variables.each_with_object({}) do |row, hash|
|
|
|
|
hash[row.key] = row.value
|
|
|
|
end
|
|
|
|
|
|
|
|
expect(vars['CHAT_INPUT']).to eq('foo')
|
|
|
|
expect(vars['CHAT_CHANNEL']).to eq('123')
|
2021-09-29 02:09:19 -04:00
|
|
|
expect(vars['CHAT_USER_ID']).to eq(chat_name.chat_id)
|
2019-02-20 16:29:48 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|