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
3 changes: 2 additions & 1 deletion .review_apps/ecs_task_definition.tf
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ locals {
{ name = "SETTINGS__AUTH_PROVIDER", value = "developer" },
{ name = "SETTINGS__FORMS_ENV", value = "review" },
{ name = "SETTINGS__FORMS_RUNNER__URL", value = "https://${local.runner_review_app_hostname}" },
{ name = "ALLOWED_HOST_PATTERNS", value = "localhost:3000" }
{ name = "ALLOWED_HOST_PATTERNS", value = "localhost:3000" },
{ name = "SETTINGS__FEATURES__JSON_SUBMISSION_ENABLED", value = "true" }
]
}

Expand Down
3 changes: 2 additions & 1 deletion app/mailers/aws_ses_form_submission_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ class AwsSesFormSubmissionMailer < ApplicationMailer
reply_to: Settings.ses_submission_email.reply_to_email_address,
delivery_method: Rails.configuration.x.aws_ses_form_submission_mailer["delivery_method"]

def submission_email(answer_content_html:, answer_content_plain_text:, submission:, files:, csv_filename: nil)
def submission_email(answer_content_html:, answer_content_plain_text:, submission:, files:, csv_filename: nil, json_filename: nil)
@answer_content_html = answer_content_html
@answer_content_plain_text = answer_content_plain_text
@submission = submission
@subject = email_subject
@csv_filename = csv_filename
@json_filename = json_filename

files.each do |name, file|
attachments[name] = {
Expand Down
3 changes: 2 additions & 1 deletion app/services/aws_ses_submission_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ def deliver_submission_email
answer_content_plain_text:,
submission: @submission,
files:,
csv_filename:).deliver_now
csv_filename:,
json_filename:).deliver_now

CurrentJobLoggingAttributes.mail_message_id = mail.message_id
mail.message_id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@
<p><%= I18n.t("mailer.submission.csv_file", filename: @csv_filename) %></p>
<% end %>

<% if @json_filename.present? %>
<p><%= I18n.t("mailer.submission.json_file", filename: @json_filename) %></p>
<% end %>

<%= @answer_content_html.html_safe %>

<hr style="border: 0; height: 1px; background: #B1B4B6; margin: 30px 0 30px 0;">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@
<%= I18n.t("mailer.submission.csv_file", filename: @csv_filename) %>
<% end %>

<% if @json_filename.present? %>
<%= I18n.t("mailer.submission.json_file", filename: @json_filename) %>
<% end %>

<%= @answer_content_plain_text %>

---
Expand Down
1 change: 1 addition & 0 deletions config/locales/cy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,7 @@ cy:
csv_file: 'A CSV file of these answers is attached to this email in a file named: %{filename}'
file_attached: "%{filename} (attached to this email)"
from: GOV.UK Forms <%{email_address}>
json_file: 'A JSON file of these answers is attached to this email in a file named: %{filename}'
payment: You can check that a payment has been made by using this reference number to search transactions within GOV.​UK Pay.
preview: This is a test submission from a preview of this form.
question_skipped: This question was skipped
Expand Down
1 change: 1 addition & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,7 @@ en:
csv_file: 'A CSV file of these answers is attached to this email in a file named: %{filename}'
file_attached: "%{filename} (attached to this email)"
from: GOV.UK Forms <%{email_address}>
json_file: 'A JSON file of these answers is attached to this email in a file named: %{filename}'
payment: You can check that a payment has been made by using this reference number to search transactions within GOV.​UK Pay.
preview: This is a test submission from a preview of this form.
question_skipped: This question was skipped
Expand Down
3 changes: 3 additions & 0 deletions spec/mailers/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Previewing emails

To preview emails listed in `aws_ses_form_submission_mailer_preview.rb` locally, use the route `/rails/mailers` while the rails server is running.
21 changes: 21 additions & 0 deletions spec/mailers/aws_ses_form_submission_mailer_preview.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,25 @@ def submission_email_with_csv
files: {},
csv_filename: "my_answers.csv")
end

def submission_email_with_json
form_document = build(:v2_form_document, submission_email: "testing@gov.uk", payment_url: "https://www.gov.uk/payments/your-payment-link")
submission = build(:submission, form_document:, is_preview: false)
AwsSesFormSubmissionMailer.submission_email(answer_content_html: "<h3>What's your email address?</h3><p>forms@example.gov.uk</p>",
answer_content_plain_text: "What's your email address?\n\nforms@example.gov.uk",
submission:,
files: {},
json_filename: "my_answers.json")
end

def submission_email_with_csv_and_json
form_document = build(:v2_form_document, submission_email: "testing@gov.uk", payment_url: "https://www.gov.uk/payments/your-payment-link")
submission = build(:submission, form_document:, is_preview: false)
AwsSesFormSubmissionMailer.submission_email(answer_content_html: "<h3>What's your email address?</h3><p>forms@example.gov.uk</p>",
answer_content_plain_text: "What's your email address?\n\nforms@example.gov.uk",
submission:,
files: {},
csv_filename: "my_answers.csv",
json_filename: "my_answers.json")
end
end
23 changes: 22 additions & 1 deletion spec/mailers/aws_ses_form_submission_mailer_spec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require "rails_helper"

describe AwsSesFormSubmissionMailer, type: :mailer do
subject(:mail) { described_class.submission_email(answer_content_html:, answer_content_plain_text:, submission:, files:, csv_filename:) }
subject(:mail) { described_class.submission_email(answer_content_html:, answer_content_plain_text:, submission:, files:, csv_filename:, json_filename:) }

let(:submission) do
build(:submission, form_document: form_document, created_at: submission_timestamp,
Expand All @@ -17,6 +17,7 @@
let(:submission_reference) { Faker::Alphanumeric.alphanumeric(number: 8).upcase }
let(:payment_url) { nil }
let(:csv_filename) { nil }
let(:json_filename) { nil }
let(:submission_timestamp) { Time.utc(2022, 12, 14, 13, 0o0, 0o0) }

context "when form filler submits a completed form" do
Expand Down Expand Up @@ -256,6 +257,26 @@
expect(part.body).not_to have_text(I18n.t("mailer.submission.csv_file", filename: csv_filename))
end
end

context "when the json file of answers is attached" do
let(:json_filename) { "my_answers.json" }

describe "the html part" do
let(:part) { mail.html_part }

it "includes text about the JSON filename" do
expect(part.body).to have_css("p", text: I18n.t("mailer.submission.json_file", filename: json_filename))
end
end

describe "the plaintext part" do
let(:part) { mail.text_part }

it "includes text about the JSON filename" do
expect(part.body).to have_text(I18n.t("mailer.submission.json_file", filename: json_filename))
end
end
end
end
end

Expand Down
6 changes: 6 additions & 0 deletions spec/services/aws_ses_submission_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
submission:,
files: {},
csv_filename: nil,
json_filename: nil,
).once
end
end
Expand Down Expand Up @@ -100,6 +101,7 @@
submission:,
files: { question.email_filename => file_content },
csv_filename: nil,
json_filename: nil,
).once
end

Expand Down Expand Up @@ -165,6 +167,7 @@
submission: submission,
files: { "govuk_forms_a_great_form_#{submission_reference}.csv" => expected_csv_content },
csv_filename: "govuk_forms_a_great_form_#{submission_reference}.csv",
json_filename: nil,
).once
end

Expand Down Expand Up @@ -196,6 +199,7 @@
question.email_filename => file_content,
},
csv_filename: "govuk_forms_a_great_form_#{submission_reference}.csv",
json_filename: nil,
).once
end
end
Expand All @@ -214,6 +218,7 @@
JSON.parse(json)["form_name"] == "A great form"
end,
},
json_filename: "govuk_forms_a_great_form_#{submission_reference}.json",
),
).and_call_original

Expand Down Expand Up @@ -254,6 +259,7 @@
submission:,
files: {},
csv_filename: nil,
json_filename: nil,
).once
end
end
Expand Down
Loading