From 54682dd6def64f2c909f00ec6b0ec4d15d429260 Mon Sep 17 00:00:00 2001
From: fumimowdan <tecknuovo@zemis.co.uk>
Date: Tue, 12 Sep 2023 10:42:24 +0100
Subject: [PATCH 01/11] Delete unused views

---
 app/models/applicants/personal_detail.rb      | 122 ----------
 .../application_routes/new.html.erb           |  32 ---
 .../application_summary/new.html.erb          |  19 --
 .../applicants/contract_details/new.html.erb  |  22 --
 .../contract_start_dates/new.html.erb         |  20 --
 .../employment_details/new.html.erb           |  28 ---
 app/views/applicants/entry_dates/new.html.erb |  15 --
 .../applicants/personal_details/new.html.erb  |  50 ----
 .../salaried_course_details/new.html.erb      |  38 ---
 .../applicants/school_details/new.html.erb    |  23 --
 app/views/applicants/subjects/new.html.erb    |  23 --
 .../applicants/submissions/show.html.erb      |  44 ----
 .../applicants/teaching_details/new.html.erb  |  18 --
 app/views/applicants/visas/new.html.erb       |  20 --
 config/locales/en.yml                         | 156 ------------
 .../models/applicants/personal_detail_spec.rb | 225 ------------------
 spec/support/application_form_assertions.rb   |  20 +-
 17 files changed, 10 insertions(+), 865 deletions(-)
 delete mode 100644 app/models/applicants/personal_detail.rb
 delete mode 100644 app/views/applicants/application_routes/new.html.erb
 delete mode 100644 app/views/applicants/application_summary/new.html.erb
 delete mode 100644 app/views/applicants/contract_details/new.html.erb
 delete mode 100644 app/views/applicants/contract_start_dates/new.html.erb
 delete mode 100644 app/views/applicants/employment_details/new.html.erb
 delete mode 100644 app/views/applicants/entry_dates/new.html.erb
 delete mode 100644 app/views/applicants/personal_details/new.html.erb
 delete mode 100644 app/views/applicants/salaried_course_details/new.html.erb
 delete mode 100644 app/views/applicants/school_details/new.html.erb
 delete mode 100644 app/views/applicants/subjects/new.html.erb
 delete mode 100644 app/views/applicants/submissions/show.html.erb
 delete mode 100644 app/views/applicants/teaching_details/new.html.erb
 delete mode 100644 app/views/applicants/visas/new.html.erb
 delete mode 100644 spec/models/applicants/personal_detail_spec.rb

diff --git a/app/models/applicants/personal_detail.rb b/app/models/applicants/personal_detail.rb
deleted file mode 100644
index 5ac761de..00000000
--- a/app/models/applicants/personal_detail.rb
+++ /dev/null
@@ -1,122 +0,0 @@
-# frozen_string_literal: true
-
-module Applicants
-  class PersonalDetail
-    include ActiveModel::Model
-    attr_accessor :given_name, :middle_name, :family_name, :email_address, :phone_number,
-                  :day, :month, :year, :sex, :passport_number, :nationality, :address_line_1,
-                  :address_line_2, :city, :postcode
-
-    SEX_OPTIONS = %w[female male].freeze
-
-    validates :given_name, presence: true
-    validates :family_name, presence: true
-    validates :email_address, presence: true
-    validates :phone_number, presence: true
-    validates :phone_number, phone: { possible: true, types: %i[voip mobile] }
-    validates :date_of_birth, presence: true
-    validate :date_of_birth_not_in_future
-    validate :age_less_than_maximum
-    validate :minimum_age
-    validates :sex, presence: true, inclusion: { in: SEX_OPTIONS }
-    validates :passport_number, presence: true, length: { maximum: 20, message: "passport number is invalid" } # rubocop:disable Rails/I18nLocaleTexts
-    validate :valid_passport_number
-    validates :nationality, presence: true, inclusion: { in: NATIONALITIES }
-    validates :address_line_1, presence: true
-    validates :city, presence: true
-    validates :postcode, presence: true, postcode: true
-
-    validate do |record|
-      EmailFormatValidator.new(record).validate
-      DayMonthYearDateValidator.new.validate(record, :date_of_birth)
-    end
-
-    def date_of_birth
-      Date.new(year.to_i, month.to_i, day.to_i)
-    rescue StandardError
-      InvalidDate.new(day:, month:, year:)
-    end
-
-    def applicant=(applicant)
-      return unless applicant
-
-      self.given_name = applicant.given_name
-      self.middle_name = applicant.middle_name
-      self.family_name = applicant.family_name
-      self.email_address = applicant.email_address
-      self.phone_number = applicant.phone_number
-      self.day = applicant.date_of_birth.day
-      self.month = applicant.date_of_birth.month
-      self.year = applicant.date_of_birth.year
-      self.sex = applicant.sex
-      self.passport_number = applicant.passport_number
-      self.nationality = applicant.nationality
-      self.address_line_1 = applicant.address.address_line_1
-      self.address_line_2 = applicant.address.address_line_2
-      self.city = applicant.address.city
-      self.postcode = applicant.address.postcode
-    end
-
-    def save!(application:)
-      Applicant.create!(
-        application: application,
-        given_name: given_name,
-        middle_name: middle_name,
-        family_name: family_name,
-        email_address: email_address,
-        phone_number: phone_number,
-        date_of_birth: date_of_birth,
-        sex: sex,
-        passport_number: passport_number,
-        nationality: nationality,
-        address_attributes: {
-          address_line_1:,
-          address_line_2:,
-          city:,
-          postcode:,
-        },
-      )
-    end
-
-  private
-
-    def date_of_birth_not_in_future
-      return unless date_of_birth.present? && date_of_birth > Date.current
-
-      errors.add(:date_of_birth, "cannot be in the future")
-    end
-
-    def age_less_than_maximum
-      return unless date_of_birth.present? && (Date.current.year - date_of_birth.year) >= MAX_AGE
-
-      errors.add(:date_of_birth)
-    end
-
-    def valid_passport_number
-      return if passport_number.blank?
-
-      # Reject if it contains any characters other than alphanumeric
-      unless /\A[a-zA-Z0-9]+\z/.match?(passport_number)
-        errors.add(:passport_number, "passport number is invalid")
-        return
-      end
-
-      # Reject if it doesn't contain at least one number
-      unless /\d/.match?(passport_number)
-        errors.add(:passport_number, "passport number is invalid")
-      end
-    end
-
-    def minimum_age
-      # rubocop:disable Rails/Blank
-      return unless date_of_birth.present?
-      # rubocop:enable Rails/Blank
-
-      errors.add(:date_of_birth, "must be at least #{MIN_AGE} years") if date_of_birth > MIN_AGE.years.ago.to_date
-    end
-  end
-
-  MAX_AGE = 80
-  MIN_AGE = 22
-  private_constant :MAX_AGE, :MIN_AGE
-end
diff --git a/app/views/applicants/application_routes/new.html.erb b/app/views/applicants/application_routes/new.html.erb
deleted file mode 100644
index bcc8e8c3..00000000
--- a/app/views/applicants/application_routes/new.html.erb
+++ /dev/null
@@ -1,32 +0,0 @@
-<div class="govuk-grid-row">
-  <div class="govuk-grid-column-two-thirds-from-desktop">
-    <%= form_with(model: @application_route, local: true) do |f| %>
-      <%= f.govuk_error_summary %>
-
-      <%= f.govuk_radio_buttons_fieldset(:application_route,
-        legend: { text: t("applicants.application_routes.title"), tag: "h1", size: "l" },
-          hint: { text: t("applicants.application_routes.hint") },
-      ) do %>
-        <%= f.govuk_radio_button(
-          :application_route,
-          :teacher,
-          label: { text: t("applicants.application_routes.radio_button.teacher.text") },
-        )%>
-        <%= f.govuk_radio_button(
-              :application_route,
-              :salaried_trainee,
-              label: { text: t("applicants.application_routes.radio_button.salaried_trainee.text") },
-              hint: { text: t("applicants.application_routes.radio_button.salaried_trainee.hint") },
-              link_errors: true,
-            )%>
-        <%= f.govuk_radio_button(
-          :application_route,
-          :other,
-          label: { text: "Other" },
-        )%>
-      <% end %>
-      
-      <%= f.govuk_submit %>
-    <% end %>
-  </div>
-</div>
diff --git a/app/views/applicants/application_summary/new.html.erb b/app/views/applicants/application_summary/new.html.erb
deleted file mode 100644
index 107ddef1..00000000
--- a/app/views/applicants/application_summary/new.html.erb
+++ /dev/null
@@ -1,19 +0,0 @@
-<% content_for :back_link do %>
-  <%= link_to 'Back', new_applicants_personal_detail_path, class: 'govuk-back-link' %>
-<% end %>
-
-<div class="govuk-grid-row">
-  <div class="govuk-grid-column-two-thirds-from-desktop">
-    <h1 class="govuk-heading-l">
-      <%= t("applicants.application_summary.title") %>
-    </h1>
-
-    <%= govuk_summary_list(rows: @summary.rows) %>
-    <%= govuk_summary_list(card: @summary.personal_card, rows: @summary.personal_rows) %>
-    <%= govuk_summary_list(card: @summary.employment_card, rows: @summary.employment_rows) %>
-
-    <%= form_with(url: applicants_application_summary_index_path, local: true) do |f| %>
-      <%= f.govuk_submit "Submit Application" %>
-    <% end %>
-  </div>
-</div>
diff --git a/app/views/applicants/contract_details/new.html.erb b/app/views/applicants/contract_details/new.html.erb
deleted file mode 100644
index 39585d66..00000000
--- a/app/views/applicants/contract_details/new.html.erb
+++ /dev/null
@@ -1,22 +0,0 @@
-<% content_for :back_link do %>
-  <%= link_to 'Back', new_applicants_school_detail_path(state_funded_secondary_school: "yes"), class: 'govuk-back-link' %>
-<% end %>
-
-<div class="govuk-grid-row">
-  <div class="govuk-grid-column-two-thirds-from-desktop">
-    <%= form_with(model: @contract_detail, local: true) do |f| %>
-      <%= f.govuk_error_summary %>
-
-      <%= f.govuk_radio_buttons_fieldset(
-        :one_year,
-        legend: { text: t("applicants.contract_details.title"), tag: "h1", size: "l" },
-        hint: {text: t("applicants.contract_details.hint") }) do %>
-        <% Applicants::ContractDetail::ONE_YEAR_OPTIONS.each_with_index do |value, i| %>
-          <%= f.govuk_radio_button :one_year, value, label: { text: value.humanize }, link_errors: i.zero? %>
-        <% end %>
-      <% end %>
-
-      <%= f.govuk_submit %>
-    <% end %>
-  </div>
-</div>
diff --git a/app/views/applicants/contract_start_dates/new.html.erb b/app/views/applicants/contract_start_dates/new.html.erb
deleted file mode 100644
index 1b89457f..00000000
--- a/app/views/applicants/contract_start_dates/new.html.erb
+++ /dev/null
@@ -1,20 +0,0 @@
-<% content_for :back_link do %>
-  <% if current_application.application_route == "teacher" %>
-    <%= link_to 'Back', new_applicants_contract_detail_path(one_year: "yes"), class: 'govuk-back-link' %>
-  <% else %>
-    <%= link_to 'Back', new_applicants_salaried_course_detail_path(eligible_course: "yes"), class: 'govuk-back-link' %>
-  <% end %>
-<% end %>
-
-<div class="govuk-grid-row">
-  <div class="govuk-grid-column-two-thirds-from-desktop">
-    <%= form_with(model: @contract_start_date, local: true) do |f| %>
-
-      <%= f.govuk_error_summary %>
-
-      <%= f.govuk_date_field :contract_start_date, legend: { text: t("applicants.contract_start_dates.title"), tag: "h1", size: "l" } %>
-
-      <%= f.govuk_submit %>
-    <% end %>
-  </div>
-</div>
diff --git a/app/views/applicants/employment_details/new.html.erb b/app/views/applicants/employment_details/new.html.erb
deleted file mode 100644
index 13bae6c4..00000000
--- a/app/views/applicants/employment_details/new.html.erb
+++ /dev/null
@@ -1,28 +0,0 @@
-<% content_for :back_link do %>
-  <%= link_to 'Back', new_applicants_personal_detail_path, class: 'govuk-back-link' %>
-<% end %>
-
-<div class="govuk-grid-row">
-  <div class="govuk-grid-column-two-thirds-from-desktop">
-    <%= form_with(model: @employment_detail, local: true) do |f| %>
-
-      <%= f.govuk_error_summary %>
-
-      <h1 class="govuk-heading-l">
-        <%= t("applicants.employment_details.title") %>
-      </h1>
-
-      <%= f.govuk_text_field :school_headteacher_name, label: { text: t("applicants.employment_details.headteacher"), size: "s" } %>
-
-      <%= f.govuk_text_field :school_name, label: { text: t("applicants.employment_details.school_name.title.#{application_route}"), size: "s" } %>
-      <%= f.govuk_fieldset legend: { text: t("applicants.employment_details.address"), size: 's' } do %>
-        <%= f.govuk_text_field :school_address_line_1, label: { text: t("applicants.employment_details.address_line_1"), size: "s"} %>
-        <%= f.govuk_text_field :school_address_line_2, label: { text: t("applicants.employment_details.address_line_2"), size: "s"} %>
-        <%= f.govuk_text_field :school_city, label: { text: t("applicants.employment_details.city"), size: "s"} %>
-        <%= f.govuk_text_field :school_postcode, label: { text: t("applicants.employment_details.postcode"), size: "s"} %>
-      <% end %>
-
-      <%= f.govuk_submit %>
-    <% end %>
-  </div>
-</div>
diff --git a/app/views/applicants/entry_dates/new.html.erb b/app/views/applicants/entry_dates/new.html.erb
deleted file mode 100644
index 2daa2941..00000000
--- a/app/views/applicants/entry_dates/new.html.erb
+++ /dev/null
@@ -1,15 +0,0 @@
-<% content_for :back_link do %>
-  <%= link_to 'Back', new_applicants_visa_path, class: 'govuk-back-link' %>
-<% end %>
-<div class="govuk-grid-row">
-  <div class="govuk-grid-column-two-thirds-from-desktop">
-    <%= form_with(model: @entry_date, local: true) do |f| %>
-
-      <%= f.govuk_error_summary %>
-      
-      <%= f.govuk_date_field :entry_date, legend: { text: t("applicants.entry_dates.title.#{application_route}"), tag: "h1", size: "l" } %>
-
-      <%= f.govuk_submit %>
-    <% end %>
-  </div>
-</div>
diff --git a/app/views/applicants/personal_details/new.html.erb b/app/views/applicants/personal_details/new.html.erb
deleted file mode 100644
index 132de2fe..00000000
--- a/app/views/applicants/personal_details/new.html.erb
+++ /dev/null
@@ -1,50 +0,0 @@
-<% content_for :back_link do %>
-  <%= link_to 'Back', new_applicants_entry_date_path, class: 'govuk-back-link' %>
-<% end %>
-<% if flash[:error] %>
-  <%= govuk_warning_text(text: flash[:error]) %>
-<% end %>
-
-<div class="govuk-grid-row">
-  <div class="govuk-grid-column-two-thirds-from-desktop">
-    <%= form_with(model: @personal_detail, local: true) do |f| %>
-
-      <%= f.govuk_error_summary %>
-
-      <h1 class="govuk-heading-l">
-        <%= t("applicants.personal_details.title") %>
-      </h1>
-
-      <%= f.govuk_text_field :given_name, label: { text: t("applicants.personal_details.given_name")  , size: "s" } %>
-      <%= f.govuk_text_field :middle_name, label: { text: t("applicants.personal_details.middle_name")  , size: "s" } %>
-      <%= f.govuk_text_field :family_name, label: { text: t("applicants.personal_details.family_name") , size: "s" } %>
-      <%= f.govuk_text_field :email_address, label: { text: t("applicants.personal_details.email_address") , size: "s" }, hint: { text: "We will use this to contact you so please make sure you have entered it correctly." } %>
-      <%= f.govuk_text_field :phone_number,
-        label: { text: t("applicants.personal_details.phone_number.title"), size: "s" },
-        hint: { text:  t("applicants.personal_details.phone_number.hint") }
-      %>
-      <%= f.govuk_date_field :date_of_birth, date_of_birth: true, legend: { text: t("applicants.personal_details.date_of_birth"), size: "s" } %>
-
-      <%= f.govuk_fieldset legend: { text: t("applicants.personal_details.address.text"), size: 's' } do %>
-        <%= f.govuk_text_field :address_line_1, label: { text: t("applicants.personal_details.address_line_1"), size: "s" } %>
-        <%= f.govuk_text_field :address_line_2, label: { text: t("applicants.personal_details.address_line_2"), size: "s" } %>
-        <%= f.govuk_text_field :city, label: { text: t("applicants.personal_details.city"), size: "s" } %>
-        <%= f.govuk_text_field :postcode, label: { text: t("applicants.personal_details.postcode"), size: "s" } %>
-      <% end %>
-
-      <%= f.govuk_select(:nationality, NATIONALITIES.dup.unshift(nil), label: { text: t("applicants.personal_details.nationality") , size: "s" }) %>
-
-      <%= f.govuk_radio_buttons_fieldset(:sex, legend: { text: t("applicants.personal_details.sex"), size: "s" }) do %>
-        <% Applicants::PersonalDetail::SEX_OPTIONS.each_with_index do |value, i| %>
-          <%= f.govuk_radio_button :sex, value, label: { text: value.humanize }, link_errors: i.zero? %>
-        <% end %>
-      <% end %>
-
-      <%= f.govuk_text_field :passport_number, label: { text: t("applicants.personal_details.passport") , size: "s" } %>
-
-      <%= invisible_captcha :username %>
-
-      <%= f.govuk_submit %>
-    <% end %>
-  </div>
-</div>
diff --git a/app/views/applicants/salaried_course_details/new.html.erb b/app/views/applicants/salaried_course_details/new.html.erb
deleted file mode 100644
index b201b327..00000000
--- a/app/views/applicants/salaried_course_details/new.html.erb
+++ /dev/null
@@ -1,38 +0,0 @@
-<% content_for :back_link do %>
-  <%= link_to 'Back', new_applicants_application_route_path(application_route: current_application.application_route), class: 'govuk-back-link' %>
-<% end %>
-
-<div class="govuk-grid-row">
-  <div class="govuk-grid-column-two-thirds-from-desktop">
-    <%= form_with(model: @salaried_course_detail, local: true) do |f| %>
-
-      <%= f.govuk_error_summary %>
-
-      <%= f.govuk_radio_buttons_fieldset(
-        :eligible_course,
-        legend: { text: t("applicants.salaried_course.title"), tag: "h1", size: "l" }
-      ) do %>
-
-        <p class="govuk-body">
-          The course must:
-        </p>
-
-        <ul class="govuk-list govuk-list--bullet">
-          <li>pay a salary</li>
-          <li>lead to qualified teacher status (QTS)</li>
-          <li>be accredited by the UK government</li>
-        </ul>
-
-        <p class="govuk-body">
-          Check with your training provider if you're not sure.
-        </p>
-
-        <% Applicants::SalariedCourseDetail::ELIGIBLE_COURSE_OPTIONS.each_with_index do |value, i| %>
-          <%= f.govuk_radio_button :eligible_course, value, label: { text: value.humanize }, link_errors: i.zero? %>
-        <% end %>
-      <% end %>
-
-      <%= f.govuk_submit %>
-    <% end %>
-  </div>
-</div>
diff --git a/app/views/applicants/school_details/new.html.erb b/app/views/applicants/school_details/new.html.erb
deleted file mode 100644
index b157b2a3..00000000
--- a/app/views/applicants/school_details/new.html.erb
+++ /dev/null
@@ -1,23 +0,0 @@
-<% content_for :back_link do %>
-  <%= link_to 'Back', new_applicants_application_route_path(application_route: current_application.application_route), class: 'govuk-back-link' %>
-<% end %>
-
-<div class="govuk-grid-row">
-  <div class="govuk-grid-column-two-thirds-from-desktop">
-    <%= form_with(model: @school_detail, local: true) do |f| %>
-      <%= f.govuk_error_summary %>
-
-      <%= f.govuk_radio_buttons_fieldset(
-        :state_funded_secondary_school,
-        legend: { text: t("applicants.school_details.title"), tag: "h1", size: "l" },
-        hint: { text: t("applicants.school_details.hint") }
-      ) do %>
-        <% Applicants::SchoolDetail::SCHOOL_OPTIONS.each_with_index do |value, i| %>
-          <%= f.govuk_radio_button :state_funded_secondary_school, value, label: { text: value.humanize }, link_errors: i.zero? %>
-        <% end %>
-      <% end %>
-
-      <%= f.govuk_submit %>
-    <% end %>
-  </div>
-</div>
diff --git a/app/views/applicants/subjects/new.html.erb b/app/views/applicants/subjects/new.html.erb
deleted file mode 100644
index da7d46f5..00000000
--- a/app/views/applicants/subjects/new.html.erb
+++ /dev/null
@@ -1,23 +0,0 @@
-<% content_for :back_link do %>
-  <%= link_to 'Back', new_applicants_contract_start_date_path, class: 'govuk-back-link' %>
-<% end %>
-
-<div class="govuk-grid-row">
-  <div class="govuk-grid-column-two-thirds-from-desktop">
-    <%= form_with(model: @subject, local: true) do |f| %>
-      <%= f.govuk_error_summary %>
-
-      <%= f.govuk_radio_buttons_fieldset(
-        :subject,
-        legend: { text: t("applicants.subjects.title.#{application_route}"), tag: "h1", size: "l" },
-        hint: { text: t("applicants.subjects.hint.#{application_route}"), tag: "h1", size: "l" }
-      )do %>
-        <% Applicants::Subject.all(application_route).each_with_index do |value, i| %>
-          <%= f.govuk_radio_button :subject, value, label: { text: value.humanize }, link_errors: i.zero? %>
-        <% end %>
-      <% end %>
-      
-      <%= f.govuk_submit %>
-    <% end %>
-  </div>
-</div>
diff --git a/app/views/applicants/submissions/show.html.erb b/app/views/applicants/submissions/show.html.erb
deleted file mode 100644
index 47fcec33..00000000
--- a/app/views/applicants/submissions/show.html.erb
+++ /dev/null
@@ -1,44 +0,0 @@
-<div class="govuk-width-container">
-  <main class="govuk-main-wrapper govuk-main-wrapper--l" id="main-content" role="main">
-    <div class="govuk-grid-row">
-      <div class="govuk-grid-column-two-thirds">
-        <div class="govuk-panel govuk-panel--confirmation">
-          <h1 class="govuk-panel__title">
-            Application submitted
-          </h1>
-          <div class="govuk-panel__body">
-            Your reference number<br><strong><%= @application.urn %></strong>
-          </div>
-        </div>
-
-        <p class="govuk-body">
-          You have successfully submitted your international relocation payment application form. You will receive a
-          confirmation email from <a href="https://gov.uk">GOV.UK</a> Notify. We will now validate the information you
-          have given us. We will email you if we have any questions.
-        </p>
-
-        <p class="govuk-body">
-          Your international relocation payment (IRP) application reference number is:
-        </p>
-
-        <p class="govuk-body">
-          <strong><%= @application.urn %></strong>
-        </p>
-
-        <p class="govuk-body">
-          Keep this safe, as you will need it if your application is successful.
-        </p>
-
-        <p class="govuk-body">
-          We’ll let you know the outcome of your application as soon as we’ve checked your eligibility. We aim to do
-          this within 30 days. If you are eligible, you will be paid by 31 January 2024.
-        </p>
-
-        <p class="govuk-body">
-          For help, you can contact us on
-          <%= govuk_link_to("IRP.Mailbox@education.gov.uk", "mailto:IRP.Mailbox@education.gov.uk") %>.
-        </p>
-      </div>
-    </div>
-  </main>
-</div>
diff --git a/app/views/applicants/teaching_details/new.html.erb b/app/views/applicants/teaching_details/new.html.erb
deleted file mode 100644
index 9609d450..00000000
--- a/app/views/applicants/teaching_details/new.html.erb
+++ /dev/null
@@ -1,18 +0,0 @@
-<div class="govuk-grid-row">
-  <div class="govuk-grid-column-two-thirds-from-desktop">
-    <%= form_with(model: @teaching_detail, local: true) do |f| %>
-      <%= f.govuk_error_summary %>
-
-      <%= f.govuk_radio_buttons_fieldset(
-        :fifty_percent,
-        legend: { text: t("applicants.teaching_details.title.#{application_route}"), tag: "h1", size: "l" },
-        hint: { text: t("applicants.teaching_details.hint.#{application_route}") }) do %>
-        <% Applicants::TeachingDetail::OPTIONS.each_with_index do |value, i| %>
-          <%= f.govuk_radio_button :fifty_percent, value, label: { text: value.humanize }, link_errors: i.zero? %>
-        <% end %>
-      <% end %>
-      
-      <%= f.govuk_submit %>
-    <% end %>
-  </div>
-</div>
\ No newline at end of file
diff --git a/app/views/applicants/visas/new.html.erb b/app/views/applicants/visas/new.html.erb
deleted file mode 100644
index c55380f5..00000000
--- a/app/views/applicants/visas/new.html.erb
+++ /dev/null
@@ -1,20 +0,0 @@
-<% content_for :back_link do %>
-  <%= link_to 'Back', new_applicants_subject_path, class: 'govuk-back-link' %>
-<% end %>
-<div class="govuk-grid-row">
-  <div class="govuk-grid-column-two-thirds-from-desktop">
-    <%= form_with(model: @visa, local: true) do |f| %>
-
-      <%= f.govuk_error_summary %>
-
-      <%= f.govuk_select(
-            :visa_type,
-            Applicants::Visa::VISA_OPTIONS.dup.unshift(nil),
-            label: { text: t("applicants.visa.title"), tag: "h1", size: "l" },
-            include_blank: true
-          ) %>
-
-      <%= f.govuk_submit %>
-    <% end %>
-  </div>
-</div>
diff --git a/config/locales/en.yml b/config/locales/en.yml
index 2c895efb..c3aeede4 100644
--- a/config/locales/en.yml
+++ b/config/locales/en.yml
@@ -30,164 +30,8 @@
 # available at https://guides.rubyonrails.org/i18n.html.
 
 en:
-  applicants:
-    application_summary:
-      title: Application summary
-    application_routes:
-      title: What is your employment status?
-      hint: Select one of the following options
-      radio_button:
-        teacher:
-          text: I am employed as a teacher in a school in England
-        salaried_trainee:
-          text: I am enrolled on a salaried teacher training course in England.
-          hint: ‘Salaried’ means a course where you are paid a wage to work while you train.
-    contract_details:
-      title: Are you employed on a contract lasting at least one year?
-      hint: Your contract can also be ongoing or permanent.
-    contract_start_dates:
-      title: Enter the start date of your contract
-    entry_dates:
-      title:
-        teacher: Enter the date you moved to England to start your teaching job
-        salaried_trainee: Enter the date you moved to England to start your teacher training course
-    school_details:
-      title: Are you employed by an English state secondary school?
-      hint: State schools receive funding from the UK government. Secondary schools teach children aged 11 to 16 or 18.
-    employment_details:
-      title: Employment information
-      school_name:
-        title:
-          teacher: Enter the name of the school
-          salaried_trainee: Enter the name of the school where you are employed as a trainee teacher
-      headteacher: Enter the name of the headteacher of the school where you are employed as a teacher
-      address: Enter the school address
-      address_line_1: Address line 1
-      address_line_2: Address line 2 (optional)
-      city: Town or city
-      postcode: Postcode
-    personal_details:
-      title: Personal information
-      given_name: Enter your given name, as it appears on your passport
-      middle_name: Enter your middle name, as it appears on your passport
-      family_name: Enter your family name, as it appears on your passport
-      email_address: Enter your current email address
-      phone_number:
-        title: Enter your current phone number
-        hint: For international numbers include the country code. We will use this to contact you so please make sure you have entered it correctly.
-      date_of_birth: Enter your date of birth, as it appears on your passport
-      address:
-        text: Enter your address in England
-      address_line_1: Address line 1
-      address_line_2: Address line 2 (optional)
-      city: Town or city
-      postcode: Postcode
-      nationality: Select your nationality
-      sex: Select your sex
-      passport: Enter your passport number, as it appears on your passport
-    subjects:
-      title:
-        teacher: What subject are you employed to teach at your school?
-        salaried_trainee: What subject are you training to teach?
-      hint:
-        teacher:
-          Physics, general or combined science including physics, and languages can be combined with other subjects but
-          must make up at least 50% of your time in the classroom. This will be validated by the Department for Education with your school.
-        salaried_trainee:
-          Physics or languages can be combined with other subjects but must make up at least 50% of your course content.
-          This will be validated by Department for Education with the school where you are training.
-    salaried_course:
-      title: Are you on a teacher training course in England which meets the following conditions?
-    teaching_details:
-      title:
-        teacher: Do you teach this subject for at least 50% of your teaching timetable?
-        salaried_trainee: Does this subject make up at least 50% of your course?
-      hint:
-        teacher: Check with your school if you're not sure
-        salaried_trainee: Check with your training provider if you're not sure.
-    visa:
-      title: Select the visa you used to move to England
   activemodel:
     errors:
-      models:
-        applicants/application_route:
-          attributes:
-            application_route:
-              blank: Select the option that applies to you
-        applicants/contract_detail:
-          attributes:
-            one_year:
-              blank: Choose the option that applies to you
-        applicants/contract_start_date:
-          attributes:
-            contract_start_date:
-              blank: Enter your contract start date
-        applicants/employment_detail:
-          attributes:
-            school_name:
-              blank: Enter your school's name
-            school_postcode:
-              blank: Enter your school's postcode
-            school_headteacher_name:
-              blank: Enter the headteacher's name
-            school_address_line_1:
-              blank: Enter your school's address
-            school_city:
-              blank: Enter your school's city
-        applicants/entry_date:
-          attributes:
-            entry_date:
-              blank: Enter your entry date
-        applicants/personal_detail:
-          attributes:
-            given_name:
-              blank: Enter your given name(s)
-            middle_name:
-              blank: Enter your middle name(s)
-            family_name:
-              blank: Enter your family name(s)
-            email_address:
-              blank: Enter your email address
-              invalid: Enter an email address in the correct format, like name@example.com
-            phone_number:
-              blank: Enter your phone number
-              invalid: Enter a telephone number, like 07700 900 982 or +34 626 587 210’
-            date_of_birth:
-              blank: Enter your date of birth
-              invalid: Age must be below 80
-            sex:
-              blank: Enter your sex
-            passport_number:
-              blank: Enter your passport number
-            nationality:
-              blank: Choose your nationality
-            address_line_1:
-              blank: Enter your address
-            city:
-              blank: Enter your city
-            postcode:
-              blank: Enter your postcode
-
-        applicants/salaried_course_detail:
-          attributes:
-            eligible_course:
-              blank: Choose the option that applies to you
-        applicants/school_detail:
-          attributes:
-            state_funded_secondary_school:
-              blank: Choose the option that applies to you
-        applicants/subject:
-          attributes:
-            subject:
-              blank: Choose a subject
-        applicants/teaching_detail:
-          attributes:
-            fifty_percent:
-              blank: Choose the option that applies to you
-        applicants/visa:
-          attributes:
-            visa_type:
-              blank: Choose your visa type
       validators:
         postcode:
           invalid: Enter a valid postcode (for example, BN1 1AA)
diff --git a/spec/models/applicants/personal_detail_spec.rb b/spec/models/applicants/personal_detail_spec.rb
deleted file mode 100644
index c64af054..00000000
--- a/spec/models/applicants/personal_detail_spec.rb
+++ /dev/null
@@ -1,225 +0,0 @@
-# frozen_string_literal: true
-
-require "rails_helper"
-
-module Applicants
-  describe PersonalDetail do
-    let(:params) { {} }
-    let(:application) { create(:application, :not_submitted, applicant: nil) }
-
-    subject(:model) { described_class.new(params) }
-
-    describe "validations" do
-      it { is_expected.to validate_presence_of(:given_name) }
-      it { is_expected.to validate_presence_of(:family_name) }
-      it { is_expected.to validate_presence_of(:email_address) }
-      it { is_expected.to validate_presence_of(:phone_number) }
-      it { is_expected.to validate_presence_of(:sex) }
-      it { is_expected.to validate_presence_of(:passport_number) }
-      it { is_expected.to validate_presence_of(:nationality) }
-      it { is_expected.to validate_presence_of(:address_line_1) }
-      it { is_expected.not_to validate_presence_of(:address_line_2) }
-      it { is_expected.to validate_presence_of(:city) }
-      it { is_expected.to validate_presence_of(:postcode) }
-
-      it {
-        expect(model).to validate_inclusion_of(:sex)
-                           .in_array(Applicants::PersonalDetail::SEX_OPTIONS)
-      }
-
-      include_examples "a valid UK postcode", described_class
-      include_examples "validates phone number with international prefix", described_class, :phone_number
-      describe "date_of_birth minimum age" do
-        subject { model.errors.messages_for(:date_of_birth) }
-        let(:model) { described_class.new(params) }
-        let(:minimum_age) { 22 }
-        let(:params) do
-          {
-            day: age.day.to_s,
-            month: age.month.to_s,
-            year: age.year.to_s,
-          }
-        end
-
-        before { model.valid? }
-
-        context "invalid when younger than minimum age" do
-          let(:age) { minimum_age.years.ago + 1.day }
-
-          it { is_expected.to be_present }
-        end
-
-        context "valid when exactly the minimum age" do
-          let(:age) { minimum_age.years.ago }
-
-          it { is_expected.to be_blank }
-        end
-
-        context "valid when older than minimum age" do
-          let(:age) { minimum_age.years.ago - 1.day }
-
-          it { is_expected.to be_blank }
-        end
-      end
-
-      describe "#applicant=" do
-        let(:applicant) do
-          create(:applicant,
-                 given_name: "John",
-                 family_name: "Smith",
-                 email_address: "john.gmail.com",
-                 phone_number: "07777777777",
-                 date_of_birth: Date.new(2020, 3, 30),
-                 sex: "male",
-                 passport_number: "123456789",
-                 nationality: "Spanish",
-                 address: build(:address,
-                                address_line_1: "1 High Street",
-                                address_line_2: "Flat 1",
-                                city: "London",
-                                postcode: "SW1A 1AA"))
-        end
-
-        subject(:model) { described_class.new(applicant:) }
-
-        it "loads the applicant's personal details" do
-          expect(model).to have_attributes(
-            given_name: "John",
-            family_name: "Smith",
-            email_address: "john.gmail.com",
-            phone_number: "07777777777",
-            sex: "male",
-            passport_number: "123456789",
-            nationality: "Spanish",
-          )
-        end
-
-        it "loads the applicant's date of birth" do
-          expect(model).to have_attributes(
-            day: 30,
-            month: 3,
-            year: 2020,
-          )
-        end
-
-        it "loads the applicant's address" do
-          expect(model).to have_attributes(
-            address_line_1: "1 High Street",
-            address_line_2: "Flat 1",
-            city: "London",
-            postcode: "SW1A 1AA",
-          )
-        end
-      end
-
-      describe "save!" do
-        let(:params) do
-          {
-            given_name: "John",
-            family_name: "Smith",
-            email_address: "john@email.com",
-            phone_number: "07777777777",
-            day: "01",
-            month: "01",
-            year: "2000",
-            sex: "Male",
-            passport_number: "123456789",
-            nationality: "British",
-            address_line_1: "1 High Street",
-            address_line_2: "Flat 1",
-            city: "London",
-            postcode: "SW1A 1AA",
-          }
-        end
-
-        subject(:model) { described_class.new(params) }
-
-        it "creates an applicant" do
-          expect { model.save!(application:) }.to change(Applicant, :count).by(1)
-        end
-
-        it "creates an address" do
-          expect { model.save!(application:) }.to change(Address, :count).by(1)
-        end
-
-        it "links the address and the applicant" do
-          model.save!(application:)
-
-          expect(Applicant.last.address).to eq(Address.last)
-        end
-
-        it "returns an applicant" do
-          expect(model.save!(application:)).to be_a(Applicant)
-        end
-      end
-
-      describe "date_of_birth" do
-        context "when date_of_birth is invalid" do
-          let(:params) { { day: "31", month: "02", year: "2000" } }
-
-          it "is invalid" do
-            model.valid?
-
-            expect(model.errors["date_of_birth"]).not_to be_blank
-          end
-        end
-
-        context "when date_of_birth is the future" do
-          let(:params) { { day: Date.tomorrow.day, month: Date.tomorrow.month, year: Date.tomorrow.year } }
-
-          it "is invalid" do
-            expect(model).not_to be_valid
-          end
-        end
-
-        context "when age is over 80 years old" do
-          let(:params) { { day: "01", month: "01", year: 81.years.ago.year } }
-
-          it "is invalid" do
-            expect(model).not_to be_valid
-          end
-        end
-
-        context "when date_of_birth is valid" do
-          let(:params) { { day: "01", month: "01", year: "2000" } }
-
-          it "is valid" do
-            model.valid?
-
-            expect(model.errors["date_of_birth"]).to be_blank
-          end
-        end
-      end
-
-      describe "passport_number validations" do
-        subject(:model) { described_class.new(passport_number:) }
-
-        before { model.valid? }
-
-        context "when passport_number is valid" do
-          valid_passports = %w[PAT34566 A345667 JS3445 434455AFT 2453454]
-
-          valid_passports.each do |valid_passport|
-            let(:passport_number) { valid_passport }
-
-            it "#{valid_passport} should be valid" do
-              expect(model.errors.messages_for(:passport_number)).to be_blank
-            end
-          end
-        end
-
-        context "when passport_number is invalid" do
-          invalid_passports = ["asdfasdf", "nil", "%$^%%^%"]
-
-          invalid_passports.each do |invalid_passport|
-            let(:passport_number) { invalid_passport }
-
-            it "#{invalid_passport} should be invalid" do
-              expect(model.errors.messages_for(:passport_number)).to include("passport number is invalid")
-            end
-          end
-        end
-      end
-    end
-  end
-end
diff --git a/spec/support/application_form_assertions.rb b/spec/support/application_form_assertions.rb
index 346f5928..2a627614 100644
--- a/spec/support/application_form_assertions.rb
+++ b/spec/support/application_form_assertions.rb
@@ -2,35 +2,35 @@
 
 RSpec.shared_context "with common application form assertions" do
   def assert_i_am_in_the_subject_question(route)
-    expect(page).to have_text(I18n.t("applicants.subjects.title.#{route}"))
+    expect(page).to have_text(I18n.t("steps.subject.question.#{route}"))
   end
 
   def assert_i_am_in_the_contract_start_date_question
-    expect(page).to have_text(I18n.t("applicants.contract_start_dates.title"))
+    expect(page).to have_text(I18n.t("steps.start_date.question"))
   end
 
   def assert_i_am_in_the_employment_details_question
-    expect(page).to have_text(I18n.t("applicants.employment_details.title"))
+    expect(page).to have_text(I18n.t("steps.employment_details.question"))
   end
 
   def assert_i_am_in_the_personal_details_question
-    expect(page).to have_text(I18n.t("applicants.personal_details.title"))
+    expect(page).to have_text(I18n.t("steps.personal_details.question"))
   end
 
   def assert_i_am_in_the_entry_date_question(route)
-    expect(page).to have_text(I18n.t("applicants.entry_dates.title.#{route}"))
+    expect(page).to have_text(I18n.t("steps.entry_date.question.#{route}"))
   end
 
   def assert_i_am_in_the_visa_type_question
-    expect(page).to have_text(I18n.t("applicants.visa.title"))
+    expect(page).to have_text(I18n.t("steps.visa.question"))
   end
 
   def assert_i_am_in_the_application_route_question
-    expect(page).to have_text(I18n.t("applicants.application_routes.title"))
+    expect(page).to have_text(I18n.t("steps.application_route.question"))
   end
 
   def assert_i_am_in_the_trainee_employment_conditions_question
-    expect(page).to have_text(I18n.t("applicants.salaried_course.title"))
+    expect(page).to have_text(I18n.t("steps.trainee_details.question"))
   end
 
   def and_i_complete_the_state_school_question
@@ -50,10 +50,10 @@ def then_i_can_see_the_landing_page
   end
 
   def assert_i_am_in_the_state_school_question
-    expect(page).to have_text(I18n.t("applicants.school_details.title"))
+    expect(page).to have_text(I18n.t("steps.school_details.question"))
   end
 
   def assert_i_am_on_the_contract_details_question
-    expect(page).to have_text(I18n.t("applicants.contract_details.title"))
+    expect(page).to have_text(I18n.t("steps.contract_details.question"))
   end
 end

From 5b0aa660152d0e72229bce7d52d4fd1364ef5693 Mon Sep 17 00:00:00 2001
From: fumimowdan <tecknuovo@zemis.co.uk>
Date: Tue, 12 Sep 2023 09:30:41 +0100
Subject: [PATCH 02/11] Add `mail-notify`

Activate for all environments
---
 Dockerfile                  | 3 +++
 Gemfile                     | 2 ++
 Gemfile.lock                | 8 ++++++++
 config/application.rb       | 8 ++++++++
 config/environments/test.rb | 2 ++
 config/locales/en.yml       | 4 ++++
 6 files changed, 27 insertions(+)

diff --git a/Dockerfile b/Dockerfile
index d3a8402e..bac235a8 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -41,5 +41,8 @@ ENV GOVUK_NOTIFY_API_KEY=$GOVUK_NOTIFY_API_KEY
 ARG GOVUK_NOTIFY_APPLICATION_SUBMITTED_TEMPLATE_ID
 ENV GOVUK_NOTIFY_APPLICATION_SUBMITTED_TEMPLATE_ID=$GOVUK_NOTIFY_APPLICATION_SUBMITTED_TEMPLATE_ID
 
+ARG GOVUK_NOTIFY_MAIL_NOTIFY_TEMPLATE_ID
+ENV GOVUK_NOTIFY_MAIL_NOTIFY_TEMPLATE_ID=$GOVUK_NOTIFY_MAIL_NOTIFY_TEMPLATE_ID
+
 CMD bundle exec rails db:migrate && \
     bundle exec rails server -b 0.0.0.0
diff --git a/Gemfile b/Gemfile
index b1e23a85..d3821b37 100644
--- a/Gemfile
+++ b/Gemfile
@@ -77,3 +77,5 @@ end
 gem "sidekiq", "~> 7.1"
 
 gem "sidekiq-cron", "~> 1.10"
+
+gem "mail-notify", "~> 1.1"
diff --git a/Gemfile.lock b/Gemfile.lock
index 7fd7853a..a1c69f4d 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -211,6 +211,13 @@ GEM
       net-imap
       net-pop
       net-smtp
+    mail-notify (1.1.0)
+      actionmailer (>= 5.2.4.6)
+      actionpack (>= 5.2.7.1)
+      actionview (>= 5.2.7.1)
+      activesupport (>= 5.2.4.6)
+      notifications-ruby-client (~> 5.1)
+      rack (>= 2.1.4.1)
     marcel (1.0.2)
     matrix (0.4.2)
     method_source (1.0.0)
@@ -463,6 +470,7 @@ DEPENDENCIES
   invisible_captcha
   jbuilder
   launchy
+  mail-notify (~> 1.1)
   notifications-ruby-client
   okcomputer
   omniauth-azure-activedirectory-v2
diff --git a/config/application.rb b/config/application.rb
index daa205c1..d0c1226d 100644
--- a/config/application.rb
+++ b/config/application.rb
@@ -40,5 +40,13 @@ class Application < Rails::Application
     # Don't generate system test files.
     config.generators.system_tests = nil
     config.active_job.queue_adapter = :sidekiq
+
+    # notify mailer
+    config.action_mailer.delivery_method = :notify
+    config.action_mailer.notify_settings = {
+      api_key: ENV.fetch("GOVUK_NOTIFY_API_KEY"),
+    }
+
+    config.x.govuk_notify.mail_notify_template_id = ENV.fetch("GOVUK_NOTIFY_MAIL_NOTIFY_TEMPLATE_ID")
   end
 end
diff --git a/config/environments/test.rb b/config/environments/test.rb
index c1aaded3..97e8955f 100644
--- a/config/environments/test.rb
+++ b/config/environments/test.rb
@@ -49,4 +49,6 @@
 
   # Annotate rendered view with file names.
   # config.action_view.annotate_rendered_view_with_filenames = true
+
+  config.active_job.queue_adapter = :test
 end
diff --git a/config/locales/en.yml b/config/locales/en.yml
index c3aeede4..73a45ad1 100644
--- a/config/locales/en.yml
+++ b/config/locales/en.yml
@@ -30,6 +30,10 @@
 # available at https://guides.rubyonrails.org/i18n.html.
 
 en:
+  mailer:
+    applicant_email:
+      subject: International relocation payment application successfully submitted
+
   activemodel:
     errors:
       validators:

From 5bc405be626ccb0d1dad3b636fcbad092bc13019 Mon Sep 17 00:00:00 2001
From: fumimowdan <tecknuovo@zemis.co.uk>
Date: Tue, 12 Sep 2023 12:19:12 +0100
Subject: [PATCH 03/11] Add GovukNotifyMailer

The `application_submission` method send a email with the body set in
the `app/views/govuk_notify_mailer/application_submission.text.erb`
file.

A govuk notify template has been created to support this functionality.
---
 app/mailers/govuk_notify_mailer.rb                 | 10 ++++++++++
 .../application_submission.text.erb                | 14 ++++++++++++++
 config/locales/en.yml                              |  2 +-
 3 files changed, 25 insertions(+), 1 deletion(-)
 create mode 100644 app/mailers/govuk_notify_mailer.rb
 create mode 100644 app/views/govuk_notify_mailer/application_submission.text.erb

diff --git a/app/mailers/govuk_notify_mailer.rb b/app/mailers/govuk_notify_mailer.rb
new file mode 100644
index 00000000..86fad95e
--- /dev/null
+++ b/app/mailers/govuk_notify_mailer.rb
@@ -0,0 +1,10 @@
+class GovukNotifyMailer < Mail::Notify::Mailer
+  def application_submission
+    @urn = params[:urn]
+    view_mail(
+      Rails.configuration.x.govuk_notify.mail_notify_template_id,
+      to: params[:email],
+      subject: t("mailer.application_submission.subject"),
+    )
+  end
+end
diff --git a/app/views/govuk_notify_mailer/application_submission.text.erb b/app/views/govuk_notify_mailer/application_submission.text.erb
new file mode 100644
index 00000000..2fd97130
--- /dev/null
+++ b/app/views/govuk_notify_mailer/application_submission.text.erb
@@ -0,0 +1,14 @@
+# Thank you
+You have successfully submitted your international relocation payment application form. We will now validate the information you have given us. We will email you if we have any questions.
+
+Your international relocation payment (IRP) application reference number is:
+
+<%= @urn %>
+
+Keep this safe, as you will need it if your application is successful.
+
+We’ll let you know the outcome of your application as soon as we’ve checked your eligibility. We will also contact your school to validate your employment status. We aim to complete our checks within 30 days.
+
+If you are eligible, you will receive an email from [IRP.Mailbox@education.gov.uk](mailto:IRP.Mailbox@education.gov.uk) asking for your bank details and your IRP application reference number. You will be paid by 31 January 2024.
+
+For help, you can contact us on [IRP.Mailbox@education.gov.uk](mailto:IRP.Mailbox@education.gov.uk)
diff --git a/config/locales/en.yml b/config/locales/en.yml
index 73a45ad1..b7f6cb3d 100644
--- a/config/locales/en.yml
+++ b/config/locales/en.yml
@@ -31,7 +31,7 @@
 
 en:
   mailer:
-    applicant_email:
+    application_submission:
       subject: International relocation payment application successfully submitted
 
   activemodel:

From fd1478372becada2166acfe8302bc914611d5c7c Mon Sep 17 00:00:00 2001
From: fumimowdan <tecknuovo@zemis.co.uk>
Date: Tue, 12 Sep 2023 11:35:04 +0100
Subject: [PATCH 04/11] Use ApplicantEmailMailer in SubmitForm service

---
 app/services/submit_form.rb       | 19 +++++++------------
 spec/services/submit_form_spec.rb | 30 +++++++++++++++++++++---------
 2 files changed, 28 insertions(+), 21 deletions(-)

diff --git a/app/services/submit_form.rb b/app/services/submit_form.rb
index 6af9d728..3718df2a 100644
--- a/app/services/submit_form.rb
+++ b/app/services/submit_form.rb
@@ -96,17 +96,12 @@ def delete_form
   end
 
   def send_applicant_email
-    return if Rails.env.development?
-
-    # TODO: perform this in a job
-    template_id = ENV.fetch("GOVUK_NOTIFY_APPLICATION_SUBMITTED_TEMPLATE_ID")
-    email_address = application.applicant.email_address
-    application_id = application.urn
-
-    GovukNotify::Client.send_email(
-      template_id,
-      email_address,
-      application_id,
-    )
+    GovukNotifyMailer
+      .with(
+        email: application.applicant.email_address,
+        urn: application.urn,
+      )
+      .application_submission
+      .deliver_later
   end
 end
diff --git a/spec/services/submit_form_spec.rb b/spec/services/submit_form_spec.rb
index ed8078ee..1cf0cabb 100644
--- a/spec/services/submit_form_spec.rb
+++ b/spec/services/submit_form_spec.rb
@@ -5,10 +5,6 @@
 
   let(:form) { build(:form, :complete, :eligible) }
 
-  before do
-    allow(GovukNotify::Client).to receive(:send_email)
-  end
-
   describe "valid?" do
     context "returns true when form complete and eligible" do
       let(:form) { build(:form, :complete, :eligible) }
@@ -50,12 +46,28 @@
       it { expect { service.submit_form! }.to change(Address, :count).by(2) }
       it { expect { service.submit_form! }.to change(Application, :count).by(1) }
       it { expect { service.submit_form! }.to change(Form, :count).from(1).to(0) }
-    end
-
-    context "send confirmation email" do
-      before { service.submit_form! }
 
-      it { expect(GovukNotify::Client).to have_received(:send_email) }
+      context "applicant email" do
+        before do
+          allow(Urn).to receive(:generate).and_return(urn)
+        end
+
+        let(:urn) { "SOMEURN" }
+        let(:expected_email_params) do
+          {
+            params: {
+              email: form.email_address,
+              urn: urn,
+            },
+            args: [],
+          }
+        end
+
+        it "enqueue mail job" do
+          expect { service.submit_form! }.to have_enqueued_job(ActionMailer::MailDeliveryJob)
+            .with("GovukNotifyMailer", "application_submission", "deliver_now", expected_email_params)
+        end
+      end
     end
   end
 end

From 842bd35519a5f232e77fd5ccc58634e627a5dab8 Mon Sep 17 00:00:00 2001
From: fumimowdan <tecknuovo@zemis.co.uk>
Date: Tue, 12 Sep 2023 10:52:03 +0100
Subject: [PATCH 05/11] Delete govuk notify client

---
 app/models/govuk_notify/client.rb       | 21 ---------------------
 spec/models/govuk_notify/client_spec.rb | 24 ------------------------
 2 files changed, 45 deletions(-)
 delete mode 100644 app/models/govuk_notify/client.rb
 delete mode 100644 spec/models/govuk_notify/client_spec.rb

diff --git a/app/models/govuk_notify/client.rb b/app/models/govuk_notify/client.rb
deleted file mode 100644
index a51fad47..00000000
--- a/app/models/govuk_notify/client.rb
+++ /dev/null
@@ -1,21 +0,0 @@
-require "notifications/client"
-
-module GovukNotify
-  class Client
-    def self.send_email(template_id, email_address, application_id)
-      new.send_email(template_id, email_address, application_id)
-    end
-
-    def initialize
-      @client = Notifications::Client.new(ENV.fetch("GOVUK_NOTIFY_API_KEY"))
-    end
-
-    def send_email(template_id, email_address, application_number)
-      @client.send_email(
-        template_id: template_id,
-        email_address: email_address,
-        personalisation: { application_number: },
-      )
-    end
-  end
-end
diff --git a/spec/models/govuk_notify/client_spec.rb b/spec/models/govuk_notify/client_spec.rb
deleted file mode 100644
index bbe59fd7..00000000
--- a/spec/models/govuk_notify/client_spec.rb
+++ /dev/null
@@ -1,24 +0,0 @@
-require "rails_helper"
-
-RSpec.describe GovukNotify::Client do
-  subject(:client) { described_class.new }
-
-  let(:notify_client) { instance_double(Notifications::Client) }
-
-  describe ".send_email" do
-    it "sends an email using GovUK Notify" do
-      allow(Notifications::Client).to receive(:new).and_return(notify_client)
-      allow(notify_client).to receive(:send_email)
-
-      client.send_email("template_id", "email_address", "application_number")
-
-      expect(notify_client).to have_received(:send_email).with(
-        template_id: "template_id",
-        email_address: "email_address",
-        personalisation: {
-          application_number: "application_number",
-        },
-      )
-    end
-  end
-end

From 281613f22c46b8494dfdea1ac69bbceb681407c5 Mon Sep 17 00:00:00 2001
From: fumimowdan <tecknuovo@zemis.co.uk>
Date: Tue, 12 Sep 2023 13:11:24 +0100
Subject: [PATCH 06/11] Add new govuk notify template id

---
 .github/workflows/build-and-deploy.yml | 1 +
 .github/workflows/ci.yml               | 1 +
 2 files changed, 2 insertions(+)

diff --git a/.github/workflows/build-and-deploy.yml b/.github/workflows/build-and-deploy.yml
index f927133d..7c58ce4e 100644
--- a/.github/workflows/build-and-deploy.yml
+++ b/.github/workflows/build-and-deploy.yml
@@ -89,6 +89,7 @@ jobs:
           COMMIT_SHA=${{ env.IMAGE_TAG }}
           GOVUK_NOTIFY_API_KEY=${{ secrets.GOVUK_NOTIFY_API_KEY }}
           GOVUK_NOTIFY_APPLICATION_SUBMITTED_TEMPLATE_ID=${{ secrets.GOVUK_NOTIFY_APPLICATION_SUBMITTED_TEMPLATE_ID }}
+          GOVUK_NOTIFY_MAIL_NOTIFY_TEMPLATE_ID=${{ secrets.GOVUK_NOTIFY_MAIL_NOTIFY_TEMPLATE_ID }}
 
     - name: Push ${{ env.DOCKER_IMAGE }} images for review
       if: ${{ github.event_name == 'pull_request' && contains(github.event.pull_request.labels.*.name, 'deploy') }}
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index ffb435e9..24d8f5a3 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -27,6 +27,7 @@ jobs:
       DATABASE_URL: 'postgres://rails:password@localhost:5432/rails_test'
       GOVUK_NOTIFY_API_KEY: ${{ secrets.GOVUK_NOTIFY_API_KEY }}
       GOVUK_NOTIFY_APPLICATION_SUBMITTED_TEMPLATE_ID: ${{ secrets.GOVUK_NOTIFY_APPLICATION_SUBMITTED_TEMPLATE_ID }}
+      GOVUK_NOTIFY_MAIL_NOTIFY_TEMPLATE_ID: ${{ secrets.GOVUK_NOTIFY_MAIL_NOTIFY_TEMPLATE_ID }}
     steps:
       - name: Checkout code
         uses: actions/checkout@v4

From 09ac7d9845395fe608493b616e5306af2e13aedd Mon Sep 17 00:00:00 2001
From: fumimowdan <tecknuovo@zemis.co.uk>
Date: Wed, 13 Sep 2023 15:38:11 +0100
Subject: [PATCH 07/11] Renamed env var

GOVUK_NOTIFY_MAIL_NOTIFY_TEMPLATE_ID to GOVUK_NOTIFY_GENERIC_EMAIL_TEMPLATE_ID
---
 .env.example                           | 1 +
 .github/workflows/build-and-deploy.yml | 2 +-
 .github/workflows/ci.yml               | 2 +-
 Dockerfile                             | 4 ++--
 app/mailers/govuk_notify_mailer.rb     | 2 +-
 config/application.rb                  | 2 +-
 6 files changed, 7 insertions(+), 6 deletions(-)

diff --git a/.env.example b/.env.example
index 523920bb..1c574d12 100644
--- a/.env.example
+++ b/.env.example
@@ -1,6 +1,7 @@
 PORT=3000
 GOVUK_NOTIFY_API_KEY=
 GOVUK_NOTIFY_APPLICATION_SUBMITTED_TEMPLATE_ID=
+GOVUK_NOTIFY_GENERIC_EMAIL_TEMPLATE_ID=
 AZURE_CLIENT_ID=
 AZURE_CLIENT_SECRET=
 AZURE_TENANT_ID=
diff --git a/.github/workflows/build-and-deploy.yml b/.github/workflows/build-and-deploy.yml
index 7c58ce4e..fc1cd50a 100644
--- a/.github/workflows/build-and-deploy.yml
+++ b/.github/workflows/build-and-deploy.yml
@@ -89,7 +89,7 @@ jobs:
           COMMIT_SHA=${{ env.IMAGE_TAG }}
           GOVUK_NOTIFY_API_KEY=${{ secrets.GOVUK_NOTIFY_API_KEY }}
           GOVUK_NOTIFY_APPLICATION_SUBMITTED_TEMPLATE_ID=${{ secrets.GOVUK_NOTIFY_APPLICATION_SUBMITTED_TEMPLATE_ID }}
-          GOVUK_NOTIFY_MAIL_NOTIFY_TEMPLATE_ID=${{ secrets.GOVUK_NOTIFY_MAIL_NOTIFY_TEMPLATE_ID }}
+          GOVUK_NOTIFY_GENERIC_EMAIL_TEMPLATE_ID=${{ secrets.GOVUK_NOTIFY_GENERIC_EMAIL_TEMPLATE_ID }}
 
     - name: Push ${{ env.DOCKER_IMAGE }} images for review
       if: ${{ github.event_name == 'pull_request' && contains(github.event.pull_request.labels.*.name, 'deploy') }}
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 24d8f5a3..92810f6a 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -27,7 +27,7 @@ jobs:
       DATABASE_URL: 'postgres://rails:password@localhost:5432/rails_test'
       GOVUK_NOTIFY_API_KEY: ${{ secrets.GOVUK_NOTIFY_API_KEY }}
       GOVUK_NOTIFY_APPLICATION_SUBMITTED_TEMPLATE_ID: ${{ secrets.GOVUK_NOTIFY_APPLICATION_SUBMITTED_TEMPLATE_ID }}
-      GOVUK_NOTIFY_MAIL_NOTIFY_TEMPLATE_ID: ${{ secrets.GOVUK_NOTIFY_MAIL_NOTIFY_TEMPLATE_ID }}
+      GOVUK_NOTIFY_GENERIC_EMAIL_TEMPLATE_ID: ${{ secrets.GOVUK_NOTIFY_GENERIC_EMAIL_TEMPLATE_ID }}
     steps:
       - name: Checkout code
         uses: actions/checkout@v4
diff --git a/Dockerfile b/Dockerfile
index bac235a8..36229831 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -41,8 +41,8 @@ ENV GOVUK_NOTIFY_API_KEY=$GOVUK_NOTIFY_API_KEY
 ARG GOVUK_NOTIFY_APPLICATION_SUBMITTED_TEMPLATE_ID
 ENV GOVUK_NOTIFY_APPLICATION_SUBMITTED_TEMPLATE_ID=$GOVUK_NOTIFY_APPLICATION_SUBMITTED_TEMPLATE_ID
 
-ARG GOVUK_NOTIFY_MAIL_NOTIFY_TEMPLATE_ID
-ENV GOVUK_NOTIFY_MAIL_NOTIFY_TEMPLATE_ID=$GOVUK_NOTIFY_MAIL_NOTIFY_TEMPLATE_ID
+ARG GOVUK_NOTIFY_GENERIC_EMAIL_TEMPLATE_ID
+ENV GOVUK_NOTIFY_GENERIC_EMAIL_TEMPLATE_ID=$GOVUK_NOTIFY_GENERIC_EMAIL_TEMPLATE_ID
 
 CMD bundle exec rails db:migrate && \
     bundle exec rails server -b 0.0.0.0
diff --git a/app/mailers/govuk_notify_mailer.rb b/app/mailers/govuk_notify_mailer.rb
index 86fad95e..a3495a13 100644
--- a/app/mailers/govuk_notify_mailer.rb
+++ b/app/mailers/govuk_notify_mailer.rb
@@ -2,7 +2,7 @@ class GovukNotifyMailer < Mail::Notify::Mailer
   def application_submission
     @urn = params[:urn]
     view_mail(
-      Rails.configuration.x.govuk_notify.mail_notify_template_id,
+      Rails.configuration.x.govuk_notify.generic_email_template_id,
       to: params[:email],
       subject: t("mailer.application_submission.subject"),
     )
diff --git a/config/application.rb b/config/application.rb
index d0c1226d..ef38132e 100644
--- a/config/application.rb
+++ b/config/application.rb
@@ -47,6 +47,6 @@ class Application < Rails::Application
       api_key: ENV.fetch("GOVUK_NOTIFY_API_KEY"),
     }
 
-    config.x.govuk_notify.mail_notify_template_id = ENV.fetch("GOVUK_NOTIFY_MAIL_NOTIFY_TEMPLATE_ID")
+    config.x.govuk_notify.generic_email_template_id = ENV.fetch("GOVUK_NOTIFY_GENERIC_EMAIL_TEMPLATE_ID")
   end
 end

From 3dde1ee051f768ce7218bdd5f39927649bb13ca1 Mon Sep 17 00:00:00 2001
From: fumimowdan <tecknuovo@zemis.co.uk>
Date: Wed, 13 Sep 2023 16:12:51 +0100
Subject: [PATCH 08/11] Fix Dockerfile

execute command rake assets:precompile after the defining docker build
arguments
---
 Dockerfile | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/Dockerfile b/Dockerfile
index 36229831..3a32fedb 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -29,9 +29,6 @@ COPY . .
 RUN echo export PATH=/usr/local/bin:\$PATH > /root/.ashrc
 ENV ENV="/root/.ashrc"
 
-RUN bundle exec rake assets:precompile && \
-    rm -rf node_modules tmp
-
 ARG COMMIT_SHA
 ENV COMMIT_SHA=$COMMIT_SHA
 
@@ -44,5 +41,8 @@ ENV GOVUK_NOTIFY_APPLICATION_SUBMITTED_TEMPLATE_ID=$GOVUK_NOTIFY_APPLICATION_SUB
 ARG GOVUK_NOTIFY_GENERIC_EMAIL_TEMPLATE_ID
 ENV GOVUK_NOTIFY_GENERIC_EMAIL_TEMPLATE_ID=$GOVUK_NOTIFY_GENERIC_EMAIL_TEMPLATE_ID
 
+RUN bundle exec rake assets:precompile && \
+    rm -rf node_modules tmp
+
 CMD bundle exec rails db:migrate && \
     bundle exec rails server -b 0.0.0.0

From c4a15c193f689a097140b315f7bdc2751477f6ad Mon Sep 17 00:00:00 2001
From: fumimowdan <tecknuovo@zemis.co.uk>
Date: Wed, 13 Sep 2023 17:04:25 +0100
Subject: [PATCH 09/11] Disable troublesome migration

Run rails db:seed in review environment when app starts

Updated Dockerfile to use a app startup shell script for that effect
---
 Dockerfile                                       |  3 +--
 bin/app-startup.sh                               | 16 ++++++++++++++++
 .../20230721082851_enable_opening_times.rb       |  5 +----
 db/seeds.rb                                      |  2 +-
 4 files changed, 19 insertions(+), 7 deletions(-)
 create mode 100755 bin/app-startup.sh

diff --git a/Dockerfile b/Dockerfile
index 3a32fedb..39153c29 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -44,5 +44,4 @@ ENV GOVUK_NOTIFY_GENERIC_EMAIL_TEMPLATE_ID=$GOVUK_NOTIFY_GENERIC_EMAIL_TEMPLATE_
 RUN bundle exec rake assets:precompile && \
     rm -rf node_modules tmp
 
-CMD bundle exec rails db:migrate && \
-    bundle exec rails server -b 0.0.0.0
+CMD ./bin/app-startup.sh
\ No newline at end of file
diff --git a/bin/app-startup.sh b/bin/app-startup.sh
new file mode 100755
index 00000000..e28122a7
--- /dev/null
+++ b/bin/app-startup.sh
@@ -0,0 +1,16 @@
+#!/usr/bin/env sh
+#
+# Dockerfile application startup script
+#
+
+# run migrations
+bundle exec rails db:migrate
+
+# add seed data in review environment
+if [ "$RAILS_ENV" = "review" ]; then
+    echo "Running rails db:seed"
+    bundle exec rails db:seed
+fi
+
+# start server
+bundle exec rails server -b 0.0.0.0
diff --git a/db/migrate/20230721082851_enable_opening_times.rb b/db/migrate/20230721082851_enable_opening_times.rb
index d86d932a..135aa388 100644
--- a/db/migrate/20230721082851_enable_opening_times.rb
+++ b/db/migrate/20230721082851_enable_opening_times.rb
@@ -1,8 +1,5 @@
 class EnableOpeningTimes < ActiveRecord::Migration[7.0]
   def change
-    AppSettings.current.update!(
-      service_start_date: Time.zone.yesterday,
-      service_end_date: Time.zone.today + 1.year,
-    )
+    # Disable this migration and use rails db:seed on review environment only
   end
 end
diff --git a/db/seeds.rb b/db/seeds.rb
index 30fe8f2c..e423cc24 100644
--- a/db/seeds.rb
+++ b/db/seeds.rb
@@ -22,7 +22,7 @@
   FactoryBot.create_list(factory, 5, :with_initial_checks_completed)
 end
 
-AppSettings.create!(
+AppSettings.current.update!(
   service_start_date: 1.day.ago,
   service_end_date: 1.year.from_now,
 )

From 4ce5ac008077190df9b06551b7315d47363f52e3 Mon Sep 17 00:00:00 2001
From: fumimowdan <tecknuovo@zemis.co.uk>
Date: Thu, 14 Sep 2023 11:04:33 +0100
Subject: [PATCH 10/11] Update worker application replica number

starts one worker instance
---
 terraform/aks/application.tf | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/terraform/aks/application.tf b/terraform/aks/application.tf
index 68ebea66..41a76b82 100644
--- a/terraform/aks/application.tf
+++ b/terraform/aks/application.tf
@@ -51,7 +51,7 @@ module "worker_application" {
   kubernetes_secret_name     = module.application_configuration.kubernetes_secret_name
 
   docker_image  = var.app_docker_image
-  replicas      = 0
+  replicas      = 1
   command       = ["bundle", "exec", "sidekiq", "-C", "./config/sidekiq.yml"]
   probe_command = ["pgrep", "-f", "sidekiq"]
 }

From 258d5a682c4197cc7f412ef209e7180320149949 Mon Sep 17 00:00:00 2001
From: fumimowdan <tecknuovo@zemis.co.uk>
Date: Thu, 14 Sep 2023 11:36:23 +0100
Subject: [PATCH 11/11] Remove GOVUK_NOTIFY_APPLICATION_SUBMITTED_TEMPLATE_ID
 env var

This environment variable was used by the old govuk notify client and
is not in use anymore
---
 .github/workflows/build-and-deploy.yml | 1 -
 .github/workflows/ci.yml               | 1 -
 Dockerfile                             | 3 ---
 3 files changed, 5 deletions(-)

diff --git a/.github/workflows/build-and-deploy.yml b/.github/workflows/build-and-deploy.yml
index fc1cd50a..f10c11ec 100644
--- a/.github/workflows/build-and-deploy.yml
+++ b/.github/workflows/build-and-deploy.yml
@@ -88,7 +88,6 @@ jobs:
         build-args: |
           COMMIT_SHA=${{ env.IMAGE_TAG }}
           GOVUK_NOTIFY_API_KEY=${{ secrets.GOVUK_NOTIFY_API_KEY }}
-          GOVUK_NOTIFY_APPLICATION_SUBMITTED_TEMPLATE_ID=${{ secrets.GOVUK_NOTIFY_APPLICATION_SUBMITTED_TEMPLATE_ID }}
           GOVUK_NOTIFY_GENERIC_EMAIL_TEMPLATE_ID=${{ secrets.GOVUK_NOTIFY_GENERIC_EMAIL_TEMPLATE_ID }}
 
     - name: Push ${{ env.DOCKER_IMAGE }} images for review
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 92810f6a..d754637f 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -26,7 +26,6 @@ jobs:
       RAILS_ENV: test
       DATABASE_URL: 'postgres://rails:password@localhost:5432/rails_test'
       GOVUK_NOTIFY_API_KEY: ${{ secrets.GOVUK_NOTIFY_API_KEY }}
-      GOVUK_NOTIFY_APPLICATION_SUBMITTED_TEMPLATE_ID: ${{ secrets.GOVUK_NOTIFY_APPLICATION_SUBMITTED_TEMPLATE_ID }}
       GOVUK_NOTIFY_GENERIC_EMAIL_TEMPLATE_ID: ${{ secrets.GOVUK_NOTIFY_GENERIC_EMAIL_TEMPLATE_ID }}
     steps:
       - name: Checkout code
diff --git a/Dockerfile b/Dockerfile
index 39153c29..f1e81bb8 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -35,9 +35,6 @@ ENV COMMIT_SHA=$COMMIT_SHA
 ARG GOVUK_NOTIFY_API_KEY
 ENV GOVUK_NOTIFY_API_KEY=$GOVUK_NOTIFY_API_KEY
 
-ARG GOVUK_NOTIFY_APPLICATION_SUBMITTED_TEMPLATE_ID
-ENV GOVUK_NOTIFY_APPLICATION_SUBMITTED_TEMPLATE_ID=$GOVUK_NOTIFY_APPLICATION_SUBMITTED_TEMPLATE_ID
-
 ARG GOVUK_NOTIFY_GENERIC_EMAIL_TEMPLATE_ID
 ENV GOVUK_NOTIFY_GENERIC_EMAIL_TEMPLATE_ID=$GOVUK_NOTIFY_GENERIC_EMAIL_TEMPLATE_ID