Skip to content

Commit 7e65f1b

Browse files
committed
Add mailers for org admin alerts
We'll be introducing a category of alerts for org admins, and these mailers correspond to Notify templates for those alerts. All the new alerts being introduced are in this commit.
1 parent 6fee90a commit 7e65f1b

File tree

4 files changed

+418
-0
lines changed

4 files changed

+418
-0
lines changed
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
class OrgAdminAlerts::DraftMadeMailer < GovukNotifyRails::Mailer
2+
def new_draft_form_made(form_name:, form_link:, group_name:, user_name:, user_email:, to_email:)
3+
set_template(Settings.govuk_notify.org_admin_alerts.new_draft_form_made_template_id)
4+
send_mail(to_email:, personalisation: {
5+
form_name:,
6+
form_link:,
7+
group_name:,
8+
user_name:,
9+
user_email:,
10+
})
11+
end
12+
13+
def copied_draft_form_made(form_name:, form_link:, copied_from_form_name:, copied_from_form_link:, group_name:, user_name:, user_email:, to_email:)
14+
set_template(Settings.govuk_notify.org_admin_alerts.copied_draft_form_made_template_id)
15+
send_mail(to_email:, personalisation: {
16+
form_name:,
17+
form_link:,
18+
copied_from_form_name:,
19+
copied_from_form_link:,
20+
group_name:,
21+
user_name:,
22+
user_email:,
23+
})
24+
end
25+
26+
def new_archived_form_draft_made(form_name:, form_link:, archived_form_name:, archived_form_link:, group_name:, user_name:, user_email:, to_email:)
27+
set_template(Settings.govuk_notify.org_admin_alerts.new_archived_form_draft_made_template_id)
28+
send_mail(to_email:, personalisation: {
29+
form_name:,
30+
form_link:,
31+
archived_form_name:,
32+
archived_form_link:,
33+
group_name:,
34+
user_name:,
35+
user_email:,
36+
})
37+
end
38+
39+
def new_live_form_draft_made(form_name:, form_link:, live_form_name:, live_form_link:, group_name:, user_name:, user_email:, to_email:)
40+
set_template(Settings.govuk_notify.org_admin_alerts.new_live_form_draft_made_template_id)
41+
send_mail(to_email:, personalisation: {
42+
form_name:,
43+
form_link:,
44+
live_form_name:,
45+
live_form_link:,
46+
group_name:,
47+
user_name:,
48+
user_email:,
49+
})
50+
end
51+
52+
private
53+
54+
def send_mail(to_email:, personalisation:)
55+
set_personalisation(**personalisation)
56+
57+
mail(to: to_email)
58+
end
59+
end
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
class OrgAdminAlerts::MadeLiveMailer < GovukNotifyRails::Mailer
2+
def new_draft_form_made_live(form_name:, form_link:, user_name:, user_email:, to_email:)
3+
set_template(Settings.govuk_notify.org_admin_alerts.new_draft_form_made_live_template_id)
4+
send_mail(to_email:, personalisation: {
5+
form_name:,
6+
form_link:,
7+
user_name:,
8+
user_email:,
9+
})
10+
end
11+
12+
def live_form_changes_made_live(form_name:, form_link:, user_name:, user_email:, to_email:)
13+
set_template(Settings.govuk_notify.org_admin_alerts.live_form_changes_made_live_template_id)
14+
send_mail(to_email:, personalisation: {
15+
form_name:,
16+
form_link:,
17+
user_name:,
18+
user_email:,
19+
})
20+
end
21+
22+
def archived_form_changes_made_live(form_name:, form_link:, user_name:, user_email:, to_email:)
23+
set_template(Settings.govuk_notify.org_admin_alerts.archived_form_changes_made_live_template_id)
24+
send_mail(to_email:, personalisation: {
25+
form_name:,
26+
form_link:,
27+
user_name:,
28+
user_email:,
29+
})
30+
end
31+
32+
def copied_form_made_live(form_name:, form_link:, copied_from_form_name:, copied_from_form_link:, user_name:, user_email:, to_email:)
33+
set_template(Settings.govuk_notify.org_admin_alerts.copied_form_made_live_template_id)
34+
send_mail(to_email:, personalisation: {
35+
form_name:,
36+
form_link:,
37+
copied_from_form_name:,
38+
copied_from_form_link:,
39+
user_name:,
40+
user_email:,
41+
})
42+
end
43+
44+
def archived_form_made_live(form_name:, form_link:, user_name:, user_email:, to_email:)
45+
set_template(Settings.govuk_notify.org_admin_alerts.archived_form_made_live_template_id)
46+
send_mail(to_email:, personalisation: {
47+
form_name:,
48+
form_link:,
49+
user_name:,
50+
user_email:,
51+
})
52+
end
53+
54+
private
55+
56+
def send_mail(to_email:, personalisation:)
57+
set_personalisation(**personalisation)
58+
59+
mail(to: to_email)
60+
end
61+
end
Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
require "rails_helper"
2+
3+
describe OrgAdminAlerts::DraftMadeMailer, type: :mailer do
4+
let(:form_name) { "Test Form" }
5+
let(:form_link) { "http://example.com/form" }
6+
let(:group_name) { "Test Group" }
7+
let(:user_name) { "Test User" }
8+
let(:user_email) { "test@example.gov.uk" }
9+
let(:to_email) { "admin@example.gov.uk" }
10+
11+
describe "#new_draft_form_made" do
12+
subject(:mail) do
13+
described_class.new_draft_form_made(
14+
form_name:,
15+
form_link:,
16+
group_name:,
17+
user_name:,
18+
user_email:,
19+
to_email:,
20+
)
21+
end
22+
23+
it "sends an email with the correct template" do
24+
expect(mail.govuk_notify_template).to eq(Settings.govuk_notify.org_admin_alerts.new_draft_form_made_template_id)
25+
end
26+
27+
it "sends an email to the correct email address" do
28+
expect(mail.to).to eq([to_email])
29+
end
30+
31+
it "includes the personalisation" do
32+
expect(mail.govuk_notify_personalisation[:form_name]).to eq(form_name)
33+
expect(mail.govuk_notify_personalisation[:form_link]).to eq(form_link)
34+
expect(mail.govuk_notify_personalisation[:group_name]).to eq(group_name)
35+
expect(mail.govuk_notify_personalisation[:user_name]).to eq(user_name)
36+
expect(mail.govuk_notify_personalisation[:user_email]).to eq(user_email)
37+
end
38+
end
39+
40+
describe "#copied_draft_form_made" do
41+
subject(:mail) do
42+
described_class.copied_draft_form_made(
43+
form_name:,
44+
form_link:,
45+
copied_from_form_name:,
46+
copied_from_form_link:,
47+
group_name:,
48+
user_name:,
49+
user_email:,
50+
to_email:,
51+
)
52+
end
53+
54+
let(:copied_from_form_name) { "Copied Form" }
55+
let(:copied_from_form_link) { "http://example.com/copied-form" }
56+
57+
it "sends an email with the correct template" do
58+
expect(mail.govuk_notify_template).to eq(Settings.govuk_notify.org_admin_alerts.copied_draft_form_made_template_id)
59+
end
60+
61+
it "sends an email to the correct email address" do
62+
expect(mail.to).to eq([to_email])
63+
end
64+
65+
it "includes the personalisation" do
66+
expect(mail.govuk_notify_personalisation[:form_name]).to eq(form_name)
67+
expect(mail.govuk_notify_personalisation[:form_link]).to eq(form_link)
68+
expect(mail.govuk_notify_personalisation[:copied_from_form_name]).to eq(copied_from_form_name)
69+
expect(mail.govuk_notify_personalisation[:copied_from_form_link]).to eq(copied_from_form_link)
70+
expect(mail.govuk_notify_personalisation[:group_name]).to eq(group_name)
71+
expect(mail.govuk_notify_personalisation[:user_name]).to eq(user_name)
72+
expect(mail.govuk_notify_personalisation[:user_email]).to eq(user_email)
73+
end
74+
end
75+
76+
describe "#new_archived_form_draft_made" do
77+
subject(:mail) do
78+
described_class.new_archived_form_draft_made(
79+
form_name:,
80+
form_link:,
81+
archived_form_name:,
82+
archived_form_link:,
83+
group_name:,
84+
user_name:,
85+
user_email:,
86+
to_email:,
87+
)
88+
end
89+
90+
let(:archived_form_name) { "Archived Form" }
91+
let(:archived_form_link) { "http://example.com/archived-form" }
92+
93+
it "sends an email with the correct template" do
94+
expect(mail.govuk_notify_template).to eq(Settings.govuk_notify.org_admin_alerts.new_archived_form_draft_made_template_id)
95+
end
96+
97+
it "sends an email to the correct email address" do
98+
expect(mail.to).to eq([to_email])
99+
end
100+
101+
it "includes the personalisation" do
102+
expect(mail.govuk_notify_personalisation[:form_name]).to eq(form_name)
103+
expect(mail.govuk_notify_personalisation[:form_link]).to eq(form_link)
104+
expect(mail.govuk_notify_personalisation[:archived_form_name]).to eq(archived_form_name)
105+
expect(mail.govuk_notify_personalisation[:archived_form_link]).to eq(archived_form_link)
106+
expect(mail.govuk_notify_personalisation[:group_name]).to eq(group_name)
107+
expect(mail.govuk_notify_personalisation[:user_name]).to eq(user_name)
108+
expect(mail.govuk_notify_personalisation[:user_email]).to eq(user_email)
109+
end
110+
end
111+
112+
describe "#new_live_form_draft_made" do
113+
subject(:mail) do
114+
described_class.new_live_form_draft_made(
115+
form_name:,
116+
form_link:,
117+
live_form_name:,
118+
live_form_link:,
119+
group_name:,
120+
user_name:,
121+
user_email:,
122+
to_email:,
123+
)
124+
end
125+
126+
let(:live_form_name) { "Live Form" }
127+
let(:live_form_link) { "http://example.com/live-form" }
128+
129+
it "sends an email with the correct template" do
130+
expect(mail.govuk_notify_template).to eq(Settings.govuk_notify.org_admin_alerts.new_live_form_draft_made_template_id)
131+
end
132+
133+
it "sends an email to the correct email address" do
134+
expect(mail.to).to eq([to_email])
135+
end
136+
137+
it "includes the personalisation" do
138+
expect(mail.govuk_notify_personalisation[:form_name]).to eq(form_name)
139+
expect(mail.govuk_notify_personalisation[:form_link]).to eq(form_link)
140+
expect(mail.govuk_notify_personalisation[:live_form_name]).to eq(live_form_name)
141+
expect(mail.govuk_notify_personalisation[:live_form_link]).to eq(live_form_link)
142+
expect(mail.govuk_notify_personalisation[:group_name]).to eq(group_name)
143+
expect(mail.govuk_notify_personalisation[:user_name]).to eq(user_name)
144+
expect(mail.govuk_notify_personalisation[:user_email]).to eq(user_email)
145+
end
146+
end
147+
end

0 commit comments

Comments
 (0)