From 55d6b5d6de0ec8b463ed327d85fed915837bfeca Mon Sep 17 00:00:00 2001 From: Manny Dinssa <44172848+Dinssa@users.noreply.github.com> Date: Wed, 13 Nov 2024 14:28:20 +0000 Subject: [PATCH] Add tests --- .../person_relationship_to_buyer_1_yes_no.rb | 2 +- ...yer2_relationship_to_buyer1_yes_no_spec.rb | 38 +++++ ...rson_relationship_to_buyer1_yes_no_spec.rb | 87 +++++++++++ ...yer2_relationship_to_buyer1_yes_no_spec.rb | 43 ++++++ ...rson_relationship_to_buyer1_yes_no_spec.rb | 110 ++++++++++++++ .../household_characteristics_spec.rb | 137 ++++++++++++++++++ 6 files changed, 416 insertions(+), 1 deletion(-) create mode 100644 spec/models/form/sales/pages/buyer2_relationship_to_buyer1_yes_no_spec.rb create mode 100644 spec/models/form/sales/pages/person_relationship_to_buyer1_yes_no_spec.rb create mode 100644 spec/models/form/sales/questions/buyer2_relationship_to_buyer1_yes_no_spec.rb create mode 100644 spec/models/form/sales/questions/person_relationship_to_buyer1_yes_no_spec.rb diff --git a/app/models/form/sales/questions/person_relationship_to_buyer_1_yes_no.rb b/app/models/form/sales/questions/person_relationship_to_buyer_1_yes_no.rb index 63bf3efb7..d08c35330 100644 --- a/app/models/form/sales/questions/person_relationship_to_buyer_1_yes_no.rb +++ b/app/models/form/sales/questions/person_relationship_to_buyer_1_yes_no.rb @@ -6,7 +6,7 @@ class Form::Sales::Questions::PersonRelationshipToBuyer1YesNo < ::Form::Question @answer_options = { "P" => { "value" => "Yes" }, "X" => { "value" => "No" }, - "R" => { "value" => "Buyer prefers not to say" }, + "R" => { "value" => "Person prefers not to say" }, } @inferred_check_answers_value = [{ "condition" => { diff --git a/spec/models/form/sales/pages/buyer2_relationship_to_buyer1_yes_no_spec.rb b/spec/models/form/sales/pages/buyer2_relationship_to_buyer1_yes_no_spec.rb new file mode 100644 index 000000000..9a5515f39 --- /dev/null +++ b/spec/models/form/sales/pages/buyer2_relationship_to_buyer1_yes_no_spec.rb @@ -0,0 +1,38 @@ +require "rails_helper" + +RSpec.describe Form::Sales::Pages::Buyer2RelationshipToBuyer1YesNo, type: :model do + subject(:page) { described_class.new(page_id, page_definition, subsection) } + + let(:page_id) { nil } + let(:page_definition) { nil } + let(:subsection) { instance_double(Form::Subsection, form: instance_double(Form, start_date: Time.zone.local(2025, 4, 1))) } + + it "has correct subsection" do + expect(page.subsection).to eq(subsection) + end + + it "has correct questions" do + expect(page.questions.map(&:id)).to eq(%w[relat2]) + end + + it "has the correct id" do + expect(page.id).to eq("buyer_2_relationship_to_buyer_1") + end + + it "has the correct description" do + expect(page.description).to be_nil + end + + it "has correct depends_on" do + expect(page.depends_on).to eq([ + { + "joint_purchase?" => true, + "buyer_has_seen_privacy_notice?" => true, + }, + { + "joint_purchase?" => true, + "buyer_not_interviewed?" => true, + }, + ]) + end +end diff --git a/spec/models/form/sales/pages/person_relationship_to_buyer1_yes_no_spec.rb b/spec/models/form/sales/pages/person_relationship_to_buyer1_yes_no_spec.rb new file mode 100644 index 000000000..a8215a0ba --- /dev/null +++ b/spec/models/form/sales/pages/person_relationship_to_buyer1_yes_no_spec.rb @@ -0,0 +1,87 @@ +require "rails_helper" + +RSpec.describe Form::Sales::Pages::PersonRelationshipToBuyer1YesNo, 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, form: instance_double(Form, start_date: Time.zone.local(2025, 4, 1))) } + let(:person_index) { 1 } + + let(:page_id) { "person_1_relationship_to_buyer_1" } + + it "has correct subsection" do + expect(page.subsection).to eq(subsection) + end + + it "has the correct description" do + expect(page.description).to be_nil + end + + context "with person 2" do + let(:person_index) { 2 } + let(:page_id) { "person_2_relationship_to_buyer_1" } + + it "has correct questions" do + expect(page.questions.map(&:id)).to eq(%w[relat2]) + end + + it "has the correct id" do + expect(page.id).to eq("person_2_relationship_to_buyer_1") + end + + it "has correct depends_on" do + expect(page.depends_on).to eq([{ "details_known_2" => 1 }]) + end + end + + context "with person 3" do + let(:person_index) { 3 } + let(:page_id) { "person_3_relationship_to_buyer_1" } + + it "has correct questions" do + expect(page.questions.map(&:id)).to eq(%w[relat3]) + end + + it "has the correct id" do + expect(page.id).to eq("person_3_relationship_to_buyer_1") + end + + it "has correct depends_on" do + expect(page.depends_on).to eq([{ "details_known_3" => 1 }]) + end + end + + context "with person 4" do + let(:person_index) { 4 } + let(:page_id) { "person_4_relationship_to_buyer_1" } + + it "has correct questions" do + expect(page.questions.map(&:id)).to eq(%w[relat4]) + end + + it "has the correct id" do + expect(page.id).to eq("person_4_relationship_to_buyer_1") + end + + it "has correct depends_on" do + expect(page.depends_on).to eq([{ "details_known_4" => 1 }]) + end + end + + context "with person 5" do + let(:person_index) { 5 } + let(:page_id) { "person_5_relationship_to_buyer_1" } + + it "has correct questions" do + expect(page.questions.map(&:id)).to eq(%w[relat5]) + end + + it "has the correct id" do + expect(page.id).to eq("person_5_relationship_to_buyer_1") + end + + it "has correct depends_on" do + expect(page.depends_on).to eq([{ "details_known_5" => 1 }]) + end + end +end diff --git a/spec/models/form/sales/questions/buyer2_relationship_to_buyer1_yes_no_spec.rb b/spec/models/form/sales/questions/buyer2_relationship_to_buyer1_yes_no_spec.rb new file mode 100644 index 000000000..5e94d7e7a --- /dev/null +++ b/spec/models/form/sales/questions/buyer2_relationship_to_buyer1_yes_no_spec.rb @@ -0,0 +1,43 @@ +require "rails_helper" + +RSpec.describe Form::Sales::Questions::Buyer2RelationshipToBuyer1YesNo, type: :model do + subject(:question) { described_class.new(question_id, question_definition, page) } + + let(:question_id) { nil } + let(:question_definition) { nil } + let(:page) { instance_double(Form::Page, subsection: instance_double(Form::Subsection, form: instance_double(Form, start_date: Time.zone.local(2025, 4, 1)))) } + + it "has correct page" do + expect(question.page).to eq(page) + end + + it "has the correct id" do + expect(question.id).to eq("relat2") + end + + it "has the correct type" do + expect(question.type).to eq("radio") + end + + it "is not marked as derived" do + expect(question.derived?(nil)).to be false + end + + it "has the correct answer_options" do + expect(question.answer_options).to eq({ + "P" => { "value" => "Yes" }, + "X" => { "value" => "No" }, + "R" => { "value" => "Buyer prefers not to say" }, + }) + end + + it "has the correct check_answers_card_number" do + expect(question.check_answers_card_number).to eq(2) + end + + it "has the correct inferred_check_answers_value" do + expect(question.inferred_check_answers_value).to eq([ + { "condition" => { "relat2" => "R" }, "value" => "Prefers not to say" }, + ]) + end +end diff --git a/spec/models/form/sales/questions/person_relationship_to_buyer1_yes_no_spec.rb b/spec/models/form/sales/questions/person_relationship_to_buyer1_yes_no_spec.rb new file mode 100644 index 000000000..cdfedc41e --- /dev/null +++ b/spec/models/form/sales/questions/person_relationship_to_buyer1_yes_no_spec.rb @@ -0,0 +1,110 @@ +require "rails_helper" + +RSpec.describe Form::Sales::Questions::PersonRelationshipToBuyer1YesNo, type: :model do + subject(:question) { described_class.new(question_id, question_definition, page, person_index:) } + + let(:question_id) { "relat2" } + let(:question_definition) { nil } + let(:page) { instance_double(Form::Page, subsection: instance_double(Form::Subsection, form: instance_double(Form, start_date: Time.zone.local(2025, 4, 1)))) } + let(:person_index) { 2 } + + it "has correct page" do + expect(question.page).to eq(page) + end + + it "has the correct type" do + expect(question.type).to eq("radio") + end + + it "is not marked as derived" do + expect(question.derived?(nil)).to be false + end + + it "has expected check answers card number" do + expect(question.check_answers_card_number).to eq(2) + end + + it "has the correct answer_options" do + expect(question.answer_options).to eq({ + "P" => { "value" => "Yes" }, + "X" => { "value" => "No" }, + "R" => { "value" => "Person prefers not to say" }, + }) + end + + context "when person 2" do + let(:question_id) { "relat2" } + let(:person_index) { 2 } + + it "has the correct id" do + expect(question.id).to eq("relat2") + end + + it "has expected check answers card number" do + expect(question.check_answers_card_number).to eq(2) + end + + it "has the correct inferred_check_answers_value" do + expect(question.inferred_check_answers_value).to eq([ + { "condition" => { "relat2" => "R" }, "value" => "Prefers not to say" }, + ]) + end + end + + context "when person 3" do + let(:question_id) { "relat3" } + let(:person_index) { 3 } + + it "has the correct id" do + expect(question.id).to eq("relat3") + end + + it "has expected check answers card number" do + expect(question.check_answers_card_number).to eq(3) + end + + it "has the correct inferred_check_answers_value" do + expect(question.inferred_check_answers_value).to eq([ + { "condition" => { "relat3" => "R" }, "value" => "Prefers not to say" }, + ]) + end + end + + context "when person 4" do + let(:question_id) { "relat4" } + let(:person_index) { 4 } + + it "has the correct id" do + expect(question.id).to eq("relat4") + end + + it "has expected check answers card number" do + expect(question.check_answers_card_number).to eq(4) + end + + it "has the correct inferred_check_answers_value" do + expect(question.inferred_check_answers_value).to eq([ + { "condition" => { "relat4" => "R" }, "value" => "Prefers not to say" }, + ]) + end + end + + context "when person 5" do + let(:question_id) { "relat5" } + let(:person_index) { 5 } + + it "has the correct id" do + expect(question.id).to eq("relat5") + end + + it "has expected check answers card number" do + expect(question.check_answers_card_number).to eq(5) + end + + it "has the correct inferred_check_answers_value" do + expect(question.inferred_check_answers_value).to eq([ + { "condition" => { "relat5" => "R" }, "value" => "Prefers not to say" }, + ]) + end + 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 3eb5042d8..8f9e8ea01 100644 --- a/spec/models/form/sales/subsections/household_characteristics_spec.rb +++ b/spec/models/form/sales/subsections/household_characteristics_spec.rb @@ -20,6 +20,7 @@ RSpec.describe Form::Sales::Subsections::HouseholdCharacteristics, type: :model before do allow(form).to receive(:start_date).and_return(Time.zone.local(2022, 4, 1)) allow(form).to receive(:start_year_2024_or_later?).and_return(false) + allow(form).to receive(:start_year_2025_or_later?).and_return(false) end it "has correct pages" do @@ -121,6 +122,7 @@ RSpec.describe Form::Sales::Subsections::HouseholdCharacteristics, type: :model before do allow(form).to receive(:start_date).and_return(Time.zone.local(2023, 4, 1)) allow(form).to receive(:start_year_2024_or_later?).and_return(false) + allow(form).to receive(:start_year_2025_or_later?).and_return(false) end it "has correct pages" do @@ -229,6 +231,141 @@ RSpec.describe Form::Sales::Subsections::HouseholdCharacteristics, type: :model before do allow(form).to receive(:start_date).and_return(Time.zone.local(2024, 4, 1)) allow(form).to receive(:start_year_2024_or_later?).and_return(true) + allow(form).to receive(:start_year_2025_or_later?).and_return(false) + end + + it "has correct pages" do + expect(household_characteristics.pages.map(&:id)).to eq( + %w[ + buyer_1_age + age_1_retirement_value_check + age_1_not_retired_value_check + age_1_old_persons_shared_ownership_joint_purchase_value_check + age_1_old_persons_shared_ownership_value_check + buyer_1_gender_identity + buyer_1_ethnic_group + buyer_1_ethnic_background_black + buyer_1_ethnic_background_asian + buyer_1_ethnic_background_arab + buyer_1_ethnic_background_mixed + buyer_1_ethnic_background_white + buyer_1_nationality + buyer_1_working_situation + working_situation_1_retirement_value_check + working_situation_1_not_retired_value_check + working_situation_buyer_1_income_min_value_check + buyer_1_live_in_property + buyer_1_live_in_property_value_check + buyer_2_relationship_to_buyer_1 + buyer_2_relationship_student_not_child_value_check + buyer_2_age + age_2_old_persons_shared_ownership_joint_purchase_value_check + age_2_old_persons_shared_ownership_value_check + age_2_buyer_retirement_value_check + age_2_buyer_not_retired_value_check + buyer_2_age_student_not_child_value_check + buyer_2_gender_identity + buyer_2_ethnic_group + buyer_2_ethnic_background_black + buyer_2_ethnic_background_asian + buyer_2_ethnic_background_arab + buyer_2_ethnic_background_mixed + buyer_2_ethnic_background_white + buyer_2_nationality + buyer_2_working_situation + working_situation_2_retirement_value_check_joint_purchase + working_situation_2_not_retired_value_check_joint_purchase + working_situation_buyer_2_income_min_value_check + buyer_2_working_situation_student_not_child_value_check + buyer_2_live_in_property + buyer_2_live_in_property_value_check + number_of_others_in_property + number_of_others_in_property_joint_purchase + person_2_known + person_2_relationship_to_buyer_1 + relationship_2_partner_under_16_value_check + relationship_2_multiple_partners_value_check + relationship_2_student_not_child_value_check + person_2_age + age_2_retirement_value_check + age_2_not_retired_value_check + age_2_student_not_child_value_check + age_2_partner_under_16_value_check + person_2_gender_identity + person_2_working_situation + working_situation_2_retirement_value_check + working_situation_2_not_retired_value_check + working_situation_2_student_not_child_value_check + person_3_known + person_3_relationship_to_buyer_1 + relationship_3_partner_under_16_value_check + relationship_3_multiple_partners_value_check + relationship_3_student_not_child_value_check + person_3_age + age_3_retirement_value_check + age_3_not_retired_value_check + age_3_student_not_child_value_check + age_3_partner_under_16_value_check + person_3_gender_identity + person_3_working_situation + working_situation_3_retirement_value_check + working_situation_3_not_retired_value_check + working_situation_3_student_not_child_value_check + person_4_known + person_4_relationship_to_buyer_1 + relationship_4_partner_under_16_value_check + relationship_4_multiple_partners_value_check + relationship_4_student_not_child_value_check + person_4_age + age_4_retirement_value_check + age_4_not_retired_value_check + age_4_student_not_child_value_check + age_4_partner_under_16_value_check + person_4_gender_identity + person_4_working_situation + working_situation_4_retirement_value_check + working_situation_4_not_retired_value_check + working_situation_4_student_not_child_value_check + person_5_known + person_5_relationship_to_buyer_1 + relationship_5_partner_under_16_value_check + relationship_5_multiple_partners_value_check + relationship_5_student_not_child_value_check + person_5_age + age_5_retirement_value_check + age_5_not_retired_value_check + age_5_student_not_child_value_check + age_5_partner_under_16_value_check + person_5_gender_identity + person_5_working_situation + working_situation_5_retirement_value_check + working_situation_5_not_retired_value_check + working_situation_5_student_not_child_value_check + person_6_known + person_6_relationship_to_buyer_1 + relationship_6_partner_under_16_value_check + relationship_6_multiple_partners_value_check + relationship_6_student_not_child_value_check + person_6_age + age_6_retirement_value_check + age_6_not_retired_value_check + age_6_student_not_child_value_check + age_6_partner_under_16_value_check + person_6_gender_identity + person_6_working_situation + working_situation_6_retirement_value_check + working_situation_6_not_retired_value_check + working_situation_6_student_not_child_value_check + ], + ) + end + end + + context "with 2025/26 form" do + before do + allow(form).to receive(:start_date).and_return(Time.zone.local(2025, 4, 1)) + allow(form).to receive(:start_year_2024_or_later?).and_return(true) + allow(form).to receive(:start_year_2025_or_later?).and_return(true) end it "has correct pages" do