Browse Source

CLD-1857 Update household characteristics section (#1249)

* Update datails known numbering in the db

* Update check answers card headers

* Display same person pges for joint and non-joint purchase

* Only display person questions once

* Remove unused person class and methods

* Always display person known pages and update headers

* Fix depends on, show retirement validation for buyer 2

* test

* Add person 5 to test

* fix context description

* Display person known question for appropriate number of other household members

* tests

* update test

* Remove page id stubbing

* Remove redundant tests

* only put validation on the pages that are routed to

* Refactor tests
pull/1282/head
kosiakkatrina 2 years ago committed by GitHub
parent
commit
af6b6bc03d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      app/components/check_answers_summary_list_card_component.rb
  2. 18
      app/models/form/sales/pages/person.rb
  3. 6
      app/models/form/sales/pages/person_age.rb
  4. 4
      app/models/form/sales/pages/person_gender_identity.rb
  5. 27
      app/models/form/sales/pages/person_known.rb
  6. 4
      app/models/form/sales/pages/person_relationship_to_buyer_1.rb
  7. 4
      app/models/form/sales/pages/person_working_situation.rb
  8. 1
      app/models/form/sales/pages/retirement_value_check.rb
  9. 20
      app/models/form/sales/questions/person.rb
  10. 8
      app/models/form/sales/questions/person_age.rb
  11. 16
      app/models/form/sales/questions/person_age_known.rb
  12. 8
      app/models/form/sales/questions/person_gender_identity.rb
  13. 10
      app/models/form/sales/questions/person_known.rb
  14. 8
      app/models/form/sales/questions/person_relationship_to_buyer_1.rb
  15. 8
      app/models/form/sales/questions/person_working_situation.rb
  16. 81
      app/models/form/sales/subsections/household_characteristics.rb
  17. 2
      app/models/validations/shared_validations.rb
  18. 1
      app/views/form/headers/_person_1_known_page.erb
  19. 2
      app/views/form/headers/_person_2_known_page.erb
  20. 2
      app/views/form/headers/_person_3_known_page.erb
  21. 2
      app/views/form/headers/_person_4_known_page.erb
  22. 1
      app/views/form/headers/_person_5_known_page.erb
  23. 17
      db/migrate/20230127160019_update_details_known_numbers.rb
  24. 3
      db/schema.rb
  25. 8
      spec/factories/sales_log.rb
  26. 14
      spec/features/form/check_answers_page_sales_logs_spec.rb
  27. 208
      spec/models/form/sales/pages/person_age_spec.rb
  28. 187
      spec/models/form/sales/pages/person_gender_identity_spec.rb
  29. 201
      spec/models/form/sales/pages/person_known_spec.rb
  30. 187
      spec/models/form/sales/pages/person_relationship_to_buyer1_spec.rb
  31. 189
      spec/models/form/sales/pages/person_working_situation_spec.rb
  32. 820
      spec/models/form/sales/pages/retirement_value_check_spec.rb
  33. 508
      spec/models/form/sales/questions/person_age_known_spec.rb
  34. 302
      spec/models/form/sales/questions/person_age_spec.rb
  35. 298
      spec/models/form/sales/questions/person_gender_identity_spec.rb
  36. 332
      spec/models/form/sales/questions/person_known_spec.rb
  37. 294
      spec/models/form/sales/questions/person_relationship_to_buyer1_spec.rb
  38. 298
      spec/models/form/sales/questions/person_working_situation_spec.rb
  39. 73
      spec/models/form/sales/subsections/household_characteristics_spec.rb
  40. 4
      spec/models/form_handler_spec.rb
  41. 4
      spec/models/sales_log_spec.rb
  42. 22
      spec/models/validations/shared_validations_spec.rb

2
app/components/check_answers_summary_list_card_component.rb

@ -30,7 +30,7 @@ class CheckAnswersSummaryListCardComponent < ViewComponent::Base
when 1..number_of_buyers
"Buyer #{question.check_answers_card_number}"
when (number_of_buyers + 1)..(number_of_buyers + 4)
"Person #{question.check_answers_card_number - number_of_buyers}"
"Person #{question.check_answers_card_number}"
end
end
end

18
app/models/form/sales/pages/person.rb

@ -3,22 +3,4 @@ class Form::Sales::Pages::Person < ::Form::Page
super(id, hsh, subsection)
@person_index = person_index
end
def person_display_number
joint_purchase? ? @person_index - 2 : @person_index - 1
end
def joint_purchase?
id.include?("_joint_purchase")
end
def details_known_question_id
"details_known_#{person_display_number}"
end
def field_for_person(field, suffix = "")
return [field, person_display_number, suffix].join if field == "details_known_"
[field, @person_index, suffix].join
end
end

6
app/models/form/sales/pages/person_age.rb

@ -1,13 +1,13 @@
class Form::Sales::Pages::PersonAge < Form::Sales::Pages::Person
def initialize(id, hsh, subsection, person_index:)
super
@depends_on = [{ details_known_question_id => 1, "jointpur" => joint_purchase? ? 1 : 2 }]
@depends_on = [{ "details_known_#{person_index}" => 1 }]
end
def questions
@questions ||= [
Form::Sales::Questions::PersonAgeKnown.new(field_for_person("age", "_known"), nil, self, person_index: @person_index),
Form::Sales::Questions::PersonAge.new(field_for_person("age"), nil, self, person_index: @person_index),
Form::Sales::Questions::PersonAgeKnown.new("age#{@person_index}_known", nil, self, person_index: @person_index),
Form::Sales::Questions::PersonAge.new("age#{@person_index}", nil, self, person_index: @person_index),
]
end
end

4
app/models/form/sales/pages/person_gender_identity.rb

@ -2,13 +2,13 @@ class Form::Sales::Pages::PersonGenderIdentity < Form::Sales::Pages::Person
def initialize(id, hsh, subsection, person_index:)
super
@depends_on = [
{ details_known_question_id => 1, "jointpur" => joint_purchase? ? 1 : 2 },
{ "details_known_#{person_index}" => 1 },
]
end
def questions
@questions ||= [
Form::Sales::Questions::PersonGenderIdentity.new(field_for_person("sex"), nil, self, person_index: @person_index),
Form::Sales::Questions::PersonGenderIdentity.new("sex#{@person_index}", nil, self, person_index: @person_index),
]
end
end

27
app/models/form/sales/pages/person_known.rb

@ -1,13 +1,34 @@
class Form::Sales::Pages::PersonKnown < Form::Sales::Pages::Person
def initialize(id, hsh, subsection, person_index:)
super
@header_partial = "person_#{person_display_number}_known_page"
@depends_on = (person_display_number..4).map { |index| { "hholdcount" => index, "jointpur" => joint_purchase? ? 1 : 2 } }
@header_partial = "person_#{person_index}_known_page"
@depends_on = depends_on
end
def questions
@questions ||= [
Form::Sales::Questions::PersonKnown.new(field_for_person("details_known_"), nil, self, person_index: @person_index),
Form::Sales::Questions::PersonKnown.new("details_known_#{@person_index}", nil, self, person_index: @person_index),
]
end
def depends_on
if @person_index == 2
[{ "jointpur" => 2,
"hholdcount" => {
"operator" => ">=",
"operand" => 1,
} }]
else
[{ "jointpur" => 2,
"hholdcount" => {
"operator" => ">=",
"operand" => @person_index - 1,
} },
{ "jointpur" => 1,
"hholdcount" => {
"operator" => ">=",
"operand" => @person_index - 2,
} }]
end
end
end

4
app/models/form/sales/pages/person_relationship_to_buyer_1.rb

@ -2,13 +2,13 @@ class Form::Sales::Pages::PersonRelationshipToBuyer1 < ::Form::Sales::Pages::Per
def initialize(id, hsh, subsection, person_index:)
super
@depends_on = [
{ details_known_question_id => 1, "jointpur" => joint_purchase? ? 1 : 2 },
{ "details_known_#{person_index}" => 1 },
]
end
def questions
@questions ||= [
Form::Sales::Questions::PersonRelationshipToBuyer1.new(field_for_person("relat"), nil, self, person_index: @person_index),
Form::Sales::Questions::PersonRelationshipToBuyer1.new("relat#{@person_index}", nil, self, person_index: @person_index),
]
end
end

4
app/models/form/sales/pages/person_working_situation.rb

@ -1,12 +1,12 @@
class Form::Sales::Pages::PersonWorkingSituation < Form::Sales::Pages::Person
def initialize(id, hsh, subsection, person_index:)
super
@depends_on = [{ details_known_question_id => 1, "jointpur" => joint_purchase? ? 1 : 2 }]
@depends_on = [{ "details_known_#{person_index}" => 1 }]
end
def questions
@questions ||= [
Form::Sales::Questions::PersonWorkingSituation.new(field_for_person("ecstat"), nil, self, person_index: @person_index),
Form::Sales::Questions::PersonWorkingSituation.new("ecstat#{@person_index}", nil, self, person_index: @person_index),
]
end
end

1
app/models/form/sales/pages/retirement_value_check.rb

@ -4,7 +4,6 @@ class Form::Sales::Pages::RetirementValueCheck < Form::Sales::Pages::Person
@depends_on = [
{
"person_#{person_index}_retired_under_soft_min_age?" => true,
"jointpur" => joint_purchase? ? 1 : 2,
},
]
@person_index = person_index

20
app/models/form/sales/questions/person.rb

@ -1,20 +0,0 @@
class Form::Sales::Questions::Person < ::Form::Question
def initialize(id, hsh, page, person_index:)
super(id, hsh, page)
@person_index = person_index
end
def person_display_number
joint_purchase? ? @person_index - 2 : @person_index - 1
end
def joint_purchase?
page.id.include?("_joint_purchase")
end
def field_for_person(field, suffix = "")
return [field, person_display_number, suffix].join if field == "details_known_"
[field, @person_index, suffix].join
end
end

8
app/models/form/sales/questions/person_age.rb

@ -1,12 +1,12 @@
class Form::Sales::Questions::PersonAge < Form::Sales::Questions::Person
class Form::Sales::Questions::PersonAge < ::Form::Question
def initialize(id, hsh, page, person_index:)
super
@check_answer_label = "Person #{person_display_number}’s age"
super(id, hsh, page)
@check_answer_label = "Person #{person_index}’s age"
@header = "Age"
@type = "numeric"
@width = 3
@inferred_check_answers_value = [{
"condition" => { field_for_person("age", "_known") => 1 },
"condition" => { "age#{person_index}_known" => 1 },
"value" => "Not known",
}]
@check_answers_card_number = person_index

16
app/models/form/sales/questions/person_age_known.rb

@ -1,24 +1,24 @@
class Form::Sales::Questions::PersonAgeKnown < ::Form::Sales::Questions::Person
class Form::Sales::Questions::PersonAgeKnown < ::Form::Question
def initialize(id, hsh, page, person_index:)
super
@check_answer_label = "Person #{person_display_number}’s age known?"
@header = "Do you know person #{person_display_number}’s age?"
super(id, hsh, page)
@check_answer_label = "Person #{person_index}’s age known?"
@header = "Do you know person #{person_index}’s age?"
@type = "radio"
@answer_options = ANSWER_OPTIONS
@conditional_for = {
field_for_person("age") => [0],
"age#{person_index}" => [0],
}
@hidden_in_check_answers = {
"depends_on" => [
{
field_for_person("age", "_known") => 0,
"age#{person_index}_known" => 0,
},
{
field_for_person("age", "_known") => 1,
"age#{person_index}_known" => 1,
},
],
}
@check_answers_card_number = @person_index
@check_answers_card_number = person_index
end
ANSWER_OPTIONS = {

8
app/models/form/sales/questions/person_gender_identity.rb

@ -1,8 +1,8 @@
class Form::Sales::Questions::PersonGenderIdentity < ::Form::Sales::Questions::Person
class Form::Sales::Questions::PersonGenderIdentity < ::Form::Question
def initialize(id, hsh, page, person_index:)
super
@check_answer_label = "Person #{person_display_number}’s gender identity"
@header = "Which of these best describes Person #{person_display_number}’s gender identity?"
super(id, hsh, page)
@check_answer_label = "Person #{person_index}’s gender identity"
@header = "Which of these best describes Person #{person_index}’s gender identity?"
@type = "radio"
@answer_options = ANSWER_OPTIONS
@check_answers_card_number = person_index

10
app/models/form/sales/questions/person_known.rb

@ -1,14 +1,14 @@
class Form::Sales::Questions::PersonKnown < Form::Sales::Questions::Person
class Form::Sales::Questions::PersonKnown < ::Form::Question
def initialize(id, hsh, page, person_index:)
super
@check_answer_label = "Details known for person #{person_display_number}?"
@header = "Do you know the details for person #{person_display_number}?"
super(id, hsh, page)
@check_answer_label = "Details known for person #{person_index}?"
@header = "Do you know the details for person #{person_index}?"
@type = "radio"
@answer_options = ANSWER_OPTIONS
@hidden_in_check_answers = {
"depends_on" => [
{
field_for_person("details_known_") => 1,
"details_known_#{person_index}" => 1,
},
],
}

8
app/models/form/sales/questions/person_relationship_to_buyer_1.rb

@ -1,8 +1,8 @@
class Form::Sales::Questions::PersonRelationshipToBuyer1 < ::Form::Sales::Questions::Person
class Form::Sales::Questions::PersonRelationshipToBuyer1 < ::Form::Question
def initialize(id, hsh, page, person_index:)
super
@check_answer_label = "Person #{person_display_number}’s relationship to Buyer 1"
@header = "What is Person #{person_display_number}’s relationship to Buyer 1?"
super(id, hsh, page)
@check_answer_label = "Person #{person_index}’s relationship to Buyer 1"
@header = "What is Person #{person_index}’s relationship to Buyer 1?"
@type = "radio"
@answer_options = ANSWER_OPTIONS
@check_answers_card_number = person_index

8
app/models/form/sales/questions/person_working_situation.rb

@ -1,8 +1,8 @@
class Form::Sales::Questions::PersonWorkingSituation < ::Form::Sales::Questions::Person
class Form::Sales::Questions::PersonWorkingSituation < ::Form::Question
def initialize(id, hsh, page, person_index:)
super
@check_answer_label = "Person #{person_display_number}’s working situation"
@header = "Which of these best describes Person #{person_display_number}’s working situation?"
super(id, hsh, page)
@check_answer_label = "Person #{person_index}’s working situation"
@header = "Which of these best describes Person #{person_index}’s working situation?"
@type = "radio"
@answer_options = ANSWER_OPTIONS
@check_answers_card_number = person_index

81
app/models/form/sales/subsections/household_characteristics.rb

@ -12,11 +12,9 @@ class Form::Sales::Subsections::HouseholdCharacteristics < ::Form::Subsection
Form::Sales::Pages::PrivacyNotice.new(nil, nil, self),
Form::Sales::Pages::Age1.new(nil, nil, self),
Form::Sales::Pages::RetirementValueCheck.new("age_1_retirement_value_check", nil, self, person_index: 1),
Form::Sales::Pages::RetirementValueCheck.new("age_1_retirement_value_check_joint_purchase", nil, self, person_index: 1),
Form::Sales::Pages::OldPersonsSharedOwnershipValueCheck.new("age_1_old_persons_shared_ownership_value_check", nil, self),
Form::Sales::Pages::GenderIdentity1.new(nil, nil, self),
Form::Sales::Pages::RetirementValueCheck.new("gender_1_retirement_value_check", nil, self, person_index: 1),
Form::Sales::Pages::RetirementValueCheck.new("gender_1_retirement_value_check_joint_purchase", nil, self, person_index: 1),
Form::Sales::Pages::Buyer1EthnicGroup.new(nil, nil, self),
Form::Sales::Pages::Buyer1EthnicBackgroundBlack.new(nil, nil, self),
Form::Sales::Pages::Buyer1EthnicBackgroundAsian.new(nil, nil, self),
@ -26,83 +24,50 @@ class Form::Sales::Subsections::HouseholdCharacteristics < ::Form::Subsection
Form::Sales::Pages::Nationality1.new(nil, nil, self),
Form::Sales::Pages::Buyer1WorkingSituation.new(nil, nil, self),
Form::Sales::Pages::RetirementValueCheck.new("working_situation_1_retirement_value_check", nil, self, person_index: 1),
Form::Sales::Pages::RetirementValueCheck.new("working_situation_1_retirement_value_check_joint_purchase", nil, self, person_index: 1),
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::Age2.new(nil, nil, self),
Form::Sales::Pages::RetirementValueCheck.new("age_2_retirement_value_check_joint_purchase", nil, self, person_index: 2),
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::GenderIdentity2.new(nil, nil, self),
Form::Sales::Pages::RetirementValueCheck.new("gender_2_retirement_value_check_joint_purchase", nil, self, person_index: 2),
Form::Sales::Pages::RetirementValueCheck.new("gender_2_buyer_retirement_value_check", nil, self, person_index: 2),
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::RetirementValueCheck.new("working_situation_2_buyer_retirement_value_check", nil, self, person_index: 2),
Form::Sales::Pages::Buyer2LiveInProperty.new(nil, nil, self),
Form::Sales::Pages::NumberOfOthersInProperty.new(nil, nil, self),
Form::Sales::Pages::PersonKnown.new("person_1_known", nil, self, person_index: 2),
Form::Sales::Pages::PersonKnown.new("person_1_known_joint_purchase", nil, self, person_index: 3),
Form::Sales::Pages::PersonRelationshipToBuyer1.new("person_1_relationship_to_buyer_1", nil, self, person_index: 2),
Form::Sales::Pages::PersonRelationshipToBuyer1.new("person_1_relationship_to_buyer_1_joint_purchase", nil, self, person_index: 3),
Form::Sales::Pages::PersonAge.new("person_1_age", nil, self, person_index: 2),
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::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::PersonAge.new("person_1_age_joint_purchase", nil, self, person_index: 3),
Form::Sales::Pages::RetirementValueCheck.new("age_3_retirement_value_check_joint_purchase", nil, self, person_index: 3),
Form::Sales::Pages::PersonGenderIdentity.new("person_1_gender_identity", 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::PersonGenderIdentity.new("person_1_gender_identity_joint_purchase", nil, self, person_index: 3),
Form::Sales::Pages::RetirementValueCheck.new("gender_3_retirement_value_check_joint_purchase", nil, self, person_index: 3),
Form::Sales::Pages::PersonWorkingSituation.new("person_1_working_situation", 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::PersonWorkingSituation.new("person_1_working_situation_joint_purchase", nil, self, person_index: 3),
Form::Sales::Pages::RetirementValueCheck.new("working_situation_3_retirement_value_check_joint_purchase", nil, self, person_index: 3),
Form::Sales::Pages::PersonKnown.new("person_2_known", nil, self, person_index: 3),
Form::Sales::Pages::PersonKnown.new("person_2_known_joint_purchase", nil, self, person_index: 4),
Form::Sales::Pages::PersonRelationshipToBuyer1.new("person_2_relationship_to_buyer_1", nil, self, person_index: 3),
Form::Sales::Pages::PersonRelationshipToBuyer1.new("person_2_relationship_to_buyer_1_joint_purchase", nil, self, person_index: 4),
Form::Sales::Pages::PersonAge.new("person_2_age", nil, self, person_index: 3),
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::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::PersonAge.new("person_2_age_joint_purchase", nil, self, person_index: 4),
Form::Sales::Pages::RetirementValueCheck.new("age_4_retirement_value_check_joint_purchase", nil, self, person_index: 4),
Form::Sales::Pages::PersonGenderIdentity.new("person_2_gender_identity", 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::PersonGenderIdentity.new("person_2_gender_identity_joint_purchase", nil, self, person_index: 4),
Form::Sales::Pages::RetirementValueCheck.new("gender_4_retirement_value_check_joint_purchase", nil, self, person_index: 4),
Form::Sales::Pages::PersonWorkingSituation.new("person_2_working_situation", 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::PersonWorkingSituation.new("person_2_working_situation_joint_purchase", nil, self, person_index: 4),
Form::Sales::Pages::RetirementValueCheck.new("working_situation_4_retirement_value_check_joint_purchase", nil, self, person_index: 4),
Form::Sales::Pages::PersonKnown.new("person_3_known", nil, self, person_index: 4),
Form::Sales::Pages::PersonKnown.new("person_3_known_joint_purchase", nil, self, person_index: 5),
Form::Sales::Pages::PersonRelationshipToBuyer1.new("person_3_relationship_to_buyer_1", nil, self, person_index: 4),
Form::Sales::Pages::PersonRelationshipToBuyer1.new("person_3_relationship_to_buyer_1_joint_purchase", nil, self, person_index: 5),
Form::Sales::Pages::PersonAge.new("person_3_age", nil, self, person_index: 4),
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::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::PersonAge.new("person_3_age_joint_purchase", nil, self, person_index: 5),
Form::Sales::Pages::RetirementValueCheck.new("age_5_retirement_value_check_joint_purchase", nil, self, person_index: 5),
Form::Sales::Pages::PersonGenderIdentity.new("person_3_gender_identity", 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::PersonGenderIdentity.new("person_3_gender_identity_joint_purchase", nil, self, person_index: 5),
Form::Sales::Pages::RetirementValueCheck.new("gender_5_retirement_value_check_joint_purchase", nil, self, person_index: 5),
Form::Sales::Pages::PersonWorkingSituation.new("person_3_working_situation", 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::PersonWorkingSituation.new("person_3_working_situation_joint_purchase", nil, self, person_index: 5),
Form::Sales::Pages::RetirementValueCheck.new("working_situation_5_retirement_value_check_joint_purchase", nil, self, person_index: 5),
Form::Sales::Pages::PersonKnown.new("person_4_known", nil, self, person_index: 5),
Form::Sales::Pages::PersonKnown.new("person_4_known_joint_purchase", nil, self, person_index: 6),
Form::Sales::Pages::PersonRelationshipToBuyer1.new("person_4_relationship_to_buyer_1", nil, self, person_index: 5),
Form::Sales::Pages::PersonRelationshipToBuyer1.new("person_4_relationship_to_buyer_1_joint_purchase", nil, self, person_index: 6),
Form::Sales::Pages::PersonAge.new("person_4_age", nil, self, person_index: 5),
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::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::PersonAge.new("person_4_age_joint_purchase", nil, self, person_index: 6),
Form::Sales::Pages::RetirementValueCheck.new("age_6_retirement_value_check_joint_purchase", nil, self, person_index: 6),
Form::Sales::Pages::PersonGenderIdentity.new("person_4_gender_identity", 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::PersonGenderIdentity.new("person_4_gender_identity_joint_purchase", nil, self, person_index: 6),
Form::Sales::Pages::RetirementValueCheck.new("gender_6_retirement_value_check_joint_purchase", nil, self, person_index: 6),
Form::Sales::Pages::PersonWorkingSituation.new("person_4_working_situation", 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::PersonWorkingSituation.new("person_4_working_situation_joint_purchase", nil, self, person_index: 6),
Form::Sales::Pages::RetirementValueCheck.new("working_situation_6_retirement_value_check_joint_purchase", nil, self, person_index: 6),
]
end
end

2
app/models/validations/shared_validations.rb

@ -18,7 +18,7 @@ module Validations::SharedValidations
def validate_numeric_min_max(record)
record.form.numeric_questions.each do |question|
next unless question.min || question.max
next unless record[question.id]
next unless record[question.id] && question.page.routed_to?(record, nil)
begin
answer = Float(record.public_send("#{question.id}_before_type_cast"))

1
app/views/form/headers/_person_1_known_page.erb

@ -1 +0,0 @@
You have given us the details for 0 of the <%= log.hholdcount %> other people in the household

2
app/views/form/headers/_person_2_known_page.erb

@ -1 +1 @@
You have given us the details for 1 of the <%= log.hholdcount %> other people in the household
You have given us the details for 0 of the <%= log.hholdcount %> other people in the household

2
app/views/form/headers/_person_3_known_page.erb

@ -1 +1 @@
You have given us the details for 2 of the <%= log.hholdcount %> other people in the household
You have given us the details for <%= log.joint_purchase? ? 0 : 1 %> of the <%= log.hholdcount %> other people in the household

2
app/views/form/headers/_person_4_known_page.erb

@ -1 +1 @@
You have given us the details for 3 of the <%= log.hholdcount %> other people in the household
You have given us the details for <%= log.joint_purchase? ? 1 : 2 %> of the <%= log.hholdcount %> other people in the household

1
app/views/form/headers/_person_5_known_page.erb

@ -0,0 +1 @@
You have given us the details for <%= log.joint_purchase? ? 2 : 3 %> of the <%= log.hholdcount %> other people in the household

17
db/migrate/20230127160019_update_details_known_numbers.rb

@ -0,0 +1,17 @@
class UpdateDetailsKnownNumbers < ActiveRecord::Migration[7.0]
def up
change_table :sales_logs, bulk: true do |t|
t.remove :details_known_1
t.column :details_known_5, :integer
t.column :details_known_6, :integer
end
end
def down
change_table :sales_logs, bulk: true do |t|
t.column :details_known_1, :integer
t.remove :details_known_5
t.remove :details_known_6
end
end
end

3
db/schema.rb

@ -433,7 +433,6 @@ ActiveRecord::Schema[7.0].define(version: 2023_02_03_104238) do
t.integer "prevown"
t.string "sex3"
t.bigint "updated_by_id"
t.integer "details_known_1"
t.integer "income1_value_check"
t.decimal "mortgage", precision: 10, scale: 2
t.integer "inc2mort"
@ -523,6 +522,8 @@ ActiveRecord::Schema[7.0].define(version: 2023_02_03_104238) do
t.integer "staircase_bought_value_check"
t.integer "monthly_charges_value_check"
t.integer "saledate_check"
t.integer "details_known_5"
t.integer "details_known_6"
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 ["owning_organisation_id"], name: "index_sales_logs_on_owning_organisation_id"

8
spec/factories/sales_log.rb

@ -38,16 +38,16 @@ FactoryBot.define do
ecstat2 { "1" }
hholdcount { "1" }
wheel { 1 }
details_known_1 { 1 }
details_known_3 { 1 }
age3_known { 0 }
age3 { 14 }
details_known_2 { 1 }
details_known_4 { 1 }
age4_known { 0 }
age4 { 18 }
details_known_3 { 1 }
details_known_5 { 1 }
age5_known { 0 }
age5 { 40 }
details_known_4 { 1 }
details_known_6 { 1 }
age6_known { 0 }
age6 { 40 }
income1nk { 0 }

14
spec/features/form/check_answers_page_sales_logs_spec.rb

@ -13,6 +13,7 @@ RSpec.describe "Sales Log Check Answers Page" do
:completed,
created_by: user,
jointpur: 1,
hholdcount: 4,
)
end
@ -22,6 +23,7 @@ RSpec.describe "Sales Log Check Answers Page" do
:completed,
created_by: user,
jointpur: 2,
hholdcount: 4,
)
end
@ -43,8 +45,11 @@ RSpec.describe "Sales Log Check Answers Page" do
visit("/sales-logs/#{completed_sales_log_joint_purchase.id}/#{subsection}/check-answers")
assert_selector ".x-govuk-summary-card__title", text: "Buyer 1", count: 1
assert_selector ".x-govuk-summary-card__title", text: "Buyer 2", count: 1
assert_selector ".x-govuk-summary-card__title", text: "Person 1", count: 1
assert_selector ".x-govuk-summary-card__title", text: "Person 1", count: 0
assert_selector ".x-govuk-summary-card__title", text: "Person 2", count: 0
assert_selector ".x-govuk-summary-card__title", text: "Person 3", count: 1
assert_selector ".x-govuk-summary-card__title", text: "Person 4", count: 1
assert_selector ".x-govuk-summary-card__title", text: "Person 5", count: 1
end
end
@ -53,8 +58,11 @@ RSpec.describe "Sales Log Check Answers Page" do
visit("/sales-logs/#{completed_sales_log_non_joint_purchase.id}/#{subsection}/check-answers")
assert_selector ".x-govuk-summary-card__title", text: "Buyer 1", count: 1
assert_selector ".x-govuk-summary-card__title", text: "Buyer 2", count: 0
assert_selector ".x-govuk-summary-card__title", text: "Person 1", count: 1
assert_selector ".x-govuk-summary-card__title", text: "Person 2", count: 0
assert_selector ".x-govuk-summary-card__title", text: "Person 1", count: 0
assert_selector ".x-govuk-summary-card__title", text: "Person 2", count: 1
assert_selector ".x-govuk-summary-card__title", text: "Person 3", count: 1
assert_selector ".x-govuk-summary-card__title", text: "Person 4", count: 1
assert_selector ".x-govuk-summary-card__title", text: "Person 5", count: 1
end
end
end

208
spec/models/form/sales/pages/person_age_spec.rb

@ -20,171 +20,85 @@ RSpec.describe Form::Sales::Pages::PersonAge, type: :model do
expect(page.description).to be_nil
end
context "with a non joint purchase" do
context "and person 1" do
let(:page_id) { "person_1_age" }
let(:person_index) { 2 }
it "has correct questions" do
expect(page.questions.map(&:id)).to eq(%w[age2_known age2])
end
it "has the correct id" do
expect(page.id).to eq("person_1_age")
end
it "has correct depends_on" do
expect(page.depends_on).to eq(
[{ "details_known_1" => 1, "jointpur" => 2 }],
)
end
context "with person 2" do
let(:page_id) { "person_2_age" }
let(:person_index) { 2 }
it "has correct questions" do
expect(page.questions.map(&:id)).to eq(%w[age2_known age2])
end
it "has the correct id" do
expect(page.id).to eq("person_2_age")
end
context "and person 2" do
let(:page_id) { "person_2_age" }
let(:person_index) { 3 }
it "has correct questions" do
expect(page.questions.map(&:id)).to eq(%w[age3_known age3])
end
it "has the correct id" do
expect(page.id).to eq("person_2_age")
end
it "has correct depends_on" do
expect(page.depends_on).to eq(
[
{ "details_known_2" => 1, "jointpur" => 2 },
],
)
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(:page_id) { "person_3_age" }
let(:person_index) { 3 }
context "and person 3" do
let(:page_id) { "person_3_age" }
let(:person_index) { 4 }
it "has correct questions" do
expect(page.questions.map(&:id)).to eq(%w[age4_known age4])
end
it "has the correct id" do
expect(page.id).to eq("person_3_age")
end
it "has correct depends_on" do
expect(page.depends_on).to eq(
[
{ "details_known_3" => 1, "jointpur" => 2 },
],
)
end
it "has correct questions" do
expect(page.questions.map(&:id)).to eq(%w[age3_known age3])
end
context "and person 4" do
let(:page_id) { "person_4_age" }
let(:person_index) { 5 }
it "has correct questions" do
expect(page.questions.map(&:id)).to eq(%w[age5_known age5])
end
it "has the correct id" do
expect(page.id).to eq("person_4_age")
end
it "has correct depends_on" do
expect(page.depends_on).to eq(
[
{ "details_known_4" => 1, "jointpur" => 2 },
],
)
end
it "has the correct id" do
expect(page.id).to eq("person_3_age")
end
it "has correct depends_on" do
expect(page.depends_on).to eq(
[
{ "details_known_3" => 1 },
],
)
end
end
context "with joint purchase" do
context "and person 1" do
let(:page_id) { "person_1_age_joint_purchase" }
let(:person_index) { 3 }
context "with person 4" do
let(:page_id) { "person_4_age" }
let(:person_index) { 4 }
it "has correct questions" do
expect(page.questions.map(&:id)).to eq(%w[age3_known age3])
end
it "has correct questions" do
expect(page.questions.map(&:id)).to eq(%w[age4_known age4])
end
it "has the correct id" do
expect(page.id).to eq("person_1_age_joint_purchase")
end
it "has the correct id" do
expect(page.id).to eq("person_4_age")
end
it "has correct depends_on" do
expect(page.depends_on).to eq(
[{ "details_known_1" => 1, "jointpur" => 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(:page_id) { "person_5_age" }
let(:person_index) { 5 }
context "and person 2" do
let(:page_id) { "person_2_age_joint_purchase" }
let(:person_index) { 4 }
it "has correct questions" do
expect(page.questions.map(&:id)).to eq(%w[age4_known age4])
end
it "has the correct id" do
expect(page.id).to eq("person_2_age_joint_purchase")
end
it "has correct depends_on" do
expect(page.depends_on).to eq(
[
{ "details_known_2" => 1, "jointpur" => 1 },
],
)
end
it "has correct questions" do
expect(page.questions.map(&:id)).to eq(%w[age5_known age5])
end
context "and person 3" do
let(:page_id) { "person_3_age_joint_purchase" }
let(:person_index) { 5 }
it "has correct questions" do
expect(page.questions.map(&:id)).to eq(%w[age5_known age5])
end
it "has the correct id" do
expect(page.id).to eq("person_3_age_joint_purchase")
end
it "has correct depends_on" do
expect(page.depends_on).to eq(
[
{ "details_known_3" => 1, "jointpur" => 1 },
],
)
end
it "has the correct id" do
expect(page.id).to eq("person_5_age")
end
context "and person 4" do
let(:page_id) { "person_4_age_joint_purchase" }
let(:person_index) { 6 }
it "has correct questions" do
expect(page.questions.map(&:id)).to eq(%w[age6_known age6])
end
it "has the correct id" do
expect(page.id).to eq("person_4_age_joint_purchase")
end
it "has correct depends_on" do
expect(page.depends_on).to eq(
[
{ "details_known_4" => 1, "jointpur" => 1 },
],
)
end
it "has correct depends_on" do
expect(page.depends_on).to eq(
[
{ "details_known_5" => 1 },
],
)
end
end
end

187
spec/models/form/sales/pages/person_gender_identity_spec.rb

@ -7,172 +7,85 @@ RSpec.describe Form::Sales::Pages::PersonGenderIdentity, type: :model do
let(:subsection) { instance_double(Form::Subsection) }
let(:person_index) { 1 }
context "without joint purchase" do
let(:page_id) { "person_1_working_situation" }
let(:page_id) { "person_2_gender_identity" }
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
context "with person 1" do
let(:person_index) { 2 }
let(:page_id) { "person_1_gender_identity" }
it "has correct questions" do
expect(page.questions.map(&:id)).to eq(%w[sex2])
end
it "has the correct id" do
expect(page.id).to eq("person_1_gender_identity")
end
it "has correct depends_on" do
expect(page.depends_on).to eq([{ "details_known_1" => 1, "jointpur" => 2 }])
end
end
it "has correct subsection" do
expect(page.subsection).to eq(subsection)
end
context "with person 2" do
let(:person_index) { 3 }
let(:page_id) { "person_2_gender_identity" }
it "has the correct header" do
expect(page.header).to be_nil
end
it "has correct questions" do
expect(page.questions.map(&:id)).to eq(%w[sex3])
end
it "has the correct description" do
expect(page.description).to be_nil
end
it "has the correct id" do
expect(page.id).to eq("person_2_gender_identity")
end
context "with person 2 " do
let(:person_index) { 2 }
let(:page_id) { "person_2_gender_identity" }
it "has correct depends_on" do
expect(page.depends_on).to eq([{ "details_known_2" => 1, "jointpur" => 2 }])
end
it "has correct questions" do
expect(page.questions.map(&:id)).to eq(%w[sex2])
end
context "with person 3" do
let(:person_index) { 4 }
let(:page_id) { "person_3_gender_identity" }
it "has correct questions" do
expect(page.questions.map(&:id)).to eq(%w[sex4])
end
it "has the correct id" do
expect(page.id).to eq("person_3_gender_identity")
end
it "has correct depends_on" do
expect(page.depends_on).to eq([{ "details_known_3" => 1, "jointpur" => 2 }])
end
it "has the correct id" do
expect(page.id).to eq("person_2_gender_identity")
end
context "with person 4" do
let(:person_index) { 5 }
let(:page_id) { "person_4_gender_identity" }
it "has correct questions" do
expect(page.questions.map(&:id)).to eq(%w[sex5])
end
it "has the correct id" do
expect(page.id).to eq("person_4_gender_identity")
end
it "has correct depends_on" do
expect(page.depends_on).to eq([{ "details_known_4" => 1, "jointpur" => 2 }])
end
it "has correct depends_on" do
expect(page.depends_on).to eq([{ "details_known_2" => 1 }])
end
end
context "with joint purchase" do
let(:page_id) { "person_1_gender_identity_joint_purchase" }
context "with person 3" do
let(:person_index) { 3 }
let(:page_id) { "person_3_gender_identity" }
it "has correct subsection" do
expect(page.subsection).to eq(subsection)
it "has correct questions" do
expect(page.questions.map(&:id)).to eq(%w[sex3])
end
it "has the correct header" do
expect(page.header).to be_nil
it "has the correct id" do
expect(page.id).to eq("person_3_gender_identity")
end
it "has the correct description" do
expect(page.description).to be_nil
it "has correct depends_on" do
expect(page.depends_on).to eq([{ "details_known_3" => 1 }])
end
end
context "with person 1" do
let(:person_index) { 3 }
let(:page_id) { "person_1_gender_identity_joint_purchase" }
it "has correct questions" do
expect(page.questions.map(&:id)).to eq(%w[sex3])
end
it "has the correct id" do
expect(page.id).to eq("person_1_gender_identity_joint_purchase")
end
context "with person 4" do
let(:person_index) { 4 }
let(:page_id) { "person_4_gender_identity" }
it "has correct depends_on" do
expect(page.depends_on).to eq([{ "details_known_1" => 1, "jointpur" => 1 }])
end
it "has correct questions" do
expect(page.questions.map(&:id)).to eq(%w[sex4])
end
context "with person 2" do
let(:person_index) { 4 }
let(:page_id) { "person_2_gender_identity_joint_purchase" }
it "has correct questions" do
expect(page.questions.map(&:id)).to eq(%w[sex4])
end
it "has the correct id" do
expect(page.id).to eq("person_2_gender_identity_joint_purchase")
end
it "has correct depends_on" do
expect(page.depends_on).to eq([{ "details_known_2" => 1, "jointpur" => 1 }])
end
it "has the correct id" do
expect(page.id).to eq("person_4_gender_identity")
end
context "with person 3" do
let(:person_index) { 5 }
let(:page_id) { "person_3_gender_identity_joint_purchase" }
it "has correct questions" do
expect(page.questions.map(&:id)).to eq(%w[sex5])
end
it "has the correct id" do
expect(page.id).to eq("person_3_gender_identity_joint_purchase")
end
it "has correct depends_on" do
expect(page.depends_on).to eq([{ "details_known_3" => 1, "jointpur" => 1 }])
end
it "has correct depends_on" do
expect(page.depends_on).to eq([{ "details_known_4" => 1 }])
end
end
context "with person 4" do
let(:person_index) { 6 }
let(:page_id) { "person_4_gender_identity_joint_purchase" }
context "with person 5" do
let(:person_index) { 5 }
let(:page_id) { "person_5_gender_identity" }
it "has correct questions" do
expect(page.questions.map(&:id)).to eq(%w[sex6])
end
it "has correct questions" do
expect(page.questions.map(&:id)).to eq(%w[sex5])
end
it "has the correct id" do
expect(page.id).to eq("person_4_gender_identity_joint_purchase")
end
it "has the correct id" do
expect(page.id).to eq("person_5_gender_identity")
end
it "has correct depends_on" do
expect(page.depends_on).to eq([{ "details_known_4" => 1, "jointpur" => 1 }])
end
it "has correct depends_on" do
expect(page.depends_on).to eq([{ "details_known_5" => 1 }])
end
end
end

201
spec/models/form/sales/pages/person_known_spec.rb

@ -7,7 +7,7 @@ RSpec.describe Form::Sales::Pages::PersonKnown, type: :model do
let(:page_id) { "person_2_known" }
let(:page_definition) { nil }
let(:subsection) { instance_double(Form::Subsection) }
let(:person_index) { 3 }
let(:person_index) { 2 }
it "has correct subsection" do
expect(page.subsection).to eq(subsection)
@ -21,34 +21,9 @@ RSpec.describe Form::Sales::Pages::PersonKnown, type: :model do
expect(page.description).to be_nil
end
context "with person 1" do
let(:page_id) { "person_1_known" }
let(:person_index) { 2 }
it "has correct questions" do
expect(page.questions.map(&:id)).to eq(%w[details_known_1])
end
it "has the correct id" do
expect(page.id).to eq("person_1_known")
end
it "has the correct header_partial" do
expect(page.header_partial).to eq("person_1_known_page")
end
it "has correct depends_on" do
expect(page.depends_on).to eq(
[
{ "hholdcount" => 1, "jointpur" => 2 }, { "hholdcount" => 2, "jointpur" => 2 }, { "hholdcount" => 3, "jointpur" => 2 }, { "hholdcount" => 4, "jointpur" => 2 }
],
)
end
end
context "with person 2" do
let(:page_id) { "person_2_known" }
let(:person_index) { 3 }
let(:person_index) { 2 }
it "has correct questions" do
expect(page.questions.map(&:id)).to eq(%w[details_known_2])
@ -63,15 +38,19 @@ RSpec.describe Form::Sales::Pages::PersonKnown, type: :model do
end
it "has correct depends_on" do
expect(page.depends_on).to eq(
[{ "hholdcount" => 2, "jointpur" => 2 }, { "hholdcount" => 3, "jointpur" => 2 }, { "hholdcount" => 4, "jointpur" => 2 }],
)
expect(page.depends_on).to eq([{
"jointpur" => 2,
"hholdcount" => {
"operator" => ">=",
"operand" => 1,
},
}])
end
end
context "with person 3" do
let(:page_id) { "person_3_known" }
let(:person_index) { 4 }
let(:person_index) { 3 }
it "has correct questions" do
expect(page.questions.map(&:id)).to eq(%w[details_known_3])
@ -86,15 +65,29 @@ RSpec.describe Form::Sales::Pages::PersonKnown, type: :model do
end
it "has correct depends_on" do
expect(page.depends_on).to eq(
[{ "hholdcount" => 3, "jointpur" => 2 }, { "hholdcount" => 4, "jointpur" => 2 }],
)
expect(page.depends_on).to eq([
{
"jointpur" => 2,
"hholdcount" => {
"operator" => ">=",
"operand" => 2,
},
},
{
"jointpur" => 1,
"hholdcount" => {
"operator" => ">=",
"operand" => 1,
},
},
])
end
end
context "with person 4" do
let(:page_id) { "person_4_known" }
let(:person_index) { 5 }
let(:person_index) { 4 }
it "has correct questions" do
expect(page.questions.map(&:id)).to eq(%w[details_known_4])
@ -109,122 +102,58 @@ RSpec.describe Form::Sales::Pages::PersonKnown, type: :model do
end
it "has correct depends_on" do
expect(page.depends_on).to eq(
[{ "hholdcount" => 4, "jointpur" => 2 }],
)
expect(page.depends_on).to eq([
{
"jointpur" => 2,
"hholdcount" => {
"operator" => ">=",
"operand" => 3,
},
},
{
"jointpur" => 1,
"hholdcount" => {
"operator" => ">=",
"operand" => 2,
},
},
])
end
end
end
context "with joint purchase" do
let(:page_id) { "person_2_known" }
let(:page_definition) { nil }
let(:subsection) { instance_double(Form::Subsection) }
let(:person_index) { 4 }
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
context "with person 1" do
let(:page_id) { "person_1_known_joint_purchase" }
let(:person_index) { 3 }
it "has correct questions" do
expect(page.questions.map(&:id)).to eq(%w[details_known_1])
end
it "has the correct id" do
expect(page.id).to eq("person_1_known_joint_purchase")
end
it "has the correct header_partial" do
expect(page.header_partial).to eq("person_1_known_page")
end
it "has correct depends_on" do
expect(page.depends_on).to eq(
[
{ "hholdcount" => 1, "jointpur" => 1 }, { "hholdcount" => 2, "jointpur" => 1 }, { "hholdcount" => 3, "jointpur" => 1 }, { "hholdcount" => 4, "jointpur" => 1 }
],
)
end
end
context "with person 2" do
let(:page_id) { "person_2_known_joint_purchase" }
let(:person_index) { 4 }
it "has correct questions" do
expect(page.questions.map(&:id)).to eq(%w[details_known_2])
end
it "has the correct id" do
expect(page.id).to eq("person_2_known_joint_purchase")
end
it "has the correct header_partial" do
expect(page.header_partial).to eq("person_2_known_page")
end
it "has correct depends_on" do
expect(page.depends_on).to eq(
[{ "hholdcount" => 2, "jointpur" => 1 }, { "hholdcount" => 3, "jointpur" => 1 }, { "hholdcount" => 4, "jointpur" => 1 }],
)
end
end
context "with person 3" do
let(:page_id) { "person_3_known_joint_purchase" }
context "with person 5" do
let(:page_id) { "person_5_known" }
let(:person_index) { 5 }
it "has correct questions" do
expect(page.questions.map(&:id)).to eq(%w[details_known_3])
end
it "has the correct id" do
expect(page.id).to eq("person_3_known_joint_purchase")
end
it "has the correct header_partial" do
expect(page.header_partial).to eq("person_3_known_page")
end
it "has correct depends_on" do
expect(page.depends_on).to eq(
[{ "hholdcount" => 3, "jointpur" => 1 }, { "hholdcount" => 4, "jointpur" => 1 }],
)
end
end
context "with person 4" do
let(:page_id) { "person_4_known_joint_purchase" }
let(:person_index) { 6 }
it "has correct questions" do
expect(page.questions.map(&:id)).to eq(%w[details_known_4])
expect(page.questions.map(&:id)).to eq(%w[details_known_5])
end
it "has the correct id" do
expect(page.id).to eq("person_4_known_joint_purchase")
expect(page.id).to eq("person_5_known")
end
it "has the correct header_partial" do
expect(page.header_partial).to eq("person_4_known_page")
expect(page.header_partial).to eq("person_5_known_page")
end
it "has correct depends_on" do
expect(page.depends_on).to eq(
[{ "hholdcount" => 4, "jointpur" => 1 }],
)
expect(page.depends_on).to eq([
{
"jointpur" => 2,
"hholdcount" => {
"operator" => ">=",
"operand" => 4,
},
},
{
"jointpur" => 1,
"hholdcount" => {
"operator" => ">=",
"operand" => 3,
},
},
])
end
end
end

187
spec/models/form/sales/pages/person_relationship_to_buyer1_spec.rb

@ -7,172 +7,85 @@ RSpec.describe Form::Sales::Pages::PersonRelationshipToBuyer1, type: :model do
let(:subsection) { instance_double(Form::Subsection) }
let(:person_index) { 1 }
context "without joint purchase" do
let(:page_id) { "person_1_relationship_to_buyer_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 header" do
expect(page.header).to be_nil
end
it "has the correct description" do
expect(page.description).to be_nil
end
context "with person 1" do
let(:person_index) { 2 }
let(:page_id) { "person_1_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_1_relationship_to_buyer_1")
end
it "has correct depends_on" do
expect(page.depends_on).to eq([{ "details_known_1" => 1, "jointpur" => 2 }])
end
end
it "has correct subsection" do
expect(page.subsection).to eq(subsection)
end
context "with person 2" do
let(:person_index) { 3 }
let(:page_id) { "person_2_relationship_to_buyer_1" }
it "has the correct header" do
expect(page.header).to be_nil
end
it "has correct questions" do
expect(page.questions.map(&:id)).to eq(%w[relat3])
end
it "has the correct description" do
expect(page.description).to be_nil
end
it "has the correct id" do
expect(page.id).to eq("person_2_relationship_to_buyer_1")
end
context "with person 2" do
let(:person_index) { 2 }
let(:page_id) { "person_2_relationship_to_buyer_1" }
it "has correct depends_on" do
expect(page.depends_on).to eq([{ "details_known_2" => 1, "jointpur" => 2 }])
end
it "has correct questions" do
expect(page.questions.map(&:id)).to eq(%w[relat2])
end
context "with person 3" do
let(:person_index) { 4 }
let(:page_id) { "person_3_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_3_relationship_to_buyer_1")
end
it "has correct depends_on" do
expect(page.depends_on).to eq([{ "details_known_3" => 1, "jointpur" => 2 }])
end
it "has the correct id" do
expect(page.id).to eq("person_2_relationship_to_buyer_1")
end
context "with person 4" do
let(:person_index) { 5 }
let(:page_id) { "person_4_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_4_relationship_to_buyer_1")
end
it "has correct depends_on" do
expect(page.depends_on).to eq([{ "details_known_4" => 1, "jointpur" => 2 }])
end
it "has correct depends_on" do
expect(page.depends_on).to eq([{ "details_known_2" => 1 }])
end
end
context "with joint purchase" do
let(:page_id) { "person_1_relationship_to_buyer_1_joint_purchase" }
context "with person 3" do
let(:person_index) { 3 }
let(:page_id) { "person_3_relationship_to_buyer_1" }
it "has correct subsection" do
expect(page.subsection).to eq(subsection)
it "has correct questions" do
expect(page.questions.map(&:id)).to eq(%w[relat3])
end
it "has the correct header" do
expect(page.header).to be_nil
it "has the correct id" do
expect(page.id).to eq("person_3_relationship_to_buyer_1")
end
it "has the correct description" do
expect(page.description).to be_nil
it "has correct depends_on" do
expect(page.depends_on).to eq([{ "details_known_3" => 1 }])
end
end
context "with person 1" do
let(:person_index) { 3 }
let(:page_id) { "person_1_relationship_to_buyer_1_joint_purchase" }
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_1_relationship_to_buyer_1_joint_purchase")
end
context "with person 4" do
let(:person_index) { 4 }
let(:page_id) { "person_4_relationship_to_buyer_1" }
it "has correct depends_on" do
expect(page.depends_on).to eq([{ "details_known_1" => 1, "jointpur" => 1 }])
end
it "has correct questions" do
expect(page.questions.map(&:id)).to eq(%w[relat4])
end
context "with person 2" do
let(:person_index) { 4 }
let(:page_id) { "person_2_relationship_to_buyer_1_joint_purchase" }
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_2_relationship_to_buyer_1_joint_purchase")
end
it "has correct depends_on" do
expect(page.depends_on).to eq([{ "details_known_2" => 1, "jointpur" => 1 }])
end
it "has the correct id" do
expect(page.id).to eq("person_4_relationship_to_buyer_1")
end
context "with person 3" do
let(:person_index) { 5 }
let(:page_id) { "person_3_relationship_to_buyer_1_joint_purchase" }
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_3_relationship_to_buyer_1_joint_purchase")
end
it "has correct depends_on" do
expect(page.depends_on).to eq([{ "details_known_3" => 1, "jointpur" => 1 }])
end
it "has correct depends_on" do
expect(page.depends_on).to eq([{ "details_known_4" => 1 }])
end
end
context "with person 4" do
let(:person_index) { 6 }
let(:page_id) { "person_4_relationship_to_buyer_1_joint_purchase" }
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[relat6])
end
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_4_relationship_to_buyer_1_joint_purchase")
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_4" => 1, "jointpur" => 1 }])
end
it "has correct depends_on" do
expect(page.depends_on).to eq([{ "details_known_5" => 1 }])
end
end
end

189
spec/models/form/sales/pages/person_working_situation_spec.rb

@ -5,174 +5,87 @@ RSpec.describe Form::Sales::Pages::PersonWorkingSituation, type: :model do
let(:page_definition) { nil }
let(:subsection) { instance_double(Form::Subsection) }
let(:person_index) { 1 }
let(:person_index) { 2 }
context "without joint purchase" do
let(:page_id) { "person_1_working_situation" }
let(:page_id) { "person_2_working_situation" }
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
context "with person 1" do
let(:person_index) { 2 }
let(:page_id) { "person_1_working_situation" }
it "has correct questions" do
expect(page.questions.map(&:id)).to eq(%w[ecstat2])
end
it "has the correct id" do
expect(page.id).to eq("person_1_working_situation")
end
it "has correct depends_on" do
expect(page.depends_on).to eq([{ "details_known_1" => 1, "jointpur" => 2 }])
end
end
it "has correct subsection" do
expect(page.subsection).to eq(subsection)
end
context "with person 2" do
let(:person_index) { 3 }
let(:page_id) { "person_2_working_situation" }
it "has the correct header" do
expect(page.header).to be_nil
end
it "has correct questions" do
expect(page.questions.map(&:id)).to eq(%w[ecstat3])
end
it "has the correct description" do
expect(page.description).to be_nil
end
it "has the correct id" do
expect(page.id).to eq("person_2_working_situation")
end
context "with person 2" do
let(:person_index) { 2 }
let(:page_id) { "person_2_working_situation" }
it "has correct depends_on" do
expect(page.depends_on).to eq([{ "details_known_2" => 1, "jointpur" => 2 }])
end
it "has correct questions" do
expect(page.questions.map(&:id)).to eq(%w[ecstat2])
end
context "with person 3" do
let(:person_index) { 4 }
let(:page_id) { "person_3_working_situation" }
it "has correct questions" do
expect(page.questions.map(&:id)).to eq(%w[ecstat4])
end
it "has the correct id" do
expect(page.id).to eq("person_3_working_situation")
end
it "has correct depends_on" do
expect(page.depends_on).to eq([{ "details_known_3" => 1, "jointpur" => 2 }])
end
it "has the correct id" do
expect(page.id).to eq("person_2_working_situation")
end
context "with person 4" do
let(:person_index) { 5 }
let(:page_id) { "person_4_working_situation" }
it "has correct questions" do
expect(page.questions.map(&:id)).to eq(%w[ecstat5])
end
it "has the correct id" do
expect(page.id).to eq("person_4_working_situation")
end
it "has correct depends_on" do
expect(page.depends_on).to eq([{ "details_known_4" => 1, "jointpur" => 2 }])
end
it "has correct depends_on" do
expect(page.depends_on).to eq([{ "details_known_2" => 1 }])
end
end
context "with joint purchase" do
let(:page_id) { "person_1_working_situation_joint_purchase" }
context "with person 3" do
let(:person_index) { 3 }
let(:page_id) { "person_3_working_situation" }
it "has correct subsection" do
expect(page.subsection).to eq(subsection)
it "has correct questions" do
expect(page.questions.map(&:id)).to eq(%w[ecstat3])
end
it "has the correct header" do
expect(page.header).to be_nil
it "has the correct id" do
expect(page.id).to eq("person_3_working_situation")
end
it "has the correct description" do
expect(page.description).to be_nil
it "has correct depends_on" do
expect(page.depends_on).to eq([{ "details_known_3" => 1 }])
end
end
context "with person 1" do
let(:person_index) { 3 }
let(:page_id) { "person_1_working_situation_joint_purchase" }
it "has correct questions" do
expect(page.questions.map(&:id)).to eq(%w[ecstat3])
end
it "has the correct id" do
expect(page.id).to eq("person_1_working_situation_joint_purchase")
end
context "with person 4" do
let(:person_index) { 4 }
let(:page_id) { "person_4_working_situation" }
it "has correct depends_on" do
expect(page.depends_on).to eq([{ "details_known_1" => 1, "jointpur" => 1 }])
end
it "has correct questions" do
expect(page.questions.map(&:id)).to eq(%w[ecstat4])
end
context "with person 2" do
let(:person_index) { 4 }
let(:page_id) { "person_2_working_situation_joint_purchase" }
it "has correct questions" do
expect(page.questions.map(&:id)).to eq(%w[ecstat4])
end
it "has the correct id" do
expect(page.id).to eq("person_2_working_situation_joint_purchase")
end
it "has correct depends_on" do
expect(page.depends_on).to eq([{ "details_known_2" => 1, "jointpur" => 1 }])
end
it "has the correct id" do
expect(page.id).to eq("person_4_working_situation")
end
context "with person 3" do
let(:person_index) { 5 }
let(:page_id) { "person_3_working_situation_joint_purchase" }
it "has correct questions" do
expect(page.questions.map(&:id)).to eq(%w[ecstat5])
end
it "has the correct id" do
expect(page.id).to eq("person_3_working_situation_joint_purchase")
end
it "has correct depends_on" do
expect(page.depends_on).to eq([{ "details_known_3" => 1, "jointpur" => 1 }])
end
it "has correct depends_on" do
expect(page.depends_on).to eq([{ "details_known_4" => 1 }])
end
end
context "with person 4" do
let(:person_index) { 6 }
let(:page_id) { "person_4_working_situation_joint_purchase" }
context "with person 5" do
let(:person_index) { 5 }
let(:page_id) { "person_5_working_situation" }
it "has correct questions" do
expect(page.questions.map(&:id)).to eq(%w[ecstat6])
end
it "has correct questions" do
expect(page.questions.map(&:id)).to eq(%w[ecstat5])
end
it "has the correct id" do
expect(page.id).to eq("person_4_working_situation_joint_purchase")
end
it "has the correct id" do
expect(page.id).to eq("person_5_working_situation")
end
it "has correct depends_on" do
expect(page.depends_on).to eq([{ "details_known_4" => 1, "jointpur" => 1 }])
end
it "has correct depends_on" do
expect(page.depends_on).to eq([{ "details_known_5" => 1 }])
end
end
end

820
spec/models/form/sales/pages/retirement_value_check_spec.rb

@ -21,587 +21,295 @@ RSpec.describe Form::Sales::Pages::RetirementValueCheck, type: :model do
expect(page.description).to be_nil
end
context "with joint purchase" do
context "with person 1" do
let(:person_index) { 1 }
let(:page_id) { "person_1_retirement_value_check_joint_purchase" }
it "has correct questions" do
expect(page.questions.map(&:id)).to eq(%w[retirement_value_check])
end
it "has the correct id" do
expect(page.id).to eq("person_1_retirement_value_check_joint_purchase")
end
it "has correct depends_on" do
expect(page.depends_on).to eq([{ "person_1_retired_under_soft_min_age?" => true, "jointpur" => 1 }])
end
it "has correct title_text" do
expect(page.title_text).to eq({
"translation" => "soft_validations.retirement.min.title",
"arguments" => [
{
"key" => "retirement_age_for_person_1",
"label" => false,
"i18n_template" => "age",
},
],
})
end
it "has correct informative_text" do
expect(page.informative_text).to eq({
"translation" => "soft_validations.retirement.min.hint_text",
"arguments" => [
{
"key" => "plural_gender_for_person_1",
"label" => false,
"i18n_template" => "gender",
},
{
"key" => "retirement_age_for_person_1",
"label" => false,
"i18n_template" => "age",
},
],
})
end
it "is interruption screen page" do
expect(page.interruption_screen?).to eq(true)
end
context "with person 1" do
let(:person_index) { 1 }
let(:page_id) { "person_1_retirement_value_check" }
it "has correct questions" do
expect(page.questions.map(&:id)).to eq(%w[retirement_value_check])
end
it "has the correct id" do
expect(page.id).to eq("person_1_retirement_value_check")
end
it "has correct depends_on" do
expect(page.depends_on).to eq([{ "person_1_retired_under_soft_min_age?" => true }])
end
it "has correct title_text" do
expect(page.title_text).to eq({
"translation" => "soft_validations.retirement.min.title",
"arguments" => [
{
"key" => "retirement_age_for_person_1",
"label" => false,
"i18n_template" => "age",
},
],
})
end
it "has correct informative_text" do
expect(page.informative_text).to eq({
"translation" => "soft_validations.retirement.min.hint_text",
"arguments" => [
{
"key" => "plural_gender_for_person_1",
"label" => false,
"i18n_template" => "gender",
},
{
"key" => "retirement_age_for_person_1",
"label" => false,
"i18n_template" => "age",
},
],
})
end
end
context "with person 2" do
let(:person_index) { 2 }
let(:page_id) { "person_2_retirement_value_check" }
it "has correct questions" do
expect(page.questions.map(&:id)).to eq(%w[retirement_value_check])
end
it "has the correct id" do
expect(page.id).to eq("person_2_retirement_value_check")
end
it "has correct depends_on" do
expect(page.depends_on).to eq([{ "person_2_retired_under_soft_min_age?" => true }])
end
it "has correct title_text" do
expect(page.title_text).to eq({
"translation" => "soft_validations.retirement.min.title",
"arguments" => [
{
"key" => "retirement_age_for_person_2",
"label" => false,
"i18n_template" => "age",
},
],
})
end
it "has correct informative_text" do
expect(page.informative_text).to eq({
"translation" => "soft_validations.retirement.min.hint_text",
"arguments" => [
{
"key" => "plural_gender_for_person_2",
"label" => false,
"i18n_template" => "gender",
},
{
"key" => "retirement_age_for_person_2",
"label" => false,
"i18n_template" => "age",
},
],
})
end
end
context "with person 3" do
let(:person_index) { 3 }
let(:page_id) { "person_3_retirement_value_check" }
context "with person 2" do
let(:person_index) { 2 }
let(:page_id) { "person_2_retirement_value_check_joint_purchase" }
it "has correct questions" do
expect(page.questions.map(&:id)).to eq(%w[retirement_value_check])
end
it "has the correct id" do
expect(page.id).to eq("person_2_retirement_value_check_joint_purchase")
end
it "has correct depends_on" do
expect(page.depends_on).to eq([{ "person_2_retired_under_soft_min_age?" => true, "jointpur" => 1 }])
end
it "has correct title_text" do
expect(page.title_text).to eq({
"translation" => "soft_validations.retirement.min.title",
"arguments" => [
{
"key" => "retirement_age_for_person_2",
"label" => false,
"i18n_template" => "age",
},
],
})
end
it "has correct informative_text" do
expect(page.informative_text).to eq({
"translation" => "soft_validations.retirement.min.hint_text",
"arguments" => [
{
"key" => "plural_gender_for_person_2",
"label" => false,
"i18n_template" => "gender",
},
{
"key" => "retirement_age_for_person_2",
"label" => false,
"i18n_template" => "age",
},
],
})
end
it "has correct questions" do
expect(page.questions.map(&:id)).to eq(%w[retirement_value_check])
end
context "with person 3" do
let(:person_index) { 3 }
let(:page_id) { "person_3_retirement_value_check_joint_purchase" }
it "has correct questions" do
expect(page.questions.map(&:id)).to eq(%w[retirement_value_check])
end
it "has the correct id" do
expect(page.id).to eq("person_3_retirement_value_check_joint_purchase")
end
it "has correct depends_on" do
expect(page.depends_on).to eq([{ "person_3_retired_under_soft_min_age?" => true, "jointpur" => 1 }])
end
it "has correct title_text" do
expect(page.title_text).to eq({
"translation" => "soft_validations.retirement.min.title",
"arguments" => [
{
"key" => "retirement_age_for_person_3",
"label" => false,
"i18n_template" => "age",
},
],
})
end
it "has correct informative_text" do
expect(page.informative_text).to eq({
"translation" => "soft_validations.retirement.min.hint_text",
"arguments" => [
{
"key" => "plural_gender_for_person_3",
"label" => false,
"i18n_template" => "gender",
},
{
"key" => "retirement_age_for_person_3",
"label" => false,
"i18n_template" => "age",
},
],
})
end
it "has the correct id" do
expect(page.id).to eq("person_3_retirement_value_check")
end
context "with person 4" do
let(:person_index) { 4 }
let(:page_id) { "person_4_retirement_value_check_joint_purchase" }
it "has correct questions" do
expect(page.questions.map(&:id)).to eq(%w[retirement_value_check])
end
it "has the correct id" do
expect(page.id).to eq("person_4_retirement_value_check_joint_purchase")
end
it "has correct depends_on" do
expect(page.depends_on).to eq([{ "person_4_retired_under_soft_min_age?" => true, "jointpur" => 1 }])
end
it "has correct title_text" do
expect(page.title_text).to eq({
"translation" => "soft_validations.retirement.min.title",
"arguments" => [
{
"key" => "retirement_age_for_person_4",
"label" => false,
"i18n_template" => "age",
},
],
})
end
it "has correct informative_text" do
expect(page.informative_text).to eq({
"translation" => "soft_validations.retirement.min.hint_text",
"arguments" => [
{
"key" => "plural_gender_for_person_4",
"label" => false,
"i18n_template" => "gender",
},
{
"key" => "retirement_age_for_person_4",
"label" => false,
"i18n_template" => "age",
},
],
})
end
it "has correct depends_on" do
expect(page.depends_on).to eq([{ "person_3_retired_under_soft_min_age?" => true }])
end
context "with person 5" do
let(:person_index) { 5 }
let(:page_id) { "person_5_retirement_value_check_joint_purchase" }
it "has correct questions" do
expect(page.questions.map(&:id)).to eq(%w[retirement_value_check])
end
it "has the correct id" do
expect(page.id).to eq("person_5_retirement_value_check_joint_purchase")
end
it "has correct depends_on" do
expect(page.depends_on).to eq([{ "person_5_retired_under_soft_min_age?" => true, "jointpur" => 1 }])
end
it "has correct title_text" do
expect(page.title_text).to eq({
"translation" => "soft_validations.retirement.min.title",
"arguments" => [
{
"key" => "retirement_age_for_person_5",
"label" => false,
"i18n_template" => "age",
},
],
})
end
it "has correct informative_text" do
expect(page.informative_text).to eq({
"translation" => "soft_validations.retirement.min.hint_text",
"arguments" => [
{
"key" => "plural_gender_for_person_5",
"label" => false,
"i18n_template" => "gender",
},
{
"key" => "retirement_age_for_person_5",
"label" => false,
"i18n_template" => "age",
},
],
})
end
it "has correct title_text" do
expect(page.title_text).to eq({
"translation" => "soft_validations.retirement.min.title",
"arguments" => [
{
"key" => "retirement_age_for_person_3",
"label" => false,
"i18n_template" => "age",
},
],
})
end
context "with person 6" do
let(:person_index) { 6 }
let(:page_id) { "person_6_retirement_value_check_joint_purchase" }
it "has correct questions" do
expect(page.questions.map(&:id)).to eq(%w[retirement_value_check])
end
it "has the correct id" do
expect(page.id).to eq("person_6_retirement_value_check_joint_purchase")
end
it "has correct depends_on" do
expect(page.depends_on).to eq([{ "person_6_retired_under_soft_min_age?" => true, "jointpur" => 1 }])
end
it "has correct title_text" do
expect(page.title_text).to eq({
"translation" => "soft_validations.retirement.min.title",
"arguments" => [
{
"key" => "retirement_age_for_person_6",
"label" => false,
"i18n_template" => "age",
},
],
})
end
it "has correct informative_text" do
expect(page.informative_text).to eq({
"translation" => "soft_validations.retirement.min.hint_text",
"arguments" => [
{
"key" => "plural_gender_for_person_6",
"label" => false,
"i18n_template" => "gender",
},
{
"key" => "retirement_age_for_person_6",
"label" => false,
"i18n_template" => "age",
},
],
})
end
it "has correct informative_text" do
expect(page.informative_text).to eq({
"translation" => "soft_validations.retirement.min.hint_text",
"arguments" => [
{
"key" => "plural_gender_for_person_3",
"label" => false,
"i18n_template" => "gender",
},
{
"key" => "retirement_age_for_person_3",
"label" => false,
"i18n_template" => "age",
},
],
})
end
end
context "without joint purchase" do
context "with person 1" do
let(:person_index) { 1 }
let(:page_id) { "person_1_retirement_value_check" }
it "has correct questions" do
expect(page.questions.map(&:id)).to eq(%w[retirement_value_check])
end
it "has the correct id" do
expect(page.id).to eq("person_1_retirement_value_check")
end
it "has correct depends_on" do
expect(page.depends_on).to eq([{ "person_1_retired_under_soft_min_age?" => true, "jointpur" => 2 }])
end
it "has correct title_text" do
expect(page.title_text).to eq({
"translation" => "soft_validations.retirement.min.title",
"arguments" => [
{
"key" => "retirement_age_for_person_1",
"label" => false,
"i18n_template" => "age",
},
],
})
end
it "has correct informative_text" do
expect(page.informative_text).to eq({
"translation" => "soft_validations.retirement.min.hint_text",
"arguments" => [
{
"key" => "plural_gender_for_person_1",
"label" => false,
"i18n_template" => "gender",
},
{
"key" => "retirement_age_for_person_1",
"label" => false,
"i18n_template" => "age",
},
],
})
end
context "with person 4" do
let(:person_index) { 4 }
let(:page_id) { "person_4_retirement_value_check" }
it "has correct questions" do
expect(page.questions.map(&:id)).to eq(%w[retirement_value_check])
end
it "has the correct id" do
expect(page.id).to eq("person_4_retirement_value_check")
end
it "has correct depends_on" do
expect(page.depends_on).to eq([{ "person_4_retired_under_soft_min_age?" => true }])
end
context "with person 2" do
let(:person_index) { 2 }
let(:page_id) { "person_2_retirement_value_check" }
it "has correct questions" do
expect(page.questions.map(&:id)).to eq(%w[retirement_value_check])
end
it "has the correct id" do
expect(page.id).to eq("person_2_retirement_value_check")
end
it "has correct depends_on" do
expect(page.depends_on).to eq([{ "person_2_retired_under_soft_min_age?" => true, "jointpur" => 2 }])
end
it "has correct title_text" do
expect(page.title_text).to eq({
"translation" => "soft_validations.retirement.min.title",
"arguments" => [
{
"key" => "retirement_age_for_person_2",
"label" => false,
"i18n_template" => "age",
},
],
})
end
it "has correct informative_text" do
expect(page.informative_text).to eq({
"translation" => "soft_validations.retirement.min.hint_text",
"arguments" => [
{
"key" => "plural_gender_for_person_2",
"label" => false,
"i18n_template" => "gender",
},
{
"key" => "retirement_age_for_person_2",
"label" => false,
"i18n_template" => "age",
},
],
})
end
it "has correct title_text" do
expect(page.title_text).to eq({
"translation" => "soft_validations.retirement.min.title",
"arguments" => [
{
"key" => "retirement_age_for_person_4",
"label" => false,
"i18n_template" => "age",
},
],
})
end
it "has correct informative_text" do
expect(page.informative_text).to eq({
"translation" => "soft_validations.retirement.min.hint_text",
"arguments" => [
{
"key" => "plural_gender_for_person_4",
"label" => false,
"i18n_template" => "gender",
},
{
"key" => "retirement_age_for_person_4",
"label" => false,
"i18n_template" => "age",
},
],
})
end
end
context "with person 5" do
let(:person_index) { 5 }
let(:page_id) { "person_5_retirement_value_check" }
it "has correct questions" do
expect(page.questions.map(&:id)).to eq(%w[retirement_value_check])
end
context "with person 3" do
let(:person_index) { 2 }
let(:page_id) { "person_3_retirement_value_check" }
it "has correct questions" do
expect(page.questions.map(&:id)).to eq(%w[retirement_value_check])
end
it "has the correct id" do
expect(page.id).to eq("person_3_retirement_value_check")
end
it "has correct depends_on" do
expect(page.depends_on).to eq([{ "person_2_retired_under_soft_min_age?" => true, "jointpur" => 2 }])
end
it "has correct title_text" do
expect(page.title_text).to eq({
"translation" => "soft_validations.retirement.min.title",
"arguments" => [
{
"key" => "retirement_age_for_person_2",
"label" => false,
"i18n_template" => "age",
},
],
})
end
it "has correct informative_text" do
expect(page.informative_text).to eq({
"translation" => "soft_validations.retirement.min.hint_text",
"arguments" => [
{
"key" => "plural_gender_for_person_2",
"label" => false,
"i18n_template" => "gender",
},
{
"key" => "retirement_age_for_person_2",
"label" => false,
"i18n_template" => "age",
},
],
})
end
it "has the correct id" do
expect(page.id).to eq("person_5_retirement_value_check")
end
context "with person 4" do
let(:person_index) { 3 }
let(:page_id) { "person_4_retirement_value_check" }
it "has correct questions" do
expect(page.questions.map(&:id)).to eq(%w[retirement_value_check])
end
it "has the correct id" do
expect(page.id).to eq("person_4_retirement_value_check")
end
it "has correct depends_on" do
expect(page.depends_on).to eq([{ "person_3_retired_under_soft_min_age?" => true, "jointpur" => 2 }])
end
it "has correct title_text" do
expect(page.title_text).to eq({
"translation" => "soft_validations.retirement.min.title",
"arguments" => [
{
"key" => "retirement_age_for_person_3",
"label" => false,
"i18n_template" => "age",
},
],
})
end
it "has correct informative_text" do
expect(page.informative_text).to eq({
"translation" => "soft_validations.retirement.min.hint_text",
"arguments" => [
{
"key" => "plural_gender_for_person_3",
"label" => false,
"i18n_template" => "gender",
},
{
"key" => "retirement_age_for_person_3",
"label" => false,
"i18n_template" => "age",
},
],
})
end
it "has correct depends_on" do
expect(page.depends_on).to eq([{ "person_5_retired_under_soft_min_age?" => true }])
end
context "with person 5" do
let(:person_index) { 4 }
let(:page_id) { "person_5_retirement_value_check" }
it "has correct questions" do
expect(page.questions.map(&:id)).to eq(%w[retirement_value_check])
end
it "has the correct id" do
expect(page.id).to eq("person_5_retirement_value_check")
end
it "has correct depends_on" do
expect(page.depends_on).to eq([{ "person_4_retired_under_soft_min_age?" => true, "jointpur" => 2 }])
end
it "has correct title_text" do
expect(page.title_text).to eq({
"translation" => "soft_validations.retirement.min.title",
"arguments" => [
{
"key" => "retirement_age_for_person_4",
"label" => false,
"i18n_template" => "age",
},
],
})
end
it "has correct informative_text" do
expect(page.informative_text).to eq({
"translation" => "soft_validations.retirement.min.hint_text",
"arguments" => [
{
"key" => "plural_gender_for_person_4",
"label" => false,
"i18n_template" => "gender",
},
{
"key" => "retirement_age_for_person_4",
"label" => false,
"i18n_template" => "age",
},
],
})
end
it "has correct title_text" do
expect(page.title_text).to eq({
"translation" => "soft_validations.retirement.min.title",
"arguments" => [
{
"key" => "retirement_age_for_person_5",
"label" => false,
"i18n_template" => "age",
},
],
})
end
context "with person 6" do
let(:person_index) { 5 }
let(:page_id) { "person_6_retirement_value_check" }
it "has correct questions" do
expect(page.questions.map(&:id)).to eq(%w[retirement_value_check])
end
it "has the correct id" do
expect(page.id).to eq("person_6_retirement_value_check")
end
it "has correct depends_on" do
expect(page.depends_on).to eq([{ "person_5_retired_under_soft_min_age?" => true, "jointpur" => 2 }])
end
it "has correct title_text" do
expect(page.title_text).to eq({
"translation" => "soft_validations.retirement.min.title",
"arguments" => [
{
"key" => "retirement_age_for_person_5",
"label" => false,
"i18n_template" => "age",
},
],
})
end
it "has correct informative_text" do
expect(page.informative_text).to eq({
"translation" => "soft_validations.retirement.min.hint_text",
"arguments" => [
{
"key" => "plural_gender_for_person_5",
"label" => false,
"i18n_template" => "gender",
},
{
"key" => "retirement_age_for_person_5",
"label" => false,
"i18n_template" => "age",
},
],
})
end
it "has correct informative_text" do
expect(page.informative_text).to eq({
"translation" => "soft_validations.retirement.min.hint_text",
"arguments" => [
{
"key" => "plural_gender_for_person_5",
"label" => false,
"i18n_template" => "gender",
},
{
"key" => "retirement_age_for_person_5",
"label" => false,
"i18n_template" => "age",
},
],
})
end
end
it "is interruption screen page" do
expect(page.interruption_screen?).to eq(true)
context "with person 6" do
let(:person_index) { 6 }
let(:page_id) { "person_6_retirement_value_check" }
it "has correct questions" do
expect(page.questions.map(&:id)).to eq(%w[retirement_value_check])
end
it "has the correct id" do
expect(page.id).to eq("person_6_retirement_value_check")
end
it "has correct depends_on" do
expect(page.depends_on).to eq([{ "person_6_retired_under_soft_min_age?" => true }])
end
it "has correct title_text" do
expect(page.title_text).to eq({
"translation" => "soft_validations.retirement.min.title",
"arguments" => [
{
"key" => "retirement_age_for_person_6",
"label" => false,
"i18n_template" => "age",
},
],
})
end
it "has correct informative_text" do
expect(page.informative_text).to eq({
"translation" => "soft_validations.retirement.min.hint_text",
"arguments" => [
{
"key" => "plural_gender_for_person_6",
"label" => false,
"i18n_template" => "gender",
},
{
"key" => "retirement_age_for_person_6",
"label" => false,
"i18n_template" => "age",
},
],
})
end
end
end

508
spec/models/form/sales/questions/person_age_known_spec.rb

@ -8,10 +8,6 @@ RSpec.describe Form::Sales::Questions::PersonAgeKnown, type: :model do
let(:page) { instance_double(Form::Page) }
let(:person_index) { 2 }
before do
allow(page).to receive(:id).and_return("person_1_age")
end
it "has correct page" do
expect(question.page).to eq(page)
end
@ -35,375 +31,171 @@ RSpec.describe Form::Sales::Questions::PersonAgeKnown, type: :model do
expect(question.hint_text).to be_nil
end
context "with a non joint purchase" do
context "and person 1" do
let(:question_id) { "age2_known" }
let(:person_index) { 2 }
before do
allow(page).to receive(:id).and_return("person_1_age")
end
it "has the correct id" do
expect(question.id).to eq("age2_known")
end
it "has the correct header" do
expect(question.header).to eq("Do you know person 1’s age?")
end
it "has the correct check_answer_label" do
expect(question.check_answer_label).to eq("Person 1’s age known?")
end
it "has correct conditional for" do
expect(question.conditional_for).to eq({
"age2" => [0],
})
end
it "has the correct hidden_in_check_answers" do
expect(question.hidden_in_check_answers).to eq(
{
"depends_on" => [
{
"age2_known" => 0,
},
{
"age2_known" => 1,
},
],
},
)
end
it "has the correct check_answers_card_number" do
expect(question.check_answers_card_number).to eq(2)
end
context "with person 2" do
let(:question_id) { "age2_known" }
let(:person_index) { 2 }
it "has the correct id" do
expect(question.id).to eq("age2_known")
end
it "has the correct header" do
expect(question.header).to eq("Do you know person 2’s age?")
end
it "has the correct check_answer_label" do
expect(question.check_answer_label).to eq("Person 2’s age known?")
end
it "has correct conditional for" do
expect(question.conditional_for).to eq({
"age2" => [0],
})
end
it "has the correct hidden_in_check_answers" do
expect(question.hidden_in_check_answers).to eq(
{
"depends_on" => [
{
"age2_known" => 0,
},
{
"age2_known" => 1,
},
],
},
)
end
it "has the correct check_answers_card_number" do
expect(question.check_answers_card_number).to eq(2)
end
end
context "with person 3" do
let(:question_id) { "age3_known" }
let(:person_index) { 3 }
it "has the correct id" do
expect(question.id).to eq("age3_known")
end
it "has the correct header" do
expect(question.header).to eq("Do you know person 3’s age?")
end
it "has the correct check_answer_label" do
expect(question.check_answer_label).to eq("Person 3’s age known?")
end
it "has correct conditional for" do
expect(question.conditional_for).to eq({
"age3" => [0],
})
end
it "has the correct hidden_in_check_answers" do
expect(question.hidden_in_check_answers).to eq(
{
"depends_on" => [
{
"age3_known" => 0,
},
{
"age3_known" => 1,
},
],
},
)
end
it "has the correct check_answers_card_number" do
expect(question.check_answers_card_number).to eq(3)
end
end
context "with person 4" do
let(:question_id) { "age4_known" }
let(:person_index) { 4 }
it "has the correct id" do
expect(question.id).to eq("age4_known")
end
it "has the correct header" do
expect(question.header).to eq("Do you know person 4’s age?")
end
it "has the correct check_answer_label" do
expect(question.check_answer_label).to eq("Person 4’s age known?")
end
context "and person 2" do
let(:question_id) { "age3_known" }
let(:person_index) { 3 }
before do
allow(page).to receive(:id).and_return("person_2_age")
end
it "has the correct id" do
expect(question.id).to eq("age3_known")
end
it "has the correct header" do
expect(question.header).to eq("Do you know person 2’s age?")
end
it "has the correct check_answer_label" do
expect(question.check_answer_label).to eq("Person 2’s age known?")
end
it "has correct conditional for" do
expect(question.conditional_for).to eq({
"age3" => [0],
})
end
it "has the correct hidden_in_check_answers" do
expect(question.hidden_in_check_answers).to eq(
{
"depends_on" => [
{
"age3_known" => 0,
},
{
"age3_known" => 1,
},
],
},
)
end
it "has the correct check_answers_card_number" do
expect(question.check_answers_card_number).to eq(3)
end
it "has correct conditional for" do
expect(question.conditional_for).to eq({
"age4" => [0],
})
end
context "and person 3" do
let(:question_id) { "age4_known" }
let(:person_index) { 4 }
before do
allow(page).to receive(:id).and_return("person_3_age")
end
it "has the correct id" do
expect(question.id).to eq("age4_known")
end
it "has the correct header" do
expect(question.header).to eq("Do you know person 3’s age?")
end
it "has the correct check_answer_label" do
expect(question.check_answer_label).to eq("Person 3’s age known?")
end
it "has correct conditional for" do
expect(question.conditional_for).to eq({
"age4" => [0],
})
end
it "has the correct hidden_in_check_answers" do
expect(question.hidden_in_check_answers).to eq(
{
"depends_on" => [
{
"age4_known" => 0,
},
{
"age4_known" => 1,
},
],
},
)
end
it "has the correct check_answers_card_number" do
expect(question.check_answers_card_number).to eq(4)
end
it "has the correct hidden_in_check_answers" do
expect(question.hidden_in_check_answers).to eq(
{
"depends_on" => [
{
"age4_known" => 0,
},
{
"age4_known" => 1,
},
],
},
)
end
context "and person 4" do
let(:question_id) { "age5_known" }
let(:person_index) { 5 }
before do
allow(page).to receive(:id).and_return("person_4_age")
end
it "has the correct id" do
expect(question.id).to eq("age5_known")
end
it "has the correct header" do
expect(question.header).to eq("Do you know person 4’s age?")
end
it "has the correct check_answer_label" do
expect(question.check_answer_label).to eq("Person 4’s age known?")
end
it "has correct conditional for" do
expect(question.conditional_for).to eq({
"age5" => [0],
})
end
it "has the correct hidden_in_check_answers" do
expect(question.hidden_in_check_answers).to eq(
{
"depends_on" => [
{
"age5_known" => 0,
},
{
"age5_known" => 1,
},
],
},
)
end
it "has the correct check_answers_card_number" do
expect(question.check_answers_card_number).to eq(5)
end
it "has the correct check_answers_card_number" do
expect(question.check_answers_card_number).to eq(4)
end
end
context "with a joint purchase" do
context "and person 1" do
let(:question_id) { "age3_known" }
let(:person_index) { 3 }
before do
allow(page).to receive(:id).and_return("person_1_age_joint_purchase")
end
it "has the correct id" do
expect(question.id).to eq("age3_known")
end
it "has the correct header" do
expect(question.header).to eq("Do you know person 1’s age?")
end
it "has the correct check_answer_label" do
expect(question.check_answer_label).to eq("Person 1’s age known?")
end
it "has correct conditional for" do
expect(question.conditional_for).to eq({
"age3" => [0],
})
end
it "has the correct hidden_in_check_answers" do
expect(question.hidden_in_check_answers).to eq(
{
"depends_on" => [
{
"age3_known" => 0,
},
{
"age3_known" => 1,
},
],
},
)
end
it "has the correct check_answers_card_number" do
expect(question.check_answers_card_number).to eq(3)
end
context "with person 5" do
let(:question_id) { "age5_known" }
let(:person_index) { 5 }
it "has the correct id" do
expect(question.id).to eq("age5_known")
end
it "has the correct header" do
expect(question.header).to eq("Do you know person 5’s age?")
end
it "has the correct check_answer_label" do
expect(question.check_answer_label).to eq("Person 5’s age known?")
end
context "and person 2" do
let(:question_id) { "age4_known" }
let(:person_index) { 4 }
before do
allow(page).to receive(:id).and_return("person_2_age_joint_purchase")
end
it "has the correct id" do
expect(question.id).to eq("age4_known")
end
it "has the correct header" do
expect(question.header).to eq("Do you know person 2’s age?")
end
it "has the correct check_answer_label" do
expect(question.check_answer_label).to eq("Person 2’s age known?")
end
it "has correct conditional for" do
expect(question.conditional_for).to eq({
"age4" => [0],
})
end
it "has the correct hidden_in_check_answers" do
expect(question.hidden_in_check_answers).to eq(
{
"depends_on" => [
{
"age4_known" => 0,
},
{
"age4_known" => 1,
},
],
},
)
end
it "has the correct check_answers_card_number" do
expect(question.check_answers_card_number).to eq(4)
end
it "has correct conditional for" do
expect(question.conditional_for).to eq({
"age5" => [0],
})
end
context "and person 3" do
let(:question_id) { "age5_known" }
let(:person_index) { 5 }
before do
allow(page).to receive(:id).and_return("person_3_age_joint_purchase")
end
it "has the correct id" do
expect(question.id).to eq("age5_known")
end
it "has the correct header" do
expect(question.header).to eq("Do you know person 3’s age?")
end
it "has the correct check_answer_label" do
expect(question.check_answer_label).to eq("Person 3’s age known?")
end
it "has correct conditional for" do
expect(question.conditional_for).to eq({
"age5" => [0],
})
end
it "has the correct hidden_in_check_answers" do
expect(question.hidden_in_check_answers).to eq(
{
"depends_on" => [
{
"age5_known" => 0,
},
{
"age5_known" => 1,
},
],
},
)
end
it "has the correct check_answers_card_number" do
expect(question.check_answers_card_number).to eq(5)
end
it "has the correct hidden_in_check_answers" do
expect(question.hidden_in_check_answers).to eq(
{
"depends_on" => [
{
"age5_known" => 0,
},
{
"age5_known" => 1,
},
],
},
)
end
context "and person 4" do
let(:question_id) { "age6_known" }
let(:person_index) { 6 }
before do
allow(page).to receive(:id).and_return("person_4_age_joint_purchase")
end
it "has the correct id" do
expect(question.id).to eq("age6_known")
end
it "has the correct header" do
expect(question.header).to eq("Do you know person 4’s age?")
end
it "has the correct check_answer_label" do
expect(question.check_answer_label).to eq("Person 4’s age known?")
end
it "has correct conditional for" do
expect(question.conditional_for).to eq({
"age6" => [0],
})
end
it "has the correct hidden_in_check_answers" do
expect(question.hidden_in_check_answers).to eq(
{
"depends_on" => [
{
"age6_known" => 0,
},
{
"age6_known" => 1,
},
],
},
)
end
it "has the correct check_answers_card_number" do
expect(question.check_answers_card_number).to eq(6)
end
it "has the correct check_answers_card_number" do
expect(question.check_answers_card_number).to eq(5)
end
end
end

302
spec/models/form/sales/questions/person_age_spec.rb

@ -8,10 +8,6 @@ RSpec.describe Form::Sales::Questions::PersonAge, type: :model do
let(:page) { instance_double(Form::Page) }
let(:person_index) { 2 }
before do
allow(page).to receive(:id).and_return("person_1_age")
end
it "has correct page" do
expect(question.page).to eq(page)
end
@ -40,263 +36,103 @@ RSpec.describe Form::Sales::Questions::PersonAge, type: :model do
expect(question.max).to eq(110)
end
context "with not a joint purchase" do
context "and person 1" do
let(:person_index) { 2 }
let(:question_id) { "age2" }
before do
allow(page).to receive(:id).and_return("person_1_age")
end
it "has the correct id" do
expect(question.id).to eq("age2")
end
it "has the correct check_answer_label" do
expect(question.check_answer_label).to eq("Person 1’s age")
end
it "has the correct width" do
expect(question.width).to eq(3)
end
it "has the correct width" do
expect(question.width).to eq(3)
end
it "has the correct inferred check answers value" do
expect(question.inferred_check_answers_value).to eq([{
"condition" => { "age2_known" => 1 },
"value" => "Not known",
}])
end
context "with person 2" do
let(:person_index) { 2 }
let(:question_id) { "age2" }
it "has the correct check_answers_card_number" do
expect(question.check_answers_card_number).to eq(2)
end
it "has the correct id" do
expect(question.id).to eq("age2")
end
context "and person 2" do
let(:person_index) { 3 }
let(:question_id) { "age3" }
before do
allow(page).to receive(:id).and_return("person_2_age")
end
it "has the correct id" do
expect(question.id).to eq("age3")
end
it "has the correct check_answer_label" do
expect(question.check_answer_label).to eq("Person 2’s age")
end
it "has the correct width" do
expect(question.width).to eq(3)
end
it "has the correct inferred check answers value" do
expect(question.inferred_check_answers_value).to eq([{
"condition" => { "age3_known" => 1 },
"value" => "Not known",
}])
end
it "has the correct check_answers_card_number" do
expect(question.check_answers_card_number).to eq(3)
end
it "has the correct check_answer_label" do
expect(question.check_answer_label).to eq("Person 2’s age")
end
context "and person 3" do
let(:person_index) { 4 }
let(:question_id) { "age4" }
before do
allow(page).to receive(:id).and_return("person_3_age")
end
it "has the correct id" do
expect(question.id).to eq("age4")
end
it "has the correct check_answer_label" do
expect(question.check_answer_label).to eq("Person 3’s age")
end
it "has the correct width" do
expect(question.width).to eq(3)
end
it "has the correct inferred check answers value" do
expect(question.inferred_check_answers_value).to eq([{
"condition" => { "age4_known" => 1 },
"value" => "Not known",
}])
end
it "has the correct 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" => { "age2_known" => 1 },
"value" => "Not known",
}])
end
context "and person 4" do
let(:person_index) { 5 }
let(:question_id) { "age5" }
before do
allow(page).to receive(:id).and_return("person_4_age")
end
it "has the correct id" do
expect(question.id).to eq("age5")
end
it "has the correct check_answer_label" do
expect(question.check_answer_label).to eq("Person 4’s age")
end
it "has the correct width" do
expect(question.width).to eq(3)
end
it "has the correct inferred check answers value" do
expect(question.inferred_check_answers_value).to eq([{
"condition" => { "age5_known" => 1 },
"value" => "Not known",
}])
end
it "has the correct check_answers_card_number" do
expect(question.check_answers_card_number).to eq(5)
end
it "has the correct check_answers_card_number" do
expect(question.check_answers_card_number).to eq(2)
end
end
context "with a joint purchase" do
context "and person 1" do
let(:person_index) { 3 }
let(:question_id) { "age3" }
before do
allow(page).to receive(:id).and_return("person_1_age_joint_purchase")
end
it "has the correct id" do
expect(question.id).to eq("age3")
end
it "has the correct check_answer_label" do
expect(question.check_answer_label).to eq("Person 1’s age")
end
it "has the correct width" do
expect(question.width).to eq(3)
end
it "has the correct inferred check answers value" do
expect(question.inferred_check_answers_value).to eq([{
"condition" => { "age3_known" => 1 },
"value" => "Not known",
}])
end
context "with person 3" do
let(:person_index) { 3 }
let(:question_id) { "age3" }
it "has the correct check_answers_card_number" do
expect(question.check_answers_card_number).to eq(3)
end
it "has the correct id" do
expect(question.id).to eq("age3")
end
context "and person 2" do
let(:person_index) { 4 }
let(:question_id) { "age4" }
before do
allow(page).to receive(:id).and_return("person_2_age_joint_purchase")
end
it "has the correct id" do
expect(question.id).to eq("age4")
end
it "has the correct check_answer_label" do
expect(question.check_answer_label).to eq("Person 2’s age")
end
it "has the correct width" do
expect(question.width).to eq(3)
end
it "has the correct inferred check answers value" do
expect(question.inferred_check_answers_value).to eq([{
"condition" => { "age4_known" => 1 },
"value" => "Not known",
}])
end
it "has the correct check_answers_card_number" do
expect(question.check_answers_card_number).to eq(4)
end
it "has the correct check_answer_label" do
expect(question.check_answer_label).to eq("Person 3’s age")
end
context "and person 3" do
let(:person_index) { 5 }
let(:question_id) { "age5" }
before do
allow(page).to receive(:id).and_return("person_3_age_joint_purchase")
end
it "has the correct id" do
expect(question.id).to eq("age5")
end
it "has the correct inferred check answers value" do
expect(question.inferred_check_answers_value).to eq([{
"condition" => { "age3_known" => 1 },
"value" => "Not known",
}])
end
it "has the correct check_answer_label" do
expect(question.check_answer_label).to eq("Person 3’s age")
end
it "has the correct check_answers_card_number" do
expect(question.check_answers_card_number).to eq(3)
end
end
it "has the correct width" do
expect(question.width).to eq(3)
end
context "with person 4" do
let(:person_index) { 4 }
let(:question_id) { "age4" }
it "has the correct inferred check answers value" do
expect(question.inferred_check_answers_value).to eq([{
"condition" => { "age5_known" => 1 },
"value" => "Not known",
}])
end
it "has the correct id" do
expect(question.id).to eq("age4")
end
it "has the correct check_answers_card_number" do
expect(question.check_answers_card_number).to eq(5)
end
it "has the correct check_answer_label" do
expect(question.check_answer_label).to eq("Person 4’s age")
end
context "and person 4" do
let(:person_index) { 6 }
let(:question_id) { "age6" }
it "has the correct inferred check answers value" do
expect(question.inferred_check_answers_value).to eq([{
"condition" => { "age4_known" => 1 },
"value" => "Not known",
}])
end
before do
allow(page).to receive(:id).and_return("person_4_age_joint_purchase")
end
it "has the correct check_answers_card_number" do
expect(question.check_answers_card_number).to eq(4)
end
end
it "has the correct id" do
expect(question.id).to eq("age6")
end
context "with person 5" do
let(:person_index) { 5 }
let(:question_id) { "age5" }
it "has the correct check_answer_label" do
expect(question.check_answer_label).to eq("Person 4’s age")
end
it "has the correct id" do
expect(question.id).to eq("age5")
end
it "has the correct width" do
expect(question.width).to eq(3)
end
it "has the correct check_answer_label" do
expect(question.check_answer_label).to eq("Person 5’s age")
end
it "has the correct inferred check answers value" do
expect(question.inferred_check_answers_value).to eq([{
"condition" => { "age6_known" => 1 },
"value" => "Not known",
}])
end
it "has the correct inferred check answers value" do
expect(question.inferred_check_answers_value).to eq([{
"condition" => { "age5_known" => 1 },
"value" => "Not known",
}])
end
it "has the correct check_answers_card_number" do
expect(question.check_answers_card_number).to eq(6)
end
it "has the correct check_answers_card_number" do
expect(question.check_answers_card_number).to eq(5)
end
end
end

298
spec/models/form/sales/questions/person_gender_identity_spec.rb

@ -8,10 +8,6 @@ RSpec.describe Form::Sales::Questions::PersonGenderIdentity, type: :model do
let(:page) { instance_double(Form::Page) }
let(:person_index) { 2 }
before do
allow(page).to receive(:id).and_return("person_1_gender_identity")
end
it "has correct page" do
expect(question.page).to eq(page)
end
@ -24,10 +20,6 @@ RSpec.describe Form::Sales::Questions::PersonGenderIdentity, type: :model do
expect(question.derived?).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({
"F" => { "value" => "Female" },
@ -37,259 +29,111 @@ RSpec.describe Form::Sales::Questions::PersonGenderIdentity, type: :model do
})
end
context "when person 1" do
context "and not joint purchase" do
let(:question_id) { "sex2" }
let(:person_index) { 2 }
before do
allow(page).to receive(:id).and_return("person_1_gender_identity")
end
it "has the correct id" do
expect(question.id).to eq("sex2")
end
it "has the correct header" do
expect(question.header).to eq("Which of these best describes Person 1’s gender identity?")
end
it "has the correct check_answer_label" do
expect(question.check_answer_label).to eq("Person 1’s gender identity")
end
it "has expected check answers card number" do
expect(question.check_answers_card_number).to eq(2)
end
context "when person 2" do
let(:question_id) { "sex2" }
let(:person_index) { 2 }
it "has the correct inferred_check_answers_value" do
expect(question.inferred_check_answers_value).to eq([
{ "condition" => { "sex2" => "R" }, "value" => "Prefers not to say" },
])
end
it "has the correct id" do
expect(question.id).to eq("sex2")
end
context "and joint purchase" do
let(:person_index) { 3 }
let(:question_id) { "sex3" }
before do
allow(page).to receive(:id).and_return("person_1_gender_identity_joint_purchase")
end
it "has the correct id" do
expect(question.id).to eq("sex3")
end
it "has the correct header" do
expect(question.header).to eq("Which of these best describes Person 1’s gender identity?")
end
it "has the correct check_answer_label" do
expect(question.check_answer_label).to eq("Person 1’s gender identity")
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" => { "sex3" => "R" }, "value" => "Prefers not to say" },
])
end
it "has the correct header" do
expect(question.header).to eq("Which of these best describes Person 2’s gender identity?")
end
end
context "when person 2" do
context "and not joint purchase" do
let(:question_id) { "sex3" }
let(:person_index) { 3 }
before do
allow(page).to receive(:id).and_return("person_2_gender_identity")
end
it "has the correct id" do
expect(question.id).to eq("sex3")
end
it "has the correct header" do
expect(question.header).to eq("Which of these best describes Person 2’s gender identity?")
end
it "has the correct check_answer_label" do
expect(question.check_answer_label).to eq("Person 2’s gender identity")
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" => { "sex3" => "R" }, "value" => "Prefers not to say" },
])
end
it "has the correct check_answer_label" do
expect(question.check_answer_label).to eq("Person 2’s gender identity")
end
context "and joint purchase" do
let(:question_id) { "sex4" }
let(:person_index) { 4 }
before do
allow(page).to receive(:id).and_return("person_2_gender_identity_joint_purchase")
end
it "has the correct id" do
expect(question.id).to eq("sex4")
end
it "has the correct header" do
expect(question.header).to eq("Which of these best describes Person 2’s gender identity?")
end
it "has the correct check_answer_label" do
expect(question.check_answer_label).to eq("Person 2’s gender identity")
end
it "has expected check answers card number" do
expect(question.check_answers_card_number).to eq(4)
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" => { "sex4" => "R" }, "value" => "Prefers not to say" },
])
end
it "has the correct inferred_check_answers_value" do
expect(question.inferred_check_answers_value).to eq([
{ "condition" => { "sex2" => "R" }, "value" => "Prefers not to say" },
])
end
end
context "when person 3" do
context "and not joint purchase" do
let(:question_id) { "sex4" }
let(:person_index) { 4 }
before do
allow(page).to receive(:id).and_return("person_3_gender_identity")
end
it "has the correct id" do
expect(question.id).to eq("sex4")
end
it "has the correct header" do
expect(question.header).to eq("Which of these best describes Person 3’s gender identity?")
end
let(:question_id) { "sex3" }
let(:person_index) { 3 }
it "has the correct check_answer_label" do
expect(question.check_answer_label).to eq("Person 3’s gender identity")
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" => { "sex4" => "R" }, "value" => "Prefers not to say" },
])
end
it "has the correct id" do
expect(question.id).to eq("sex3")
end
context "and joint purchase" do
let(:question_id) { "sex5" }
let(:person_index) { 5 }
before do
allow(page).to receive(:id).and_return("person_3_gender_identity_joint_purchase")
end
it "has the correct id" do
expect(question.id).to eq("sex5")
end
it "has the correct header" do
expect(question.header).to eq("Which of these best describes Person 3’s gender identity?")
end
it "has the correct header" do
expect(question.header).to eq("Which of these best describes Person 3’s gender identity?")
end
it "has the correct check_answer_label" do
expect(question.check_answer_label).to eq("Person 3’s gender identity")
end
it "has the correct check_answer_label" do
expect(question.check_answer_label).to eq("Person 3’s gender identity")
end
it "has expected check answers card number" do
expect(question.check_answers_card_number).to eq(5)
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" => { "sex5" => "R" }, "value" => "Prefers not to say" },
])
end
it "has the correct inferred_check_answers_value" do
expect(question.inferred_check_answers_value).to eq([
{ "condition" => { "sex3" => "R" }, "value" => "Prefers not to say" },
])
end
end
context "when person 4" do
context "and not joint purchase" do
let(:question_id) { "sex5" }
let(:person_index) { 5 }
before do
allow(page).to receive(:id).and_return("person_4_gender_identity")
end
it "has the correct id" do
expect(question.id).to eq("sex5")
end
let(:question_id) { "sex4" }
let(:person_index) { 4 }
it "has the correct header" do
expect(question.header).to eq("Which of these best describes Person 4’s gender identity?")
end
it "has the correct id" do
expect(question.id).to eq("sex4")
end
it "has the correct check_answer_label" do
expect(question.check_answer_label).to eq("Person 4’s gender identity")
end
it "has the correct header" do
expect(question.header).to eq("Which of these best describes Person 4’s gender identity?")
end
it "has expected check answers card number" do
expect(question.check_answers_card_number).to eq(5)
end
it "has the correct check_answer_label" do
expect(question.check_answer_label).to eq("Person 4’s gender identity")
end
it "has the correct inferred_check_answers_value" do
expect(question.inferred_check_answers_value).to eq([
{ "condition" => { "sex5" => "R" }, "value" => "Prefers not to say" },
])
end
it "has expected check answers card number" do
expect(question.check_answers_card_number).to eq(4)
end
context "and joint purchase" do
let(:question_id) { "sex6" }
let(:person_index) { 6 }
it "has the correct inferred_check_answers_value" do
expect(question.inferred_check_answers_value).to eq([
{ "condition" => { "sex4" => "R" }, "value" => "Prefers not to say" },
])
end
end
before do
allow(page).to receive(:id).and_return("person_4_gender_identity_joint_purchase")
end
context "when person 5" do
let(:question_id) { "sex5" }
let(:person_index) { 5 }
it "has the correct id" do
expect(question.id).to eq("sex6")
end
it "has the correct id" do
expect(question.id).to eq("sex5")
end
it "has the correct header" do
expect(question.header).to eq("Which of these best describes Person 4’s gender identity?")
end
it "has the correct header" do
expect(question.header).to eq("Which of these best describes Person 5’s gender identity?")
end
it "has the correct check_answer_label" do
expect(question.check_answer_label).to eq("Person 4’s gender identity")
end
it "has the correct check_answer_label" do
expect(question.check_answer_label).to eq("Person 5’s gender identity")
end
it "has expected check answers card number" do
expect(question.check_answers_card_number).to eq(6)
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" => { "sex6" => "R" }, "value" => "Prefers not to say" },
])
end
it "has the correct inferred_check_answers_value" do
expect(question.inferred_check_answers_value).to eq([
{ "condition" => { "sex5" => "R" }, "value" => "Prefers not to say" },
])
end
end
end

332
spec/models/form/sales/questions/person_known_spec.rb

@ -8,10 +8,6 @@ RSpec.describe Form::Sales::Questions::PersonKnown, type: :model do
let(:page) { instance_double(Form::Page) }
let(:person_index) { 2 }
before do
allow(page).to receive(:id).and_return("person_1_known")
end
it "has correct page" do
expect(question.page).to eq(page)
end
@ -31,291 +27,119 @@ RSpec.describe Form::Sales::Questions::PersonKnown, type: :model do
})
end
it "has correct conditional for" do
expect(question.conditional_for).to be_nil
end
it "has the correct hint" do
expect(question.hint_text).to be_nil
end
context "with a non joint purchase" do
context "and person 1" do
let(:question_id) { "details_known_1" }
let(:person_index) { 2 }
before do
allow(page).to receive(:id).and_return("person_1_known")
end
it "has the correct id" do
expect(question.id).to eq("details_known_1")
end
it "has the correct header" do
expect(question.header).to eq("Do you know the details for person 1?")
end
it "has the correct check_answer_label" do
expect(question.check_answer_label).to eq("Details known for person 1?")
end
context "with person 2" do
let(:question_id) { "details_known_2" }
let(:person_index) { 2 }
it "has correct conditional for" do
expect(question.conditional_for).to be_nil
end
it "has the correct hidden_in_check_answers" do
expect(question.hidden_in_check_answers).to eq(
"depends_on" => [{ "details_known_1" => 1 }],
)
end
it "has the correct check_answers_card_number" do
expect(question.check_answers_card_number).to eq(2)
end
it "has the correct id" do
expect(question.id).to eq("details_known_2")
end
context "and person 2" do
let(:question_id) { "details_known_2" }
let(:person_index) { 3 }
before do
allow(page).to receive(:id).and_return("person_2_known")
end
it "has the correct id" do
expect(question.id).to eq("details_known_2")
end
it "has the correct header" do
expect(question.header).to eq("Do you know the details for person 2?")
end
it "has the correct check_answer_label" do
expect(question.check_answer_label).to eq("Details known for person 2?")
end
it "has correct conditional for" do
expect(question.conditional_for).to be_nil
end
it "has the correct hidden_in_check_answers" do
expect(question.hidden_in_check_answers).to eq(
"depends_on" => [{ "details_known_2" => 1 }],
)
end
it "has the correct check_answers_card_number" do
expect(question.check_answers_card_number).to eq(3)
end
it "has the correct header" do
expect(question.header).to eq("Do you know the details for person 2?")
end
context "and person 3" do
let(:question_id) { "details_known_3" }
let(:person_index) { 4 }
before do
allow(page).to receive(:id).and_return("person_3_known")
end
it "has the correct id" do
expect(question.id).to eq("details_known_3")
end
it "has the correct header" do
expect(question.header).to eq("Do you know the details for person 3?")
end
it "has the correct check_answer_label" do
expect(question.check_answer_label).to eq("Details known for person 3?")
end
it "has correct conditional for" do
expect(question.conditional_for).to be_nil
end
it "has the correct hidden_in_check_answers" do
expect(question.hidden_in_check_answers).to eq(
"depends_on" => [{ "details_known_3" => 1 }],
)
end
it "has the correct check_answers_card_number" do
expect(question.check_answers_card_number).to eq(4)
end
it "has the correct check_answer_label" do
expect(question.check_answer_label).to eq("Details known for person 2?")
end
context "and person 4" do
let(:question_id) { "details_known_4" }
let(:person_index) { 5 }
before do
allow(page).to receive(:id).and_return("person_4_known")
end
it "has the correct id" do
expect(question.id).to eq("details_known_4")
end
it "has the correct header" do
expect(question.header).to eq("Do you know the details for person 4?")
end
it "has the correct check_answer_label" do
expect(question.check_answer_label).to eq("Details known for person 4?")
end
it "has correct conditional for" do
expect(question.conditional_for).to be_nil
end
it "has the correct hidden_in_check_answers" do
expect(question.hidden_in_check_answers).to eq(
"depends_on" => [{ "details_known_4" => 1 }],
)
end
it "has the correct hidden_in_check_answers" do
expect(question.hidden_in_check_answers).to eq(
"depends_on" => [{ "details_known_2" => 1 }],
)
end
it "has the correct check_answers_card_number" do
expect(question.check_answers_card_number).to eq(5)
end
it "has the correct check_answers_card_number" do
expect(question.check_answers_card_number).to eq(2)
end
end
context "with a joint purchase" do
context "and person 1" do
let(:question_id) { "details_known_1" }
let(:person_index) { 3 }
before do
allow(page).to receive(:id).and_return("person_1_known_joint_purchase")
end
it "has the correct id" do
expect(question.id).to eq("details_known_1")
end
it "has the correct header" do
expect(question.header).to eq("Do you know the details for person 1?")
end
it "has the correct check_answer_label" do
expect(question.check_answer_label).to eq("Details known for person 1?")
end
it "has correct conditional for" do
expect(question.conditional_for).to be_nil
end
it "has the correct hidden_in_check_answers" do
expect(question.hidden_in_check_answers).to eq(
"depends_on" => [{ "details_known_1" => 1 }],
)
end
context "with person 3" do
let(:question_id) { "details_known_3" }
let(:person_index) { 3 }
it "has the correct check_answers_card_number" do
expect(question.check_answers_card_number).to eq(3)
end
it "has the correct id" do
expect(question.id).to eq("details_known_3")
end
context "and person 2" do
let(:question_id) { "details_known_2" }
let(:person_index) { 4 }
before do
allow(page).to receive(:id).and_return("person_2_known_joint_purchase")
end
it "has the correct id" do
expect(question.id).to eq("details_known_2")
end
it "has the correct header" do
expect(question.header).to eq("Do you know the details for person 2?")
end
it "has the correct check_answer_label" do
expect(question.check_answer_label).to eq("Details known for person 2?")
end
it "has correct conditional for" do
expect(question.conditional_for).to be_nil
end
it "has the correct hidden_in_check_answers" do
expect(question.hidden_in_check_answers).to eq(
"depends_on" => [{ "details_known_2" => 1 }],
)
end
it "has the correct check_answers_card_number" do
expect(question.check_answers_card_number).to eq(4)
end
it "has the correct header" do
expect(question.header).to eq("Do you know the details for person 3?")
end
context "and person 3" do
let(:question_id) { "details_known_3" }
let(:person_index) { 5 }
before do
allow(page).to receive(:id).and_return("person_3_known_joint_purchase")
end
it "has the correct check_answer_label" do
expect(question.check_answer_label).to eq("Details known for person 3?")
end
it "has the correct id" do
expect(question.id).to eq("details_known_3")
end
it "has the correct hidden_in_check_answers" do
expect(question.hidden_in_check_answers).to eq(
"depends_on" => [{ "details_known_3" => 1 }],
)
end
it "has the correct header" do
expect(question.header).to eq("Do you know the details for person 3?")
end
it "has the correct check_answers_card_number" do
expect(question.check_answers_card_number).to eq(3)
end
end
it "has the correct check_answer_label" do
expect(question.check_answer_label).to eq("Details known for person 3?")
end
context "with person 4" do
let(:question_id) { "details_known_4" }
let(:person_index) { 4 }
it "has correct conditional for" do
expect(question.conditional_for).to be_nil
end
it "has the correct id" do
expect(question.id).to eq("details_known_4")
end
it "has the correct hidden_in_check_answers" do
expect(question.hidden_in_check_answers).to eq(
"depends_on" => [{ "details_known_3" => 1 }],
)
end
it "has the correct header" do
expect(question.header).to eq("Do you know the details for person 4?")
end
it "has the correct check_answers_card_number" do
expect(question.check_answers_card_number).to eq(5)
end
it "has the correct check_answer_label" do
expect(question.check_answer_label).to eq("Details known for person 4?")
end
context "and person 4" do
let(:question_id) { "details_known_4" }
let(:person_index) { 6 }
it "has the correct hidden_in_check_answers" do
expect(question.hidden_in_check_answers).to eq(
"depends_on" => [{ "details_known_4" => 1 }],
)
end
before do
allow(page).to receive(:id).and_return("person_4_known_joint_purchase")
end
it "has the correct check_answers_card_number" do
expect(question.check_answers_card_number).to eq(4)
end
end
it "has the correct id" do
expect(question.id).to eq("details_known_4")
end
context "with person 5" do
let(:question_id) { "details_known_5" }
let(:person_index) { 5 }
it "has the correct header" do
expect(question.header).to eq("Do you know the details for person 4?")
end
it "has the correct id" do
expect(question.id).to eq("details_known_5")
end
it "has the correct check_answer_label" do
expect(question.check_answer_label).to eq("Details known for person 4?")
end
it "has the correct header" do
expect(question.header).to eq("Do you know the details for person 5?")
end
it "has correct conditional for" do
expect(question.conditional_for).to be_nil
end
it "has the correct check_answer_label" do
expect(question.check_answer_label).to eq("Details known for person 5?")
end
it "has the correct hidden_in_check_answers" do
expect(question.hidden_in_check_answers).to eq(
"depends_on" => [{ "details_known_4" => 1 }],
)
end
it "has the correct hidden_in_check_answers" do
expect(question.hidden_in_check_answers).to eq(
"depends_on" => [{ "details_known_5" => 1 }],
)
end
it "has the correct check_answers_card_number" do
expect(question.check_answers_card_number).to eq(6)
end
it "has the correct check_answers_card_number" do
expect(question.check_answers_card_number).to eq(5)
end
end
end

294
spec/models/form/sales/questions/person_relationship_to_buyer1_spec.rb

@ -8,10 +8,6 @@ RSpec.describe Form::Sales::Questions::PersonRelationshipToBuyer1, type: :model
let(:page) { instance_double(Form::Page) }
let(:person_index) { 2 }
before do
allow(page).to receive(:id).and_return("person_1_relationship_to_buyer_1")
end
it "has correct page" do
expect(question.page).to eq(page)
end
@ -37,259 +33,111 @@ RSpec.describe Form::Sales::Questions::PersonRelationshipToBuyer1, type: :model
})
end
context "when person 1" do
context "and not joint purchase" do
let(:question_id) { "relat2" }
let(:person_index) { 2 }
before do
allow(page).to receive(:id).and_return("person_1_relationship_to_buyer_1")
end
it "has the correct id" do
expect(question.id).to eq("relat2")
end
it "has the correct header" do
expect(question.header).to eq("What is Person 1’s relationship to Buyer 1?")
end
it "has the correct check_answer_label" do
expect(question.check_answer_label).to eq("Person 1’s relationship to Buyer 1")
end
it "has expected check answers card number" do
expect(question.check_answers_card_number).to eq(2)
end
context "when person 2" do
let(:question_id) { "relat2" }
let(:person_index) { 2 }
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
it "has the correct id" do
expect(question.id).to eq("relat2")
end
context "and joint purchase" do
let(:person_index) { 3 }
let(:question_id) { "relat3" }
before do
allow(page).to receive(:id).and_return("person_1_relationship_to_buyer_1_joint_purchase")
end
it "has the correct id" do
expect(question.id).to eq("relat3")
end
it "has the correct header" do
expect(question.header).to eq("What is Person 1’s relationship to Buyer 1?")
end
it "has the correct check_answer_label" do
expect(question.check_answer_label).to eq("Person 1’s relationship to Buyer 1")
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
it "has the correct header" do
expect(question.header).to eq("What is Person 2’s relationship to Buyer 1?")
end
end
context "when person 2" do
context "and not joint purchase" do
let(:question_id) { "relat3" }
let(:person_index) { 3 }
before do
allow(page).to receive(:id).and_return("person_2_relationship_to_buyer_1")
end
it "has the correct id" do
expect(question.id).to eq("relat3")
end
it "has the correct header" do
expect(question.header).to eq("What is Person 2’s relationship to Buyer 1?")
end
it "has the correct check_answer_label" do
expect(question.check_answer_label).to eq("Person 2’s relationship to Buyer 1")
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
it "has the correct check_answer_label" do
expect(question.check_answer_label).to eq("Person 2’s relationship to Buyer 1")
end
context "and joint purchase" do
let(:question_id) { "relat4" }
let(:person_index) { 4 }
before do
allow(page).to receive(:id).and_return("person_2_relationship_to_buyer_1_joint_purchase")
end
it "has the correct id" do
expect(question.id).to eq("relat4")
end
it "has the correct header" do
expect(question.header).to eq("What is Person 2’s relationship to Buyer 1?")
end
it "has the correct check_answer_label" do
expect(question.check_answer_label).to eq("Person 2’s relationship to Buyer 1")
end
it "has expected check answers card number" do
expect(question.check_answers_card_number).to eq(4)
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" => { "relat4" => "R" }, "value" => "Prefers not to say" },
])
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
context "and not joint purchase" do
let(:question_id) { "relat4" }
let(:person_index) { 4 }
before do
allow(page).to receive(:id).and_return("person_3_relationship_to_buyer_1")
end
it "has the correct id" do
expect(question.id).to eq("relat4")
end
it "has the correct header" do
expect(question.header).to eq("What is Person 3’s relationship to Buyer 1?")
end
it "has the correct check_answer_label" do
expect(question.check_answer_label).to eq("Person 3’s relationship to Buyer 1")
end
let(:question_id) { "relat3" }
let(:person_index) { 3 }
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
it "has the correct id" do
expect(question.id).to eq("relat3")
end
context "and joint purchase" do
let(:question_id) { "relat5" }
let(:person_index) { 5 }
before do
allow(page).to receive(:id).and_return("person_3_relationship_to_buyer_1_joint_purchase")
end
it "has the correct id" do
expect(question.id).to eq("relat5")
end
it "has the correct header" do
expect(question.header).to eq("What is Person 3’s relationship to Buyer 1?")
end
it "has the correct header" do
expect(question.header).to eq("What is Person 3’s relationship to Buyer 1?")
end
it "has the correct check_answer_label" do
expect(question.check_answer_label).to eq("Person 3’s relationship to Buyer 1")
end
it "has the correct check_answer_label" do
expect(question.check_answer_label).to eq("Person 3’s relationship to Buyer 1")
end
it "has expected check answers card number" do
expect(question.check_answers_card_number).to eq(5)
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" => { "relat5" => "R" }, "value" => "Prefers not to say" },
])
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
context "and not joint purchase" do
let(:question_id) { "relat5" }
let(:person_index) { 5 }
before do
allow(page).to receive(:id).and_return("person_4_relationship_to_buyer_1")
end
it "has the correct id" do
expect(question.id).to eq("relat5")
end
let(:question_id) { "relat4" }
let(:person_index) { 4 }
it "has the correct header" do
expect(question.header).to eq("What is Person 4’s relationship to Buyer 1?")
end
it "has the correct id" do
expect(question.id).to eq("relat4")
end
it "has the correct check_answer_label" do
expect(question.check_answer_label).to eq("Person 4’s relationship to Buyer 1")
end
it "has the correct header" do
expect(question.header).to eq("What is Person 4’s relationship to Buyer 1?")
end
it "has expected check answers card number" do
expect(question.check_answers_card_number).to eq(5)
end
it "has the correct check_answer_label" do
expect(question.check_answer_label).to eq("Person 4’s relationship to Buyer 1")
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
it "has expected check answers card number" do
expect(question.check_answers_card_number).to eq(4)
end
context "and joint purchase" do
let(:question_id) { "relat6" }
let(:person_index) { 6 }
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
before do
allow(page).to receive(:id).and_return("person_4_relationship_to_buyer_1_joint_purchase")
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("relat6")
end
it "has the correct id" do
expect(question.id).to eq("relat5")
end
it "has the correct header" do
expect(question.header).to eq("What is Person 4’s relationship to Buyer 1?")
end
it "has the correct header" do
expect(question.header).to eq("What is Person 5’s relationship to Buyer 1?")
end
it "has the correct check_answer_label" do
expect(question.check_answer_label).to eq("Person 4’s relationship to Buyer 1")
end
it "has the correct check_answer_label" do
expect(question.check_answer_label).to eq("Person 5’s relationship to Buyer 1")
end
it "has expected check answers card number" do
expect(question.check_answers_card_number).to eq(6)
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" => { "relat6" => "R" }, "value" => "Prefers not to say" },
])
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

298
spec/models/form/sales/questions/person_working_situation_spec.rb

@ -8,10 +8,6 @@ RSpec.describe Form::Sales::Questions::PersonWorkingSituation, type: :model do
let(:page) { instance_double(Form::Page) }
let(:person_index) { 2 }
before do
allow(page).to receive(:id).and_return("person_1_working_situation")
end
it "has correct page" do
expect(question.page).to eq(page)
end
@ -24,10 +20,6 @@ RSpec.describe Form::Sales::Questions::PersonWorkingSituation, type: :model do
expect(question.derived?).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({
"2" => { "value" => "Part-time - Less than 30 hours" },
@ -44,259 +36,111 @@ RSpec.describe Form::Sales::Questions::PersonWorkingSituation, type: :model do
})
end
context "when person 1" do
context "and not joint purchase" do
let(:question_id) { "ecstat2" }
let(:person_index) { 2 }
before do
allow(page).to receive(:id).and_return("person_1_working_situation")
end
it "has the correct id" do
expect(question.id).to eq("ecstat2")
end
it "has the correct header" do
expect(question.header).to eq("Which of these best describes Person 1’s working situation?")
end
it "has the correct check_answer_label" do
expect(question.check_answer_label).to eq("Person 1’s working situation")
end
it "has expected check answers card number" do
expect(question.check_answers_card_number).to eq(2)
end
context "when person 2" do
let(:question_id) { "ecstat2" }
let(:person_index) { 2 }
it "has the correct inferred_check_answers_value" do
expect(question.inferred_check_answers_value).to eq([
{ "condition" => { "ecstat2" => 10 }, "value" => "Prefers not to say" },
])
end
it "has the correct id" do
expect(question.id).to eq("ecstat2")
end
context "and joint purchase" do
let(:person_index) { 3 }
let(:question_id) { "ecstat3" }
before do
allow(page).to receive(:id).and_return("person_1_working_situation_joint_purchase")
end
it "has the correct id" do
expect(question.id).to eq("ecstat3")
end
it "has the correct header" do
expect(question.header).to eq("Which of these best describes Person 1’s working situation?")
end
it "has the correct check_answer_label" do
expect(question.check_answer_label).to eq("Person 1’s working situation")
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" => { "ecstat3" => 10 }, "value" => "Prefers not to say" },
])
end
it "has the correct header" do
expect(question.header).to eq("Which of these best describes Person 2’s working situation?")
end
end
context "when person 2" do
context "and not joint purchase" do
let(:question_id) { "ecstat3" }
let(:person_index) { 3 }
before do
allow(page).to receive(:id).and_return("person_2_working_situation")
end
it "has the correct id" do
expect(question.id).to eq("ecstat3")
end
it "has the correct header" do
expect(question.header).to eq("Which of these best describes Person 2’s working situation?")
end
it "has the correct check_answer_label" do
expect(question.check_answer_label).to eq("Person 2’s working situation")
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" => { "ecstat3" => 10 }, "value" => "Prefers not to say" },
])
end
it "has the correct check_answer_label" do
expect(question.check_answer_label).to eq("Person 2’s working situation")
end
context "and joint purchase" do
let(:question_id) { "ecstat4" }
let(:person_index) { 4 }
before do
allow(page).to receive(:id).and_return("person_2_working_situation_joint_purchase")
end
it "has the correct id" do
expect(question.id).to eq("ecstat4")
end
it "has the correct header" do
expect(question.header).to eq("Which of these best describes Person 2’s working situation?")
end
it "has the correct check_answer_label" do
expect(question.check_answer_label).to eq("Person 2’s working situation")
end
it "has expected check answers card number" do
expect(question.check_answers_card_number).to eq(4)
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" => { "ecstat4" => 10 }, "value" => "Prefers not to say" },
])
end
it "has the correct inferred_check_answers_value" do
expect(question.inferred_check_answers_value).to eq([
{ "condition" => { "ecstat2" => 10 }, "value" => "Prefers not to say" },
])
end
end
context "when person 3" do
context "and not joint purchase" do
let(:question_id) { "ecstat4" }
let(:person_index) { 4 }
before do
allow(page).to receive(:id).and_return("person_3_working_situation")
end
it "has the correct id" do
expect(question.id).to eq("ecstat4")
end
it "has the correct header" do
expect(question.header).to eq("Which of these best describes Person 3’s working situation?")
end
let(:question_id) { "ecstat3" }
let(:person_index) { 3 }
it "has the correct check_answer_label" do
expect(question.check_answer_label).to eq("Person 3’s working situation")
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" => { "ecstat4" => 10 }, "value" => "Prefers not to say" },
])
end
it "has the correct id" do
expect(question.id).to eq("ecstat3")
end
context "and joint purchase" do
let(:question_id) { "ecstat5" }
let(:person_index) { 5 }
before do
allow(page).to receive(:id).and_return("person_3_working_situation_joint_purchase")
end
it "has the correct id" do
expect(question.id).to eq("ecstat5")
end
it "has the correct header" do
expect(question.header).to eq("Which of these best describes Person 3’s working situation?")
end
it "has the correct header" do
expect(question.header).to eq("Which of these best describes Person 3’s working situation?")
end
it "has the correct check_answer_label" do
expect(question.check_answer_label).to eq("Person 3’s working situation")
end
it "has the correct check_answer_label" do
expect(question.check_answer_label).to eq("Person 3’s working situation")
end
it "has expected check answers card number" do
expect(question.check_answers_card_number).to eq(5)
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" => { "ecstat5" => 10 }, "value" => "Prefers not to say" },
])
end
it "has the correct inferred_check_answers_value" do
expect(question.inferred_check_answers_value).to eq([
{ "condition" => { "ecstat3" => 10 }, "value" => "Prefers not to say" },
])
end
end
context "when person 4" do
context "and not joint purchase" do
let(:question_id) { "ecstat5" }
let(:person_index) { 5 }
before do
allow(page).to receive(:id).and_return("person_4_working_situation")
end
it "has the correct id" do
expect(question.id).to eq("ecstat5")
end
let(:question_id) { "ecstat4" }
let(:person_index) { 4 }
it "has the correct header" do
expect(question.header).to eq("Which of these best describes Person 4’s working situation?")
end
it "has the correct id" do
expect(question.id).to eq("ecstat4")
end
it "has the correct check_answer_label" do
expect(question.check_answer_label).to eq("Person 4’s working situation")
end
it "has the correct header" do
expect(question.header).to eq("Which of these best describes Person 4’s working situation?")
end
it "has expected check answers card number" do
expect(question.check_answers_card_number).to eq(5)
end
it "has the correct check_answer_label" do
expect(question.check_answer_label).to eq("Person 4’s working situation")
end
it "has the correct inferred_check_answers_value" do
expect(question.inferred_check_answers_value).to eq([
{ "condition" => { "ecstat5" => 10 }, "value" => "Prefers not to say" },
])
end
it "has expected check answers card number" do
expect(question.check_answers_card_number).to eq(4)
end
context "and joint purchase" do
let(:question_id) { "ecstat6" }
let(:person_index) { 6 }
it "has the correct inferred_check_answers_value" do
expect(question.inferred_check_answers_value).to eq([
{ "condition" => { "ecstat4" => 10 }, "value" => "Prefers not to say" },
])
end
end
before do
allow(page).to receive(:id).and_return("person_4_working_situation_joint_purchase")
end
context "when person 5" do
let(:question_id) { "ecstat5" }
let(:person_index) { 5 }
it "has the correct id" do
expect(question.id).to eq("ecstat6")
end
it "has the correct id" do
expect(question.id).to eq("ecstat5")
end
it "has the correct header" do
expect(question.header).to eq("Which of these best describes Person 4’s working situation?")
end
it "has the correct header" do
expect(question.header).to eq("Which of these best describes Person 5’s working situation?")
end
it "has the correct check_answer_label" do
expect(question.check_answer_label).to eq("Person 4’s working situation")
end
it "has the correct check_answer_label" do
expect(question.check_answer_label).to eq("Person 5’s working situation")
end
it "has expected check answers card number" do
expect(question.check_answers_card_number).to eq(6)
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" => { "ecstat6" => 10 }, "value" => "Prefers not to say" },
])
end
it "has the correct inferred_check_answers_value" do
expect(question.inferred_check_answers_value).to eq([
{ "condition" => { "ecstat5" => 10 }, "value" => "Prefers not to say" },
])
end
end
end

73
spec/models/form/sales/subsections/household_characteristics_spec.rb

@ -18,11 +18,9 @@ RSpec.describe Form::Sales::Subsections::HouseholdCharacteristics, type: :model
privacy_notice
buyer_1_age
age_1_retirement_value_check
age_1_retirement_value_check_joint_purchase
age_1_old_persons_shared_ownership_value_check
buyer_1_gender_identity
gender_1_retirement_value_check
gender_1_retirement_value_check_joint_purchase
buyer_1_ethnic_group
buyer_1_ethnic_background_black
buyer_1_ethnic_background_asian
@ -32,83 +30,50 @@ RSpec.describe Form::Sales::Subsections::HouseholdCharacteristics, type: :model
buyer_1_nationality
buyer_1_working_situation
working_situation_1_retirement_value_check
working_situation_1_retirement_value_check_joint_purchase
working_situation_buyer_1_income_value_check
buyer_1_live_in_property
buyer_2_relationship_to_buyer_1
buyer_2_age
age_2_retirement_value_check_joint_purchase
age_2_old_persons_shared_ownership_value_check
age_2_buyer_retirement_value_check
buyer_2_gender_identity
gender_2_retirement_value_check_joint_purchase
gender_2_buyer_retirement_value_check
buyer_2_working_situation
working_situation_2_retirement_value_check_joint_purchase
working_situation_2_buyer_retirement_value_check
buyer_2_live_in_property
number_of_others_in_property
person_1_known
person_1_known_joint_purchase
person_1_relationship_to_buyer_1
person_1_relationship_to_buyer_1_joint_purchase
person_1_age
age_2_retirement_value_check
person_1_age_joint_purchase
age_3_retirement_value_check_joint_purchase
person_1_gender_identity
gender_2_retirement_value_check
person_1_gender_identity_joint_purchase
gender_3_retirement_value_check_joint_purchase
person_1_working_situation
working_situation_2_retirement_value_check
person_1_working_situation_joint_purchase
working_situation_3_retirement_value_check_joint_purchase
person_2_known
person_2_known_joint_purchase
person_2_relationship_to_buyer_1
person_2_relationship_to_buyer_1_joint_purchase
person_2_age
age_3_retirement_value_check
person_2_age_joint_purchase
age_4_retirement_value_check_joint_purchase
age_2_retirement_value_check
person_2_gender_identity
gender_3_retirement_value_check
person_2_gender_identity_joint_purchase
gender_4_retirement_value_check_joint_purchase
gender_2_retirement_value_check
person_2_working_situation
working_situation_3_retirement_value_check
person_2_working_situation_joint_purchase
working_situation_4_retirement_value_check_joint_purchase
working_situation_2_retirement_value_check
person_3_known
person_3_known_joint_purchase
person_3_relationship_to_buyer_1
person_3_relationship_to_buyer_1_joint_purchase
person_3_age
age_4_retirement_value_check
person_3_age_joint_purchase
age_5_retirement_value_check_joint_purchase
age_3_retirement_value_check
person_3_gender_identity
gender_4_retirement_value_check
person_3_gender_identity_joint_purchase
gender_5_retirement_value_check_joint_purchase
gender_3_retirement_value_check
person_3_working_situation
working_situation_4_retirement_value_check
person_3_working_situation_joint_purchase
working_situation_5_retirement_value_check_joint_purchase
working_situation_3_retirement_value_check
person_4_known
person_4_known_joint_purchase
person_4_relationship_to_buyer_1
person_4_relationship_to_buyer_1_joint_purchase
person_4_age
age_5_retirement_value_check
person_4_age_joint_purchase
age_6_retirement_value_check_joint_purchase
age_4_retirement_value_check
person_4_gender_identity
gender_5_retirement_value_check
person_4_gender_identity_joint_purchase
gender_6_retirement_value_check_joint_purchase
gender_4_retirement_value_check
person_4_working_situation
working_situation_4_retirement_value_check
person_5_known
person_5_relationship_to_buyer_1
person_5_age
age_5_retirement_value_check
person_5_gender_identity
gender_5_retirement_value_check
person_5_working_situation
working_situation_5_retirement_value_check
person_4_working_situation_joint_purchase
working_situation_6_retirement_value_check_joint_purchase
],
)
end

4
spec/models/form_handler_spec.rb

@ -52,14 +52,14 @@ RSpec.describe FormHandler do
it "is able to load a current sales form" do
form = form_handler.get_form("current_sales")
expect(form).to be_a(Form)
expect(form.pages.count).to eq(214)
expect(form.pages.count).to eq(179)
expect(form.name).to eq("2022_2023_sales")
end
it "is able to load a previous sales form" do
form = form_handler.get_form("previous_sales")
expect(form).to be_a(Form)
expect(form.pages.count).to eq(214)
expect(form.pages.count).to eq(179)
expect(form.name).to eq("2021_2022_sales")
end
end

4
spec/models/sales_log_spec.rb

@ -252,10 +252,10 @@ RSpec.describe SalesLog, type: :model do
:completed,
jointpur: 1,
hholdcount: 4,
details_known_1: 1,
details_known_2: 1,
details_known_3: 1,
details_known_4: 1,
details_known_5: 1,
details_known_6: 1,
relat2: "C",
relat3: "C",
relat4: "X",

22
spec/models/validations/shared_validations_spec.rb

@ -5,7 +5,7 @@ RSpec.describe Validations::SharedValidations do
let(:validator_class) { Class.new { include Validations::SharedValidations } }
let(:record) { FactoryBot.create(:lettings_log) }
let(:sales_record) { FactoryBot.create(:sales_log) }
let(:sales_record) { FactoryBot.create(:sales_log, :completed) }
let(:fake_2021_2022_form) { Form.new("spec/fixtures/forms/2021_2022.json") }
describe "numeric min max validations" do
@ -67,6 +67,24 @@ RSpec.describe Validations::SharedValidations do
shared_validator.validate_numeric_min_max(record)
expect(record.errors["age6"]).to be_empty
end
context "with sales log" do
it "validates that person 2's age is between 0 and 110 for non joint purchase" do
sales_record.jointpur = 2
sales_record.hholdcount = 1
sales_record.details_known_2 = 1
sales_record.age2 = 130
shared_validator.validate_numeric_min_max(sales_record)
expect(sales_record.errors["age2"].first).to eq("Person 2’s age must be between 0 and 110")
end
it "validates that buyer 2's age is between 0 and 110 for joint purchase" do
sales_record.jointpur = 1
sales_record.age2 = 130
shared_validator.validate_numeric_min_max(sales_record)
expect(sales_record.errors["age2"].first).to eq("Buyer 2’s age must be between 0 and 110")
end
end
end
it "adds the correct validation text when a question has a min but not a max" do
@ -77,6 +95,8 @@ RSpec.describe Validations::SharedValidations do
context "when validating percent" do
it "validates that suffixes are added in the error message" do
sales_record.ownershipsch = 1
sales_record.staircase = 1
sales_record.stairbought = 150
shared_validator.validate_numeric_min_max(sales_record)
expect(sales_record.errors["stairbought"])

Loading…
Cancel
Save