Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 60 additions & 0 deletions app/mailers/org_admin_alerts/draft_created_mailer.rb
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
62 changes: 62 additions & 0 deletions app/mailers/org_admin_alerts/made_live_mailer.rb
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
10 changes: 10 additions & 0 deletions config/settings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,16 @@ govuk_notify:
group_upgrade_rejected_template_id: f494999a-1a38-4b01-a3c8-dbb2d60e6e5f
group_deleted_group_admin_editor_template_id: b987d794-9214-40f5-8014-65d5b9c058d8
group_deleted_org_admin_template_id: 4c6d6c67-e9f1-4012-adc2-05f23dc69638
org_admin_alerts:
new_draft_form_made_live_template_id: 95065d23-e7ad-4af7-9a2f-7209276d74d0
live_form_changes_made_live_template_id: 02c38f9b-197e-480d-8031-bba9498d5907
archived_form_changes_made_live_template_id: 9db2d85b-9db4-48c3-bbc6-31aa0c742384
copied_form_made_live_template_id: 2c8d446c-474e-4f0e-9319-4c1b309e9727
archived_form_made_live_template_id: 85a4fb11-5cc5-42dc-ae27-78d187850605
new_draft_form_created_template_id: 1dc55d5d-c088-4464-b56f-132da1802058
copied_draft_form_created_template_id: a2d4f9a0-71b6-483d-ba83-0eb2e2592772
new_archived_form_draft_created_template_id: 02228b71-e680-4152-a5bd-0bc4b8a4695f
new_live_form_draft_created_template_id: 8c114e68-edd1-470b-bbf9-532733eaa0d1

# When set to true, any capybara tests will run chrome normally rather than in headless mode.
show_browser_during_tests: false
Expand Down
119 changes: 119 additions & 0 deletions spec/mailers/org_admin_alerts/draft_created_mailer_spec.rb
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

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Define a constant instead of duplicating this literal "sends an email with the correct template" 4 times.

See more on https://sonarcloud.io/project/issues?id=alphagov_forms-admin&issues=AZzC2t-lRf3m_395Ndi3&open=AZzC2t-lRf3m_395Ndi3&pullRequest=2602
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

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Define a constant instead of duplicating this literal "sends an email to the correct email address" 4 times.

See more on https://sonarcloud.io/project/issues?id=alphagov_forms-admin&issues=AZzC2t-lRf3m_395Ndi5&open=AZzC2t-lRf3m_395Ndi5&pullRequest=2602
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

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Define a constant instead of duplicating this literal "includes the personalisation" 4 times.

See more on https://sonarcloud.io/project/issues?id=alphagov_forms-admin&issues=AZzC2t-lRf3m_395Ndi1&open=AZzC2t-lRf3m_395Ndi1&pullRequest=2602
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
137 changes: 137 additions & 0 deletions spec/mailers/org_admin_alerts/made_live_mailer_spec.rb
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

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Define a constant instead of duplicating this literal "sends an email with the correct template" 5 times.

See more on https://sonarcloud.io/project/issues?id=alphagov_forms-admin&issues=AZzC2t-WRf3m_395Ndiz&open=AZzC2t-WRf3m_395Ndiz&pullRequest=2602
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

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Define a constant instead of duplicating this literal "sends an email to the correct email address" 5 times.

See more on https://sonarcloud.io/project/issues?id=alphagov_forms-admin&issues=AZzC2t-WRf3m_395Ndi0&open=AZzC2t-WRf3m_395Ndi0&pullRequest=2602
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

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Define a constant instead of duplicating this literal "includes the personalisation" 5 times.

See more on https://sonarcloud.io/project/issues?id=alphagov_forms-admin&issues=AZzC2t-WRf3m_395Ndiy&open=AZzC2t-WRf3m_395Ndiy&pullRequest=2602
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
Loading