2019-03-30 03:23:56 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-12-06 12:59:03 -05:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2017-07-10 10:24:02 -04:00
|
|
|
describe ChatNotificationService do
|
2017-04-18 05:50:04 -04:00
|
|
|
describe 'Associations' do
|
2016-12-06 12:59:03 -05:00
|
|
|
before do
|
|
|
|
allow(subject).to receive(:activated?).and_return(true)
|
|
|
|
end
|
|
|
|
|
|
|
|
it { is_expected.to validate_presence_of :webhook }
|
|
|
|
end
|
2017-04-18 05:50:04 -04:00
|
|
|
|
|
|
|
describe '#can_test?' do
|
|
|
|
context 'with empty repository' do
|
2017-04-24 11:23:51 -04:00
|
|
|
it 'returns true' do
|
2017-08-02 15:55:11 -04:00
|
|
|
subject.project = create(:project, :empty_repo)
|
2017-04-18 05:50:04 -04:00
|
|
|
|
2017-04-24 11:23:51 -04:00
|
|
|
expect(subject.can_test?).to be true
|
2017-04-18 05:50:04 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with repository' do
|
|
|
|
it 'returns true' do
|
2017-08-01 14:51:52 -04:00
|
|
|
subject.project = create(:project, :repository)
|
2017-04-18 05:50:04 -04:00
|
|
|
|
|
|
|
expect(subject.can_test?).to be true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2018-08-30 05:57:39 -04:00
|
|
|
|
|
|
|
describe '#execute' do
|
|
|
|
let(:chat_service) { described_class.new }
|
|
|
|
let(:user) { create(:user) }
|
|
|
|
let(:project) { create(:project, :repository) }
|
|
|
|
let(:webhook_url) { 'https://example.gitlab.com/' }
|
|
|
|
|
|
|
|
before do
|
|
|
|
allow(chat_service).to receive_messages(
|
|
|
|
project: project,
|
|
|
|
project_id: project.id,
|
|
|
|
service_hook: true,
|
|
|
|
webhook: webhook_url
|
|
|
|
)
|
|
|
|
|
|
|
|
WebMock.stub_request(:post, webhook_url)
|
|
|
|
|
|
|
|
subject.active = true
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with a repository' do
|
|
|
|
it 'returns true' do
|
|
|
|
subject.project = project
|
|
|
|
data = Gitlab::DataBuilder::Push.build_sample(project, user)
|
|
|
|
|
|
|
|
expect(Slack::Notifier).to receive(:new)
|
|
|
|
.with(webhook_url, {})
|
|
|
|
.and_return(
|
|
|
|
double(:slack_service).as_null_object
|
|
|
|
)
|
|
|
|
|
|
|
|
expect(chat_service.execute(data)).to be true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with an empty repository' do
|
|
|
|
it 'returns true' do
|
|
|
|
subject.project = create(:project, :empty_repo)
|
|
|
|
data = Gitlab::DataBuilder::Push.build_sample(subject.project, user)
|
|
|
|
|
|
|
|
expect(Slack::Notifier).to receive(:new)
|
|
|
|
.with(webhook_url, {})
|
|
|
|
.and_return(
|
|
|
|
double(:slack_service).as_null_object
|
|
|
|
)
|
|
|
|
|
|
|
|
expect(chat_service.execute(data)).to be true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2016-12-06 12:59:03 -05:00
|
|
|
end
|