Commit 185451c9 authored by Justin Ho's avatar Justin Ho

Allow multiple Slack channels for notifications

parent 4c595e9d
......@@ -84,10 +84,10 @@ class ChatNotificationService < Service
event_type = data[:event_type] || object_kind
channel_name = get_channel_field(event_type).presence || channel
channel_names = get_channel_field(event_type).presence || channel
opts = {}
opts[:channel] = channel_name if channel_name
opts[:channel] = channel_names.split(',').map(&:strip) if channel_names
opts[:username] = username if username
return false unless notify(message, opts)
......
---
title: Allow multiple Slack channels for notifications
merge_request: 24132
author:
type: added
......@@ -74,5 +74,41 @@ describe ChatNotificationService do
chat_service.execute(data)
end
end
context 'with channel specified' do
let(:channel1) { 'slack-integration' }
let(:channel2) { '#slack-test' }
before do
allow(chat_service).to receive(:push_channel).and_return(channel)
end
context 'with single channel name' do
let(:channel) { channel1 }
it 'notifies one channel' do
expect(chat_service).to receive(:notify).with(any_args, hash_including(channel: [channel1])).and_return(true)
expect(chat_service.execute(data)).to be(true)
end
end
context 'with multiple channel names' do
let(:channel) { [channel1, channel2].join(',') }
it 'notifies all channels' do
expect(chat_service).to receive(:notify).with(any_args, hash_including(channel: [channel1, channel2])).and_return(true)
expect(chat_service.execute(data)).to be(true)
end
end
context 'with multiple channel names with spaces' do
let(:channel) { [channel1, channel2].join(', ') }
it 'notifies all channels' do
expect(chat_service).to receive(:notify).with(any_args, hash_including(channel: [channel1, channel2])).and_return(true)
expect(chat_service.execute(data)).to be(true)
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