Add tests for ChatNotificationService#execute
This commit is contained in:
parent
9c491bc628
commit
3a0f3082af
1 changed files with 50 additions and 0 deletions
|
@ -26,4 +26,54 @@ describe ChatNotificationService do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
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
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue