Browse Source

Merge branch 'main' into CLDC-1522-buyer-2-relationship

pull/936/head
natdeanlewissoftwire 3 years ago
parent
commit
49d8cc400a
  1. 8
      app/frontend/controllers/conditional_question_controller.js
  2. 2
      app/helpers/question_attribute_helper.rb
  3. 5
      app/models/derived_variables/sales_log_variables.rb
  4. 6
      app/models/form/question.rb
  5. 18
      app/models/form/sales/pages/buyer1_ethnic_background_arab.rb
  6. 18
      app/models/form/sales/pages/buyer1_ethnic_background_asian.rb
  7. 18
      app/models/form/sales/pages/buyer1_ethnic_background_black.rb
  8. 18
      app/models/form/sales/pages/buyer1_ethnic_background_mixed.rb
  9. 18
      app/models/form/sales/pages/buyer1_ethnic_background_white.rb
  10. 15
      app/models/form/sales/pages/buyer1_ethnic_group.rb
  11. 15
      app/models/form/sales/pages/buyer1_working_situation.rb
  12. 15
      app/models/form/sales/pages/buyer2_live_in_property.rb
  13. 15
      app/models/form/sales/pages/buyer2_working_situation.rb
  14. 15
      app/models/form/sales/pages/buyer_company.rb
  15. 15
      app/models/form/sales/pages/buyer_interview.rb
  16. 18
      app/models/form/sales/pages/gender_identity2.rb
  17. 16
      app/models/form/sales/pages/nationality1.rb
  18. 18
      app/models/form/sales/pages/privacy_notice.rb
  19. 17
      app/models/form/sales/questions/buyer1_ethnic_background_arab.rb
  20. 20
      app/models/form/sales/questions/buyer1_ethnic_background_asian.rb
  21. 18
      app/models/form/sales/questions/buyer1_ethnic_background_black.rb
  22. 19
      app/models/form/sales/questions/buyer1_ethnic_background_mixed.rb
  23. 19
      app/models/form/sales/questions/buyer1_ethnic_background_white.rb
  24. 28
      app/models/form/sales/questions/buyer1_ethnic_group.rb
  25. 26
      app/models/form/sales/questions/buyer1_working_situation.rb
  26. 17
      app/models/form/sales/questions/buyer2_live_in_property.rb
  27. 26
      app/models/form/sales/questions/buyer2_working_situation.rb
  28. 17
      app/models/form/sales/questions/buyer_company.rb
  29. 17
      app/models/form/sales/questions/buyer_interview.rb
  30. 18
      app/models/form/sales/questions/gender_identity2.rb
  31. 30
      app/models/form/sales/questions/nationality1.rb
  32. 10
      app/models/form/sales/questions/other_nationality1.rb
  33. 18
      app/models/form/sales/questions/privacy_notice.rb
  34. 13
      app/models/form/sales/subsections/household_characteristics.rb
  35. 1
      app/models/form/sales/subsections/setup.rb
  36. 4
      app/models/lettings_log.rb
  37. 4
      app/models/log.rb
  38. 5
      app/models/sales_log.rb
  39. 1
      app/views/form/guidance/_privacy_notice_buyer.erb
  40. 2
      app/views/form/guidance/_privacy_notice_tenant.erb
  41. 4
      app/views/logs/index.html.erb
  42. 5
      app/views/organisations/logs.html.erb
  43. 579
      config/forms/2021_2022.json
  44. 583
      config/forms/2022_2023.json
  45. 16
      config/forms/schema/2021_2022.json
  46. 21
      config/forms/schema/generic.json
  47. 8
      db/migrate/20220927082602_add_national_column.rb
  48. 6
      db/migrate/20220927100350_add_background_to_sales_log.rb
  49. 5
      db/migrate/20220930134358_add_buyer2_sex_to_sales_log.rb
  50. 7
      db/migrate/20221003092048_add_noint_to_sales_log.rb
  51. 7
      db/migrate/20221003134554_add_buy2livein_to_sales_log.rb
  52. 7
      db/migrate/20221003150610_add_ecstat2_to_sales_log.rb
  53. 7
      db/migrate/20221004095132_add_privacy_notice_to_sales_log.rb
  54. 7
      db/migrate/20221004184301_add_ecstat1_to_sales_log.rb
  55. 18
      db/schema.rb
  56. 9
      spec/factories/sales_log.rb
  57. 18
      spec/features/form/conditional_questions_spec.rb
  58. 37
      spec/features/organisation_spec.rb
  59. 175
      spec/fixtures/forms/2021_2022.json
  60. 4
      spec/fixtures/forms/2022_2023.json
  61. 6
      spec/fixtures/forms/test_validator.json
  62. 4
      spec/helpers/question_attribute_helper_spec.rb
  63. 23
      spec/models/form/question_spec.rb
  64. 33
      spec/models/form/sales/pages/buyer1_ethnic_background_arab_spec.rb
  65. 33
      spec/models/form/sales/pages/buyer1_ethnic_background_asian_spec.rb
  66. 33
      spec/models/form/sales/pages/buyer1_ethnic_background_black_spec.rb
  67. 33
      spec/models/form/sales/pages/buyer1_ethnic_background_mixed_spec.rb
  68. 29
      spec/models/form/sales/pages/buyer1_ethnic_background_white_spec.rb
  69. 33
      spec/models/form/sales/pages/buyer1_ethnic_group_spec.rb
  70. 25
      spec/models/form/sales/pages/buyer1_working_situation_spec.rb
  71. 29
      spec/models/form/sales/pages/buyer2_live_in_property_spec.rb
  72. 29
      spec/models/form/sales/pages/buyer2_working_situation_spec.rb
  73. 29
      spec/models/form/sales/pages/buyer_company_spec.rb
  74. 29
      spec/models/form/sales/pages/buyer_interview_spec.rb
  75. 35
      spec/models/form/sales/pages/gender_identity2_spec.rb
  76. 33
      spec/models/form/sales/pages/nationality1_spec.rb
  77. 33
      spec/models/form/sales/pages/privacy_notice_spec.rb
  78. 44
      spec/models/form/sales/questions/buyer1_ethnic_background_arab_spec.rb
  79. 47
      spec/models/form/sales/questions/buyer1_ethnic_background_asian_spec.rb
  80. 45
      spec/models/form/sales/questions/buyer1_ethnic_background_black_spec.rb
  81. 46
      spec/models/form/sales/questions/buyer1_ethnic_background_mixed_spec.rb
  82. 46
      spec/models/form/sales/questions/buyer1_ethnic_background_white_spec.rb
  83. 49
      spec/models/form/sales/questions/buyer1_ethnic_group_spec.rb
  84. 49
      spec/models/form/sales/questions/buyer1_working_situation_spec.rb
  85. 44
      spec/models/form/sales/questions/buyer2_live_in_property_spec.rb
  86. 53
      spec/models/form/sales/questions/buyer2_working_situation_spec.rb
  87. 40
      spec/models/form/sales/questions/buyer_company_spec.rb
  88. 44
      spec/models/form/sales/questions/buyer_interview_spec.rb
  89. 42
      spec/models/form/sales/questions/gender_identity2_spec.rb
  90. 63
      spec/models/form/sales/questions/nationality1_spec.rb
  91. 37
      spec/models/form/sales/questions/other_nationality1_spec.rb
  92. 43
      spec/models/form/sales/questions/privacy_notice_spec.rb
  93. 21
      spec/models/form/sales/subsections/household_characteristics_spec.rb
  94. 2
      spec/models/form/sales/subsections/setup_spec.rb
  95. 4
      spec/models/form_handler_spec.rb
  96. 4
      spec/models/form_spec.rb
  97. 3
      spec/models/lettings_log_spec.rb
  98. 3
      spec/models/sales_log_spec.rb
  99. 17
      spec/shared/shared_examples_for_derived_fields.rb

8
app/frontend/controllers/conditional_question_controller.js

@ -8,14 +8,16 @@ export default class extends Controller {
displayConditional () { displayConditional () {
if (this.element.checked) { if (this.element.checked) {
const selectedValue = this.element.value const selectedValue = this.element.value
const conditionalFor = JSON.parse(this.element.dataset.info) const dataInfo = JSON.parse(this.element.dataset.info)
const conditionalFor = dataInfo.conditional_questions
const logType = dataInfo.log_type
Object.entries(conditionalFor).forEach(([targetQuestion, conditions]) => { Object.entries(conditionalFor).forEach(([targetQuestion, conditions]) => {
if (!conditions.map(String).includes(String(selectedValue))) { if (!conditions.map(String).includes(String(selectedValue))) {
const textNumericInput = document.getElementById(`lettings-log-${targetQuestion.replaceAll('_', '-')}-field`) const textNumericInput = document.getElementById(`${logType}-log-${targetQuestion.replaceAll('_', '-')}-field`)
if (textNumericInput == null) { if (textNumericInput == null) {
const dateInputs = [1, 2, 3].map((idx) => { const dateInputs = [1, 2, 3].map((idx) => {
return document.getElementById(`lettings_log_${targetQuestion}_${idx}i`) return document.getElementById(`${logType}_log_${targetQuestion}_${idx}i`)
}) })
this.clearDateInputs(dateInputs) this.clearDateInputs(dateInputs)
} else { } else {

2
app/helpers/question_attribute_helper.rb

@ -27,7 +27,7 @@ private
{ {
"data-controller": "conditional-question", "data-controller": "conditional-question",
"data-action": "click->conditional-question#displayConditional", "data-action": "click->conditional-question#displayConditional",
"data-info": question.conditional_for.to_json, "data-info": { conditional_questions: question.conditional_for, log_type: question.form.type }.to_json,
} }
end end
end end

5
app/models/derived_variables/sales_log_variables.rb

@ -0,0 +1,5 @@
module DerivedVariables::SalesLogVariables
def set_derived_fields!
self.ethnic = 17 if ethnic_refused?
end
end

6
app/models/form/question.rb

@ -50,9 +50,11 @@ class Form::Question
answer = label_from_value(log[id]) if log[id].present? answer = label_from_value(log[id]) if log[id].present?
answer_label = [prefix, format_value(answer), suffix_label(log)].join("") if answer answer_label = [prefix, format_value(answer), suffix_label(log)].join("") if answer
return answer_label if answer_label
has_inferred_check_answers_value?(log) ? inferred_check_answers_value["value"] : "" inferred = inferred_check_answers_value["value"] if inferred_check_answers_value && has_inferred_check_answers_value?(log)
return inferred if inferred.present?
answer_label
end end
def get_inferred_answers(log) def get_inferred_answers(log)

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

@ -0,0 +1,18 @@
class Form::Sales::Pages::Buyer1EthnicBackgroundArab < ::Form::Page
def initialize(id, hsh, subsection)
super
@id = "buyer_1_ethnic_background_arab"
@header = ""
@description = ""
@subsection = subsection
@depends_on = [{
"ethnic_group" => 4,
}]
end
def questions
@questions ||= [
Form::Sales::Questions::Buyer1EthnicBackgroundArab.new(nil, nil, self),
]
end
end

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

@ -0,0 +1,18 @@
class Form::Sales::Pages::Buyer1EthnicBackgroundAsian < ::Form::Page
def initialize(id, hsh, subsection)
super
@id = "buyer_1_ethnic_background_asian"
@header = ""
@description = ""
@subsection = subsection
@depends_on = [{
"ethnic_group" => 2,
}]
end
def questions
@questions ||= [
Form::Sales::Questions::Buyer1EthnicBackgroundAsian.new(nil, nil, self),
]
end
end

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

@ -0,0 +1,18 @@
class Form::Sales::Pages::Buyer1EthnicBackgroundBlack < ::Form::Page
def initialize(id, hsh, subsection)
super
@id = "buyer_1_ethnic_background_black"
@header = ""
@description = ""
@subsection = subsection
@depends_on = [{
"ethnic_group" => 3,
}]
end
def questions
@questions ||= [
Form::Sales::Questions::Buyer1EthnicBackgroundBlack.new(nil, nil, self),
]
end
end

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

@ -0,0 +1,18 @@
class Form::Sales::Pages::Buyer1EthnicBackgroundMixed < ::Form::Page
def initialize(id, hsh, subsection)
super
@id = "buyer_1_ethnic_background_mixed"
@header = ""
@description = ""
@subsection = subsection
@depends_on = [{
"ethnic_group" => 1,
}]
end
def questions
@questions ||= [
Form::Sales::Questions::Buyer1EthnicBackgroundMixed.new(nil, nil, self),
]
end
end

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

@ -0,0 +1,18 @@
class Form::Sales::Pages::Buyer1EthnicBackgroundWhite < ::Form::Page
def initialize(id, hsh, subsection)
super
@id = "buyer_1_ethnic_background_white"
@header = ""
@description = ""
@subsection = subsection
@depends_on = [{
"ethnic_group" => 0,
}]
end
def questions
@questions ||= [
Form::Sales::Questions::Buyer1EthnicBackgroundWhite.new(nil, nil, self),
]
end
end

15
app/models/form/sales/pages/buyer1_ethnic_group.rb

@ -0,0 +1,15 @@
class Form::Sales::Pages::Buyer1EthnicGroup < ::Form::Page
def initialize(id, hsh, subsection)
super
@id = "buyer_1_ethnic_group"
@header = ""
@description = ""
@subsection = subsection
end
def questions
@questions ||= [
Form::Sales::Questions::Buyer1EthnicGroup.new(nil, nil, self),
]
end
end

15
app/models/form/sales/pages/buyer1_working_situation.rb

@ -0,0 +1,15 @@
class Form::Sales::Pages::Buyer1WorkingSituation < ::Form::Page
def initialize(id, hsh, subsection)
super
@id = "buyer_1_working_situation"
@header = "Which of these best describes buyer 1's working situation?"
@description = ""
@subsection = subsection
end
def questions
@questions ||= [
Form::Sales::Questions::Buyer1WorkingSituation.new(nil, nil, self),
]
end
end

15
app/models/form/sales/pages/buyer2_live_in_property.rb

@ -0,0 +1,15 @@
class Form::Sales::Pages::Buyer2LiveInProperty < ::Form::Page
def initialize(id, hsh, subsection)
super
@id = "buyer_2_live_in_property"
@header = ""
@description = ""
@subsection = subsection
end
def questions
@questions ||= [
Form::Sales::Questions::Buyer2LiveInProperty.new(nil, nil, self),
]
end
end

15
app/models/form/sales/pages/buyer2_working_situation.rb

@ -0,0 +1,15 @@
class Form::Sales::Pages::Buyer2WorkingSituation < ::Form::Page
def initialize(id, hsh, subsection)
super
@id = "buyer_2_working_situation"
@header = ""
@description = ""
@subsection = subsection
end
def questions
@questions ||= [
Form::Sales::Questions::Buyer2WorkingSituation.new(nil, nil, self),
]
end
end

15
app/models/form/sales/pages/buyer_company.rb

@ -0,0 +1,15 @@
class Form::Sales::Pages::BuyerCompany < ::Form::Page
def initialize(id, hsh, subsection)
super
@id = "buyer_company"
@header = ""
@description = ""
@subsection = subsection
end
def questions
@questions ||= [
Form::Sales::Questions::BuyerCompany.new(nil, nil, self),
]
end
end

15
app/models/form/sales/pages/buyer_interview.rb

@ -0,0 +1,15 @@
class Form::Sales::Pages::BuyerInterview < ::Form::Page
def initialize(id, hsh, subsection)
super
@id = "buyer_interview"
@header = ""
@description = ""
@subsection = subsection
end
def questions
@questions ||= [
Form::Sales::Questions::BuyerInterview.new(nil, nil, self),
]
end
end

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

@ -0,0 +1,18 @@
class Form::Sales::Pages::GenderIdentity2 < ::Form::Page
def initialize(id, hsh, subsection)
super
@id = "buyer_2_gender_identity"
@header = ""
@description = ""
@subsection = subsection
@depends_on = [{
"jointpur" => 1,
}]
end
def questions
@questions ||= [
Form::Sales::Questions::GenderIdentity2.new(nil, nil, self),
]
end
end

16
app/models/form/sales/pages/nationality1.rb

@ -0,0 +1,16 @@
class Form::Sales::Pages::Nationality1 < ::Form::Page
def initialize(id, hsh, subsection)
super
@id = "buyer_1_nationality"
@header = ""
@description = ""
@subsection = subsection
end
def questions
@questions ||= [
Form::Sales::Questions::Nationality1.new(nil, nil, self),
Form::Sales::Questions::OtherNationality1.new(nil, nil, self),
]
end
end

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

@ -0,0 +1,18 @@
class Form::Sales::Pages::PrivacyNotice < ::Form::Page
def initialize(id, hsh, subsection)
super
@id = "privacy_notice"
@header = "Department for Levelling Up, Housing and Communities privacy notice"
@description = ""
@subsection = subsection
@depends_on = [{
"noint" => 1,
}]
end
def questions
@questions ||= [
Form::Sales::Questions::PrivacyNotice.new(nil, nil, self),
]
end
end

17
app/models/form/sales/questions/buyer1_ethnic_background_arab.rb

@ -0,0 +1,17 @@
class Form::Sales::Questions::Buyer1EthnicBackgroundArab < ::Form::Question
def initialize(id, hsh, page)
super
@id = "ethnic"
@check_answer_label = "Buyer 1’s ethnic background"
@header = "Which of the following best describes the buyer 1’s Arab background?"
@type = "radio"
@answer_options = ANSWER_OPTIONS
@page = page
@hint_text = "Buyer 1 is the person in the household who does the most paid work. If it’s a joint purchase and the buyers do the same amount of paid work, buyer 1 is whoever is the oldest."
end
ANSWER_OPTIONS = {
"19" => { "value" => "Arab" },
"16" => { "value" => "Other ethnic group" },
}.freeze
end

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

@ -0,0 +1,20 @@
class Form::Sales::Questions::Buyer1EthnicBackgroundAsian < ::Form::Question
def initialize(id, hsh, page)
super
@id = "ethnic"
@check_answer_label = "Buyer 1’s ethnic background"
@header = "Which of the following best describes the buyer 1’s Asian or Asian British background?"
@type = "radio"
@answer_options = ANSWER_OPTIONS
@page = page
@hint_text = "Buyer 1 is the person in the household who does the most paid work. If it’s a joint purchase and the buyers do the same amount of paid work, buyer 1 is whoever is the oldest."
end
ANSWER_OPTIONS = {
"10" => { "value" => "Bangladeshi" },
"15" => { "value" => "Chinese" },
"8" => { "value" => "Indian" },
"9" => { "value" => "Pakistani" },
"11" => { "value" => "Any other Asian or Asian British background" },
}.freeze
end

18
app/models/form/sales/questions/buyer1_ethnic_background_black.rb

@ -0,0 +1,18 @@
class Form::Sales::Questions::Buyer1EthnicBackgroundBlack < ::Form::Question
def initialize(id, hsh, page)
super
@id = "ethnic"
@check_answer_label = "Buyer 1’s ethnic background"
@header = "Which of the following best describes the buyer 1’s Black, African, Caribbean or Black British background?"
@type = "radio"
@answer_options = ANSWER_OPTIONS
@page = page
@hint_text = "Buyer 1 is the person in the household who does the most paid work. If it’s a joint purchase and the buyers do the same amount of paid work, buyer 1 is whoever is the oldest."
end
ANSWER_OPTIONS = {
"13" => { "value" => "African" },
"12" => { "value" => "Caribbean" },
"14" => { "value" => "Any other Black, African or Caribbean background" },
}.freeze
end

19
app/models/form/sales/questions/buyer1_ethnic_background_mixed.rb

@ -0,0 +1,19 @@
class Form::Sales::Questions::Buyer1EthnicBackgroundMixed < ::Form::Question
def initialize(id, hsh, page)
super
@id = "ethnic"
@check_answer_label = "Buyer 1’s ethnic background"
@header = "Which of the following best describes the buyer 1’s Mixed or Multiple ethnic groups background?"
@type = "radio"
@answer_options = ANSWER_OPTIONS
@page = page
@hint_text = "Buyer 1 is the person in the household who does the most paid work. If it’s a joint purchase and the buyers do the same amount of paid work, buyer 1 is whoever is the oldest."
end
ANSWER_OPTIONS = {
"4" => { "value" => "White and Black Caribbean" },
"5" => { "value" => "White and Black African" },
"6" => { "value" => "White and Asian" },
"7" => { "value" => "Any other Mixed or Multiple ethnic background" },
}.freeze
end

19
app/models/form/sales/questions/buyer1_ethnic_background_white.rb

@ -0,0 +1,19 @@
class Form::Sales::Questions::Buyer1EthnicBackgroundWhite < ::Form::Question
def initialize(id, hsh, page)
super
@id = "ethnic"
@check_answer_label = "Buyer 1’s ethnic background"
@header = "Which of the following best describes the buyer 1’s White background?"
@type = "radio"
@answer_options = ANSWER_OPTIONS
@page = page
@hint_text = "Buyer 1 is the person in the household who does the most paid work. If it’s a joint purchase and the buyers do the same amount of paid work, buyer 1 is whoever is the oldest."
end
ANSWER_OPTIONS = {
"1" => { "value" => "English, Welsh, Northern Irish, Scottish or British" },
"2" => { "value" => "Irish" },
"18" => { "value" => "Gypsy or Irish Traveller" },
"3" => { "value" => "Any other White background" },
}.freeze
end

28
app/models/form/sales/questions/buyer1_ethnic_group.rb

@ -0,0 +1,28 @@
class Form::Sales::Questions::Buyer1EthnicGroup < ::Form::Question
def initialize(id, hsh, page)
super
@id = "ethnic_group"
@check_answer_label = "Buyer 1’s ethnic group"
@header = "What is buyer 1’s ethnic group?"
@type = "radio"
@answer_options = ANSWER_OPTIONS
@page = page
@hint_text = "Buyer 1 is the person in the household who does the most paid work. If it’s a joint purchase and the buyers do the same amount of paid work, buyer 1 is whoever is the oldest."
@inferred_check_answers_value = {
"condition" => {
"ethnic_group" => 17,
},
"value" => "Prefers not to say",
}
end
ANSWER_OPTIONS = {
"0" => { "value" => "White" },
"1" => { "value" => "Mixed or Multiple ethnic groups" },
"2" => { "value" => "Asian or Asian British" },
"3" => { "value" => "Black, African, Caribbean or Black British" },
"4" => { "value" => "Arab or other ethnic group" },
"divider" => { "value" => true },
"17" => { "value" => "Buyer 1 prefers not to say" },
}.freeze
end

26
app/models/form/sales/questions/buyer1_working_situation.rb

@ -0,0 +1,26 @@
class Form::Sales::Questions::Buyer1WorkingSituation < ::Form::Question
def initialize(id, hsh, page)
super
@id = "ecstat1"
@check_answer_label = "Buyer 1's working situation"
@header = "Which of these best describes buyer 1's working situation?"
@type = "radio"
@answer_options = ANSWER_OPTIONS
@page = page
@hint_text = "Buyer 1 is the person in the household who does the most paid work. If it's a joint purchase and the buyers do the same amount of paid work, buyer 1 is whoever is the oldest."
end
ANSWER_OPTIONS = {
"2" => { "value" => "Part-time - Less than 30 hours" },
"1" => { "value" => "Full-time - 30 hours or more" },
"3" => { "value" => "In government training into work, such as New Deal" },
"4" => { "value" => "Jobseeker" },
"6" => { "value" => "Not seeking work" },
"8" => { "value" => "Unable to work due to long term sick or disability" },
"5" => { "value" => "Retired" },
"0" => { "value" => "Other" },
"10" => { "value" => "Buyer prefers not to say" },
"7" => { "value" => "Full-time student" },
"9" => { "value" => "Child under 16" },
}.freeze
end

17
app/models/form/sales/questions/buyer2_live_in_property.rb

@ -0,0 +1,17 @@
class Form::Sales::Questions::Buyer2LiveInProperty < ::Form::Question
def initialize(id, hsh, page)
super
@id = "buy2livein"
@check_answer_label = "Will buyer 2 live in the property?"
@header = "Will buyer 2 live in the property?"
@type = "radio"
@hint_text = ""
@answer_options = ANSWER_OPTIONS
@page = page
end
ANSWER_OPTIONS = {
"1" => { "value" => "Yes" },
"2" => { "value" => "No" },
}.freeze
end

26
app/models/form/sales/questions/buyer2_working_situation.rb

@ -0,0 +1,26 @@
class Form::Sales::Questions::Buyer2WorkingSituation < ::Form::Question
def initialize(id, hsh, page)
super
@id = "ecstat2"
@check_answer_label = "Buyer 2's working situation"
@header = "Which of these best describes buyer 2's working situation?"
@type = "radio"
@hint_text = ""
@page = page
@answer_options = ANSWER_OPTIONS
end
ANSWER_OPTIONS = {
"2" => { "value" => "Part-time - Less than 30 hours" },
"1" => { "value" => "Full-time - 30 hours or more" },
"3" => { "value" => "In government training into work, such as New Deal" },
"4" => { "value" => "Jobseeker" },
"6" => { "value" => "Not seeking work" },
"8" => { "value" => "Unable to work due to long term sick or disability" },
"5" => { "value" => "Retired" },
"0" => { "value" => "Other" },
"10" => { "value" => "Buyer prefers not to say" },
"7" => { "value" => "Full-time student" },
"9" => { "value" => "Child under 16" },
}.freeze
end

17
app/models/form/sales/questions/buyer_company.rb

@ -0,0 +1,17 @@
class Form::Sales::Questions::BuyerCompany < ::Form::Question
def initialize(id, hsh, page)
super
@id = "companybuy"
@check_answer_label = "Company buyer"
@header = "Is the buyer a company?"
@hint_text = ""
@type = "radio"
@answer_options = ANSWER_OPTIONS
@page = page
end
ANSWER_OPTIONS = {
"1" => { "value" => "Yes" },
"2" => { "value" => "No" },
}.freeze
end

17
app/models/form/sales/questions/buyer_interview.rb

@ -0,0 +1,17 @@
class Form::Sales::Questions::BuyerInterview < ::Form::Question
def initialize(id, hsh, page)
super
@id = "noint"
@check_answer_label = "Buyer interviewed in person?"
@header = "Was the buyer interviewed for any of the answers you will provide on this log?"
@type = "radio"
@hint_text = "You should still try to answer all questions even if the buyer wasn't interviewed in person"
@page = page
@answer_options = ANSWER_OPTIONS
end
ANSWER_OPTIONS = {
"1" => { "value" => "No" },
"2" => { "value" => "Yes" },
}.freeze
end

18
app/models/form/sales/questions/gender_identity2.rb

@ -0,0 +1,18 @@
class Form::Sales::Questions::GenderIdentity2 < ::Form::Question
def initialize(id, hsh, page)
super
@id = "sex2"
@check_answer_label = "Buyer 2’s gender identity"
@header = "Which of these best describes buyer 2’s gender identity?"
@type = "radio"
@page = page
@answer_options = ANSWER_OPTIONS
end
ANSWER_OPTIONS = {
"F" => { "value" => "Female" },
"M" => { "value" => "Male" },
"X" => { "value" => "Non-binary" },
"R" => { "value" => "Buyer prefers not to say" },
}.freeze
end

30
app/models/form/sales/questions/nationality1.rb

@ -0,0 +1,30 @@
class Form::Sales::Questions::Nationality1 < ::Form::Question
def initialize(id, hsh, page)
super
@id = "national"
@check_answer_label = "Buyer 1’s nationality"
@header = "What is buyer 1’s nationality?"
@type = "radio"
@hint_text = "Buyer 1 is the person in the household who does the most paid work. If it’s a joint purchase and the buyers do the same amount of paid work, buyer 1 is whoever is the oldest."
@page = page
@answer_options = ANSWER_OPTIONS
@conditional_for = {
"othernational" => [12],
}
@hidden_in_check_answers = {
"depends_on" => [
{
"national" => 12,
},
],
}
end
ANSWER_OPTIONS = {
"18" => { "value" => "United Kingdom" },
"17" => { "value" => "Republic of Ireland" },
"19" => { "value" => "European Economic Area (EEA), excluding ROI" },
"12" => { "value" => "Other" },
"13" => { "value" => "Buyer prefers not to say" },
}.freeze
end

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

@ -0,0 +1,10 @@
class Form::Sales::Questions::OtherNationality1 < ::Form::Question
def initialize(id, hsh, page)
super
@id = "othernational"
@check_answer_label = "Buyer 1’s nationality"
@header = "Nationality"
@type = "text"
@page = page
end
end

18
app/models/form/sales/questions/privacy_notice.rb

@ -0,0 +1,18 @@
class Form::Sales::Questions::PrivacyNotice < ::Form::Question
def initialize(id, hsh, page)
super
@id = "privacynotice"
@check_answer_label = "Buyer has seen the privacy notice?"
@header = "Declaration"
@type = "checkbox"
@hint_text = ""
@page = page
@answer_options = ANSWER_OPTIONS
@guidance_position = GuidancePosition::TOP
@guidance_partial = "privacy_notice_buyer"
end
ANSWER_OPTIONS = {
"privacynotice" => { "value" => "The buyer has seen the DLUHC privacy notice" },
}.freeze
end

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

@ -9,11 +9,24 @@ class Form::Sales::Subsections::HouseholdCharacteristics < ::Form::Subsection
def pages def pages
@pages ||= [ @pages ||= [
Form::Sales::Pages::BuyerInterview.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::GenderIdentity1.new(nil, nil, self), Form::Sales::Pages::GenderIdentity1.new(nil, nil, self),
Form::Sales::Pages::Buyer1EthnicGroup.new(nil, nil, self),
Form::Sales::Pages::Buyer1EthnicBackgroundBlack.new(nil, nil, self),
Form::Sales::Pages::Buyer1EthnicBackgroundAsian.new(nil, nil, self),
Form::Sales::Pages::Buyer1EthnicBackgroundArab.new(nil, nil, self),
Form::Sales::Pages::Buyer1EthnicBackgroundMixed.new(nil, nil, self),
Form::Sales::Pages::Buyer1EthnicBackgroundWhite.new(nil, nil, self),
Form::Sales::Pages::Nationality1.new(nil, nil, self),
Form::Sales::Pages::Buyer1WorkingSituation.new(nil, 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::GenderIdentity2.new(nil, nil, self),
Form::Sales::Pages::Buyer2WorkingSituation.new(nil, nil, self),
Form::Sales::Pages::Buyer2LiveInProperty.new(nil, nil, self),
] ]
end end
end end

1
app/models/form/sales/subsections/setup.rb

@ -16,6 +16,7 @@ class Form::Sales::Subsections::Setup < ::Form::Subsection
Form::Sales::Pages::SharedOwnershipType.new(nil, nil, self), Form::Sales::Pages::SharedOwnershipType.new(nil, nil, self),
Form::Sales::Pages::DiscountedOwnershipType.new(nil, nil, self), Form::Sales::Pages::DiscountedOwnershipType.new(nil, nil, self),
Form::Sales::Pages::OutrightOwnershipType.new(nil, nil, self), Form::Sales::Pages::OutrightOwnershipType.new(nil, nil, self),
Form::Sales::Pages::BuyerCompany.new(nil, nil, self),
Form::Sales::Pages::BuyerLive.new(nil, nil, self), Form::Sales::Pages::BuyerLive.new(nil, nil, self),
Form::Sales::Pages::JointPurchase.new(nil, nil, self), Form::Sales::Pages::JointPurchase.new(nil, nil, self),
Form::Sales::Pages::NumberJointBuyers.new(nil, nil, self), Form::Sales::Pages::NumberJointBuyers.new(nil, nil, self),

4
app/models/lettings_log.rb

@ -372,10 +372,6 @@ class LettingsLog < Log
hb == 7 hb == 7
end end
def ethnic_refused?
ethnic_group == 17
end
def receives_housing_related_benefits? def receives_housing_related_benefits?
if collection_start_year <= 2021 if collection_start_year <= 2021
receives_housing_benefit_only? || receives_uc_with_housing_element_excl_housing_benefit? || receives_housing_benefit_only? || receives_uc_with_housing_element_excl_housing_benefit? ||

4
app/models/log.rb

@ -36,6 +36,10 @@ class Log < ApplicationRecord
false false
end end
def ethnic_refused?
ethnic_group == 17
end
private private
def update_status! def update_status!

5
app/models/sales_log.rb

@ -3,10 +3,15 @@ class SalesLogValidator < ActiveModel::Validator
end end
class SalesLog < Log class SalesLog < Log
include DerivedVariables::SalesLogVariables
self.inheritance_column = :_type_disabled self.inheritance_column = :_type_disabled
has_paper_trail has_paper_trail
validates_with SalesLogValidator validates_with SalesLogValidator
before_validation :set_derived_fields!
before_validation :reset_invalidated_dependent_fields!
scope :filter_by_year, ->(year) { where(saledate: Time.zone.local(year.to_i, 4, 1)...Time.zone.local(year.to_i + 1, 4, 1)) } scope :filter_by_year, ->(year) { where(saledate: Time.zone.local(year.to_i, 4, 1)...Time.zone.local(year.to_i + 1, 4, 1)) }
scope :search_by, ->(param) { filter_by_id(param) } scope :search_by, ->(param) { filter_by_id(param) }

1
app/views/form/guidance/_privacy_notice_buyer.erb

@ -0,0 +1 @@
<p class="govuk-body">Make sure the buyer has seen <%= govuk_link_to "the Department for Levelling Up, Housing & Communities (DLUHC) privacy notice", privacy_notice_path, target: :_blank %> before completing this log.</p>

2
app/views/form/guidance/_privacy_notice.erb → app/views/form/guidance/_privacy_notice_tenant.erb

@ -1 +1 @@
<p class="govuk-body">Make sure the tenant has seen <%= govuk_link_to "the Department for Levelling Up, Housing & Communities (DLUHC) privacy notice", privacy_notice_path %> before completing this log.</p> <p class="govuk-body">Make sure the tenant has seen <%= govuk_link_to "the Department for Levelling Up, Housing & Communities (DLUHC) privacy notice", privacy_notice_path, target: :_blank %> before completing this log.</p>

4
app/views/logs/index.html.erb

@ -7,10 +7,10 @@
<div class="app-filter-layout" data-controller="filter-layout"> <div class="app-filter-layout" data-controller="filter-layout">
<div class="govuk-button-group app-filter-toggle"> <div class="govuk-button-group app-filter-toggle">
<% if current_page?(:controller => 'lettings_logs', :action => 'index') %> <% if current_page?(controller: 'lettings_logs', action: 'index') %>
<%= govuk_button_to "Create a new lettings log", lettings_logs_path %> <%= govuk_button_to "Create a new lettings log", lettings_logs_path %>
<% end %> <% end %>
<% if FeatureToggle.sales_log_enabled? && current_page?(:controller => 'sales_logs', :action => 'index') %> <% if FeatureToggle.sales_log_enabled? && current_page?(controller: 'sales_logs', action: 'index') %>
<%= govuk_button_to "Create a new sales log", sales_logs_path %> <%= govuk_button_to "Create a new sales log", sales_logs_path %>
<% end %> <% end %>
<%#= govuk_link_to "Upload logs", bulk_upload_lettings_logs_path %> <%#= govuk_link_to "Upload logs", bulk_upload_lettings_logs_path %>

5
app/views/organisations/logs.html.erb

@ -14,7 +14,12 @@
<div class="app-filter-layout" data-controller="filter-layout"> <div class="app-filter-layout" data-controller="filter-layout">
<div class="govuk-button-group app-filter-toggle"> <div class="govuk-button-group app-filter-toggle">
<% if current_page?(controller: 'organisations', action: 'lettings_logs') %>
<%= govuk_button_to "Create a new lettings log for this organisation", lettings_logs_path(lettings_log: { owning_organisation_id: @organisation.id }, method: :post) %> <%= govuk_button_to "Create a new lettings log for this organisation", lettings_logs_path(lettings_log: { owning_organisation_id: @organisation.id }, method: :post) %>
<% end %>
<% if current_page?(controller: 'organisations', action: 'sales_logs') %>
<%= govuk_button_to "Create a new sales log for this organisation", sales_logs_path(sales_log: { owning_organisation_id: @organisation.id }, method: :post) %>
<% end %>
</div> </div>
<%= render partial: "logs/log_filters" %> <%= render partial: "logs/log_filters" %>

579
config/forms/2021_2022.json

File diff suppressed because it is too large Load Diff

583
config/forms/2022_2023.json

File diff suppressed because it is too large Load Diff

16
config/forms/schema/2021_2022.json

@ -4,7 +4,12 @@
"title": "Form", "title": "Form",
"description": "A form", "description": "A form",
"type": "object", "type": "object",
"required": ["form_type", "start_year", "end_year", "sections"], "required": [
"form_type",
"start_year",
"end_year",
"sections"
],
"properties": { "properties": {
"form_type": { "form_type": {
"description": "", "description": "",
@ -35,7 +40,9 @@
"[a-z_]+": { "[a-z_]+": {
"description": "", "description": "",
"type": "object", "type": "object",
"required": ["label"], "required": [
"label"
],
"properties": { "properties": {
"label": { "label": {
"description": "", "description": "",
@ -62,7 +69,10 @@
"[a-z_]+": { "[a-z_]+": {
"description": "", "description": "",
"type": "object", "type": "object",
"required": ["header", "check_answer_label"], "required": [
"header",
"check_answer_label"
],
"properties": { "properties": {
"check_answer_label": { "check_answer_label": {
"description": "", "description": "",

21
config/forms/schema/generic.json

@ -4,7 +4,12 @@
"title": "Form", "title": "Form",
"description": "A form", "description": "A form",
"type": "object", "type": "object",
"required": ["form_type", "start_year", "end_year", "sections"], "required": [
"form_type",
"start_year",
"end_year",
"sections"
],
"properties": { "properties": {
"form_type": { "form_type": {
"description": "", "description": "",
@ -35,7 +40,9 @@
"[a-z_]+": { "[a-z_]+": {
"description": "SubSection Name", "description": "SubSection Name",
"type": "object", "type": "object",
"required": ["label"], "required": [
"label"
],
"properties": { "properties": {
"label": { "label": {
"description": "", "description": "",
@ -47,7 +54,10 @@
"^(?!(depends_on))[a-z_]+$": { "^(?!(depends_on))[a-z_]+$": {
"description": "Page Name", "description": "Page Name",
"type": "object", "type": "object",
"required": ["header", "questions"], "required": [
"header",
"questions"
],
"properties": { "properties": {
"header": { "header": {
"description": "", "description": "",
@ -63,7 +73,10 @@
"[a-z_]+": { "[a-z_]+": {
"description": "Question Name", "description": "Question Name",
"type": "object", "type": "object",
"required": ["header", "type"], "required": [
"header",
"type"
],
"properties": { "properties": {
"header": { "header": {
"description": "", "description": "",

8
db/migrate/20220927082602_add_national_column.rb

@ -0,0 +1,8 @@
class AddNationalColumn < ActiveRecord::Migration[7.0]
def change
change_table :sales_logs, bulk: true do |t|
t.column :national, :integer
t.column :othernational, :string
end
end
end

6
db/migrate/20220927100350_add_background_to_sales_log.rb

@ -0,0 +1,6 @@
class AddBackgroundToSalesLog < ActiveRecord::Migration[7.0]
change_table :sales_logs, bulk: true do |t|
t.column :ethnic, :integer
t.column :ethnic_group, :integer
end
end

5
db/migrate/20220930134358_add_buyer2_sex_to_sales_log.rb

@ -0,0 +1,5 @@
class AddBuyer2SexToSalesLog < ActiveRecord::Migration[7.0]
def change
add_column :sales_logs, :sex2, :string
end
end

7
db/migrate/20221003092048_add_noint_to_sales_log.rb

@ -0,0 +1,7 @@
class AddNointToSalesLog < ActiveRecord::Migration[7.0]
def change
change_table :sales_logs, bulk: true do |t|
t.column :noint, :int
end
end
end

7
db/migrate/20221003134554_add_buy2livein_to_sales_log.rb

@ -0,0 +1,7 @@
class AddBuy2liveinToSalesLog < ActiveRecord::Migration[7.0]
def change
change_table :sales_logs, bulk: true do |t|
t.column :buy2livein, :int
end
end
end

7
db/migrate/20221003150610_add_ecstat2_to_sales_log.rb

@ -0,0 +1,7 @@
class AddEcstat2ToSalesLog < ActiveRecord::Migration[7.0]
def change
change_table :sales_logs, bulk: true do |t|
t.column :ecstat2, :int
end
end
end

7
db/migrate/20221004095132_add_privacy_notice_to_sales_log.rb

@ -0,0 +1,7 @@
class AddPrivacyNoticeToSalesLog < ActiveRecord::Migration[7.0]
def change
change_table :sales_logs, bulk: true do |t|
t.column :privacynotice, :int
end
end
end

7
db/migrate/20221004184301_add_ecstat1_to_sales_log.rb

@ -0,0 +1,7 @@
class AddEcstat1ToSalesLog < ActiveRecord::Migration[7.0]
def change
change_table :sales_logs, bulk: true do |t|
t.column :ecstat1, :int
end
end
end

18
db/schema.rb

@ -10,7 +10,7 @@
# #
# It's strongly recommended that you check this file into your version control system. # It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema[7.0].define(version: 2022_09_29_125204) do ActiveRecord::Schema[7.0].define(version: 2022_10_04_184301) do
# These are extensions that must be enabled in order to support this database # These are extensions that must be enabled in order to support this database
enable_extension "plpgsql" enable_extension "plpgsql"
@ -333,18 +333,28 @@ ActiveRecord::Schema[7.0].define(version: 2022_09_29_125204) do
t.integer "jointmore" t.integer "jointmore"
t.integer "jointpur" t.integer "jointpur"
t.integer "beds" t.integer "beds"
t.integer "companybuy"
t.integer "age1" t.integer "age1"
t.integer "age1_known" t.integer "age1_known"
t.integer "companybuy"
t.string "sex1" t.string "sex1"
t.integer "ethnic"
t.integer "ethnic_group"
t.integer "buy1livein" t.integer "buy1livein"
t.integer "buylivein" t.integer "buylivein"
t.integer "builtype" t.integer "builtype"
t.integer "proptype" t.integer "proptype"
t.string "relat2"
t.string "otherrelat2"
t.integer "age2" t.integer "age2"
t.integer "age2_known" t.integer "age2_known"
t.string "relat2"
t.string "otherrelat2"
t.string "sex2"
t.integer "noint"
t.integer "buy2livein"
t.integer "ecstat2"
t.integer "ecstat1"
t.integer "national"
t.string "othernational"
t.integer "privacynotice"
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 ["managing_organisation_id"], name: "index_sales_logs_on_managing_organisation_id" t.index ["managing_organisation_id"], name: "index_sales_logs_on_managing_organisation_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"

9
spec/factories/sales_log.rb

@ -16,18 +16,27 @@ FactoryBot.define do
ownershipsch { 2 } ownershipsch { 2 }
type { 8 } type { 8 }
saledate { Time.utc(2022, 2, 2, 10, 36, 49) } saledate { Time.utc(2022, 2, 2, 10, 36, 49) }
companybuy { 1 }
jointpur { 1 } jointpur { 1 }
beds { 2 } beds { 2 }
jointmore { 1 } jointmore { 1 }
noint { 2 }
age1_known { 0 } age1_known { 0 }
age1 { 30 } age1 { 30 }
sex1 { "X" } sex1 { "X" }
national { 18 }
buy1livein { 1 } buy1livein { 1 }
relat2 { "P" } relat2 { "P" }
proptype { 1 } proptype { 1 }
age2_known { 0 } age2_known { 0 }
age2 { 35 } age2 { 35 }
builtype { 1 } builtype { 1 }
ethnic { 3 }
ethnic_group { 12 }
sex2 { "X" }
buy2livein { "1" }
ecstat1 { "1" }
ecstat2 { "1" }
end end
end end
end end

18
spec/features/form/conditional_questions_spec.rb

@ -12,6 +12,14 @@ RSpec.describe "Form Conditional Questions" do
managing_organisation: user.organisation, managing_organisation: user.organisation,
) )
end end
let(:sales_log) do
FactoryBot.create(
:sales_log,
:completed,
owning_organisation: user.organisation,
managing_organisation: user.organisation,
)
end
let(:id) { lettings_log.id } let(:id) { lettings_log.id }
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") }
@ -44,5 +52,15 @@ RSpec.describe "Form Conditional Questions" do
visit("/lettings-logs/#{id}/property-postcode") visit("/lettings-logs/#{id}/property-postcode")
expect(page).to have_field("lettings-log-postcode-full-field", with: "NW1 6RT") expect(page).to have_field("lettings-log-postcode-full-field", with: "NW1 6RT")
end end
it "gets cleared if the conditional question is hidden after editing the answer" do
sales_log.update!(national: 12, othernational: "other")
visit("/sales-logs/#{sales_log.id}/buyer-1-nationality")
expect(page).to have_field("sales-log-othernational-field", with: "other")
choose("sales-log-national-18-field", allow_label_click: true)
choose("sales-log-national-12-field", allow_label_click: true)
expect(page).to have_field("sales-log-othernational-field", with: "")
end
end end
end end

37
spec/features/organisation_spec.rb

@ -134,7 +134,7 @@ RSpec.describe "User Features" do
click_button("Submit") click_button("Submit")
end end
context "when viewing logs for specific organisation" do context "when viewing lettings logs for specific organisation" do
let(:first_log) { organisation.lettings_logs.first } let(:first_log) { organisation.lettings_logs.first }
let!(:log_to_search) { FactoryBot.create(:lettings_log, owning_organisation: user.organisation, managing_organisation_id: organisation.id) } let!(:log_to_search) { FactoryBot.create(:lettings_log, owning_organisation: user.organisation, managing_organisation_id: organisation.id) }
let!(:other_logs) { FactoryBot.create_list(:lettings_log, 4, owning_organisation_id: organisation.id, managing_organisation_id: organisation.id) } let!(:other_logs) { FactoryBot.create_list(:lettings_log, 4, owning_organisation_id: organisation.id, managing_organisation_id: organisation.id) }
@ -189,7 +189,7 @@ RSpec.describe "User Features" do
expect(page).to have_link("Clear search") expect(page).to have_link("Clear search")
end end
it "displays the logs belonging to the same organisation after I clear the search result after I clear the search resultss" do it "displays the logs belonging to the same organisation after I clear the search result after I clear the search results" do
click_link("Clear search") click_link("Clear search")
expect(page).to have_link(log_to_search.id.to_s) expect(page).to have_link(log_to_search.id.to_s)
end end
@ -210,6 +210,39 @@ RSpec.describe "User Features" do
end end
end end
context "when viewing sales logs for specific organisation" do
let(:first_log) { organisation.sales_logs.first }
let(:number_of_sales_logs) { SalesLog.count }
before do
FactoryBot.create_list(:sales_log, 4, owning_organisation_id: organisation.id, managing_organisation_id: organisation.id)
visit("/organisations/#{org_id}/sales-logs")
end
it "shows a create button for that organisation" do
expect(page).to have_button("Create a new sales log for this organisation")
end
context "when creating a log for that organisation" do
it "pre-fills the value for owning organisation for that log" do
click_button("Create a new sales log for this organisation")
click_link("Set up this sales log")
expect(page).to have_content(org_name)
end
end
it "can filter sales logs" do
expect(page).to have_content("#{number_of_sales_logs} total logs")
organisation.sales_logs.map(&:id).each do |sales_log_id|
expect(page).to have_link sales_log_id.to_s, href: "/sales-logs/#{sales_log_id}"
end
check("years-2021-field")
click_button("Apply filters")
expect(page).to have_current_path("/organisations/#{org_id}/sales-logs?years[]=&years[]=2021&status[]=&user=all")
expect(page).not_to have_link first_log.id.to_s, href: "/sales-logs/#{first_log.id}"
end
end
context "when I search for users belonging to a specific organisation" do context "when I search for users belonging to a specific organisation" do
context "when I am signed in and there are users in the database" do context "when I am signed in and there are users in the database" do
let!(:user_list) { FactoryBot.create_list(:user, 4, organisation: user.organisation) } let!(:user_list) { FactoryBot.create_list(:user, 4, organisation: user.organisation) }

175
spec/fixtures/forms/2021_2022.json vendored

@ -28,7 +28,8 @@
{ {
"housingneeds_a": null "housingneeds_a": null
} }
]}, ]
},
"person_1_age": { "person_1_age": {
"questions": { "questions": {
"age1": { "age1": {
@ -209,7 +210,10 @@
}, },
"depends_on": [ "depends_on": [
{ {
"age2": { "operator": ">", "operand": 50 } "age2": {
"operator": ">",
"operand": 50
}
} }
] ]
}, },
@ -229,8 +233,15 @@
"9": { "9": {
"value": "Child under 16", "value": "Child under 16",
"depends_on": [ "depends_on": [
{ "age2_known": 1 }, {
{ "age2": { "operator": "<", "operand": 16 } } "age2_known": 1
},
{
"age2": {
"operator": "<",
"operand": 16
}
}
] ]
}, },
"1": { "1": {
@ -241,7 +252,10 @@
}, },
"depends_on": [ "depends_on": [
{ {
"age2": { "operator": ">", "operand": 15 } "age2": {
"operator": ">",
"operand": 15
}
} }
] ]
}, },
@ -286,7 +300,15 @@
} }
}, },
"conditional_for": { "conditional_for": {
"leftreg": [1] "leftreg": [
1
]
},
"inferred_check_answers_value": {
"condition": {
"armedforces": 3
},
"value": "Prefers not to say"
} }
}, },
"leftreg": { "leftreg": {
@ -461,9 +483,15 @@
"hint_text": "", "hint_text": "",
"type": "text", "type": "text",
"width": 5, "width": 5,
"inferred_answers": { "la": { "is_la_inferred": true } }, "inferred_answers": {
"la": {
"is_la_inferred": true
}
},
"inferred_check_answers_value": { "inferred_check_answers_value": {
"condition": { "postcode_known": 0 }, "condition": {
"postcode_known": 0
},
"value": "Not known" "value": "Not known"
} }
} }
@ -488,7 +516,11 @@
} }
} }
}, },
"depends_on": [{"is_la_inferred": false}] "depends_on": [
{
"is_la_inferred": false
}
]
}, },
"property_wheelchair_accessible": { "property_wheelchair_accessible": {
"questions": { "questions": {
@ -542,7 +574,14 @@
} }
} }
}, },
"depends_on": [{ "preg_occ": 1 }, { "wchair" : 1 }] "depends_on": [
{
"preg_occ": 1
},
{
"wchair": 1
}
]
}, },
"conditional_question_no_page": { "conditional_question_no_page": {
"questions": { "questions": {
@ -560,7 +599,11 @@
} }
} }
}, },
"depends_on": [{ "preg_occ": 2 }] "depends_on": [
{
"preg_occ": 2
}
]
}, },
"conditional_question_no_second_page": { "conditional_question_no_second_page": {
"questions": { "questions": {
@ -578,7 +621,12 @@
} }
} }
}, },
"depends_on": [{ "preg_occ": 2, "sex1": "M" }] "depends_on": [
{
"preg_occ": 2,
"sex1": "M"
}
]
} }
} }
} }
@ -604,9 +652,24 @@
"width": 5, "width": 5,
"prefix": "£", "prefix": "£",
"suffix": [ "suffix": [
{ "label": " every week", "depends_on" : { "incfreq": 1 } }, {
{ "label": " every month", "depends_on" : { "incfreq": 2 } }, "label": " every week",
{ "label": " every year", "depends_on" : { "incfreq": 3 } } "depends_on": {
"incfreq": 1
}
},
{
"label": " every month",
"depends_on": {
"incfreq": 2
}
},
{
"label": " every year",
"depends_on": {
"incfreq": 3
}
}
] ]
}, },
"incfreq": { "incfreq": {
@ -628,11 +691,18 @@
} }
}, },
"net_income_value_check": { "net_income_value_check": {
"depends_on": [{ "net_income_soft_validation_triggered?": true }], "depends_on": [
"title_text": { "translation": "soft_validations.net_income.title_text" }, {
"net_income_soft_validation_triggered?": true
}
],
"title_text": {
"translation": "soft_validations.net_income.title_text"
},
"informative_text": { "informative_text": {
"translation": "soft_validations.net_income.hint_text", "translation": "soft_validations.net_income.hint_text",
"arguments": [{ "arguments": [
{
"key": "ecstat1", "key": "ecstat1",
"label": true, "label": true,
"i18n_template": "ecstat1" "i18n_template": "ecstat1"
@ -693,7 +763,9 @@
} }
}, },
"conditional_for": { "conditional_for": {
"conditional_question": [0] "conditional_question": [
0
]
} }
}, },
"conditional_question": { "conditional_question": {
@ -712,7 +784,11 @@
} }
}, },
"dependent_page": { "dependent_page": {
"depends_on": [{ "incfreq": 1 }], "depends_on": [
{
"incfreq": 1
}
],
"questions": { "questions": {
"dependent_question": { "dependent_question": {
"check_answer_label": "Dependent Question", "check_answer_label": "Dependent Question",
@ -757,7 +833,12 @@
"min": 0, "min": 0,
"step": 1, "step": 1,
"width": 4, "width": 4,
"fields-to-add": ["brent", "scharge", "pscharge", "supcharg"], "fields-to-add": [
"brent",
"scharge",
"pscharge",
"supcharg"
],
"result-field": "tcharge" "result-field": "tcharge"
}, },
"scharge": { "scharge": {
@ -768,7 +849,12 @@
"min": 0, "min": 0,
"step": 1, "step": 1,
"width": 4, "width": 4,
"fields-to-add": ["brent", "scharge", "pscharge", "supcharg"], "fields-to-add": [
"brent",
"scharge",
"pscharge",
"supcharg"
],
"result-field": "tcharge" "result-field": "tcharge"
}, },
"pscharge": { "pscharge": {
@ -779,7 +865,12 @@
"min": 0, "min": 0,
"step": 1, "step": 1,
"width": 4, "width": 4,
"fields-to-add": ["brent", "scharge", "pscharge", "supcharg"], "fields-to-add": [
"brent",
"scharge",
"pscharge",
"supcharg"
],
"result-field": "tcharge" "result-field": "tcharge"
}, },
"supcharg": { "supcharg": {
@ -791,7 +882,12 @@
"max": 300, "max": 300,
"step": 1, "step": 1,
"width": 4, "width": 4,
"fields-to-add": ["brent", "scharge", "pscharge", "supcharg"], "fields-to-add": [
"brent",
"scharge",
"pscharge",
"supcharg"
],
"result-field": "tcharge" "result-field": "tcharge"
}, },
"tcharge": { "tcharge": {
@ -836,7 +932,11 @@
"width": 4 "width": 4
} }
}, },
"depends_on": [{ "period": 3 }] "depends_on": [
{
"period": 3
}
]
}, },
"care_home_charge_bi_weekly": { "care_home_charge_bi_weekly": {
"questions": { "questions": {
@ -850,7 +950,11 @@
"width": 4 "width": 4
} }
}, },
"depends_on": [{ "period": 2 }] "depends_on": [
{
"period": 2
}
]
} }
} }
} }
@ -898,11 +1002,22 @@
} }
}, },
"hidden_in_check_answers": { "hidden_in_check_answers": {
"depends_on": [{ "layear": 0 }, { "layear": 1 }] "depends_on": [
{
"layear": 0
},
{
"layear": 1
}
]
} }
} }
}, },
"depends_on": [{ "renewal": 0 }] "depends_on": [
{
"renewal": 0
}
]
}, },
"time_on_la_waiting_list": { "time_on_la_waiting_list": {
"questions": { "questions": {
@ -950,7 +1065,9 @@
"hint_text": "If the household has moved from settled accommodation immediately prior to being re-housed", "hint_text": "If the household has moved from settled accommodation immediately prior to being re-housed",
"type": "text", "type": "text",
"width": 5, "width": 5,
"conditional_for": { "fake_key": "fake_condition" } "conditional_for": {
"fake_key": "fake_condition"
}
}, },
"ppostcode_full": { "ppostcode_full": {
"check_answer_label": "Postcode of previous accommodation if the household has moved from settled accommodation", "check_answer_label": "Postcode of previous accommodation if the household has moved from settled accommodation",

4
spec/fixtures/forms/2022_2023.json vendored

@ -40,7 +40,9 @@
} }
} }
}, },
"depends_on": [false] "depends_on": [
false
]
} }
}, },
"depends_on": [ "depends_on": [

6
spec/fixtures/forms/test_validator.json vendored

@ -22,7 +22,11 @@
"type": "text" "type": "text"
} }
}, },
"depends_on": [{"test": "Yes"}] "depends_on": [
{
"test": "Yes"
}
]
}, },
"person_1_age": { "person_1_age": {
"header": "", "header": "",

4
spec/helpers/question_attribute_helper_spec.rb

@ -40,7 +40,7 @@ RSpec.describe QuestionAttributeHelper do
"conditional_for" => { "conditional_for" => {
"next_question": ">1", "next_question": ">1",
}, },
}, nil) }, form.get_page("rent"))
end end
let(:expected_attribs) do let(:expected_attribs) do
{ {
@ -48,7 +48,7 @@ RSpec.describe QuestionAttributeHelper do
"data-action": "input->numeric-question#calculateFields click->conditional-question#displayConditional", "data-action": "input->numeric-question#calculateFields click->conditional-question#displayConditional",
"data-target": "lettings-log-#{question.result_field.to_s.dasherize}-field", "data-target": "lettings-log-#{question.result_field.to_s.dasherize}-field",
"data-calculated": question.fields_to_add.to_json, "data-calculated": question.fields_to_add.to_json,
"data-info": question.conditional_for.to_json, "data-info": { conditional_questions: question.conditional_for, log_type: "lettings" }.to_json,
} }
end end

23
spec/models/form/question_spec.rb

@ -340,6 +340,29 @@ RSpec.describe Form::Question, type: :model do
expect(question.answer_label(lettings_log)).to eq("£500.00 every year") expect(question.answer_label(lettings_log)).to eq("£500.00 every year")
end end
end end
context "with inferred_check_answers_value" do
context "when Lettings form" do
let(:section_id) { "household" }
let(:subsection_id) { "household_needs" }
let(:page_id) { "armed_forces" }
let(:question_id) { "armedforces" }
it "returns the inferred label value" do
lettings_log.armedforces = 3
expect(question.answer_label(lettings_log)).to eq("Prefers not to say")
end
end
context "when Sales form" do
let(:sales_log) { FactoryBot.create(:sales_log, :completed, ethnic_group: 17) }
let(:question) { sales_log.form.get_question("ethnic_group", sales_log) }
it "returns the inferred label value" do
expect(question.answer_label(sales_log)).to eq("Prefers not to say")
end
end
end
end end
describe ".completed?" do describe ".completed?" do

33
spec/models/form/sales/pages/buyer1_ethnic_background_arab_spec.rb

@ -0,0 +1,33 @@
require "rails_helper"
RSpec.describe Form::Sales::Pages::Buyer1EthnicBackgroundArab, type: :model do
subject(:page) { described_class.new(page_id, page_definition, subsection) }
let(:page_id) { nil }
let(:page_definition) { nil }
let(:subsection) { instance_double(Form::Subsection) }
it "has correct subsection" do
expect(page.subsection).to eq(subsection)
end
it "has correct questions" do
expect(page.questions.map(&:id)).to eq(%w[ethnic])
end
it "has the correct id" do
expect(page.id).to eq("buyer_1_ethnic_background_arab")
end
it "has the correct header" do
expect(page.header).to eq("")
end
it "has the correct description" do
expect(page.description).to eq("")
end
it "has correct depends_on" do
expect(page.depends_on).to eq([{ "ethnic_group" => 4 }])
end
end

33
spec/models/form/sales/pages/buyer1_ethnic_background_asian_spec.rb

@ -0,0 +1,33 @@
require "rails_helper"
RSpec.describe Form::Sales::Pages::Buyer1EthnicBackgroundAsian, type: :model do
subject(:page) { described_class.new(page_id, page_definition, subsection) }
let(:page_id) { nil }
let(:page_definition) { nil }
let(:subsection) { instance_double(Form::Subsection) }
it "has correct subsection" do
expect(page.subsection).to eq(subsection)
end
it "has correct questions" do
expect(page.questions.map(&:id)).to eq(%w[ethnic])
end
it "has the correct id" do
expect(page.id).to eq("buyer_1_ethnic_background_asian")
end
it "has the correct header" do
expect(page.header).to eq("")
end
it "has the correct description" do
expect(page.description).to eq("")
end
it "has correct depends_on" do
expect(page.depends_on).to eq([{ "ethnic_group" => 2 }])
end
end

33
spec/models/form/sales/pages/buyer1_ethnic_background_black_spec.rb

@ -0,0 +1,33 @@
require "rails_helper"
RSpec.describe Form::Sales::Pages::Buyer1EthnicBackgroundBlack, type: :model do
subject(:page) { described_class.new(page_id, page_definition, subsection) }
let(:page_id) { nil }
let(:page_definition) { nil }
let(:subsection) { instance_double(Form::Subsection) }
it "has correct subsection" do
expect(page.subsection).to eq(subsection)
end
it "has correct questions" do
expect(page.questions.map(&:id)).to eq(%w[ethnic])
end
it "has the correct id" do
expect(page.id).to eq("buyer_1_ethnic_background_black")
end
it "has the correct header" do
expect(page.header).to eq("")
end
it "has the correct description" do
expect(page.description).to eq("")
end
it "has correct depends_on" do
expect(page.depends_on).to eq([{ "ethnic_group" => 3 }])
end
end

33
spec/models/form/sales/pages/buyer1_ethnic_background_mixed_spec.rb

@ -0,0 +1,33 @@
require "rails_helper"
RSpec.describe Form::Sales::Pages::Buyer1EthnicBackgroundMixed, type: :model do
subject(:page) { described_class.new(page_id, page_definition, subsection) }
let(:page_id) { nil }
let(:page_definition) { nil }
let(:subsection) { instance_double(Form::Subsection) }
it "has correct subsection" do
expect(page.subsection).to eq(subsection)
end
it "has correct questions" do
expect(page.questions.map(&:id)).to eq(%w[ethnic])
end
it "has the correct id" do
expect(page.id).to eq("buyer_1_ethnic_background_mixed")
end
it "has the correct header" do
expect(page.header).to eq("")
end
it "has the correct description" do
expect(page.description).to eq("")
end
it "has correct depends_on" do
expect(page.depends_on).to eq([{ "ethnic_group" => 1 }])
end
end

29
spec/models/form/sales/pages/buyer1_ethnic_background_white_spec.rb

@ -0,0 +1,29 @@
require "rails_helper"
RSpec.describe Form::Sales::Pages::Buyer1EthnicBackgroundWhite, type: :model do
subject(:page) { described_class.new(page_id, page_definition, subsection) }
let(:page_id) { nil }
let(:page_definition) { nil }
let(:subsection) { instance_double(Form::Subsection) }
it "has correct subsection" do
expect(page.subsection).to eq(subsection)
end
it "has correct questions" do
expect(page.questions.map(&:id)).to eq(%w[ethnic])
end
it "has the correct id" do
expect(page.id).to eq("buyer_1_ethnic_background_white")
end
it "has the correct header" do
expect(page.header).to eq("")
end
it "has the correct description" do
expect(page.description).to eq("")
end
end

33
spec/models/form/sales/pages/buyer1_ethnic_group_spec.rb

@ -0,0 +1,33 @@
require "rails_helper"
RSpec.describe Form::Sales::Pages::Buyer1EthnicGroup, type: :model do
subject(:page) { described_class.new(page_id, page_definition, subsection) }
let(:page_id) { nil }
let(:page_definition) { nil }
let(:subsection) { instance_double(Form::Subsection) }
it "has correct subsection" do
expect(page.subsection).to eq(subsection)
end
it "has correct questions" do
expect(page.questions.map(&:id)).to eq(%w[ethnic_group])
end
it "has the correct id" do
expect(page.id).to eq("buyer_1_ethnic_group")
end
it "has the correct header" do
expect(page.header).to eq("")
end
it "has the correct description" do
expect(page.description).to eq("")
end
it "has correct depends_on" do
expect(page.depends_on).to be_nil
end
end

25
spec/models/form/sales/pages/buyer1_working_situation_spec.rb

@ -0,0 +1,25 @@
require "rails_helper"
RSpec.describe Form::Sales::Pages::Buyer1WorkingSituation, type: :model do
subject(:page) { described_class.new(page_id, page_definition, subsection) }
let(:page_id) { nil }
let(:page_definition) { nil }
let(:subsection) { instance_double(Form::Subsection) }
it "has correct subsection" do
expect(page.subsection).to eq(subsection)
end
it "has correct questions" do
expect(page.questions.map(&:id)).to eq(%w[ecstat1])
end
it "has the correct id" do
expect(page.id).to eq("buyer_1_working_situation")
end
it "has the correct header" do
expect(page.header).to eq("Which of these best describes buyer 1's working situation?")
end
end

29
spec/models/form/sales/pages/buyer2_live_in_property_spec.rb

@ -0,0 +1,29 @@
require "rails_helper"
RSpec.describe Form::Sales::Pages::Buyer2LiveInProperty, type: :model do
subject(:page) { described_class.new(page_id, page_definition, subsection) }
let(:page_id) { nil }
let(:page_definition) { nil }
let(:subsection) { instance_double(Form::Subsection) }
it "has correct subsection" do
expect(page.subsection).to eq(subsection)
end
it "has correct questions" do
expect(page.questions.map(&:id)).to eq(%w[buy2livein])
end
it "has the correct id" do
expect(page.id).to eq("buyer_2_live_in_property")
end
it "has the correct header" do
expect(page.header).to eq("")
end
it "has the correct description" do
expect(page.description).to eq("")
end
end

29
spec/models/form/sales/pages/buyer2_working_situation_spec.rb

@ -0,0 +1,29 @@
require "rails_helper"
RSpec.describe Form::Sales::Pages::Buyer2WorkingSituation, type: :model do
subject(:page) { described_class.new(page_id, page_definition, subsection) }
let(:page_id) { nil }
let(:page_definition) { nil }
let(:subsection) { instance_double(Form::Subsection) }
it "has correct subsection" do
expect(page.subsection).to eq(subsection)
end
it "has correct questions" do
expect(page.questions.map(&:id)).to eq(%w[ecstat2])
end
it "has the correct id" do
expect(page.id).to eq("buyer_2_working_situation")
end
it "has the correct header" do
expect(page.header).to eq("")
end
it "has the correct description" do
expect(page.description).to eq("")
end
end

29
spec/models/form/sales/pages/buyer_company_spec.rb

@ -0,0 +1,29 @@
require "rails_helper"
RSpec.describe Form::Sales::Pages::BuyerCompany, type: :model do
subject(:page) { described_class.new(page_id, page_definition, subsection) }
let(:page_id) { nil }
let(:page_definition) { nil }
let(:subsection) { instance_double(Form::Subsection) }
it "has correct subsection" do
expect(page.subsection).to eq(subsection)
end
it "has correct questions" do
expect(page.questions.map(&:id)).to eq(%w[companybuy])
end
it "has the correct id" do
expect(page.id).to eq("buyer_company")
end
it "has the correct header" do
expect(page.header).to eq("")
end
it "has the correct description" do
expect(page.description).to eq("")
end
end

29
spec/models/form/sales/pages/buyer_interview_spec.rb

@ -0,0 +1,29 @@
require "rails_helper"
RSpec.describe Form::Sales::Pages::BuyerInterview, type: :model do
subject(:page) { described_class.new(page_id, page_definition, subsection) }
let(:page_id) { nil }
let(:page_definition) { nil }
let(:subsection) { instance_double(Form::Subsection) }
it "has correct subsection" do
expect(page.subsection).to eq(subsection)
end
it "has correct questions" do
expect(page.questions.map(&:id)).to eq(%w[noint])
end
it "has the correct id" do
expect(page.id).to eq("buyer_interview")
end
it "has the correct header" do
expect(page.header).to eq("")
end
it "has the correct description" do
expect(page.description).to eq("")
end
end

35
spec/models/form/sales/pages/gender_identity2_spec.rb

@ -0,0 +1,35 @@
require "rails_helper"
RSpec.describe Form::Sales::Pages::GenderIdentity2, type: :model do
subject(:page) { described_class.new(page_id, page_definition, subsection) }
let(:page_id) { nil }
let(:page_definition) { nil }
let(:subsection) { instance_double(Form::Subsection) }
it "has correct subsection" do
expect(page.subsection).to eq(subsection)
end
it "has correct questions" do
expect(page.questions.map(&:id)).to eq(%w[sex2])
end
it "has the correct id" do
expect(page.id).to eq("buyer_2_gender_identity")
end
it "has the correct header" do
expect(page.header).to eq("")
end
it "has the correct description" do
expect(page.description).to eq("")
end
it "has correct depends_on" do
expect(page.depends_on).to eq([{
"jointpur" => 1,
}])
end
end

33
spec/models/form/sales/pages/nationality1_spec.rb

@ -0,0 +1,33 @@
require "rails_helper"
RSpec.describe Form::Sales::Pages::Nationality1, type: :model do
subject(:page) { described_class.new(page_id, page_definition, subsection) }
let(:page_id) { nil }
let(:page_definition) { nil }
let(:subsection) { instance_double(Form::Subsection) }
it "has correct subsection" do
expect(page.subsection).to eq(subsection)
end
it "has correct questions" do
expect(page.questions.map(&:id)).to eq(%w[national othernational])
end
it "has the correct id" do
expect(page.id).to eq("buyer_1_nationality")
end
it "has the correct header" do
expect(page.header).to eq("")
end
it "has the correct description" do
expect(page.description).to eq("")
end
it "has correct depends_on" do
expect(page.depends_on).to be_nil
end
end

33
spec/models/form/sales/pages/privacy_notice_spec.rb

@ -0,0 +1,33 @@
require "rails_helper"
RSpec.describe Form::Sales::Pages::PrivacyNotice, type: :model do
subject(:page) { described_class.new(page_id, page_definition, subsection) }
let(:page_id) { nil }
let(:page_definition) { nil }
let(:subsection) { instance_double(Form::Subsection) }
it "has correct subsection" do
expect(page.subsection).to eq(subsection)
end
it "has correct questions" do
expect(page.questions.map(&:id)).to eq(%w[privacynotice])
end
it "has the correct id" do
expect(page.id).to eq("privacy_notice")
end
it "has the correct header" do
expect(page.header).to eq("Department for Levelling Up, Housing and Communities privacy notice")
end
it "has the correct description" do
expect(page.description).to eq("")
end
it "has correct depends_on" do
expect(page.depends_on).to eq([{ "noint" => 1 }])
end
end

44
spec/models/form/sales/questions/buyer1_ethnic_background_arab_spec.rb

@ -0,0 +1,44 @@
require "rails_helper"
RSpec.describe Form::Sales::Questions::Buyer1EthnicBackgroundArab, type: :model do
subject(:question) { described_class.new(question_id, question_definition, page) }
let(:question_id) { nil }
let(:question_definition) { nil }
let(:page) { instance_double(Form::Page) }
it "has correct page" do
expect(question.page).to eq(page)
end
it "has the correct id" do
expect(question.id).to eq("ethnic")
end
it "has the correct header" do
expect(question.header).to eq("Which of the following best describes the buyer 1’s Arab background?")
end
it "has the correct check_answer_label" do
expect(question.check_answer_label).to eq("Buyer 1’s ethnic background")
end
it "has the correct type" do
expect(question.type).to eq("radio")
end
it "is not marked as derived" do
expect(question.derived?).to be false
end
it "has the correct hint_text" do
expect(question.hint_text).to eq("Buyer 1 is the person in the household who does the most paid work. If it’s a joint purchase and the buyers do the same amount of paid work, buyer 1 is whoever is the oldest.")
end
it "has the correct answer_options" do
expect(question.answer_options).to eq({
"16" => { "value" => "Other ethnic group" },
"19" => { "value" => "Arab" },
})
end
end

47
spec/models/form/sales/questions/buyer1_ethnic_background_asian_spec.rb

@ -0,0 +1,47 @@
require "rails_helper"
RSpec.describe Form::Sales::Questions::Buyer1EthnicBackgroundAsian, type: :model do
subject(:question) { described_class.new(question_id, question_definition, page) }
let(:question_id) { nil }
let(:question_definition) { nil }
let(:page) { instance_double(Form::Page) }
it "has correct page" do
expect(question.page).to eq(page)
end
it "has the correct id" do
expect(question.id).to eq("ethnic")
end
it "has the correct header" do
expect(question.header).to eq("Which of the following best describes the buyer 1’s Asian or Asian British background?")
end
it "has the correct check_answer_label" do
expect(question.check_answer_label).to eq("Buyer 1’s ethnic background")
end
it "has the correct type" do
expect(question.type).to eq("radio")
end
it "is not marked as derived" do
expect(question.derived?).to be false
end
it "has the correct hint_text" do
expect(question.hint_text).to eq("Buyer 1 is the person in the household who does the most paid work. If it’s a joint purchase and the buyers do the same amount of paid work, buyer 1 is whoever is the oldest.")
end
it "has the correct answer_options" do
expect(question.answer_options).to eq({
"10" => { "value" => "Bangladeshi" },
"11" => { "value" => "Any other Asian or Asian British background" },
"15" => { "value" => "Chinese" },
"8" => { "value" => "Indian" },
"9" => { "value" => "Pakistani" },
})
end
end

45
spec/models/form/sales/questions/buyer1_ethnic_background_black_spec.rb

@ -0,0 +1,45 @@
require "rails_helper"
RSpec.describe Form::Sales::Questions::Buyer1EthnicBackgroundBlack, type: :model do
subject(:question) { described_class.new(question_id, question_definition, page) }
let(:question_id) { nil }
let(:question_definition) { nil }
let(:page) { instance_double(Form::Page) }
it "has correct page" do
expect(question.page).to eq(page)
end
it "has the correct id" do
expect(question.id).to eq("ethnic")
end
it "has the correct header" do
expect(question.header).to eq("Which of the following best describes the buyer 1’s Black, African, Caribbean or Black British background?")
end
it "has the correct check_answer_label" do
expect(question.check_answer_label).to eq("Buyer 1’s ethnic background")
end
it "has the correct type" do
expect(question.type).to eq("radio")
end
it "is not marked as derived" do
expect(question.derived?).to be false
end
it "has the correct hint_text" do
expect(question.hint_text).to eq("Buyer 1 is the person in the household who does the most paid work. If it’s a joint purchase and the buyers do the same amount of paid work, buyer 1 is whoever is the oldest.")
end
it "has the correct answer_options" do
expect(question.answer_options).to eq({
"12" => { "value" => "Caribbean" },
"13" => { "value" => "African" },
"14" => { "value" => "Any other Black, African or Caribbean background" },
})
end
end

46
spec/models/form/sales/questions/buyer1_ethnic_background_mixed_spec.rb

@ -0,0 +1,46 @@
require "rails_helper"
RSpec.describe Form::Sales::Questions::Buyer1EthnicBackgroundMixed, type: :model do
subject(:question) { described_class.new(question_id, question_definition, page) }
let(:question_id) { nil }
let(:question_definition) { nil }
let(:page) { instance_double(Form::Page) }
it "has correct page" do
expect(question.page).to eq(page)
end
it "has the correct id" do
expect(question.id).to eq("ethnic")
end
it "has the correct header" do
expect(question.header).to eq("Which of the following best describes the buyer 1’s Mixed or Multiple ethnic groups background?")
end
it "has the correct check_answer_label" do
expect(question.check_answer_label).to eq("Buyer 1’s ethnic background")
end
it "has the correct type" do
expect(question.type).to eq("radio")
end
it "is not marked as derived" do
expect(question.derived?).to be false
end
it "has the correct hint_text" do
expect(question.hint_text).to eq("Buyer 1 is the person in the household who does the most paid work. If it’s a joint purchase and the buyers do the same amount of paid work, buyer 1 is whoever is the oldest.")
end
it "has the correct answer_options" do
expect(question.answer_options).to eq({
"4" => { "value" => "White and Black Caribbean" },
"5" => { "value" => "White and Black African" },
"6" => { "value" => "White and Asian" },
"7" => { "value" => "Any other Mixed or Multiple ethnic background" },
})
end
end

46
spec/models/form/sales/questions/buyer1_ethnic_background_white_spec.rb

@ -0,0 +1,46 @@
require "rails_helper"
RSpec.describe Form::Sales::Questions::Buyer1EthnicBackgroundWhite, type: :model do
subject(:question) { described_class.new(question_id, question_definition, page) }
let(:question_id) { nil }
let(:question_definition) { nil }
let(:page) { instance_double(Form::Page) }
it "has correct page" do
expect(question.page).to eq(page)
end
it "has the correct id" do
expect(question.id).to eq("ethnic")
end
it "has the correct header" do
expect(question.header).to eq("Which of the following best describes the buyer 1’s White background?")
end
it "has the correct check_answer_label" do
expect(question.check_answer_label).to eq("Buyer 1’s ethnic background")
end
it "has the correct type" do
expect(question.type).to eq("radio")
end
it "is not marked as derived" do
expect(question.derived?).to be false
end
it "has the correct hint_text" do
expect(question.hint_text).to eq("Buyer 1 is the person in the household who does the most paid work. If it’s a joint purchase and the buyers do the same amount of paid work, buyer 1 is whoever is the oldest.")
end
it "has the correct answer_options" do
expect(question.answer_options).to eq({
"1" => { "value" => "English, Welsh, Northern Irish, Scottish or British" },
"18" => { "value" => "Gypsy or Irish Traveller" },
"2" => { "value" => "Irish" },
"3" => { "value" => "Any other White background" },
})
end
end

49
spec/models/form/sales/questions/buyer1_ethnic_group_spec.rb

@ -0,0 +1,49 @@
require "rails_helper"
RSpec.describe Form::Sales::Questions::Buyer1EthnicGroup, type: :model do
subject(:question) { described_class.new(question_id, question_definition, page) }
let(:question_id) { nil }
let(:question_definition) { nil }
let(:page) { instance_double(Form::Page) }
it "has correct page" do
expect(question.page).to eq(page)
end
it "has the correct id" do
expect(question.id).to eq("ethnic_group")
end
it "has the correct header" do
expect(question.header).to eq("What is buyer 1’s ethnic group?")
end
it "has the correct check_answer_label" do
expect(question.check_answer_label).to eq("Buyer 1’s ethnic group")
end
it "has the correct type" do
expect(question.type).to eq("radio")
end
it "is not marked as derived" do
expect(question.derived?).to be false
end
it "has the correct hint_text" do
expect(question.hint_text).to eq("Buyer 1 is the person in the household who does the most paid work. If it’s a joint purchase and the buyers do the same amount of paid work, buyer 1 is whoever is the oldest.")
end
it "has the correct answer_options" do
expect(question.answer_options).to eq({
"0" => { "value" => "White" },
"1" => { "value" => "Mixed or Multiple ethnic groups" },
"17" => { "value" => "Buyer 1 prefers not to say" },
"2" => { "value" => "Asian or Asian British" },
"3" => { "value" => "Black, African, Caribbean or Black British" },
"4" => { "value" => "Arab or other ethnic group" },
"divider" => { "value" => true },
})
end
end

49
spec/models/form/sales/questions/buyer1_working_situation_spec.rb

@ -0,0 +1,49 @@
require "rails_helper"
RSpec.describe Form::Sales::Questions::Buyer1WorkingSituation, type: :model do
subject(:question) { described_class.new(question_id, question_definition, page) }
let(:question_id) { nil }
let(:question_definition) { nil }
let(:page) { instance_double(Form::Page) }
it "has correct page" do
expect(question.page).to eq(page)
end
it "has the correct id" do
expect(question.id).to eq("ecstat1")
end
it "has the correct header" do
expect(question.header).to eq("Which of these best describes buyer 1's working situation?")
end
it "has the correct check_answer_label" do
expect(question.check_answer_label).to eq("Buyer 1's working situation")
end
it "has the correct type" do
expect(question.type).to eq("radio")
end
it "is not marked as derived" do
expect(question.derived?).to be false
end
it "has the correct answer_options" do
expect(question.answer_options).to eq({
"2" => { "value" => "Part-time - Less than 30 hours" },
"1" => { "value" => "Full-time - 30 hours or more" },
"3" => { "value" => "In government training into work, such as New Deal" },
"4" => { "value" => "Jobseeker" },
"6" => { "value" => "Not seeking work" },
"8" => { "value" => "Unable to work due to long term sick or disability" },
"5" => { "value" => "Retired" },
"0" => { "value" => "Other" },
"10" => { "value" => "Buyer prefers not to say" },
"7" => { "value" => "Full-time student" },
"9" => { "value" => "Child under 16" },
})
end
end

44
spec/models/form/sales/questions/buyer2_live_in_property_spec.rb

@ -0,0 +1,44 @@
require "rails_helper"
RSpec.describe Form::Sales::Questions::Buyer2LiveInProperty, type: :model do
subject(:question) { described_class.new(question_id, question_definition, page) }
let(:question_id) { nil }
let(:question_definition) { nil }
let(:page) { instance_double(Form::Page) }
it "has correct page" do
expect(question.page).to eq(page)
end
it "has the correct id" do
expect(question.id).to eq("buy2livein")
end
it "has the correct header" do
expect(question.header).to eq("Will buyer 2 live in the property?")
end
it "has the correct check_answer_label" do
expect(question.check_answer_label).to eq("Will buyer 2 live in the property?")
end
it "has the correct type" do
expect(question.type).to eq("radio")
end
it "is not marked as derived" do
expect(question.derived?).to be false
end
it "has the correct hint" do
expect(question.hint_text).to eq("")
end
it "has the correct answer_options" do
expect(question.answer_options).to eq({
"1" => { "value" => "Yes" },
"2" => { "value" => "No" },
})
end
end

53
spec/models/form/sales/questions/buyer2_working_situation_spec.rb

@ -0,0 +1,53 @@
require "rails_helper"
RSpec.describe Form::Sales::Questions::Buyer2WorkingSituation, type: :model do
subject(:question) { described_class.new(question_id, question_definition, page) }
let(:question_id) { nil }
let(:question_definition) { nil }
let(:page) { instance_double(Form::Page) }
it "has correct page" do
expect(question.page).to eq(page)
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 buyer 2's working situation?")
end
it "has the correct check_answer_label" do
expect(question.check_answer_label).to eq("Buyer 2's working situation")
end
it "has the correct type" do
expect(question.type).to eq("radio")
end
it "is not marked as derived" do
expect(question.derived?).to be false
end
it "has the correct hint" do
expect(question.hint_text).to eq("")
end
it "has the correct answer_options" do
expect(question.answer_options).to eq({
"2" => { "value" => "Part-time - Less than 30 hours" },
"1" => { "value" => "Full-time - 30 hours or more" },
"3" => { "value" => "In government training into work, such as New Deal" },
"4" => { "value" => "Jobseeker" },
"6" => { "value" => "Not seeking work" },
"8" => { "value" => "Unable to work due to long term sick or disability" },
"5" => { "value" => "Retired" },
"0" => { "value" => "Other" },
"10" => { "value" => "Buyer prefers not to say" },
"7" => { "value" => "Full-time student" },
"9" => { "value" => "Child under 16" },
})
end
end

40
spec/models/form/sales/questions/buyer_company_spec.rb

@ -0,0 +1,40 @@
require "rails_helper"
RSpec.describe Form::Sales::Questions::BuyerCompany, type: :model do
subject(:question) { described_class.new(question_id, question_definition, page) }
let(:question_id) { nil }
let(:question_definition) { nil }
let(:page) { instance_double(Form::Page) }
it "has correct page" do
expect(question.page).to eq(page)
end
it "has the correct id" do
expect(question.id).to eq("companybuy")
end
it "has the correct header" do
expect(question.header).to eq("Is the buyer a company?")
end
it "has the correct type" do
expect(question.type).to eq("radio")
end
it "is not marked as derived" do
expect(question.derived?).to be false
end
it "has the correct hint_text" do
expect(question.hint_text).to eq("")
end
it "has the correct answer_options" do
expect(question.answer_options).to eq({
"1" => { "value" => "Yes" },
"2" => { "value" => "No" },
})
end
end

44
spec/models/form/sales/questions/buyer_interview_spec.rb

@ -0,0 +1,44 @@
require "rails_helper"
RSpec.describe Form::Sales::Questions::BuyerInterview, type: :model do
subject(:question) { described_class.new(question_id, question_definition, page) }
let(:question_id) { nil }
let(:question_definition) { nil }
let(:page) { instance_double(Form::Page) }
it "has correct page" do
expect(question.page).to eq(page)
end
it "has the correct id" do
expect(question.id).to eq("noint")
end
it "has the correct header" do
expect(question.header).to eq("Was the buyer interviewed for any of the answers you will provide on this log?")
end
it "has the correct check_answer_label" do
expect(question.check_answer_label).to eq("Buyer interviewed in person?")
end
it "has the correct type" do
expect(question.type).to eq("radio")
end
it "is not marked as derived" do
expect(question.derived?).to be false
end
it "has the correct hint" do
expect(question.hint_text).to eq("You should still try to answer all questions even if the buyer wasn't interviewed in person")
end
it "has the correct answer_options" do
expect(question.answer_options).to eq({
"1" => { "value" => "No" },
"2" => { "value" => "Yes" },
})
end
end

42
spec/models/form/sales/questions/gender_identity2_spec.rb

@ -0,0 +1,42 @@
require "rails_helper"
RSpec.describe Form::Sales::Questions::GenderIdentity2, type: :model do
subject(:question) { described_class.new(question_id, question_definition, page) }
let(:question_id) { nil }
let(:question_definition) { nil }
let(:page) { instance_double(Form::Page) }
it "has correct page" do
expect(question.page).to eq(page)
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 buyer 2’s gender identity?")
end
it "has the correct check_answer_label" do
expect(question.check_answer_label).to eq("Buyer 2’s gender identity")
end
it "has the correct type" do
expect(question.type).to eq("radio")
end
it "is not marked as derived" do
expect(question.derived?).to be false
end
it "has the correct answer_options" do
expect(question.answer_options).to eq({
"F" => { "value" => "Female" },
"M" => { "value" => "Male" },
"X" => { "value" => "Non-binary" },
"R" => { "value" => "Buyer prefers not to say" },
})
end
end

63
spec/models/form/sales/questions/nationality1_spec.rb

@ -0,0 +1,63 @@
require "rails_helper"
RSpec.describe Form::Sales::Questions::Nationality1, type: :model do
subject(:question) { described_class.new(question_id, question_definition, page) }
let(:question_id) { nil }
let(:question_definition) { nil }
let(:page) { instance_double(Form::Page) }
it "has correct page" do
expect(question.page).to eq(page)
end
it "has the correct id" do
expect(question.id).to eq("national")
end
it "has the correct header" do
expect(question.header).to eq("What is buyer 1’s nationality?")
end
it "has the correct check_answer_label" do
expect(question.check_answer_label).to eq("Buyer 1’s nationality")
end
it "has the correct type" do
expect(question.type).to eq("radio")
end
it "is not marked as derived" do
expect(question.derived?).to be false
end
it "has the correct hint" do
expect(question.hint_text).to eq("Buyer 1 is the person in the household who does the most paid work. If it’s a joint purchase and the buyers do the same amount of paid work, buyer 1 is whoever is the oldest.")
end
it "has the correct answer_options" do
expect(question.answer_options).to eq({
"18" => { "value" => "United Kingdom" },
"17" => { "value" => "Republic of Ireland" },
"19" => { "value" => "European Economic Area (EEA), excluding ROI" },
"12" => { "value" => "Other" },
"13" => { "value" => "Buyer prefers not to say" },
})
end
it "has correct conditional for" do
expect(question.conditional_for).to eq({
"othernational" => [12],
})
end
it "has correct hidden in check answers" do
expect(question.hidden_in_check_answers).to eq({
"depends_on" => [
{
"national" => 12,
},
],
})
end
end

37
spec/models/form/sales/questions/other_nationality1_spec.rb

@ -0,0 +1,37 @@
require "rails_helper"
RSpec.describe Form::Sales::Questions::OtherNationality1, type: :model do
subject(:question) { described_class.new(question_id, question_definition, page) }
let(:question_id) { nil }
let(:question_definition) { nil }
let(:page) { instance_double(Form::Page) }
it "has correct page" do
expect(question.page).to eq(page)
end
it "has the correct id" do
expect(question.id).to eq("othernational")
end
it "has the correct header" do
expect(question.header).to eq("Nationality")
end
it "has the correct check_answer_label" do
expect(question.check_answer_label).to eq("Buyer 1’s nationality")
end
it "has the correct type" do
expect(question.type).to eq("text")
end
it "is not marked as derived" do
expect(question.derived?).to be false
end
it "has the correct hint" do
expect(question.hint_text).to be_nil
end
end

43
spec/models/form/sales/questions/privacy_notice_spec.rb

@ -0,0 +1,43 @@
require "rails_helper"
RSpec.describe Form::Sales::Questions::PrivacyNotice, type: :model do
subject(:question) { described_class.new(question_id, question_definition, page) }
let(:question_id) { nil }
let(:question_definition) { nil }
let(:page) { instance_double(Form::Page) }
it "has correct page" do
expect(question.page).to eq(page)
end
it "has the correct id" do
expect(question.id).to eq("privacynotice")
end
it "has the correct header" do
expect(question.header).to eq("Declaration")
end
it "has the correct check_answer_label" do
expect(question.check_answer_label).to eq("Buyer has seen the privacy notice?")
end
it "has the correct type" do
expect(question.type).to eq("checkbox")
end
it "is not marked as derived" do
expect(question.derived?).to be false
end
it "has the correct hint" do
expect(question.hint_text).to eq("")
end
it "has the correct answer_options" do
expect(question.answer_options).to eq({
"privacynotice" => { "value" => "The buyer has seen the DLUHC privacy notice" },
})
end
end

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

@ -13,7 +13,26 @@ RSpec.describe Form::Sales::Subsections::HouseholdCharacteristics, type: :model
it "has correct pages" do it "has correct pages" do
expect(household_characteristics.pages.map(&:id)).to eq( expect(household_characteristics.pages.map(&:id)).to eq(
%w[buyer_1_age buyer_1_gender_identity buyer_1_live_in_property buyer_2_relationship_to_buyer_1 buyer_2_age], %w[
buyer_interview
privacy_notice
buyer_1_age
buyer_1_gender_identity
buyer_1_ethnic_group
buyer_1_ethnic_background_black
buyer_1_ethnic_background_asian
buyer_1_ethnic_background_arab
buyer_1_ethnic_background_mixed
buyer_1_ethnic_background_white
buyer_1_nationality
buyer_1_working_situation
buyer_1_live_in_property
buyer_2_relationship_to_buyer_1
buyer_2_age
buyer_2_gender_identity
buyer_2_working_situation
buyer_2_live_in_property
],
) )
end end

2
spec/models/form/sales/subsections/setup_spec.rb

@ -13,7 +13,7 @@ RSpec.describe Form::Sales::Subsections::Setup, type: :model do
it "has correct pages" do it "has correct pages" do
expect(setup.pages.map(&:id)).to eq( expect(setup.pages.map(&:id)).to eq(
%w[organisation created_by completion_date purchaser_code ownership_scheme shared_ownership_type discounted_ownership_type outright_ownership_type buyer_live joint_purchase number_joint_buyers builtype], %w[organisation created_by completion_date purchaser_code ownership_scheme shared_ownership_type discounted_ownership_type outright_ownership_type buyer_company buyer_live joint_purchase number_joint_buyers builtype],
) )
end end

4
spec/models/form_handler_spec.rb

@ -61,14 +61,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(19) expect(form.pages.count).to eq(33)
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(19) expect(form.pages.count).to eq(33)
expect(form.name).to eq("2021_2022_sales") expect(form.name).to eq("2021_2022_sales")
end end
end end

4
spec/models/form_spec.rb

@ -218,9 +218,9 @@ RSpec.describe Form, type: :model do
expect(form.sections[0].class).to eq(Form::Sales::Sections::Setup) expect(form.sections[0].class).to eq(Form::Sales::Sections::Setup)
expect(form.subsections.count).to eq(1) expect(form.subsections.count).to eq(1)
expect(form.subsections.first.id).to eq("setup") expect(form.subsections.first.id).to eq("setup")
expect(form.pages.count).to eq(12) expect(form.pages.count).to eq(13)
expect(form.pages.first.id).to eq("organisation") expect(form.pages.first.id).to eq("organisation")
expect(form.questions.count).to eq(13) expect(form.questions.count).to eq(14)
expect(form.questions.first.id).to eq("owning_organisation_id") expect(form.questions.first.id).to eq("owning_organisation_id")
expect(form.start_date).to eq(Time.zone.parse("2022-04-01")) expect(form.start_date).to eq(Time.zone.parse("2022-04-01"))
expect(form.end_date).to eq(Time.zone.parse("2023-07-01")) expect(form.end_date).to eq(Time.zone.parse("2023-07-01"))

3
spec/models/lettings_log_spec.rb

@ -1,4 +1,5 @@
require "rails_helper" require "rails_helper"
require "shared/shared_examples_for_derived_fields"
RSpec.describe LettingsLog do RSpec.describe LettingsLog do
let(:owning_organisation) { FactoryBot.create(:organisation) } let(:owning_organisation) { FactoryBot.create(:organisation) }
@ -10,6 +11,8 @@ RSpec.describe LettingsLog do
allow(FormHandler.instance).to receive(:current_lettings_form).and_return(fake_2021_2022_form) allow(FormHandler.instance).to receive(:current_lettings_form).and_return(fake_2021_2022_form)
end end
include_examples "shared examples for derived fields", :lettings_log
it "inherits from log" do it "inherits from log" do
expect(described_class).to be < Log expect(described_class).to be < Log
expect(described_class).to be < ApplicationRecord expect(described_class).to be < ApplicationRecord

3
spec/models/sales_log_spec.rb

@ -1,9 +1,12 @@
require "rails_helper" require "rails_helper"
require "shared/shared_examples_for_derived_fields"
RSpec.describe SalesLog, type: :model do RSpec.describe SalesLog, type: :model do
let(:owning_organisation) { FactoryBot.create(:organisation) } let(:owning_organisation) { FactoryBot.create(:organisation) }
let(:created_by_user) { FactoryBot.create(:user) } let(:created_by_user) { FactoryBot.create(:user) }
include_examples "shared examples for derived fields", :sales_log
it "inherits from log" do it "inherits from log" do
expect(described_class).to be < Log expect(described_class).to be < Log
expect(described_class).to be < ApplicationRecord expect(described_class).to be < ApplicationRecord

17
spec/shared/shared_examples_for_derived_fields.rb

@ -0,0 +1,17 @@
require "rails_helper"
RSpec.shared_examples "shared examples for derived fields" do |log_type|
describe "sets ethnic based on the value of ethnic_refused" do
it "is set to 17 when ethnic_group is 17" do
log = FactoryBot.build(log_type, ethnic_group: 17, ethnic: nil)
expect { log.set_derived_fields! }.to change(log, :ethnic).from(nil).to(17)
end
it "is is not modified otherwise" do
log = FactoryBot.build(log_type, ethnic_group: nil, ethnic: nil)
expect { log.set_derived_fields! }.not_to change(log, :ethnic)
end
end
end
Loading…
Cancel
Save