-
Notifications
You must be signed in to change notification settings - Fork 10
Add mailers for org admin alerts #2602
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| class OrgAdminAlerts::DraftCreatedMailer < GovukNotifyRails::Mailer | ||
| include Rails.application.routes.url_helpers | ||
| def new_draft_form_created(form:, user:, to_email:) | ||
| set_template(Settings.govuk_notify.org_admin_alerts.new_draft_form_created_template_id) | ||
| send_mail(to_email:, personalisation: { | ||
| form_name: form.name, | ||
| form_link: form_url(form), | ||
| group_name: form.group.name, | ||
| user_name: user.name, | ||
| user_email: user.email, | ||
| }) | ||
| end | ||
|
|
||
| def copied_draft_form_created(form:, copied_from_form:, user:, to_email:) | ||
| set_template(Settings.govuk_notify.org_admin_alerts.copied_draft_form_created_template_id) | ||
| send_mail(to_email:, personalisation: { | ||
| form_name: form.name, | ||
| form_link: form_url(form), | ||
| copied_from_form_name: copied_from_form.name, | ||
| copied_from_form_link: form_url(copied_from_form), | ||
| group_name: form.group.name, | ||
| user_name: user.name, | ||
| user_email: user.email, | ||
| }) | ||
| end | ||
|
|
||
| def new_archived_form_draft_created(form:, user:, to_email:) | ||
| set_template(Settings.govuk_notify.org_admin_alerts.new_archived_form_draft_created_template_id) | ||
| send_mail(to_email:, personalisation: { | ||
| form_name: form.name, | ||
| form_link: form_url(form), | ||
| archived_form_name: form.archived_form_document.content["name"], | ||
| archived_form_link: archived_form_url(form), | ||
| group_name: form.group.name, | ||
| user_name: user.name, | ||
| user_email: user.email, | ||
| }) | ||
| end | ||
|
|
||
| def new_live_form_draft_created(form:, user:, to_email:) | ||
| set_template(Settings.govuk_notify.org_admin_alerts.new_live_form_draft_created_template_id) | ||
| send_mail(to_email:, personalisation: { | ||
| form_name: form.name, | ||
| form_link: form_url(form), | ||
| live_form_name: form.live_form_document.content["name"], | ||
| live_form_link: live_form_url(form), | ||
| group_name: form.group.name, | ||
| user_name: user.name, | ||
| user_email: user.email, | ||
| }) | ||
| end | ||
|
|
||
| private | ||
|
|
||
| def send_mail(to_email:, personalisation:) | ||
| set_personalisation(**personalisation) | ||
|
|
||
| mail(to: to_email) | ||
| end | ||
| end |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| class OrgAdminAlerts::MadeLiveMailer < GovukNotifyRails::Mailer | ||
| include Rails.application.routes.url_helpers | ||
| def new_draft_form_made_live(form:, user:, to_email:) | ||
| set_template(Settings.govuk_notify.org_admin_alerts.new_draft_form_made_live_template_id) | ||
| send_mail(to_email:, personalisation: { | ||
| form_name: form.name, | ||
| form_link: live_form_url(form), | ||
| user_name: user.name, | ||
| user_email: user.email, | ||
| }) | ||
| end | ||
|
|
||
| def live_form_changes_made_live(form:, user:, to_email:) | ||
| set_template(Settings.govuk_notify.org_admin_alerts.live_form_changes_made_live_template_id) | ||
| send_mail(to_email:, personalisation: { | ||
| form_name: form.name, | ||
| form_link: live_form_url(form), | ||
| user_name: user.name, | ||
| user_email: user.email, | ||
| }) | ||
| end | ||
|
|
||
| def archived_form_changes_made_live(form:, user:, to_email:) | ||
| set_template(Settings.govuk_notify.org_admin_alerts.archived_form_changes_made_live_template_id) | ||
| send_mail(to_email:, personalisation: { | ||
| form_name: form.name, | ||
| form_link: live_form_url(form), | ||
| user_name: user.name, | ||
| user_email: user.email, | ||
| }) | ||
| end | ||
|
|
||
| def copied_form_made_live(form:, copied_from_form:, user:, to_email:) | ||
| set_template(Settings.govuk_notify.org_admin_alerts.copied_form_made_live_template_id) | ||
| send_mail(to_email:, personalisation: { | ||
| form_name: form.name, | ||
| form_link: live_form_url(form), | ||
| copied_from_form_name: copied_from_form.name, | ||
| copied_from_form_link: form_url(copied_from_form), | ||
| user_name: user.name, | ||
| user_email: user.email, | ||
| }) | ||
| end | ||
|
|
||
| def archived_form_made_live(form:, user:, to_email:) | ||
| set_template(Settings.govuk_notify.org_admin_alerts.archived_form_made_live_template_id) | ||
| send_mail(to_email:, personalisation: { | ||
| form_name: form.name, | ||
| form_link: live_form_url(form), | ||
| user_name: user.name, | ||
| user_email: user.email, | ||
| }) | ||
| end | ||
|
|
||
| private | ||
|
|
||
| def send_mail(to_email:, personalisation:) | ||
| set_personalisation(**personalisation) | ||
|
|
||
| mail(to: to_email) | ||
| end | ||
| end |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,119 @@ | ||
| require "rails_helper" | ||
|
|
||
| describe OrgAdminAlerts::DraftCreatedMailer, type: :mailer do | ||
| let(:form) { create :form, :with_group } | ||
| let(:user) { create :user } | ||
| let(:to_email) { "admin@example.gov.uk" } | ||
|
|
||
| describe "#new_draft_form_created" do | ||
| subject(:mail) do | ||
| described_class.new_draft_form_created(form:, user:, to_email:) | ||
| end | ||
|
|
||
| it "sends an email with the correct template" do | ||
|
Check failure on line 13 in spec/mailers/org_admin_alerts/draft_created_mailer_spec.rb
|
||
| expect(mail.govuk_notify_template).to eq(Settings.govuk_notify.org_admin_alerts.new_draft_form_created_template_id) | ||
| end | ||
|
|
||
| it "sends an email to the correct email address" do | ||
|
Check failure on line 17 in spec/mailers/org_admin_alerts/draft_created_mailer_spec.rb
|
||
| expect(mail.to).to eq([to_email]) | ||
| end | ||
|
|
||
| it "includes the personalisation" do | ||
|
Check failure on line 21 in spec/mailers/org_admin_alerts/draft_created_mailer_spec.rb
|
||
| expect(mail.govuk_notify_personalisation[:form_name]).to eq(form.name) | ||
| expect(mail.govuk_notify_personalisation[:form_link]).to eq(form_url(form)) | ||
| expect(mail.govuk_notify_personalisation[:group_name]).to eq(form.group.name) | ||
| expect(mail.govuk_notify_personalisation[:user_name]).to eq(user.name) | ||
| expect(mail.govuk_notify_personalisation[:user_email]).to eq(user.email) | ||
| end | ||
| end | ||
|
|
||
| describe "#copied_draft_form_created" do | ||
| subject(:mail) do | ||
| described_class.copied_draft_form_created(form:, copied_from_form:, user:, to_email:) | ||
| end | ||
|
|
||
| let(:copied_from_form) { create :form } | ||
|
|
||
| it "sends an email with the correct template" do | ||
| expect(mail.govuk_notify_template).to eq(Settings.govuk_notify.org_admin_alerts.copied_draft_form_created_template_id) | ||
| end | ||
|
|
||
| it "sends an email to the correct email address" do | ||
| expect(mail.to).to eq([to_email]) | ||
| end | ||
|
|
||
| it "includes the personalisation" do | ||
| expect(mail.govuk_notify_personalisation[:form_name]).to eq(form.name) | ||
| expect(mail.govuk_notify_personalisation[:form_link]).to eq(form_url(form)) | ||
| expect(mail.govuk_notify_personalisation[:copied_from_form_name]).to eq(copied_from_form.name) | ||
| expect(mail.govuk_notify_personalisation[:copied_from_form_link]).to eq(form_url(copied_from_form)) | ||
| expect(mail.govuk_notify_personalisation[:group_name]).to eq(form.group.name) | ||
| expect(mail.govuk_notify_personalisation[:user_name]).to eq(user.name) | ||
| expect(mail.govuk_notify_personalisation[:user_email]).to eq(user.email) | ||
| end | ||
| end | ||
|
|
||
| describe "#new_archived_form_draft_created" do | ||
| subject(:mail) do | ||
| described_class.new_archived_form_draft_created(form: archived_form, user:, to_email:) | ||
| end | ||
|
|
||
| let(:archived_form) { create :form, :archived_with_draft, :with_group } | ||
| let(:new_draft_name) { "New Draft Form Name" } | ||
|
|
||
| before do | ||
| archived_form.name = new_draft_name | ||
| archived_form.save! | ||
| end | ||
|
|
||
| it "sends an email with the correct template" do | ||
| expect(mail.govuk_notify_template).to eq(Settings.govuk_notify.org_admin_alerts.new_archived_form_draft_created_template_id) | ||
| end | ||
|
|
||
| it "sends an email to the correct email address" do | ||
| expect(mail.to).to eq([to_email]) | ||
| end | ||
|
|
||
| it "includes the personalisation" do | ||
| expect(mail.govuk_notify_personalisation[:form_name]).to eq(new_draft_name) | ||
| expect(mail.govuk_notify_personalisation[:form_link]).to eq(form_url(archived_form)) | ||
| expect(mail.govuk_notify_personalisation[:archived_form_name]).to eq(archived_form.archived_form_document.content["name"]) | ||
| expect(mail.govuk_notify_personalisation[:archived_form_link]).to eq(archived_form_url(archived_form)) | ||
| expect(mail.govuk_notify_personalisation[:group_name]).to eq(archived_form.group.name) | ||
| expect(mail.govuk_notify_personalisation[:user_name]).to eq(user.name) | ||
| expect(mail.govuk_notify_personalisation[:user_email]).to eq(user.email) | ||
| end | ||
| end | ||
|
|
||
| describe "#new_live_form_draft_created" do | ||
| subject(:mail) do | ||
| described_class.new_live_form_draft_created(form: live_form, user:, to_email:) | ||
| end | ||
|
|
||
| let(:live_form) { create :form, :live_with_draft, :with_group } | ||
| let(:new_draft_name) { "New Draft Form Name" } | ||
|
|
||
| before do | ||
| live_form.name = new_draft_name | ||
| live_form.save! | ||
| end | ||
|
|
||
| it "sends an email with the correct template" do | ||
| expect(mail.govuk_notify_template).to eq(Settings.govuk_notify.org_admin_alerts.new_live_form_draft_created_template_id) | ||
| end | ||
|
|
||
| it "sends an email to the correct email address" do | ||
| expect(mail.to).to eq([to_email]) | ||
| end | ||
|
|
||
| it "includes the personalisation" do | ||
| expect(mail.govuk_notify_personalisation[:form_name]).to eq(new_draft_name) | ||
| expect(mail.govuk_notify_personalisation[:form_link]).to eq(form_url(live_form)) | ||
| expect(mail.govuk_notify_personalisation[:live_form_name]).to eq(live_form.live_form_document.content["name"]) | ||
| expect(mail.govuk_notify_personalisation[:live_form_link]).to eq(live_form_url(live_form)) | ||
| expect(mail.govuk_notify_personalisation[:group_name]).to eq(live_form.group.name) | ||
| expect(mail.govuk_notify_personalisation[:user_name]).to eq(user.name) | ||
| expect(mail.govuk_notify_personalisation[:user_email]).to eq(user.email) | ||
| end | ||
| end | ||
| end | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,137 @@ | ||
| require "rails_helper" | ||
|
|
||
| describe OrgAdminAlerts::MadeLiveMailer, type: :mailer do | ||
| let(:form) { create :form, :live } | ||
| let(:user) { create :user } | ||
| let(:to_email) { "admin@example.gov.uk" } | ||
|
|
||
| describe "#new_draft_form_made_live" do | ||
| subject(:mail) do | ||
| described_class.new_draft_form_made_live( | ||
| form:, | ||
| user:, | ||
| to_email:, | ||
| ) | ||
| end | ||
|
|
||
| it "sends an email with the correct template" do | ||
|
Check failure on line 17 in spec/mailers/org_admin_alerts/made_live_mailer_spec.rb
|
||
| expect(mail.govuk_notify_template).to eq(Settings.govuk_notify.org_admin_alerts.new_draft_form_made_live_template_id) | ||
| end | ||
|
|
||
| it "sends an email to the correct email address" do | ||
|
Check failure on line 21 in spec/mailers/org_admin_alerts/made_live_mailer_spec.rb
|
||
| expect(mail.to).to eq([to_email]) | ||
| end | ||
|
|
||
| it "includes the personalisation" do | ||
|
Check failure on line 25 in spec/mailers/org_admin_alerts/made_live_mailer_spec.rb
|
||
| expect(mail.govuk_notify_personalisation[:form_name]).to eq(form.name) | ||
| expect(mail.govuk_notify_personalisation[:form_link]).to eq(live_form_url(form)) | ||
| expect(mail.govuk_notify_personalisation[:user_name]).to eq(user.name) | ||
| expect(mail.govuk_notify_personalisation[:user_email]).to eq(user.email) | ||
| end | ||
| end | ||
|
|
||
| describe "#live_form_changes_made_live" do | ||
| subject(:mail) do | ||
| described_class.live_form_changes_made_live( | ||
| form:, | ||
| user:, | ||
| to_email:, | ||
| ) | ||
| end | ||
|
|
||
| it "sends an email with the correct template" do | ||
| expect(mail.govuk_notify_template).to eq(Settings.govuk_notify.org_admin_alerts.live_form_changes_made_live_template_id) | ||
| end | ||
|
|
||
| it "sends an email to the correct email address" do | ||
| expect(mail.to).to eq([to_email]) | ||
| end | ||
|
|
||
| it "includes the personalisation" do | ||
| expect(mail.govuk_notify_personalisation[:form_name]).to eq(form.name) | ||
| expect(mail.govuk_notify_personalisation[:form_link]).to eq(live_form_url(form)) | ||
| expect(mail.govuk_notify_personalisation[:user_name]).to eq(user.name) | ||
| expect(mail.govuk_notify_personalisation[:user_email]).to eq(user.email) | ||
| end | ||
| end | ||
|
|
||
| describe "#archived_form_changes_made_live" do | ||
| subject(:mail) do | ||
| described_class.archived_form_changes_made_live( | ||
| form:, | ||
| user:, | ||
| to_email:, | ||
| ) | ||
| end | ||
|
|
||
| it "sends an email with the correct template" do | ||
| expect(mail.govuk_notify_template).to eq(Settings.govuk_notify.org_admin_alerts.archived_form_changes_made_live_template_id) | ||
| end | ||
|
|
||
| it "sends an email to the correct email address" do | ||
| expect(mail.to).to eq([to_email]) | ||
| end | ||
|
|
||
| it "includes the personalisation" do | ||
| expect(mail.govuk_notify_personalisation[:form_name]).to eq(form.name) | ||
| expect(mail.govuk_notify_personalisation[:form_link]).to eq(live_form_url(form)) | ||
| expect(mail.govuk_notify_personalisation[:user_name]).to eq(user.name) | ||
| expect(mail.govuk_notify_personalisation[:user_email]).to eq(user.email) | ||
| end | ||
| end | ||
|
|
||
| describe "#copied_form_made_live" do | ||
| subject(:mail) do | ||
| described_class.copied_form_made_live( | ||
| form:, | ||
| copied_from_form:, | ||
| user:, | ||
| to_email:, | ||
| ) | ||
| end | ||
|
|
||
| let(:copied_from_form) { create :form } | ||
|
|
||
| it "sends an email with the correct template" do | ||
| expect(mail.govuk_notify_template).to eq(Settings.govuk_notify.org_admin_alerts.copied_form_made_live_template_id) | ||
| end | ||
|
|
||
| it "sends an email to the correct email address" do | ||
| expect(mail.to).to eq([to_email]) | ||
| end | ||
|
|
||
| it "includes the personalisation" do | ||
| expect(mail.govuk_notify_personalisation[:form_name]).to eq(form.name) | ||
| expect(mail.govuk_notify_personalisation[:form_link]).to eq(live_form_url(form)) | ||
| expect(mail.govuk_notify_personalisation[:copied_from_form_name]).to eq(copied_from_form.name) | ||
| expect(mail.govuk_notify_personalisation[:copied_from_form_link]).to eq(form_url(copied_from_form)) | ||
| expect(mail.govuk_notify_personalisation[:user_name]).to eq(user.name) | ||
| expect(mail.govuk_notify_personalisation[:user_email]).to eq(user.email) | ||
| end | ||
| end | ||
|
|
||
| describe "#archived_form_made_live" do | ||
| subject(:mail) do | ||
| described_class.archived_form_made_live( | ||
| form:, | ||
| user:, | ||
| to_email:, | ||
| ) | ||
| end | ||
|
|
||
| it "sends an email with the correct template" do | ||
| expect(mail.govuk_notify_template).to eq(Settings.govuk_notify.org_admin_alerts.archived_form_made_live_template_id) | ||
| end | ||
|
|
||
| it "sends an email to the correct email address" do | ||
| expect(mail.to).to eq([to_email]) | ||
| end | ||
|
|
||
| it "includes the personalisation" do | ||
| expect(mail.govuk_notify_personalisation[:form_name]).to eq(form.name) | ||
| expect(mail.govuk_notify_personalisation[:form_link]).to eq(live_form_url(form)) | ||
| expect(mail.govuk_notify_personalisation[:user_name]).to eq(user.name) | ||
| expect(mail.govuk_notify_personalisation[:user_email]).to eq(user.email) | ||
| end | ||
| end | ||
| end | ||
Uh oh!
There was an error while loading. Please reload this page.