From 3acd57c255551f6fc5bf485ded4f78d3bc6bfe2e Mon Sep 17 00:00:00 2001 From: kosiakkatrina <54268893+kosiakkatrina@users.noreply.github.com> Date: Mon, 20 Mar 2023 15:25:23 +0000 Subject: [PATCH] Student child validation (#1441) * Move household validation to soft validaiton * Add student_not_child_value_check column * Add soft validation pages * Update import service * typo * Change class names and fix a typo * More typos --- .../person_student_not_child_value_check.rb | 21 ++++ .../person_student_not_child_value_check.rb | 24 ++++ .../subsections/household_characteristics.rb | 18 +++ .../sales/household_validations.rb | 6 - .../validations/sales/soft_validations.rb | 11 ++ .../imports/sales_logs_import_service.rb | 4 +- config/locales/en.yml | 5 +- ...84057_add_student_not_child_value_check.rb | 5 + db/schema.rb | 5 +- ...rson_student_not_child_value_check_spec.rb | 106 ++++++++++++++++++ ...rson_student_not_child_value_check_spec.rb | 61 ++++++++++ .../household_characteristics_spec.rb | 36 ++++++ .../sales/household_validations_spec.rb | 11 +- .../sales/soft_validations_spec.rb | 68 +++++++++++ .../imports/sales_logs_import_service_spec.rb | 29 +++-- 15 files changed, 383 insertions(+), 27 deletions(-) create mode 100644 app/models/form/sales/pages/person_student_not_child_value_check.rb create mode 100644 app/models/form/sales/questions/person_student_not_child_value_check.rb create mode 100644 db/migrate/20230320084057_add_student_not_child_value_check.rb create mode 100644 spec/models/form/sales/pages/person_student_not_child_value_check_spec.rb create mode 100644 spec/models/form/sales/questions/person_student_not_child_value_check_spec.rb diff --git a/app/models/form/sales/pages/person_student_not_child_value_check.rb b/app/models/form/sales/pages/person_student_not_child_value_check.rb new file mode 100644 index 000000000..e3513e169 --- /dev/null +++ b/app/models/form/sales/pages/person_student_not_child_value_check.rb @@ -0,0 +1,21 @@ +class Form::Sales::Pages::PersonStudentNotChildValueCheck < Form::Sales::Pages::Person + def initialize(id, hsh, subsection, person_index:) + super + @depends_on = [ + { + "person_#{person_index}_student_not_child?" => true, + }, + ] + @person_index = person_index + @title_text = { + "translation" => "soft_validations.student_not_child.title_text", + } + @informative_text = {} + end + + def questions + @questions ||= [ + Form::Sales::Questions::PersonStudentNotChildValueCheck.new(nil, nil, self, person_index: @person_index), + ] + end +end diff --git a/app/models/form/sales/questions/person_student_not_child_value_check.rb b/app/models/form/sales/questions/person_student_not_child_value_check.rb new file mode 100644 index 000000000..fba35d05b --- /dev/null +++ b/app/models/form/sales/questions/person_student_not_child_value_check.rb @@ -0,0 +1,24 @@ +class Form::Sales::Questions::PersonStudentNotChildValueCheck < ::Form::Question + def initialize(id, hsh, page, person_index:) + super(id, hsh, page) + @id = "student_not_child_value_check" + @check_answer_label = "Student not a child confirmation" + @type = "interruption_screen" + @answer_options = { + "0" => { "value" => "Yes" }, + "1" => { "value" => "No" }, + } + @hidden_in_check_answers = { + "depends_on" => [ + { + "student_not_child_value_check" => 0, + }, + { + "student_not_child_value_check" => 1, + }, + ], + } + @check_answers_card_number = person_index + @header = "Are you sure this person is not a child?" + end +end diff --git a/app/models/form/sales/subsections/household_characteristics.rb b/app/models/form/sales/subsections/household_characteristics.rb index 311162e03..922d95edd 100644 --- a/app/models/form/sales/subsections/household_characteristics.rb +++ b/app/models/form/sales/subsections/household_characteristics.rb @@ -27,58 +27,76 @@ class Form::Sales::Subsections::HouseholdCharacteristics < ::Form::Subsection Form::Sales::Pages::Buyer1IncomeValueCheck.new("working_situation_buyer_1_income_value_check", nil, self), Form::Sales::Pages::Buyer1LiveInProperty.new(nil, nil, self), Form::Sales::Pages::Buyer2RelationshipToBuyer1.new(nil, nil, self), + Form::Sales::Pages::PersonStudentNotChildValueCheck.new("buyer_2_relationship_student_not_child_value_check", nil, self, person_index: 2), Form::Sales::Pages::Age2.new(nil, nil, self), Form::Sales::Pages::OldPersonsSharedOwnershipValueCheck.new("age_2_old_persons_shared_ownership_value_check", nil, self), Form::Sales::Pages::RetirementValueCheck.new("age_2_buyer_retirement_value_check", nil, self, person_index: 2), + Form::Sales::Pages::PersonStudentNotChildValueCheck.new("buyer_2_age_student_not_child_value_check", nil, self, person_index: 2), Form::Sales::Pages::GenderIdentity2.new(nil, nil, self), Form::Sales::Pages::RetirementValueCheck.new("gender_2_buyer_retirement_value_check", nil, self, person_index: 2), buyer_2_ethnicity_nationality_pages, Form::Sales::Pages::Buyer2WorkingSituation.new(nil, nil, self), Form::Sales::Pages::RetirementValueCheck.new("working_situation_2_retirement_value_check_joint_purchase", nil, self, person_index: 2), Form::Sales::Pages::Buyer2IncomeValueCheck.new("working_situation_buyer_2_income_value_check", nil, self), + Form::Sales::Pages::PersonStudentNotChildValueCheck.new("buyer_2_working_situation_student_not_child_value_check", nil, self, person_index: 2), Form::Sales::Pages::Buyer2LiveInProperty.new(nil, nil, self), Form::Sales::Pages::NumberOfOthersInProperty.new("number_of_others_in_property", nil, self, joint_purchase: false), Form::Sales::Pages::NumberOfOthersInProperty.new("number_of_others_in_property_joint_purchase", nil, self, joint_purchase: true), Form::Sales::Pages::PersonKnown.new("person_2_known", nil, self, person_index: 2), Form::Sales::Pages::PersonRelationshipToBuyer1.new("person_2_relationship_to_buyer_1", nil, self, person_index: 2), + Form::Sales::Pages::PersonStudentNotChildValueCheck.new("relationship_2_student_not_child_value_check", nil, self, person_index: 2), Form::Sales::Pages::PersonAge.new("person_2_age", nil, self, person_index: 2), Form::Sales::Pages::RetirementValueCheck.new("age_2_retirement_value_check", nil, self, person_index: 2), + Form::Sales::Pages::PersonStudentNotChildValueCheck.new("age_2_student_not_child_value_check", nil, self, person_index: 2), Form::Sales::Pages::PersonGenderIdentity.new("person_2_gender_identity", nil, self, person_index: 2), Form::Sales::Pages::RetirementValueCheck.new("gender_2_retirement_value_check", nil, self, person_index: 2), Form::Sales::Pages::PersonWorkingSituation.new("person_2_working_situation", nil, self, person_index: 2), Form::Sales::Pages::RetirementValueCheck.new("working_situation_2_retirement_value_check", nil, self, person_index: 2), + Form::Sales::Pages::PersonStudentNotChildValueCheck.new("working_situation_2_student_not_child_value_check", nil, self, person_index: 2), Form::Sales::Pages::PersonKnown.new("person_3_known", nil, self, person_index: 3), Form::Sales::Pages::PersonRelationshipToBuyer1.new("person_3_relationship_to_buyer_1", nil, self, person_index: 3), + Form::Sales::Pages::PersonStudentNotChildValueCheck.new("relationship_3_student_not_child_value_check", nil, self, person_index: 3), Form::Sales::Pages::PersonAge.new("person_3_age", nil, self, person_index: 3), Form::Sales::Pages::RetirementValueCheck.new("age_3_retirement_value_check", nil, self, person_index: 3), + Form::Sales::Pages::PersonStudentNotChildValueCheck.new("age_3_student_not_child_value_check", nil, self, person_index: 3), Form::Sales::Pages::PersonGenderIdentity.new("person_3_gender_identity", nil, self, person_index: 3), Form::Sales::Pages::RetirementValueCheck.new("gender_3_retirement_value_check", nil, self, person_index: 3), Form::Sales::Pages::PersonWorkingSituation.new("person_3_working_situation", nil, self, person_index: 3), Form::Sales::Pages::RetirementValueCheck.new("working_situation_3_retirement_value_check", nil, self, person_index: 3), + Form::Sales::Pages::PersonStudentNotChildValueCheck.new("working_situation_3_student_not_child_value_check", nil, self, person_index: 3), Form::Sales::Pages::PersonKnown.new("person_4_known", nil, self, person_index: 4), Form::Sales::Pages::PersonRelationshipToBuyer1.new("person_4_relationship_to_buyer_1", nil, self, person_index: 4), + Form::Sales::Pages::PersonStudentNotChildValueCheck.new("relationship_4_student_not_child_value_check", nil, self, person_index: 4), Form::Sales::Pages::PersonAge.new("person_4_age", nil, self, person_index: 4), Form::Sales::Pages::RetirementValueCheck.new("age_4_retirement_value_check", nil, self, person_index: 4), + Form::Sales::Pages::PersonStudentNotChildValueCheck.new("age_4_student_not_child_value_check", nil, self, person_index: 4), Form::Sales::Pages::PersonGenderIdentity.new("person_4_gender_identity", nil, self, person_index: 4), Form::Sales::Pages::RetirementValueCheck.new("gender_4_retirement_value_check", nil, self, person_index: 4), Form::Sales::Pages::PersonWorkingSituation.new("person_4_working_situation", nil, self, person_index: 4), Form::Sales::Pages::RetirementValueCheck.new("working_situation_4_retirement_value_check", nil, self, person_index: 4), + Form::Sales::Pages::PersonStudentNotChildValueCheck.new("working_situation_4_student_not_child_value_check", nil, self, person_index: 4), Form::Sales::Pages::PersonKnown.new("person_5_known", nil, self, person_index: 5), Form::Sales::Pages::PersonRelationshipToBuyer1.new("person_5_relationship_to_buyer_1", nil, self, person_index: 5), + Form::Sales::Pages::PersonStudentNotChildValueCheck.new("relationship_5_student_not_child_value_check", nil, self, person_index: 5), Form::Sales::Pages::PersonAge.new("person_5_age", nil, self, person_index: 5), Form::Sales::Pages::RetirementValueCheck.new("age_5_retirement_value_check", nil, self, person_index: 5), + Form::Sales::Pages::PersonStudentNotChildValueCheck.new("age_5_student_not_child_value_check", nil, self, person_index: 5), Form::Sales::Pages::PersonGenderIdentity.new("person_5_gender_identity", nil, self, person_index: 5), Form::Sales::Pages::RetirementValueCheck.new("gender_5_retirement_value_check", nil, self, person_index: 5), Form::Sales::Pages::PersonWorkingSituation.new("person_5_working_situation", nil, self, person_index: 5), Form::Sales::Pages::RetirementValueCheck.new("working_situation_5_retirement_value_check", nil, self, person_index: 5), + Form::Sales::Pages::PersonStudentNotChildValueCheck.new("working_situation_5_student_not_child_value_check", nil, self, person_index: 5), Form::Sales::Pages::PersonKnown.new("person_6_known", nil, self, person_index: 6), Form::Sales::Pages::PersonRelationshipToBuyer1.new("person_6_relationship_to_buyer_1", nil, self, person_index: 6), + Form::Sales::Pages::PersonStudentNotChildValueCheck.new("relationship_6_student_not_child_value_check", nil, self, person_index: 6), Form::Sales::Pages::PersonAge.new("person_6_age", nil, self, person_index: 6), Form::Sales::Pages::RetirementValueCheck.new("age_6_retirement_value_check", nil, self, person_index: 6), + Form::Sales::Pages::PersonStudentNotChildValueCheck.new("age_6_student_not_child_value_check", nil, self, person_index: 6), Form::Sales::Pages::PersonGenderIdentity.new("person_6_gender_identity", nil, self, person_index: 6), Form::Sales::Pages::RetirementValueCheck.new("gender_6_retirement_value_check", nil, self, person_index: 6), Form::Sales::Pages::PersonWorkingSituation.new("person_6_working_situation", nil, self, person_index: 6), Form::Sales::Pages::RetirementValueCheck.new("working_situation_6_retirement_value_check", nil, self, person_index: 6), + Form::Sales::Pages::PersonStudentNotChildValueCheck.new("working_situation_6_student_not_child_value_check", nil, self, person_index: 6), ].flatten.compact end diff --git a/app/models/validations/sales/household_validations.rb b/app/models/validations/sales/household_validations.rb index ec73b4abb..e53b7154e 100644 --- a/app/models/validations/sales/household_validations.rb +++ b/app/models/validations/sales/household_validations.rb @@ -45,12 +45,6 @@ private student = person_is_fulltime_student?(economic_status) child = person_is_child?(relationship) - if age_between_16_19 && student && !child - record.errors.add "age#{person_num}", I18n.t("validations.household.age.student_16_19.cannot_be_16_19.student_not_child") - record.errors.add "ecstat#{person_num}", I18n.t("validations.household.ecstat.student_16_19.cannot_be_student.16_19_not_child") - record.errors.add "relat#{person_num}", I18n.t("validations.household.relat.student_16_19.must_be_child") - end - if age_between_16_19 && !student && child record.errors.add "age#{person_num}", I18n.t("validations.household.age.student_16_19.cannot_be_16_19.child_not_student") record.errors.add "ecstat#{person_num}", I18n.t("validations.household.ecstat.student_16_19.must_be_student") diff --git a/app/models/validations/sales/soft_validations.rb b/app/models/validations/sales/soft_validations.rb index a44e0a293..5819b0fe1 100644 --- a/app/models/validations/sales/soft_validations.rb +++ b/app/models/validations/sales/soft_validations.rb @@ -103,6 +103,17 @@ module Validations::Sales::SoftValidations mscharge > soft_max end + (2..6).each do |person_num| + define_method("person_#{person_num}_student_not_child?") do + relat = send("relat#{person_num}") + ecstat = send("ecstat#{person_num}") + age = send("age#{person_num}") + return unless age && ecstat && relat + + age.between?(16, 19) && ecstat == 7 && relat != "C" + end + end + private def sale_range diff --git a/app/services/imports/sales_logs_import_service.rb b/app/services/imports/sales_logs_import_service.rb index 35c94eb15..d7a3c8534 100644 --- a/app/services/imports/sales_logs_import_service.rb +++ b/app/services/imports/sales_logs_import_service.rb @@ -152,6 +152,7 @@ module Imports attributes["old_persons_shared_ownership_value_check"] = 0 attributes["income2_value_check"] = 0 attributes["monthly_charges_value_check"] = 0 + attributes["student_not_child_value_check"] = 0 # Sets the log creator owner_id = meta_field_value(xml_doc, "owner-user-id").strip @@ -253,7 +254,8 @@ module Imports staircase_bought_value_check monthly_charges_value_check hodate_check - saledate_check] + saledate_check + student_not_child_value_check] end def check_status_completed(sales_log, previous_status) diff --git a/config/locales/en.yml b/config/locales/en.yml index 2d17cf207..8c9cd12c1 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -344,7 +344,6 @@ en: not_student_16_19: "Answer cannot be between 16 and 19 as person %{person_num} is a child of the lead tenant but is not a full-time student" student_16_19: cannot_be_16_19: - student_not_child: "Person cannot be aged 16-19 if they are a student but don't have relationship ‘child’" child_not_student: "Person cannot be aged 16-19 if they have relationship ‘child’ but are not a student" must_be_16_19: "Person must be aged 16-19 if they are a student and have relationship ‘child’" partner_under_16: "Cannot be under 16 if the relationship is partner" @@ -358,7 +357,6 @@ en: student_16_19: cannot_be_student: child_not_16_19: "Person cannot be a student if they are not aged 16-19 but have relationship ‘child’" - 16_19_not_child: "Person cannot be a student if they are aged 16-19 but don‘t have relationship ‘child’" must_be_student: "Person must be a student if they are aged 16-19 and have relationship ‘child’" retired_male: "Answer cannot be ‘retired’ as the male tenant is under 65" retired_female: "Answer cannot be ‘retired’ as the female tenant is under 60" @@ -372,7 +370,6 @@ en: cannot_be_child: student_not_16_19: "Answer cannot be ‘child’ if the person is a student but not aged 16-19" 16_19_not_student: "Answer cannot be ‘child’ if the person is aged 16-19 but not a student" - must_be_child: "Answer must be ‘child’ if the person is aged 16-19 and a student" housingneeds_a: one_or_two_choices: "You can only select one option or ‘other disabled access needs’ plus ‘wheelchair-accessible housing’, ‘wheelchair access to essential rooms’ or ‘level access housing’" housingneeds_type: @@ -526,6 +523,8 @@ en: staircase_bought_seems_high: "You said %{percentage}% was bought in this staircasing transaction, which seems high. Are you sure?" monthly_charges_over_soft_max: title_text: "The amount of monthly charges is high for this type of property and sale type" + student_not_child: + title_text: "You told us this person is a student aged beween 16 and 19" devise: two_factor_authentication: diff --git a/db/migrate/20230320084057_add_student_not_child_value_check.rb b/db/migrate/20230320084057_add_student_not_child_value_check.rb new file mode 100644 index 000000000..ecd037368 --- /dev/null +++ b/db/migrate/20230320084057_add_student_not_child_value_check.rb @@ -0,0 +1,5 @@ +class AddStudentNotChildValueCheck < ActiveRecord::Migration[7.0] + def change + add_column :sales_logs, :student_not_child_value_check, :integer + end +end diff --git a/db/schema.rb b/db/schema.rb index 075cc4b5e..32d71dfeb 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.0].define(version: 2023_03_09_145740) do +ActiveRecord::Schema[7.0].define(version: 2023_03_20_084057) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -560,7 +560,6 @@ ActiveRecord::Schema[7.0].define(version: 2023_03_09_145740) do t.integer "buy2living" t.integer "prevtenbuy2" t.integer "pregblank" - t.integer "nationalbuy2" t.string "uprn" t.integer "uprn_known" t.integer "uprn_confirmed" @@ -568,6 +567,8 @@ ActiveRecord::Schema[7.0].define(version: 2023_03_09_145740) do t.string "address_line2" t.string "town_or_city" t.string "county" + t.integer "nationalbuy2" + t.integer "student_not_child_value_check" t.index ["bulk_upload_id"], name: "index_sales_logs_on_bulk_upload_id" t.index ["created_by_id"], name: "index_sales_logs_on_created_by_id" t.index ["old_id"], name: "index_sales_logs_on_old_id", unique: true diff --git a/spec/models/form/sales/pages/person_student_not_child_value_check_spec.rb b/spec/models/form/sales/pages/person_student_not_child_value_check_spec.rb new file mode 100644 index 000000000..3499cda9f --- /dev/null +++ b/spec/models/form/sales/pages/person_student_not_child_value_check_spec.rb @@ -0,0 +1,106 @@ +require "rails_helper" + +RSpec.describe Form::Sales::Pages::PersonStudentNotChildValueCheck, type: :model do + subject(:page) { described_class.new(page_id, page_definition, subsection, person_index:) } + + let(:page_definition) { nil } + let(:subsection) { instance_double(Form::Subsection) } + let(:person_index) { 2 } + + let(:page_id) { "person_2_student_not_child_value_check" } + + it "has correct subsection" do + expect(page.subsection).to eq(subsection) + end + + it "has the correct header" do + expect(page.header).to be_nil + end + + it "has the correct description" do + expect(page.description).to be_nil + end + + it "is interruption screen page" do + expect(page.interruption_screen?).to eq(true) + end + + it "has correct title_text" do + expect(page.title_text).to eq({ + "translation" => "soft_validations.student_not_child.title_text", + }) + end + + it "has correct informative_text" do + expect(page.informative_text).to eq({}) + end + + it "has correct questions" do + expect(page.questions.map(&:id)).to eq(%w[student_not_child_value_check]) + end + + context "with person 2" do + let(:person_index) { 2 } + let(:page_id) { "person_2_student_not_child_value_check" } + + it "has the correct id" do + expect(page.id).to eq(page_id) + end + + it "has correct depends_on" do + expect(page.depends_on).to eq([{ "person_2_student_not_child?" => true }]) + end + end + + context "with person 3" do + let(:person_index) { 3 } + let(:page_id) { "person_3_student_not_child_value_check" } + + it "has the correct id" do + expect(page.id).to eq(page_id) + end + + it "has correct depends_on" do + expect(page.depends_on).to eq([{ "person_3_student_not_child?" => true }]) + end + end + + context "with person 4" do + let(:person_index) { 4 } + let(:page_id) { "person_4_student_not_child_value_check" } + + it "has the correct id" do + expect(page.id).to eq(page_id) + end + + it "has correct depends_on" do + expect(page.depends_on).to eq([{ "person_4_student_not_child?" => true }]) + end + end + + context "with person 5" do + let(:person_index) { 5 } + let(:page_id) { "person_5_student_not_child_value_check" } + + it "has the correct id" do + expect(page.id).to eq(page_id) + end + + it "has correct depends_on" do + expect(page.depends_on).to eq([{ "person_5_student_not_child?" => true }]) + end + end + + context "with person 6" do + let(:person_index) { 6 } + let(:page_id) { "person_6_student_not_child_value_check" } + + it "has the correct id" do + expect(page.id).to eq(page_id) + end + + it "has correct depends_on" do + expect(page.depends_on).to eq([{ "person_6_student_not_child?" => true }]) + end + end +end diff --git a/spec/models/form/sales/questions/person_student_not_child_value_check_spec.rb b/spec/models/form/sales/questions/person_student_not_child_value_check_spec.rb new file mode 100644 index 000000000..f36e7ad57 --- /dev/null +++ b/spec/models/form/sales/questions/person_student_not_child_value_check_spec.rb @@ -0,0 +1,61 @@ +require "rails_helper" + +RSpec.describe Form::Sales::Questions::PersonStudentNotChildValueCheck, type: :model do + subject(:question) { described_class.new(question_id, question_definition, page, person_index: 1) } + + let(:question_id) { nil } + let(:question_definition) { nil } + let(:page) { instance_double(Form::Page) } + + it "has correct page" do + expect(question.page).to eq(page) + end + + it "has the correct id" do + expect(question.id).to eq("student_not_child_value_check") + end + + it "has the correct header" do + expect(question.header).to eq("Are you sure this person is not a child?") + end + + it "has the correct check_answer_label" do + expect(question.check_answer_label).to eq("Student not a child confirmation") + end + + it "has the correct type" do + expect(question.type).to eq("interruption_screen") + end + + it "is not marked as derived" do + expect(question.derived?).to be false + end + + it "has the correct hint" do + expect(question.hint_text).to be_nil + end + + it "has a correct check_answers_card_number" do + expect(question.check_answers_card_number).to eq(1) + end + + it "has the correct answer_options" do + expect(question.answer_options).to eq({ + "0" => { "value" => "Yes" }, + "1" => { "value" => "No" }, + }) + end + + it "has the correct hidden_in_check_answers" do + expect(question.hidden_in_check_answers).to eq({ + "depends_on" => [ + { + "student_not_child_value_check" => 0, + }, + { + "student_not_child_value_check" => 1, + }, + ], + }) + end +end diff --git a/spec/models/form/sales/subsections/household_characteristics_spec.rb b/spec/models/form/sales/subsections/household_characteristics_spec.rb index b47ac970d..57a9ce019 100644 --- a/spec/models/form/sales/subsections/household_characteristics_spec.rb +++ b/spec/models/form/sales/subsections/household_characteristics_spec.rb @@ -40,57 +40,75 @@ RSpec.describe Form::Sales::Subsections::HouseholdCharacteristics, type: :model working_situation_buyer_1_income_value_check buyer_1_live_in_property buyer_2_relationship_to_buyer_1 + buyer_2_relationship_student_not_child_value_check buyer_2_age age_2_old_persons_shared_ownership_value_check age_2_buyer_retirement_value_check + buyer_2_age_student_not_child_value_check buyer_2_gender_identity gender_2_buyer_retirement_value_check buyer_2_working_situation working_situation_2_retirement_value_check_joint_purchase working_situation_buyer_2_income_value_check + buyer_2_working_situation_student_not_child_value_check buyer_2_live_in_property number_of_others_in_property number_of_others_in_property_joint_purchase person_2_known person_2_relationship_to_buyer_1 + relationship_2_student_not_child_value_check person_2_age age_2_retirement_value_check + age_2_student_not_child_value_check person_2_gender_identity gender_2_retirement_value_check person_2_working_situation working_situation_2_retirement_value_check + working_situation_2_student_not_child_value_check person_3_known person_3_relationship_to_buyer_1 + relationship_3_student_not_child_value_check person_3_age age_3_retirement_value_check + age_3_student_not_child_value_check person_3_gender_identity gender_3_retirement_value_check person_3_working_situation working_situation_3_retirement_value_check + working_situation_3_student_not_child_value_check person_4_known person_4_relationship_to_buyer_1 + relationship_4_student_not_child_value_check person_4_age age_4_retirement_value_check + age_4_student_not_child_value_check person_4_gender_identity gender_4_retirement_value_check person_4_working_situation working_situation_4_retirement_value_check + working_situation_4_student_not_child_value_check person_5_known person_5_relationship_to_buyer_1 + relationship_5_student_not_child_value_check person_5_age age_5_retirement_value_check + age_5_student_not_child_value_check person_5_gender_identity gender_5_retirement_value_check person_5_working_situation working_situation_5_retirement_value_check + working_situation_5_student_not_child_value_check person_6_known person_6_relationship_to_buyer_1 + relationship_6_student_not_child_value_check person_6_age age_6_retirement_value_check + age_6_student_not_child_value_check person_6_gender_identity gender_6_retirement_value_check person_6_working_situation working_situation_6_retirement_value_check + working_situation_6_student_not_child_value_check ], ) end @@ -124,9 +142,11 @@ RSpec.describe Form::Sales::Subsections::HouseholdCharacteristics, type: :model working_situation_buyer_1_income_value_check buyer_1_live_in_property buyer_2_relationship_to_buyer_1 + buyer_2_relationship_student_not_child_value_check buyer_2_age age_2_old_persons_shared_ownership_value_check age_2_buyer_retirement_value_check + buyer_2_age_student_not_child_value_check buyer_2_gender_identity gender_2_buyer_retirement_value_check buyer_2_ethnic_group @@ -139,49 +159,65 @@ RSpec.describe Form::Sales::Subsections::HouseholdCharacteristics, type: :model buyer_2_working_situation working_situation_2_retirement_value_check_joint_purchase working_situation_buyer_2_income_value_check + buyer_2_working_situation_student_not_child_value_check buyer_2_live_in_property number_of_others_in_property number_of_others_in_property_joint_purchase person_2_known person_2_relationship_to_buyer_1 + relationship_2_student_not_child_value_check person_2_age age_2_retirement_value_check + age_2_student_not_child_value_check person_2_gender_identity gender_2_retirement_value_check person_2_working_situation working_situation_2_retirement_value_check + working_situation_2_student_not_child_value_check person_3_known person_3_relationship_to_buyer_1 + relationship_3_student_not_child_value_check person_3_age age_3_retirement_value_check + age_3_student_not_child_value_check person_3_gender_identity gender_3_retirement_value_check person_3_working_situation working_situation_3_retirement_value_check + working_situation_3_student_not_child_value_check person_4_known person_4_relationship_to_buyer_1 + relationship_4_student_not_child_value_check person_4_age age_4_retirement_value_check + age_4_student_not_child_value_check person_4_gender_identity gender_4_retirement_value_check person_4_working_situation working_situation_4_retirement_value_check + working_situation_4_student_not_child_value_check person_5_known person_5_relationship_to_buyer_1 + relationship_5_student_not_child_value_check person_5_age age_5_retirement_value_check + age_5_student_not_child_value_check person_5_gender_identity gender_5_retirement_value_check person_5_working_situation working_situation_5_retirement_value_check + working_situation_5_student_not_child_value_check person_6_known person_6_relationship_to_buyer_1 + relationship_6_student_not_child_value_check person_6_age age_6_retirement_value_check + age_6_student_not_child_value_check person_6_gender_identity gender_6_retirement_value_check person_6_working_situation working_situation_6_retirement_value_check + working_situation_6_student_not_child_value_check ], ) end diff --git a/spec/models/validations/sales/household_validations_spec.rb b/spec/models/validations/sales/household_validations_spec.rb index 10367390e..5c7a921e4 100644 --- a/spec/models/validations/sales/household_validations_spec.rb +++ b/spec/models/validations/sales/household_validations_spec.rb @@ -84,17 +84,14 @@ RSpec.describe Validations::Sales::HouseholdValidations do .to include(match I18n.t("validations.household.age.child_over_20")) end - it "adds errors for a person aged 16-19 who is a student but not a child of the buyer" do + it "does not add and error for a person aged 16-19 who is a student but not a child of the buyer" do record.age2 = 18 record.ecstat2 = "7" record.relat2 = "P" household_validator.validate_household_number_of_other_members(record) - expect(record.errors["relat2"]) - .to include(match I18n.t("validations.household.relat.student_16_19.must_be_child")) - expect(record.errors["age2"]) - .to include(match I18n.t("validations.household.age.student_16_19.cannot_be_16_19.student_not_child")) - expect(record.errors["ecstat2"]) - .to include(match I18n.t("validations.household.ecstat.student_16_19.cannot_be_student.16_19_not_child")) + expect(record.errors["relat2"]).to be_empty + expect(record.errors["ecstat2"]).to be_empty + expect(record.errors["age2"]).to be_empty end it "adds errors for a person aged 16-19 who is a child of the buyer but not a student" do diff --git a/spec/models/validations/sales/soft_validations_spec.rb b/spec/models/validations/sales/soft_validations_spec.rb index 5d475b450..dc8bbfedd 100644 --- a/spec/models/validations/sales/soft_validations_spec.rb +++ b/spec/models/validations/sales/soft_validations_spec.rb @@ -730,4 +730,72 @@ RSpec.describe Validations::Sales::SoftValidations do end end end + + describe "#person_2_student_not_child?" do + it "returns false if age is not given" do + record.age2 = nil + record.relat2 = "P" + record.ecstat2 = 7 + + expect(record).not_to be_person_2_student_not_child + end + + it "returns false if retaltionship is not given" do + record.age2 = 17 + record.relat2 = nil + record.ecstat2 = 7 + + expect(record).not_to be_person_2_student_not_child + end + + it "returns false if economic status is not given" do + record.age2 = 17 + record.relat2 = "P" + record.ecstat2 = nil + + expect(record).not_to be_person_2_student_not_child + end + + it "returns true if it's a student aged 16-19 and not a child" do + record.age2 = 17 + record.relat2 = "P" + record.ecstat2 = 7 + + expect(record).to be_person_2_student_not_child + end + end + + describe "#person_3_student_not_child?" do + it "returns false if age is not given" do + record.age3 = nil + record.relat3 = "P" + record.ecstat3 = 7 + + expect(record).not_to be_person_3_student_not_child + end + + it "returns false if retaltionship is not given" do + record.age3 = 17 + record.relat3 = nil + record.ecstat3 = 7 + + expect(record).not_to be_person_3_student_not_child + end + + it "returns false if economic status is not given" do + record.age3 = 17 + record.relat3 = "P" + record.ecstat3 = nil + + expect(record).not_to be_person_3_student_not_child + end + + it "returns true if it's a student aged 16-19 and not a child" do + record.age3 = 17 + record.relat3 = "P" + record.ecstat3 = 7 + + expect(record).to be_person_3_student_not_child + end + end end diff --git a/spec/services/imports/sales_logs_import_service_spec.rb b/spec/services/imports/sales_logs_import_service_spec.rb index a9c085abc..d0e1f807d 100644 --- a/spec/services/imports/sales_logs_import_service_spec.rb +++ b/spec/services/imports/sales_logs_import_service_spec.rb @@ -363,20 +363,34 @@ RSpec.describe Imports::SalesLogsImportService do end end - context "and it has an invalid record with invalid child, student and 16-19 age combination" do + context "and the student not child soft validation is triggered (student_not_child_value_check)" do + let(:sales_log_id) { "shared_ownership_sales_log" } + + before do + sales_log_xml.at_xpath("//xmlns:P2Rel").content = "P" + sales_log_xml.at_xpath("//xmlns:P2Eco").content = "7" + sales_log_xml.at_xpath("//xmlns:P2Age").content = "16" + end + + it "completes the log" do + sales_log_service.send(:create_log, sales_log_xml) + sales_log = SalesLog.find_by(old_id: sales_log_id) + expect(sales_log.status).to eq("completed") + end + end + + context "and it has an invalid record with invalid child age" do let(:sales_log_id) { "discounted_ownership_sales_log" } before do sales_log_xml.at_xpath("//meta:status").content = "submitted-invalid" - sales_log_xml.at_xpath("//xmlns:P2Age").content = 16 - sales_log_xml.at_xpath("//xmlns:P2Eco").content = 7 - sales_log_xml.at_xpath("//xmlns:P2Rel").content = "X" + sales_log_xml.at_xpath("//xmlns:P2Age").content = 17 + sales_log_xml.at_xpath("//xmlns:P2Eco").content = 9 end it "intercepts the relevant validation error" do - expect(logger).to receive(:warn).with(/Removing field age2 from log triggering validation: Person cannot be aged 16-19 if they are a student but don't have relationship ‘child’/) - expect(logger).to receive(:warn).with(/Removing field relat2 from log triggering validation: Answer must be ‘child’ if the person is aged 16-19 and a student/) - expect(logger).to receive(:warn).with(/Removing field ecstat2 from log triggering validation: Person cannot be a student if they are aged 16-19 but don‘t have relationship ‘child’/) + expect(logger).to receive(:warn).with(/Log discounted_ownership_sales_log: Removing field ecstat2 from log triggering validation: Answer cannot be ‘child under 16’ as you told us the person 2 is older than 16/) + expect(logger).to receive(:warn).with(/Log discounted_ownership_sales_log: Removing field age2 from log triggering validation: Answer cannot be over 16 as person’s 2 working situation is ‘child under 16‘/) expect { sales_log_service.send(:create_log, sales_log_xml) } .not_to raise_error end @@ -389,7 +403,6 @@ RSpec.describe Imports::SalesLogsImportService do expect(sales_log).not_to be_nil expect(sales_log.age2).to be_nil - expect(sales_log.relat2).to be_nil expect(sales_log.ecstat2).to be_nil end end