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
fill_in 'Username', with: 'test_user'
fill_in 'service_push_channel', with: '#test_channel'
page.check('Notify only broken pipelines')
page.check('Notify only default branch')
page.select 'All branches', from: 'Branches to be notified'
check_all_events
click_on 'Save'
......
......@@ -272,14 +272,61 @@ describe MicrosoftTeamsService do
end
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
context 'only notify for the default branch' do
context 'when enabled' 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
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', ref: 'not-the-default-branch')
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
chat_service.notify_only_default_branch = true
chat_service.branches_to_be_notified = "default"
end
it 'does not call the Microsoft Teams API for pipeline events' do
......@@ -290,14 +337,78 @@ describe MicrosoftTeamsService do
end
end
context 'when disabled' do
context 'notify for only protected branches' do
before do
chat_service.branches_to_be_notified = "protected"
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, :failed, project: project,
sha: project.commit.sha, ref: 'not-the-default-branch')
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
chat_service.notify_only_default_branch = false
chat_service.branches_to_be_notified = "all"
end
it_behaves_like 'call Microsoft Teams API'
......
......@@ -101,27 +101,132 @@ describe PipelinesEmailService, :mailer do
it_behaves_like 'sending email'
end
context 'when pipeline is failed and on a non-default branch' do
context 'when the pipeline failed' do
context 'on default branch' do
before do
data[:object_attributes][:ref] = 'not-the-default-branch'
pipeline.update(ref: 'not-the-default-branch')
data[:object_attributes][:ref] = project.default_branch
pipeline.update(ref: project.default_branch)
end
context 'with notify_only_default branch on' do
context 'notifications are enabled only for default branch' do
before do
subject.notify_only_default_branch = true
subject.branches_to_be_notified = "default"
end
it_behaves_like 'sending email'
end
context 'with notify_only_default_branch off' do
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
context 'on a protected branch' do
before do
create(:protected_branch, project: project, name: 'a-protected-branch')
data[:object_attributes][:ref] = 'a-protected-branch'
pipeline.update(ref: 'a-protected-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
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
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
describe '#execute' do
before do
subject.project = project
end
def run
subject.execute(data)
end
......@@ -159,38 +264,124 @@ describe PipelinesEmailService, :mailer do
end
end
context 'with notify_only_default_branch off' do
context 'with default branch' do
context 'when the pipeline failed' do
context 'on a 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
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 'with non default branch' do
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
context 'on a protected branch' do
before do
create(:protected_branch, project: project, name: 'a-protected-branch')
data[:object_attributes][:ref] = 'a-protected-branch'
pipeline.update(ref: 'a-protected-branch')
end
context 'notifications are enabled only for default branch' do
before do
data[:object_attributes][:ref] = 'not-the-default-branch'
pipeline.update(ref: 'not-the-default-branch')
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 '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
context 'with notify_only_default_branch on' do
it_behaves_like 'sending email'
end
context 'notifications are enabled only for all branches' do
before do
subject.notify_only_default_branch = true
subject.branches_to_be_notified = "all"
end
context 'with default branch' do
it_behaves_like 'sending email'
end
end
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
before do
subject.branches_to_be_notified = "default"
end
context 'with non default branch' do
it_behaves_like 'not sending email'
end
context 'notifications are enabled only for protected branch' do
before do
data[:object_attributes][:ref] = 'not-the-default-branch'
pipeline.update(ref: 'not-the-default-branch')
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
......
......@@ -70,14 +70,60 @@ shared_examples_for "chat service" do |service_name|
subject.execute(sample_data)
end
context "with not default branch" do
context "with default branch" 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
context "when notify_only_default_branch enabled" do
context "when only default branch are to be notified" 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
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_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 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
......@@ -87,9 +133,75 @@ shared_examples_for "chat service" do |service_name|
end
end
context "when notify_only_default_branch disabled" do
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.notify_only_default_branch = false
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
it_behaves_like "#{service_name} service"
......@@ -220,15 +332,86 @@ shared_examples_for "chat service" do |service_name|
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: "not-the-default-branch")
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
create(:ci_pipeline, :failed, project: project,
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
context "when notify_only_default_branch enabled" do
context "when default and protected branches are to be notified" do
before do
subject.notify_only_default_branch = true
subject.branches_to_be_notified = "default_and_protected"
end
it "does not call the Discord Webhooks API" do
......@@ -238,9 +421,9 @@ shared_examples_for "chat service" do |service_name|
end
end
context "when notify_only_default_branch disabled" do
context "when all branches are to be notified" do
before do
subject.notify_only_default_branch = false
subject.branches_to_be_notified = "all"
end
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