diff --git a/app/forms/teacher_reference_number_form.rb b/app/forms/teacher_reference_number_form.rb index 28c817853b..9a37d30e71 100644 --- a/app/forms/teacher_reference_number_form.rb +++ b/app/forms/teacher_reference_number_form.rb @@ -1,9 +1,9 @@ class TeacherReferenceNumberForm < Form + include TeacherReferenceNumberValidation + attribute :teacher_reference_number - before_validation do - self.teacher_reference_number = teacher_reference_number&.gsub(/\D/, "") - end + before_validation :normalise_teacher_reference_number validates :teacher_reference_number, presence: { @@ -12,7 +12,7 @@ class TeacherReferenceNumberForm < Form validates :teacher_reference_number, length: { - is: 7, + is: TRN_LENGTH, message: ->(form, _) { form.i18n_errors_path("length") } }, if: -> { teacher_reference_number.present? } diff --git a/app/helpers/admin/claims_helper.rb b/app/helpers/admin/claims_helper.rb index 5eb9a7c079..be8c73a699 100644 --- a/app/helpers/admin/claims_helper.rb +++ b/app/helpers/admin/claims_helper.rb @@ -36,7 +36,7 @@ def personal_data_removed_text def admin_personal_details(claim) [ - [translate("admin.teacher_reference_number"), claim.teacher_reference_number], + [translate("admin.teacher_reference_number"), claim.eligibility.teacher_reference_number], [translate("govuk_verify_fields.full_name").capitalize, claim.personal_data_removed? ? personal_data_removed_text : claim.full_name], [translate("govuk_verify_fields.date_of_birth").capitalize, claim.personal_data_removed? ? personal_data_removed_text : l(claim.date_of_birth, format: :day_month_year)], [translate("admin.national_insurance_number"), claim.personal_data_removed? ? personal_data_removed_text : claim.national_insurance_number], @@ -98,11 +98,19 @@ def claim_route(claim) end def matching_attributes(first_claim, second_claim) - first_attributes = matching_attributes_for(first_claim) - second_attributes = matching_attributes_for(second_claim) + first_attributes = matching_attributes_for_claim(first_claim) + second_attributes = matching_attributes_for_claim(second_claim) + + first_eligibility_attributes = matching_attributes_for_eligibility(first_claim.eligibility) + second_eligibility_attributes = matching_attributes_for_eligibility(second_claim.eligibility) matching_attributes = first_attributes & second_attributes - matching_attributes.to_h.compact.keys.map(&:humanize).sort + claim_matches = matching_attributes.to_h.compact.keys.map(&:humanize).sort + + matching_eligibility_attributes = first_eligibility_attributes & second_eligibility_attributes + eligibility_matches = matching_eligibility_attributes.to_h.compact.keys.map(&:humanize).sort + + claim_matches + eligibility_matches end def identity_confirmation_task_claim_verifier_match_status_tag(claim) @@ -226,9 +234,16 @@ def no_claims(status) private - def matching_attributes_for(claim) + def matching_attributes_for_claim(claim) claim.attributes - .slice(*Claim::MatchingAttributeFinder::ATTRIBUTE_GROUPS_TO_MATCH.flatten) + .slice(*Claim::MatchingAttributeFinder::CLAIM_ATTRIBUTE_GROUPS_TO_MATCH.flatten) + .reject { |_, v| v.blank? } + .to_a + end + + def matching_attributes_for_eligibility(eligibility) + eligibility.attributes + .slice(*eligibility.policy.eligibility_matching_attributes.flatten) .reject { |_, v| v.blank? } .to_a end diff --git a/app/jobs/claim_verifier_job.rb b/app/jobs/claim_verifier_job.rb index 70ab84cf64..d876bbfbfa 100644 --- a/app/jobs/claim_verifier_job.rb +++ b/app/jobs/claim_verifier_job.rb @@ -3,7 +3,7 @@ def perform(claim) AutomatedChecks::ClaimVerifier.new( claim:, dqt_teacher_status: claim.has_dqt_record? ? Dqt::Teacher.new(claim.dqt_teacher_status) : Dqt::Client.new.teacher.find( - claim.teacher_reference_number, + claim.eligibility.teacher_reference_number, birthdate: claim.date_of_birth.to_s, nino: claim.national_insurance_number ) diff --git a/app/jobs/qualifications_no_match_check_job.rb b/app/jobs/qualifications_no_match_check_job.rb index b953316190..832100e5e3 100644 --- a/app/jobs/qualifications_no_match_check_job.rb +++ b/app/jobs/qualifications_no_match_check_job.rb @@ -24,7 +24,7 @@ def perform(filter: nil) AutomatedChecks::ClaimVerifiers::Qualifications.new( claim: claim, dqt_teacher_status: Dqt::Client.new.teacher.find( - claim.teacher_reference_number, + claim.eligibility.teacher_reference_number, birthdate: claim.date_of_birth.to_s, nino: claim.national_insurance_number ) diff --git a/app/models/automated_checks/claim_verifiers/census_subjects_taught.rb b/app/models/automated_checks/claim_verifiers/census_subjects_taught.rb index a520bf35d2..6bb0f26cc7 100644 --- a/app/models/automated_checks/claim_verifiers/census_subjects_taught.rb +++ b/app/models/automated_checks/claim_verifiers/census_subjects_taught.rb @@ -10,7 +10,7 @@ def initialize( ) self.admin_user = admin_user self.claim = claim - self.school_workforce_census = SchoolWorkforceCensus.where(teacher_reference_number: claim.teacher_reference_number) + self.school_workforce_census = SchoolWorkforceCensus.where(teacher_reference_number: claim.eligibility.teacher_reference_number) self.school_workforce_census_subjects = school_workforce_census end diff --git a/app/models/automated_checks/claim_verifiers/employment.rb b/app/models/automated_checks/claim_verifiers/employment.rb index fe376ae4c8..d3186ef15c 100644 --- a/app/models/automated_checks/claim_verifiers/employment.rb +++ b/app/models/automated_checks/claim_verifiers/employment.rb @@ -7,7 +7,7 @@ class Employment def initialize(claim:, admin_user: nil) self.admin_user = admin_user self.claim = claim - self.teachers_pensions_service = TeachersPensionsService.by_teacher_reference_number(claim.teacher_reference_number) + self.teachers_pensions_service = TeachersPensionsService.by_teacher_reference_number(claim.eligibility.teacher_reference_number) end def perform diff --git a/app/models/automated_checks/claim_verifiers/identity.rb b/app/models/automated_checks/claim_verifiers/identity.rb index d6ad1ef1c9..c6d31d8cc3 100644 --- a/app/models/automated_checks/claim_verifiers/identity.rb +++ b/app/models/automated_checks/claim_verifiers/identity.rb @@ -147,7 +147,7 @@ def partial_match unless trn_matched? notes << create_field_note( name: "Teacher reference number", - claimant: claim.teacher_reference_number, + claimant: claim.eligibility.teacher_reference_number, dqt: dqt_teacher_status.teacher_reference_number ) end @@ -162,7 +162,7 @@ def tasks=(tasks) end def trn_matched? - claim.teacher_reference_number == dqt_teacher_status.teacher_reference_number + claim.eligibility.teacher_reference_number == dqt_teacher_status.teacher_reference_number end end end diff --git a/app/models/base_policy.rb b/app/models/base_policy.rb index 7ffd82daf1..da9f4a0c42 100644 --- a/app/models/base_policy.rb +++ b/app/models/base_policy.rb @@ -24,4 +24,26 @@ def locale_key def payroll_file_name to_s end + + def policies_claimable + return [] unless const_defined?(:OTHER_CLAIMABLE_POLICIES) + + [self] + self::OTHER_CLAIMABLE_POLICIES + end + + def policy_eligibilities_claimable + policies_claimable.map { |p| p::Eligibility } + end + + def eligibility_matching_attributes + return [] unless const_defined?(:ELIGIBILITY_MATCHING_ATTRIBUTES) + + self::ELIGIBILITY_MATCHING_ATTRIBUTES + end + + def searchable_eligibility_attributes + return [] unless const_defined?(:SEARCHABLE_ELIGIBILITY_ATTRIBUTES) + + self::SEARCHABLE_ELIGIBILITY_ATTRIBUTES + end end diff --git a/app/models/claim.rb b/app/models/claim.rb index 818faae867..625b7b2f22 100644 --- a/app/models/claim.rb +++ b/app/models/claim.rb @@ -2,12 +2,10 @@ class Claim < ApplicationRecord MIN_QA_THRESHOLD = 10 - TRN_LENGTH = 7 NO_STUDENT_LOAN = "not_applicable" STUDENT_LOAN_PLAN_OPTIONS = StudentLoan::PLANS.dup << NO_STUDENT_LOAN ADDRESS_ATTRIBUTES = %w[address_line_1 address_line_2 address_line_3 address_line_4 postcode].freeze AMENDABLE_ATTRIBUTES = %i[ - teacher_reference_number national_insurance_number date_of_birth student_loan_plan @@ -22,7 +20,6 @@ class Claim < ApplicationRecord address_line_4: true, postcode: true, payroll_gender: true, - teacher_reference_number: true, national_insurance_number: true, has_student_loan: false, student_loan_country: false, @@ -76,7 +73,8 @@ class Claim < ApplicationRecord qualifications_details_check: true, dqt_teacher_status: false, submitted_using_slc_data: false, - journeys_session_id: false + journeys_session_id: false, + column_to_remove_teacher_reference_number: true }.freeze DECISION_DEADLINE = 12.weeks DECISION_DEADLINE_WARNING_POINT = 2.weeks @@ -126,9 +124,6 @@ class Claim < ApplicationRecord validates :academic_year_before_type_cast, format: {with: AcademicYear::ACADEMIC_YEAR_REGEXP} - validates :teacher_reference_number, on: [:submit, :amendment], presence: {message: "Enter your teacher reference number"} - validate :trn_must_be_seven_digits - validates :has_student_loan, on: [:"student-loan"], inclusion: {in: [true, false]} validates :student_loan_plan, inclusion: {in: STUDENT_LOAN_PLAN_OPTIONS}, allow_nil: true validates :student_loan_plan, on: [:"student-loan", :amendment], presence: {message: "Enter a valid student loan plan"} @@ -147,7 +142,6 @@ class Claim < ApplicationRecord validate :building_society_roll_number_must_be_between_one_and_eighteen_digits validate :building_society_roll_number_must_be_in_a_valid_format - before_save :normalise_trn, if: :teacher_reference_number_changed? before_save :normalise_ni_number, if: :national_insurance_number_changed? before_save :normalise_bank_account_number, if: :bank_account_number_changed? before_save :normalise_bank_sort_code, if: :bank_sort_code_changed? @@ -405,18 +399,6 @@ def set_a_reminder? private - def normalise_trn - self.teacher_reference_number = normalised_trn - end - - def normalised_trn - teacher_reference_number.gsub(/\D/, "") - end - - def trn_must_be_seven_digits - errors.add(:teacher_reference_number, "Teacher reference number must be 7 digits") if teacher_reference_number.present? && normalised_trn.length != TRN_LENGTH - end - def normalise_ni_number self.national_insurance_number = normalised_ni_number end diff --git a/app/models/claim/claims_preventing_payment_finder.rb b/app/models/claim/claims_preventing_payment_finder.rb index 3526a56fe2..82be1248d9 100644 --- a/app/models/claim/claims_preventing_payment_finder.rb +++ b/app/models/claim/claims_preventing_payment_finder.rb @@ -15,6 +15,9 @@ def initialize(claim) # The returned claims have different payment or tax details to those # provided by `claim`, and hence `claim` cannot be paid in the same payment # as the returned claims. + # + # NOTE: This only works for ECP/LUPP and TSLR cross policy as this requires a TRN + # Driven by: Policies.policies_claimable(policy) using OTHER_CLAIMABLE_POLICIES config otherwise this just returns [] def claims_preventing_payment @claims_preventing_payment ||= find_claims_preventing_payment end @@ -22,14 +25,21 @@ def claims_preventing_payment private def find_claims_preventing_payment - payrollable_claims_from_same_claimant = Claim.payrollable.where(teacher_reference_number: claim.teacher_reference_number) + eligibility_ids = claim.policy.policies_claimable.map { |policy| + policy::Eligibility.where(teacher_reference_number: claim.eligibility.teacher_reference_number) + }.flatten.map(&:id) + + payrollable_claims_from_same_claimant = Claim.payrollable.where(eligibility_id: eligibility_ids) payrollable_topup_claims_from_same_claimant = Topup.includes(:claim).payrollable - .select { |t| t.claim.teacher_reference_number == claim.teacher_reference_number } + .select { |t| + claim.policy.policy_eligibilities_claimable.map(&:to_s).include?(t.claim.eligibility_type) && + t.claim.eligibility.teacher_reference_number == claim.eligibility.teacher_reference_number + } .map(&:claim) [payrollable_claims_from_same_claimant, payrollable_topup_claims_from_same_claimant].reduce([], :concat).select do |other_claim| - Payment::PERSONAL_DETAILS_ATTRIBUTES_FORBIDDING_DISCREPANCIES.any? do |attribute| + Payment::PERSONAL_CLAIM_DETAILS_ATTRIBUTES_FORBIDDING_DISCREPANCIES.any? do |attribute| attribute_does_not_match?(other_claim, attribute) end end diff --git a/app/models/claim/data_report_request.rb b/app/models/claim/data_report_request.rb index f07637dd51..2d7d423433 100644 --- a/app/models/claim/data_report_request.rb +++ b/app/models/claim/data_report_request.rb @@ -28,7 +28,7 @@ def to_csv @claims.each do |claim| csv << [ ExcelUtils.escape_formulas(claim.reference), - ExcelUtils.escape_formulas(claim.teacher_reference_number), + ExcelUtils.escape_formulas(claim.eligibility.teacher_reference_number), ExcelUtils.escape_formulas(claim.national_insurance_number), ExcelUtils.escape_formulas(claim.full_name), ExcelUtils.escape_formulas(claim.email_address), diff --git a/app/models/claim/matching_attribute_finder.rb b/app/models/claim/matching_attribute_finder.rb index 74825e3925..710601bb92 100644 --- a/app/models/claim/matching_attribute_finder.rb +++ b/app/models/claim/matching_attribute_finder.rb @@ -1,7 +1,7 @@ class Claim class MatchingAttributeFinder - ATTRIBUTE_GROUPS_TO_MATCH = [ - ["teacher_reference_number"], + # Fields on the claim model to consider a match + CLAIM_ATTRIBUTE_GROUPS_TO_MATCH = [ ["email_address"], ["national_insurance_number"], ["bank_account_number", "bank_sort_code", "building_society_roll_number"] @@ -13,17 +13,20 @@ def initialize(source_claim) # Returns a list of claims that could potentially be from the same applicant # because they either share a same single attribute with the source claim, - # (for example, the same TRN, or email), or they share a group of attributes + # (for example, the same national_insurance_number, email, etc...), or they share a group of attributes # with the source claim (for example bank sort code, account number and roll # number). # + # The associated eligibility fields can be used as well + # # This may not necessarily mean the claim cannot be approved, but means it # warrants a degree of caution and further investigation. def matching_claims match_queries = Claim.none - ATTRIBUTE_GROUPS_TO_MATCH.each do |attributes| - vals = values_for_attributes(attributes) + # Claim attributes + CLAIM_ATTRIBUTE_GROUPS_TO_MATCH.each do |attributes| + vals = values_for_attributes(@source_claim, attributes) next if vals.blank? @@ -33,20 +36,46 @@ def matching_claims match_queries = match_queries.or(query) end + # Eligibility attributes + eligibility_ids = eligibility_attributes_groups_to_match.map { |attributes| + vals = values_for_attributes(@source_claim.eligibility, attributes) + concatenated_columns = "CONCAT(#{attributes.join(",")})" + + policies_to_find_matches.map { |policy| + policy::Eligibility.where("LOWER(#{concatenated_columns}) = LOWER(?)", vals.join) + } + }.flatten.map(&:id) + + eligibility_match_query = Claim.where(eligibility_id: eligibility_ids) + match_queries = match_queries.or(eligibility_match_query) + claims_to_compare.merge(match_queries) end private + def policies_to_find_matches + @source_claim.policy.policies_claimable + end + + def eligibility_attributes_groups_to_match + @source_claim.policy.eligibility_matching_attributes + end + + def policies_to_find_matches_eligibility_types + policies_to_find_matches.map { |policy| policy::Eligibility.to_s } + end + def claims_to_compare Claim.submitted .by_academic_year(@source_claim.academic_year) + .by_policies(policies_to_find_matches) .where.not(id: @source_claim.id) end - def values_for_attributes(attributes) + def values_for_attributes(object, attributes) attributes.map { |attribute| - @source_claim.read_attribute(attribute) + object.read_attribute(attribute) }.reject(&:blank?) end end diff --git a/app/models/claim/search.rb b/app/models/claim/search.rb index 30045149f5..7eb9df3e36 100644 --- a/app/models/claim/search.rb +++ b/app/models/claim/search.rb @@ -1,15 +1,14 @@ class Claim # Accepts a search term and returns all Claims that match against any of the - # attributes defined in the `SEARCHABLE_ATTRIBUTES` constant. Both subject + # attributes defined in the `SEARCHABLE_ATTRIBUTES` or `policy::SEARCHABLE_ELIGIBILITY_ATTRIBUTES` constant. Both subject # and attribute are downcased, so the search is case-insensitive. class Search attr_accessor :search_term - SEARCHABLE_ATTRIBUTES = %w[ + SEARCHABLE_CLAIM_ATTRIBUTES = %w[ reference email_address surname - teacher_reference_number ] def initialize(search_term) @@ -17,9 +16,17 @@ def initialize(search_term) end def claims - SEARCHABLE_ATTRIBUTES.inject(Claim.none) do |relation, attribute| + claim_match_query = SEARCHABLE_CLAIM_ATTRIBUTES.inject(Claim.none) { |relation, attribute| relation.or(search_by(attribute)) - end + } + + eligibility_ids = Policies::POLICIES.map { |policy| + policy.searchable_eligibility_attributes.map { |attribute| + policy::Eligibility.where("LOWER(#{attribute}) = LOWER(?)", search_term) + } + }.flatten.map(&:id) + + claim_match_query.or(Claim.where(eligibility_id: eligibility_ids)) end private diff --git a/app/models/concerns/teacher_reference_number_validation.rb b/app/models/concerns/teacher_reference_number_validation.rb new file mode 100644 index 0000000000..84d49c1637 --- /dev/null +++ b/app/models/concerns/teacher_reference_number_validation.rb @@ -0,0 +1,28 @@ +module TeacherReferenceNumberValidation + extend ActiveSupport::Concern + + TRN_LENGTH = 7 + + def validate_teacher_reference_number_length + if teacher_reference_number.present? && !valid_teacher_reference_number_length?(teacher_reference_number) + errors.add(:teacher_reference_number, "Teacher reference number must be #{TRN_LENGTH} digits") + end + end + + def normalise_teacher_reference_number + self.teacher_reference_number = normalised_teacher_reference_number(teacher_reference_number) + end + + def normalised_teacher_reference_number(trn) + trn.to_s.gsub(/\D/, "") + end + + def valid_teacher_reference_number_length?(trn) + trn.to_s.length == TRN_LENGTH + end + + # For some reason less than 7 digits is a thing for the school workforce census import! + def valid_teacher_reference_number_length_for_school_workforce_census?(trn) + trn.to_s.length <= TRN_LENGTH + end +end diff --git a/app/models/concerns/trn_validation.rb b/app/models/concerns/trn_validation.rb deleted file mode 100644 index 8ae027c4dc..0000000000 --- a/app/models/concerns/trn_validation.rb +++ /dev/null @@ -1,13 +0,0 @@ -module TrnValidation - extend ActiveSupport::Concern - - TRN_LENGTH = 7 - - def normalize_teacher_reference_number(teacher_reference_number) - teacher_reference_number.to_s.gsub(/\D/, "") - end - - def valid_trn_length?(teacher_reference_number) - teacher_reference_number.length <= TRN_LENGTH - end -end diff --git a/app/models/journeys/page_sequence.rb b/app/models/journeys/page_sequence.rb index d6fe3bcead..930c2bcf29 100644 --- a/app/models/journeys/page_sequence.rb +++ b/app/models/journeys/page_sequence.rb @@ -3,7 +3,7 @@ # Used to model the sequence of pages that make up the claim process. module Journeys class PageSequence - attr_reader :current_slug, :completed_slugs + attr_reader :current_slug DEAD_END_SLUGS = %w[complete existing-session eligible-later future-eligibility ineligible] OPTIONAL_SLUGS = %w[postcode-search select-home-address reset-claim] @@ -47,10 +47,16 @@ def in_sequence?(slug) def has_completed_journey_until?(slug) return true if DEAD_END_SLUGS.include?(slug) - return true if (slug == "address" || answers.postcode.present?) && incomplete_slugs == ["address"] incomplete_slugs.empty? end + def completed_slugs + # /address is considered completed if provided via /postcode-search and /select-home-address + return @completed_slugs + ["address"] if answers.postcode.present? + + @completed_slugs + end + def next_required_slug (slugs - completed_slugs - OPTIONAL_SLUGS).first end diff --git a/app/models/payment.rb b/app/models/payment.rb index 843546e8e6..e9fdf3027c 100644 --- a/app/models/payment.rb +++ b/app/models/payment.rb @@ -16,7 +16,7 @@ class Payment < ApplicationRecord validates :scheduled_payment_date, presence: true, on: :upload validate :personal_details_must_be_consistent - PERSONAL_DETAILS_ATTRIBUTES_PERMITTING_DISCREPANCIES = %i[ + PERSONAL_CLAIM_DETAILS_ATTRIBUTES_PERMITTING_DISCREPANCIES = %i[ first_name middle_name surname @@ -31,8 +31,7 @@ class Payment < ApplicationRecord banking_name national_insurance_number ] - PERSONAL_DETAILS_ATTRIBUTES_FORBIDDING_DISCREPANCIES = %i[ - teacher_reference_number + PERSONAL_CLAIM_DETAILS_ATTRIBUTES_FORBIDDING_DISCREPANCIES = %i[ date_of_birth student_loan_plan bank_sort_code @@ -40,7 +39,11 @@ class Payment < ApplicationRecord building_society_roll_number ] - delegate(*(PERSONAL_DETAILS_ATTRIBUTES_PERMITTING_DISCREPANCIES + PERSONAL_DETAILS_ATTRIBUTES_FORBIDDING_DISCREPANCIES), to: :claim_for_personal_details) + PERSONAL_ELIGIBILITY_DETAILS_ATTRIBUTES_FORBIDDING_DISCREPANCIES = %i[ + teacher_reference_number + ] + + delegate(*(PERSONAL_CLAIM_DETAILS_ATTRIBUTES_PERMITTING_DISCREPANCIES + PERSONAL_CLAIM_DETAILS_ATTRIBUTES_FORBIDDING_DISCREPANCIES), to: :claim_for_personal_details) def policies_in_payment claims.map { |claim| claim.policy.payroll_file_name }.uniq.sort.join(" ") @@ -53,14 +56,22 @@ def confirmed? private def personal_details_must_be_consistent - mismatching_attributes = PERSONAL_DETAILS_ATTRIBUTES_FORBIDDING_DISCREPANCIES.select { |attribute| + mismatching_attributes = PERSONAL_CLAIM_DETAILS_ATTRIBUTES_FORBIDDING_DISCREPANCIES.select { |attribute| attribute_values = claims.map(&attribute) attribute_values.uniq.count > 1 && !attribute_values.all?(&:blank?) } - if mismatching_attributes.any? + mismatching_eligibility_attributes = PERSONAL_ELIGIBILITY_DETAILS_ATTRIBUTES_FORBIDDING_DISCREPANCIES.select { |attribute| + attribute_values = claims.map(&:eligibility).map(&attribute) + attribute_values.uniq.count > 1 && !attribute_values.all?(&:blank?) + } + + if mismatching_attributes.any? || mismatching_eligibility_attributes.any? claims_sentence = claims.map(&:reference).to_sentence - attributes_sentence = mismatching_attributes.map { |attribute| Claim.human_attribute_name(attribute).downcase }.to_sentence + attributes_list = mismatching_attributes.map { |attribute| Claim.human_attribute_name(attribute).downcase } + attributes_list += mismatching_eligibility_attributes.map { |attribute| claims.first.eligibility.class.human_attribute_name(attribute).downcase } + attributes_sentence = attributes_list.to_sentence + errors.add(:claims, "#{claims_sentence} have different values for #{attributes_sentence}") end end diff --git a/app/models/payroll_run.rb b/app/models/payroll_run.rb index ec658a4ce2..e40b085a05 100644 --- a/app/models/payroll_run.rb +++ b/app/models/payroll_run.rb @@ -48,7 +48,7 @@ def all_payments_confirmed? def self.create_with_claims!(claims, topups, attrs = {}) ActiveRecord::Base.transaction do PayrollRun.create!(attrs).tap do |payroll_run| - [claims, topups].reduce([], :concat).group_by(&:teacher_reference_number).each_value do |grouped_items| + [claims, topups].reduce([], :concat).group_by { |obj| group_by_field(obj) }.each_value do |grouped_items| # associates the claim to the payment, for Topup that's its associated claim grouped_claims = grouped_items.map { |i| i.is_a?(Topup) ? i.claim : i } @@ -62,6 +62,10 @@ def self.create_with_claims!(claims, topups, attrs = {}) end end + def self.group_by_field(obj) + obj.is_a?(Claim) ? obj.eligibility.teacher_reference_number : obj.teacher_reference_number + end + def download_triggered? downloaded_at.present? && downloaded_by.present? end diff --git a/app/models/policies.rb b/app/models/policies.rb index 9929012d76..c155fd43bf 100644 --- a/app/models/policies.rb +++ b/app/models/policies.rb @@ -7,7 +7,7 @@ module Policies AMENDABLE_ELIGIBILITY_ATTRIBUTES = POLICIES.map do |policy| policy::Eligibility::AMENDABLE_ATTRIBUTES - end.flatten.freeze + end.flatten.uniq.freeze def self.all POLICIES diff --git a/app/models/policies/early_career_payments.rb b/app/models/policies/early_career_payments.rb index 4147b7bc82..946a59b1c0 100644 --- a/app/models/policies/early_career_payments.rb +++ b/app/models/policies/early_career_payments.rb @@ -24,6 +24,18 @@ module EarlyCareerPayments POLICY_START_YEAR = AcademicYear.new(2021).freeze + # Used in + # - checking payments with multiple policies: ClaimsPreventingPaymentFinder + # - matching claims with multiple policies: MatchingAttributeFinder + OTHER_CLAIMABLE_POLICIES = [ + LevellingUpPremiumPayments, + StudentLoans + ].freeze + + ELIGIBILITY_MATCHING_ATTRIBUTES = [["teacher_reference_number"]].freeze + + SEARCHABLE_ELIGIBILITY_ATTRIBUTES = %w[teacher_reference_number].freeze + def eligibility_page_url "https://www.gov.uk/guidance/early-career-payments-guidance-for-teachers-and-schools" end diff --git a/app/models/policies/early_career_payments/eligibility.rb b/app/models/policies/early_career_payments/eligibility.rb index 0d54f9cdcd..b01583141e 100644 --- a/app/models/policies/early_career_payments/eligibility.rb +++ b/app/models/policies/early_career_payments/eligibility.rb @@ -1,11 +1,13 @@ module Policies module EarlyCareerPayments class Eligibility < ApplicationRecord + include TeacherReferenceNumberValidation + def policy Policies::EarlyCareerPayments end - AMENDABLE_ATTRIBUTES = [:award_amount].freeze + AMENDABLE_ATTRIBUTES = [:teacher_reference_number, :award_amount].freeze IGNORED_ATTRIBUTES = [ "eligible_degree_subject" @@ -58,10 +60,15 @@ def self.max_award_amount_in_pounds has_one :claim, as: :eligibility, inverse_of: :eligibility belongs_to :current_school, optional: true, class_name: "School" + before_validation :normalise_teacher_reference_number, if: :teacher_reference_number_changed? + validates :current_school, on: [:"correct-school"], presence: {message: "Select the school you teach at or choose somewhere else"}, unless: :school_somewhere_else? validates_numericality_of :award_amount, message: "Enter a valid monetary amount", allow_nil: true, greater_than_or_equal_to: 0, less_than_or_equal_to: 7500 validates :award_amount, on: :amendment, award_range: {max: max_award_amount_in_pounds} + validates :teacher_reference_number, on: :amendment, presence: {message: "Enter your teacher reference number"} + validate :validate_teacher_reference_number_length + delegate :name, to: :current_school, prefix: true, allow_nil: true delegate :academic_year, to: :claim diff --git a/app/models/policies/levelling_up_premium_payments.rb b/app/models/policies/levelling_up_premium_payments.rb index b7e62da6ce..57c9072399 100644 --- a/app/models/policies/levelling_up_premium_payments.rb +++ b/app/models/policies/levelling_up_premium_payments.rb @@ -12,6 +12,18 @@ module LevellingUpPremiumPayments AutomatedChecks::ClaimVerifiers::StudentLoanPlan ].freeze + # Used in + # - checking payments with multiple policies: ClaimsPreventingPaymentFinder + # - matching claims with multiple policies: MatchingAttributeFinder + OTHER_CLAIMABLE_POLICIES = [ + EarlyCareerPayments, + StudentLoans + ].freeze + + ELIGIBILITY_MATCHING_ATTRIBUTES = [["teacher_reference_number"]].freeze + + SEARCHABLE_ELIGIBILITY_ATTRIBUTES = %w[teacher_reference_number].freeze + def notify_reply_to_id "03ece7eb-2a5b-461b-9c91-6630d0051aa6" end diff --git a/app/models/policies/levelling_up_premium_payments/eligibility.rb b/app/models/policies/levelling_up_premium_payments/eligibility.rb index 65b3542219..042b95ba67 100644 --- a/app/models/policies/levelling_up_premium_payments/eligibility.rb +++ b/app/models/policies/levelling_up_premium_payments/eligibility.rb @@ -1,6 +1,8 @@ module Policies module LevellingUpPremiumPayments class Eligibility < ApplicationRecord + include TeacherReferenceNumberValidation + def policy Policies::LevellingUpPremiumPayments end @@ -11,11 +13,15 @@ def policy has_one :claim, as: :eligibility, inverse_of: :eligibility belongs_to :current_school, optional: true, class_name: "School" + before_validation :normalise_teacher_reference_number, if: :teacher_reference_number_changed? + validate :award_amount_must_be_in_range, on: :amendment + validates :teacher_reference_number, on: :amendment, presence: {message: "Enter your teacher reference number"} + validate :validate_teacher_reference_number_length delegate :name, to: :current_school, prefix: true, allow_nil: true - AMENDABLE_ATTRIBUTES = [:award_amount].freeze + AMENDABLE_ATTRIBUTES = [:teacher_reference_number, :award_amount].freeze FIRST_ITT_AY = "2017/2018" LAST_POLICY_YEAR = "2024/2025" diff --git a/app/models/policies/student_loans.rb b/app/models/policies/student_loans.rb index e3f6294af1..a39eda968a 100644 --- a/app/models/policies/student_loans.rb +++ b/app/models/policies/student_loans.rb @@ -25,6 +25,18 @@ module StudentLoans POLICY_END_YEAR = AcademicYear.new(2020).freeze ACADEMIC_YEARS_QUALIFIED_TEACHERS_CAN_CLAIM_FOR = 11 + # Used in + # - checking payments with multiple policies: ClaimsPreventingPaymentFinder + # - matching claims with multiple policies: MatchingAttributeFinder + OTHER_CLAIMABLE_POLICIES = [ + EarlyCareerPayments, + LevellingUpPremiumPayments + ] + + ELIGIBILITY_MATCHING_ATTRIBUTES = [["teacher_reference_number"]].freeze + + SEARCHABLE_ELIGIBILITY_ATTRIBUTES = %w[teacher_reference_number].freeze + def eligibility_page_url "https://www.gov.uk/guidance/teachers-claim-back-your-student-loan-repayments" end diff --git a/app/models/policies/student_loans/eligibility.rb b/app/models/policies/student_loans/eligibility.rb index 4d701cb2e5..7b366caef3 100644 --- a/app/models/policies/student_loans/eligibility.rb +++ b/app/models/policies/student_loans/eligibility.rb @@ -3,6 +3,8 @@ module Policies module StudentLoans class Eligibility < ApplicationRecord + include TeacherReferenceNumberValidation + SUBJECT_ATTRIBUTES = [ :biology_taught, :chemistry_taught, @@ -10,7 +12,7 @@ class Eligibility < ApplicationRecord :computing_taught, :languages_taught ].freeze - AMENDABLE_ATTRIBUTES = %i[student_loan_repayment_amount].freeze + AMENDABLE_ATTRIBUTES = %i[teacher_reference_number student_loan_repayment_amount].freeze self.table_name = "student_loans_eligibilities" @@ -34,12 +36,16 @@ class Eligibility < ApplicationRecord belongs_to :claim_school, optional: true, class_name: "School" belongs_to :current_school, optional: true, class_name: "School" + before_validation :normalise_teacher_reference_number, if: :teacher_reference_number_changed? + validates :claim_school, on: [:"select-claim-school"], presence: {message: ->(object, _data) { object.select_claim_school_presence_error_message }}, unless: :claim_school_somewhere_else? validates :employment_status, on: [:submit], presence: {message: ->(object, _data) { "Select if you still work at #{object.claim_school_name}, another school or no longer teach in England" }} validates :had_leadership_position, on: [:submit], inclusion: {in: [true, false], message: "Select yes if you were employed in a leadership position"} validates :mostly_performed_leadership_duties, on: [:submit], inclusion: {in: [true, false], message: "Select yes if you spent more than half your working hours on leadership duties"}, if: :had_leadership_position? validates_numericality_of :student_loan_repayment_amount, message: "Enter a valid monetary amount", allow_nil: true, greater_than_or_equal_to: 0, less_than_or_equal_to: 99999 validates :student_loan_repayment_amount, on: :amendment, award_range: {max: 5_000} + validates :teacher_reference_number, on: :amendment, presence: {message: "Enter your teacher reference number"} + validate :validate_teacher_reference_number_length delegate :name, to: :claim_school, prefix: true, allow_nil: true delegate :name, to: :current_school, prefix: true, allow_nil: true diff --git a/app/models/school_workforce_census_data_importer.rb b/app/models/school_workforce_census_data_importer.rb index 528db56cd1..b414893d2c 100644 --- a/app/models/school_workforce_census_data_importer.rb +++ b/app/models/school_workforce_census_data_importer.rb @@ -1,5 +1,5 @@ class SchoolWorkforceCensusDataImporter < CsvImporter::Base - include ::TrnValidation + include ::TeacherReferenceNumberValidation import_options( target_data_model: SchoolWorkforceCensus, @@ -11,12 +11,12 @@ class SchoolWorkforceCensusDataImporter < CsvImporter::Base private def skip_row_conditions?(row) - row[0].blank? || row[4] == "NULL" || row[0] == "NULL" || !valid_trn?(row[0]) + row[0].blank? || row[4] == "NULL" || row[0] == "NULL" || !valid_teacher_reference_number?(row[0]) end - def valid_trn?(trn) - normalize_teacher_reference_number(trn) - valid_trn_length?(trn) + def valid_teacher_reference_number?(trn) + normalised_teacher_reference_number(trn) + valid_teacher_reference_number_length_for_school_workforce_census?(trn) end def row_to_hash(row) diff --git a/app/models/topup.rb b/app/models/topup.rb index b185f8b460..dc746d2a19 100644 --- a/app/models/topup.rb +++ b/app/models/topup.rb @@ -10,12 +10,14 @@ class Topup < ApplicationRecord validates :award_amount, presence: {message: "Enter top up amount"} validate :award_amount_must_be_in_range, on: :create - delegate :teacher_reference_number, to: :claim - def payrolled? payment.present? end + def teacher_reference_number + claim.eligibility.teacher_reference_number + end + private def award_amount_must_be_in_range diff --git a/app/views/admin/amendments/new.html.erb b/app/views/admin/amendments/new.html.erb index 1bf404a300..eab90c3541 100644 --- a/app/views/admin/amendments/new.html.erb +++ b/app/views/admin/amendments/new.html.erb @@ -19,19 +19,21 @@ <%= form_with model: @amendment, url: admin_claim_amendments_path(@claim), html: { autocomplete: "off" } do |f| %> <%= f.fields_for :claim, @amendment.claim do |claim_form| %> -
-
- <%= form_group_tag(@amendment, :teacher_reference_number) do %> - <%= claim_form.label :teacher_reference_number, class: "govuk-label" %> - <%= errors_tag @amendment, :teacher_reference_number %> - <% end %> -
-
-
- <%= claim_form.text_field :teacher_reference_number, class: "govuk-input govuk-input--width-10" %> + <%= claim_form.fields_for :eligibility, @amendment.claim.eligibility, include_id: false do |eligibility_form| %> +
+
+ <%= form_group_tag(@amendment.claim.eligibility, :teacher_reference_number) do %> + <%= eligibility_form.label :teacher_reference_number, class: "govuk-label" %> + <%= errors_tag @amendment.claim.eligibility, :teacher_reference_number %> + <% end %> +
+
+
+ <%= eligibility_form.text_field(:teacher_reference_number, class: "govuk-input govuk-input--width-10") %> +
-
+ <% end %>
diff --git a/app/views/admin/tasks/_claim_summary.html.erb b/app/views/admin/tasks/_claim_summary.html.erb index 9da8f08daf..6197d0c2b5 100644 --- a/app/views/admin/tasks/_claim_summary.html.erb +++ b/app/views/admin/tasks/_claim_summary.html.erb @@ -26,7 +26,7 @@
- <%= claim.teacher_reference_number %> + <%= claim.eligibility.teacher_reference_number %>
diff --git a/config/analytics_blocklist.yml b/config/analytics_blocklist.yml index f50bb151b0..e353302397 100644 --- a/config/analytics_blocklist.yml +++ b/config/analytics_blocklist.yml @@ -19,7 +19,7 @@ - building_society_roll_number - banking_name - mobile_number - - teacher_reference_number + - column_to_remove_teacher_reference_number - email_address - payroll_gender - one_time_password @@ -98,4 +98,9 @@ - gender_digit :international_relocation_payments_eligibilities: - passport_number - + :levelling_up_premium_payments_eligibilities: + - teacher_reference_number + :early_career_payments_eligibilities: + - teacher_reference_number + :student_loans_eligibilities: + - teacher_reference_number diff --git a/config/brakeman.ignore b/config/brakeman.ignore index 4bf570841b..1e49f435ac 100644 --- a/config/brakeman.ignore +++ b/config/brakeman.ignore @@ -30,7 +30,7 @@ "check_name": "SQL", "message": "Possible SQL injection", "file": "app/models/claim/search.rb", - "line": 28, + "line": 45, "link": "https://brakemanscanner.org/docs/warning_types/sql_injection/", "code": "Claim.submitted.where(\"LOWER(#{attribute}) = LOWER(?)\", search_term)", "render_path": null, @@ -118,13 +118,13 @@ { "warning_type": "SQL Injection", "warning_code": 0, - "fingerprint": "aac74520956533997d73d1c601c2bcde5d3cd501f14401fb9cb8e2bfdc7862fa", + "fingerprint": "f83635b54e1ce0088178d8082ffe632ab8aa81b10fce1026caf87f286cb4d81a", "check_name": "SQL", "message": "Possible SQL injection", "file": "app/models/claim/matching_attribute_finder.rb", - "line": 31, + "line": 54, "link": "https://brakemanscanner.org/docs/warning_types/sql_injection/", - "code": "Claim.where(\"LOWER(#{\"CONCAT(#{attributes.join(\",\")})\"}) = LOWER(?)\", values_for_attributes(attributes).join)", + "code": "Claim.where(\"LOWER(#{\"CONCAT(#{attributes.join(\",\")})\"}) = LOWER(?)\", values_for_attributes(source_claim, attributes).join)", "render_path": null, "location": { "type": "method", @@ -136,55 +136,9 @@ "cwe_id": [ 89 ], - "note": "The concetenated attributes in the CONCAT operation are not user-generated, so this can be safely ignored" - }, - { - "warning_type": "Redirect", - "warning_code": 18, - "fingerprint": "b838db1b7beff28cdeff71a154a46d7c57062fb11aebf82f0487a9991445bea5", - "check_name": "Redirect", - "message": "Possible unprotected redirect", - "file": "app/controllers/concerns/part_of_claim_journey.rb", - "line": 25, - "link": "https://brakemanscanner.org/docs/warning_types/redirect/", - "code": "redirect_to(Journeys::Configuration.start_page_url(current_journey_routing_name), :allow_other_host => true)", - "render_path": null, - "location": { - "type": "method", - "class": "PartOfClaimJourney", - "method": "send_unstarted_claimants_to_the_start" - }, - "user_input": "Journeys::Configuration.start_page_url(current_journey_routing_name)", - "confidence": "Weak", - "cwe_id": [ - 601 - ], - "note": "" - }, - { - "warning_type": "Redirect", - "warning_code": 18, - "fingerprint": "d7efbb65a649f824e34aa86f2d844a9d5ffac945eea04198f59418ac1998721c", - "check_name": "Redirect", - "message": "Possible unprotected redirect", - "file": "app/controllers/submissions_controller.rb", - "line": 22, - "link": "https://brakemanscanner.org/docs/warning_types/redirect/", - "code": "redirect_to(Journeys::Configuration.start_page_url(current_journey_routing_name), :allow_other_host => true)", - "render_path": null, - "location": { - "type": "method", - "class": "SubmissionsController", - "method": "show" - }, - "user_input": "Journeys::Configuration.start_page_url(current_journey_routing_name)", - "confidence": "Weak", - "cwe_id": [ - 601 - ], "note": "" } ], - "updated": "2024-03-07 12:34:07 +0000", + "updated": "2024-06-20 16:06:05 +0100", "brakeman_version": "6.1.2" } diff --git a/db/migrate/20240511100914_move_teacher_reference_number_to_eligibility.rb b/db/migrate/20240511100914_move_teacher_reference_number_to_eligibility.rb new file mode 100644 index 0000000000..557ac81636 --- /dev/null +++ b/db/migrate/20240511100914_move_teacher_reference_number_to_eligibility.rb @@ -0,0 +1,19 @@ +class MoveTeacherReferenceNumberToEligibility < ActiveRecord::Migration[7.0] + def change + add_column :early_career_payments_eligibilities, :teacher_reference_number, :string, limit: 11 + add_column :levelling_up_premium_payments_eligibilities, :teacher_reference_number, :string, limit: 11 + add_column :student_loans_eligibilities, :teacher_reference_number, :string, limit: 11 + + add_index :early_career_payments_eligibilities, :teacher_reference_number, name: "index_ecp_eligibility_trn" + add_index :levelling_up_premium_payments_eligibilities, :teacher_reference_number, name: "index_lupp_eligibility_trn" + add_index :student_loans_eligibilities, :teacher_reference_number, name: "index_sl_eligibility_trn" + + # Copy teacher_reference_number from Claim to Eligibility + Claim.all.includes(:eligibility).each do |claim| + claim.eligibility.update!(teacher_reference_number: claim.teacher_reference_number) + end + + # Keep the old column but rename it so it's not accidentally used, needs removing soon after migration is successful + rename_column :claims, :teacher_reference_number, :column_to_remove_teacher_reference_number + end +end diff --git a/db/schema.rb b/db/schema.rb index 2bbacefc1c..2db075d1f0 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -49,7 +49,7 @@ t.string "address_line_4", limit: 100 t.string "postcode", limit: 11 t.date "date_of_birth" - t.string "teacher_reference_number", limit: 11 + t.string "column_to_remove_teacher_reference_number", limit: 11 t.string "national_insurance_number", limit: 9 t.string "email_address", limit: 256 t.string "bank_sort_code", limit: 6 @@ -170,7 +170,9 @@ t.decimal "award_amount", precision: 7, scale: 2 t.boolean "induction_completed" t.boolean "school_somewhere_else" + t.string "teacher_reference_number", limit: 11 t.index ["current_school_id"], name: "index_early_career_payments_eligibilities_on_current_school_id" + t.index ["teacher_reference_number"], name: "index_ecp_eligibility_trn" end create_table "file_uploads", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| @@ -246,7 +248,9 @@ t.boolean "eligible_degree_subject" t.boolean "induction_completed" t.boolean "school_somewhere_else" + t.string "teacher_reference_number", limit: 11 t.index ["current_school_id"], name: "index_lup_payments_eligibilities_on_current_school_id" + t.index ["teacher_reference_number"], name: "index_lupp_eligibility_trn" end create_table "local_authorities", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| @@ -406,9 +410,11 @@ t.boolean "had_leadership_position" t.boolean "mostly_performed_leadership_duties" t.boolean "claim_school_somewhere_else" + t.string "teacher_reference_number", limit: 11 t.index ["claim_school_id"], name: "index_student_loans_eligibilities_on_claim_school_id" t.index ["created_at"], name: "index_student_loans_eligibilities_on_created_at" t.index ["current_school_id"], name: "index_student_loans_eligibilities_on_current_school_id" + t.index ["teacher_reference_number"], name: "index_sl_eligibility_trn" end create_table "support_tickets", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| diff --git a/spec/factories/amendments.rb b/spec/factories/amendments.rb index e1ba30273b..0abe1b5004 100644 --- a/spec/factories/amendments.rb +++ b/spec/factories/amendments.rb @@ -2,12 +2,12 @@ factory :amendment do association :claim, factory: [:claim, :submitted] association :created_by, factory: :dfe_signin_user - claim_changes { {"teacher_reference_number" => [generate(:teacher_reference_number).to_s, claim.teacher_reference_number]} } + claim_changes { {"teacher_reference_number" => [generate(:teacher_reference_number).to_s, claim.eligibility.teacher_reference_number]} } notes { "We couldn’t find the teacher in Teacher Pensions Service data. We contacted them in Zendesk and they told us they made a typo and gave their correct TRN" } trait :personal_data_removed do personal_data_removed_at { Time.zone.now } - claim_changes { {"teacher_reference_number" => [generate(:teacher_reference_number).to_s, claim.teacher_reference_number], "bank_account_number" => nil} } + claim_changes { {"teacher_reference_number" => [generate(:teacher_reference_number).to_s, claim.eligibility.teacher_reference_number], "bank_account_number" => nil} } end end end diff --git a/spec/factories/claims.rb b/spec/factories/claims.rb index 71ee639506..22579f1c9a 100644 --- a/spec/factories/claims.rb +++ b/spec/factories/claims.rb @@ -39,7 +39,6 @@ trait :with_details_from_dfe_identity do first_name { "Jo" } surname { "Bloggs" } - teacher_reference_number { generate(:teacher_reference_number) } date_of_birth { 20.years.ago.to_date } national_insurance_number { generate(:national_insurance_number) } end diff --git a/spec/factories/early_career_payments/eligibilities.rb b/spec/factories/early_career_payments/eligibilities.rb index 269b369b67..dfcccd38df 100644 --- a/spec/factories/early_career_payments/eligibilities.rb +++ b/spec/factories/early_career_payments/eligibilities.rb @@ -3,6 +3,7 @@ award_amount { 5000.0 } trait :eligible do + teacher_reference_number { generate(:teacher_reference_number) } eligible_now end diff --git a/spec/factories/levelling_up_premium_payments/eligibilities.rb b/spec/factories/levelling_up_premium_payments/eligibilities.rb index f9e81c8a55..e387e12253 100644 --- a/spec/factories/levelling_up_premium_payments/eligibilities.rb +++ b/spec/factories/levelling_up_premium_payments/eligibilities.rb @@ -2,7 +2,8 @@ factory :levelling_up_premium_payments_eligibility, class: "Policies::LevellingUpPremiumPayments::Eligibility" do award_amount { 2000.0 } - trait :eligible do # TODO rename + trait :eligible do + teacher_reference_number { generate(:teacher_reference_number) } eligible_now end diff --git a/spec/factories/payments.rb b/spec/factories/payments.rb index e866c32dc3..991361a4d9 100644 --- a/spec/factories/payments.rb +++ b/spec/factories/payments.rb @@ -7,10 +7,10 @@ claims do personal_details = { national_insurance_number: generate(:national_insurance_number), - teacher_reference_number: generate(:teacher_reference_number), email_address: "email@example.com", bank_sort_code: "220011", - bank_account_number: "12345678" + bank_account_number: "12345678", + eligibility_attributes: {teacher_reference_number: generate(:teacher_reference_number)} } claim_policies.map do |policy| association(:claim, :approved, personal_details.merge(policy: policy)) diff --git a/spec/factories/student_loans/eligibilities.rb b/spec/factories/student_loans/eligibilities.rb index 95e5a21523..bdb969d62b 100644 --- a/spec/factories/student_loans/eligibilities.rb +++ b/spec/factories/student_loans/eligibilities.rb @@ -11,6 +11,7 @@ had_leadership_position { true } mostly_performed_leadership_duties { false } student_loan_repayment_amount { 1000 } + teacher_reference_number { generate(:teacher_reference_number) } end trait :ineligible do diff --git a/spec/features/admin_amend_claim_spec.rb b/spec/features/admin_amend_claim_spec.rb index 872e13534b..5323c37668 100644 --- a/spec/features/admin_amend_claim_spec.rb +++ b/spec/features/admin_amend_claim_spec.rb @@ -8,7 +8,7 @@ RSpec.feature "Admin amends a claim" do let(:claim) do create(:claim, :submitted, - teacher_reference_number: "1234567", + eligibility_attributes: {teacher_reference_number: "1234567"}, payroll_gender: :dont_know, date_of_birth: date_of_birth, student_loan_plan: :plan_1, @@ -57,7 +57,7 @@ expect(amendment.notes).to eq("This claimant got some of their details wrong and then contacted us") expect(amendment.created_by).to eq(@signed_in_user) - expect(claim.reload.teacher_reference_number).to eq("7654321") + expect(claim.eligibility.reload.teacher_reference_number).to eq("7654321") expect(claim.date_of_birth).to eq(new_date_of_birth) expect(claim.student_loan_plan).to eq("plan_2") expect(claim.bank_sort_code).to eq("111213") @@ -88,7 +88,7 @@ fill_in "Teacher reference number", with: "7654321" - expect { click_on "Cancel" }.not_to change { [claim.reload.amendments.size, claim.teacher_reference_number] } + expect { click_on "Cancel" }.not_to change { [claim.reload.amendments.size, claim.eligibility.teacher_reference_number] } expect(current_url).to eq(admin_claim_tasks_url(claim)) end diff --git a/spec/features/admin_claim_tasks_update_with_dqt_api_spec.rb b/spec/features/admin_claim_tasks_update_with_dqt_api_spec.rb index c06d689435..77639b8b7f 100644 --- a/spec/features/admin_claim_tasks_update_with_dqt_api_spec.rb +++ b/spec/features/admin_claim_tasks_update_with_dqt_api_spec.rb @@ -110,7 +110,7 @@ def task_outcome status = 200 end - stub_request(:get, "#{ENV["DQT_API_URL"]}teachers/#{claim.teacher_reference_number}") + stub_request(:get, "#{ENV["DQT_API_URL"]}teachers/#{claim.eligibility.teacher_reference_number}") .with(query: WebMock::API.hash_including({ birthdate: claim.date_of_birth.to_s, nino: claim.national_insurance_number @@ -173,7 +173,7 @@ def task_outcome date_of_birth: claim.date_of_birth, name: "#{claim.first_name} #{claim.surname}", national_insurance_number: claim.national_insurance_number, - teacher_reference_number: claim.teacher_reference_number + teacher_reference_number: claim.eligibility.teacher_reference_number } end @@ -211,7 +211,7 @@ def task_outcome date_of_birth: claim.date_of_birth, name: "#{claim.first_name} #{claim.surname}", national_insurance_number: "QQ100000B", - teacher_reference_number: claim.teacher_reference_number + teacher_reference_number: claim.eligibility.teacher_reference_number } end @@ -290,7 +290,7 @@ def task_outcome scenario "shows the notes added as part of automated identity checking" do expect(notes).to include( have_text("Teacher reference number not matched").and( - have_text("Claimant: \"#{claim.teacher_reference_number}\"").and( + have_text("Claimant: \"#{claim.eligibility.teacher_reference_number}\"").and( have_text("DQT: \"7654321\"").and( have_text("by an automated check") ) @@ -319,7 +319,7 @@ def task_outcome date_of_birth: claim.date_of_birth, name: "Except #{claim.surname}", national_insurance_number: claim.national_insurance_number, - teacher_reference_number: claim.teacher_reference_number + teacher_reference_number: claim.eligibility.teacher_reference_number } end @@ -375,7 +375,7 @@ def task_outcome date_of_birth: claim.date_of_birth, name: "#{claim.first_name} Except", national_insurance_number: claim.national_insurance_number, - teacher_reference_number: claim.teacher_reference_number + teacher_reference_number: claim.eligibility.teacher_reference_number } end @@ -431,7 +431,7 @@ def task_outcome date_of_birth: claim.date_of_birth, name: "#{claim.first_name} Middle Names #{claim.surname}", national_insurance_number: claim.national_insurance_number, - teacher_reference_number: claim.teacher_reference_number + teacher_reference_number: claim.eligibility.teacher_reference_number } end @@ -470,7 +470,7 @@ def task_outcome date_of_birth: claim.date_of_birth + 1.day, name: "#{claim.first_name} #{claim.surname}", national_insurance_number: claim.national_insurance_number, - teacher_reference_number: claim.teacher_reference_number + teacher_reference_number: claim.eligibility.teacher_reference_number } end @@ -568,7 +568,7 @@ def task_outcome date_of_birth: claim.date_of_birth, name: "#{claim.first_name} #{claim.surname}", national_insurance_number: claim.national_insurance_number, - teacher_reference_number: claim.teacher_reference_number + teacher_reference_number: claim.eligibility.teacher_reference_number } end @@ -626,7 +626,7 @@ def task_outcome date_of_birth: claim.date_of_birth + 1.day, name: "Except #{claim.surname}", national_insurance_number: claim.national_insurance_number, - teacher_reference_number: claim.teacher_reference_number + teacher_reference_number: claim.eligibility.teacher_reference_number } end @@ -1008,7 +1008,7 @@ def task_outcome date_of_birth: claim.date_of_birth, name: "#{claim.first_name} #{claim.surname}", national_insurance_number: claim.national_insurance_number, - teacher_reference_number: claim.teacher_reference_number + teacher_reference_number: claim.eligibility.teacher_reference_number } end @@ -1046,7 +1046,7 @@ def task_outcome date_of_birth: claim.date_of_birth, name: "#{claim.first_name} #{claim.surname}", national_insurance_number: "QQ100000B", - teacher_reference_number: claim.teacher_reference_number + teacher_reference_number: claim.eligibility.teacher_reference_number } end @@ -1125,7 +1125,7 @@ def task_outcome scenario "shows the notes added as part of automated identity checking" do expect(notes).to include( have_text("Teacher reference number not matched").and( - have_text("Claimant: \"#{claim.teacher_reference_number}\"").and( + have_text("Claimant: \"#{claim.eligibility.teacher_reference_number}\"").and( have_text("DQT: \"7654321\"").and( have_text("by an automated check") ) @@ -1154,7 +1154,7 @@ def task_outcome date_of_birth: claim.date_of_birth, name: "Except #{claim.surname}", national_insurance_number: claim.national_insurance_number, - teacher_reference_number: claim.teacher_reference_number + teacher_reference_number: claim.eligibility.teacher_reference_number } end @@ -1210,7 +1210,7 @@ def task_outcome date_of_birth: claim.date_of_birth, name: "#{claim.first_name} Except", national_insurance_number: claim.national_insurance_number, - teacher_reference_number: claim.teacher_reference_number + teacher_reference_number: claim.eligibility.teacher_reference_number } end @@ -1270,7 +1270,7 @@ def task_outcome date_of_birth: claim.date_of_birth, name: "#{claim.first_name} Middle Names #{claim.surname}", national_insurance_number: claim.national_insurance_number, - teacher_reference_number: claim.teacher_reference_number + teacher_reference_number: claim.eligibility.teacher_reference_number } end @@ -1309,7 +1309,7 @@ def task_outcome date_of_birth: claim.date_of_birth + 1.day, name: "#{claim.first_name} #{claim.surname}", national_insurance_number: claim.national_insurance_number, - teacher_reference_number: claim.teacher_reference_number + teacher_reference_number: claim.eligibility.teacher_reference_number } end @@ -1407,7 +1407,7 @@ def task_outcome date_of_birth: claim.date_of_birth, name: "#{claim.first_name} #{claim.surname}", national_insurance_number: claim.national_insurance_number, - teacher_reference_number: claim.teacher_reference_number + teacher_reference_number: claim.eligibility.teacher_reference_number } end @@ -1461,7 +1461,7 @@ def task_outcome date_of_birth: claim.date_of_birth + 1.day, name: "Except #{claim.surname}", national_insurance_number: claim.national_insurance_number, - teacher_reference_number: claim.teacher_reference_number + teacher_reference_number: claim.eligibility.teacher_reference_number } end diff --git a/spec/features/admin_claim_with_inconsistent_payroll_information_spec.rb b/spec/features/admin_claim_with_inconsistent_payroll_information_spec.rb index 8763cd636c..e4c343df56 100644 --- a/spec/features/admin_claim_with_inconsistent_payroll_information_spec.rb +++ b/spec/features/admin_claim_with_inconsistent_payroll_information_spec.rb @@ -4,7 +4,7 @@ let(:personal_details) do { national_insurance_number: generate(:national_insurance_number), - teacher_reference_number: generate(:teacher_reference_number), + eligibility_attributes: {teacher_reference_number: generate(:teacher_reference_number)}, date_of_birth: 30.years.ago.to_date, student_loan_plan: StudentLoan::PLAN_1, email_address: "email@example.com", diff --git a/spec/features/admin_claim_with_matching_details_spec.rb b/spec/features/admin_claim_with_matching_details_spec.rb index c77a32b59c..bb2220b9f5 100644 --- a/spec/features/admin_claim_with_matching_details_spec.rb +++ b/spec/features/admin_claim_with_matching_details_spec.rb @@ -9,7 +9,7 @@ scenario "service operator can check a claim with matching details" do claim = create(:claim, :submitted, policy: Policies::StudentLoans) - claim_with_matching_details = create(:claim, :submitted, teacher_reference_number: claim.teacher_reference_number) + claim_with_matching_details = create(:claim, :submitted, eligibility_attributes: {teacher_reference_number: claim.eligibility.teacher_reference_number}) click_on "View claims" find("a[href='#{admin_claim_tasks_path(claim)}']").click diff --git a/spec/features/admin_data_report_request_spec.rb b/spec/features/admin_data_report_request_spec.rb index 4453b1b065..c34b3300a4 100644 --- a/spec/features/admin_data_report_request_spec.rb +++ b/spec/features/admin_data_report_request_spec.rb @@ -32,7 +32,7 @@ csv.each_with_index do |row, i| claim = claims.detect { |c| c.reference == row["Claim reference"] } expect(claim).not_to be_nil - expect(row["Teacher reference number"]).to eq(claim.teacher_reference_number) + expect(row["Teacher reference number"]).to eq(claim.eligibility.teacher_reference_number) expect(row["NINO"]).to eq(claim.national_insurance_number) expect(row["Full name"]).to eq(claim.full_name) expect(row["Email"]).to eq(claim.email_address) diff --git a/spec/features/admin_search_spec.rb b/spec/features/admin_search_spec.rb index 0a5b5f8735..98d61a1af5 100644 --- a/spec/features/admin_search_spec.rb +++ b/spec/features/admin_search_spec.rb @@ -18,7 +18,7 @@ expect(page).to have_content(claim1.reference) expect(page).to have_no_content(claim2.reference) - expect(page).to have_content(claim1.teacher_reference_number) + expect(page).to have_content(claim1.eligibility.teacher_reference_number) expect(page).to have_content(claim1.policy.short_name) end @@ -35,7 +35,7 @@ expect(page).to have_content(claim1.reference) expect(page).to have_no_content(claim2.reference) - expect(page).to have_content(claim1.teacher_reference_number) + expect(page).to have_content(claim1.eligibility.teacher_reference_number) expect(page).to have_content(claim1.policy.short_name) end diff --git a/spec/features/early_career_payments_claim_spec.rb b/spec/features/early_career_payments_claim_spec.rb index 547d2a803e..75d65d87b5 100644 --- a/spec/features/early_career_payments_claim_spec.rb +++ b/spec/features/early_career_payments_claim_spec.rb @@ -246,7 +246,7 @@ expect(claim.bank_sort_code).to eq("123456") expect(claim.bank_account_number).to eq("87654321") expect(claim.payroll_gender).to eq("female") - expect(claim.teacher_reference_number).to eq("1234567") + expect(claim.eligibility.teacher_reference_number).to eq("1234567") expect(claim.reload.submitted_at).to eq(Time.zone.now) policy_options_provided = [ {"policy" => "EarlyCareerPayments", "award_amount" => "5000.0"}, @@ -655,7 +655,7 @@ expect(claim.bank_sort_code).to eq("123456") expect(claim.bank_account_number).to eq("87654321") expect(claim.payroll_gender).to eq("female") - expect(claim.teacher_reference_number).to eql("1234567") + expect(claim.eligibility.teacher_reference_number).to eql("1234567") expect(claim.submitted_at).to eq(Time.zone.now) policy_options_provided = [ {"policy" => "EarlyCareerPayments", "award_amount" => "5000.0"}, @@ -965,7 +965,7 @@ expect(submitted_claim.bank_sort_code).to eq("123456") expect(submitted_claim.bank_account_number).to eq("87654321") expect(submitted_claim.payroll_gender).to eq("female") - expect(submitted_claim.teacher_reference_number).to eql("1234567") + expect(submitted_claim.eligibility.teacher_reference_number).to eql("1234567") expect(submitted_claim.submitted_at).to eq(Time.zone.now) policy_options_provided = [ diff --git a/spec/features/levelling_up_premium_payments_spec.rb b/spec/features/levelling_up_premium_payments_spec.rb index 9ae995d42a..9e716ec98f 100644 --- a/spec/features/levelling_up_premium_payments_spec.rb +++ b/spec/features/levelling_up_premium_payments_spec.rb @@ -251,7 +251,7 @@ def submit_application expect(submitted_claim.bank_sort_code).to eq("123456") expect(submitted_claim.bank_account_number).to eq("87654321") expect(submitted_claim.payroll_gender).to eq("female") - expect(submitted_claim.teacher_reference_number).to eql("1234567") + expect(submitted_claim.eligibility.teacher_reference_number).to eql("1234567") # - Application complete (make sure its Word for Word and styling matches) expect(page).to have_text("You applied for a levelling up premium payment") diff --git a/spec/helpers/admin/claims_helper_spec.rb b/spec/helpers/admin/claims_helper_spec.rb index 12add2e93e..432dfb5ae7 100644 --- a/spec/helpers/admin/claims_helper_spec.rb +++ b/spec/helpers/admin/claims_helper_spec.rb @@ -10,14 +10,14 @@ :claim, first_name: "Bruce", surname: "Wayne", - teacher_reference_number: "1234567", national_insurance_number: "QQ123456C", email_address: "test@email.com", address_line_1: "Flat 1", address_line_2: "1 Test Road", address_line_3: "Test Town", postcode: "AB1 2CD", - date_of_birth: Date.new(1901, 1, 1) + date_of_birth: Date.new(1901, 1, 1), + eligibility_attributes: {teacher_reference_number: "1234567"} ) end @@ -35,7 +35,7 @@ end context "when a claim has had personal data deleted" do - let(:claim) { build(:claim, :rejected, :personal_data_removed, teacher_reference_number: "1234567", email_address: "test@email.com") } + let(:claim) { build(:claim, :rejected, :personal_data_removed, eligibility_attributes: {teacher_reference_number: "1234567"}, email_address: "test@email.com") } it "returns the expected strings" do expected_answers = [ @@ -176,23 +176,23 @@ let(:first_claim) { build( :claim, - teacher_reference_number: "0902344", national_insurance_number: "QQ891011C", email_address: "genghis.khan@mongol-empire.com", bank_account_number: "34682151", bank_sort_code: "972654", - building_society_roll_number: "123456789/ABCD" + building_society_roll_number: "123456789/ABCD", + eligibility_attributes: {teacher_reference_number: "0902344"} ) } let(:second_claim) { build( :claim, :submitted, - teacher_reference_number: first_claim.teacher_reference_number, national_insurance_number: first_claim.national_insurance_number, bank_account_number: first_claim.bank_account_number, bank_sort_code: first_claim.bank_sort_code, - building_society_roll_number: first_claim.building_society_roll_number + building_society_roll_number: first_claim.building_society_roll_number, + eligibility_attributes: {teacher_reference_number: first_claim.eligibility.teacher_reference_number} ) } subject { helper.matching_attributes(first_claim, second_claim) } diff --git a/spec/jobs/qualifications_no_match_check_job_spec.rb b/spec/jobs/qualifications_no_match_check_job_spec.rb index 0e81933d01..78868de968 100644 --- a/spec/jobs/qualifications_no_match_check_job_spec.rb +++ b/spec/jobs/qualifications_no_match_check_job_spec.rb @@ -3,7 +3,7 @@ RSpec.describe QualificationsNoMatchCheckJob do before do stub_qualified_teaching_statuses_show( - trn: claim.teacher_reference_number, + trn: claim.eligibility.teacher_reference_number, params: { birthdate: claim.date_of_birth&.to_s, nino: claim.national_insurance_number diff --git a/spec/mailers/payment_mailer_spec.rb b/spec/mailers/payment_mailer_spec.rb index de81bcf57c..90e3f04de0 100644 --- a/spec/mailers/payment_mailer_spec.rb +++ b/spec/mailers/payment_mailer_spec.rb @@ -96,18 +96,17 @@ context "with a payment with multiple claims" do describe "#confirmation" do let(:payment) { create(:payment, :confirmed, :with_figures, net_pay: 2500.00, student_loan_repayment: 60, claims: claims, scheduled_payment_date: Date.parse("2019-01-01")) } - let(:student_loans_eligibility) { build(:student_loans_eligibility, :eligible, student_loan_repayment_amount: 500) } + let(:teacher_reference_number) { "1234567" } let(:claims) do personal_details = { national_insurance_number: "JM603818B", - teacher_reference_number: "1234567", bank_sort_code: "112233", bank_account_number: "95928482", building_society_roll_number: nil } [ - build(:claim, :approved, personal_details.merge(eligibility: student_loans_eligibility)), - build(:claim, :approved, personal_details.merge(policy: Policies::EarlyCareerPayments)) + build(:claim, :approved, personal_details.merge(eligibility_attributes: {student_loan_repayment_amount: 500, teacher_reference_number: teacher_reference_number})), + build(:claim, :approved, personal_details.merge(policy: Policies::EarlyCareerPayments, eligibility_attributes: {teacher_reference_number: teacher_reference_number})) ] end let(:mail) { PaymentMailer.confirmation(payment) } diff --git a/spec/models/amendment_spec.rb b/spec/models/amendment_spec.rb index 7bc5388869..17d11794d0 100644 --- a/spec/models/amendment_spec.rb +++ b/spec/models/amendment_spec.rb @@ -33,7 +33,7 @@ let(:claim) { create(:claim, :submitted, - teacher_reference_number: "1234567", + eligibility_attributes: {teacher_reference_number: "1234567"}, bank_sort_code: "111213", bank_account_number: "12345678", building_society_roll_number: nil, @@ -45,7 +45,7 @@ context "given valid claim attributes and valid amendment attributes" do let(:claim_attributes) do { - teacher_reference_number: "7654321", + eligibility_attributes: {teacher_reference_number: "7654321"}, bank_account_number: "87654321" } end @@ -66,7 +66,7 @@ expect(amendment.created_by).to eq(dfe_signin_user) expect(claim.reload.amendments).to eq([amendment]) - expect(claim.teacher_reference_number).to eq("7654321") + expect(claim.eligibility.teacher_reference_number).to eq("7654321") expect(claim.bank_account_number).to eq("87654321") end end @@ -74,7 +74,7 @@ context "given valid claim attributes and missing amendment notes" do let(:claim_attributes) do { - teacher_reference_number: "7654321", + eligibility_attributes: {teacher_reference_number: "7654321"}, bank_account_number: "87654321" } end @@ -92,11 +92,11 @@ expect(amendment.claim_changes).to eq("teacher_reference_number" => ["1234567", "7654321"], "bank_account_number" => ["12345678", "87654321"]) expect(amendment.created_by).to eq(dfe_signin_user) - expect(claim.teacher_reference_number).to eq("7654321") + expect(claim.eligibility.teacher_reference_number).to eq("7654321") expect(claim.bank_account_number).to eq("87654321") expect(claim.reload.amendments).to be_empty - expect(claim.teacher_reference_number).to eq("1234567") + expect(claim.eligibility.teacher_reference_number).to eq("1234567") expect(claim.bank_account_number).to eq("12345678") expect(amendment.errors.attribute_names).to eq([:notes]) @@ -106,7 +106,7 @@ context "given invalid claim attributes and valid amendment attributes" do let(:claim_attributes) do { - teacher_reference_number: "765432", + eligibility_attributes: {teacher_reference_number: "765432"}, bank_account_number: "87654321" } end @@ -117,27 +117,58 @@ } end - it "assigns the new values to the claim but does not persist them, and returns a non-persisted amendment, with the errors from the claim copied to the amendment’s errors" do + it "assigns the new values to the claim but does not persist them, and returns a non-persisted amendment, with the errors from the claim copied to the amendment's errors" do amendment = described_class.amend_claim(claim, claim_attributes, amendment_attributes) expect(amendment).to_not be_persisted expect(amendment.created_by).to eq(dfe_signin_user) - expect(claim.teacher_reference_number).to eq("765432") + expect(claim.eligibility.teacher_reference_number).to eq("765432") expect(claim.bank_account_number).to eq("87654321") expect(claim.reload.amendments).to be_empty - expect(claim.teacher_reference_number).to eq("1234567") + expect(claim.eligibility.teacher_reference_number).to eq("1234567") expect(claim.bank_account_number).to eq("12345678") - expect(amendment.errors.attribute_names).to match_array([:teacher_reference_number]) + expect(amendment.errors.attribute_names).to match_array([:"eligibility.teacher_reference_number"]) + end + end + + context "given invalid claim attributes (blank trn) and valid amendment attributes" do + let(:claim_attributes) do + { + eligibility_attributes: {teacher_reference_number: ""}, + bank_account_number: "87654321" + } + end + let(:amendment_attributes) do + { + notes: "This is a change", + created_by: dfe_signin_user + } + end + + it "assigns the new values to the claim but does not persist them, and returns a non-persisted amendment, with the errors from the claim copied to the amendment's errors" do + amendment = described_class.amend_claim(claim, claim_attributes, amendment_attributes) + + expect(amendment).to_not be_persisted + expect(amendment.created_by).to eq(dfe_signin_user) + + expect(claim.eligibility.teacher_reference_number).to eq("") + expect(claim.bank_account_number).to eq("87654321") + + expect(claim.reload.amendments).to be_empty + expect(claim.eligibility.teacher_reference_number).to eq("1234567") + expect(claim.bank_account_number).to eq("12345678") + + expect(amendment.errors.attribute_names).to match_array([:"eligibility.teacher_reference_number"]) end end context "given invalid claim attributes and missing amendment notes" do let(:claim_attributes) do { - teacher_reference_number: "765432", + eligibility_attributes: {teacher_reference_number: "765432"}, bank_account_number: "87654321" } end @@ -147,27 +178,27 @@ } end - it "assigns the new values to the claim but does not persist them, and returns a non-persisted amendment which has errors, with the errors from the claim copied to the amendment’s errors" do + it "assigns the new values to the claim but does not persist them, and returns a non-persisted amendment which has errors, with the errors from the claim copied to the amendment's errors" do amendment = described_class.amend_claim(claim, claim_attributes, amendment_attributes) expect(amendment).to_not be_persisted expect(amendment.created_by).to eq(dfe_signin_user) - expect(claim.teacher_reference_number).to eq("765432") + expect(claim.eligibility.teacher_reference_number).to eq("765432") expect(claim.bank_account_number).to eq("87654321") expect(claim.reload.amendments).to be_empty - expect(claim.teacher_reference_number).to eq("1234567") + expect(claim.eligibility.teacher_reference_number).to eq("1234567") expect(claim.bank_account_number).to eq("12345678") - expect(amendment.errors.attribute_names).to match_array([:notes, :teacher_reference_number]) + expect(amendment.errors.attribute_names).to match_array([:notes, :"eligibility.teacher_reference_number"]) end end context "given claim attributes which are all the same as the current values" do let(:claim_attributes) do { - teacher_reference_number: claim.teacher_reference_number + eligibility_attributes: {teacher_reference_number: claim.eligibility.teacher_reference_number} } end let(:amendment_attributes) do @@ -178,7 +209,7 @@ end it "returns a non-persisted amendment which has errors on claim_changes" do - amendment = described_class.amend_claim(claim, claim_attributes, amendment_attributes) + amendment = described_class.amend_claim(claim.reload, claim_attributes, amendment_attributes) expect(amendment).to_not be_persisted expect(claim.reload.amendments).to be_empty @@ -200,14 +231,14 @@ } end - it "stores the normalised value in the amendment’s claim_changes" do - amendment = described_class.amend_claim(claim, claim_attributes, amendment_attributes) + it "stores the normalised value in the amendment's claim_changes" do + amendment = described_class.amend_claim(claim.reload, claim_attributes, amendment_attributes) expect(amendment.claim_changes).to eq("bank_sort_code" => ["111213", "010203"]) end end - context "when amending the claim’s eligibility attributes" do + context "when amending the claim's eligibility attributes" do context "with a Student Loans (TSLR) claim" do let(:claim) do create(:claim, :submitted, eligibility: build(:student_loans_eligibility, :eligible, student_loan_repayment_amount: 1000)) @@ -215,9 +246,7 @@ let(:claim_attributes) do { - eligibility_attributes: { - student_loan_repayment_amount: 555 - } + eligibility_attributes: {student_loan_repayment_amount: 555} } end let(:amendment_attributes) do @@ -227,8 +256,8 @@ } end - it "stores the value in the amendment’s claim_changes" do - amendment = described_class.amend_claim(claim, claim_attributes, amendment_attributes) + it "stores the value in the amendment's claim_changes" do + amendment = described_class.amend_claim(claim.reload, claim_attributes, amendment_attributes) expect(amendment.claim_changes).to eq("student_loan_repayment_amount" => [1000, 555]) end @@ -295,7 +324,7 @@ before { create(:journey_configuration, :additional_payments) } - it "stores the value in the amendment’s claim_changes" do + it "stores the value in the amendment's claim_changes" do amendment = described_class.amend_claim(claim, claim_attributes, amendment_attributes) expect(amendment.claim_changes).to eq("award_amount" => [7_500, 2_500]) @@ -306,7 +335,7 @@ context "when updating a value from nil to an empty string" do let(:claim_attributes) do { - teacher_reference_number: "7654321", + eligibility_attributes: {teacher_reference_number: "7654321"}, building_society_roll_number: "" } end @@ -317,7 +346,7 @@ } end - it "does not mark the value as changed in the amendment’s claim_changes" do + it "does not mark the value as changed in the amendment's claim_changes" do amendment = described_class.amend_claim(claim, claim_attributes, amendment_attributes) expect(amendment.claim_changes).to eq("teacher_reference_number" => ["1234567", "7654321"]) diff --git a/spec/models/automated_checks/claim_verifiers/census_subjects_taught_spec.rb b/spec/models/automated_checks/claim_verifiers/census_subjects_taught_spec.rb index 0261efb5e5..48dd56f4ac 100644 --- a/spec/models/automated_checks/claim_verifiers/census_subjects_taught_spec.rb +++ b/spec/models/automated_checks/claim_verifiers/census_subjects_taught_spec.rb @@ -14,7 +14,6 @@ module ClaimVerifiers national_insurance_number: "RT901113D", reference: "QKCVAQ3K", surname: "Bonnet-Fontaine", - teacher_reference_number: teacher_reference_number, policy: policy ) @@ -23,7 +22,8 @@ module ClaimVerifiers attributes_for( :"#{policy_underscored}_eligibility", :eligible, - eligible_itt_subject: :mathematics + eligible_itt_subject: :mathematics, + teacher_reference_number: teacher_reference_number ) ) elsif policy == Policies::LevellingUpPremiumPayments @@ -31,7 +31,8 @@ module ClaimVerifiers attributes_for( :"#{policy_underscored}_eligibility", :eligible, - eligible_itt_subject: :computing + eligible_itt_subject: :computing, + teacher_reference_number: teacher_reference_number ) ) elsif policy == Policies::StudentLoans @@ -41,7 +42,8 @@ module ClaimVerifiers :eligible, biology_taught: true, computing_taught: true, - physics_taught: false + physics_taught: false, + teacher_reference_number: teacher_reference_number ) ) end @@ -89,7 +91,6 @@ module ClaimVerifiers national_insurance_number: "RT901113D", reference: "QKCVAQ3K", surname: "Bonnet-Fontaine", - teacher_reference_number: teacher_reference_number, policy: policy ) @@ -98,7 +99,8 @@ module ClaimVerifiers attributes_for( :"#{policy_underscored}_eligibility", :eligible, - eligible_itt_subject: :none_of_the_above + eligible_itt_subject: :none_of_the_above, + teacher_reference_number: teacher_reference_number ) ) elsif policy == Policies::LevellingUpPremiumPayments @@ -106,7 +108,8 @@ module ClaimVerifiers attributes_for( :"#{policy_underscored}_eligibility", :eligible, - eligible_itt_subject: :none_of_the_above + eligible_itt_subject: :none_of_the_above, + teacher_reference_number: teacher_reference_number ) ) elsif policy == Policies::StudentLoans @@ -116,7 +119,8 @@ module ClaimVerifiers :eligible, biology_taught: false, computing_taught: false, - physics_taught: false + physics_taught: false, + teacher_reference_number: teacher_reference_number ) ) end @@ -344,9 +348,9 @@ module ClaimVerifiers national_insurance_number: "RT901113D", reference: "QKCVAQ3K", surname: "Bonnet-Fontaine", - teacher_reference_number: teacher_reference_number, policy: policy, - tasks: [build(:task, name: :census_subjects_taught)] + tasks: [build(:task, name: :census_subjects_taught)], + eligibility_attributes: {teacher_reference_number: teacher_reference_number} ) end @@ -405,7 +409,6 @@ module ClaimVerifiers national_insurance_number: "RT901113D", reference: "QKCVAQ3K", surname: "Bonnet-Fontaine", - teacher_reference_number: teacher_reference_number, policy: Policies::StudentLoans ) @@ -416,7 +419,8 @@ module ClaimVerifiers biology_taught: false, computing_taught: false, physics_taught: false, - languages_taught: true + languages_taught: true, + teacher_reference_number: teacher_reference_number ) ) diff --git a/spec/models/automated_checks/claim_verifiers/employment_spec.rb b/spec/models/automated_checks/claim_verifiers/employment_spec.rb index facbf0ce9b..1f428b900e 100644 --- a/spec/models/automated_checks/claim_verifiers/employment_spec.rb +++ b/spec/models/automated_checks/claim_verifiers/employment_spec.rb @@ -24,7 +24,6 @@ module ClaimVerifiers national_insurance_number: "RT901113D", reference: "QKCVAQ3K", surname: "Bonnet-Fontaine", - teacher_reference_number: teacher_reference_number, policy: policy, submitted_at: DateTime.new(2022, 1, 12, 13, 0, 0) ) @@ -33,7 +32,8 @@ module ClaimVerifiers attributes_for( :"#{policy_underscored}_eligibility", :eligible, - current_school_id: school.id + current_school_id: school.id, + teacher_reference_number: teacher_reference_number ) ) diff --git a/spec/models/automated_checks/claim_verifiers/identity_spec.rb b/spec/models/automated_checks/claim_verifiers/identity_spec.rb index 4a7e6df081..b5e18c3aa4 100644 --- a/spec/models/automated_checks/claim_verifiers/identity_spec.rb +++ b/spec/models/automated_checks/claim_verifiers/identity_spec.rb @@ -17,7 +17,7 @@ module ClaimVerifiers end stub_qualified_teaching_statuses_show( - trn: claim_arg.teacher_reference_number, + trn: claim_arg.eligibility.teacher_reference_number, params: { birthdate: claim_arg.date_of_birth&.to_s, nino: claim_arg.national_insurance_number @@ -36,7 +36,6 @@ module ClaimVerifiers national_insurance_number: "QQ100000C", reference: "AB123456", surname: "ELIGIBLE", - teacher_reference_number: "1234567", policy: policy ) @@ -45,7 +44,8 @@ module ClaimVerifiers claim.eligibility.update!( attributes_for( :"#{policy_underscored}_eligibility", - :eligible + :eligible, + teacher_reference_number: "1234567" ) ) @@ -56,7 +56,7 @@ module ClaimVerifiers { claim: claim_arg, dqt_teacher_status: Dqt::Client.new.teacher.find( - claim_arg.teacher_reference_number, + claim_arg.eligibility.teacher_reference_number, birthdate: claim_arg.date_of_birth, nino: claim_arg.national_insurance_number ) @@ -79,7 +79,7 @@ module ClaimVerifiers dob: claim_arg.date_of_birth, name: claim_arg.full_name, nino: claim_arg.national_insurance_number, - trn: claim_arg.teacher_reference_number + trn: claim_arg.eligibility.teacher_reference_number } end @@ -554,7 +554,7 @@ module ClaimVerifiers reference: "AB123456", surname: "ELIGIBLE", tasks: [build(:task, name: :identity_confirmation)], - teacher_reference_number: "1234567" + eligibility_attributes: {teacher_reference_number: "1234567"} ) end @@ -675,7 +675,6 @@ module ClaimVerifiers national_insurance_number: " QQ100000C ", reference: "AB123456", surname: "ELIGIBLE ", - teacher_reference_number: " 1234567 ", policy: policy ) @@ -684,7 +683,8 @@ module ClaimVerifiers claim.eligibility.update!( attributes_for( :"#{policy_underscored}_eligibility", - :eligible + :eligible, + teacher_reference_number: " 1234567 " ) ) diff --git a/spec/models/automated_checks/claim_verifiers/induction_spec.rb b/spec/models/automated_checks/claim_verifiers/induction_spec.rb index 9a2f081ed0..7edd71f081 100644 --- a/spec/models/automated_checks/claim_verifiers/induction_spec.rb +++ b/spec/models/automated_checks/claim_verifiers/induction_spec.rb @@ -9,7 +9,7 @@ module ClaimVerifiers { claim: claim_arg, dqt_teacher_status: Dqt::Client.new.teacher.find( - claim_arg.teacher_reference_number, + claim_arg.eligibility.teacher_reference_number, birthdate: claim_arg.date_of_birth, nino: claim_arg.national_insurance_number ) @@ -30,7 +30,7 @@ module ClaimVerifiers end stub_qualified_teaching_statuses_show( - trn: claim_arg.teacher_reference_number, + trn: claim_arg.eligibility.teacher_reference_number, params: { birthdate: claim_arg.date_of_birth&.to_s, nino: claim_arg.national_insurance_number diff --git a/spec/models/automated_checks/claim_verifiers/qualifications_spec.rb b/spec/models/automated_checks/claim_verifiers/qualifications_spec.rb index e6287827ac..087ea5f231 100644 --- a/spec/models/automated_checks/claim_verifiers/qualifications_spec.rb +++ b/spec/models/automated_checks/claim_verifiers/qualifications_spec.rb @@ -17,7 +17,7 @@ module ClaimVerifiers end stub_qualified_teaching_statuses_show( - trn: claim_arg.teacher_reference_number, + trn: claim_arg.eligibility.teacher_reference_number, params: { birthdate: claim_arg.date_of_birth&.to_s, nino: claim_arg.national_insurance_number @@ -38,7 +38,6 @@ module ClaimVerifiers national_insurance_number: "QQ100000C", reference: "AB123456", surname: "ELIGIBLE", - teacher_reference_number: "1234567", policy: Policies::EarlyCareerPayments ) @@ -46,7 +45,8 @@ module ClaimVerifiers attributes_for( :early_career_payments_eligibility, :eligible, - qualification: :undergraduate_itt + qualification: :undergraduate_itt, + teacher_reference_number: "1234567" ) ) @@ -57,7 +57,7 @@ module ClaimVerifiers { claim: claim_arg, dqt_teacher_status: Dqt::Client.new.teacher.find( - claim_arg.teacher_reference_number, + claim_arg.eligibility.teacher_reference_number, birthdate: claim_arg.date_of_birth, nino: claim_arg.national_insurance_number ) @@ -331,7 +331,7 @@ module ClaimVerifiers reference: "AB123456", surname: "ELIGIBLE", tasks: [build(:task, name: :qualifications)], - teacher_reference_number: "1234567" + eligibility_attributes: {teacher_reference_number: "1234567"} ) end diff --git a/spec/models/base_policy_spec.rb b/spec/models/base_policy_spec.rb index 6f0ca71125..abc200c266 100644 --- a/spec/models/base_policy_spec.rb +++ b/spec/models/base_policy_spec.rb @@ -1,10 +1,40 @@ require "rails_helper" module Policies + module TestPolicyA + include BasePolicy + + extend self + + class Eligibility + end + end + + module TestPolicyB + include BasePolicy + + extend self + + class Eligibility + end + end + module TestPolicy include BasePolicy extend self + + OTHER_CLAIMABLE_POLICIES = [ + TestPolicyA, + TestPolicyB + ].freeze + + ELIGIBILITY_MATCHING_ATTRIBUTES = [["some_reference"]].freeze + + SEARCHABLE_ELIGIBILITY_ATTRIBUTES = %w[some_searchable_reference].freeze + + class Eligibility + end end end @@ -38,4 +68,48 @@ module TestPolicy expect(Policies::TestPolicy.locale_key).to eq("test_policy") end end + + describe "::policies_claimable" do + it do + expect(Policies::TestPolicy.policies_claimable).to contain_exactly( + Policies::TestPolicy, Policies::TestPolicyA, Policies::TestPolicyB + ) + end + + it do + expect(Policies::TestPolicyA.policies_claimable).to be_empty + end + end + + describe "::policy_eligibilities_claimable" do + it do + expect(Policies::TestPolicy.policy_eligibilities_claimable).to contain_exactly( + Policies::TestPolicy::Eligibility, Policies::TestPolicyA::Eligibility, Policies::TestPolicyB::Eligibility + ) + end + + it do + expect(Policies::TestPolicyA.policy_eligibilities_claimable).to be_empty + end + end + + describe "::eligibility_matching_attributes" do + it do + expect(Policies::TestPolicy.eligibility_matching_attributes).to contain_exactly(["some_reference"]) + end + + it do + expect(Policies::TestPolicyA.eligibility_matching_attributes).to be_empty + end + end + + describe "::searchable_eligibility_attributes" do + it do + expect(Policies::TestPolicy.searchable_eligibility_attributes).to contain_exactly("some_searchable_reference") + end + + it do + expect(Policies::TestPolicyA.searchable_eligibility_attributes).to be_empty + end + end end diff --git a/spec/models/claim/claims_preventing_payment_finder_spec.rb b/spec/models/claim/claims_preventing_payment_finder_spec.rb index 1af1abfd4e..5311772fdc 100644 --- a/spec/models/claim/claims_preventing_payment_finder_spec.rb +++ b/spec/models/claim/claims_preventing_payment_finder_spec.rb @@ -8,10 +8,10 @@ describe "#claims_preventing_payment" do let(:personal_details) do { - teacher_reference_number: generate(:teacher_reference_number), bank_account_number: "32828838", bank_sort_code: "183828", - first_name: "Boris" + first_name: "Boris", + eligibility_attributes: {teacher_reference_number: generate(:teacher_reference_number)} } end let(:claim) { create(:claim, :submitted, personal_details) } @@ -42,7 +42,9 @@ end it "includes the other claim where a topup is payrollable" do - lup_eligibility = create(:levelling_up_premium_payments_eligibility, :eligible, award_amount: 1500.0) + eligibility_attributes = inconsistent_personal_details.delete(:eligibility_attributes) + + lup_eligibility = create(:levelling_up_premium_payments_eligibility, :eligible, award_amount: 1500.0, **eligibility_attributes) other_claim = create(:claim, :approved, inconsistent_personal_details.merge(policy: Policies::LevellingUpPremiumPayments, eligibility: lup_eligibility)) create(:payment, claims: [other_claim]) other_claim.topups.create(award_amount: "500.00", created_by: user) diff --git a/spec/models/claim/data_report_request_spec.rb b/spec/models/claim/data_report_request_spec.rb index e61f14e5fa..d65834550a 100644 --- a/spec/models/claim/data_report_request_spec.rb +++ b/spec/models/claim/data_report_request_spec.rb @@ -21,7 +21,7 @@ it "contains the correct values" do claims.each_with_index do |claim, index| expect(report_request_csv[index].fields("Claim reference")).to include(claim.reference) - expect(report_request_csv[index].fields("Teacher reference number")).to include(claim.teacher_reference_number) + expect(report_request_csv[index].fields("Teacher reference number")).to include(claim.eligibility.teacher_reference_number) expect(report_request_csv[index].fields("NINO")).to include(claim.national_insurance_number) expect(report_request_csv[index].fields("Full name")).to include(claim.full_name) expect(report_request_csv[index].fields("Email")).to include(claim.email_address) @@ -54,7 +54,7 @@ it "contains the correct values" do claims.each_with_index do |claim, index| expect(report_request_csv[index].fields("Claim reference")).to include(claim.reference) - expect(report_request_csv[index].fields("Teacher reference number")).to include(claim.teacher_reference_number) + expect(report_request_csv[index].fields("Teacher reference number")).to include(claim.eligibility.teacher_reference_number) expect(report_request_csv[index].fields("NINO")).to include(claim.national_insurance_number) expect(report_request_csv[index].fields("Full name")).to include(claim.full_name) expect(report_request_csv[index].fields("Email")).to include(claim.email_address) diff --git a/spec/models/claim/matching_attribute_finder_spec.rb b/spec/models/claim/matching_attribute_finder_spec.rb index e2b67f5d6f..c1e868a0dd 100644 --- a/spec/models/claim/matching_attribute_finder_spec.rb +++ b/spec/models/claim/matching_attribute_finder_spec.rb @@ -4,40 +4,40 @@ describe "#matching_claims for ECP/LUP claims" do let!(:source_claim) { create(:claim, - teacher_reference_number: "0902344", national_insurance_number: "QQ891011C", email_address: "genghis.khan@mongol-empire.com", bank_account_number: "34682151", bank_sort_code: "972654", academic_year: AcademicYear.new("2019"), building_society_roll_number: "123456789/ABCD", - policy: Policies::EarlyCareerPayments) + policy: Policies::EarlyCareerPayments, + eligibility_attributes: {teacher_reference_number: "0902344"}) } let!(:student_loans_claim) { create(:claim, :submitted, - teacher_reference_number: "0902344", national_insurance_number: "QQ891011C", email_address: "genghis.khan@mongol-empire.com", bank_account_number: "34682151", bank_sort_code: "972654", academic_year: AcademicYear.new("2019"), building_society_roll_number: "123456789/ABCD", - policy: Policies::StudentLoans) + policy: Policies::StudentLoans, + eligibility_attributes: {teacher_reference_number: "0902344"}) } let!(:lup_claim) { create(:claim, :submitted, - teacher_reference_number: "0902344", national_insurance_number: "QQ891011C", email_address: "genghis.khan@mongol-empire.com", bank_account_number: "34682151", bank_sort_code: "972654", academic_year: AcademicYear.new("2019"), building_society_roll_number: "123456789/ABCD", - policy: Policies::LevellingUpPremiumPayments) + policy: Policies::LevellingUpPremiumPayments, + eligibility_attributes: {teacher_reference_number: "0902344"}) } subject(:matching_claims) { Claim::MatchingAttributeFinder.new(source_claim).matching_claims } @@ -50,14 +50,14 @@ describe "#matching_claims" do let(:source_claim) { create(:claim, - teacher_reference_number: "0902344", national_insurance_number: "QQ891011C", email_address: "genghis.khan@mongol-empire.com", bank_account_number: "34682151", bank_sort_code: "972654", academic_year: AcademicYear.new("2019"), building_society_roll_number: "123456789/ABCD", - policy: Policies::StudentLoans) + policy: Policies::StudentLoans, + eligibility_attributes: {teacher_reference_number: "0902344"}) } subject(:matching_claims) { Claim::MatchingAttributeFinder.new(source_claim).matching_claims } @@ -73,20 +73,20 @@ end it "does not include unsubmitted claims with matching attributes" do - create(:claim, :submittable, teacher_reference_number: source_claim.teacher_reference_number) + create(:claim, :submittable, eligibility_attributes: {teacher_reference_number: source_claim.eligibility.teacher_reference_number}) expect(matching_claims).to be_empty end it "does not include claims that match, but have a different policy" do - student_loans_claim = create(:claim, :submitted, teacher_reference_number: source_claim.teacher_reference_number, policy: Policies::StudentLoans) + student_loans_claim = create(:claim, :submitted, eligibility_attributes: {teacher_reference_number: source_claim.eligibility.teacher_reference_number}, policy: Policies::StudentLoans) expect(matching_claims).to contain_exactly(student_loans_claim) end it "does not include claims that match, but have a different academic year" do create(:claim, :submitted, - teacher_reference_number: source_claim.teacher_reference_number, + eligibility_attributes: {teacher_reference_number: source_claim.eligibility.teacher_reference_number}, academic_year: AcademicYear.new("2020"), policy: source_claim.policy) @@ -94,7 +94,7 @@ end it "includes a claim with a matching teacher reference number" do - claim_with_matching_attribute = create(:claim, :submitted, teacher_reference_number: source_claim.teacher_reference_number) + claim_with_matching_attribute = create(:claim, :submitted, eligibility_attributes: {teacher_reference_number: source_claim.eligibility.teacher_reference_number}) expect(matching_claims).to eq([claim_with_matching_attribute]) end diff --git a/spec/models/claim/personal_data_scrubber_spec.rb b/spec/models/claim/personal_data_scrubber_spec.rb index 10e8359a40..88e72b4511 100644 --- a/spec/models/claim/personal_data_scrubber_spec.rb +++ b/spec/models/claim/personal_data_scrubber_spec.rb @@ -181,7 +181,7 @@ travel_to last_academic_year - 1.week do claim = create(:claim, :submitted) amendment = create(:amendment, claim: claim, claim_changes: { - "teacher_reference_number" => [generate(:teacher_reference_number).to_s, claim.teacher_reference_number], + "teacher_reference_number" => [generate(:teacher_reference_number).to_s, claim.eligibility.teacher_reference_number], "payroll_gender" => ["male", claim.payroll_gender], "date_of_birth" => [25.years.ago.to_date, claim.date_of_birth], "student_loan_plan" => ["plan_1", claim.student_loan_plan], diff --git a/spec/models/claim/search_spec.rb b/spec/models/claim/search_spec.rb index 82a024c346..65c569a417 100644 --- a/spec/models/claim/search_spec.rb +++ b/spec/models/claim/search_spec.rb @@ -94,7 +94,7 @@ end context "search by teacher reference number" do - let(:claim) { create(:claim, :submitted, teacher_reference_number: teacher_reference_number) } + let!(:claim) { create(:claim, :submitted, eligibility_attributes: {teacher_reference_number: teacher_reference_number}) } context "matches" do let(:query) { teacher_reference_number } @@ -109,7 +109,7 @@ end context "multiple matches" do - let(:historical_matching_claim) { create(:claim, :submitted, teacher_reference_number: teacher_reference_number) } + let!(:historical_matching_claim) { create(:claim, :submitted, eligibility_attributes: {teacher_reference_number: teacher_reference_number}) } let(:query) { teacher_reference_number } specify { expect(search.claims).to contain_exactly(claim, historical_matching_claim) } diff --git a/spec/models/claim_auto_approval_spec.rb b/spec/models/claim_auto_approval_spec.rb index f394da79f4..b7b75d9a95 100644 --- a/spec/models/claim_auto_approval_spec.rb +++ b/spec/models/claim_auto_approval_spec.rb @@ -29,7 +29,7 @@ context "when the claim is a duplicate" do let(:claim) { create(:claim, :submitted) } - let!(:duplicate) { create(:claim, :submitted, teacher_reference_number: claim.teacher_reference_number, policy: claim.policy) } + let!(:duplicate) { create(:claim, :submitted, eligibility_attributes: {teacher_reference_number: claim.eligibility.teacher_reference_number}, policy: claim.policy) } it { is_expected.to eq(false) } end diff --git a/spec/models/claim_checking_tasks_spec.rb b/spec/models/claim_checking_tasks_spec.rb index d39e04ea4c..cdd181bded 100644 --- a/spec/models/claim_checking_tasks_spec.rb +++ b/spec/models/claim_checking_tasks_spec.rb @@ -29,7 +29,7 @@ shared_examples :matching_details_task do it "includes a task for matching details when there are claims with matching details" do - create(:claim, :submitted, policy:, teacher_reference_number: claim.teacher_reference_number) + create(:claim, :submitted, policy:, eligibility_attributes: {teacher_reference_number: claim.eligibility.teacher_reference_number}) expect(checking_tasks.applicable_task_names).to match_array(applicable_tasks + %w[matching_details]) end @@ -135,7 +135,7 @@ end end - let!(:previous_claim) { create(:claim, :submitted, policy:, teacher_reference_number: claim.teacher_reference_number) } + let!(:previous_claim) { create(:claim, :submitted, policy:, eligibility_attributes: {teacher_reference_number: claim.eligibility.teacher_reference_number}) } it { is_expected.to eq(false) } end diff --git a/spec/models/claim_spec.rb b/spec/models/claim_spec.rb index a30f2c380d..ef5c807cab 100644 --- a/spec/models/claim_spec.rb +++ b/spec/models/claim_spec.rb @@ -43,9 +43,9 @@ context "that has a teacher_reference_number" do it "validates the length of the teacher reference number" do - expect(build(:claim, teacher_reference_number: "1/2/3/4/5/6/7")).to be_valid - expect(build(:claim, teacher_reference_number: "1/2/3/4/5")).not_to be_valid - expect(build(:claim, teacher_reference_number: "12/345678")).not_to be_valid + expect(build(:claim, eligibility_attributes: {teacher_reference_number: "1/2/3/4/5/6/7"}).eligibility).to be_valid + expect(build(:claim, eligibility_attributes: {teacher_reference_number: "1/2/3/4/5"}).eligibility).not_to be_valid + expect(build(:claim, eligibility_attributes: {teacher_reference_number: "12/345678"}).eligibility).not_to be_valid end end @@ -109,20 +109,20 @@ end describe "#teacher_reference_number" do - let(:claim) { build(:claim, teacher_reference_number: teacher_reference_number) } + let(:claim) { build(:claim, eligibility_attributes: {teacher_reference_number: teacher_reference_number}) } context "when the teacher reference number is stored and contains non digits" do let(:teacher_reference_number) { "12\\23 /232 " } it "strips out the non digits" do claim.save! - expect(claim.teacher_reference_number).to eql("1223232") + expect(claim.eligibility.teacher_reference_number).to eql("1223232") end end context "before the teacher reference number is stored" do let(:teacher_reference_number) { "12/34567" } it "is not modified" do - expect(claim.teacher_reference_number).to eql("12/34567") + expect(claim.eligibility.teacher_reference_number).to eql("12/34567") end end end @@ -328,9 +328,9 @@ it "returns false when there exists another payrollable claim with the same teacher reference number but with inconsistent attributes that would prevent us from running payroll" do teacher_reference_number = generate(:teacher_reference_number) - create(:claim, :approved, teacher_reference_number: teacher_reference_number, date_of_birth: 20.years.ago) + create(:claim, :approved, eligibility_attributes: {teacher_reference_number: teacher_reference_number}, date_of_birth: 20.years.ago) - expect(create(:claim, :submitted, teacher_reference_number: teacher_reference_number, date_of_birth: 30.years.ago).approvable?).to eq false + expect(create(:claim, :submitted, eligibility_attributes: {teacher_reference_number: teacher_reference_number}, date_of_birth: 30.years.ago).approvable?).to eq false end context "when the claim is held" do @@ -572,7 +572,6 @@ :address_line_4, :postcode, :payroll_gender, - :teacher_reference_number, :national_insurance_number, :email_address, :mobile_number, @@ -592,7 +591,8 @@ :details_check, :email_address_check, :mobile_check, - :qualifications_details_check + :qualifications_details_check, + :column_to_remove_teacher_reference_number ]) end end diff --git a/spec/models/decision_spec.rb b/spec/models/decision_spec.rb index fb6e7ad41b..24adf8c05b 100644 --- a/spec/models/decision_spec.rb +++ b/spec/models/decision_spec.rb @@ -71,7 +71,7 @@ it "prevents a claim with matching bank details from being approved" do personal_details = { - teacher_reference_number: generate(:teacher_reference_number), + eligibility_attributes: {teacher_reference_number: generate(:teacher_reference_number)}, bank_sort_code: "112233" } diff --git a/spec/models/early_career_payments/eligibility_spec.rb b/spec/models/early_career_payments/eligibility_spec.rb index 1fc2dd4073..c4e7f008a3 100644 --- a/spec/models/early_career_payments/eligibility_spec.rb +++ b/spec/models/early_career_payments/eligibility_spec.rb @@ -117,9 +117,9 @@ end it "validates that the award_amount is less than £7,500 when amending a claim" do - expect(Policies::EarlyCareerPayments::Eligibility.new(award_amount: 7_501)).not_to be_valid(:amendment) - expect(Policies::EarlyCareerPayments::Eligibility.new(award_amount: 7_500)).to be_valid(:amendment) - expect(Policies::EarlyCareerPayments::Eligibility.new(award_amount: 7_499)).to be_valid(:amendment) + expect(Policies::EarlyCareerPayments::Eligibility.new(teacher_reference_number: "1234567", award_amount: 7_501)).not_to be_valid(:amendment) + expect(Policies::EarlyCareerPayments::Eligibility.new(teacher_reference_number: "1234567", award_amount: 7_500)).to be_valid(:amendment) + expect(Policies::EarlyCareerPayments::Eligibility.new(teacher_reference_number: "1234567", award_amount: 7_499)).to be_valid(:amendment) end end end diff --git a/spec/models/payment_spec.rb b/spec/models/payment_spec.rb index dc2d64a64c..eedf7abd15 100644 --- a/spec/models/payment_spec.rb +++ b/spec/models/payment_spec.rb @@ -71,7 +71,7 @@ let(:claims) do build_list(:claim, 2, :approved, national_insurance_number: "JM603818B", - teacher_reference_number: "1234567", + eligibility_attributes: {teacher_reference_number: "1234567"}, email_address: "email@example.com", bank_sort_code: "112233", bank_account_number: "95928482", @@ -97,7 +97,7 @@ end it "is invalid when claims' teacher reference numbers do not match" do - claims[0].teacher_reference_number = "9988776" + claims[0].eligibility.teacher_reference_number = "9988776" expect(subject).not_to be_valid expect(subject.errors[:claims]).to eq(["#{claims[0].reference} and #{claims[1].reference} have different values for teacher reference number"]) @@ -179,7 +179,7 @@ let(:claims) do personal_details = { national_insurance_number: "JM603818B", - teacher_reference_number: "1234567", + eligibility_attributes: {teacher_reference_number: "1234567"}, bank_sort_code: "112233", bank_account_number: "95928482", building_society_roll_number: nil @@ -201,7 +201,7 @@ let(:personal_details) do { national_insurance_number: generate(:national_insurance_number), - teacher_reference_number: generate(:teacher_reference_number), + eligibility_attributes: {teacher_reference_number: generate(:teacher_reference_number)}, email_address: generate(:email_address), bank_sort_code: "112233", bank_account_number: "95928482", @@ -262,11 +262,11 @@ end describe "method delegations" do - described_class::PERSONAL_DETAILS_ATTRIBUTES_PERMITTING_DISCREPANCIES.each do |method| + described_class::PERSONAL_CLAIM_DETAILS_ATTRIBUTES_PERMITTING_DISCREPANCIES.each do |method| it { is_expected.to delegate_method(method).to(:claim_for_personal_details) } end - described_class::PERSONAL_DETAILS_ATTRIBUTES_FORBIDDING_DISCREPANCIES.each do |method| + described_class::PERSONAL_CLAIM_DETAILS_ATTRIBUTES_FORBIDDING_DISCREPANCIES.each do |method| it { is_expected.to delegate_method(method).to(:claim_for_personal_details) } end end diff --git a/spec/models/payroll/payment_csv_row_spec.rb b/spec/models/payroll/payment_csv_row_spec.rb index 851514f27b..e306b8356e 100644 --- a/spec/models/payroll/payment_csv_row_spec.rb +++ b/spec/models/payroll/payment_csv_row_spec.rb @@ -16,7 +16,7 @@ let(:personal_details_for_student_loans_and_early_career_payments_claim) do { national_insurance_number: generate(:national_insurance_number), - teacher_reference_number: generate(:teacher_reference_number), + eligibility_attributes: {teacher_reference_number: generate(:teacher_reference_number)}, payroll_gender: :female, date_of_birth: Date.new(1980, 12, 1), student_loan_plan: StudentLoan::PLAN_2, @@ -105,7 +105,7 @@ let(:personal_details_for_ecp_claim_1) do { national_insurance_number: generate(:national_insurance_number), - teacher_reference_number: generate(:teacher_reference_number), + eligibility_attributes: {teacher_reference_number: generate(:teacher_reference_number)}, payroll_gender: :male, date_of_birth: Date.new(1988, 3, 21), student_loan_plan: StudentLoan::PLAN_1_AND_3, @@ -177,7 +177,7 @@ let(:personal_details_for_ecp_claim_2) do { national_insurance_number: generate(:national_insurance_number), - teacher_reference_number: generate(:teacher_reference_number), + eligibility_attributes: {teacher_reference_number: generate(:teacher_reference_number)}, payroll_gender: :female, date_of_birth: Date.new(1994, 6, 30), student_loan_plan: StudentLoan::PLAN_1, diff --git a/spec/models/payroll_run_spec.rb b/spec/models/payroll_run_spec.rb index a353d9c842..ac6d7dd487 100644 --- a/spec/models/payroll_run_spec.rb +++ b/spec/models/payroll_run_spec.rb @@ -54,8 +54,8 @@ describe "#total_award_amount" do it "returns the sum of the award amounts of its claims" do - payment_1 = build(:payment, claims: [build(:claim, :approved, eligibility: build(:student_loans_eligibility, :eligible, student_loan_repayment_amount: 1500))]) - payment_2 = build(:payment, claims: [build(:claim, :approved, eligibility: build(:student_loans_eligibility, :eligible, student_loan_repayment_amount: 2000))]) + payment_1 = build(:payment, claims: [build(:claim, :approved, eligibility_attributes: {student_loan_repayment_amount: 1500})]) + payment_2 = build(:payment, claims: [build(:claim, :approved, eligibility_attributes: {student_loan_repayment_amount: 2000})]) payroll_run = PayrollRun.create!(created_by: user, payments: [payment_1, payment_2]) @@ -66,13 +66,13 @@ describe "#number_of_claims_for_policy" do it "returns the correct number of claims under each policy" do payment_1 = build(:payment, claims: [ - build(:claim, :approved, eligibility: build(:student_loans_eligibility, :eligible, student_loan_repayment_amount: 1500)) + build(:claim, :approved, eligibility_attributes: {student_loan_repayment_amount: 1500}) ]) payment_2 = build(:payment, claims: [ - build(:claim, :approved, policy: Policies::EarlyCareerPayments, eligibility: build(:early_career_payments_eligibility, :eligible)) + build(:claim, :approved, policy: Policies::EarlyCareerPayments) ]) payment_3 = build(:payment, claims: [ - build(:claim, :approved, policy: Policies::LevellingUpPremiumPayments, eligibility: build(:levelling_up_premium_payments_eligibility, :eligible)) + build(:claim, :approved, policy: Policies::LevellingUpPremiumPayments) ]) payroll_run = PayrollRun.create!(created_by: user, payments: [payment_1, payment_2, payment_3]) @@ -86,20 +86,20 @@ describe "#total_claim_amount_for_policy" do it "returns the correct total amount claimed under each policy" do payment_1 = build(:payment, claims: [ - build(:claim, :approved, eligibility: build(:student_loans_eligibility, :eligible, student_loan_repayment_amount: 1500)) + build(:claim, :approved, policy: Policies::StudentLoans, eligibility_attributes: {student_loan_repayment_amount: 1500}) ]) payment_2 = build(:payment, claims: [ - build(:claim, :approved, policy: Policies::EarlyCareerPayments, eligibility: build(:early_career_payments_eligibility, :eligible)) + build(:claim, :approved, policy: Policies::EarlyCareerPayments) ]) payment_3 = build(:payment, claims: [ - build(:claim, :approved, policy: Policies::EarlyCareerPayments, eligibility: build(:early_career_payments_eligibility, :eligible)) + build(:claim, :approved, policy: Policies::EarlyCareerPayments) ]) payment_4 = build(:payment, claims: [ - build(:claim, :approved, eligibility: build(:student_loans_eligibility, :eligible, student_loan_repayment_amount: 1000)) + build(:claim, :approved, eligibility_attributes: {student_loan_repayment_amount: 1000}) ]) payment_5 = build(:payment, claims: [ - build(:claim, :approved, policy: Policies::LevellingUpPremiumPayments, teacher_reference_number: "1234567", bank_sort_code: "123456", bank_account_number: "12345678", eligibility: build(:levelling_up_premium_payments_eligibility, :eligible)), - build(:claim, :approved, teacher_reference_number: "1234567", bank_sort_code: "123456", bank_account_number: "12345678", eligibility: build(:student_loans_eligibility, :eligible, student_loan_repayment_amount: 1000)) + build(:claim, :approved, policy: Policies::LevellingUpPremiumPayments, bank_sort_code: "123456", bank_account_number: "12345678", eligibility_attributes: {teacher_reference_number: "1234567"}), + build(:claim, :approved, bank_sort_code: "123456", bank_account_number: "12345678", eligibility_attributes: {student_loan_repayment_amount: 1000, teacher_reference_number: "1234567"}) ]) payroll_run = PayrollRun.create!(created_by: user, payments: [payment_1, payment_2, payment_3, payment_4, payment_5]) @@ -126,7 +126,7 @@ let(:personal_details) do { national_insurance_number: generate(:national_insurance_number), - teacher_reference_number: generate(:teacher_reference_number), + eligibility_attributes: {teacher_reference_number: generate(:teacher_reference_number)}, email_address: generate(:email_address), bank_sort_code: "112233", bank_account_number: "95928482", diff --git a/spec/models/policies_spec.rb b/spec/models/policies_spec.rb index 89d90aff26..9384573a53 100644 --- a/spec/models/policies_spec.rb +++ b/spec/models/policies_spec.rb @@ -13,8 +13,8 @@ describe "::AMENDABLE_ELIGIBILITY_ATTRIBUTES" do it do - expect(described_class::AMENDABLE_ELIGIBILITY_ATTRIBUTES).to eq([ - :student_loan_repayment_amount, :award_amount, :award_amount + expect(described_class::AMENDABLE_ELIGIBILITY_ATTRIBUTES.sort).to eq([ + :award_amount, :student_loan_repayment_amount, :teacher_reference_number ]) end end diff --git a/spec/models/student_loans/eligibility_spec.rb b/spec/models/student_loans/eligibility_spec.rb index c452cbd78a..9dc19a469b 100644 --- a/spec/models/student_loans/eligibility_spec.rb +++ b/spec/models/student_loans/eligibility_spec.rb @@ -50,8 +50,8 @@ end it "validates that the loan repayment less than £5000 when amending a claim" do - expect(described_class.new(student_loan_repayment_amount: "5001")).not_to be_valid(:amendment) - expect(described_class.new(student_loan_repayment_amount: "1200")).to be_valid(:amendment) + expect(described_class.new(teacher_reference_number: "1234567", student_loan_repayment_amount: "5001")).not_to be_valid(:amendment) + expect(described_class.new(teacher_reference_number: "1234567", student_loan_repayment_amount: "1200")).to be_valid(:amendment) end end diff --git a/spec/models/teachers_pensions_service_spec.rb b/spec/models/teachers_pensions_service_spec.rb index ca55cdf177..52621bae15 100644 --- a/spec/models/teachers_pensions_service_spec.rb +++ b/spec/models/teachers_pensions_service_spec.rb @@ -8,7 +8,7 @@ let(:school) { create(:school, local_authority:, establishment_number:) } let(:la_urn) { local_authority.code } let(:school_urn) { school.establishment_number } - let(:teacher_reference_number) { claim.teacher_reference_number } + let(:teacher_reference_number) { claim.eligibility.teacher_reference_number } let(:start_date) { end_date - 1.week } describe ".recent_tps_school" do @@ -63,7 +63,7 @@ let!(:ineligible_school) { create(:school, :student_loans_ineligible) } let!(:ineligible_school2) { create(:school, :student_loans_ineligible) } let(:trn) { "1234567" } - let(:claim) { create(:claim, teacher_reference_number: trn) } + let(:claim) { create(:claim, eligibility_attributes: {teacher_reference_number: trn}) } context "previous financial year has eligible school and ineligible school" do it "returns most recent eligible school" do diff --git a/spec/requests/admin_amendments_spec.rb b/spec/requests/admin_amendments_spec.rb index 6b4f07cf12..ac416edf14 100644 --- a/spec/requests/admin_amendments_spec.rb +++ b/spec/requests/admin_amendments_spec.rb @@ -1,13 +1,13 @@ require "rails_helper" RSpec.describe "Admin claim amendments" do - let(:claim) { create(:claim, :submitted, teacher_reference_number: "1234567", bank_sort_code: "010203", date_of_birth: 25.years.ago.to_date) } + let(:claim) { create(:claim, :submitted, eligibility_attributes: {teacher_reference_number: "1234567"}, bank_sort_code: "010203", date_of_birth: 25.years.ago.to_date) } context "when signed in as a service operator" do before { @signed_in_user = sign_in_as_service_operator } describe "admin/amendments#index" do - let(:claim) { create(:claim, :submitted, teacher_reference_number: "1234567") } + let(:claim) { create(:claim, :submitted, eligibility_attributes: {teacher_reference_number: "1234567"}) } let!(:amendment) { create(:amendment, claim: claim, notes: "Made a change", claim_changes: {"teacher_reference_number" => ["7654321", "1234567"]}) } it "list the amendments on a claim" do @@ -23,7 +23,7 @@ old_date_of_birth = claim.date_of_birth new_date_of_birth = 30.years.ago.to_date expect { - post admin_claim_amendments_url(claim, amendment: {claim: {teacher_reference_number: "7654321", bank_sort_code: "111213", "date_of_birth(3i)": new_date_of_birth.day, "date_of_birth(2i)": new_date_of_birth.month, "date_of_birth(1i)": new_date_of_birth.year}, + post admin_claim_amendments_url(claim, amendment: {claim: {eligibility_attributes: {teacher_reference_number: "7654321"}, bank_sort_code: "111213", "date_of_birth(3i)": new_date_of_birth.day, "date_of_birth(2i)": new_date_of_birth.month, "date_of_birth(1i)": new_date_of_birth.year}, notes: "Claimant made a typo"}) }.to change { claim.reload.amendments.size }.by(1) @@ -39,7 +39,7 @@ expect(amendment.notes).to eq("Claimant made a typo") expect(amendment.created_by).to eq(@signed_in_user) - expect(claim.teacher_reference_number).to eq("7654321") + expect(claim.eligibility.teacher_reference_number).to eq("7654321") expect(claim.bank_sort_code).to eq("111213") expect(claim.date_of_birth).to eq(new_date_of_birth) end @@ -66,9 +66,9 @@ it "displays a validation error and does not update the claim or create an amendment when invalid values are entered" do expect { - post admin_claim_amendments_url(claim, amendment: {claim: {teacher_reference_number: "654321", bank_account_number: ""}, + post admin_claim_amendments_url(claim, amendment: {claim: {eligibility_attributes: {teacher_reference_number: "654321"}, bank_account_number: ""}, notes: "Claimant made a typo"}) - }.not_to change { [claim.reload.teacher_reference_number, claim.amendments.size] } + }.not_to change { [claim.eligibility.reload.teacher_reference_number, claim.amendments.size] } expect(response).to have_http_status(:ok) @@ -78,9 +78,9 @@ it "displays an error message and does not create an amendment when none of the claim’s values are changed" do expect { - post admin_claim_amendments_url(claim, amendment: {claim: {teacher_reference_number: claim.teacher_reference_number}, + post admin_claim_amendments_url(claim, amendment: {claim: {eligibility_attributes: {teacher_reference_number: claim.eligibility.teacher_reference_number}}, notes: "Claimant made a typo"}) - }.not_to change { [claim.reload.teacher_reference_number, claim.amendments.size] } + }.not_to change { [claim.eligibility.reload.teacher_reference_number, claim.amendments.size] } expect(response).to have_http_status(:ok) @@ -105,7 +105,7 @@ let(:claim) { create(:claim, :approved, payments: [payment]) } it "shows an error" do - post admin_claim_amendments_url(claim, amendment: {claim: {teacher_reference_number: claim.teacher_reference_number}, + post admin_claim_amendments_url(claim, amendment: {claim: {eligibility_attributes: {teacher_reference_number: claim.eligibility.teacher_reference_number}}, notes: "Claimant made a typo"}) expect(response.body).to include("This claim cannot be amended.") end @@ -130,8 +130,8 @@ describe "admin_amendments#create" do it "returns a unauthorized response and does not create an amendment or change the claim" do expect { - post admin_claim_amendments_url(claim, amendment: {claim: {teacher_reference_number: "7654321"}}) - }.not_to change { [claim.reload.teacher_reference_number, claim.amendments.size] } + post admin_claim_amendments_url(claim, amendment: {claim: {eligibility_attributes: {teacher_reference_number: "7654321"}}}) + }.not_to change { [claim.eligibility.reload.teacher_reference_number, claim.amendments.size] } expect(response).to have_http_status(:unauthorized) end diff --git a/spec/requests/admin_claims_spec.rb b/spec/requests/admin_claims_spec.rb index ec6cb4b437..f7c6fce3de 100644 --- a/spec/requests/admin_claims_spec.rb +++ b/spec/requests/admin_claims_spec.rb @@ -110,7 +110,7 @@ end context "when another claim has matching attributes" do - let!(:claim_with_matching_attributes) { create(:claim, :submitted, teacher_reference_number: claim.teacher_reference_number, policy: policy) } + let!(:claim_with_matching_attributes) { create(:claim, :submitted, eligibility_attributes: {teacher_reference_number: claim.eligibility.teacher_reference_number}, policy: policy) } it "returns the claim and the duplicate" do get admin_claim_path(claim) diff --git a/spec/requests/admin_decisions_spec.rb b/spec/requests/admin_decisions_spec.rb index 50a45e594e..73d56b292e 100644 --- a/spec/requests/admin_decisions_spec.rb +++ b/spec/requests/admin_decisions_spec.rb @@ -219,7 +219,7 @@ let(:personal_details) do { national_insurance_number: generate(:national_insurance_number), - teacher_reference_number: generate(:teacher_reference_number), + eligibility_attributes: {teacher_reference_number: generate(:teacher_reference_number)}, date_of_birth: 30.years.ago.to_date, student_loan_plan: StudentLoan::PLAN_1, email_address: "email@example.com", diff --git a/spec/requests/admin_payroll_runs_spec.rb b/spec/requests/admin_payroll_runs_spec.rb index 7f2dd0f036..ba603a0af4 100644 --- a/spec/requests/admin_payroll_runs_spec.rb +++ b/spec/requests/admin_payroll_runs_spec.rb @@ -17,9 +17,9 @@ it "limits the number of claims entering payroll when exceeding the maximum allowed" do stubbed_max_payments = stub_const("PayrollRun::MAX_MONTHLY_PAYMENTS", 2) - create(:claim, :approved, eligibility: create(:student_loans_eligibility, student_loan_repayment_amount: 100), submitted_at: 3.days.ago) - create(:claim, :approved, eligibility: create(:student_loans_eligibility, student_loan_repayment_amount: 50), submitted_at: 1.days.ago) - create(:claim, :approved, eligibility: create(:student_loans_eligibility, student_loan_repayment_amount: 10), submitted_at: 2.days.ago) + create(:claim, :approved, eligibility_attributes: {student_loan_repayment_amount: 100}, submitted_at: 3.days.ago) + create(:claim, :approved, eligibility_attributes: {student_loan_repayment_amount: 50}, submitted_at: 1.days.ago) + create(:claim, :approved, eligibility_attributes: {student_loan_repayment_amount: 10}, submitted_at: 2.days.ago) get new_admin_payroll_run_path diff --git a/spec/requests/admin_tps_data_upload_spec.rb b/spec/requests/admin_tps_data_upload_spec.rb index eb92da3f7f..56d49ded09 100644 --- a/spec/requests/admin_tps_data_upload_spec.rb +++ b/spec/requests/admin_tps_data_upload_spec.rb @@ -76,10 +76,10 @@ def upload_tps_data_csm_file(file) :claim, :submitted, policy: Policies::EarlyCareerPayments, - teacher_reference_number: 1000106, submitted_at: Date.new(2022, 7, 15), academic_year: AcademicYear::Type.new.serialize(AcademicYear.new(2021)), eligibility_attributes: { + teacher_reference_number: 1000106, current_school: current_school } ) @@ -90,9 +90,9 @@ def upload_tps_data_csm_file(file) :claim, :submitted, policy: Policies::EarlyCareerPayments, - teacher_reference_number: 1000107, submitted_at: Date.new(2022, 7, 15), - academic_year: AcademicYear::Type.new.serialize(AcademicYear.new(2021)) + academic_year: AcademicYear::Type.new.serialize(AcademicYear.new(2021)), + eligibility_attributes: {teacher_reference_number: 1000107} ) end @@ -101,9 +101,9 @@ def upload_tps_data_csm_file(file) :claim, :submitted, policy: Policies::EarlyCareerPayments, - teacher_reference_number: 1000108, submitted_at: Date.new(2022, 7, 15), - academic_year: AcademicYear::Type.new.serialize(AcademicYear.new(2021)) + academic_year: AcademicYear::Type.new.serialize(AcademicYear.new(2021)), + eligibility_attributes: {teacher_reference_number: 1000108} ) end @@ -143,7 +143,7 @@ def upload_tps_data_csm_file(file) it "runs the employment task again for NO MATCH claims" do csv = <<~CSV Teacher reference number,NINO,Start Date,End Date,LA URN,School URN,Employer ID - #{claim_no_data.teacher_reference_number},ZX043155C,01/07/2022,30/09/2022,#{claim_no_data.school.local_authority.code},#{claim_no_data.school.establishment_number},1122 + #{claim_no_data.eligibility.teacher_reference_number},ZX043155C,01/07/2022,30/09/2022,#{claim_no_data.school.local_authority.code},#{claim_no_data.school.establishment_number},1122 CSV file = Rack::Test::UploadedFile.new(StringIO.new(csv), "text/csv", original_filename: "tps_data.csv") @@ -184,10 +184,10 @@ def upload_tps_data_csm_file(file) :claim, :submitted, policy: Policies::StudentLoans, - teacher_reference_number: 1000106, submitted_at: Date.new(2022, 7, 15), academic_year: AcademicYear::Type.new.serialize(AcademicYear.new(2021)), eligibility_attributes: { + teacher_reference_number: 1000106, current_school: current_school, claim_school: claim_school } @@ -199,9 +199,9 @@ def upload_tps_data_csm_file(file) :claim, :submitted, policy: Policies::StudentLoans, - teacher_reference_number: 1000107, submitted_at: Date.new(2022, 7, 15), - academic_year: AcademicYear::Type.new.serialize(AcademicYear.new(2021)) + academic_year: AcademicYear::Type.new.serialize(AcademicYear.new(2021)), + eligibility_attributes: {teacher_reference_number: 1000107} ) end diff --git a/spec/support/admin_edit_claim_feature_shared_examples.rb b/spec/support/admin_edit_claim_feature_shared_examples.rb index 6494e83ed9..555602db1d 100644 --- a/spec/support/admin_edit_claim_feature_shared_examples.rb +++ b/spec/support/admin_edit_claim_feature_shared_examples.rb @@ -30,7 +30,7 @@ end context "non-claim attribute" do - let(:old_value) { claim.teacher_reference_number } + let(:old_value) { claim.eligibility.teacher_reference_number } let(:new_value) { old_value.next } let(:reason) { "Fix typo" } diff --git a/spec/support/admin_view_claim_feature_shared_examples.rb b/spec/support/admin_view_claim_feature_shared_examples.rb index 6f02411e14..6a94d47da8 100644 --- a/spec/support/admin_view_claim_feature_shared_examples.rb +++ b/spec/support/admin_view_claim_feature_shared_examples.rb @@ -34,13 +34,12 @@ } let!(:similar_claim) { - eligibility = create(:"#{policy.to_s.underscore}_eligibility", :eligible) + eligibility = create(:"#{policy.to_s.underscore}_eligibility", :eligible, teacher_reference_number: multiple_claim.eligibility.teacher_reference_number) create( :claim, :submitted, policy: policy, - eligibility: eligibility, - teacher_reference_number: multiple_claim.teacher_reference_number + eligibility: eligibility ) } diff --git a/spec/support/fixture_helpers.rb b/spec/support/fixture_helpers.rb index f8213c56af..3203f4c8ce 100644 --- a/spec/support/fixture_helpers.rb +++ b/spec/support/fixture_helpers.rb @@ -13,7 +13,7 @@ def claim_from_example_dqt_report(trait) create(:claim, :submitted, first_name: "FRED", surname: "ELIGIBLE", - teacher_reference_number: "1234567", + eligibility_attributes: {teacher_reference_number: "1234567"}, reference: "AB123456", date_of_birth: Date.new(1990, 8, 23), national_insurance_number: "QQ123456C") @@ -23,7 +23,7 @@ def claim_from_example_dqt_report(trait) create(:claim, :submitted, first_name: "Dwayne", surname: "Hecos", - teacher_reference_number: "9876543", + eligibility_attributes: {teacher_reference_number: "9876543"}, reference: "ZY987654", date_of_birth: Date.new(1991, 1, 8), national_insurance_number: "QQ123456C") @@ -33,7 +33,7 @@ def claim_from_example_dqt_report(trait) create(:claim, :submitted, first_name: "Jo", surname: "Eligible", - teacher_reference_number: "8901231", + eligibility_attributes: {teacher_reference_number: "8901231"}, reference: "RR123456", date_of_birth: Date.new(1899, 1, 1), national_insurance_number: "QQ123456C") @@ -43,33 +43,33 @@ def claim_from_example_dqt_report(trait) create(:claim, :submitted, first_name: "Sarah", surname: "Eligible", - teacher_reference_number: "8981212", + eligibility_attributes: {teacher_reference_number: "8981212"}, reference: "DD123456", date_of_birth: Date.new(1980, 4, 10), national_insurance_number: "QQ123456C") when :claim_without_dqt_record # Submitted claim that has no DQT associated with it - create(:claim, :submitted, teacher_reference_number: "3456789", reference: "XX123456") + create(:claim, :submitted, eligibility_attributes: {teacher_reference_number: "3456789"}, reference: "XX123456") when :claim_with_ineligible_dqt_record # Submitted claim with matching data in DQT that is considered ineligible create(:claim, :submitted, - teacher_reference_number: "6758493", + eligibility_attributes: {teacher_reference_number: "6758493"}, reference: "CD123456", date_of_birth: Date.new(1979, 4, 21)) when :claim_with_decision # Eligible claim with matching data that already has a decision create(:claim, :approved, - teacher_reference_number: "5554433", + eligibility_attributes: {teacher_reference_number: "5554433"}, reference: "EF123456", date_of_birth: Date.new(1985, 5, 15)) when :claim_with_qualification_task # Eligible claim with matching data that already has a qualification task create(:claim, :submitted, - teacher_reference_number: "6060606", + eligibility_attributes: {teacher_reference_number: "6060606"}, reference: "GH123456", date_of_birth: Date.new(1980, 10, 4), tasks: [build(:task, name: "qualifications")])