diff --git a/app/forms/journeys/further_education_payments/claim_submission_form.rb b/app/forms/journeys/further_education_payments/claim_submission_form.rb index f3179f0459..d144f29046 100644 --- a/app/forms/journeys/further_education_payments/claim_submission_form.rb +++ b/app/forms/journeys/further_education_payments/claim_submission_form.rb @@ -4,9 +4,7 @@ class ClaimSubmissionForm < ::ClaimSubmissionBaseForm private def main_eligibility - @main_eligibility ||= Policies::FurtherEducationPayments::Eligibility.new( - teacher_reference_number: @journey_session.answers.teacher_reference_number - ) + @main_eligibility ||= eligibilities.first end def calculate_award_amount(eligibility) diff --git a/app/forms/journeys/further_education_payments/eligible_form.rb b/app/forms/journeys/further_education_payments/eligible_form.rb index 32e32a998d..5976b41097 100644 --- a/app/forms/journeys/further_education_payments/eligible_form.rb +++ b/app/forms/journeys/further_education_payments/eligible_form.rb @@ -2,11 +2,12 @@ module Journeys module FurtherEducationPayments class EligibleForm < Form def save - true + journey_session.answers.assign_attributes(award_amount:) + journey_session.save! end def award_amount - journey_session.answers.award_amount + journey_session.answers.calculate_award_amount end end end diff --git a/app/models/claim.rb b/app/models/claim.rb index 613d77937a..0c8d418a54 100644 --- a/app/models/claim.rb +++ b/app/models/claim.rb @@ -78,7 +78,11 @@ class Claim < ApplicationRecord dqt_teacher_status: false, submitted_using_slc_data: false, journeys_session_id: false, - column_to_remove_teacher_reference_number: true + column_to_remove_teacher_reference_number: true, + identity_confirmed_with_onelogin: false, + logged_in_with_onelogin: false, + onelogin_credentials: true, + onelogin_user_info: true }.freeze DECISION_DEADLINE = 12.weeks DECISION_DEADLINE_WARNING_POINT = 2.weeks diff --git a/app/models/journeys/further_education_payments/session_answers.rb b/app/models/journeys/further_education_payments/session_answers.rb index 0b3ccb63b9..2a5e2779d0 100644 --- a/app/models/journeys/further_education_payments/session_answers.rb +++ b/app/models/journeys/further_education_payments/session_answers.rb @@ -24,6 +24,7 @@ class SessionAnswers < Journeys::SessionAnswers attribute :subject_to_formal_performance_action, :boolean attribute :subject_to_disciplinary_action, :boolean attribute :half_teaching_hours, :boolean + attribute :award_amount, :decimal def policy Policies::FurtherEducationPayments @@ -120,7 +121,7 @@ def less_than_half_hours_teaching_eligible_courses? hours_teaching_eligible_subjects == false end - def award_amount + def calculate_award_amount case teaching_hours_per_week when "more_than_12" school.eligible_fe_provider.max_award_amount diff --git a/app/models/policies/further_education_payments/eligibility.rb b/app/models/policies/further_education_payments/eligibility.rb index 7d5f73f719..d3aa06bf1f 100644 --- a/app/models/policies/further_education_payments/eligibility.rb +++ b/app/models/policies/further_education_payments/eligibility.rb @@ -5,6 +5,12 @@ class Eligibility < ApplicationRecord has_one :claim, as: :eligibility, inverse_of: :eligibility + belongs_to :possible_school, optional: true, class_name: "School" + belongs_to :school, optional: true + + # Claim#school expects this + alias_method :current_school, :school + def policy Policies::FurtherEducationPayments end diff --git a/config/analytics.yml b/config/analytics.yml index 4e821629d4..1bb528b256 100644 --- a/config/analytics.yml +++ b/config/analytics.yml @@ -74,6 +74,8 @@ shared: - qualifications_details_check - submitted_using_slc_data - journeys_session_id + - identity_confirmed_with_onelogin + - logged_in_with_onelogin :decisions: - id - result @@ -271,6 +273,29 @@ shared: - created_at - updated_at - award_amount + - teaching_responsibilities + - provision_search + - possible_school_id + - school_id + - contract_type + - fixed_term_full_year + - taught_at_least_one_term + - teaching_hours_per_week + - teaching_hours_per_week_next_term + - further_education_teaching_start_year + - subjects_taught + - building_construction_courses + - chemistry_courses + - computing_courses + - early_years_courses + - engineering_manufacturing_courses + - maths_courses + - physics_courses + - hours_teaching_eligible_subjects + - teaching_qualification + - subject_to_formal_performance_action + - subject_to_disciplinary_action + - half_teaching_hours :eligible_fe_providers: - id - ukprn diff --git a/config/analytics_blocklist.yml b/config/analytics_blocklist.yml index 88bb454fcf..8966aa4831 100644 --- a/config/analytics_blocklist.yml +++ b/config/analytics_blocklist.yml @@ -26,6 +26,8 @@ - hmrc_bank_validation_responses - dqt_teacher_status - teacher_id_user_info + - onelogin_credentials + - onelogin_user_info :claim_decisions: - trn - claimant_age diff --git a/db/migrate/20240814123634_add_answer_fields_to_fe_eligibilities.rb b/db/migrate/20240814123634_add_answer_fields_to_fe_eligibilities.rb new file mode 100644 index 0000000000..2c13c9c29b --- /dev/null +++ b/db/migrate/20240814123634_add_answer_fields_to_fe_eligibilities.rb @@ -0,0 +1,27 @@ +class AddAnswerFieldsToFeEligibilities < ActiveRecord::Migration[7.0] + def change + add_column :further_education_payments_eligibilities, :teaching_responsibilities, :boolean + add_column :further_education_payments_eligibilities, :provision_search, :text + add_reference :further_education_payments_eligibilities, :possible_school, type: :uuid, foreign_key: {to_table: :schools}, index: {name: :index_fe_payments_eligibilities_on_possible_school_id} + add_reference :further_education_payments_eligibilities, :school, type: :uuid, foreign_key: {to_table: :schools}, index: {name: :index_fe_payments_eligibilities_on_school_id} + add_column :further_education_payments_eligibilities, :contract_type, :text + add_column :further_education_payments_eligibilities, :fixed_term_full_year, :boolean + add_column :further_education_payments_eligibilities, :taught_at_least_one_term, :boolean + add_column :further_education_payments_eligibilities, :teaching_hours_per_week, :text + add_column :further_education_payments_eligibilities, :teaching_hours_per_week_next_term, :text + add_column :further_education_payments_eligibilities, :further_education_teaching_start_year, :text + add_column :further_education_payments_eligibilities, :subjects_taught, :jsonb, default: [] + add_column :further_education_payments_eligibilities, :building_construction_courses, :jsonb, default: [] + add_column :further_education_payments_eligibilities, :chemistry_courses, :jsonb, default: [] + add_column :further_education_payments_eligibilities, :computing_courses, :jsonb, default: [] + add_column :further_education_payments_eligibilities, :early_years_courses, :jsonb, default: [] + add_column :further_education_payments_eligibilities, :engineering_manufacturing_courses, :jsonb, default: [] + add_column :further_education_payments_eligibilities, :maths_courses, :jsonb, default: [] + add_column :further_education_payments_eligibilities, :physics_courses, :jsonb, default: [] + add_column :further_education_payments_eligibilities, :hours_teaching_eligible_subjects, :boolean + add_column :further_education_payments_eligibilities, :teaching_qualification, :text + add_column :further_education_payments_eligibilities, :subject_to_formal_performance_action, :boolean + add_column :further_education_payments_eligibilities, :subject_to_disciplinary_action, :boolean + add_column :further_education_payments_eligibilities, :half_teaching_hours, :boolean + end +end diff --git a/db/migrate/20240816122950_add_onelogin_fields_to_claims.rb b/db/migrate/20240816122950_add_onelogin_fields_to_claims.rb new file mode 100644 index 0000000000..f686d416dd --- /dev/null +++ b/db/migrate/20240816122950_add_onelogin_fields_to_claims.rb @@ -0,0 +1,8 @@ +class AddOneloginFieldsToClaims < ActiveRecord::Migration[7.0] + def change + add_column :claims, :identity_confirmed_with_onelogin, :boolean + add_column :claims, :logged_in_with_onelogin, :boolean + add_column :claims, :onelogin_credentials, :jsonb, default: {} + add_column :claims, :onelogin_user_info, :jsonb, default: {} + end +end diff --git a/db/schema.rb b/db/schema.rb index b5eac09e53..5667259b99 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.0].define(version: 2024_08_12_123209) do +ActiveRecord::Schema[7.0].define(version: 2024_08_16_122950) do # These are extensions that must be enabled in order to support this database enable_extension "citext" enable_extension "pg_trgm" @@ -98,6 +98,10 @@ t.boolean "submitted_using_slc_data", default: false t.datetime "sent_one_time_password_at" t.uuid "journeys_session_id" + t.boolean "identity_confirmed_with_onelogin" + t.boolean "logged_in_with_onelogin" + t.jsonb "onelogin_credentials", default: {} + t.jsonb "onelogin_user_info", default: {} t.index ["academic_year"], name: "index_claims_on_academic_year" t.index ["created_at"], name: "index_claims_on_created_at" t.index ["eligibility_type", "eligibility_id"], name: "index_claims_on_eligibility_type_and_eligibility_id" @@ -218,6 +222,31 @@ t.datetime "updated_at", null: false t.decimal "award_amount", precision: 7, scale: 2 t.text "teacher_reference_number" + t.boolean "teaching_responsibilities" + t.text "provision_search" + t.uuid "possible_school_id" + t.uuid "school_id" + t.text "contract_type" + t.boolean "fixed_term_full_year" + t.boolean "taught_at_least_one_term" + t.text "teaching_hours_per_week" + t.text "teaching_hours_per_week_next_term" + t.text "further_education_teaching_start_year" + t.jsonb "subjects_taught", default: [] + t.jsonb "building_construction_courses", default: [] + t.jsonb "chemistry_courses", default: [] + t.jsonb "computing_courses", default: [] + t.jsonb "early_years_courses", default: [] + t.jsonb "engineering_manufacturing_courses", default: [] + t.jsonb "maths_courses", default: [] + t.jsonb "physics_courses", default: [] + t.boolean "hours_teaching_eligible_subjects" + t.text "teaching_qualification" + t.boolean "subject_to_formal_performance_action" + t.boolean "subject_to_disciplinary_action" + t.boolean "half_teaching_hours" + t.index ["possible_school_id"], name: "index_fe_payments_eligibilities_on_possible_school_id" + t.index ["school_id"], name: "index_fe_payments_eligibilities_on_school_id" end create_table "international_relocation_payments_eligibilities", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| @@ -520,6 +549,8 @@ add_foreign_key "decisions", "dfe_sign_in_users", column: "created_by_id" add_foreign_key "early_career_payments_eligibilities", "schools", column: "current_school_id" add_foreign_key "eligible_ey_providers", "local_authorities" + add_foreign_key "further_education_payments_eligibilities", "schools" + add_foreign_key "further_education_payments_eligibilities", "schools", column: "possible_school_id" add_foreign_key "international_relocation_payments_eligibilities", "schools", column: "current_school_id" add_foreign_key "levelling_up_premium_payments_eligibilities", "schools", column: "current_school_id" add_foreign_key "notes", "claims" diff --git a/spec/factories/journeys/further_education_payments/further_education_payments_answers.rb b/spec/factories/journeys/further_education_payments/further_education_payments_answers.rb index f9e13c415b..7b0f172ffe 100644 --- a/spec/factories/journeys/further_education_payments/further_education_payments_answers.rb +++ b/spec/factories/journeys/further_education_payments/further_education_payments_answers.rb @@ -1,13 +1,115 @@ FactoryBot.define do factory :further_education_payments_answers, class: "Journeys::FurtherEducationPayments::SessionAnswers" do - trait :with_details_from_onelogin do + trait :with_name do first_name { "Jo" } surname { "Bloggs" } - onelogin_user_info { {email: "jo.bloggs@example.com"} } + end + + trait :with_details_from_onelogin do + with_name + onelogin_user_info { {"email" => "jo.bloggs@example.com"} } + end + + trait :with_onelogin_credentials do + onelogin_credentials { {"id_token" => "some_token"} } + end + + trait :with_dob do + date_of_birth { 20.years.ago.to_date } + end + + trait :with_nino do + national_insurance_number { generate(:national_insurance_number) } + end + + trait :with_personal_details do + with_details_from_onelogin + with_dob + with_nino + end + + trait :with_email_details do + email_address { generate(:email_address) } + email_verified { true } + end + + trait :with_mobile_details do + mobile_number { "07474000123" } + provide_mobile_number { true } + mobile_verified { true } + end + + trait :with_bank_details do + bank_or_building_society { :personal_bank_account } + banking_name { "Jo Bloggs" } + bank_sort_code { rand(100000..999999) } + bank_account_number { rand(10000000..99999999) } + end + + trait :with_bank_details_validated do + hmrc_bank_validation_succeeded { true } + hmrc_bank_validation_responses do + [ + {code: 200, body: "Test response"} + ] + end + end + + trait :with_payroll_gender do + payroll_gender { "female" } + end + + trait :with_teacher_reference_number do + teacher_reference_number { generate(:teacher_reference_number) } + end + + trait :permanent do + contract_type { "permanent" } + teaching_hours_per_week { "more_than_12" } + end + + trait :with_academic_year do + academic_year { AcademicYear.current } + end + + trait :eligible do + teaching_responsibilities { true } + school_id { create(:school, :further_education, :fe_eligible).id } + permanent + further_education_teaching_start_year { "2019" } + subjects_taught { ["maths", "physics"] } + maths_courses { ["approved_level_321_maths", "gcse_maths"] } + physics_courses { ["gcse_physics"] } + hours_teaching_eligible_subjects { true } + half_teaching_hours { true } + teaching_qualification { "yes" } + subject_to_formal_performance_action { false } + subject_to_disciplinary_action { false } + end + + trait :with_award_amount do + award_amount { 4_000.0 } + end + + trait :with_address do + address_line_1 { "1 Test Road" } + address_line_2 { "Some Second Line" } + address_line_3 { "Some Town" } + address_line_4 { "Some County" } + postcode { "WIA OAA" } end trait :submittable do - # FIXME implement this trait with the details required to submit a claim + with_academic_year + eligible + with_award_amount + with_personal_details + with_address + with_email_details + with_mobile_details + with_bank_details + with_bank_details_validated + with_payroll_gender end end end diff --git a/spec/factories/journeys/teacher_student_loan_reimbursement/session_answers.rb b/spec/factories/journeys/teacher_student_loan_reimbursement/session_answers.rb index 550ce20b93..049efe027d 100644 --- a/spec/factories/journeys/teacher_student_loan_reimbursement/session_answers.rb +++ b/spec/factories/journeys/teacher_student_loan_reimbursement/session_answers.rb @@ -77,7 +77,7 @@ qualifications_details_check { true } end - trait :with_acadmic_year do + trait :with_academic_year do academic_year { AcademicYear.new(2019) } end @@ -105,7 +105,7 @@ with_leadership_position with_qts_award_year with_qualification_details_check - with_acadmic_year + with_academic_year with_student_loan with_student_loan_repayment_amount end diff --git a/spec/forms/journeys/further_education_payments/claim_submission_form_spec.rb b/spec/forms/journeys/further_education_payments/claim_submission_form_spec.rb new file mode 100644 index 0000000000..df6a3a5573 --- /dev/null +++ b/spec/forms/journeys/further_education_payments/claim_submission_form_spec.rb @@ -0,0 +1,64 @@ +require "rails_helper" + +RSpec.describe Journeys::FurtherEducationPayments::ClaimSubmissionForm do + before do + create(:journey_configuration, :further_education_payments) + end + + let(:journey) { Journeys::FurtherEducationPayments } + let(:school) { create(:school, :further_education, :fe_eligible) } + + let(:answers) { + build( + :further_education_payments_answers, + :submittable, + :with_onelogin_credentials, + identity_confirmed_with_onelogin: true, + logged_in_with_onelogin: true + ) + } + + let(:journey_session) { create(:further_education_payments_session, answers: answers) } + let(:form) { described_class.new(journey_session: journey_session) } + + describe "#save" do + subject { form.save } + + it "saves all answers into the Eligibility model" do + subject + claim = form.claim + eligibility = form.claim.eligibility + + expect(claim.identity_confirmed_with_onelogin).to eq(answers.identity_confirmed_with_onelogin) + expect(claim.logged_in_with_onelogin).to eq(answers.logged_in_with_onelogin) + expect(claim.onelogin_credentials).to eq(answers.onelogin_credentials) + expect(claim.onelogin_user_info).to eq(answers.onelogin_user_info) + + expect(eligibility.award_amount).to eq(answers.award_amount) + expect(eligibility.teacher_reference_number).to eq(answers.teacher_reference_number) + expect(eligibility.teaching_responsibilities).to eq(answers.teaching_responsibilities) + expect(eligibility.provision_search).to eq(answers.provision_search) + expect(eligibility.possible_school_id).to eq(answers.possible_school_id) + expect(eligibility.school_id).to eq(answers.school_id) + expect(eligibility.contract_type).to eq(answers.contract_type) + expect(eligibility.fixed_term_full_year).to eq(answers.fixed_term_full_year) + expect(eligibility.taught_at_least_one_term).to eq(answers.taught_at_least_one_term) + expect(eligibility.teaching_hours_per_week).to eq(answers.teaching_hours_per_week) + expect(eligibility.teaching_hours_per_week_next_term).to eq(answers.teaching_hours_per_week_next_term) + expect(eligibility.further_education_teaching_start_year).to eq(answers.further_education_teaching_start_year) + expect(eligibility.subjects_taught).to eq(answers.subjects_taught) + expect(eligibility.building_construction_courses).to eq(answers.building_construction_courses) + expect(eligibility.chemistry_courses).to eq(answers.chemistry_courses) + expect(eligibility.computing_courses).to eq(answers.computing_courses) + expect(eligibility.early_years_courses).to eq(answers.early_years_courses) + expect(eligibility.engineering_manufacturing_courses).to eq(answers.engineering_manufacturing_courses) + expect(eligibility.maths_courses).to eq(answers.maths_courses) + expect(eligibility.physics_courses).to eq(answers.physics_courses) + expect(eligibility.hours_teaching_eligible_subjects).to eq(answers.hours_teaching_eligible_subjects) + expect(eligibility.teaching_qualification).to eq(answers.teaching_qualification) + expect(eligibility.subject_to_formal_performance_action).to eq(answers.subject_to_formal_performance_action) + expect(eligibility.subject_to_disciplinary_action).to eq(answers.subject_to_disciplinary_action) + expect(eligibility.half_teaching_hours).to eq(answers.half_teaching_hours) + end + end +end diff --git a/spec/forms/journeys/further_education_payments/eligible_form_spec.rb b/spec/forms/journeys/further_education_payments/eligible_form_spec.rb new file mode 100644 index 0000000000..0b43e666f5 --- /dev/null +++ b/spec/forms/journeys/further_education_payments/eligible_form_spec.rb @@ -0,0 +1,33 @@ +require "rails_helper" + +RSpec.describe Journeys::FurtherEducationPayments::EligibleForm, type: :model do + let(:journey) { Journeys::FurtherEducationPayments } + let(:journey_session) { create(:further_education_payments_session, answers:) } + + let(:params) do + ActionController::Parameters.new + end + + let(:school) { create(:school, :further_education) } + + let(:answers) { build(:further_education_payments_answers, teaching_hours_per_week: "more_than_12", school_id: school.id) } + + subject do + described_class.new( + journey_session:, + journey:, + params: + ) + end + + describe "#save" do + let!(:eligible_fe_provider) { create(:eligible_fe_provider, ukprn: school.ukprn, max_award_amount: 4_000.0) } + + it "updates award_amount" do + expect { subject.save }.to( + change { journey_session.reload.answers.award_amount } + .to(4_000.0) + ) + end + end +end diff --git a/spec/models/claim_spec.rb b/spec/models/claim_spec.rb index a966149c75..07797e91a1 100644 --- a/spec/models/claim_spec.rb +++ b/spec/models/claim_spec.rb @@ -602,7 +602,9 @@ :email_address_check, :mobile_check, :qualifications_details_check, - :column_to_remove_teacher_reference_number + :column_to_remove_teacher_reference_number, + :onelogin_credentials, + :onelogin_user_info ]) end end diff --git a/spec/models/journeys/further_education_payments/answers_presenter_spec.rb b/spec/models/journeys/further_education_payments/answers_presenter_spec.rb index 27658c5267..c99c096e61 100644 --- a/spec/models/journeys/further_education_payments/answers_presenter_spec.rb +++ b/spec/models/journeys/further_education_payments/answers_presenter_spec.rb @@ -13,7 +13,7 @@ let(:school_id) { college.id } let(:contract_type) { "permanent" } let(:teaching_hours_per_week) { "more_than_12" } - let(:further_education_teaching_start_year) { 2023 } + let(:further_education_teaching_start_year) { "2023" } let(:subjects_taught) { ["chemistry", "maths"] } let(:half_teaching_hours) { true } let(:teaching_qualification) { "yes" } diff --git a/spec/models/journeys/further_education_payments/session_answers_spec.rb b/spec/models/journeys/further_education_payments/session_answers_spec.rb index bc555d9628..1cbbe2b9f1 100644 --- a/spec/models/journeys/further_education_payments/session_answers_spec.rb +++ b/spec/models/journeys/further_education_payments/session_answers_spec.rb @@ -5,7 +5,7 @@ let(:school) { create(:school, :further_education, :fe_eligible) } - describe "#award_amount" do + describe "#calculate_award_amount" do context "when teaching over 12 hours per week" do let(:answers) do build( @@ -16,7 +16,7 @@ end it "returns max award amount" do - expect(subject.award_amount).to eql(school.eligible_fe_provider.max_award_amount) + expect(subject.calculate_award_amount).to eql(school.eligible_fe_provider.max_award_amount) end end @@ -30,7 +30,7 @@ end it "returns lower award amount" do - expect(subject.award_amount).to eql(school.eligible_fe_provider.lower_award_amount) + expect(subject.calculate_award_amount).to eql(school.eligible_fe_provider.lower_award_amount) end end @@ -44,7 +44,7 @@ end it "returns zero" do - expect(subject.award_amount).to be_zero + expect(subject.calculate_award_amount).to be_zero end end end diff --git a/spec/requests/deauth_spec.rb b/spec/requests/deauth_spec.rb index e3e7d103ed..d83974fd5a 100644 --- a/spec/requests/deauth_spec.rb +++ b/spec/requests/deauth_spec.rb @@ -28,7 +28,7 @@ get "/further-education-payments/claim" journey_session = Journeys::FurtherEducationPayments::Session.last - journey_session.answers.onelogin_credentials = {id_token: "some_token"} + journey_session.answers.onelogin_credentials = {"id_token" => "some_token"} journey_session.save! delete "/deauth/onelogin"