Commit 5c99ba03 authored by Balasankar "Balu" C's avatar Balasankar "Balu" C

Modify specs to match backend code

Signed-off-by: default avatarBalasankar "Balu" C <balasankar@gitlab.com>
parent 2a86722a
...@@ -216,7 +216,7 @@ describe 'Admin updates settings' do ...@@ -216,7 +216,7 @@ describe 'Admin updates settings' do
fill_in 'Username', with: 'test_user' fill_in 'Username', with: 'test_user'
fill_in 'service_push_channel', with: '#test_channel' fill_in 'service_push_channel', with: '#test_channel'
page.check('Notify only broken pipelines') page.check('Notify only broken pipelines')
page.check('Notify only default branch') page.select 'All branches', from: 'Branches to be notified'
check_all_events check_all_events
click_on 'Save' click_on 'Save'
......
...@@ -272,14 +272,61 @@ describe MicrosoftTeamsService do ...@@ -272,14 +272,61 @@ describe MicrosoftTeamsService do
end end
end end
context 'only notify for the default branch' do context 'with default branch' do
context 'when enabled' do let(:pipeline) do
let(:pipeline) do create(:ci_pipeline, project: project, status: 'failed', sha: project.commit.sha, ref: project.default_branch)
create(:ci_pipeline, project: project, status: 'failed', ref: 'not-the-default-branch') end
context 'only notify for the default branch' do
before do
chat_service.branches_to_be_notified = "default"
end
it_behaves_like 'call Microsoft Teams API'
end
context 'notify for only protected branches' do
before do
chat_service.branches_to_be_notified = "protected"
end
it 'does not call the 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 'notify for only default and protected branches' do
before do
chat_service.branches_to_be_notified = "default_and_protected"
end
it_behaves_like 'call Microsoft Teams API'
end
context 'notify for all branches' do
before do
chat_service.branches_to_be_notified = "all"
end end
it_behaves_like 'call Microsoft Teams API'
end
end
context 'with protected branch' do
before do
create(:protected_branch, project: project, name: 'a-protected-branch')
end
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
before do before do
chat_service.notify_only_default_branch = true chat_service.branches_to_be_notified = "default"
end end
it 'does not call the Microsoft Teams API for pipeline events' do it 'does not call the Microsoft Teams API for pipeline events' do
...@@ -290,14 +337,78 @@ describe MicrosoftTeamsService do ...@@ -290,14 +337,78 @@ describe MicrosoftTeamsService do
end end
end end
context 'when disabled' do context 'notify for only protected branches' do
let(:pipeline) do before do
create(:ci_pipeline, :failed, project: project, chat_service.branches_to_be_notified = "protected"
sha: project.commit.sha, ref: 'not-the-default-branch')
end end
it_behaves_like 'call Microsoft Teams API'
end
context 'notify for only default and protected branches' do
before do
chat_service.branches_to_be_notified = "default_and_protected"
end
it_behaves_like 'call Microsoft Teams API'
end
context 'notify for all branches' do
before do
chat_service.branches_to_be_notified = "all"
end
it_behaves_like 'call Microsoft Teams API'
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
before do
chat_service.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)
expect(result).to be_falsy
end
end
context 'notify for only protected branches' do
before do
chat_service.branches_to_be_notified = "protected"
end
it 'does not call the 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 'notify for only default and protected branches' do
before do
chat_service.branches_to_be_notified = "default_and_protected"
end
it 'does not call the 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 'notify for all branches' do
before do before do
chat_service.notify_only_default_branch = false chat_service.branches_to_be_notified = "all"
end end
it_behaves_like 'call Microsoft Teams API' it_behaves_like 'call Microsoft Teams API'
......
...@@ -101,27 +101,132 @@ describe PipelinesEmailService, :mailer do ...@@ -101,27 +101,132 @@ describe PipelinesEmailService, :mailer do
it_behaves_like 'sending email' it_behaves_like 'sending email'
end end
context 'when pipeline is failed and on a non-default branch' do context 'when the pipeline failed' do
before do context 'on default branch' do
data[:object_attributes][:ref] = 'not-the-default-branch' before do
pipeline.update(ref: 'not-the-default-branch') data[:object_attributes][:ref] = project.default_branch
pipeline.update(ref: project.default_branch)
end
context 'notifications are enabled only for default branch' do
before do
subject.branches_to_be_notified = "default"
end
it_behaves_like 'sending email'
end
context 'notifications are enabled only for protected branch' do
before do
subject.branches_to_be_notified = "protected"
end
it_behaves_like 'sending email'
end
context 'notifications are enabled only for default and protected branches ' do
before do
subject.branches_to_be_notified = "default_and_protected"
end
it_behaves_like 'sending email'
end
context 'notifications are enabled only for all branches' do
before do
subject.branches_to_be_notified = "all"
end
it_behaves_like 'sending email'
end
end end
context 'with notify_only_default branch on' do context 'on a protected branch' do
before 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 end
it_behaves_like 'sending email' context 'notifications are enabled only for default branch' do
before do
subject.branches_to_be_notified = "default"
end
it_behaves_like 'sending email'
end
context 'notifications are enabled only for protected branch' do
before do
subject.branches_to_be_notified = "protected"
end
it_behaves_like 'sending email'
end
context 'notifications are enabled only for default and protected branches ' do
before do
subject.branches_to_be_notified = "default_and_protected"
end
it_behaves_like 'sending email'
end
context 'notifications are enabled only for all branches' do
before do
subject.branches_to_be_notified = "all"
end
it_behaves_like 'sending email'
end
end end
context 'with notify_only_default_branch off' do context 'on a neither protected nor default branch' do
it_behaves_like 'sending email' 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
before do
subject.branches_to_be_notified = "default"
end
it_behaves_like 'sending email'
end
context 'notifications are enabled only for protected branch' do
before do
subject.branches_to_be_notified = "protected"
end
it_behaves_like 'sending email'
end
context 'notifications are enabled only for default and protected branches ' do
before do
subject.branches_to_be_notified = "default_and_protected"
end
it_behaves_like 'sending email'
end
context 'notifications are enabled only for all branches' do
before do
subject.branches_to_be_notified = "all"
end
it_behaves_like 'sending email'
end
end end
end end
end end
describe '#execute' do describe '#execute' do
before do
subject.project = project
end
def run def run
subject.execute(data) subject.execute(data)
end end
...@@ -159,37 +264,123 @@ describe PipelinesEmailService, :mailer do ...@@ -159,37 +264,123 @@ describe PipelinesEmailService, :mailer do
end end
end end
context 'with notify_only_default_branch off' do context 'when the pipeline failed' do
context 'with default branch' do context 'on a default branch' do
it_behaves_like 'sending email' 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
before do
subject.branches_to_be_notified = "default"
end
it_behaves_like 'sending email'
end
context 'notifications are enabled only for protected branch' do
before do
subject.branches_to_be_notified = "protected"
end
it_behaves_like 'not sending email'
end
context 'notifications are enabled only for default and protected branches ' do
before do
subject.branches_to_be_notified = "default_and_protected"
end
it_behaves_like 'sending email'
end
context 'notifications are enabled only for all branches' do
before do
subject.branches_to_be_notified = "all"
end
it_behaves_like 'sending email'
end
end end
context 'with non default branch' do context 'on a protected branch' do
before do before do
data[:object_attributes][:ref] = 'not-the-default-branch' create(:protected_branch, project: project, name: 'a-protected-branch')
pipeline.update(ref: 'not-the-default-branch') data[:object_attributes][:ref] = 'a-protected-branch'
pipeline.update(ref: 'a-protected-branch')
end end
it_behaves_like 'sending email' context 'notifications are enabled only for default branch' do
end before do
end subject.branches_to_be_notified = "default"
end
context 'with notify_only_default_branch on' do it_behaves_like 'not sending email'
before do end
subject.notify_only_default_branch = true
end
context 'with default branch' do context 'notifications are enabled only for protected branch' do
it_behaves_like 'sending email' before do
subject.branches_to_be_notified = "protected"
end
it_behaves_like 'sending email'
end
context 'notifications are enabled only for default and protected branches ' do
before do
subject.branches_to_be_notified = "default_and_protected"
end
it_behaves_like 'sending email'
end
context 'notifications are enabled only for all branches' do
before do
subject.branches_to_be_notified = "all"
end
it_behaves_like 'sending email'
end
end end
context 'with non default branch' do context 'on a neither protected nor default branch' do
before do before do
data[:object_attributes][:ref] = 'not-the-default-branch' data[:object_attributes][:ref] = 'a-random-branch'
pipeline.update(ref: 'not-the-default-branch') pipeline.update(ref: 'a-random-branch')
end end
it_behaves_like 'not sending email' context 'notifications are enabled only for default branch' do
before do
subject.branches_to_be_notified = "default"
end
it_behaves_like 'not sending email'
end
context 'notifications are enabled only for protected branch' do
before do
subject.branches_to_be_notified = "protected"
end
it_behaves_like 'not sending email'
end
context 'notifications are enabled only for default and protected branches ' do
before do
subject.branches_to_be_notified = "default_and_protected"
end
it_behaves_like 'not sending email'
end
context 'notifications are enabled only for all branches' do
before do
subject.branches_to_be_notified = "all"
end
it_behaves_like 'sending email'
end
end end
end end
end end
......
...@@ -70,14 +70,22 @@ shared_examples_for "chat service" do |service_name| ...@@ -70,14 +70,22 @@ shared_examples_for "chat service" do |service_name|
subject.execute(sample_data) subject.execute(sample_data)
end end
context "with not default branch" do context "with default branch" do
let(:sample_data) do let(:sample_data) do
Gitlab::DataBuilder::Push.build(project: project, user: user, ref: "not-the-default-branch") Gitlab::DataBuilder::Push.build(project: project, user: user, ref: project.default_branch)
end end
context "when notify_only_default_branch enabled" do context "when only default branch are to be notified" do
before do before do
subject.notify_only_default_branch = true subject.branches_to_be_notified = "default"
end
it_behaves_like "#{service_name} service"
end
context "when only protected branches are to be notified" do
before do
subject.branches_to_be_notified = "protected"
end end
it "does not call the Discord Webhooks API" do it "does not call the Discord Webhooks API" do
...@@ -87,9 +95,113 @@ shared_examples_for "chat service" do |service_name| ...@@ -87,9 +95,113 @@ shared_examples_for "chat service" do |service_name|
end end
end end
context "when notify_only_default_branch disabled" do context "when default and protected branches are to be notified" do
before do
subject.branches_to_be_notified = "default_and_protected"
end
it_behaves_like "#{service_name} service"
end
context "when all branches are to be notified" do
before do before do
subject.notify_only_default_branch = false subject.branches_to_be_notified = "all"
end
it_behaves_like "#{service_name} service"
end
end
context "with protected branch" do
before do
create(:protected_branch, project: project, name: "a-protected-branch")
end
let(:sample_data) do
Gitlab::DataBuilder::Push.build(project: project, user: user, ref: "a-protected-branch")
end
context "when only default branch are to be notified" do
before do
subject.branches_to_be_notified = "default"
end
it "does not call the Discord Webhooks API" do
result = subject.execute(sample_data)
expect(result).to be_falsy
end
end
context "when only protected branches are to be notified" do
before do
subject.branches_to_be_notified = "protected"
end
it_behaves_like "#{service_name} service"
end
context "when default and protected branches are to be notified" do
before do
subject.branches_to_be_notified = "default_and_protected"
end
it_behaves_like "#{service_name} service"
end
context "when all branches are to be notified" do
before do
subject.branches_to_be_notified = "all"
end
it_behaves_like "#{service_name} service"
end
end
context "with neither default nor protected branch" do
let(:sample_data) do
Gitlab::DataBuilder::Push.build(project: project, user: user, ref: "a-random-branch")
end
context "when only default branch are to be notified" do
before do
subject.branches_to_be_notified = "default"
end
it "does not call the Discord Webhooks API" do
result = subject.execute(sample_data)
expect(result).to be_falsy
end
end
context "when only protected branches are to be notified" do
before do
subject.branches_to_be_notified = "protected"
end
it "does not call the Discord Webhooks API" do
result = subject.execute(sample_data)
expect(result).to be_falsy
end
end
context "when default and protected branches are to be notified" do
before do
subject.branches_to_be_notified = "default_and_protected"
end
it "does not call the Discord Webhooks API" do
result = subject.execute(sample_data)
expect(result).to be_falsy
end
end
context "when all branches are to be notified" do
before do
subject.branches_to_be_notified = "all"
end end
it_behaves_like "#{service_name} service" it_behaves_like "#{service_name} service"
...@@ -220,15 +332,86 @@ shared_examples_for "chat service" do |service_name| ...@@ -220,15 +332,86 @@ shared_examples_for "chat service" do |service_name|
end end
end end
context "with not default branch" do context "with protected branch" do
before do
create(:protected_branch, project: project, name: 'a-protected-branch')
end
let(:pipeline) do
create(:ci_pipeline, :failed, project: project,
sha: project.commit.sha, ref: 'a-protected-branch')
end
context "when only default branch are to be notified" do
before do
subject.branches_to_be_notified = "default"
end
it "does not call the Discord Webhooks API" do
result = subject.execute(sample_data)
expect(result).to be_falsy
end
end
context "when only protected branches are to be notified" do
before do
subject.branches_to_be_notified = "protected"
end
it_behaves_like "#{service_name} service"
end
context "when default and protected branches are to be notified" do
before do
subject.branches_to_be_notified = "default_and_protected"
end
it_behaves_like "#{service_name} service"
end
context "when all branches are to be notified" do
before do
subject.branches_to_be_notified = "all"
end
it_behaves_like "#{service_name} service"
end
end
context "with neither default nor protected branch" do
let(:pipeline) do let(:pipeline) do
create(:ci_pipeline, :failed, project: project, create(:ci_pipeline, :failed, project: project,
sha: project.commit.sha, ref: "not-the-default-branch") sha: project.commit.sha, ref: "a-random-branch")
end
context "when only default branch are to be notified" do
before do
subject.branches_to_be_notified = "default"
end
it "does not call the Discord Webhooks API" do
result = subject.execute(sample_data)
expect(result).to be_falsy
end
end
context "when only protected branches are to be notified" do
before do
subject.branches_to_be_notified = "protected"
end
it "does not call the Discord Webhooks API" do
result = subject.execute(sample_data)
expect(result).to be_falsy
end
end end
context "when notify_only_default_branch enabled" do context "when default and protected branches are to be notified" do
before do before do
subject.notify_only_default_branch = true subject.branches_to_be_notified = "default_and_protected"
end end
it "does not call the Discord Webhooks API" do it "does not call the Discord Webhooks API" do
...@@ -238,9 +421,9 @@ shared_examples_for "chat service" do |service_name| ...@@ -238,9 +421,9 @@ shared_examples_for "chat service" do |service_name|
end end
end end
context "when notify_only_default_branch disabled" do context "when all branches are to be notified" do
before do before do
subject.notify_only_default_branch = false subject.branches_to_be_notified = "all"
end end
it_behaves_like "#{service_name} service" it_behaves_like "#{service_name} service"
......
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