diff --git a/app/controllers/applicants/application_routes_controller.rb b/app/controllers/applicants/application_routes_controller.rb deleted file mode 100644 index ece0c4df..00000000 --- a/app/controllers/applicants/application_routes_controller.rb +++ /dev/null @@ -1,37 +0,0 @@ -# frozen_string_literal: true - -module Applicants - class ApplicationRoutesController < ApplicationController - def new - @application_route = ApplicationRoute.new(application_route: params[:application_route]) - end - - def create - @application_route = ApplicationRoute.new(application_route_params) - - if @application_route.valid? - if @application_route.eligible? - application = Application.create!(application_route: @application_route.application_route) - session["application_id"] = application.id - - case @application_route.application_route - when "teacher" - redirect_to(new_applicants_school_detail_path) - when "salaried_trainee" - redirect_to(new_applicants_salaried_course_detail_path) - end - else - redirect_to(ineligible_path) - end - else - render(:new) - end - end - - private - - def application_route_params - params.fetch(:applicants_application_route, {}).permit(:application_route) - end - end -end diff --git a/app/controllers/applicants/application_summary_controller.rb b/app/controllers/applicants/application_summary_controller.rb deleted file mode 100644 index 259ec785..00000000 --- a/app/controllers/applicants/application_summary_controller.rb +++ /dev/null @@ -1,17 +0,0 @@ -# frozen_string_literal: true - -module Applicants - class ApplicationSummaryController < ApplicationController - before_action :check_application! - - def new - @summary = Summary.new(application: current_application) - end - - def create - SubmitApplication.new(current_application).run - - redirect_to(applicants_submission_path) - end - end -end diff --git a/app/controllers/applicants/contract_details_controller.rb b/app/controllers/applicants/contract_details_controller.rb deleted file mode 100644 index 70ca08f2..00000000 --- a/app/controllers/applicants/contract_details_controller.rb +++ /dev/null @@ -1,33 +0,0 @@ -# frozen_string_literal: true - -module Applicants - class ContractDetailsController < ApplicationController - before_action :check_application! - before_action :check_teacher! - - def new - @contract_detail = ContractDetail.new(one_year: params[:one_year]) - end - - def create - @contract_detail = ContractDetail.new(contract_detail_params) - - if @contract_detail.valid? - if @contract_detail.eligible? - - redirect_to(new_applicants_contract_start_date_path) - else - redirect_to(ineligible_path) - end - else - render(:new) - end - end - - private - - def contract_detail_params - params.fetch(:applicants_contract_detail, {}).permit(:one_year) - end - end -end diff --git a/app/controllers/applicants/contract_start_dates_controller.rb b/app/controllers/applicants/contract_start_dates_controller.rb deleted file mode 100644 index 58dced86..00000000 --- a/app/controllers/applicants/contract_start_dates_controller.rb +++ /dev/null @@ -1,41 +0,0 @@ -# frozen_string_literal: true - -module Applicants - class ContractStartDatesController < ApplicationController - before_action :check_application! - def new - @contract_start_date = ContractStartDate.new(contract_start_date: current_application.start_date) - end - - def create - @contract_start_date = ContractStartDate.new(contract_start_date_params) - - if @contract_start_date.valid? - if Policies::ContractStartDate.eligible?(@contract_start_date.contract_start_date) - current_application.update!(start_date: @contract_start_date.contract_start_date) - - redirect_to(new_applicants_subject_path) - else - redirect_to(ineligible_path) - end - else - render(:new) - end - end - - private - - def contract_start_date_params - params.require(:applicants_contract_start_date).permit( - *DATE_CONVERSION.keys, - ).transform_keys { |key| DATE_CONVERSION[key] } - end - - DATE_CONVERSION = { - "contract_start_date(3i)" => "day", - "contract_start_date(2i)" => "month", - "contract_start_date(1i)" => "year", - }.freeze - private_constant :DATE_CONVERSION - end -end diff --git a/app/controllers/applicants/employment_details_controller.rb b/app/controllers/applicants/employment_details_controller.rb deleted file mode 100644 index 0ad1b9b1..00000000 --- a/app/controllers/applicants/employment_details_controller.rb +++ /dev/null @@ -1,40 +0,0 @@ -# frozen_string_literal: true - -module Applicants - class EmploymentDetailsController < ApplicationController - before_action :check_application! - def new - @employment_detail = if current_application.applicant.school - EmploymentDetail.build(current_application.applicant.school) - else - EmploymentDetail.new - end - end - - def create - @employment_detail = EmploymentDetail.new(employment_detail_params) - - if @employment_detail.valid? - @employment_detail.applicant = current_applicant - @employment_detail.save! - - redirect_to(new_applicants_application_summary_path) - else - render(:new) - end - end - - private - - def employment_detail_params - params.require(:applicants_employment_detail).permit( - :school_name, - :school_headteacher_name, - :school_address_line_1, - :school_address_line_2, - :school_city, - :school_postcode, - ) - end - end -end diff --git a/app/controllers/applicants/entry_dates_controller.rb b/app/controllers/applicants/entry_dates_controller.rb deleted file mode 100644 index 1f67cc1a..00000000 --- a/app/controllers/applicants/entry_dates_controller.rb +++ /dev/null @@ -1,49 +0,0 @@ -# frozen_string_literal: true - -module Applicants - class EntryDatesController < ApplicationController - before_action :check_application! - - def new - @entry_date = EntryDate.new(entry_date: current_application.date_of_entry) - end - - def create - @entry_date = EntryDate.new(entry_date_params) - - if @entry_date.valid? - if eligible? - current_application.update!(date_of_entry: @entry_date.entry_date) - - redirect_to(new_applicants_personal_detail_path) - else - redirect_to(ineligible_path) - end - else - render(:new) - end - end - - private - - def eligible? - Policies::EntryDate.eligible?( - @entry_date.entry_date, - current_application.start_date, - ) - end - - def entry_date_params - params.require(:applicants_entry_date).permit( - *DATE_CONVERSION.keys, - ).transform_keys { |key| DATE_CONVERSION[key] } - end - - DATE_CONVERSION = { - "entry_date(3i)" => "day", - "entry_date(2i)" => "month", - "entry_date(1i)" => "year", - }.freeze - private_constant :DATE_CONVERSION - end -end diff --git a/app/controllers/applicants/personal_details_controller.rb b/app/controllers/applicants/personal_details_controller.rb deleted file mode 100644 index c7be43d4..00000000 --- a/app/controllers/applicants/personal_details_controller.rb +++ /dev/null @@ -1,53 +0,0 @@ -# frozen_string_literal: true - -module Applicants - class PersonalDetailsController < ApplicationController - invisible_captcha only: %i[create], honeypot: :username - before_action :check_application! - - def new - @personal_detail = PersonalDetail.new(applicant: current_application.applicant) - end - - def create - @personal_detail = PersonalDetail.new(personal_detail_params) - - if @personal_detail.valid? - @personal_detail.save!(application: current_application) - - redirect_to(new_applicants_employment_detail_path) - else - render(:new) - end - end - - private - - def personal_detail_params - params.require(:applicants_personal_detail).permit( - :given_name, - :middle_name, - :family_name, - :email_address, - :phone_number, - :sex, - :passport_number, - :nationality, - :address_line_1, - :address_line_2, - :city, - :postcode, - *DOB_CONVERSION.keys, - ).transform_keys do |key| - DOB_CONVERSION.key?(key) ? DOB_CONVERSION[key] : key - end - end - - DOB_CONVERSION = { - "date_of_birth(3i)" => "day", - "date_of_birth(2i)" => "month", - "date_of_birth(1i)" => "year", - }.freeze - private_constant :DOB_CONVERSION - end -end diff --git a/app/controllers/applicants/salaried_course_details_controller.rb b/app/controllers/applicants/salaried_course_details_controller.rb deleted file mode 100644 index a8cd1afb..00000000 --- a/app/controllers/applicants/salaried_course_details_controller.rb +++ /dev/null @@ -1,34 +0,0 @@ -# frozen_string_literal: true - -module Applicants - class SalariedCourseDetailsController < ApplicationController - before_action :check_application! - - before_action :check_trainee! - - def new - @salaried_course_detail = SalariedCourseDetail.new(eligible_course: params[:eligible_course]) - end - - def create - @salaried_course_detail = SalariedCourseDetail.new(salaried_course_detail_params) - - if @salaried_course_detail.valid? - if @salaried_course_detail.eligible? - - redirect_to(new_applicants_contract_start_date_path) - else - redirect_to(ineligible_salaried_course_path) - end - else - render(:new) - end - end - - private - - def salaried_course_detail_params - params.fetch(:applicants_salaried_course_detail, {}).permit(:eligible_course) - end - end -end diff --git a/app/controllers/applicants/school_details_controller.rb b/app/controllers/applicants/school_details_controller.rb deleted file mode 100644 index 1bcf58be..00000000 --- a/app/controllers/applicants/school_details_controller.rb +++ /dev/null @@ -1,34 +0,0 @@ -# frozen_string_literal: true - -module Applicants - class SchoolDetailsController < ApplicationController - before_action :check_application! - - before_action :check_teacher! - - def new - @school_detail = SchoolDetail.new(state_funded_secondary_school: params[:state_funded_secondary_school]) - end - - def create - @school_detail = SchoolDetail.new(school_detail_params) - - if @school_detail.valid? - if @school_detail.eligible? - - redirect_to(new_applicants_contract_detail_path) - else - redirect_to(ineligible_path) - end - else - render(:new) - end - end - - private - - def school_detail_params - params.fetch(:applicants_school_detail, {}).permit(:state_funded_secondary_school) - end - end -end diff --git a/app/controllers/applicants/subjects_controller.rb b/app/controllers/applicants/subjects_controller.rb deleted file mode 100644 index fa23abe9..00000000 --- a/app/controllers/applicants/subjects_controller.rb +++ /dev/null @@ -1,32 +0,0 @@ -# frozen_string_literal: true - -module Applicants - class SubjectsController < ApplicationController - before_action :check_application! - def new - @subject = Subject.new(subject: current_application.subject) - end - - def create - @subject = Subject.new(subject_params) - - if @subject.valid? - if @subject.eligible? - current_application.update!(subject: @subject.subject) - - redirect_to(new_applicants_visa_path) - else - redirect_to(ineligible_path) - end - else - render(:new) - end - end - - private - - def subject_params - params.fetch(:applicants_subject, {}).permit(:subject) - end - end -end diff --git a/app/controllers/applicants/submissions_controller.rb b/app/controllers/applicants/submissions_controller.rb deleted file mode 100644 index 67b70d38..00000000 --- a/app/controllers/applicants/submissions_controller.rb +++ /dev/null @@ -1,13 +0,0 @@ -# frozen_string_literal: true - -module Applicants - class SubmissionsController < ApplicationController - before_action :check_application! - - def show - @application = Application.find(session[:application_id]) - - session[:application_id] = nil - end - end -end diff --git a/app/controllers/applicants/visas_controller.rb b/app/controllers/applicants/visas_controller.rb deleted file mode 100644 index 6345bc8d..00000000 --- a/app/controllers/applicants/visas_controller.rb +++ /dev/null @@ -1,32 +0,0 @@ -# frozen_string_literal: true - -module Applicants - class VisasController < ApplicationController - before_action :check_application! - def new - @visa = Visa.new(visa_type: current_application.visa_type) - end - - def create - @visa = Visa.new(visa_params) - - if @visa.valid? - if @visa.eligible? - current_application.update!(visa_type: @visa.visa_type) - - redirect_to(new_applicants_entry_date_path) - else - redirect_to(ineligible_path) - end - else - render(:new) - end - end - - private - - def visa_params - params.require(:applicants_visa).permit(:visa_type) - end - end -end diff --git a/app/models/submit_application.rb b/app/models/submit_application.rb deleted file mode 100644 index 1559dd3c..00000000 --- a/app/models/submit_application.rb +++ /dev/null @@ -1,34 +0,0 @@ -class SubmitApplication - def initialize(application) - @application = application - end - - def run - create_application - send_email_to_applicant - - @application - end - -private - - def create_application - @application.update!( - application_date: Date.current.to_s, - application_progress: ApplicationProgress.new, - ) - @application.assign_urn! - end - - def send_email_to_applicant - 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, - ) - end -end diff --git a/config/routes.rb b/config/routes.rb index ee6544d5..2c51bcc3 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -19,22 +19,6 @@ get "/privacy", to: "pages#privacy" get "/sitemap", to: "pages#sitemap" - # namespace :applicants do - # resources :application_routes, only: %i[new create] - # resources :school_details, only: %i[new create edit] - # resources :contract_details, only: %i[new create edit] - # resources :contract_start_dates, only: %i[new create edit] - # resources :subjects, only: %i[new create edit] - # resources :teaching_details, only: %i[new create edit] - # resources :visas, only: %i[new create edit] - # resources :entry_dates, only: %i[new create edit] - # resources :personal_details, only: %i[new create edit] - # resources :employment_details, only: %i[new create edit] - # resources :salaried_course_details, only: %i[new create edit] - # resources :application_summary, only: %i[new create] - # resource :submission, only: %i[show] - # end - devise_for :users, controllers: { omniauth_callbacks: "users/omniauth_callbacks" } devise_scope :user do get "/users/sign_out", to: "devise/sessions#destroy", as: :destroy_user_session diff --git a/spec/controllers/applicants/submissions_controller_spec.rb b/spec/controllers/applicants/submissions_controller_spec.rb deleted file mode 100644 index 52e00dad..00000000 --- a/spec/controllers/applicants/submissions_controller_spec.rb +++ /dev/null @@ -1,21 +0,0 @@ -require "rails_helper" - -module Applicants - RSpec.describe SubmissionsController, pending: "will be removed" do - describe "GET #show" do - let(:application) { create(:application, :submitted) } - - before do - allow(controller).to receive(:current_application).and_return(application) - end - - it "resets the session's application_id to nil" do - session[:application_id] = application.id - - get :show - - expect(session[:application_id]).to be_nil - end - end - end -end diff --git a/spec/models/submit_application_spec.rb b/spec/models/submit_application_spec.rb deleted file mode 100644 index d6ec31ec..00000000 --- a/spec/models/submit_application_spec.rb +++ /dev/null @@ -1,43 +0,0 @@ -require "rails_helper" - -describe SubmitApplication do - describe "#run!" do - subject(:submit_application) { described_class.new(application) } - - let(:application) { create(:application) } - - it "returns an application" do - expect(submit_application.run).to be_a(Application) - end - - it "sets the applicant" do - submit_application.run - - expect(application).to be_present - end - - it "sets the application date" do - application = submit_application.run - - expect(application.application_date).to eq(Date.current) - end - - it "sets the urn" do - application = submit_application.run - - expect(application.urn).to be_present - end - - it "send an email" do - allow(GovukNotify::Client).to receive(:send_email) - - submit_application.run - - expect(GovukNotify::Client).to have_received(:send_email).with( - "661cdff0-08f0-4ccc-b23c-7d9d442517f6", - application.applicant.email_address, - application.urn, - ) - end - end -end diff --git a/spec/requests/question_for_contract_start_date_spec.rb b/spec/requests/question_for_contract_start_date_spec.rb deleted file mode 100644 index 04b9c409..00000000 --- a/spec/requests/question_for_contract_start_date_spec.rb +++ /dev/null @@ -1,83 +0,0 @@ -require "rails_helper" - -module Applicants - RSpec.describe "Question for Contract Start Date", pending: "will be removed" do - describe "POST create" do - let(:valid_params) do - { - applicants_contract_start_date: { - "contract_start_date(3i)" => "1", - "contract_start_date(2i)" => "1", - "contract_start_date(1i)" => "2023", - }, - } - end - - context "when it is not a teacher" do - before do - set_user_type("salaried_trainee") - end - - it "redirects to the new subject path if it is eligible" do - allow(Policies::ContractStartDate).to receive(:eligible?).and_return(true) - post "/applicants/contract_start_dates", params: valid_params - - expect(response).to redirect_to(new_applicants_subject_path) - end - end - - context "when it is a teacher" do - before do - set_user_type("teacher") - end - - context "with valid params" do - it "redirects to the new subject path if it is eligible" do - allow(Policies::ContractStartDate).to receive(:eligible?).and_return(true) - post "/applicants/contract_start_dates", params: valid_params - - expect(response).to redirect_to(new_applicants_subject_path) - end - - it "redirects to the ineligible path if it is not eligible" do - allow(Policies::ContractStartDate).to receive(:eligible?).and_return(false) - post "/applicants/contract_start_dates", params: valid_params - - expect(response).to redirect_to(ineligible_path) - end - end - - context "with invalid params" do - let(:invalid) do - { - applicants_contract_start_date: { - "contract_start_date(3i)" => "31", - "contract_start_date(2i)" => "31", - "contract_start_date(1i)" => "2023", - }, - } - end - - it "renders the new template" do - post "/applicants/contract_start_dates", params: invalid - - expect(response.body).to include("Enter the start date of your contract") - end - end - end - - # rubocop:disable RSpec/AnyInstance - def set_user_type(route_type) - # TODO: Remove this stub when we have a better way of storing the route type on the DB - # The current implementation of the application route is to store it in the session, - # this is not ideal and should be changed to be stored in the database. For now we are - # stubbing the session to return the route type, but this is temporary. - application = create(:application, application_route: route_type, urn: nil) - allow_any_instance_of(ContractStartDatesController).to receive(:session).and_return( - { "application_id" => application.id }, - ) - end - # rubocop:enable RSpec/AnyInstance - end - end -end diff --git a/spec/requests/question_for_employment_details_spec.rb b/spec/requests/question_for_employment_details_spec.rb deleted file mode 100644 index db9bd59f..00000000 --- a/spec/requests/question_for_employment_details_spec.rb +++ /dev/null @@ -1,78 +0,0 @@ -require "rails_helper" - -module Applicants - RSpec.describe "Question for Employment details", pending: "will be removed" do - describe "POST create" do - let(:valid_params) do - { - applicants_employment_detail: { - "school_name" => "Alexander McLeod Primary School", - "school_headteacher_name" => "Mr. Headteacher", - "school_address_line_1" => "7 McLeud", - "school_address_line_2" => "second line", - "school_city" => "London", - "school_postcode" => "E1 8QS", - }, - } - end - - before do - set_applicant_details! - end - - context "with valid params" do - it "redirects to the summary path" do - post "/applicants/employment_details", params: valid_params - - expect(response).to redirect_to(new_applicants_application_summary_path) - end - - it "creates a School" do - expect { post "/applicants/employment_details", params: valid_params } - .to change(School, :count).by(1) - end - - it "creates an Applicant Address" do - expect { post "/applicants/employment_details", params: valid_params } - .to change(Address, :count).by(1) - end - - it "links the applicant with the school" do - post "/applicants/employment_details", params: valid_params - - expect(Applicant.last.school).to eq(School.last) - end - end - - context "with invalid params" do - let(:invalid) do - { - applicants_employment_detail: { - "school_name" => "Alexander McLeod Primary School", - "school_postcode" => "E1 8QS", - "school_headteacher_name" => "Mr. Headteacher", - }, - } - end - - it "renders the new template" do - post "/applicants/employment_details", params: invalid - - expect(response.body).to include("Employment information") - end - end - end - - # rubocop:disable RSpec/AnyInstance - def set_applicant_details! - # The current implementation uses the user session to store attributes, which - # is not ideal and should be changed next. For now we are stubbing the session - # to return the applicant details. - application = create(:application, urn: nil) - allow_any_instance_of(EmploymentDetailsController).to receive(:session).and_return({ - "application_id" => application.id, - }) - end - # rubocop:enable RSpec/AnyInstance - end -end diff --git a/spec/requests/question_for_personal_details_spec.rb b/spec/requests/question_for_personal_details_spec.rb deleted file mode 100644 index b6d178d1..00000000 --- a/spec/requests/question_for_personal_details_spec.rb +++ /dev/null @@ -1,76 +0,0 @@ -require "rails_helper" - -module Applicants - RSpec.describe "Question for Personal details", pending: "will be removed" do - describe "POST create" do - let(:valid_params) do - { - applicants_personal_detail: { - "given_name" => "John", - "family_name" => "Doe", - "email_address" => "john@email.com", - "phone_number" => "07702496000", - "sex" => "male", - "passport_number" => "123456789", - "nationality" => "British National Overseas", - "address_line_1" => "7 McLeud", - "address_line_2" => "second line", - "city" => "London", - "postcode" => "E1 8QS", - "date_of_birth(3i)" => "1", - "date_of_birth(2i)" => "1", - "date_of_birth(1i)" => "1990", - }, - } - end - - before do - set_applicant_route! - end - - context "with valid params" do - it "redirects to the employment details path" do - post "/applicants/personal_details", params: valid_params - - expect(response).to redirect_to(new_applicants_employment_detail_path) - end - - it "creates an Applicant" do - expect { - post "/applicants/personal_details", params: valid_params - }.to change(Applicant, :count).by(1) - end - end - - context "with invalid params" do - let(:invalid) do - { - applicants_personal_detail: { - "school_name" => "Alexander McLeod Primary School", - "school_postcode" => "E1 8QS", - "school_headteacher_name" => "Mr. Headteacher", - }, - } - end - - it "renders the new template" do - post "/applicants/personal_details", params: invalid - - expect(response.body).to include("Personal information") - end - end - - # rubocop:disable RSpec/AnyInstance - def set_applicant_route! - # The current implementation users the user session to store attributes, which - # is not ideal and should be changed next. For now we are stubbing the session - # to return the applicant details. - application = create(:application, urn: nil) - allow_any_instance_of(PersonalDetailsController).to receive(:session).and_return({ - "application_id" => application.id, - }) - end - # rubocop:enable RSpec/AnyInstance - end - end -end