diff --git a/spec/models/form/sales/pages/buyer1_gender_same_as_sex_spec.rb b/spec/models/form/sales/pages/buyer1_gender_same_as_sex_spec.rb new file mode 100644 index 000000000..245d96ba8 --- /dev/null +++ b/spec/models/form/sales/pages/buyer1_gender_same_as_sex_spec.rb @@ -0,0 +1,29 @@ +require "rails_helper" + +RSpec.describe Form::Sales::Pages::Buyer1GenderSameAsSex, 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(2026, 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[gender_same_as_sex1 gender_description1]) + end + + it "has the correct id" do + expect(page.id).to eq("buyer_1_gender_same_as_sex") + 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([{ "buyer_has_seen_privacy_notice?" => true }, { "buyer_not_interviewed?" => true }]) + end +end diff --git a/spec/models/form/sales/pages/person_gender_same_as_sex_spec.rb b/spec/models/form/sales/pages/person_gender_same_as_sex_spec.rb new file mode 100644 index 000000000..84bb685e2 --- /dev/null +++ b/spec/models/form/sales/pages/person_gender_same_as_sex_spec.rb @@ -0,0 +1,103 @@ +require "rails_helper" + +RSpec.describe Form::Sales::Pages::PersonGenderSameAsSex, 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(2026, 4, 1))) } + let(:person_index) { 2 } + let(:page_id) { "person_2_gender_same_as_sex" } + + 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_gender_same_as_sex" } + + it "has correct questions" do + expect(page.questions.map(&:id)).to eq(%w[gender_same_as_sex2 gender_description2]) + end + + it "has the correct id" do + expect(page.id).to eq("person_2_gender_same_as_sex") + 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_gender_same_as_sex" } + + it "has correct questions" do + expect(page.questions.map(&:id)).to eq(%w[gender_same_as_sex3 gender_description3]) + end + + it "has the correct id" do + expect(page.id).to eq("person_3_gender_same_as_sex") + 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_gender_same_as_sex" } + + it "has correct questions" do + expect(page.questions.map(&:id)).to eq(%w[gender_same_as_sex4 gender_description4]) + end + + it "has the correct id" do + expect(page.id).to eq("person_4_gender_same_as_sex") + 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_gender_same_as_sex" } + + it "has correct questions" do + expect(page.questions.map(&:id)).to eq(%w[gender_same_as_sex5 gender_description5]) + end + + it "has the correct id" do + expect(page.id).to eq("person_5_gender_same_as_sex") + end + + it "has correct depends_on" do + expect(page.depends_on).to eq([{ "details_known_5" => 1 }]) + end + end + + context "with person 6" do + let(:person_index) { 6 } + let(:page_id) { "person_6_gender_same_as_sex" } + + it "has correct questions" do + expect(page.questions.map(&:id)).to eq(%w[gender_same_as_sex6 gender_description6]) + end + + it "has the correct id" do + expect(page.id).to eq("person_6_gender_same_as_sex") + end + + it "has correct depends_on" do + expect(page.depends_on).to eq([{ "details_known_6" => 1 }]) + end + end +end diff --git a/spec/models/form/sales/questions/gender_description2_spec.rb b/spec/models/form/sales/questions/gender_description2_spec.rb new file mode 100644 index 000000000..cc1420fd9 --- /dev/null +++ b/spec/models/form/sales/questions/gender_description2_spec.rb @@ -0,0 +1,52 @@ +require "rails_helper" + +RSpec.describe Form::Sales::Questions::GenderDescription2, 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) } + let(:subsection) { instance_double(Form::Subsection) } + let(:form) { instance_double(Form, start_date: Time.zone.local(2026, 4, 1)) } + + before do + allow(page).to receive(:subsection).and_return(subsection) + allow(subsection).to receive(:form).and_return(form) + end + + it "has correct page" do + expect(question.page).to eq(page) + end + + it "has the correct id" do + expect(question.id).to eq("gender_description2") + end + + it "has the correct type" do + expect(question.type).to eq("text") + 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 be_nil + end + + context "when gender_same_as_sex2 is 'Yes'" do + let(:log) { build(:sales_log, gender_same_as_sex2: 1) } + + it "is marked as derived" do + expect(question.derived?(log)).to be true + end + end + + context "when gender_same_as_sex2 is 'No'" do + let(:log) { build(:sales_log, gender_same_as_sex2: 2) } + + it "is not marked as derived" do + expect(question.derived?(log)).to be false + end + end +end diff --git a/spec/models/form/sales/questions/gender_description_spec.rb b/spec/models/form/sales/questions/gender_description_spec.rb new file mode 100644 index 000000000..db5189210 --- /dev/null +++ b/spec/models/form/sales/questions/gender_description_spec.rb @@ -0,0 +1,60 @@ +require "rails_helper" + +RSpec.describe Form::Sales::Questions::GenderDescription1, 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) } + let(:subsection) { instance_double(Form::Subsection) } + let(:form) { instance_double(Form, start_date: Time.zone.local(2026, 4, 1)) } + + before do + allow(page).to receive(:subsection).and_return(subsection) + allow(subsection).to receive(:form).and_return(form) + end + + it "has correct page" do + expect(question.page).to eq(page) + end + + it "has the correct id" do + expect(question.id).to eq("gender_description1") + end + + it "has the correct type" do + expect(question.type).to eq("text") + end + + it "has expected check answers card number" do + expect(question.check_answers_card_number).to eq(1) + end + + it "has the correct inferred_check_answers_value" do + expect(question.inferred_check_answers_value).to be_nil + end + + context "when gender_same_as_sex1 is 'Yes'" do + let(:log) { build(:sales_log, gender_same_as_sex1: 1) } + + it "is marked as derived" do + expect(question.derived?(log)).to be true + end + end + + context "when gender_same_as_sex1 is 'No'" do + let(:log) { build(:sales_log, gender_same_as_sex1: 2) } + + it "is not marked as derived" do + expect(question.derived?(log)).to be false + end + end + + context "when gender_same_as_sex1 is 'Prefers not to say'" do + let(:log) { build(:sales_log, gender_same_as_sex1: 3) } + + it "is marked as derived" do + expect(question.derived?(log)).to be true + end + end +end diff --git a/spec/models/form/sales/questions/gender_same_as_sex2_spec.rb b/spec/models/form/sales/questions/gender_same_as_sex2_spec.rb new file mode 100644 index 000000000..d3636abef --- /dev/null +++ b/spec/models/form/sales/questions/gender_same_as_sex2_spec.rb @@ -0,0 +1,57 @@ +require "rails_helper" + +RSpec.describe Form::Sales::Questions::GenderSameAsSex2, 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) } + let(:subsection) { instance_double(Form::Subsection) } + let(:form) { instance_double(Form, start_date: Time.zone.local(2026, 4, 1)) } + + before do + allow(page).to receive(:subsection).and_return(subsection) + allow(subsection).to receive(:form).and_return(form) + end + + it "has correct page" do + expect(question.page).to eq(page) + end + + it "has the correct id" do + expect(question.id).to eq("gender_same_as_sex2") + 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 conditional_for" do + expect(question.conditional_for).to eq({ "gender_description2" => [2] }) + end + + it "has the correct inferred_check_answers_value" do + expect(question.inferred_check_answers_value).to eq([{ "condition" => { "gender_same_as_sex2" => 2 }, "value" => "No" }]) + end + + it "has the correct answer_options" do + expect(question.answer_options).to eq({ + "1" => { "value" => "Yes" }, + "2" => { "value" => "No, enter gender identity" }, + "divider" => { "value" => true }, + "3" => { "value" => "Buyer prefers not to say" }, + }) + end + + it "returns correct label_from_value for 'Prefers not to say'" do + expect(question.label_from_value(3)).to eq("Prefers not to say") + end +end diff --git a/spec/models/form/sales/questions/gender_same_as_sex_spec.rb b/spec/models/form/sales/questions/gender_same_as_sex_spec.rb new file mode 100644 index 000000000..ac3dee00a --- /dev/null +++ b/spec/models/form/sales/questions/gender_same_as_sex_spec.rb @@ -0,0 +1,65 @@ +require "rails_helper" + +RSpec.describe Form::Sales::Questions::GenderSameAsSex1, 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) } + let(:subsection) { instance_double(Form::Subsection) } + let(:form) { instance_double(Form, start_date: Time.zone.local(2026, 4, 1)) } + + before do + allow(page).to receive(:subsection).and_return(subsection) + allow(subsection).to receive(:form).and_return(form) + end + + it "has correct page" do + expect(question.page).to eq(page) + end + + it "has the correct id" do + expect(question.id).to eq("gender_same_as_sex1") + 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(1) + end + + it "has the correct conditional_for" do + expect(question.conditional_for).to eq({ "gender_description1" => [2] }) + end + + it "has the correct inferred_check_answers_value" do + expect(question.inferred_check_answers_value).to eq([{ "condition" => { "gender_same_as_sex1" => 2 }, "value" => "No" }]) + end + + it "has the correct answer_options" do + expect(question.answer_options).to eq({ + "1" => { "value" => "Yes" }, + "2" => { "value" => "No, enter gender identity" }, + "divider" => { "value" => true }, + "3" => { "value" => "Buyer prefers not to say" }, + }) + end + + it "returns correct label_from_value for 'No'" do + expect(question.label_from_value(2)).to eq("No, enter gender identity") + end + + it "returns correct label_from_value for 'Prefers not to say'" do + expect(question.label_from_value(3)).to eq("Prefers not to say") + end + + it "returns nil label_from_value for nil" do + expect(question.label_from_value(nil)).to be_nil + end +end diff --git a/spec/models/form/sales/questions/person_gender_description_spec.rb b/spec/models/form/sales/questions/person_gender_description_spec.rb new file mode 100644 index 000000000..bafa340b2 --- /dev/null +++ b/spec/models/form/sales/questions/person_gender_description_spec.rb @@ -0,0 +1,105 @@ +require "rails_helper" + +RSpec.describe Form::Sales::Questions::PersonGenderDescription, type: :model do + subject(:question) { described_class.new(question_id, question_definition, page, person_index:) } + + let(:question_id) { nil } + let(:question_definition) { nil } + let(:page) { instance_double(Form::Page) } + let(:person_index) { 2 } + let(:subsection) { instance_double(Form::Subsection) } + let(:form) { instance_double(Form, start_date: Time.zone.local(2026, 4, 1)) } + + before do + allow(page).to receive(:subsection).and_return(subsection) + allow(subsection).to receive(:form).and_return(form) + end + + it "has correct page" do + expect(question.page).to eq(page) + end + + it "has the correct type" do + expect(question.type).to eq("text") + end + + context "when person 2" do + let(:person_index) { 2 } + + it "has the correct id" do + expect(question.id).to eq("gender_description2") + 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 be_nil + end + end + + context "when person 3" do + let(:person_index) { 3 } + + it "has the correct id" do + expect(question.id).to eq("gender_description3") + 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 be_nil + end + end + + context "when person 4" do + let(:person_index) { 4 } + + it "has the correct id" do + expect(question.id).to eq("gender_description4") + 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 be_nil + end + end + + context "when person 5" do + let(:person_index) { 5 } + + it "has the correct id" do + expect(question.id).to eq("gender_description5") + 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 be_nil + end + end + + context "when person 6" do + let(:person_index) { 6 } + + it "has the correct id" do + expect(question.id).to eq("gender_description6") + end + + it "has expected check answers card number" do + expect(question.check_answers_card_number).to eq(6) + end + + it "has the correct inferred_check_answers_value" do + expect(question.inferred_check_answers_value).to be_nil + end + end +end diff --git a/spec/models/form/sales/questions/person_gender_same_as_sex_spec.rb b/spec/models/form/sales/questions/person_gender_same_as_sex_spec.rb new file mode 100644 index 000000000..1b6ce7e1c --- /dev/null +++ b/spec/models/form/sales/questions/person_gender_same_as_sex_spec.rb @@ -0,0 +1,142 @@ +require "rails_helper" + +RSpec.describe Form::Sales::Questions::PersonGenderSameAsSex, type: :model do + subject(:question) { described_class.new(question_id, question_definition, page, person_index:) } + + let(:question_id) { nil } + let(:question_definition) { nil } + let(:page) { instance_double(Form::Page) } + let(:person_index) { 2 } + let(:subsection) { instance_double(Form::Subsection) } + let(:form) { instance_double(Form, start_date: Time.zone.local(2026, 4, 1)) } + + before do + allow(page).to receive(:subsection).and_return(subsection) + allow(subsection).to receive(:form).and_return(form) + end + + 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 the correct answer_options" do + expect(question.answer_options).to eq({ + "1" => { "value" => "Yes" }, + "2" => { "value" => "No, enter gender identity" }, + "divider" => { "value" => true }, + "3" => { "value" => "Person prefers not to say" }, + }) + end + + it "returns correct label_from_value for 'Prefers not to say'" do + expect(question.label_from_value(3)).to eq("Prefers not to say") + end + + context "when person 2" do + let(:person_index) { 2 } + + it "has the correct id" do + expect(question.id).to eq("gender_same_as_sex2") + end + + it "has expected check answers card number" do + expect(question.check_answers_card_number).to eq(2) + end + + it "has the correct conditional_for" do + expect(question.conditional_for).to eq({ "gender_description2" => [2] }) + end + + it "has the correct inferred_check_answers_value" do + expect(question.inferred_check_answers_value).to eq([{ "condition" => { "gender_same_as_sex2" => 2 }, "value" => "No" }]) + end + end + + context "when person 3" do + let(:person_index) { 3 } + + it "has the correct id" do + expect(question.id).to eq("gender_same_as_sex3") + end + + it "has expected check answers card number" do + expect(question.check_answers_card_number).to eq(3) + end + + it "has the correct conditional_for" do + expect(question.conditional_for).to eq({ "gender_description3" => [2] }) + end + + it "has the correct inferred_check_answers_value" do + expect(question.inferred_check_answers_value).to eq([{ "condition" => { "gender_same_as_sex3" => 2 }, "value" => "No" }]) + end + end + + context "when person 4" do + let(:person_index) { 4 } + + it "has the correct id" do + expect(question.id).to eq("gender_same_as_sex4") + end + + it "has expected check answers card number" do + expect(question.check_answers_card_number).to eq(4) + end + + it "has the correct conditional_for" do + expect(question.conditional_for).to eq({ "gender_description4" => [2] }) + end + + it "has the correct inferred_check_answers_value" do + expect(question.inferred_check_answers_value).to eq([{ "condition" => { "gender_same_as_sex4" => 2 }, "value" => "No" }]) + end + end + + context "when person 5" do + let(:person_index) { 5 } + + it "has the correct id" do + expect(question.id).to eq("gender_same_as_sex5") + end + + it "has expected check answers card number" do + expect(question.check_answers_card_number).to eq(5) + end + + it "has the correct conditional_for" do + expect(question.conditional_for).to eq({ "gender_description5" => [2] }) + end + + it "has the correct inferred_check_answers_value" do + expect(question.inferred_check_answers_value).to eq([{ "condition" => { "gender_same_as_sex5" => 2 }, "value" => "No" }]) + end + end + + context "when person 6" do + let(:person_index) { 6 } + + it "has the correct id" do + expect(question.id).to eq("gender_same_as_sex6") + end + + it "has expected check answers card number" do + expect(question.check_answers_card_number).to eq(6) + end + + it "has the correct conditional_for" do + expect(question.conditional_for).to eq({ "gender_description6" => [2] }) + end + + it "has the correct inferred_check_answers_value" do + expect(question.inferred_check_answers_value).to eq([{ "condition" => { "gender_same_as_sex6" => 2 }, "value" => "No" }]) + 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 74ed15da4..5f1280bea 100644 --- a/spec/models/form/sales/subsections/household_characteristics_spec.rb +++ b/spec/models/form/sales/subsections/household_characteristics_spec.rb @@ -419,6 +419,7 @@ RSpec.describe Form::Sales::Subsections::HouseholdCharacteristics, type: :model age_1_old_persons_shared_ownership_joint_purchase_value_check age_1_old_persons_shared_ownership_value_check buyer_1_sex_registered_at_birth + buyer_1_gender_same_as_sex buyer_1_gender_identity buyer_1_ethnic_group buyer_1_ethnic_background_black @@ -440,6 +441,7 @@ RSpec.describe Form::Sales::Subsections::HouseholdCharacteristics, type: :model age_2_buyer_retirement_value_check age_2_buyer_not_retired_value_check buyer_2_sex_registered_at_birth + buyer_2_gender_same_as_sex buyer_2_gender_identity buyer_2_ethnic_group buyer_2_ethnic_background_black @@ -465,6 +467,7 @@ RSpec.describe Form::Sales::Subsections::HouseholdCharacteristics, type: :model age_2_not_retired_value_check age_2_partner_under_16_value_check person_2_sex_registered_at_birth + person_2_gender_same_as_sex person_2_gender_identity person_2_working_situation working_situation_2_retirement_value_check @@ -478,6 +481,7 @@ RSpec.describe Form::Sales::Subsections::HouseholdCharacteristics, type: :model age_3_not_retired_value_check age_3_partner_under_16_value_check person_3_sex_registered_at_birth + person_3_gender_same_as_sex person_3_gender_identity person_3_working_situation working_situation_3_retirement_value_check @@ -491,6 +495,7 @@ RSpec.describe Form::Sales::Subsections::HouseholdCharacteristics, type: :model age_4_not_retired_value_check age_4_partner_under_16_value_check person_4_sex_registered_at_birth + person_4_gender_same_as_sex person_4_gender_identity person_4_working_situation working_situation_4_retirement_value_check @@ -504,6 +509,7 @@ RSpec.describe Form::Sales::Subsections::HouseholdCharacteristics, type: :model age_5_not_retired_value_check age_5_partner_under_16_value_check person_5_sex_registered_at_birth + person_5_gender_same_as_sex person_5_gender_identity person_5_working_situation working_situation_5_retirement_value_check @@ -517,6 +523,7 @@ RSpec.describe Form::Sales::Subsections::HouseholdCharacteristics, type: :model age_6_not_retired_value_check age_6_partner_under_16_value_check person_6_sex_registered_at_birth + person_6_gender_same_as_sex person_6_gender_identity person_6_working_situation working_situation_6_retirement_value_check