|
| 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 |
0 commit comments