Browse Source

Merge branch 'main' into CLDC-1222-improve-case-log-import-performance

CLDC-1222-improve-case-log-import-performance
Mo Seedat 3 years ago
parent
commit
0f8abd935d
  1. 36
      app/controllers/locations_controller.rb
  2. 6
      app/helpers/check_answers_helper.rb
  3. 13
      app/helpers/tab_nav_helper.rb
  4. 5
      app/models/derived_variables/sales_log_variables.rb
  5. 6
      app/models/form/question.rb
  6. 19
      app/models/form/sales/pages/age2.rb
  7. 15
      app/models/form/sales/pages/building_type.rb
  8. 18
      app/models/form/sales/pages/buyer1_ethnic_background_arab.rb
  9. 18
      app/models/form/sales/pages/buyer1_ethnic_background_asian.rb
  10. 18
      app/models/form/sales/pages/buyer1_ethnic_background_black.rb
  11. 18
      app/models/form/sales/pages/buyer1_ethnic_background_mixed.rb
  12. 18
      app/models/form/sales/pages/buyer1_ethnic_background_white.rb
  13. 15
      app/models/form/sales/pages/buyer1_ethnic_group.rb
  14. 19
      app/models/form/sales/pages/buyer2_relationship_to_buyer1.rb
  15. 15
      app/models/form/sales/pages/buyer_company.rb
  16. 15
      app/models/form/sales/pages/buyer_interview.rb
  17. 18
      app/models/form/sales/pages/gender_identity2.rb
  18. 15
      app/models/form/sales/pages/property_unit_type.rb
  19. 11
      app/models/form/sales/questions/age2.rb
  20. 17
      app/models/form/sales/questions/building_type.rb
  21. 17
      app/models/form/sales/questions/buyer1_ethnic_background_arab.rb
  22. 20
      app/models/form/sales/questions/buyer1_ethnic_background_asian.rb
  23. 18
      app/models/form/sales/questions/buyer1_ethnic_background_black.rb
  24. 19
      app/models/form/sales/questions/buyer1_ethnic_background_mixed.rb
  25. 19
      app/models/form/sales/questions/buyer1_ethnic_background_white.rb
  26. 28
      app/models/form/sales/questions/buyer1_ethnic_group.rb
  27. 19
      app/models/form/sales/questions/buyer2_age_known.rb
  28. 29
      app/models/form/sales/questions/buyer2_relationship_to_buyer1.rb
  29. 17
      app/models/form/sales/questions/buyer_company.rb
  30. 17
      app/models/form/sales/questions/buyer_interview.rb
  31. 18
      app/models/form/sales/questions/gender_identity2.rb
  32. 10
      app/models/form/sales/questions/other_buyer2_relationship_to_buyer1.rb
  33. 19
      app/models/form/sales/questions/property_unit_type.rb
  34. 10
      app/models/form/sales/subsections/household_characteristics.rb
  35. 1
      app/models/form/sales/subsections/property_information.rb
  36. 2
      app/models/form/sales/subsections/setup.rb
  37. 4
      app/models/lettings_log.rb
  38. 4
      app/models/log.rb
  39. 5
      app/models/sales_log.rb
  40. 35
      app/views/locations/edit_local_authority.html.erb
  41. 4
      app/views/locations/index.html.erb
  42. 4
      app/views/logs/index.html.erb
  43. 7
      app/views/organisations/logs.html.erb
  44. 4
      app/views/schemes/check_answers.html.erb
  45. 585
      config/forms/2021_2022.json
  46. 589
      config/forms/2022_2023.json
  47. 16
      config/forms/schema/2021_2022.json
  48. 21
      config/forms/schema/generic.json
  49. 2
      config/initializers/sidekiq.rb
  50. 1
      config/locales/en.yml
  51. 4
      config/routes.rb
  52. 6
      db/migrate/20220927100350_add_background_to_sales_log.rb
  53. 5
      db/migrate/20220927144455_add_building_type_to_sales_log.rb
  54. 5
      db/migrate/20220928132657_add_prop_type_to_sales_log.rb
  55. 8
      db/migrate/20220929105157_add_buyer2_age_to_sales_log.rb
  56. 8
      db/migrate/20220929125204_add_buyer2_relationship_to_buyer1_column.rb
  57. 5
      db/migrate/20220930134358_add_buyer2_sex_to_sales_log.rb
  58. 7
      db/migrate/20221003092048_add_noint_to_sales_log.rb
  59. 12
      db/schema.rb
  60. 4
      manifest.yml
  61. 10
      spec/factories/sales_log.rb
  62. 37
      spec/features/organisation_spec.rb
  63. 1257
      spec/fixtures/forms/2021_2022.json
  64. 96
      spec/fixtures/forms/2022_2023.json
  65. 6
      spec/fixtures/forms/test_validator.json
  66. 2
      spec/helpers/tab_nav_helper_spec.rb
  67. 23
      spec/models/form/question_spec.rb
  68. 35
      spec/models/form/sales/pages/age2_spec.rb
  69. 29
      spec/models/form/sales/pages/building_type_spec.rb
  70. 33
      spec/models/form/sales/pages/buyer1_ethnic_background_arab_spec.rb
  71. 33
      spec/models/form/sales/pages/buyer1_ethnic_background_asian_spec.rb
  72. 33
      spec/models/form/sales/pages/buyer1_ethnic_background_black_spec.rb
  73. 33
      spec/models/form/sales/pages/buyer1_ethnic_background_mixed_spec.rb
  74. 29
      spec/models/form/sales/pages/buyer1_ethnic_background_white_spec.rb
  75. 33
      spec/models/form/sales/pages/buyer1_ethnic_group_spec.rb
  76. 33
      spec/models/form/sales/pages/buyer2_relationship_to_buyer1_spec.rb
  77. 29
      spec/models/form/sales/pages/buyer_company_spec.rb
  78. 29
      spec/models/form/sales/pages/buyer_interview_spec.rb
  79. 35
      spec/models/form/sales/pages/gender_identity2_spec.rb
  80. 29
      spec/models/form/sales/pages/property_unit_type_spec.rb
  81. 41
      spec/models/form/sales/questions/age2_spec.rb
  82. 44
      spec/models/form/sales/questions/building_type_spec.rb
  83. 44
      spec/models/form/sales/questions/buyer1_ethnic_background_arab_spec.rb
  84. 47
      spec/models/form/sales/questions/buyer1_ethnic_background_asian_spec.rb
  85. 45
      spec/models/form/sales/questions/buyer1_ethnic_background_black_spec.rb
  86. 46
      spec/models/form/sales/questions/buyer1_ethnic_background_mixed_spec.rb
  87. 46
      spec/models/form/sales/questions/buyer1_ethnic_background_white_spec.rb
  88. 49
      spec/models/form/sales/questions/buyer1_ethnic_group_spec.rb
  89. 46
      spec/models/form/sales/questions/buyer2_age_known_spec.rb
  90. 62
      spec/models/form/sales/questions/buyer2_relationship_to_buyer1_spec.rb
  91. 40
      spec/models/form/sales/questions/buyer_company_spec.rb
  92. 44
      spec/models/form/sales/questions/buyer_interview_spec.rb
  93. 42
      spec/models/form/sales/questions/gender_identity2_spec.rb
  94. 37
      spec/models/form/sales/questions/other_buyer2_relationship_to_buyer1_spec.rb
  95. 43
      spec/models/form/sales/questions/property_unit_type_spec.rb
  96. 16
      spec/models/form/sales/subsections/household_characteristics_spec.rb
  97. 2
      spec/models/form/sales/subsections/property_information_spec.rb
  98. 2
      spec/models/form/sales/subsections/setup_spec.rb
  99. 6
      spec/models/form_handler_spec.rb
  100. 4
      spec/models/form_spec.rb
  101. Some files were not shown because too many files have changed in this diff Show More

36
app/controllers/locations_controller.rb

@ -22,7 +22,9 @@ class LocationsController < ApplicationController
if date_params_missing?(location_params) || valid_date_params?(location_params)
@location = Location.new(location_params)
if @location.save
if location_params[:add_another_location] == "Yes"
if @location.location_admin_district.nil?
redirect_to(location_edit_local_authority_path(id: @scheme.id, location_id: @location.id, add_another_location: location_params[:add_another_location]))
elsif location_params[:add_another_location] == "Yes"
redirect_to new_location_path(@scheme)
else
check_answers_path = @scheme.confirmed? ? scheme_check_answers_path(@scheme, anchor: "locations") : scheme_check_answers_path(@scheme)
@ -47,16 +49,36 @@ class LocationsController < ApplicationController
render_not_found and return unless @location && @scheme
end
def edit_local_authority
render_not_found and return unless @location && @scheme
end
def update
render_not_found and return unless @location && @scheme
page = params[:location][:page]
if @location.update(location_params)
if page == "edit-local-authority" && !valid_location_admin_district?(location_params)
error_message = I18n.t("validations.location_admin_district")
@location.errors.add :location_admin_district, error_message
render :edit_local_authority, status: :unprocessable_entity
elsif @location.update(location_params)
case page
when "edit"
location_params[:add_another_location] == "Yes" ? redirect_to(new_location_path(@location.scheme)) : redirect_to(scheme_check_answers_path(@scheme, anchor: "locations"))
if @location.location_admin_district.nil?
redirect_to(location_edit_local_authority_path(id: @scheme.id, location_id: @location.id, add_another_location: location_params[:add_another_location]))
elsif location_params[:add_another_location] == "Yes"
redirect_to(new_location_path(@location.scheme))
else
redirect_to(scheme_check_answers_path(@scheme, anchor: "locations"))
end
when "edit-name"
redirect_to(scheme_check_answers_path(@scheme, anchor: "locations"))
when "edit-local-authority"
if params[:add_another_location] == "Yes"
redirect_to(new_location_path(@location.scheme))
else
redirect_to(scheme_check_answers_path(@scheme, anchor: "locations"))
end
end
else
render :edit, status: :unprocessable_entity
@ -95,13 +117,13 @@ private
end
def authenticate_action!
if %w[new edit update create index edit_name].include?(action_name) && !((current_user.organisation == @scheme&.owning_organisation) || current_user.support?)
if %w[new edit update create index edit_name edit_local_authority].include?(action_name) && !((current_user.organisation == @scheme&.owning_organisation) || current_user.support?)
render_not_found and return
end
end
def location_params
required_params = params.require(:location).permit(:postcode, :name, :units, :type_of_unit, :add_another_location, :startdate, :mobility_type).merge(scheme_id: @scheme.id)
required_params = params.require(:location).permit(:postcode, :name, :units, :type_of_unit, :add_another_location, :startdate, :mobility_type, :location_admin_district).merge(scheme_id: @scheme.id)
required_params[:postcode] = PostcodeService.clean(required_params[:postcode]) if required_params[:postcode]
required_params
end
@ -109,4 +131,8 @@ private
def search_term
params["search"]
end
def valid_location_admin_district?(location_params)
location_params["location_admin_district"] != "Select an option"
end
end

6
app/helpers/check_answers_helper.rb

@ -16,7 +16,7 @@ module CheckAnswersHelper
!scheme.confirmed? || editable_attributes.include?(attribute_name)
end
def get_location_change_link_href(scheme, location)
def get_location_change_link_href_postcode(scheme, location)
if location.confirmed?
location_edit_name_path(id: scheme.id, location_id: location.id)
else
@ -24,6 +24,10 @@ module CheckAnswersHelper
end
end
def get_location_change_link_href_location_admin_district(scheme, location)
location_edit_local_authority_path(id: scheme.id, location_id: location.id)
end
def any_questions_have_summary_card_number?(subsection, lettings_log)
subsection.applicable_questions(lettings_log).map(&:check_answers_card_number).compact.length.positive?
end

13
app/helpers/tab_nav_helper.rb

@ -6,11 +6,22 @@ module TabNavHelper
[govuk_link_to(link_text, user), "<span class=\"govuk-visually-hidden\">User </span><span class=\"govuk-!-font-weight-regular app-!-colour-muted\">#{user.email}</span>"].join("\n")
end
def location_cell(location, link)
def location_cell_postcode(location, link)
link_text = location.postcode
[govuk_link_to(link_text, link, method: :patch), "<span class=\"govuk-visually-hidden\">Location </span><span class=\"govuk-!-font-weight-regular app-!-colour-muted\">#{location.name}</span>"].join("\n")
end
def location_cell_location_admin_district(location, link)
la = location.location_admin_district
if location.confirmed?
la
elsif la
govuk_link_to(la, link, method: :patch)
else
govuk_link_to("Select local authority", link, method: :patch)
end
end
def scheme_cell(scheme)
link_text = scheme.service_name
link = scheme.confirmed? ? scheme : scheme_check_answers_path(scheme)

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 = [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 has_inferred_check_answers_value?(log)
return inferred if inferred.present?
answer_label
end
def get_inferred_answers(log)

19
app/models/form/sales/pages/age2.rb

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

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

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

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

19
app/models/form/sales/pages/buyer2_relationship_to_buyer1.rb

@ -0,0 +1,19 @@
class Form::Sales::Pages::Buyer2RelationshipToBuyer1 < ::Form::Page
def initialize(id, hsh, subsection)
super
@id = "buyer_2_relationship_to_buyer_1"
@header = ""
@description = ""
@subsection = subsection
@depends_on = [{
"jointpur" => 1,
}]
end
def questions
@questions ||= [
Form::Sales::Questions::Buyer2RelationshipToBuyer1.new(nil, nil, self),
Form::Sales::Questions::OtherBuyer2RelationshipToBuyer1.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

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

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

11
app/models/form/sales/questions/age2.rb

@ -0,0 +1,11 @@
class Form::Sales::Questions::Age2 < ::Form::Question
def initialize(id, hsh, page)
super
@id = "age2"
@check_answer_label = "Buyer 2’s age"
@header = "Age"
@type = "numeric"
@page = page
@width = 2
end
end

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

@ -0,0 +1,17 @@
class Form::Sales::Questions::BuildingType < ::Form::Question
def initialize(id, hsh, page)
super
@id = "builtype"
@check_answer_label = "Type of building"
@header = "What type of building is the property?"
@type = "radio"
@answer_options = ANSWER_OPTIONS
@page = page
@hint_text = ""
end
ANSWER_OPTIONS = {
"1" => { "value" => "Purpose built" },
"2" => { "value" => "Converted from previous residential or non-residential property" },
}.freeze
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

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

@ -0,0 +1,19 @@
class Form::Sales::Questions::Buyer2AgeKnown < ::Form::Question
def initialize(id, hsh, page)
super
@id = "age2_known"
@check_answer_label = "Buyer 2’s age"
@header = "Do you know buyer 2’s age?"
@type = "radio"
@answer_options = ANSWER_OPTIONS
@page = page
@conditional_for = {
"age2" => [0],
}
end
ANSWER_OPTIONS = {
"0" => { "value" => "Yes" },
"1" => { "value" => "No" },
}.freeze
end

29
app/models/form/sales/questions/buyer2_relationship_to_buyer1.rb

@ -0,0 +1,29 @@
class Form::Sales::Questions::Buyer2RelationshipToBuyer1 < ::Form::Question
def initialize(id, hsh, page)
super
@id = "relat2"
@check_answer_label = "Buyer 2's relationship to buyer 1"
@header = "What is buyer 2's relationship to buyer 1?"
@type = "radio"
@hint_text = ""
@page = page
@answer_options = ANSWER_OPTIONS
@conditional_for = {
"otherrelat2" => %w[X],
}
@hidden_in_check_answers = {
"depends_on" => [
{
"relat2" => "X",
},
],
}
end
ANSWER_OPTIONS = {
"P" => { "value" => "Parent" },
"C" => { "value" => "Child", "hint" => "Must be eligible for child benefit, aged under 16 or under 20 if still in full-time education." },
"X" => { "value" => "Other" },
"R" => { "value" => "Buyer prefers not to say" },
}.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

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

@ -0,0 +1,10 @@
class Form::Sales::Questions::OtherBuyer2RelationshipToBuyer1 < ::Form::Question
def initialize(id, hsh, page)
super
@id = "otherrelat2"
@check_answer_label = "Buyer 2's relationship to buyer 1"
@header = "Buyer 2's relationship to buyer 1"
@type = "text"
@page = page
end
end

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

@ -0,0 +1,19 @@
class Form::Sales::Questions::PropertyUnitType < ::Form::Question
def initialize(id, hsh, page)
super
@id = "proptype"
@check_answer_label = "Type of unit"
@header = "What type of unit is the property?"
@type = "radio"
@answer_options = ANSWER_OPTIONS
@page = page
end
ANSWER_OPTIONS = {
"1" => { "value" => "Flat or maisonette" },
"2" => { "value" => "Bedsit" },
"3" => { "value" => "House" },
"4" => { "value" => "Bungalow" },
"9" => { "value" => "Other" },
}.freeze
end

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

@ -9,9 +9,19 @@ class Form::Sales::Subsections::HouseholdCharacteristics < ::Form::Subsection
def pages
@pages ||= [
Form::Sales::Pages::BuyerInterview.new(nil, nil, self),
Form::Sales::Pages::Age1.new(nil, nil, self),
Form::Sales::Pages::GenderIdentity1.new(nil, nil, self),
Form::Sales::Pages::Buyer1LiveInProperty.new(nil, nil, self),
Form::Sales::Pages::Buyer2RelationshipToBuyer1.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::Age2.new(nil, nil, self),
Form::Sales::Pages::GenderIdentity2.new(nil, nil, self),
]
end
end

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

@ -10,6 +10,7 @@ class Form::Sales::Subsections::PropertyInformation < ::Form::Subsection
def pages
@pages ||= [
Form::Sales::Pages::PropertyNumberOfBedrooms.new(nil, nil, self),
Form::Sales::Pages::PropertyUnitType.new(nil, nil, self),
]
end
end

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

@ -16,9 +16,11 @@ class Form::Sales::Subsections::Setup < ::Form::Subsection
Form::Sales::Pages::SharedOwnershipType.new(nil, nil, self),
Form::Sales::Pages::DiscountedOwnershipType.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::JointPurchase.new(nil, nil, self),
Form::Sales::Pages::NumberJointBuyers.new(nil, nil, self),
Form::Sales::Pages::BuildingType.new(nil, nil, self),
]
end
end

4
app/models/lettings_log.rb

@ -376,10 +376,6 @@ class LettingsLog < Log
hb == 7
end
def ethnic_refused?
ethnic_group == 17
end
def receives_housing_related_benefits?
if collection_start_year <= 2021
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
end
def ethnic_refused?
ethnic_group == 17
end
private
def update_status!

5
app/models/sales_log.rb

@ -3,10 +3,15 @@ class SalesLogValidator < ActiveModel::Validator
end
class SalesLog < Log
include DerivedVariables::SalesLogVariables
self.inheritance_column = :_type_disabled
has_paper_trail
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 :search_by, ->(param) { filter_by_id(param) }

35
app/views/locations/edit_local_authority.html.erb

@ -0,0 +1,35 @@
<% content_for :before_content do %>
<%= govuk_back_link(
text: "Back",
href: "/schemes/#{@scheme.id}/locations",
) %>
<% end %>
<%= form_for(@location, method: :patch, url: location_path(location_id: @location.id, add_another_location: params[:add_another_location])) do |f| %>
<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds">
<%= f.govuk_error_summary %>
<%= render partial: "organisations/headings", locals: { main: "What is the local authority of #{@location.postcode}?", sub: @scheme.service_name } %>
<% la_list = FormHandler.instance.current_lettings_form.get_question("la", nil).answer_options.values %>
<% las = la_list.map { |la| OpenStruct.new(name: la) } %>
<%= f.govuk_collection_select :location_admin_district,
las,
:name,
:name,
label: { hidden: true },
"data-controller": %w[conditional-filter accessible-autocomplete] %>
<%= f.hidden_field :page, value: "edit-local-authority" %>
<div class="govuk-button-group">
<%= f.govuk_submit "Save and continue" %>
<%= govuk_link_to "Skip for now", "/schemes/#{@scheme.id}/check-answers#locations" %>
</div>
</div>
</div>
<% end %>

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

@ -52,11 +52,11 @@
<%= table.body do |body| %>
<%= body.row do |row| %>
<% row.cell(text: location.id) %>
<% row.cell(text: simple_format(location_cell(location, "/schemes/#{@scheme.id}/locations/#{location.id}/edit-name"), { class: "govuk-!-font-weight-bold" }, wrapper_tag: "div")) %>
<% row.cell(text: simple_format(location_cell_postcode(location, "/schemes/#{@scheme.id}/locations/#{location.id}/edit-name"), { class: "govuk-!-font-weight-bold" }, wrapper_tag: "div")) %>
<% row.cell(text: location.units) %>
<% row.cell(text: simple_format("<span>#{location.type_of_unit}</span>")) %>
<% row.cell(text: location.mobility_type) %>
<% row.cell(text: location.location_admin_district) %>
<% row.cell(text: simple_format(location_cell_location_admin_district(location, "/schemes/#{@scheme.id}/locations/#{location.id}/edit-local-authority"), wrapper_tag: "div")) %>
<% row.cell(text: location.startdate&.to_formatted_s(:govuk_date)) %>
<% end %>
<% end %>

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

@ -7,10 +7,10 @@
<div class="app-filter-layout" data-controller="filter-layout">
<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 %>
<% 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 %>
<% end %>
<%#= govuk_link_to "Upload logs", bulk_upload_lettings_logs_path %>

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

@ -14,7 +14,12 @@
<div class="app-filter-layout" data-controller="filter-layout">
<div class="govuk-button-group app-filter-toggle">
<%= govuk_button_to "Create a new lettings log for this organisation", lettings_logs_path(lettings_log: { owning_organisation_id: @organisation.id }, method: :post) %>
<% 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) %>
<% 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>
<%= render partial: "logs/log_filters" %>

4
app/views/schemes/check_answers.html.erb

@ -68,11 +68,11 @@
<%= table.body do |body| %>
<%= body.row do |row| %>
<% row.cell(text: location.id) %>
<% row.cell(text: simple_format(location_cell(location, get_location_change_link_href(@scheme, location)), { class: "govuk-!-font-weight-bold" }, wrapper_tag: "div")) %>
<% row.cell(text: simple_format(location_cell_postcode(location, get_location_change_link_href_postcode(@scheme, location)), { class: "govuk-!-font-weight-bold" }, wrapper_tag: "div")) %>
<% row.cell(text: location.units) %>
<% row.cell(text: simple_format("<span>#{location.type_of_unit}</span>")) %>
<% row.cell(text: location.mobility_type) %>
<% row.cell(text: location.location_admin_district) %>
<% row.cell(text: simple_format(location_cell_location_admin_district(location, get_location_change_link_href_location_admin_district(@scheme, location)), wrapper_tag: "div")) %>
<% row.cell(text: location.startdate&.to_formatted_s(:govuk_date)) %>
<% end %>
<% end %>

585
config/forms/2021_2022.json

File diff suppressed because it is too large Load Diff

589
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",
"description": "A form",
"type": "object",
"required": ["form_type", "start_year", "end_year", "sections"],
"required": [
"form_type",
"start_year",
"end_year",
"sections"
],
"properties": {
"form_type": {
"description": "",
@ -35,7 +40,9 @@
"[a-z_]+": {
"description": "",
"type": "object",
"required": ["label"],
"required": [
"label"
],
"properties": {
"label": {
"description": "",
@ -62,7 +69,10 @@
"[a-z_]+": {
"description": "",
"type": "object",
"required": ["header", "check_answer_label"],
"required": [
"header",
"check_answer_label"
],
"properties": {
"check_answer_label": {
"description": "",

21
config/forms/schema/generic.json

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

2
config/initializers/sidekiq.rb

@ -1,3 +1,5 @@
require "sidekiq/web"
if Rails.env.staging? || Rails.env.production?
redis_url = Configuration::PaasConfigurationService.new.redis_uris[:"dluhc-core-#{Rails.env}-redis"]

1
config/locales/en.yml

@ -104,6 +104,7 @@ en:
invalid_date: "Enter a date in the correct format, for example 31 1 2022"
outside_collection_window: "Enter a date within the current collection windows"
postcode: "Enter a postcode in the correct format, for example AA1 1AA"
location_admin_district: "Select a local authority"
email:
taken: "Enter an email address that hasn’t already been used to sign up"
invalid: "Enter an email address in the correct format, like name@example.com"

4
config/routes.rb

@ -1,5 +1,8 @@
# For details on the DSL available within this file, see https://guides.rubyonrails.org/routing.html
Rails.application.routes.draw do
mount_sidekiq = -> { mount Sidekiq::Web => "/sidekiq" }
authenticate(:user, :support?.to_proc, &mount_sidekiq)
devise_for :users, {
path: :account,
controllers: {
@ -50,6 +53,7 @@ Rails.application.routes.draw do
resources :locations do
get "edit-name", to: "locations#edit_name"
get "edit", to: "locations#edit"
get "edit-local-authority", to: "locations#edit_local_authority"
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/20220927144455_add_building_type_to_sales_log.rb

@ -0,0 +1,5 @@
class AddBuildingTypeToSalesLog < ActiveRecord::Migration[7.0]
def change
add_column :sales_logs, :builtype, :integer
end
end

5
db/migrate/20220928132657_add_prop_type_to_sales_log.rb

@ -0,0 +1,5 @@
class AddPropTypeToSalesLog < ActiveRecord::Migration[7.0]
def change
add_column :sales_logs, :proptype, :integer
end
end

8
db/migrate/20220929105157_add_buyer2_age_to_sales_log.rb

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

8
db/migrate/20220929125204_add_buyer2_relationship_to_buyer1_column.rb

@ -0,0 +1,8 @@
class AddBuyer2RelationshipToBuyer1Column < ActiveRecord::Migration[7.0]
def change
change_table :sales_logs, bulk: true do |t|
t.column :relat2, :string
t.column :otherrelat2, :string
end
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

12
db/schema.rb

@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema[7.0].define(version: 2022_09_27_133123) do
ActiveRecord::Schema[7.0].define(version: 2022_10_03_092048) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@ -339,6 +339,16 @@ ActiveRecord::Schema[7.0].define(version: 2022_09_27_133123) do
t.string "sex1"
t.integer "buy1livein"
t.integer "buylivein"
t.integer "builtype"
t.integer "proptype"
t.string "relat2"
t.string "otherrelat2"
t.integer "age2"
t.integer "age2_known"
t.integer "ethnic"
t.integer "ethnic_group"
t.string "sex2"
t.integer "noint"
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 ["owning_organisation_id"], name: "index_sales_logs_on_owning_organisation_id"

4
manifest.yml

@ -30,6 +30,10 @@ applications:
command: bundle exec rake cf:on_first_instance db:migrate && bin/rails server
instances: 4
memory: 1G
- type: worker
command: bundle exec sidekiq
health-check-type: process
instances: 2
env:
RAILS_ENV: production
host: submit-social-housing-lettings-sales-data

10
spec/factories/sales_log.rb

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

37
spec/features/organisation_spec.rb

@ -134,7 +134,7 @@ RSpec.describe "User Features" do
click_button("Submit")
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!(: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) }
@ -189,7 +189,7 @@ RSpec.describe "User Features" do
expect(page).to have_link("Clear search")
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")
expect(page).to have_link(log_to_search.id.to_s)
end
@ -210,6 +210,39 @@ RSpec.describe "User Features" do
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 am signed in and there are users in the database" do
let!(:user_list) { FactoryBot.create_list(:user, 4, organisation: user.organisation) }

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

File diff suppressed because it is too large Load Diff

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

@ -1,55 +1,57 @@
{
"form_type": "lettings",
"start_date": "2022-04-01T00:00:00.000+01:00",
"end_date": "2023-07-01T00:00:00.000+01:00",
"sections": {
"household": {
"label": "About the household",
"subsections": {
"household_characteristics": {
"label": "Household characteristics",
"pages": {
"tenant_code_test": {
"questions": {
"tenancycode": {
"check_answer_label": "Tenant code",
"header": "Different question header text for this year - 2023",
"type": "text",
"width": 10
}
"form_type": "lettings",
"start_date": "2022-04-01T00:00:00.000+01:00",
"end_date": "2023-07-01T00:00:00.000+01:00",
"sections": {
"household": {
"label": "About the household",
"subsections": {
"household_characteristics": {
"label": "Household characteristics",
"pages": {
"tenant_code_test": {
"questions": {
"tenancycode": {
"check_answer_label": "Tenant code",
"header": "Different question header text for this year - 2023",
"type": "text",
"width": 10
}
},
"outstanding_amount_known": {
"header": "",
"description": "",
"questions": {
"tshortfall_known": {
"check_answer_label": "",
"header": "",
"hint_text": "",
"hidden_in_check_answers": true,
"type": "radio",
"derived": true,
"answer_options": {
"0": {
"value": "Yes"
},
"1": {
"value": "No"
}
}
}
},
"depends_on": [false]
}
},
"depends_on": [
{
"setup": "completed"
}
]
}
"outstanding_amount_known": {
"header": "",
"description": "",
"questions": {
"tshortfall_known": {
"check_answer_label": "",
"header": "",
"hint_text": "",
"hidden_in_check_answers": true,
"type": "radio",
"derived": true,
"answer_options": {
"0": {
"value": "Yes"
},
"1": {
"value": "No"
}
}
}
},
"depends_on": [
false
]
}
},
"depends_on": [
{
"setup": "completed"
}
]
}
}
}
}
}

6
spec/fixtures/forms/test_validator.json vendored

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

2
spec/helpers/tab_nav_helper_spec.rb

@ -24,7 +24,7 @@ RSpec.describe TabNavHelper do
it "returns the location link to the postcode with optional name" do
link = "/schemes/#{location.scheme.id}/locations/#{location.id}/edit"
expected_html = "<a class=\"govuk-link\" rel=\"nofollow\" data-method=\"patch\" href=\"/schemes/#{scheme.id}/locations/#{location.id}/edit\">#{location.postcode}</a>\n<span class=\"govuk-visually-hidden\">Location </span><span class=\"govuk-!-font-weight-regular app-!-colour-muted\">#{location.name}</span>"
expect(location_cell(location, link)).to match(expected_html)
expect(location_cell_postcode(location, link)).to match(expected_html)
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")
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
describe ".completed?" do

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

@ -0,0 +1,35 @@
require "rails_helper"
RSpec.describe Form::Sales::Pages::Age2, 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[age2_known age2])
end
it "has the correct id" do
expect(page.id).to eq("buyer_2_age")
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

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

@ -0,0 +1,29 @@
require "rails_helper"
RSpec.describe Form::Sales::Pages::BuildingType, 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[builtype])
end
it "has the correct id" do
expect(page.id).to eq("builtype")
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_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

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

@ -0,0 +1,33 @@
require "rails_helper"
RSpec.describe Form::Sales::Pages::Buyer2RelationshipToBuyer1, 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[relat2 otherrelat2])
end
it "has the correct id" do
expect(page.id).to eq("buyer_2_relationship_to_buyer_1")
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

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

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

@ -0,0 +1,29 @@
require "rails_helper"
RSpec.describe Form::Sales::Pages::PropertyUnitType, 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[proptype])
end
it "has the correct id" do
expect(page.id).to eq("property_unit_type")
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

41
spec/models/form/sales/questions/age2_spec.rb

@ -0,0 +1,41 @@
require "rails_helper"
RSpec.describe Form::Sales::Questions::Age2, 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("age2")
end
it "has the correct header" do
expect(question.header).to eq("Age")
end
it "has the correct check_answer_label" do
expect(question.check_answer_label).to eq("Buyer 2’s age")
end
it "has the correct type" do
expect(question.type).to eq("numeric")
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
it "has the correct width" do
expect(question.width).to eq(2)
end
end

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

@ -0,0 +1,44 @@
require "rails_helper"
RSpec.describe Form::Sales::Questions::BuildingType, 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("builtype")
end
it "has the correct header" do
expect(question.header).to eq("What type of building is the property?")
end
it "has the correct check_answer_label" do
expect(question.check_answer_label).to eq("Type of building")
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" => "Purpose built" },
"2" => { "value" => "Converted from previous residential or non-residential property" },
})
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

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

@ -0,0 +1,46 @@
require "rails_helper"
RSpec.describe Form::Sales::Questions::Buyer2AgeKnown, 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("age2_known")
end
it "has the correct header" do
expect(question.header).to eq("Do you know buyer 2’s age?")
end
it "has the correct check_answer_label" do
expect(question.check_answer_label).to eq("Buyer 2’s age")
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({
"0" => { "value" => "Yes" },
"1" => { "value" => "No" },
})
end
it "has correct conditional for" do
expect(question.conditional_for).to eq({
"age2" => [0],
})
end
end

62
spec/models/form/sales/questions/buyer2_relationship_to_buyer1_spec.rb

@ -0,0 +1,62 @@
require "rails_helper"
RSpec.describe Form::Sales::Questions::Buyer2RelationshipToBuyer1, 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("relat2")
end
it "has the correct header" do
expect(question.header).to eq("What is buyer 2's relationship to buyer 1?")
end
it "has the correct check_answer_label" do
expect(question.check_answer_label).to eq("Buyer 2's relationship to buyer 1")
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({
"P" => { "value" => "Parent" },
"C" => { "value" => "Child", "hint" => "Must be eligible for child benefit, aged under 16 or under 20 if still in full-time education." },
"X" => { "value" => "Other" },
"R" => { "value" => "Buyer prefers not to say" },
})
end
it "has correct conditional for" do
expect(question.conditional_for).to eq({
"otherrelat2" => %w[X],
})
end
it "has correct hidden in check answers" do
expect(question.hidden_in_check_answers).to eq({
"depends_on" => [
{
"relat2" => "X",
},
],
})
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

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

@ -0,0 +1,37 @@
require "rails_helper"
RSpec.describe Form::Sales::Questions::OtherBuyer2RelationshipToBuyer1, 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("otherrelat2")
end
it "has the correct header" do
expect(question.header).to eq("Buyer 2's relationship to buyer 1")
end
it "has the correct check_answer_label" do
expect(question.check_answer_label).to eq("Buyer 2's relationship to buyer 1")
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/property_unit_type_spec.rb

@ -0,0 +1,43 @@
require "rails_helper"
RSpec.describe Form::Sales::Questions::PropertyUnitType, 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("proptype")
end
it "has the correct header" do
expect(question.header).to eq("What type of unit is the property?")
end
it "has the correct check_answer_label" do
expect(question.check_answer_label).to eq("Type of unit")
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({
"1" => { "value" => "Flat or maisonette" },
"2" => { "value" => "Bedsit" },
"3" => { "value" => "House" },
"4" => { "value" => "Bungalow" },
"9" => { "value" => "Other" },
})
end
end

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

@ -13,7 +13,21 @@ RSpec.describe Form::Sales::Subsections::HouseholdCharacteristics, type: :model
it "has correct pages" do
expect(household_characteristics.pages.map(&:id)).to eq(
%w[buyer_1_age buyer_1_gender_identity buyer_1_live_in_property],
%w[
buyer_interview
buyer_1_age
buyer_1_gender_identity
buyer_1_live_in_property
buyer_2_relationship_to_buyer_1
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_2_age
buyer_2_gender_identity
],
)
end

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

@ -13,7 +13,7 @@ RSpec.describe Form::Sales::Subsections::PropertyInformation, type: :model do
it "has correct pages" do
expect(property_information.pages.map(&:id)).to eq(
%w[property_number_of_bedrooms],
%w[property_number_of_bedrooms property_unit_type],
)
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
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],
%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

6
spec/models/form_handler_spec.rb

@ -61,14 +61,14 @@ RSpec.describe FormHandler do
it "is able to load a current sales form" do
form = form_handler.get_form("current_sales")
expect(form).to be_a(Form)
expect(form.pages.count).to eq(15)
expect(form.pages.count).to eq(28)
expect(form.name).to eq("2022_2023_sales")
end
it "is able to load a previous sales form" do
form = form_handler.get_form("previous_sales")
expect(form).to be_a(Form)
expect(form.pages.count).to eq(15)
expect(form.pages.count).to eq(28)
expect(form.name).to eq("2021_2022_sales")
end
end
@ -91,7 +91,7 @@ RSpec.describe FormHandler do
Timecop.unfreeze
end
it "returns the same year as the the current start year" do
it "returns the same year as the current start year" do
expect(form_handler.current_collection_start_year).to eq(2022)
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.subsections.count).to eq(1)
expect(form.subsections.first.id).to eq("setup")
expect(form.pages.count).to eq(11)
expect(form.pages.count).to eq(13)
expect(form.pages.first.id).to eq("organisation")
expect(form.questions.count).to eq(12)
expect(form.questions.count).to eq(14)
expect(form.questions.first.id).to eq("owning_organisation_id")
expect(form.start_date).to eq(Time.zone.parse("2022-04-01"))
expect(form.end_date).to eq(Time.zone.parse("2023-07-01"))

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save