|
| 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