debian-mirror-gitlab/spec/models/project_services/chat_notification_service_spec.rb

79 lines
2 KiB
Ruby
Raw Normal View History

2019-07-07 11:18:12 +05:30
# frozen_string_literal: true
2017-08-17 22:00:37 +05:30
require 'spec_helper'
2017-09-10 17:25:29 +05:30
describe ChatNotificationService do
2017-08-17 22:00:37 +05:30
describe 'Associations' do
before do
allow(subject).to receive(:activated?).and_return(true)
end
it { is_expected.to validate_presence_of :webhook }
end
describe '#can_test?' do
context 'with empty repository' do
it 'returns true' do
2017-09-10 17:25:29 +05:30
subject.project = create(:project, :empty_repo)
2017-08-17 22:00:37 +05:30
expect(subject.can_test?).to be true
end
end
context 'with repository' do
it 'returns true' do
2017-09-10 17:25:29 +05:30
subject.project = create(:project, :repository)
2017-08-17 22:00:37 +05:30
expect(subject.can_test?).to be true
end
end
end
2018-11-20 20:47:30 +05:30
describe '#execute' do
2019-12-04 20:38:33 +05:30
subject(:chat_service) { described_class.new }
2018-11-20 20:47:30 +05:30
let(:user) { create(:user) }
let(:project) { create(:project, :repository) }
let(:webhook_url) { 'https://example.gitlab.com/' }
2020-03-09 13:42:32 +05:30
let(:data) { Gitlab::DataBuilder::Push.build_sample(subject.project, user) }
2018-11-20 20:47:30 +05:30
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
2019-12-04 20:38:33 +05:30
expect(chat_service).to receive(:notify).and_return(true)
2018-11-20 20:47:30 +05:30
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)
2019-12-04 20:38:33 +05:30
expect(chat_service).to receive(:notify).and_return(true)
2018-11-20 20:47:30 +05:30
expect(chat_service.execute(data)).to be true
end
end
2020-03-09 13:42:32 +05:30
context 'with a project with name containing spaces' do
it 'does not remove spaces' do
allow(project).to receive(:full_name).and_return('Project Name')
expect(chat_service).to receive(:get_message).with(any_args, hash_including(project_name: 'Project Name'))
chat_service.execute(data)
end
end
2018-11-20 20:47:30 +05:30
end
2017-08-17 22:00:37 +05:30
end