Skip to content

Commit dad21c3

Browse files
committed
Only send org admin alerts if the feature flag is enabled
1 parent abafbd2 commit dad21c3

File tree

6 files changed

+39
-5
lines changed

6 files changed

+39
-5
lines changed

app/services/org_admin_alerts_service.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,15 @@ def initialize(form:, current_user:)
66
end
77

88
def form_made_live
9+
return unless feature_enabled?
10+
911
@org_admins.each do |org_admin_user|
1012
form_made_live_email(to_email: org_admin_user.email).deliver_now
1113
end
1214
end
1315

1416
def new_draft_form_created
17+
return unless feature_enabled?
1518
return unless @form.group.active?
1619

1720
@org_admins.each do |org_admin_user|
@@ -20,6 +23,8 @@ def new_draft_form_created
2023
end
2124

2225
def draft_of_existing_form_created
26+
return unless feature_enabled?
27+
2328
@org_admins.each do |org_admin_user|
2429
draft_of_existing_form_created_email(to_email: org_admin_user.email).deliver_now
2530
end
@@ -74,4 +79,8 @@ def draft_of_existing_form_created_email(to_email:)
7479
def copied_from_form
7580
Form.find_by(id: @form.copied_from_id)
7681
end
82+
83+
def feature_enabled?
84+
FeatureService.enabled?(:org_admin_alerts_enabled)
85+
end
7786
end

spec/requests/forms/copy_controller_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@
6666
expect(response).to redirect_to(form_path(Form.last.id))
6767
end
6868

69-
it "sends an email to the organisation admins" do
69+
it "sends an email to the organisation admins", :feature_org_admin_alerts_enabled do
7070
post create_copy_form_path(id), params: { forms_copy_input: { name: "Copied Form", tag: "draft" } }
7171
expect(ActionMailer::Base.deliveries.count).to eq(1)
7272

spec/requests/forms/make_live_controller_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@
7878
expect(response).to render_template(:confirmation)
7979
end
8080

81-
it "sends an email to the organisation admins" do
81+
it "sends an email to the organisation admins", :feature_org_admin_alerts_enabled do
8282
post(make_live_path(form_id: form.id), params: form_params)
8383
expect(ActionMailer::Base.deliveries.count).to eq(1)
8484

spec/requests/forms_controller_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
login_as user
1313
end
1414

15-
describe "#send_org_admin_alerts_if_draft_created" do
15+
describe "#send_org_admin_alerts_if_draft_created", :feature_org_admin_alerts_enabled do
1616
before do
1717
post change_form_name_path(form_id: form.id), params: { forms_name_input: { name: "New name" } }
1818
end

spec/requests/group_forms_controller_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@
131131
expect(response).to redirect_to(form_url(Form.last.id))
132132
end
133133

134-
it "sends an email to the organisation admins" do
134+
it "sends an email to the organisation admins", :feature_org_admin_alerts_enabled do
135135
post group_forms_url(group), params: { forms_name_input: valid_attributes }
136136
expect(ActionMailer::Base.deliveries.count).to eq(1)
137137

spec/services/org_admin_alerts_service_spec.rb

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
require "rails_helper"
22

3-
RSpec.describe OrgAdminAlertsService do
3+
RSpec.describe OrgAdminAlertsService, :feature_org_admin_alerts_enabled do
44
subject(:service) { described_class.new(form:, current_user:) }
55

66
let(:organisation) { create(:organisation, :with_signed_mou) }
@@ -145,6 +145,15 @@
145145
expect(ActionMailer::Base.deliveries.size).to eq(0)
146146
end
147147
end
148+
149+
context "when the feature is disabled", feature_org_admin_alerts_enabled: false do
150+
let(:previous_state) { :draft }
151+
152+
it "does not send any emails" do
153+
service.form_made_live
154+
expect(ActionMailer::Base.deliveries.size).to eq(0)
155+
end
156+
end
148157
end
149158

150159
describe "#new_draft_form_created" do
@@ -206,6 +215,13 @@
206215
expect(ActionMailer::Base.deliveries.size).to eq(0)
207216
end
208217
end
218+
219+
context "when the feature is disabled", feature_org_admin_alerts_enabled: false do
220+
it "does not send any emails" do
221+
service.new_draft_form_created
222+
expect(ActionMailer::Base.deliveries.size).to eq(0)
223+
end
224+
end
209225
end
210226

211227
describe "#draft_of_existing_form_created" do
@@ -264,5 +280,14 @@
264280
expect(ActionMailer::Base.deliveries.size).to eq(0)
265281
end
266282
end
283+
284+
context "when the feature is disabled", feature_org_admin_alerts_enabled: false do
285+
let(:form) { create(:form, :live_with_draft) }
286+
287+
it "does not send any emails" do
288+
service.draft_of_existing_form_created
289+
expect(ActionMailer::Base.deliveries.size).to eq(0)
290+
end
291+
end
267292
end
268293
end

0 commit comments

Comments
 (0)