Skip to content
Draft
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
1 change: 0 additions & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -860,7 +860,6 @@ CHECKSUMS
bootsnap (1.24.3) sha256=f7fa3d20597e2f0aa52b0a1aba83fb54d4f79e9c2e210ec4fa1e8895514dcad8
brakeman (8.0.4) sha256=7bf921fa9638544835df9aa7b3e720a9a72c0267f34f92135955edd80d4dcf6f
builder (3.3.0) sha256=497918d2f9dca528fdca4b88d84e4ef4387256d984b8154e9d5d3fe5a9c8835f
bundler (4.0.11) sha256=5bcec0fb78302e48d02ee46f10ee6e6942be647ba5b44a6d1ddfda9a240ce785
bundler-audit (0.9.3) sha256=81c8766c71e47d0d28a0f98c7eed028539f21a6ea3cd8f685eb6f42333c9b4e9
capybara (3.40.0) sha256=42dba720578ea1ca65fd7a41d163dd368502c191804558f6e0f71b391054aeef
coercible (1.0.0) sha256=5081ad24352cc8435ce5472bc2faa30260c7ea7f2102cc6a9f167c4d9bffaadc
Expand Down
18 changes: 12 additions & 6 deletions app/controllers/forms/check_your_answers_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,24 @@ def show
return redirect_to form_step_path(current_context.form.id, current_context.form.form_slug, current_context.next_step_slug, nil) unless current_context.can_visit?(CheckYourAnswersStep::CHECK_YOUR_ANSWERS_STEP_SLUG)

setup_check_your_answers
email_confirmation_input = EmailConfirmationInput.new
skip_confirmation_email = skip_confirmation_email?
email_confirmation_input = skip_confirmation_email ? EmailConfirmationInput.new(send_confirmation: "skip_confirmation") : EmailConfirmationInput.new

@support_details = current_context.support_details

render template: "forms/check_your_answers/show", locals: { email_confirmation_input: }
render template: "forms/check_your_answers/show", locals: { email_confirmation_input:, skip_confirmation_email: }
end

def submit_answers
@support_details = current_context.support_details
email_confirmation_input = EmailConfirmationInput.new(email_confirmation_input_params)
skip_confirmation_email = skip_confirmation_email?
email_confirmation_input = skip_confirmation_email ? EmailConfirmationInput.new(send_confirmation: "skip_confirmation") : EmailConfirmationInput.new(email_confirmation_input_params)
requested_email_confirmation = email_confirmation_input.send_confirmation == "send_email"

unless email_confirmation_input.valid?
setup_check_your_answers

return render template: "forms/check_your_answers/show", locals: { email_confirmation_input: }, status: :unprocessable_content
return render template: "forms/check_your_answers/show", locals: { email_confirmation_input:, skip_confirmation_email: }, status: :unprocessable_content
end

return redirect_to error_repeat_submission_path(@form.id) if current_context.form_submitted?
Expand All @@ -52,7 +54,7 @@ def submit_answers
rescue FormSubmissionService::ConfirmationEmailToAddressError
setup_check_your_answers
email_confirmation_input.errors.add(:confirmation_email_address, :invalid_email)
render template: "forms/check_your_answers/show", locals: { email_confirmation_input: }, status: :unprocessable_content
render template: "forms/check_your_answers/show", locals: { email_confirmation_input:, skip_confirmation_email: }, status: :unprocessable_content
end
rescue StandardError => e
log_rescued_exception(e)
Expand All @@ -76,8 +78,12 @@ def setup_check_your_answers
end
end

def skip_confirmation_email?
current_context.wants_copy_of_answers? && current_context.get_copy_of_answers_email_address.present?
end

def back_link
if FeatureService.enabled?("filler_answer_email_enabled")
if FeatureService.enabled?("filler_answer_email_enabled") && current_context.form.copy_of_answers_enabled?
copy_of_answers_path(form_id: current_context.form.id, form_slug: current_context.form.form_slug)
else
previous_step = current_context.previous_step(CheckYourAnswersStep::CHECK_YOUR_ANSWERS_STEP_SLUG)
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/forms/copy_of_answers_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def back_link
end

def redirect_if_feature_disabled
return if FeatureService.enabled?(:filler_answer_email_enabled)
return if FeatureService.enabled?(:filler_answer_email_enabled) && current_context.form.copy_of_answers_enabled?

redirect_to check_your_answers_path(form_id: current_context.form.id, form_slug: current_context.form.form_slug)
end
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/forms/step_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ def next_step_changing

def next_step_in_form_path
if @step.next_step_slug_after_routing == CheckYourAnswersStep::CHECK_YOUR_ANSWERS_STEP_SLUG
if FeatureService.enabled?("filler_answer_email_enabled")
if FeatureService.enabled?("filler_answer_email_enabled") && @form.copy_of_answers_enabled?
copy_of_answers_path(form_id: @form.id, form_slug: @form.form_slug)
else
check_answers_path
Expand Down
5 changes: 5 additions & 0 deletions app/models/form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ def initialize(form_document)
:start_page,
:send_daily_submission_batch,
:send_weekly_submission_batch,
:send_copy_of_answers,
:submission_email,
:submission_type,
:support_email,
Expand Down Expand Up @@ -64,6 +65,10 @@ def welsh?
language == :cy
end

def copy_of_answers_enabled?
send_copy_of_answers == "enabled"
end

def multilingual?
available_languages.count > 1
end
Expand Down
16 changes: 10 additions & 6 deletions app/views/forms/check_your_answers/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,18 @@

<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds-from-desktop">
<%= form.govuk_radio_buttons_fieldset(:send_confirmation, legend: { size: 'm', tag: 'h2' }) do %>
<%= form.govuk_radio_button :send_confirmation, 'send_email', link_errors: :true do %>
<%= form.govuk_email_field :confirmation_email_address, autocomplete: 'email', spellcheck: false %>
<% if skip_confirmation_email %>
<p><%= t('form.check_your_answers.send_copy', email_address: @current_context.get_copy_of_answers_email_address) %></p>
<% else %>
<%= form.govuk_radio_buttons_fieldset(:send_confirmation, legend: { size: 'm', tag: 'h2' }) do %>
<%= form.govuk_radio_button :send_confirmation, 'send_email', link_errors: :true do %>
<%= form.govuk_email_field :confirmation_email_address, autocomplete: 'email', spellcheck: false %>
<% end %>
<%= form.govuk_radio_button :send_confirmation, 'skip_confirmation' %>
<% end %>
<%= form.govuk_radio_button :send_confirmation, 'skip_confirmation' %>
<% end %>

<%= form.hidden_field :confirmation_email_reference, id: 'confirmation-email-reference' %>
<%= form.hidden_field :confirmation_email_reference, id: 'confirmation-email-reference' %>
<% end %>

<%if @current_context.form.try(:declaration_markdown).present? %>
<h2 class="govuk-heading-m govuk-!-margin-top-7"><%= t('form.check_your_answers.declaration') %></h2>
Expand Down
3 changes: 3 additions & 0 deletions app/views/forms/submitted/submitted.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds">
<%= render partial: "forms/submitted/submitted_panel", locals: {current_context: @current_context, } %>
<% if @current_context.wants_copy_of_answers? && @current_context.get_copy_of_answers_email_address.present? %>
<p><%= t('form.submitted.copy_of_answers_sent') %></p>
<% end %>

<% if @current_context.requested_email_confirmation? %>
<p><%= t('form.submitted.email_sent') %></p>
Expand Down
2 changes: 2 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -364,11 +364,13 @@ en:
agree_and_submit: Agree and submit
declaration: Declaration
not_completed: Not completed
send_copy: "We’ll send a confirmation email with a copy of your answers to your GOV.UK One Login email address: %{email_address}"
submit: Submit
title: Check your answers before submitting your form
submitted:
continue_to_pay: Continue to pay
email_sent: We’ve sent you a confirmation email.
copy_of_answers_sent: We’ve sent you a confirmation email with a copy of your answers.
need_to_pay: You still need to pay
title: Your form has been submitted
what_happens_next: What happens next
Expand Down
1 change: 1 addition & 0 deletions spec/factories/v2_form_document.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
s3_bucket_name { nil }
s3_bucket_region { nil }
updated_at { Time.current.iso8601(3) }
send_copy_of_answers { "disabled" }
send_daily_submission_batch { false }
send_weekly_submission_batch { false }

Expand Down
18 changes: 18 additions & 0 deletions spec/models/form_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,24 @@
end
end

describe "#copy_of_answers_enabled?" do
context "when send_copy_of_answers is \"enabled\"" do
let(:form_document) { build :v2_form_document, send_copy_of_answers: "enabled" }

it "returns true" do
expect(form.copy_of_answers_enabled?).to be true
end
end

context "when send_copy_of_answers is \"disabled\"" do
let(:form_document) { build :v2_form_document, send_copy_of_answers: "disabled" }

it "returns false" do
expect(form.copy_of_answers_enabled?).to be false
end
end
end

describe "#document_json" do
let(:form_document) { build :v2_form_document, :live, :s3_submissions_enabled }

Expand Down
96 changes: 96 additions & 0 deletions spec/requests/forms/check_your_answers_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
support_email: "help@example.gov.uk",
support_url: "https://example.gov.uk/help",
support_url_text: "Get help",
send_copy_of_answers: "enabled",
submission_email:)
end

Expand Down Expand Up @@ -194,6 +195,75 @@

include_examples "for notification references"
end

context "when the user has said yes to copy of answers and has a One Login email" do
let(:store) do
{
answers:,
confirmation_details: {
form_id.to_s => {
"wants_copy_of_answers" => true,
"copy_of_answers_email_address" => "user@example.gov.uk",
},
},
}.with_indifferent_access
end

before do
get check_your_answers_path(mode:, form_id:, form_slug: form_data.form_slug)
end

it "hides the confirmation email question" do
expect(response.body).not_to include("email_confirmation_input[send_confirmation]")
end
end

context "when the user has said yes to copy of answers but has no One Login email" do
let(:store) do
{
answers:,
confirmation_details: {
form_id.to_s => {
"wants_copy_of_answers" => true,
},
},
}.with_indifferent_access
end

before do
get check_your_answers_path(mode:, form_id:, form_slug: form_data.form_slug)
end

it "shows the confirmation email question" do
expect(response.body).to include("email_confirmation_input[send_confirmation]")
end
end

context "when send_copy_of_answers is disabled on the form" do
let(:form_data) do
build(:v2_form_document, :with_support, :with_submission_email,
form_id: form_id,
start_page: 1,
privacy_policy_url: "http://www.example.gov.uk/privacy_policy",
what_happens_next_markdown: "Good things come to those that wait",
declaration_text: "agree to the declaration",
steps: steps_data,
support_phone: "0203 222 2222",
support_email: "help@example.gov.uk",
support_url: "https://example.gov.uk/help",
support_url_text: "Get help",
send_copy_of_answers: "disabled",
submission_email:)
end

before do
get check_your_answers_path(mode:, form_id:, form_slug: form_data.form_slug)
end

it "Displays a back link to the last step" do
expect(response.body).to include(form_step_path(mode:, form_id:, form_slug: form_data.form_slug, step_slug: 2))
end
end
end
end

Expand Down Expand Up @@ -276,6 +346,32 @@
include_examples "for notification references"
end

context "when the user has said yes to copy of answers and has a One Login email" do
let(:store) do
{
answers:,
confirmation_details: {
form_id.to_s => {
"wants_copy_of_answers" => true,
"copy_of_answers_email_address" => "user@example.gov.uk",
},
},
}.with_indifferent_access
end

before do
travel_to frozen_time do
perform_enqueued_jobs do
post form_submit_answers_path(form_id:, form_slug: "form-name", mode:), params: {}
end
end
end

it "submits successfully without email_confirmation_input params" do
expect(response).to redirect_to(form_submitted_path)
end
end

context "when the submission type is s3" do
let(:form_data) do
build(:v2_form_document, :s3_submissions_enabled, form_id:, steps: steps_data, start_page: 1)
Expand Down
16 changes: 15 additions & 1 deletion spec/requests/forms/copy_of_answers_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

RSpec.describe Forms::CopyOfAnswersController, type: :request do
let(:form) do
build(:v2_form_document, :with_support, form_id: 2, start_page: 1, steps:, available_languages:)
build(:v2_form_document, :with_support, form_id: 2, start_page: 1, steps:, available_languages:, send_copy_of_answers: "enabled")
end

let(:steps) do
Expand Down Expand Up @@ -51,6 +51,20 @@
end
end

context "when the feature flag is enabled but send_copy_of_answers is disabled on the form", :feature_filler_answer_email_enabled do
let(:form) do
build(:v2_form_document, :with_support, form_id: 2, start_page: 1, steps:, available_languages:, send_copy_of_answers: "disabled")
end

before do
get copy_of_answers_path(mode:, form_id: form.form_id, form_slug: form.form_slug)
end

it "redirects to check your answers" do
expect(response).to redirect_to(check_your_answers_path(form_id: form.form_id, form_slug: form.form_slug, mode:))
end
end

context "when the feature flag is enabled", :feature_filler_answer_email_enabled do
before do
get copy_of_answers_path(mode:, form_id: form.form_id, form_slug: form.form_slug)
Expand Down
20 changes: 20 additions & 0 deletions spec/requests/forms/step_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
what_happens_next_markdown: "Good things come to those that wait",
declaration_text: "agree to the declaration",
available_languages:,
send_copy_of_answers: "enabled",
steps: steps_data)
end

Expand Down Expand Up @@ -720,6 +721,25 @@
post save_form_step_path(mode:, form_id: 2, form_slug: form_data.form_slug, step_slug: 2), params: { question: { text: "answer text" } }
expect(response).to redirect_to(copy_of_answers_path(2, form_data.form_slug, mode:))
end

context "when send_copy_of_answers is disabled on the form" do
let(:form_data) do
build(:v2_form_document, :with_support,
form_id: 2,
start_page: first_step_id,
privacy_policy_url: "http://www.example.gov.uk/privacy_policy",
what_happens_next_markdown: "Good things come to those that wait",
declaration_text: "agree to the declaration",
available_languages:,
send_copy_of_answers: "disabled",
steps: steps_data)
end

it "Redirects to the check your answers page" do
post save_form_step_path(mode:, form_id: 2, form_slug: form_data.form_slug, step_slug: 2), params: { question: { text: "answer text" } }
expect(response).to redirect_to(check_your_answers_path(2, form_data.form_slug, mode:))
end
end
end
end

Expand Down
Loading