Skip to content

Commit a036604

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 dd314d1 commit a036604

File tree

4 files changed

+366
-0
lines changed

4 files changed

+366
-0
lines changed
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
class OrgAdminAlerts::DraftCreatedMailer < GovukNotifyRails::Mailer
2+
include Rails.application.routes.url_helpers
3+
def new_draft_form_created(form:, user:, to_email:)
4+
set_template(Settings.govuk_notify.org_admin_alerts.new_draft_form_created_template_id)
5+
send_mail(to_email:, personalisation: {
6+
form_name: form.name,
7+
form_link: form_url(form),
8+
group_name: form.group.name,
9+
user_name: user.name,
10+
user_email: user.email,
11+
})
12+
end
13+
14+
def copied_draft_form_created(form:, copied_from_form:, user:, to_email:)
15+
set_template(Settings.govuk_notify.org_admin_alerts.copied_draft_form_created_template_id)
16+
send_mail(to_email:, personalisation: {
17+
form_name: form.name,
18+
form_link: form_url(form),
19+
copied_from_form_name: copied_from_form.name,
20+
copied_from_form_link: form_url(copied_from_form),
21+
group_name: form.group.name,
22+
user_name: user.name,
23+
user_email: user.email,
24+
})
25+
end
26+
27+
def new_archived_form_draft_created(form:, user:, to_email:)
28+
set_template(Settings.govuk_notify.org_admin_alerts.new_archived_form_draft_created_template_id)
29+
send_mail(to_email:, personalisation: {
30+
form_name: form.name,
31+
form_link: form_url(form),
32+
archived_form_name: form.archived_form_document.content["name"],
33+
archived_form_link: archived_form_url(form),
34+
group_name: form.group.name,
35+
user_name: user.name,
36+
user_email: user.email,
37+
})
38+
end
39+
40+
def new_live_form_draft_created(form:, user:, to_email:)
41+
set_template(Settings.govuk_notify.org_admin_alerts.new_live_form_draft_created_template_id)
42+
send_mail(to_email:, personalisation: {
43+
form_name: form.name,
44+
form_link: form_url(form),
45+
live_form_name: form.live_form_document.content["name"],
46+
live_form_link: live_form_url(form),
47+
group_name: form.group.name,
48+
user_name: user.name,
49+
user_email: user.email,
50+
})
51+
end
52+
53+
private
54+
55+
def send_mail(to_email:, personalisation:)
56+
set_personalisation(**personalisation)
57+
58+
mail(to: to_email)
59+
end
60+
end
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
class OrgAdminAlerts::MadeLiveMailer < GovukNotifyRails::Mailer
2+
include Rails.application.routes.url_helpers
3+
def new_draft_form_made_live(form:, user:, to_email:)
4+
set_template(Settings.govuk_notify.org_admin_alerts.new_draft_form_made_live_template_id)
5+
send_mail(to_email:, personalisation: {
6+
form_name: form.name,
7+
form_link: live_form_url(form),
8+
user_name: user.name,
9+
user_email: user.email,
10+
})
11+
end
12+
13+
def live_form_changes_made_live(form:, user:, to_email:)
14+
set_template(Settings.govuk_notify.org_admin_alerts.live_form_changes_made_live_template_id)
15+
send_mail(to_email:, personalisation: {
16+
form_name: form.name,
17+
form_link: live_form_url(form),
18+
user_name: user.name,
19+
user_email: user.email,
20+
})
21+
end
22+
23+
def archived_form_changes_made_live(form:, user:, to_email:)
24+
set_template(Settings.govuk_notify.org_admin_alerts.archived_form_changes_made_live_template_id)
25+
send_mail(to_email:, personalisation: {
26+
form_name: form.name,
27+
form_link: live_form_url(form),
28+
user_name: user.name,
29+
user_email: user.email,
30+
})
31+
end
32+
33+
def copied_form_made_live(form:, copied_from_form:, user:, to_email:)
34+
set_template(Settings.govuk_notify.org_admin_alerts.copied_form_made_live_template_id)
35+
send_mail(to_email:, personalisation: {
36+
form_name: form.name,
37+
form_link: live_form_url(form),
38+
copied_from_form_name: copied_from_form.name,
39+
copied_from_form_link: form_url(copied_from_form),
40+
user_name: user.name,
41+
user_email: user.email,
42+
})
43+
end
44+
45+
def archived_form_made_live(form:, user:, to_email:)
46+
set_template(Settings.govuk_notify.org_admin_alerts.archived_form_made_live_template_id)
47+
send_mail(to_email:, personalisation: {
48+
form_name: form.name,
49+
form_link: live_form_url(form),
50+
user_name: user.name,
51+
user_email: user.email,
52+
})
53+
end
54+
55+
private
56+
57+
def send_mail(to_email:, personalisation:)
58+
set_personalisation(**personalisation)
59+
60+
mail(to: to_email)
61+
end
62+
end
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
require "rails_helper"
2+
3+
describe OrgAdminAlerts::DraftCreatedMailer, type: :mailer do
4+
let(:form) { create :form, :with_group }
5+
let(:user) { create :user }
6+
let(:to_email) { "admin@example.gov.uk" }
7+
8+
describe "#new_draft_form_created" do
9+
subject(:mail) do
10+
described_class.new_draft_form_created(form:, user:, to_email:)
11+
end
12+
13+
it "sends an email with the correct template" do
14+
expect(mail.govuk_notify_template).to eq(Settings.govuk_notify.org_admin_alerts.new_draft_form_created_template_id)
15+
end
16+
17+
it "sends an email to the correct email address" do
18+
expect(mail.to).to eq([to_email])
19+
end
20+
21+
it "includes the personalisation" do
22+
expect(mail.govuk_notify_personalisation[:form_name]).to eq(form.name)
23+
expect(mail.govuk_notify_personalisation[:form_link]).to eq(form_url(form))
24+
expect(mail.govuk_notify_personalisation[:group_name]).to eq(form.group.name)
25+
expect(mail.govuk_notify_personalisation[:user_name]).to eq(user.name)
26+
expect(mail.govuk_notify_personalisation[:user_email]).to eq(user.email)
27+
end
28+
end
29+
30+
describe "#copied_draft_form_created" do
31+
subject(:mail) do
32+
described_class.copied_draft_form_created(form:, copied_from_form:, user:, to_email:)
33+
end
34+
35+
let(:copied_from_form) { create :form }
36+
37+
it "sends an email with the correct template" do
38+
expect(mail.govuk_notify_template).to eq(Settings.govuk_notify.org_admin_alerts.copied_draft_form_created_template_id)
39+
end
40+
41+
it "sends an email to the correct email address" do
42+
expect(mail.to).to eq([to_email])
43+
end
44+
45+
it "includes the personalisation" do
46+
expect(mail.govuk_notify_personalisation[:form_name]).to eq(form.name)
47+
expect(mail.govuk_notify_personalisation[:form_link]).to eq(form_url(form))
48+
expect(mail.govuk_notify_personalisation[:copied_from_form_name]).to eq(copied_from_form.name)
49+
expect(mail.govuk_notify_personalisation[:copied_from_form_link]).to eq(form_url(copied_from_form))
50+
expect(mail.govuk_notify_personalisation[:group_name]).to eq(form.group.name)
51+
expect(mail.govuk_notify_personalisation[:user_name]).to eq(user.name)
52+
expect(mail.govuk_notify_personalisation[:user_email]).to eq(user.email)
53+
end
54+
end
55+
56+
describe "#new_archived_form_draft_created" do
57+
subject(:mail) do
58+
described_class.new_archived_form_draft_created(form: archived_form, user:, to_email:)
59+
end
60+
61+
let(:archived_form) { create :form, :archived_with_draft, :with_group }
62+
63+
it "sends an email with the correct template" do
64+
expect(mail.govuk_notify_template).to eq(Settings.govuk_notify.org_admin_alerts.new_archived_form_draft_created_template_id)
65+
end
66+
67+
it "sends an email to the correct email address" do
68+
expect(mail.to).to eq([to_email])
69+
end
70+
71+
it "includes the personalisation" do
72+
expect(mail.govuk_notify_personalisation[:form_name]).to eq(archived_form.name)
73+
expect(mail.govuk_notify_personalisation[:form_link]).to eq(form_url(archived_form))
74+
expect(mail.govuk_notify_personalisation[:archived_form_name]).to eq(archived_form.archived_form_document.content["name"])
75+
expect(mail.govuk_notify_personalisation[:archived_form_link]).to eq(archived_form_url(archived_form))
76+
expect(mail.govuk_notify_personalisation[:group_name]).to eq(archived_form.group.name)
77+
expect(mail.govuk_notify_personalisation[:user_name]).to eq(user.name)
78+
expect(mail.govuk_notify_personalisation[:user_email]).to eq(user.email)
79+
end
80+
end
81+
82+
describe "#new_live_form_draft_created" do
83+
subject(:mail) do
84+
described_class.new_live_form_draft_created(form: live_form, user:, to_email:)
85+
end
86+
87+
let(:live_form) { create :form, :live_with_draft, :with_group }
88+
89+
it "sends an email with the correct template" do
90+
expect(mail.govuk_notify_template).to eq(Settings.govuk_notify.org_admin_alerts.new_live_form_draft_created_template_id)
91+
end
92+
93+
it "sends an email to the correct email address" do
94+
expect(mail.to).to eq([to_email])
95+
end
96+
97+
it "includes the personalisation" do
98+
expect(mail.govuk_notify_personalisation[:form_name]).to eq(live_form.name)
99+
expect(mail.govuk_notify_personalisation[:form_link]).to eq(form_url(live_form))
100+
expect(mail.govuk_notify_personalisation[:live_form_name]).to eq(live_form.live_form_document.content["name"])
101+
expect(mail.govuk_notify_personalisation[:live_form_link]).to eq(live_form_url(live_form))
102+
expect(mail.govuk_notify_personalisation[:group_name]).to eq(live_form.group.name)
103+
expect(mail.govuk_notify_personalisation[:user_name]).to eq(user.name)
104+
expect(mail.govuk_notify_personalisation[:user_email]).to eq(user.email)
105+
end
106+
end
107+
end
Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
require "rails_helper"
2+
3+
describe OrgAdminAlerts::MadeLiveMailer, type: :mailer do
4+
let(:form) { create :form, :live }
5+
let(:user) { create :user }
6+
let(:to_email) { "admin@example.gov.uk" }
7+
8+
describe "#new_draft_form_made_live" do
9+
subject(:mail) do
10+
described_class.new_draft_form_made_live(
11+
form:,
12+
user:,
13+
to_email:,
14+
)
15+
end
16+
17+
it "sends an email with the correct template" do
18+
expect(mail.govuk_notify_template).to eq(Settings.govuk_notify.org_admin_alerts.new_draft_form_made_live_template_id)
19+
end
20+
21+
it "sends an email to the correct email address" do
22+
expect(mail.to).to eq([to_email])
23+
end
24+
25+
it "includes the personalisation" do
26+
expect(mail.govuk_notify_personalisation[:form_name]).to eq(form.name)
27+
expect(mail.govuk_notify_personalisation[:form_link]).to eq(live_form_url(form))
28+
expect(mail.govuk_notify_personalisation[:user_name]).to eq(user.name)
29+
expect(mail.govuk_notify_personalisation[:user_email]).to eq(user.email)
30+
end
31+
end
32+
33+
describe "#live_form_changes_made_live" do
34+
subject(:mail) do
35+
described_class.live_form_changes_made_live(
36+
form:,
37+
user:,
38+
to_email:,
39+
)
40+
end
41+
42+
it "sends an email with the correct template" do
43+
expect(mail.govuk_notify_template).to eq(Settings.govuk_notify.org_admin_alerts.live_form_changes_made_live_template_id)
44+
end
45+
46+
it "sends an email to the correct email address" do
47+
expect(mail.to).to eq([to_email])
48+
end
49+
50+
it "includes the personalisation" do
51+
expect(mail.govuk_notify_personalisation[:form_name]).to eq(form.name)
52+
expect(mail.govuk_notify_personalisation[:form_link]).to eq(live_form_url(form))
53+
expect(mail.govuk_notify_personalisation[:user_name]).to eq(user.name)
54+
expect(mail.govuk_notify_personalisation[:user_email]).to eq(user.email)
55+
end
56+
end
57+
58+
describe "#archived_form_changes_made_live" do
59+
subject(:mail) do
60+
described_class.archived_form_changes_made_live(
61+
form:,
62+
user:,
63+
to_email:,
64+
)
65+
end
66+
67+
it "sends an email with the correct template" do
68+
expect(mail.govuk_notify_template).to eq(Settings.govuk_notify.org_admin_alerts.archived_form_changes_made_live_template_id)
69+
end
70+
71+
it "sends an email to the correct email address" do
72+
expect(mail.to).to eq([to_email])
73+
end
74+
75+
it "includes the personalisation" do
76+
expect(mail.govuk_notify_personalisation[:form_name]).to eq(form.name)
77+
expect(mail.govuk_notify_personalisation[:form_link]).to eq(live_form_url(form))
78+
expect(mail.govuk_notify_personalisation[:user_name]).to eq(user.name)
79+
expect(mail.govuk_notify_personalisation[:user_email]).to eq(user.email)
80+
end
81+
end
82+
83+
describe "#copied_form_made_live" do
84+
subject(:mail) do
85+
described_class.copied_form_made_live(
86+
form:,
87+
copied_from_form:,
88+
user:,
89+
to_email:,
90+
)
91+
end
92+
93+
let(:copied_from_form) { create :form }
94+
95+
it "sends an email with the correct template" do
96+
expect(mail.govuk_notify_template).to eq(Settings.govuk_notify.org_admin_alerts.copied_form_made_live_template_id)
97+
end
98+
99+
it "sends an email to the correct email address" do
100+
expect(mail.to).to eq([to_email])
101+
end
102+
103+
it "includes the personalisation" do
104+
expect(mail.govuk_notify_personalisation[:form_name]).to eq(form.name)
105+
expect(mail.govuk_notify_personalisation[:form_link]).to eq(live_form_url(form))
106+
expect(mail.govuk_notify_personalisation[:copied_from_form_name]).to eq(copied_from_form.name)
107+
expect(mail.govuk_notify_personalisation[:copied_from_form_link]).to eq(form_url(copied_from_form))
108+
expect(mail.govuk_notify_personalisation[:user_name]).to eq(user.name)
109+
expect(mail.govuk_notify_personalisation[:user_email]).to eq(user.email)
110+
end
111+
end
112+
113+
describe "#archived_form_made_live" do
114+
subject(:mail) do
115+
described_class.archived_form_made_live(
116+
form:,
117+
user:,
118+
to_email:,
119+
)
120+
end
121+
122+
it "sends an email with the correct template" do
123+
expect(mail.govuk_notify_template).to eq(Settings.govuk_notify.org_admin_alerts.archived_form_made_live_template_id)
124+
end
125+
126+
it "sends an email to the correct email address" do
127+
expect(mail.to).to eq([to_email])
128+
end
129+
130+
it "includes the personalisation" do
131+
expect(mail.govuk_notify_personalisation[:form_name]).to eq(form.name)
132+
expect(mail.govuk_notify_personalisation[:form_link]).to eq(live_form_url(form))
133+
expect(mail.govuk_notify_personalisation[:user_name]).to eq(user.name)
134+
expect(mail.govuk_notify_personalisation[:user_email]).to eq(user.email)
135+
end
136+
end
137+
end

0 commit comments

Comments
 (0)