Commit a97d266f authored by blackst0ne's avatar blackst0ne
Browse files

DRY specs, fix typos in docs

parent 0b0e0c8ee522
......@@ -16,7 +16,7 @@ def self.to_param
end
def help
"This service sends notifications about projects events to Discord channels.<br />
"This service sends notifications about project events to Discord channels.<br />
To set up this service:
<ol>
<li><a href='https://support.discordapp.com/hc/en-us/articles/228383668-Intro-to-Webhooks'>Setup a custom Incoming Webhook</a>.</li>
......
......@@ -4,7 +4,7 @@
The Discord Notifications service sends event notifications from GitLab to the channel for which the webhook was created.
To send GitLab event notifications to a Discord channel, create a webhook in Discourse and configure it in GitLab.
To send GitLab event notifications to a Discord channel, create a webhook in Discord and configure it in GitLab.
## Create webhook
......
......@@ -43,20 +43,12 @@
WebMock.stub_request(:post, webhook_url)
end
shared_examples "Discord service" do
it "calls Discord Webhooks API" do
subject.execute(sample_data)
expect(WebMock).to have_requested(:post, webhook_url).with { |req| req.body =~ /\A{"content":.+}\Z/ }.once
end
end
context "with push events" do
let(:sample_data) do
Gitlab::DataBuilder::Push.build_sample(project, user)
end
it_behaves_like "Discord service"
it_behaves_like "Interacts with external service", "Discord", content_key: :content
it "specifies the webhook when it is configured" do
expect(Discordrb::Webhooks::Client).to receive(:new).with(url: webhook_url).and_return(double(:discord_service).as_null_object)
......@@ -86,7 +78,7 @@
subject.notify_only_default_branch = false
end
it_behaves_like "Discord service"
it_behaves_like "Interacts with external service", "Discord", content_key: :content
end
end
end
......@@ -99,7 +91,7 @@
service.hook_data(issue, "open")
end
it_behaves_like "Discord service"
it_behaves_like "Interacts with external service", "Discord", content_key: :content
end
context "with merge events" do
......@@ -122,7 +114,7 @@
project.add_developer(user)
end
it_behaves_like "Discord service"
it_behaves_like "Interacts with external service", "Discord", content_key: :content
end
context "with wiki page events" do
......@@ -137,7 +129,7 @@
let(:wiki_page) { create(:wiki_page, wiki: project.wiki, attrs: opts) }
let(:sample_data) { Gitlab::DataBuilder::WikiPage.build(wiki_page, user, "create") }
it_behaves_like "Discord service"
it_behaves_like "Interacts with external service", "Discord", content_key: :content
end
context "with note events" do
......@@ -152,7 +144,7 @@
note: "a comment on a commit")
end
it_behaves_like "Discord service"
it_behaves_like "Interacts with external service", "Discord", content_key: :content
end
context "with merge request comment" do
......@@ -160,7 +152,7 @@
create(:note_on_merge_request, project: project, note: "merge request note")
end
it_behaves_like "Discord service"
it_behaves_like "Interacts with external service", "Discord", content_key: :content
end
context "with issue comment" do
......@@ -168,7 +160,7 @@
create(:note_on_issue, project: project, note: "issue note")
end
it_behaves_like "Discord service"
it_behaves_like "Interacts with external service", "Discord", content_key: :content
end
context "with snippet comment" do
......@@ -176,7 +168,7 @@
create(:note_on_project_snippet, project: project, note: "snippet note")
end
it_behaves_like "Discord service"
it_behaves_like "Interacts with external service", "Discord", content_key: :content
end
end
......@@ -191,7 +183,7 @@
context "with failed pipeline" do
let(:status) { "failed" }
it_behaves_like "Discord service"
it_behaves_like "Interacts with external service", "Discord", content_key: :content
end
context "with succeeded pipeline" do
......@@ -210,7 +202,7 @@
subject.notify_only_broken_pipelines = false
end
it_behaves_like "Discord service"
it_behaves_like "Interacts with external service", "Discord", content_key: :content
end
end
......@@ -236,7 +228,7 @@
subject.notify_only_default_branch = false
end
it_behaves_like "Discord service"
it_behaves_like "Interacts with external service", "Discord", content_key: :content
end
end
end
......
......@@ -41,23 +41,12 @@
WebMock.stub_request(:post, webhook_url)
end
shared_examples 'Hangouts Chat service' do
it 'calls Hangouts Chat API' do
subject.execute(sample_data)
expect(WebMock)
.to have_requested(:post, webhook_url)
.with { |req| req.body =~ /\A{"text":.+}\Z/ }
.once
end
end
context 'with push events' do
let(:sample_data) do
Gitlab::DataBuilder::Push.build_sample(project, user)
end
it_behaves_like 'Hangouts Chat service'
it_behaves_like "Interacts with external service", "Hangouts Chat", content_key: :text
it 'specifies the webhook when it is configured' do
expect(HangoutsChat::Sender).to receive(:new).with(webhook_url).and_return(double(:hangouts_chat_service).as_null_object)
......@@ -87,7 +76,7 @@
subject.notify_only_default_branch = false
end
it_behaves_like 'Hangouts Chat service'
it_behaves_like "Interacts with external service", "Hangouts Chat", content_key: :text
end
end
end
......@@ -100,7 +89,7 @@
service.hook_data(issue, 'open')
end
it_behaves_like 'Hangouts Chat service'
it_behaves_like "Interacts with external service", "Hangouts Chat", content_key: :text
end
context 'with merge events' do
......@@ -123,7 +112,7 @@
project.add_developer(user)
end
it_behaves_like 'Hangouts Chat service'
it_behaves_like "Interacts with external service", "Hangouts Chat", content_key: :text
end
context 'with wiki page events' do
......@@ -138,7 +127,7 @@
let(:wiki_page) { create(:wiki_page, wiki: project.wiki, attrs: opts) }
let(:sample_data) { Gitlab::DataBuilder::WikiPage.build(wiki_page, user, 'create') }
it_behaves_like 'Hangouts Chat service'
it_behaves_like "Interacts with external service", "Hangouts Chat", content_key: :text
end
context 'with note events' do
......@@ -152,7 +141,7 @@
note: 'a comment on a commit')
end
it_behaves_like 'Hangouts Chat service'
it_behaves_like "Interacts with external service", "Hangouts Chat", content_key: :text
end
context 'with merge request comment' do
......@@ -161,7 +150,7 @@
note: 'merge request note')
end
it_behaves_like 'Hangouts Chat service'
it_behaves_like "Interacts with external service", "Hangouts Chat", content_key: :text
end
context 'with issue comment' do
......@@ -169,7 +158,7 @@
create(:note_on_issue, project: project, note: 'issue note')
end
it_behaves_like 'Hangouts Chat service'
it_behaves_like "Interacts with external service", "Hangouts Chat", content_key: :text
end
context 'with snippet comment' do
......@@ -178,7 +167,7 @@
note: 'snippet note')
end
it_behaves_like 'Hangouts Chat service'
it_behaves_like "Interacts with external service", "Hangouts Chat", content_key: :text
end
end
......@@ -193,7 +182,7 @@
context 'with failed pipeline' do
let(:status) { 'failed' }
it_behaves_like 'Hangouts Chat service'
it_behaves_like "Interacts with external service", "Hangouts Chat", content_key: :text
end
context 'with succeeded pipeline' do
......@@ -212,7 +201,7 @@
subject.notify_only_broken_pipelines = false
end
it_behaves_like 'Hangouts Chat service'
it_behaves_like "Interacts with external service", "Hangouts Chat", content_key: :text
end
end
......@@ -238,7 +227,7 @@
subject.notify_only_default_branch = false
end
it_behaves_like 'Hangouts Chat service'
it_behaves_like "Interacts with external service", "Hangouts Chat", content_key: :text
end
end
end
......
require "spec_helper"
shared_examples_for "Interacts with external service" do |service_name, content_key:|
it "calls #{service_name} Webhooks API" do
subject.execute(sample_data)
expect(WebMock).to have_requested(:post, webhook_url).with { |req| req.body =~ /\A{"#{content_key}":.+}\Z/ }.once
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