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 3 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 when 1..number_of_buyers
"Buyer #{question.check_answers_card_number}" "Buyer #{question.check_answers_card_number}"
when (number_of_buyers + 1)..(number_of_buyers + 4) 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 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) super(id, hsh, subsection)
@person_index = person_index @person_index = person_index
end 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 end

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

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

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

@ -1,13 +1,34 @@
class Form::Sales::Pages::PersonKnown < Form::Sales::Pages::Person class Form::Sales::Pages::PersonKnown < Form::Sales::Pages::Person
def initialize(id, hsh, subsection, person_index:) def initialize(id, hsh, subsection, person_index:)
super super
@header_partial = "person_#{person_display_number}_known_page" @header_partial = "person_#{person_index}_known_page"
@depends_on = (person_display_number..4).map { |index| { "hholdcount" => index, "jointpur" => joint_purchase? ? 1 : 2 } } @depends_on = depends_on
end end
def questions def questions
@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 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 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:) def initialize(id, hsh, subsection, person_index:)
super super
@depends_on = [ @depends_on = [
{ details_known_question_id => 1, "jointpur" => joint_purchase? ? 1 : 2 }, { "details_known_#{person_index}" => 1 },
] ]
end end
def questions def questions
@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
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 class Form::Sales::Pages::PersonWorkingSituation < Form::Sales::Pages::Person
def initialize(id, hsh, subsection, person_index:) def initialize(id, hsh, subsection, person_index:)
super super
@depends_on = [{ details_known_question_id => 1, "jointpur" => joint_purchase? ? 1 : 2 }] @depends_on = [{ "details_known_#{person_index}" => 1 }]
end end
def questions def questions
@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
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 = [ @depends_on = [
{ {
"person_#{person_index}_retired_under_soft_min_age?" => true, "person_#{person_index}_retired_under_soft_min_age?" => true,
"jointpur" => joint_purchase? ? 1 : 2,
}, },
] ]
@person_index = person_index @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:) def initialize(id, hsh, page, person_index:)
super super(id, hsh, page)
@check_answer_label = "Person #{person_display_number}’s age" @check_answer_label = "Person #{person_index}’s age"
@header = "Age" @header = "Age"
@type = "numeric" @type = "numeric"
@width = 3 @width = 3
@inferred_check_answers_value = [{ @inferred_check_answers_value = [{
"condition" => { field_for_person("age", "_known") => 1 }, "condition" => { "age#{person_index}_known" => 1 },
"value" => "Not known", "value" => "Not known",
}] }]
@check_answers_card_number = person_index @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:) def initialize(id, hsh, page, person_index:)
super super(id, hsh, page)
@check_answer_label = "Person #{person_display_number}’s age known?" @check_answer_label = "Person #{person_index}’s age known?"
@header = "Do you know person #{person_display_number}’s age?" @header = "Do you know person #{person_index}’s age?"
@type = "radio" @type = "radio"
@answer_options = ANSWER_OPTIONS @answer_options = ANSWER_OPTIONS
@conditional_for = { @conditional_for = {
field_for_person("age") => [0], "age#{person_index}" => [0],
} }
@hidden_in_check_answers = { @hidden_in_check_answers = {
"depends_on" => [ "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 end
ANSWER_OPTIONS = { 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:) def initialize(id, hsh, page, person_index:)
super super(id, hsh, page)
@check_answer_label = "Person #{person_display_number}’s gender identity" @check_answer_label = "Person #{person_index}’s gender identity"
@header = "Which of these best describes Person #{person_display_number}’s gender identity?" @header = "Which of these best describes Person #{person_index}’s gender identity?"
@type = "radio" @type = "radio"
@answer_options = ANSWER_OPTIONS @answer_options = ANSWER_OPTIONS
@check_answers_card_number = person_index @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:) def initialize(id, hsh, page, person_index:)
super super(id, hsh, page)
@check_answer_label = "Details known for person #{person_display_number}?" @check_answer_label = "Details known for person #{person_index}?"
@header = "Do you know the details for person #{person_display_number}?" @header = "Do you know the details for person #{person_index}?"
@type = "radio" @type = "radio"
@answer_options = ANSWER_OPTIONS @answer_options = ANSWER_OPTIONS
@hidden_in_check_answers = { @hidden_in_check_answers = {
"depends_on" => [ "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:) def initialize(id, hsh, page, person_index:)
super super(id, hsh, page)
@check_answer_label = "Person #{person_display_number}’s relationship to Buyer 1" @check_answer_label = "Person #{person_index}’s relationship to Buyer 1"
@header = "What is Person #{person_display_number}’s relationship to Buyer 1?" @header = "What is Person #{person_index}’s relationship to Buyer 1?"
@type = "radio" @type = "radio"
@answer_options = ANSWER_OPTIONS @answer_options = ANSWER_OPTIONS
@check_answers_card_number = person_index @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:) def initialize(id, hsh, page, person_index:)
super super(id, hsh, page)
@check_answer_label = "Person #{person_display_number}’s working situation" @check_answer_label = "Person #{person_index}’s working situation"
@header = "Which of these best describes Person #{person_display_number}’s working situation?" @header = "Which of these best describes Person #{person_index}’s working situation?"
@type = "radio" @type = "radio"
@answer_options = ANSWER_OPTIONS @answer_options = ANSWER_OPTIONS
@check_answers_card_number = person_index @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::PrivacyNotice.new(nil, nil, self),
Form::Sales::Pages::Age1.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", 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::OldPersonsSharedOwnershipValueCheck.new("age_1_old_persons_shared_ownership_value_check", nil, self),
Form::Sales::Pages::GenderIdentity1.new(nil, 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", 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::Buyer1EthnicGroup.new(nil, nil, self),
Form::Sales::Pages::Buyer1EthnicBackgroundBlack.new(nil, nil, self), Form::Sales::Pages::Buyer1EthnicBackgroundBlack.new(nil, nil, self),
Form::Sales::Pages::Buyer1EthnicBackgroundAsian.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::Nationality1.new(nil, nil, self),
Form::Sales::Pages::Buyer1WorkingSituation.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", 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::Buyer1IncomeValueCheck.new("working_situation_buyer_1_income_value_check", nil, self),
Form::Sales::Pages::Buyer1LiveInProperty.new(nil, nil, self), Form::Sales::Pages::Buyer1LiveInProperty.new(nil, nil, self),
Form::Sales::Pages::Buyer2RelationshipToBuyer1.new(nil, nil, self), Form::Sales::Pages::Buyer2RelationshipToBuyer1.new(nil, nil, self),
Form::Sales::Pages::Age2.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::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::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::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::Buyer2LiveInProperty.new(nil, nil, self),
Form::Sales::Pages::NumberOfOthersInProperty.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_2_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_2_relationship_to_buyer_1", nil, self, person_index: 2),
Form::Sales::Pages::PersonRelationshipToBuyer1.new("person_1_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::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::RetirementValueCheck.new("age_2_retirement_value_check", 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::PersonGenderIdentity.new("person_2_gender_identity", nil, self, person_index: 2),
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::RetirementValueCheck.new("gender_2_retirement_value_check", 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::PersonWorkingSituation.new("person_2_working_situation", nil, self, person_index: 2),
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::RetirementValueCheck.new("working_situation_2_retirement_value_check", 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::PersonKnown.new("person_3_known", 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::PersonRelationshipToBuyer1.new("person_3_relationship_to_buyer_1", nil, self, person_index: 3),
Form::Sales::Pages::PersonKnown.new("person_2_known", nil, self, person_index: 3), Form::Sales::Pages::PersonAge.new("person_3_age", 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::RetirementValueCheck.new("age_3_retirement_value_check", 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::PersonGenderIdentity.new("person_3_gender_identity", nil, self, person_index: 3),
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::RetirementValueCheck.new("gender_3_retirement_value_check", 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::PersonWorkingSituation.new("person_3_working_situation", nil, self, person_index: 3),
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::RetirementValueCheck.new("working_situation_3_retirement_value_check", 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::PersonKnown.new("person_4_known", 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::PersonRelationshipToBuyer1.new("person_4_relationship_to_buyer_1", nil, self, person_index: 4),
Form::Sales::Pages::PersonKnown.new("person_3_known", nil, self, person_index: 4), Form::Sales::Pages::PersonAge.new("person_4_age", 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::RetirementValueCheck.new("age_4_retirement_value_check", 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::PersonGenderIdentity.new("person_4_gender_identity", nil, self, person_index: 4),
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::RetirementValueCheck.new("gender_4_retirement_value_check", 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::PersonWorkingSituation.new("person_4_working_situation", nil, self, person_index: 4),
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::RetirementValueCheck.new("working_situation_4_retirement_value_check", 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::PersonKnown.new("person_5_known", 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::PersonRelationshipToBuyer1.new("person_5_relationship_to_buyer_1", nil, self, person_index: 5),
Form::Sales::Pages::PersonKnown.new("person_4_known", nil, self, person_index: 5), Form::Sales::Pages::PersonAge.new("person_5_age", 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::RetirementValueCheck.new("age_5_retirement_value_check", 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::PersonGenderIdentity.new("person_5_gender_identity", nil, self, person_index: 5),
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::RetirementValueCheck.new("gender_5_retirement_value_check", 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::PersonWorkingSituation.new("person_5_working_situation", nil, self, person_index: 5),
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::RetirementValueCheck.new("working_situation_5_retirement_value_check", 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
end end

2
app/models/validations/shared_validations.rb

@ -18,7 +18,7 @@ module Validations::SharedValidations
def validate_numeric_min_max(record) def validate_numeric_min_max(record)
record.form.numeric_questions.each do |question| record.form.numeric_questions.each do |question|
next unless question.min || question.max next unless question.min || question.max
next unless record[question.id] next unless record[question.id] && question.page.routed_to?(record, nil)
begin begin
answer = Float(record.public_send("#{question.id}_before_type_cast")) 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.integer "prevown"
t.string "sex3" t.string "sex3"
t.bigint "updated_by_id" t.bigint "updated_by_id"
t.integer "details_known_1"
t.integer "income1_value_check" t.integer "income1_value_check"
t.decimal "mortgage", precision: 10, scale: 2 t.decimal "mortgage", precision: 10, scale: 2
t.integer "inc2mort" 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 "staircase_bought_value_check"
t.integer "monthly_charges_value_check" t.integer "monthly_charges_value_check"
t.integer "saledate_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 ["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 ["created_by_id"], name: "index_sales_logs_on_created_by_id"
t.index ["owning_organisation_id"], name: "index_sales_logs_on_owning_organisation_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" } ecstat2 { "1" }
hholdcount { "1" } hholdcount { "1" }
wheel { 1 } wheel { 1 }
details_known_1 { 1 } details_known_3 { 1 }
age3_known { 0 } age3_known { 0 }
age3 { 14 } age3 { 14 }
details_known_2 { 1 } details_known_4 { 1 }
age4_known { 0 } age4_known { 0 }
age4 { 18 } age4 { 18 }
details_known_3 { 1 } details_known_5 { 1 }
age5_known { 0 } age5_known { 0 }
age5 { 40 } age5 { 40 }
details_known_4 { 1 } details_known_6 { 1 }
age6_known { 0 } age6_known { 0 }
age6 { 40 } age6 { 40 }
income1nk { 0 } 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, :completed,
created_by: user, created_by: user,
jointpur: 1, jointpur: 1,
hholdcount: 4,
) )
end end
@ -22,6 +23,7 @@ RSpec.describe "Sales Log Check Answers Page" do
:completed, :completed,
created_by: user, created_by: user,
jointpur: 2, jointpur: 2,
hholdcount: 4,
) )
end 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") 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 1", count: 1
assert_selector ".x-govuk-summary-card__title", text: "Buyer 2", 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 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
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") 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 1", count: 1
assert_selector ".x-govuk-summary-card__title", text: "Buyer 2", count: 0 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 1", count: 0
assert_selector ".x-govuk-summary-card__title", text: "Person 2", 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 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 expect(page.description).to be_nil
end end
context "with a non joint purchase" do context "with person 2" do
context "and person 1" do let(:page_id) { "person_2_age" }
let(:page_id) { "person_1_age" } let(:person_index) { 2 }
let(:person_index) { 2 }
it "has correct questions" do
it "has correct questions" do expect(page.questions.map(&:id)).to eq(%w[age2_known age2])
expect(page.questions.map(&:id)).to eq(%w[age2_known age2]) end
end
it "has the correct id" do
it "has the correct id" do expect(page.id).to eq("person_2_age")
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
end end
context "and person 2" do it "has correct depends_on" do
let(:page_id) { "person_2_age" } expect(page.depends_on).to eq(
let(:person_index) { 3 } [{ "details_known_2" => 1 }],
)
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
end end
end
context "with person 3" do
let(:page_id) { "person_3_age" }
let(:person_index) { 3 }
context "and person 3" do it "has correct questions" do
let(:page_id) { "person_3_age" } expect(page.questions.map(&:id)).to eq(%w[age3_known age3])
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
end end
context "and person 4" do it "has the correct id" do
let(:page_id) { "person_4_age" } expect(page.id).to eq("person_3_age")
let(:person_index) { 5 } end
it "has correct questions" do it "has correct depends_on" do
expect(page.questions.map(&:id)).to eq(%w[age5_known age5]) expect(page.depends_on).to eq(
end [
{ "details_known_3" => 1 },
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
end end
end end
context "with joint purchase" do context "with person 4" do
context "and person 1" do let(:page_id) { "person_4_age" }
let(:page_id) { "person_1_age_joint_purchase" } let(:person_index) { 4 }
let(:person_index) { 3 }
it "has correct questions" do it "has correct questions" do
expect(page.questions.map(&:id)).to eq(%w[age3_known age3]) expect(page.questions.map(&:id)).to eq(%w[age4_known age4])
end end
it "has the correct id" do it "has the correct id" do
expect(page.id).to eq("person_1_age_joint_purchase") expect(page.id).to eq("person_4_age")
end end
it "has correct depends_on" do it "has correct depends_on" do
expect(page.depends_on).to eq( expect(page.depends_on).to eq(
[{ "details_known_1" => 1, "jointpur" => 1 }], [
) { "details_known_4" => 1 },
end ],
)
end end
end
context "with person 5" do
let(:page_id) { "person_5_age" }
let(:person_index) { 5 }
context "and person 2" do it "has correct questions" do
let(:page_id) { "person_2_age_joint_purchase" } expect(page.questions.map(&:id)).to eq(%w[age5_known age5])
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
end end
context "and person 3" do it "has the correct id" do
let(:page_id) { "person_3_age_joint_purchase" } expect(page.id).to eq("person_5_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_3_age_joint_purchase")
end
it "has correct depends_on" do
expect(page.depends_on).to eq(
[
{ "details_known_3" => 1, "jointpur" => 1 },
],
)
end
end end
context "and person 4" do it "has correct depends_on" do
let(:page_id) { "person_4_age_joint_purchase" } expect(page.depends_on).to eq(
let(:person_index) { 6 } [
{ "details_known_5" => 1 },
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
end end
end 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(:subsection) { instance_double(Form::Subsection) }
let(:person_index) { 1 } let(:person_index) { 1 }
context "without joint purchase" do let(:page_id) { "person_2_gender_identity" }
let(:page_id) { "person_1_working_situation" }
it "has correct subsection" do it "has correct subsection" do
expect(page.subsection).to eq(subsection) expect(page.subsection).to eq(subsection)
end 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
context "with person 2" do it "has the correct header" do
let(:person_index) { 3 } expect(page.header).to be_nil
let(:page_id) { "person_2_gender_identity" } end
it "has correct questions" do it "has the correct description" do
expect(page.questions.map(&:id)).to eq(%w[sex3]) expect(page.description).to be_nil
end end
it "has the correct id" do context "with person 2 " do
expect(page.id).to eq("person_2_gender_identity") let(:person_index) { 2 }
end let(:page_id) { "person_2_gender_identity" }
it "has correct depends_on" do it "has correct questions" do
expect(page.depends_on).to eq([{ "details_known_2" => 1, "jointpur" => 2 }]) expect(page.questions.map(&:id)).to eq(%w[sex2])
end
end end
context "with person 3" do it "has the correct id" do
let(:person_index) { 4 } expect(page.id).to eq("person_2_gender_identity")
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
end end
context "with person 4" do it "has correct depends_on" do
let(:person_index) { 5 } expect(page.depends_on).to eq([{ "details_known_2" => 1 }])
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
end end
end end
context "with joint purchase" do context "with person 3" do
let(:page_id) { "person_1_gender_identity_joint_purchase" } let(:person_index) { 3 }
let(:page_id) { "person_3_gender_identity" }
it "has correct subsection" do it "has correct questions" do
expect(page.subsection).to eq(subsection) expect(page.questions.map(&:id)).to eq(%w[sex3])
end end
it "has the correct header" do it "has the correct id" do
expect(page.header).to be_nil expect(page.id).to eq("person_3_gender_identity")
end end
it "has the correct description" do it "has correct depends_on" do
expect(page.description).to be_nil expect(page.depends_on).to eq([{ "details_known_3" => 1 }])
end end
end
context "with person 1" do context "with person 4" do
let(:person_index) { 3 } let(:person_index) { 4 }
let(:page_id) { "person_1_gender_identity_joint_purchase" } let(:page_id) { "person_4_gender_identity" }
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
it "has correct depends_on" do it "has correct questions" do
expect(page.depends_on).to eq([{ "details_known_1" => 1, "jointpur" => 1 }]) expect(page.questions.map(&:id)).to eq(%w[sex4])
end
end end
context "with person 2" do it "has the correct id" do
let(:person_index) { 4 } expect(page.id).to eq("person_4_gender_identity")
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
end end
context "with person 3" do it "has correct depends_on" do
let(:person_index) { 5 } expect(page.depends_on).to eq([{ "details_known_4" => 1 }])
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
end end
end
context "with person 4" do context "with person 5" do
let(:person_index) { 6 } let(:person_index) { 5 }
let(:page_id) { "person_4_gender_identity_joint_purchase" } let(:page_id) { "person_5_gender_identity" }
it "has correct questions" do it "has correct questions" do
expect(page.questions.map(&:id)).to eq(%w[sex6]) expect(page.questions.map(&:id)).to eq(%w[sex5])
end end
it "has the correct id" do it "has the correct id" do
expect(page.id).to eq("person_4_gender_identity_joint_purchase") expect(page.id).to eq("person_5_gender_identity")
end end
it "has correct depends_on" do it "has correct depends_on" do
expect(page.depends_on).to eq([{ "details_known_4" => 1, "jointpur" => 1 }]) expect(page.depends_on).to eq([{ "details_known_5" => 1 }])
end
end end
end 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_id) { "person_2_known" }
let(:page_definition) { nil } let(:page_definition) { nil }
let(:subsection) { instance_double(Form::Subsection) } let(:subsection) { instance_double(Form::Subsection) }
let(:person_index) { 3 } let(:person_index) { 2 }
it "has correct subsection" do it "has correct subsection" do
expect(page.subsection).to eq(subsection) 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 expect(page.description).to be_nil
end 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 context "with person 2" do
let(:page_id) { "person_2_known" } let(:page_id) { "person_2_known" }
let(:person_index) { 3 } let(:person_index) { 2 }
it "has correct questions" do it "has correct questions" do
expect(page.questions.map(&:id)).to eq(%w[details_known_2]) 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 end
it "has correct depends_on" do it "has correct depends_on" do
expect(page.depends_on).to eq( expect(page.depends_on).to eq([{
[{ "hholdcount" => 2, "jointpur" => 2 }, { "hholdcount" => 3, "jointpur" => 2 }, { "hholdcount" => 4, "jointpur" => 2 }], "jointpur" => 2,
) "hholdcount" => {
"operator" => ">=",
"operand" => 1,
},
}])
end end
end end
context "with person 3" do context "with person 3" do
let(:page_id) { "person_3_known" } let(:page_id) { "person_3_known" }
let(:person_index) { 4 } let(:person_index) { 3 }
it "has correct questions" do it "has correct questions" do
expect(page.questions.map(&:id)).to eq(%w[details_known_3]) 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 end
it "has correct depends_on" do it "has correct depends_on" do
expect(page.depends_on).to eq( expect(page.depends_on).to eq([
[{ "hholdcount" => 3, "jointpur" => 2 }, { "hholdcount" => 4, "jointpur" => 2 }], {
) "jointpur" => 2,
"hholdcount" => {
"operator" => ">=",
"operand" => 2,
},
},
{
"jointpur" => 1,
"hholdcount" => {
"operator" => ">=",
"operand" => 1,
},
},
])
end end
end end
context "with person 4" do context "with person 4" do
let(:page_id) { "person_4_known" } let(:page_id) { "person_4_known" }
let(:person_index) { 5 } let(:person_index) { 4 }
it "has correct questions" do 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_4])
@ -109,122 +102,58 @@ RSpec.describe Form::Sales::Pages::PersonKnown, type: :model do
end end
it "has correct depends_on" do it "has correct depends_on" do
expect(page.depends_on).to eq( expect(page.depends_on).to eq([
[{ "hholdcount" => 4, "jointpur" => 2 }], {
) "jointpur" => 2,
"hholdcount" => {
"operator" => ">=",
"operand" => 3,
},
},
{
"jointpur" => 1,
"hholdcount" => {
"operator" => ">=",
"operand" => 2,
},
},
])
end end
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 context "with person 5" do
expect(page.header_partial).to eq("person_1_known_page") let(:page_id) { "person_5_known" }
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" }
let(:person_index) { 5 } let(:person_index) { 5 }
it "has correct questions" do it "has correct questions" do
expect(page.questions.map(&:id)).to eq(%w[details_known_3]) expect(page.questions.map(&:id)).to eq(%w[details_known_5])
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])
end end
it "has the correct id" do 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 end
it "has the correct header_partial" do 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 end
it "has correct depends_on" do it "has correct depends_on" do
expect(page.depends_on).to eq( expect(page.depends_on).to eq([
[{ "hholdcount" => 4, "jointpur" => 1 }], {
) "jointpur" => 2,
"hholdcount" => {
"operator" => ">=",
"operand" => 4,
},
},
{
"jointpur" => 1,
"hholdcount" => {
"operator" => ">=",
"operand" => 3,
},
},
])
end end
end 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(:subsection) { instance_double(Form::Subsection) }
let(:person_index) { 1 } 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 it "has correct subsection" do
expect(page.subsection).to eq(subsection) expect(page.subsection).to eq(subsection)
end 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
context "with person 2" do it "has the correct header" do
let(:person_index) { 3 } expect(page.header).to be_nil
let(:page_id) { "person_2_relationship_to_buyer_1" } end
it "has correct questions" do it "has the correct description" do
expect(page.questions.map(&:id)).to eq(%w[relat3]) expect(page.description).to be_nil
end end
it "has the correct id" do context "with person 2" do
expect(page.id).to eq("person_2_relationship_to_buyer_1") let(:person_index) { 2 }
end let(:page_id) { "person_2_relationship_to_buyer_1" }
it "has correct depends_on" do it "has correct questions" do
expect(page.depends_on).to eq([{ "details_known_2" => 1, "jointpur" => 2 }]) expect(page.questions.map(&:id)).to eq(%w[relat2])
end
end end
context "with person 3" do it "has the correct id" do
let(:person_index) { 4 } expect(page.id).to eq("person_2_relationship_to_buyer_1")
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
end end
context "with person 4" do it "has correct depends_on" do
let(:person_index) { 5 } expect(page.depends_on).to eq([{ "details_known_2" => 1 }])
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
end end
end end
context "with joint purchase" do context "with person 3" do
let(:page_id) { "person_1_relationship_to_buyer_1_joint_purchase" } let(:person_index) { 3 }
let(:page_id) { "person_3_relationship_to_buyer_1" }
it "has correct subsection" do it "has correct questions" do
expect(page.subsection).to eq(subsection) expect(page.questions.map(&:id)).to eq(%w[relat3])
end end
it "has the correct header" do it "has the correct id" do
expect(page.header).to be_nil expect(page.id).to eq("person_3_relationship_to_buyer_1")
end end
it "has the correct description" do it "has correct depends_on" do
expect(page.description).to be_nil expect(page.depends_on).to eq([{ "details_known_3" => 1 }])
end end
end
context "with person 1" do context "with person 4" do
let(:person_index) { 3 } let(:person_index) { 4 }
let(:page_id) { "person_1_relationship_to_buyer_1_joint_purchase" } let(:page_id) { "person_4_relationship_to_buyer_1" }
it "has correct questions" do
expect(page.questions.map(&:id)).to eq(%w[relat3])
end
it "has the correct id" do
expect(page.id).to eq("person_1_relationship_to_buyer_1_joint_purchase")
end
it "has correct depends_on" do it "has correct questions" do
expect(page.depends_on).to eq([{ "details_known_1" => 1, "jointpur" => 1 }]) expect(page.questions.map(&:id)).to eq(%w[relat4])
end
end end
context "with person 2" do it "has the correct id" do
let(:person_index) { 4 } expect(page.id).to eq("person_4_relationship_to_buyer_1")
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
end end
context "with person 3" do it "has correct depends_on" do
let(:person_index) { 5 } expect(page.depends_on).to eq([{ "details_known_4" => 1 }])
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
end end
end
context "with person 4" do context "with person 5" do
let(:person_index) { 6 } let(:person_index) { 5 }
let(:page_id) { "person_4_relationship_to_buyer_1_joint_purchase" } let(:page_id) { "person_5_relationship_to_buyer_1" }
it "has correct questions" do it "has correct questions" do
expect(page.questions.map(&:id)).to eq(%w[relat6]) expect(page.questions.map(&:id)).to eq(%w[relat5])
end end
it "has the correct id" do it "has the correct id" do
expect(page.id).to eq("person_4_relationship_to_buyer_1_joint_purchase") expect(page.id).to eq("person_5_relationship_to_buyer_1")
end end
it "has correct depends_on" do it "has correct depends_on" do
expect(page.depends_on).to eq([{ "details_known_4" => 1, "jointpur" => 1 }]) expect(page.depends_on).to eq([{ "details_known_5" => 1 }])
end
end end
end 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(:page_definition) { nil }
let(:subsection) { instance_double(Form::Subsection) } let(:subsection) { instance_double(Form::Subsection) }
let(:person_index) { 1 } let(:person_index) { 2 }
context "without joint purchase" do let(:page_id) { "person_2_working_situation" }
let(:page_id) { "person_1_working_situation" }
it "has correct subsection" do it "has correct subsection" do
expect(page.subsection).to eq(subsection) expect(page.subsection).to eq(subsection)
end 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
context "with person 2" do it "has the correct header" do
let(:person_index) { 3 } expect(page.header).to be_nil
let(:page_id) { "person_2_working_situation" } end
it "has correct questions" do it "has the correct description" do
expect(page.questions.map(&:id)).to eq(%w[ecstat3]) expect(page.description).to be_nil
end end
it "has the correct id" do context "with person 2" do
expect(page.id).to eq("person_2_working_situation") let(:person_index) { 2 }
end let(:page_id) { "person_2_working_situation" }
it "has correct depends_on" do it "has correct questions" do
expect(page.depends_on).to eq([{ "details_known_2" => 1, "jointpur" => 2 }]) expect(page.questions.map(&:id)).to eq(%w[ecstat2])
end
end end
context "with person 3" do it "has the correct id" do
let(:person_index) { 4 } expect(page.id).to eq("person_2_working_situation")
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
end end
context "with person 4" do it "has correct depends_on" do
let(:person_index) { 5 } expect(page.depends_on).to eq([{ "details_known_2" => 1 }])
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
end end
end end
context "with joint purchase" do context "with person 3" do
let(:page_id) { "person_1_working_situation_joint_purchase" } let(:person_index) { 3 }
let(:page_id) { "person_3_working_situation" }
it "has correct subsection" do it "has correct questions" do
expect(page.subsection).to eq(subsection) expect(page.questions.map(&:id)).to eq(%w[ecstat3])
end end
it "has the correct header" do it "has the correct id" do
expect(page.header).to be_nil expect(page.id).to eq("person_3_working_situation")
end end
it "has the correct description" do it "has correct depends_on" do
expect(page.description).to be_nil expect(page.depends_on).to eq([{ "details_known_3" => 1 }])
end end
end
context "with person 1" do context "with person 4" do
let(:person_index) { 3 } let(:person_index) { 4 }
let(:page_id) { "person_1_working_situation_joint_purchase" } let(:page_id) { "person_4_working_situation" }
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
it "has correct depends_on" do it "has correct questions" do
expect(page.depends_on).to eq([{ "details_known_1" => 1, "jointpur" => 1 }]) expect(page.questions.map(&:id)).to eq(%w[ecstat4])
end
end end
context "with person 2" do it "has the correct id" do
let(:person_index) { 4 } expect(page.id).to eq("person_4_working_situation")
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
end end
context "with person 3" do it "has correct depends_on" do
let(:person_index) { 5 } expect(page.depends_on).to eq([{ "details_known_4" => 1 }])
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
end end
end
context "with person 4" do context "with person 5" do
let(:person_index) { 6 } let(:person_index) { 5 }
let(:page_id) { "person_4_working_situation_joint_purchase" } let(:page_id) { "person_5_working_situation" }
it "has correct questions" do it "has correct questions" do
expect(page.questions.map(&:id)).to eq(%w[ecstat6]) expect(page.questions.map(&:id)).to eq(%w[ecstat5])
end end
it "has the correct id" do it "has the correct id" do
expect(page.id).to eq("person_4_working_situation_joint_purchase") expect(page.id).to eq("person_5_working_situation")
end end
it "has correct depends_on" do it "has correct depends_on" do
expect(page.depends_on).to eq([{ "details_known_4" => 1, "jointpur" => 1 }]) expect(page.depends_on).to eq([{ "details_known_5" => 1 }])
end
end end
end 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 expect(page.description).to be_nil
end end
context "with joint purchase" do it "is interruption screen page" do
context "with person 1" do expect(page.interruption_screen?).to eq(true)
let(:person_index) { 1 } end
let(:page_id) { "person_1_retirement_value_check_joint_purchase" }
context "with person 1" do
it "has correct questions" do let(:person_index) { 1 }
expect(page.questions.map(&:id)).to eq(%w[retirement_value_check]) let(:page_id) { "person_1_retirement_value_check" }
end
it "has correct questions" do
it "has the correct id" do expect(page.questions.map(&:id)).to eq(%w[retirement_value_check])
expect(page.id).to eq("person_1_retirement_value_check_joint_purchase") end
end
it "has the correct id" do
it "has correct depends_on" do expect(page.id).to eq("person_1_retirement_value_check")
expect(page.depends_on).to eq([{ "person_1_retired_under_soft_min_age?" => true, "jointpur" => 1 }]) end
end
it "has correct depends_on" do
it "has correct title_text" do expect(page.depends_on).to eq([{ "person_1_retired_under_soft_min_age?" => true }])
expect(page.title_text).to eq({ end
"translation" => "soft_validations.retirement.min.title",
"arguments" => [ it "has correct title_text" do
{ expect(page.title_text).to eq({
"key" => "retirement_age_for_person_1", "translation" => "soft_validations.retirement.min.title",
"label" => false, "arguments" => [
"i18n_template" => "age", {
}, "key" => "retirement_age_for_person_1",
], "label" => false,
}) "i18n_template" => "age",
end },
],
it "has correct informative_text" do })
expect(page.informative_text).to eq({ end
"translation" => "soft_validations.retirement.min.hint_text",
"arguments" => [ it "has correct informative_text" do
{ expect(page.informative_text).to eq({
"key" => "plural_gender_for_person_1", "translation" => "soft_validations.retirement.min.hint_text",
"label" => false, "arguments" => [
"i18n_template" => "gender", {
}, "key" => "plural_gender_for_person_1",
{ "label" => false,
"key" => "retirement_age_for_person_1", "i18n_template" => "gender",
"label" => false, },
"i18n_template" => "age", {
}, "key" => "retirement_age_for_person_1",
], "label" => false,
}) "i18n_template" => "age",
end },
],
})
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
end
context "with person 3" do
let(:person_index) { 3 }
let(:page_id) { "person_3_retirement_value_check" }
context "with person 2" do it "has correct questions" do
let(:person_index) { 2 } expect(page.questions.map(&:id)).to eq(%w[retirement_value_check])
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
end end
context "with person 3" do it "has the correct id" do
let(:person_index) { 3 } expect(page.id).to eq("person_3_retirement_value_check")
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
end end
context "with person 4" do it "has correct depends_on" do
let(:person_index) { 4 } expect(page.depends_on).to eq([{ "person_3_retired_under_soft_min_age?" => true }])
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
end end
context "with person 5" do it "has correct title_text" do
let(:person_index) { 5 } expect(page.title_text).to eq({
let(:page_id) { "person_5_retirement_value_check_joint_purchase" } "translation" => "soft_validations.retirement.min.title",
"arguments" => [
it "has correct questions" do {
expect(page.questions.map(&:id)).to eq(%w[retirement_value_check]) "key" => "retirement_age_for_person_3",
end "label" => false,
"i18n_template" => "age",
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
end end
context "with person 6" do it "has correct informative_text" do
let(:person_index) { 6 } expect(page.informative_text).to eq({
let(:page_id) { "person_6_retirement_value_check_joint_purchase" } "translation" => "soft_validations.retirement.min.hint_text",
"arguments" => [
it "has correct questions" do {
expect(page.questions.map(&:id)).to eq(%w[retirement_value_check]) "key" => "plural_gender_for_person_3",
end "label" => false,
"i18n_template" => "gender",
it "has the correct id" do },
expect(page.id).to eq("person_6_retirement_value_check_joint_purchase") {
end "key" => "retirement_age_for_person_3",
"label" => false,
it "has correct depends_on" do "i18n_template" => "age",
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
end end
end end
context "without joint purchase" do context "with person 4" do
context "with person 1" do let(:person_index) { 4 }
let(:person_index) { 1 } let(:page_id) { "person_4_retirement_value_check" }
let(:page_id) { "person_1_retirement_value_check" }
it "has correct questions" do
it "has correct questions" do expect(page.questions.map(&:id)).to eq(%w[retirement_value_check])
expect(page.questions.map(&:id)).to eq(%w[retirement_value_check]) end
end
it "has the correct id" do
it "has the correct id" do expect(page.id).to eq("person_4_retirement_value_check")
expect(page.id).to eq("person_1_retirement_value_check") end
end
it "has correct depends_on" do
it "has correct depends_on" do expect(page.depends_on).to eq([{ "person_4_retired_under_soft_min_age?" => true }])
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
end end
context "with person 2" do it "has correct title_text" do
let(:person_index) { 2 } expect(page.title_text).to eq({
let(:page_id) { "person_2_retirement_value_check" } "translation" => "soft_validations.retirement.min.title",
"arguments" => [
it "has correct questions" do {
expect(page.questions.map(&:id)).to eq(%w[retirement_value_check]) "key" => "retirement_age_for_person_4",
end "label" => false,
"i18n_template" => "age",
it "has the correct id" do },
expect(page.id).to eq("person_2_retirement_value_check") ],
end })
end
it "has correct depends_on" do
expect(page.depends_on).to eq([{ "person_2_retired_under_soft_min_age?" => true, "jointpur" => 2 }]) it "has correct informative_text" do
end expect(page.informative_text).to eq({
"translation" => "soft_validations.retirement.min.hint_text",
it "has correct title_text" do "arguments" => [
expect(page.title_text).to eq({ {
"translation" => "soft_validations.retirement.min.title", "key" => "plural_gender_for_person_4",
"arguments" => [ "label" => false,
{ "i18n_template" => "gender",
"key" => "retirement_age_for_person_2", },
"label" => false, {
"i18n_template" => "age", "key" => "retirement_age_for_person_4",
}, "label" => false,
], "i18n_template" => "age",
}) },
end ],
})
it "has correct informative_text" do end
expect(page.informative_text).to eq({ end
"translation" => "soft_validations.retirement.min.hint_text",
"arguments" => [ context "with person 5" do
{ let(:person_index) { 5 }
"key" => "plural_gender_for_person_2", let(:page_id) { "person_5_retirement_value_check" }
"label" => false,
"i18n_template" => "gender", it "has correct questions" do
}, expect(page.questions.map(&:id)).to eq(%w[retirement_value_check])
{
"key" => "retirement_age_for_person_2",
"label" => false,
"i18n_template" => "age",
},
],
})
end
end end
context "with person 3" do it "has the correct id" do
let(:person_index) { 2 } expect(page.id).to eq("person_5_retirement_value_check")
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
end end
context "with person 4" do it "has correct depends_on" do
let(:person_index) { 3 } expect(page.depends_on).to eq([{ "person_5_retired_under_soft_min_age?" => true }])
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
end end
context "with person 5" do it "has correct title_text" do
let(:person_index) { 4 } expect(page.title_text).to eq({
let(:page_id) { "person_5_retirement_value_check" } "translation" => "soft_validations.retirement.min.title",
"arguments" => [
it "has correct questions" do {
expect(page.questions.map(&:id)).to eq(%w[retirement_value_check]) "key" => "retirement_age_for_person_5",
end "label" => false,
"i18n_template" => "age",
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
end end
context "with person 6" do it "has correct informative_text" do
let(:person_index) { 5 } expect(page.informative_text).to eq({
let(:page_id) { "person_6_retirement_value_check" } "translation" => "soft_validations.retirement.min.hint_text",
"arguments" => [
it "has correct questions" do {
expect(page.questions.map(&:id)).to eq(%w[retirement_value_check]) "key" => "plural_gender_for_person_5",
end "label" => false,
"i18n_template" => "gender",
it "has the correct id" do },
expect(page.id).to eq("person_6_retirement_value_check") {
end "key" => "retirement_age_for_person_5",
"label" => false,
it "has correct depends_on" do "i18n_template" => "age",
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
end end
end end
it "is interruption screen page" do context "with person 6" do
expect(page.interruption_screen?).to eq(true) 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
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(:page) { instance_double(Form::Page) }
let(:person_index) { 2 } let(:person_index) { 2 }
before do
allow(page).to receive(:id).and_return("person_1_age")
end
it "has correct page" do it "has correct page" do
expect(question.page).to eq(page) expect(question.page).to eq(page)
end end
@ -35,375 +31,171 @@ RSpec.describe Form::Sales::Questions::PersonAgeKnown, type: :model do
expect(question.hint_text).to be_nil expect(question.hint_text).to be_nil
end end
context "with a non joint purchase" do context "with person 2" do
context "and person 1" do let(:question_id) { "age2_known" }
let(:question_id) { "age2_known" } let(:person_index) { 2 }
let(:person_index) { 2 }
it "has the correct id" do
before do expect(question.id).to eq("age2_known")
allow(page).to receive(:id).and_return("person_1_age") end
end
it "has the correct header" do
it "has the correct id" do expect(question.header).to eq("Do you know person 2’s age?")
expect(question.id).to eq("age2_known") end
end
it "has the correct check_answer_label" do
it "has the correct header" do expect(question.check_answer_label).to eq("Person 2’s age known?")
expect(question.header).to eq("Do you know person 1’s age?") end
end
it "has correct conditional for" do
it "has the correct check_answer_label" do expect(question.conditional_for).to eq({
expect(question.check_answer_label).to eq("Person 1’s age known?") "age2" => [0],
end })
end
it "has correct conditional for" do
expect(question.conditional_for).to eq({ it "has the correct hidden_in_check_answers" do
"age2" => [0], expect(question.hidden_in_check_answers).to eq(
}) {
end "depends_on" => [
{
it "has the correct hidden_in_check_answers" do "age2_known" => 0,
expect(question.hidden_in_check_answers).to eq( },
{ {
"depends_on" => [ "age2_known" => 1,
{ },
"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 end
it "has the correct check_answers_card_number" do context "with person 3" do
expect(question.check_answers_card_number).to eq(2) let(:question_id) { "age3_known" }
end 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 end
context "and person 2" do it "has correct conditional for" do
let(:question_id) { "age3_known" } expect(question.conditional_for).to eq({
let(:person_index) { 3 } "age4" => [0],
})
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
end end
context "and person 3" do it "has the correct hidden_in_check_answers" do
let(:question_id) { "age4_known" } expect(question.hidden_in_check_answers).to eq(
let(:person_index) { 4 } {
"depends_on" => [
before do {
allow(page).to receive(:id).and_return("person_3_age") "age4_known" => 0,
end },
{
it "has the correct id" do "age4_known" => 1,
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
end end
context "and person 4" do it "has the correct check_answers_card_number" do
let(:question_id) { "age5_known" } expect(question.check_answers_card_number).to eq(4)
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
end end
end end
context "with a joint purchase" do context "with person 5" do
context "and person 1" do let(:question_id) { "age5_known" }
let(:question_id) { "age3_known" } let(:person_index) { 5 }
let(:person_index) { 3 }
it "has the correct id" do
before do expect(question.id).to eq("age5_known")
allow(page).to receive(:id).and_return("person_1_age_joint_purchase") end
end
it "has the correct header" do
it "has the correct id" do expect(question.header).to eq("Do you know person 5’s age?")
expect(question.id).to eq("age3_known") end
end
it "has the correct check_answer_label" do
it "has the correct header" do expect(question.check_answer_label).to eq("Person 5’s age known?")
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
end end
context "and person 2" do it "has correct conditional for" do
let(:question_id) { "age4_known" } expect(question.conditional_for).to eq({
let(:person_index) { 4 } "age5" => [0],
})
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
end end
context "and person 3" do it "has the correct hidden_in_check_answers" do
let(:question_id) { "age5_known" } expect(question.hidden_in_check_answers).to eq(
let(:person_index) { 5 } {
"depends_on" => [
before do {
allow(page).to receive(:id).and_return("person_3_age_joint_purchase") "age5_known" => 0,
end },
{
it "has the correct id" do "age5_known" => 1,
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
end end
context "and person 4" do it "has the correct check_answers_card_number" do
let(:question_id) { "age6_known" } expect(question.check_answers_card_number).to eq(5)
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
end end
end 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(:page) { instance_double(Form::Page) }
let(:person_index) { 2 } let(:person_index) { 2 }
before do
allow(page).to receive(:id).and_return("person_1_age")
end
it "has correct page" do it "has correct page" do
expect(question.page).to eq(page) expect(question.page).to eq(page)
end end
@ -40,263 +36,103 @@ RSpec.describe Form::Sales::Questions::PersonAge, type: :model do
expect(question.max).to eq(110) expect(question.max).to eq(110)
end end
context "with not a joint purchase" do it "has the correct width" do
context "and person 1" do expect(question.width).to eq(3)
let(:person_index) { 2 } end
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 inferred check answers value" do context "with person 2" do
expect(question.inferred_check_answers_value).to eq([{ let(:person_index) { 2 }
"condition" => { "age2_known" => 1 }, let(:question_id) { "age2" }
"value" => "Not known",
}])
end
it "has the correct check_answers_card_number" do it "has the correct id" do
expect(question.check_answers_card_number).to eq(2) expect(question.id).to eq("age2")
end
end end
context "and person 2" do it "has the correct check_answer_label" do
let(:person_index) { 3 } expect(question.check_answer_label).to eq("Person 2’s age")
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
end end
context "and person 3" do it "has the correct inferred check answers value" do
let(:person_index) { 4 } expect(question.inferred_check_answers_value).to eq([{
let(:question_id) { "age4" } "condition" => { "age2_known" => 1 },
"value" => "Not known",
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
end end
context "and person 4" do it "has the correct check_answers_card_number" do
let(:person_index) { 5 } expect(question.check_answers_card_number).to eq(2)
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
end end
end end
context "with a joint purchase" do context "with person 3" do
context "and person 1" do let(:person_index) { 3 }
let(:person_index) { 3 } let(:question_id) { "age3" }
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
it "has the correct check_answers_card_number" do it "has the correct id" do
expect(question.check_answers_card_number).to eq(3) expect(question.id).to eq("age3")
end
end end
context "and person 2" do it "has the correct check_answer_label" do
let(:person_index) { 4 } expect(question.check_answer_label).to eq("Person 3’s age")
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
end end
context "and person 3" do it "has the correct inferred check answers value" do
let(:person_index) { 5 } expect(question.inferred_check_answers_value).to eq([{
let(:question_id) { "age5" } "condition" => { "age3_known" => 1 },
"value" => "Not known",
before do }])
allow(page).to receive(:id).and_return("person_3_age_joint_purchase") end
end
it "has the correct id" do
expect(question.id).to eq("age5")
end
it "has the correct check_answer_label" do it "has the correct check_answers_card_number" do
expect(question.check_answer_label).to eq("Person 3’s age") expect(question.check_answers_card_number).to eq(3)
end end
end
it "has the correct width" do context "with person 4" do
expect(question.width).to eq(3) let(:person_index) { 4 }
end let(:question_id) { "age4" }
it "has the correct inferred check answers value" do it "has the correct id" do
expect(question.inferred_check_answers_value).to eq([{ expect(question.id).to eq("age4")
"condition" => { "age5_known" => 1 }, end
"value" => "Not known",
}])
end
it "has the correct check_answers_card_number" do it "has the correct check_answer_label" do
expect(question.check_answers_card_number).to eq(5) expect(question.check_answer_label).to eq("Person 4’s age")
end
end end
context "and person 4" do it "has the correct inferred check answers value" do
let(:person_index) { 6 } expect(question.inferred_check_answers_value).to eq([{
let(:question_id) { "age6" } "condition" => { "age4_known" => 1 },
"value" => "Not known",
}])
end
before do it "has the correct check_answers_card_number" do
allow(page).to receive(:id).and_return("person_4_age_joint_purchase") expect(question.check_answers_card_number).to eq(4)
end end
end
it "has the correct id" do context "with person 5" do
expect(question.id).to eq("age6") let(:person_index) { 5 }
end let(:question_id) { "age5" }
it "has the correct check_answer_label" do it "has the correct id" do
expect(question.check_answer_label).to eq("Person 4’s age") expect(question.id).to eq("age5")
end end
it "has the correct width" do it "has the correct check_answer_label" do
expect(question.width).to eq(3) expect(question.check_answer_label).to eq("Person 5’s age")
end end
it "has the correct inferred check answers value" do it "has the correct inferred check answers value" do
expect(question.inferred_check_answers_value).to eq([{ expect(question.inferred_check_answers_value).to eq([{
"condition" => { "age6_known" => 1 }, "condition" => { "age5_known" => 1 },
"value" => "Not known", "value" => "Not known",
}]) }])
end end
it "has the correct check_answers_card_number" do it "has the correct check_answers_card_number" do
expect(question.check_answers_card_number).to eq(6) expect(question.check_answers_card_number).to eq(5)
end
end end
end 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(:page) { instance_double(Form::Page) }
let(:person_index) { 2 } let(:person_index) { 2 }
before do
allow(page).to receive(:id).and_return("person_1_gender_identity")
end
it "has correct page" do it "has correct page" do
expect(question.page).to eq(page) expect(question.page).to eq(page)
end end
@ -24,10 +20,6 @@ RSpec.describe Form::Sales::Questions::PersonGenderIdentity, type: :model do
expect(question.derived?).to be false expect(question.derived?).to be false
end 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 it "has the correct answer_options" do
expect(question.answer_options).to eq({ expect(question.answer_options).to eq({
"F" => { "value" => "Female" }, "F" => { "value" => "Female" },
@ -37,259 +29,111 @@ RSpec.describe Form::Sales::Questions::PersonGenderIdentity, type: :model do
}) })
end end
context "when person 1" do context "when person 2" do
context "and not joint purchase" do let(:question_id) { "sex2" }
let(:question_id) { "sex2" } let(:person_index) { 2 }
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
it "has the correct inferred_check_answers_value" do it "has the correct id" do
expect(question.inferred_check_answers_value).to eq([ expect(question.id).to eq("sex2")
{ "condition" => { "sex2" => "R" }, "value" => "Prefers not to say" },
])
end
end end
context "and joint purchase" do it "has the correct header" do
let(:person_index) { 3 } expect(question.header).to eq("Which of these best describes Person 2’s gender identity?")
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
end 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 it "has the correct check_answer_label" do
expect(question.id).to eq("sex3") expect(question.check_answer_label).to eq("Person 2’s gender identity")
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
end end
context "and joint purchase" do it "has expected check answers card number" do
let(:question_id) { "sex4" } expect(question.check_answers_card_number).to eq(2)
let(:person_index) { 4 } end
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 the correct inferred_check_answers_value" do it "has the correct inferred_check_answers_value" do
expect(question.inferred_check_answers_value).to eq([ expect(question.inferred_check_answers_value).to eq([
{ "condition" => { "sex4" => "R" }, "value" => "Prefers not to say" }, { "condition" => { "sex2" => "R" }, "value" => "Prefers not to say" },
]) ])
end
end end
end end
context "when person 3" do context "when person 3" do
context "and not joint purchase" do let(:question_id) { "sex3" }
let(:question_id) { "sex4" } let(:person_index) { 3 }
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
it "has the correct check_answer_label" do it "has the correct id" do
expect(question.check_answer_label).to eq("Person 3’s gender identity") expect(question.id).to eq("sex3")
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
end end
context "and joint purchase" do it "has the correct header" do
let(:question_id) { "sex5" } expect(question.header).to eq("Which of these best describes Person 3’s gender identity?")
let(:person_index) { 5 } end
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 check_answer_label" do it "has the correct check_answer_label" do
expect(question.check_answer_label).to eq("Person 3’s gender identity") expect(question.check_answer_label).to eq("Person 3’s gender identity")
end end
it "has expected check answers card number" do it "has expected check answers card number" do
expect(question.check_answers_card_number).to eq(5) expect(question.check_answers_card_number).to eq(3)
end end
it "has the correct inferred_check_answers_value" do it "has the correct inferred_check_answers_value" do
expect(question.inferred_check_answers_value).to eq([ expect(question.inferred_check_answers_value).to eq([
{ "condition" => { "sex5" => "R" }, "value" => "Prefers not to say" }, { "condition" => { "sex3" => "R" }, "value" => "Prefers not to say" },
]) ])
end
end end
end end
context "when person 4" do context "when person 4" do
context "and not joint purchase" do let(:question_id) { "sex4" }
let(:question_id) { "sex5" } let(:person_index) { 4 }
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
it "has the correct header" do it "has the correct id" do
expect(question.header).to eq("Which of these best describes Person 4’s gender identity?") expect(question.id).to eq("sex4")
end end
it "has the correct check_answer_label" do it "has the correct header" do
expect(question.check_answer_label).to eq("Person 4’s gender identity") expect(question.header).to eq("Which of these best describes Person 4’s gender identity?")
end end
it "has expected check answers card number" do it "has the correct check_answer_label" do
expect(question.check_answers_card_number).to eq(5) expect(question.check_answer_label).to eq("Person 4’s gender identity")
end end
it "has the correct inferred_check_answers_value" do it "has expected check answers card number" do
expect(question.inferred_check_answers_value).to eq([ expect(question.check_answers_card_number).to eq(4)
{ "condition" => { "sex5" => "R" }, "value" => "Prefers not to say" },
])
end
end end
context "and joint purchase" do it "has the correct inferred_check_answers_value" do
let(:question_id) { "sex6" } expect(question.inferred_check_answers_value).to eq([
let(:person_index) { 6 } { "condition" => { "sex4" => "R" }, "value" => "Prefers not to say" },
])
end
end
before do context "when person 5" do
allow(page).to receive(:id).and_return("person_4_gender_identity_joint_purchase") let(:question_id) { "sex5" }
end let(:person_index) { 5 }
it "has the correct id" do it "has the correct id" do
expect(question.id).to eq("sex6") expect(question.id).to eq("sex5")
end end
it "has the correct header" do it "has the correct header" do
expect(question.header).to eq("Which of these best describes Person 4’s gender identity?") expect(question.header).to eq("Which of these best describes Person 5’s gender identity?")
end end
it "has the correct check_answer_label" do it "has the correct check_answer_label" do
expect(question.check_answer_label).to eq("Person 4’s gender identity") expect(question.check_answer_label).to eq("Person 5’s gender identity")
end end
it "has expected check answers card number" do it "has expected check answers card number" do
expect(question.check_answers_card_number).to eq(6) expect(question.check_answers_card_number).to eq(5)
end end
it "has the correct inferred_check_answers_value" do it "has the correct inferred_check_answers_value" do
expect(question.inferred_check_answers_value).to eq([ expect(question.inferred_check_answers_value).to eq([
{ "condition" => { "sex6" => "R" }, "value" => "Prefers not to say" }, { "condition" => { "sex5" => "R" }, "value" => "Prefers not to say" },
]) ])
end
end end
end 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(:page) { instance_double(Form::Page) }
let(:person_index) { 2 } let(:person_index) { 2 }
before do
allow(page).to receive(:id).and_return("person_1_known")
end
it "has correct page" do it "has correct page" do
expect(question.page).to eq(page) expect(question.page).to eq(page)
end end
@ -31,291 +27,119 @@ RSpec.describe Form::Sales::Questions::PersonKnown, type: :model do
}) })
end end
it "has correct conditional for" do
expect(question.conditional_for).to be_nil
end
it "has the correct hint" do it "has the correct hint" do
expect(question.hint_text).to be_nil expect(question.hint_text).to be_nil
end end
context "with a non joint purchase" do context "with person 2" do
context "and person 1" do let(:question_id) { "details_known_2" }
let(:question_id) { "details_known_1" } let(:person_index) { 2 }
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
it "has correct conditional for" do it "has the correct id" do
expect(question.conditional_for).to be_nil expect(question.id).to eq("details_known_2")
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
end end
context "and person 2" do it "has the correct header" do
let(:question_id) { "details_known_2" } expect(question.header).to eq("Do you know the details for person 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
end end
context "and person 3" do it "has the correct check_answer_label" do
let(:question_id) { "details_known_3" } expect(question.check_answer_label).to eq("Details known for person 2?")
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
end end
context "and person 4" do it "has the correct hidden_in_check_answers" do
let(:question_id) { "details_known_4" } expect(question.hidden_in_check_answers).to eq(
let(:person_index) { 5 } "depends_on" => [{ "details_known_2" => 1 }],
)
before do end
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 check_answers_card_number" do it "has the correct check_answers_card_number" do
expect(question.check_answers_card_number).to eq(5) expect(question.check_answers_card_number).to eq(2)
end
end end
end end
context "with a joint purchase" do context "with person 3" do
context "and person 1" do let(:question_id) { "details_known_3" }
let(:question_id) { "details_known_1" } let(:person_index) { 3 }
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
it "has the correct check_answers_card_number" do it "has the correct id" do
expect(question.check_answers_card_number).to eq(3) expect(question.id).to eq("details_known_3")
end
end end
context "and person 2" do it "has the correct header" do
let(:question_id) { "details_known_2" } expect(question.header).to eq("Do you know the details for person 3?")
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
end end
context "and person 3" do it "has the correct check_answer_label" do
let(:question_id) { "details_known_3" } expect(question.check_answer_label).to eq("Details known for person 3?")
let(:person_index) { 5 } end
before do
allow(page).to receive(:id).and_return("person_3_known_joint_purchase")
end
it "has the correct id" do it "has the correct hidden_in_check_answers" do
expect(question.id).to eq("details_known_3") expect(question.hidden_in_check_answers).to eq(
end "depends_on" => [{ "details_known_3" => 1 }],
)
end
it "has the correct header" do it "has the correct check_answers_card_number" do
expect(question.header).to eq("Do you know the details for person 3?") expect(question.check_answers_card_number).to eq(3)
end end
end
it "has the correct check_answer_label" do context "with person 4" do
expect(question.check_answer_label).to eq("Details known for person 3?") let(:question_id) { "details_known_4" }
end let(:person_index) { 4 }
it "has correct conditional for" do it "has the correct id" do
expect(question.conditional_for).to be_nil expect(question.id).to eq("details_known_4")
end end
it "has the correct hidden_in_check_answers" do it "has the correct header" do
expect(question.hidden_in_check_answers).to eq( expect(question.header).to eq("Do you know the details for person 4?")
"depends_on" => [{ "details_known_3" => 1 }], end
)
end
it "has the correct check_answers_card_number" do it "has the correct check_answer_label" do
expect(question.check_answers_card_number).to eq(5) expect(question.check_answer_label).to eq("Details known for person 4?")
end
end end
context "and person 4" do it "has the correct hidden_in_check_answers" do
let(:question_id) { "details_known_4" } expect(question.hidden_in_check_answers).to eq(
let(:person_index) { 6 } "depends_on" => [{ "details_known_4" => 1 }],
)
end
before do it "has the correct check_answers_card_number" do
allow(page).to receive(:id).and_return("person_4_known_joint_purchase") expect(question.check_answers_card_number).to eq(4)
end end
end
it "has the correct id" do context "with person 5" do
expect(question.id).to eq("details_known_4") let(:question_id) { "details_known_5" }
end let(:person_index) { 5 }
it "has the correct header" do it "has the correct id" do
expect(question.header).to eq("Do you know the details for person 4?") expect(question.id).to eq("details_known_5")
end end
it "has the correct check_answer_label" do it "has the correct header" do
expect(question.check_answer_label).to eq("Details known for person 4?") expect(question.header).to eq("Do you know the details for person 5?")
end end
it "has correct conditional for" do it "has the correct check_answer_label" do
expect(question.conditional_for).to be_nil expect(question.check_answer_label).to eq("Details known for person 5?")
end end
it "has the correct hidden_in_check_answers" do it "has the correct hidden_in_check_answers" do
expect(question.hidden_in_check_answers).to eq( expect(question.hidden_in_check_answers).to eq(
"depends_on" => [{ "details_known_4" => 1 }], "depends_on" => [{ "details_known_5" => 1 }],
) )
end end
it "has the correct check_answers_card_number" do it "has the correct check_answers_card_number" do
expect(question.check_answers_card_number).to eq(6) expect(question.check_answers_card_number).to eq(5)
end
end end
end 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(:page) { instance_double(Form::Page) }
let(:person_index) { 2 } 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 it "has correct page" do
expect(question.page).to eq(page) expect(question.page).to eq(page)
end end
@ -37,259 +33,111 @@ RSpec.describe Form::Sales::Questions::PersonRelationshipToBuyer1, type: :model
}) })
end end
context "when person 1" do context "when person 2" do
context "and not joint purchase" do let(:question_id) { "relat2" }
let(:question_id) { "relat2" } let(:person_index) { 2 }
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
it "has the correct inferred_check_answers_value" do it "has the correct id" do
expect(question.inferred_check_answers_value).to eq([ expect(question.id).to eq("relat2")
{ "condition" => { "relat2" => "R" }, "value" => "Prefers not to say" },
])
end
end end
context "and joint purchase" do it "has the correct header" do
let(:person_index) { 3 } expect(question.header).to eq("What is Person 2’s relationship to Buyer 1?")
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
end 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 it "has the correct check_answer_label" do
expect(question.header).to eq("What is Person 2’s relationship to Buyer 1?") expect(question.check_answer_label).to eq("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
end end
context "and joint purchase" do it "has expected check answers card number" do
let(:question_id) { "relat4" } expect(question.check_answers_card_number).to eq(2)
let(:person_index) { 4 } end
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 the correct inferred_check_answers_value" do it "has the correct inferred_check_answers_value" do
expect(question.inferred_check_answers_value).to eq([ expect(question.inferred_check_answers_value).to eq([
{ "condition" => { "relat4" => "R" }, "value" => "Prefers not to say" }, { "condition" => { "relat2" => "R" }, "value" => "Prefers not to say" },
]) ])
end
end end
end end
context "when person 3" do context "when person 3" do
context "and not joint purchase" do let(:question_id) { "relat3" }
let(:question_id) { "relat4" } let(:person_index) { 3 }
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
it "has expected check answers card number" do it "has the correct id" do
expect(question.check_answers_card_number).to eq(4) expect(question.id).to eq("relat3")
end
it "has the correct inferred_check_answers_value" do
expect(question.inferred_check_answers_value).to eq([
{ "condition" => { "relat4" => "R" }, "value" => "Prefers not to say" },
])
end
end end
context "and joint purchase" do it "has the correct header" do
let(:question_id) { "relat5" } expect(question.header).to eq("What is Person 3’s relationship to Buyer 1?")
let(:person_index) { 5 } end
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 check_answer_label" do it "has the correct check_answer_label" do
expect(question.check_answer_label).to eq("Person 3’s relationship to Buyer 1") expect(question.check_answer_label).to eq("Person 3’s relationship to Buyer 1")
end end
it "has expected check answers card number" do it "has expected check answers card number" do
expect(question.check_answers_card_number).to eq(5) expect(question.check_answers_card_number).to eq(3)
end end
it "has the correct inferred_check_answers_value" do it "has the correct inferred_check_answers_value" do
expect(question.inferred_check_answers_value).to eq([ expect(question.inferred_check_answers_value).to eq([
{ "condition" => { "relat5" => "R" }, "value" => "Prefers not to say" }, { "condition" => { "relat3" => "R" }, "value" => "Prefers not to say" },
]) ])
end
end end
end end
context "when person 4" do context "when person 4" do
context "and not joint purchase" do let(:question_id) { "relat4" }
let(:question_id) { "relat5" } let(:person_index) { 4 }
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
it "has the correct header" do it "has the correct id" do
expect(question.header).to eq("What is Person 4’s relationship to Buyer 1?") expect(question.id).to eq("relat4")
end end
it "has the correct check_answer_label" do it "has the correct header" do
expect(question.check_answer_label).to eq("Person 4’s relationship to Buyer 1") expect(question.header).to eq("What is Person 4’s relationship to Buyer 1?")
end end
it "has expected check answers card number" do it "has the correct check_answer_label" do
expect(question.check_answers_card_number).to eq(5) expect(question.check_answer_label).to eq("Person 4’s relationship to Buyer 1")
end end
it "has the correct inferred_check_answers_value" do it "has expected check answers card number" do
expect(question.inferred_check_answers_value).to eq([ expect(question.check_answers_card_number).to eq(4)
{ "condition" => { "relat5" => "R" }, "value" => "Prefers not to say" },
])
end
end end
context "and joint purchase" do it "has the correct inferred_check_answers_value" do
let(:question_id) { "relat6" } expect(question.inferred_check_answers_value).to eq([
let(:person_index) { 6 } { "condition" => { "relat4" => "R" }, "value" => "Prefers not to say" },
])
end
end
before do context "when person 5" do
allow(page).to receive(:id).and_return("person_4_relationship_to_buyer_1_joint_purchase") let(:question_id) { "relat5" }
end let(:person_index) { 5 }
it "has the correct id" do it "has the correct id" do
expect(question.id).to eq("relat6") expect(question.id).to eq("relat5")
end end
it "has the correct header" do it "has the correct header" do
expect(question.header).to eq("What is Person 4’s relationship to Buyer 1?") expect(question.header).to eq("What is Person 5’s relationship to Buyer 1?")
end end
it "has the correct check_answer_label" do it "has the correct check_answer_label" do
expect(question.check_answer_label).to eq("Person 4’s relationship to Buyer 1") expect(question.check_answer_label).to eq("Person 5’s relationship to Buyer 1")
end end
it "has expected check answers card number" do it "has expected check answers card number" do
expect(question.check_answers_card_number).to eq(6) expect(question.check_answers_card_number).to eq(5)
end end
it "has the correct inferred_check_answers_value" do it "has the correct inferred_check_answers_value" do
expect(question.inferred_check_answers_value).to eq([ expect(question.inferred_check_answers_value).to eq([
{ "condition" => { "relat6" => "R" }, "value" => "Prefers not to say" }, { "condition" => { "relat5" => "R" }, "value" => "Prefers not to say" },
]) ])
end
end end
end 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(:page) { instance_double(Form::Page) }
let(:person_index) { 2 } let(:person_index) { 2 }
before do
allow(page).to receive(:id).and_return("person_1_working_situation")
end
it "has correct page" do it "has correct page" do
expect(question.page).to eq(page) expect(question.page).to eq(page)
end end
@ -24,10 +20,6 @@ RSpec.describe Form::Sales::Questions::PersonWorkingSituation, type: :model do
expect(question.derived?).to be false expect(question.derived?).to be false
end 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 it "has the correct answer_options" do
expect(question.answer_options).to eq({ expect(question.answer_options).to eq({
"2" => { "value" => "Part-time - Less than 30 hours" }, "2" => { "value" => "Part-time - Less than 30 hours" },
@ -44,259 +36,111 @@ RSpec.describe Form::Sales::Questions::PersonWorkingSituation, type: :model do
}) })
end end
context "when person 1" do context "when person 2" do
context "and not joint purchase" do let(:question_id) { "ecstat2" }
let(:question_id) { "ecstat2" } let(:person_index) { 2 }
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
it "has the correct inferred_check_answers_value" do it "has the correct id" do
expect(question.inferred_check_answers_value).to eq([ expect(question.id).to eq("ecstat2")
{ "condition" => { "ecstat2" => 10 }, "value" => "Prefers not to say" },
])
end
end end
context "and joint purchase" do it "has the correct header" do
let(:person_index) { 3 } expect(question.header).to eq("Which of these best describes Person 2’s working situation?")
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
end 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 it "has the correct check_answer_label" do
expect(question.id).to eq("ecstat3") expect(question.check_answer_label).to eq("Person 2’s working situation")
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
end end
context "and joint purchase" do it "has expected check answers card number" do
let(:question_id) { "ecstat4" } expect(question.check_answers_card_number).to eq(2)
let(:person_index) { 4 } end
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 the correct inferred_check_answers_value" do it "has the correct inferred_check_answers_value" do
expect(question.inferred_check_answers_value).to eq([ expect(question.inferred_check_answers_value).to eq([
{ "condition" => { "ecstat4" => 10 }, "value" => "Prefers not to say" }, { "condition" => { "ecstat2" => 10 }, "value" => "Prefers not to say" },
]) ])
end
end end
end end
context "when person 3" do context "when person 3" do
context "and not joint purchase" do let(:question_id) { "ecstat3" }
let(:question_id) { "ecstat4" } let(:person_index) { 3 }
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
it "has the correct check_answer_label" do it "has the correct id" do
expect(question.check_answer_label).to eq("Person 3’s working situation") expect(question.id).to eq("ecstat3")
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
end end
context "and joint purchase" do it "has the correct header" do
let(:question_id) { "ecstat5" } expect(question.header).to eq("Which of these best describes Person 3’s working situation?")
let(:person_index) { 5 } end
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 check_answer_label" do it "has the correct check_answer_label" do
expect(question.check_answer_label).to eq("Person 3’s working situation") expect(question.check_answer_label).to eq("Person 3’s working situation")
end end
it "has expected check answers card number" do it "has expected check answers card number" do
expect(question.check_answers_card_number).to eq(5) expect(question.check_answers_card_number).to eq(3)
end end
it "has the correct inferred_check_answers_value" do it "has the correct inferred_check_answers_value" do
expect(question.inferred_check_answers_value).to eq([ expect(question.inferred_check_answers_value).to eq([
{ "condition" => { "ecstat5" => 10 }, "value" => "Prefers not to say" }, { "condition" => { "ecstat3" => 10 }, "value" => "Prefers not to say" },
]) ])
end
end end
end end
context "when person 4" do context "when person 4" do
context "and not joint purchase" do let(:question_id) { "ecstat4" }
let(:question_id) { "ecstat5" } let(:person_index) { 4 }
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
it "has the correct header" do it "has the correct id" do
expect(question.header).to eq("Which of these best describes Person 4’s working situation?") expect(question.id).to eq("ecstat4")
end end
it "has the correct check_answer_label" do it "has the correct header" do
expect(question.check_answer_label).to eq("Person 4’s working situation") expect(question.header).to eq("Which of these best describes Person 4’s working situation?")
end end
it "has expected check answers card number" do it "has the correct check_answer_label" do
expect(question.check_answers_card_number).to eq(5) expect(question.check_answer_label).to eq("Person 4’s working situation")
end end
it "has the correct inferred_check_answers_value" do it "has expected check answers card number" do
expect(question.inferred_check_answers_value).to eq([ expect(question.check_answers_card_number).to eq(4)
{ "condition" => { "ecstat5" => 10 }, "value" => "Prefers not to say" },
])
end
end end
context "and joint purchase" do it "has the correct inferred_check_answers_value" do
let(:question_id) { "ecstat6" } expect(question.inferred_check_answers_value).to eq([
let(:person_index) { 6 } { "condition" => { "ecstat4" => 10 }, "value" => "Prefers not to say" },
])
end
end
before do context "when person 5" do
allow(page).to receive(:id).and_return("person_4_working_situation_joint_purchase") let(:question_id) { "ecstat5" }
end let(:person_index) { 5 }
it "has the correct id" do it "has the correct id" do
expect(question.id).to eq("ecstat6") expect(question.id).to eq("ecstat5")
end end
it "has the correct header" do it "has the correct header" do
expect(question.header).to eq("Which of these best describes Person 4’s working situation?") expect(question.header).to eq("Which of these best describes Person 5’s working situation?")
end end
it "has the correct check_answer_label" do it "has the correct check_answer_label" do
expect(question.check_answer_label).to eq("Person 4’s working situation") expect(question.check_answer_label).to eq("Person 5’s working situation")
end end
it "has expected check answers card number" do it "has expected check answers card number" do
expect(question.check_answers_card_number).to eq(6) expect(question.check_answers_card_number).to eq(5)
end end
it "has the correct inferred_check_answers_value" do it "has the correct inferred_check_answers_value" do
expect(question.inferred_check_answers_value).to eq([ expect(question.inferred_check_answers_value).to eq([
{ "condition" => { "ecstat6" => 10 }, "value" => "Prefers not to say" }, { "condition" => { "ecstat5" => 10 }, "value" => "Prefers not to say" },
]) ])
end
end end
end 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 privacy_notice
buyer_1_age buyer_1_age
age_1_retirement_value_check age_1_retirement_value_check
age_1_retirement_value_check_joint_purchase
age_1_old_persons_shared_ownership_value_check age_1_old_persons_shared_ownership_value_check
buyer_1_gender_identity buyer_1_gender_identity
gender_1_retirement_value_check gender_1_retirement_value_check
gender_1_retirement_value_check_joint_purchase
buyer_1_ethnic_group buyer_1_ethnic_group
buyer_1_ethnic_background_black buyer_1_ethnic_background_black
buyer_1_ethnic_background_asian buyer_1_ethnic_background_asian
@ -32,83 +30,50 @@ RSpec.describe Form::Sales::Subsections::HouseholdCharacteristics, type: :model
buyer_1_nationality buyer_1_nationality
buyer_1_working_situation buyer_1_working_situation
working_situation_1_retirement_value_check working_situation_1_retirement_value_check
working_situation_1_retirement_value_check_joint_purchase
working_situation_buyer_1_income_value_check working_situation_buyer_1_income_value_check
buyer_1_live_in_property buyer_1_live_in_property
buyer_2_relationship_to_buyer_1 buyer_2_relationship_to_buyer_1
buyer_2_age buyer_2_age
age_2_retirement_value_check_joint_purchase
age_2_old_persons_shared_ownership_value_check age_2_old_persons_shared_ownership_value_check
age_2_buyer_retirement_value_check
buyer_2_gender_identity buyer_2_gender_identity
gender_2_retirement_value_check_joint_purchase gender_2_buyer_retirement_value_check
buyer_2_working_situation buyer_2_working_situation
working_situation_2_retirement_value_check_joint_purchase working_situation_2_buyer_retirement_value_check
buyer_2_live_in_property buyer_2_live_in_property
number_of_others_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
person_2_known_joint_purchase
person_2_relationship_to_buyer_1 person_2_relationship_to_buyer_1
person_2_relationship_to_buyer_1_joint_purchase
person_2_age person_2_age
age_3_retirement_value_check age_2_retirement_value_check
person_2_age_joint_purchase
age_4_retirement_value_check_joint_purchase
person_2_gender_identity person_2_gender_identity
gender_3_retirement_value_check gender_2_retirement_value_check
person_2_gender_identity_joint_purchase
gender_4_retirement_value_check_joint_purchase
person_2_working_situation person_2_working_situation
working_situation_3_retirement_value_check working_situation_2_retirement_value_check
person_2_working_situation_joint_purchase
working_situation_4_retirement_value_check_joint_purchase
person_3_known person_3_known
person_3_known_joint_purchase
person_3_relationship_to_buyer_1 person_3_relationship_to_buyer_1
person_3_relationship_to_buyer_1_joint_purchase
person_3_age person_3_age
age_4_retirement_value_check age_3_retirement_value_check
person_3_age_joint_purchase
age_5_retirement_value_check_joint_purchase
person_3_gender_identity person_3_gender_identity
gender_4_retirement_value_check gender_3_retirement_value_check
person_3_gender_identity_joint_purchase
gender_5_retirement_value_check_joint_purchase
person_3_working_situation person_3_working_situation
working_situation_4_retirement_value_check working_situation_3_retirement_value_check
person_3_working_situation_joint_purchase
working_situation_5_retirement_value_check_joint_purchase
person_4_known person_4_known
person_4_known_joint_purchase
person_4_relationship_to_buyer_1 person_4_relationship_to_buyer_1
person_4_relationship_to_buyer_1_joint_purchase
person_4_age person_4_age
age_5_retirement_value_check age_4_retirement_value_check
person_4_age_joint_purchase
age_6_retirement_value_check_joint_purchase
person_4_gender_identity person_4_gender_identity
gender_5_retirement_value_check gender_4_retirement_value_check
person_4_gender_identity_joint_purchase
gender_6_retirement_value_check_joint_purchase
person_4_working_situation 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 working_situation_5_retirement_value_check
person_4_working_situation_joint_purchase
working_situation_6_retirement_value_check_joint_purchase
], ],
) )
end 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 it "is able to load a current sales form" do
form = form_handler.get_form("current_sales") form = form_handler.get_form("current_sales")
expect(form).to be_a(Form) 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") expect(form.name).to eq("2022_2023_sales")
end end
it "is able to load a previous sales form" do it "is able to load a previous sales form" do
form = form_handler.get_form("previous_sales") form = form_handler.get_form("previous_sales")
expect(form).to be_a(Form) 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") expect(form.name).to eq("2021_2022_sales")
end end
end end

4
spec/models/sales_log_spec.rb

@ -252,10 +252,10 @@ RSpec.describe SalesLog, type: :model do
:completed, :completed,
jointpur: 1, jointpur: 1,
hholdcount: 4, hholdcount: 4,
details_known_1: 1,
details_known_2: 1,
details_known_3: 1, details_known_3: 1,
details_known_4: 1, details_known_4: 1,
details_known_5: 1,
details_known_6: 1,
relat2: "C", relat2: "C",
relat3: "C", relat3: "C",
relat4: "X", 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(:validator_class) { Class.new { include Validations::SharedValidations } }
let(:record) { FactoryBot.create(:lettings_log) } 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") } let(:fake_2021_2022_form) { Form.new("spec/fixtures/forms/2021_2022.json") }
describe "numeric min max validations" do describe "numeric min max validations" do
@ -67,6 +67,24 @@ RSpec.describe Validations::SharedValidations do
shared_validator.validate_numeric_min_max(record) shared_validator.validate_numeric_min_max(record)
expect(record.errors["age6"]).to be_empty expect(record.errors["age6"]).to be_empty
end 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 end
it "adds the correct validation text when a question has a min but not a max" do 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 context "when validating percent" do
it "validates that suffixes are added in the error message" do it "validates that suffixes are added in the error message" do
sales_record.ownershipsch = 1
sales_record.staircase = 1
sales_record.stairbought = 150 sales_record.stairbought = 150
shared_validator.validate_numeric_min_max(sales_record) shared_validator.validate_numeric_min_max(sales_record)
expect(sales_record.errors["stairbought"]) expect(sales_record.errors["stairbought"])

Loading…
Cancel
Save