summaryrefslogtreecommitdiff
path: root/spec/models/project_services
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2019-09-13 18:06:03 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2019-09-13 18:06:03 +0000
commit40d3d574132d2849646c20eb9d8742b159d9bfc8 (patch)
tree431dee6675639da4421dbb1d6f50b7734a3190c3 /spec/models/project_services
parent5939b09fd3db37ec98dfce0345162617d9d1d313 (diff)
downloadgitlab-ce-40d3d574132d2849646c20eb9d8742b159d9bfc8.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/models/project_services')
-rw-r--r--spec/models/project_services/mattermost_service_spec.rb2
-rw-r--r--spec/models/project_services/microsoft_teams_service_spec.rb97
-rw-r--r--spec/models/project_services/pipelines_email_service_spec.rb157
-rw-r--r--spec/models/project_services/slack_service_spec.rb2
4 files changed, 203 insertions, 55 deletions
diff --git a/spec/models/project_services/mattermost_service_spec.rb b/spec/models/project_services/mattermost_service_spec.rb
index 6261c70f266..5b974985706 100644
--- a/spec/models/project_services/mattermost_service_spec.rb
+++ b/spec/models/project_services/mattermost_service_spec.rb
@@ -3,5 +3,5 @@
require 'spec_helper'
describe MattermostService do
- it_behaves_like "slack or mattermost notifications"
+ it_behaves_like "slack or mattermost notifications", "Mattermost"
end
diff --git a/spec/models/project_services/microsoft_teams_service_spec.rb b/spec/models/project_services/microsoft_teams_service_spec.rb
index 73c20359091..275244fa5fd 100644
--- a/spec/models/project_services/microsoft_teams_service_spec.rb
+++ b/spec/models/project_services/microsoft_teams_service_spec.rb
@@ -226,9 +226,10 @@ describe MicrosoftTeamsService do
)
end
- shared_examples 'call Microsoft Teams API' do
+ shared_examples 'call Microsoft Teams API' do |branches_to_be_notified: nil|
before do
WebMock.stub_request(:post, webhook_url)
+ chat_service.branches_to_be_notified = branches_to_be_notified if branches_to_be_notified
end
it 'calls Microsoft Teams API for pipeline events' do
@@ -245,6 +246,18 @@ describe MicrosoftTeamsService do
end
end
+ shared_examples 'does not call Microsoft Teams API' do |branches_to_be_notified: nil|
+ before do
+ chat_service.branches_to_be_notified = branches_to_be_notified if branches_to_be_notified
+ end
+ it 'does not call Microsoft Teams API for pipeline events' do
+ data = Gitlab::DataBuilder::Pipeline.build(pipeline)
+ result = chat_service.execute(data)
+
+ expect(result).to be_falsy
+ end
+ end
+
context 'with failed pipeline' do
let(:status) { 'failed' }
@@ -272,35 +285,73 @@ describe MicrosoftTeamsService do
end
end
- context 'only notify for the default branch' do
- context 'when enabled' do
- let(:pipeline) do
- create(:ci_pipeline, project: project, status: 'failed', ref: 'not-the-default-branch')
- end
+ context 'with default branch' do
+ let(:pipeline) do
+ create(:ci_pipeline, project: project, status: 'failed', sha: project.commit.sha, ref: project.default_branch)
+ end
- before do
- chat_service.notify_only_default_branch = true
- end
+ context 'only notify for the default branch' do
+ it_behaves_like 'call Microsoft Teams API', branches_to_be_notified: "default"
+ end
- it 'does not call the Microsoft Teams API for pipeline events' do
- data = Gitlab::DataBuilder::Pipeline.build(pipeline)
- result = chat_service.execute(data)
+ context 'notify for only protected branches' do
+ it_behaves_like 'does not call Microsoft Teams API', branches_to_be_notified: "protected"
+ end
- expect(result).to be_falsy
- end
+ context 'notify for only default and protected branches' do
+ it_behaves_like 'call Microsoft Teams API', branches_to_be_notified: "default_and_protected"
end
- context 'when disabled' do
- let(:pipeline) do
- create(:ci_pipeline, :failed, project: project,
- sha: project.commit.sha, ref: 'not-the-default-branch')
- end
+ context 'notify for all branches' do
+ it_behaves_like 'call Microsoft Teams API', branches_to_be_notified: "all"
+ end
+ end
- before do
- chat_service.notify_only_default_branch = false
- end
+ context 'with protected branch' do
+ before do
+ create(:protected_branch, project: project, name: 'a-protected-branch')
+ end
- it_behaves_like 'call Microsoft Teams API'
+ let(:pipeline) do
+ create(:ci_pipeline, project: project, status: 'failed', sha: project.commit.sha, ref: 'a-protected-branch')
+ end
+
+ context 'only notify for the default branch' do
+ it_behaves_like 'does not call Microsoft Teams API', branches_to_be_notified: "default"
+ end
+
+ context 'notify for only protected branches' do
+ it_behaves_like 'call Microsoft Teams API', branches_to_be_notified: "protected"
+ end
+
+ context 'notify for only default and protected branches' do
+ it_behaves_like 'call Microsoft Teams API', branches_to_be_notified: "default_and_protected"
+ end
+
+ context 'notify for all branches' do
+ it_behaves_like 'call Microsoft Teams API', branches_to_be_notified: "all"
+ end
+ end
+
+ context 'with neither protected nor default branch' do
+ let(:pipeline) do
+ create(:ci_pipeline, project: project, status: 'failed', sha: project.commit.sha, ref: 'a-random-branch')
+ end
+
+ context 'only notify for the default branch' do
+ it_behaves_like 'does not call Microsoft Teams API', branches_to_be_notified: "default"
+ end
+
+ context 'notify for only protected branches' do
+ it_behaves_like 'does not call Microsoft Teams API', branches_to_be_notified: "protected"
+ end
+
+ context 'notify for only default and protected branches' do
+ it_behaves_like 'does not call Microsoft Teams API', branches_to_be_notified: "default_and_protected"
+ end
+
+ context 'notify for all branches' do
+ it_behaves_like 'call Microsoft Teams API', branches_to_be_notified: "all"
end
end
end
diff --git a/spec/models/project_services/pipelines_email_service_spec.rb b/spec/models/project_services/pipelines_email_service_spec.rb
index b85565e0c25..67358d6c3d6 100644
--- a/spec/models/project_services/pipelines_email_service_spec.rb
+++ b/spec/models/project_services/pipelines_email_service_spec.rb
@@ -53,9 +53,10 @@ describe PipelinesEmailService, :mailer do
end
end
- shared_examples 'sending email' do
+ shared_examples 'sending email' do |branches_to_be_notified: nil|
before do
subject.recipients = recipients
+ subject.branches_to_be_notified = branches_to_be_notified if branches_to_be_notified
perform_enqueued_jobs do
run
@@ -69,9 +70,10 @@ describe PipelinesEmailService, :mailer do
end
end
- shared_examples 'not sending email' do
+ shared_examples 'not sending email' do |branches_to_be_notified: nil|
before do
subject.recipients = recipients
+ subject.branches_to_be_notified = branches_to_be_notified if branches_to_be_notified
perform_enqueued_jobs do
run
@@ -101,27 +103,84 @@ describe PipelinesEmailService, :mailer do
it_behaves_like 'sending email'
end
- context 'when pipeline is failed and on a non-default branch' do
- before do
- data[:object_attributes][:ref] = 'not-the-default-branch'
- pipeline.update(ref: 'not-the-default-branch')
+ context 'when the pipeline failed' do
+ context 'on default branch' do
+ before do
+ data[:object_attributes][:ref] = project.default_branch
+ pipeline.update(ref: project.default_branch)
+ end
+
+ context 'notifications are enabled only for default branch' do
+ it_behaves_like 'sending email', branches_to_be_notified: "default"
+ end
+
+ context 'notifications are enabled only for protected branch' do
+ it_behaves_like 'sending email', branches_to_be_notified: "protected"
+ end
+
+ context 'notifications are enabled only for default and protected branches ' do
+ it_behaves_like 'sending email', branches_to_be_notified: "default_and_protected"
+ end
+
+ context 'notifications are enabled only for all branches' do
+ it_behaves_like 'sending email', branches_to_be_notified: "all"
+ end
end
- context 'with notify_only_default branch on' do
+ context 'on a protected branch' do
before do
- subject.notify_only_default_branch = true
+ create(:protected_branch, project: project, name: 'a-protected-branch')
+ data[:object_attributes][:ref] = 'a-protected-branch'
+ pipeline.update(ref: 'a-protected-branch')
end
- it_behaves_like 'sending email'
+ context 'notifications are enabled only for default branch' do
+ it_behaves_like 'sending email', branches_to_be_notified: "default"
+ end
+
+ context 'notifications are enabled only for protected branch' do
+ it_behaves_like 'sending email', branches_to_be_notified: "protected"
+ end
+
+ context 'notifications are enabled only for default and protected branches ' do
+ it_behaves_like 'sending email', branches_to_be_notified: "default_and_protected"
+ end
+
+ context 'notifications are enabled only for all branches' do
+ it_behaves_like 'sending email', branches_to_be_notified: "all"
+ end
end
- context 'with notify_only_default_branch off' do
- it_behaves_like 'sending email'
+ context 'on a neither protected nor default branch' do
+ before do
+ data[:object_attributes][:ref] = 'a-random-branch'
+ pipeline.update(ref: 'a-random-branch')
+ end
+
+ context 'notifications are enabled only for default branch' do
+ it_behaves_like 'sending email', branches_to_be_notified: "default"
+ end
+
+ context 'notifications are enabled only for protected branch' do
+ it_behaves_like 'sending email', branches_to_be_notified: "protected"
+ end
+
+ context 'notifications are enabled only for default and protected branches ' do
+ it_behaves_like 'sending email', branches_to_be_notified: "default_and_protected"
+ end
+
+ context 'notifications are enabled only for all branches' do
+ it_behaves_like 'sending email', branches_to_be_notified: "all"
+ end
end
end
end
describe '#execute' do
+ before do
+ subject.project = project
+ end
+
def run
subject.execute(data)
end
@@ -159,37 +218,75 @@ describe PipelinesEmailService, :mailer do
end
end
- context 'with notify_only_default_branch off' do
- context 'with default branch' do
- it_behaves_like 'sending email'
+ context 'when the pipeline failed' do
+ context 'on default branch' do
+ before do
+ data[:object_attributes][:ref] = project.default_branch
+ pipeline.update(ref: project.default_branch)
+ end
+
+ context 'notifications are enabled only for default branch' do
+ it_behaves_like 'sending email', branches_to_be_notified: "default"
+ end
+
+ context 'notifications are enabled only for protected branch' do
+ it_behaves_like 'not sending email', branches_to_be_notified: "protected"
+ end
+
+ context 'notifications are enabled only for default and protected branches ' do
+ it_behaves_like 'sending email', branches_to_be_notified: "default_and_protected"
+ end
+
+ context 'notifications are enabled only for all branches' do
+ it_behaves_like 'sending email', branches_to_be_notified: "all"
+ end
end
- context 'with non default branch' do
+ context 'on a protected branch' do
before do
- data[:object_attributes][:ref] = 'not-the-default-branch'
- pipeline.update(ref: 'not-the-default-branch')
+ create(:protected_branch, project: project, name: 'a-protected-branch')
+ data[:object_attributes][:ref] = 'a-protected-branch'
+ pipeline.update(ref: 'a-protected-branch')
end
- it_behaves_like 'sending email'
- end
- end
+ context 'notifications are enabled only for default branch' do
+ it_behaves_like 'not sending email', branches_to_be_notified: "default"
+ end
- context 'with notify_only_default_branch on' do
- before do
- subject.notify_only_default_branch = true
- end
+ context 'notifications are enabled only for protected branch' do
+ it_behaves_like 'sending email', branches_to_be_notified: "protected"
+ end
- context 'with default branch' do
- it_behaves_like 'sending email'
+ context 'notifications are enabled only for default and protected branches ' do
+ it_behaves_like 'sending email', branches_to_be_notified: "default_and_protected"
+ end
+
+ context 'notifications are enabled only for all branches' do
+ it_behaves_like 'sending email', branches_to_be_notified: "all"
+ end
end
- context 'with non default branch' do
+ context 'on a neither protected nor default branch' do
before do
- data[:object_attributes][:ref] = 'not-the-default-branch'
- pipeline.update(ref: 'not-the-default-branch')
+ data[:object_attributes][:ref] = 'a-random-branch'
+ pipeline.update(ref: 'a-random-branch')
end
- it_behaves_like 'not sending email'
+ context 'notifications are enabled only for default branch' do
+ it_behaves_like 'not sending email', branches_to_be_notified: "default"
+ end
+
+ context 'notifications are enabled only for protected branch' do
+ it_behaves_like 'not sending email', branches_to_be_notified: "protected"
+ end
+
+ context 'notifications are enabled only for default and protected branches ' do
+ it_behaves_like 'not sending email', branches_to_be_notified: "default_and_protected"
+ end
+
+ context 'notifications are enabled only for all branches' do
+ it_behaves_like 'sending email', branches_to_be_notified: "all"
+ end
end
end
end
diff --git a/spec/models/project_services/slack_service_spec.rb b/spec/models/project_services/slack_service_spec.rb
index 01f580c5d01..f751dd6ffb9 100644
--- a/spec/models/project_services/slack_service_spec.rb
+++ b/spec/models/project_services/slack_service_spec.rb
@@ -3,5 +3,5 @@
require 'spec_helper'
describe SlackService do
- it_behaves_like "slack or mattermost notifications"
+ it_behaves_like "slack or mattermost notifications", "Slack"
end