Browse Source

Refactor log setup into code (#672)

* Refactor log setup into code

* Fix remaining tests

* Revert schema changes

* Add tests for setup section

Co-authored-by: baarkerlounger  <baarkerlounger@users.noreply.github.com>

* rename spec

Co-authored-by: Kat <katrina@madetech.com>
Co-authored-by: baarkerlounger  <baarkerlounger@users.noreply.github.com>
pull/650/head
baarkerlounger 3 years ago committed by GitHub
parent
commit
7de5558295
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 8
      app/models/form.rb
  2. 18
      app/models/form/page.rb
  3. 44
      app/models/form/question.rb
  4. 8
      app/models/form/section.rb
  5. 18
      app/models/form/setup/pages/needs_type.rb
  6. 16
      app/models/form/setup/pages/property_reference.rb
  7. 16
      app/models/form/setup/pages/renewal.rb
  8. 19
      app/models/form/setup/pages/rent_type.rb
  9. 15
      app/models/form/setup/pages/tenancy_start_date.rb
  10. 16
      app/models/form/setup/pages/tenant_code.rb
  11. 10
      app/models/form/setup/questions/irproduct_other.rb
  12. 17
      app/models/form/setup/questions/needs_type.rb
  13. 12
      app/models/form/setup/questions/property_reference.rb
  14. 17
      app/models/form/setup/questions/renewal.rb
  15. 22
      app/models/form/setup/questions/rent_type.rb
  16. 10
      app/models/form/setup/questions/tenancy_start_date.rb
  17. 12
      app/models/form/setup/questions/tenant_code.rb
  18. 10
      app/models/form/setup/sections/setup.rb
  19. 20
      app/models/form/setup/subsections/setup.rb
  20. 8
      app/models/form/subsection.rb
  21. 8
      app/models/form_handler.rb
  22. 138
      config/forms/setup/log_setup.json
  23. 3
      spec/features/form/check_answers_page_spec.rb
  24. 4
      spec/features/form/form_navigation_spec.rb
  25. 14
      spec/fixtures/forms/2021_2022.json
  26. 2
      spec/fixtures/forms/2022_2023.json
  27. 71
      spec/fixtures/forms/setup/log_setup.json
  28. 10
      spec/helpers/tasklist_helper_spec.rb
  29. 4
      spec/models/case_log_spec.rb
  30. 37
      spec/models/form/setup/pages/needs_type_spec.rb
  31. 37
      spec/models/form/setup/pages/property_reference_spec.rb
  32. 37
      spec/models/form/setup/pages/renewal_spec.rb
  33. 37
      spec/models/form/setup/pages/rent_type_spec.rb
  34. 37
      spec/models/form/setup/pages/tenancy_start_date_spec.rb
  35. 37
      spec/models/form/setup/pages/tenant_code_spec.rb
  36. 29
      spec/models/form/setup/questions/irproduct_other_spec.rb
  37. 36
      spec/models/form/setup/questions/needs_type_spec.rb
  38. 37
      spec/models/form/setup/questions/property_reference_spec.rb
  39. 40
      spec/models/form/setup/questions/renewal_spec.rb
  40. 48
      spec/models/form/setup/questions/rent_type_spec.rb
  41. 29
      spec/models/form/setup/questions/tenancy_start_date_spec.rb
  42. 37
      spec/models/form/setup/questions/tenant_code_spec.rb
  43. 29
      spec/models/form/setup/sections/setup_spec.rb
  44. 25
      spec/models/form/setup/subsections/setup_spec.rb
  45. 2
      spec/models/form/subsection_spec.rb
  46. 4
      spec/models/form_handler_spec.rb
  47. 1
      spec/models/form_spec.rb
  48. 3
      spec/models/rent_period_spec.rb
  49. 6
      spec/requests/case_logs_controller_spec.rb
  50. 4
      spec/requests/form_controller_spec.rb
  51. 3
      spec/services/imports/case_logs_field_import_service_spec.rb
  52. 5
      spec/services/imports/case_logs_import_service_spec.rb
  53. 9
      yarn.lock

8
app/models/form.rb

@ -3,13 +3,13 @@ class Form
:start_date, :end_date, :type, :name, :setup_definition,
:setup_sections, :form_sections
def initialize(form_path, name, setup_path)
raise "No setup definition file exists for given path".freeze unless File.exist?(setup_path)
include Form::Setup
def initialize(form_path, name)
raise "No form definition file exists for given year".freeze unless File.exist?(form_path)
@name = name
@setup_definition = JSON.parse(File.open(setup_path).read)
@setup_sections = setup_definition["sections"].map { |id, s| Form::Section.new(id, s, self) } || []
@setup_sections = [Form::Setup::Sections::Setup.new(nil, nil, self)]
@form_definition = JSON.parse(File.open(form_path).read)
@form_sections = form_definition["sections"].map { |id, s| Form::Section.new(id, s, self) }
@type = form_definition["form_type"]

18
app/models/form/page.rb

@ -4,15 +4,17 @@ class Form::Page
def initialize(id, hsh, subsection)
@id = id
@header = hsh["header"]
@description = hsh["description"]
@questions = hsh["questions"].map { |q_id, q| Form::Question.new(q_id, q, self) }
@depends_on = hsh["depends_on"]
@derived = hsh["derived"]
@title_text = hsh["title_text"]
@informative_text = hsh["informative_text"]
@hide_subsection_label = hsh["hide_subsection_label"]
@subsection = subsection
if hsh
@header = hsh["header"]
@description = hsh["description"]
@questions = hsh["questions"].map { |q_id, q| Form::Question.new(q_id, q, self) }
@depends_on = hsh["depends_on"]
@derived = hsh["derived"]
@title_text = hsh["title_text"]
@informative_text = hsh["informative_text"]
@hide_subsection_label = hsh["hide_subsection_label"]
end
end
delegate :form, to: :subsection

44
app/models/form/question.rb

@ -7,28 +7,30 @@ class Form::Question
def initialize(id, hsh, page)
@id = id
@check_answer_label = hsh["check_answer_label"]
@header = hsh["header"]
@guidance_partial = hsh["guidance_partial"]
@hint_text = hsh["hint_text"]
@type = hsh["type"]
@min = hsh["min"]
@max = hsh["max"]
@step = hsh["step"]
@width = hsh["width"]
@fields_to_add = hsh["fields-to-add"]
@result_field = hsh["result-field"]
@readonly = hsh["readonly"]
@answer_options = hsh["answer_options"]
@conditional_for = hsh["conditional_for"]
@inferred_answers = hsh["inferred_answers"]
@inferred_check_answers_value = hsh["inferred_check_answers_value"]
@hidden_in_check_answers = hsh["hidden_in_check_answers"]
@prefix = hsh["prefix"]
@suffix = hsh["suffix"]
@requires_js = hsh["requires_js"]
@fields_added = hsh["fields_added"]
@page = page
if hsh
@check_answer_label = hsh["check_answer_label"]
@header = hsh["header"]
@guidance_partial = hsh["guidance_partial"]
@hint_text = hsh["hint_text"]
@type = hsh["type"]
@min = hsh["min"]
@max = hsh["max"]
@step = hsh["step"]
@width = hsh["width"]
@fields_to_add = hsh["fields-to-add"]
@result_field = hsh["result-field"]
@readonly = hsh["readonly"]
@answer_options = hsh["answer_options"]
@conditional_for = hsh["conditional_for"]
@inferred_answers = hsh["inferred_answers"]
@inferred_check_answers_value = hsh["inferred_check_answers_value"]
@hidden_in_check_answers = hsh["hidden_in_check_answers"]
@prefix = hsh["prefix"]
@suffix = hsh["suffix"]
@requires_js = hsh["requires_js"]
@fields_added = hsh["fields_added"]
end
end
delegate :subsection, to: :page

8
app/models/form/section.rb

@ -3,9 +3,11 @@ class Form::Section
def initialize(id, hsh, form)
@id = id
@label = hsh["label"]
@description = hsh["description"]
@form = form
@subsections = hsh["subsections"].map { |s_id, s| Form::Subsection.new(s_id, s, self) }
if hsh
@label = hsh["label"]
@description = hsh["description"]
@subsections = hsh["subsections"].map { |s_id, s| Form::Subsection.new(s_id, s, self) }
end
end
end

18
app/models/form/setup/pages/needs_type.rb

@ -0,0 +1,18 @@
class Form::Setup::Pages::NeedsType < ::Form::Page
def initialize(id, hsh, subsection)
super
@id = "needs_type"
@header = ""
@description = ""
@questions = questions
@depends_on = [{ "supported_housing_schemes_enabled?" => true }]
@derived = true
@subsection = subsection
end
def questions
[
Form::Setup::Questions::NeedsType.new(nil, nil, self),
]
end
end

16
app/models/form/setup/pages/property_reference.rb

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

16
app/models/form/setup/pages/renewal.rb

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

19
app/models/form/setup/pages/rent_type.rb

@ -0,0 +1,19 @@
class Form::Setup::Pages::RentType < ::Form::Page
def initialize(id, hsh, subsection)
super
@id = "rent_type"
@header = ""
@description = ""
@questions = questions
@depends_on = [{ "supported_housing_schemes_enabled?" => true }]
@derived = true
@subsection = subsection
end
def questions
[
Form::Setup::Questions::RentType.new(nil, nil, self),
Form::Setup::Questions::IrproductOther.new(nil, nil, self),
]
end
end

15
app/models/form/setup/pages/tenancy_start_date.rb

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

16
app/models/form/setup/pages/tenant_code.rb

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

10
app/models/form/setup/questions/irproduct_other.rb

@ -0,0 +1,10 @@
class Form::Setup::Questions::IrproductOther < ::Form::Question
def initialize(id, hsh, page)
super
@id = "irproduct_other"
@check_answer_label = "Product name"
@header = "Name of rent product"
@type = "text"
@page = page
end
end

17
app/models/form/setup/questions/needs_type.rb

@ -0,0 +1,17 @@
class Form::Setup::Questions::NeedsType < ::Form::Question
def initialize(id, hsh, page)
super
@id = "needstype"
@check_answer_label = "Needs type"
@header = "What is the needs type?"
@hint_text = ""
@type = "radio"
@answer_options = ANSWER_OPTIONS
@page = page
end
ANSWER_OPTIONS = {
"1" => { "value" => "General needs" },
"2" => { "value" => "Supported housing" },
}.freeze
end

12
app/models/form/setup/questions/property_reference.rb

@ -0,0 +1,12 @@
class Form::Setup::Questions::PropertyReference < ::Form::Question
def initialize(id, hsh, page)
super
@id = "propcode"
@check_answer_label = "Property reference"
@header = "What is the property reference?"
@hint_text = "This is how you usually refer to this property on your own systems."
@type = "text"
@width = 10
@page = page
end
end

17
app/models/form/setup/questions/renewal.rb

@ -0,0 +1,17 @@
class Form::Setup::Questions::Renewal < ::Form::Question
def initialize(id, hsh, page)
super
@id = "renewal"
@check_answer_label = "Property renewal"
@header = "Is this letting a renewal?"
@hint_text = ""
@type = "radio"
@answer_options = ANSWER_OPTIONS
@page = page
end
ANSWER_OPTIONS = {
"1" => { "value" => "Yes" },
"0" => { "value" => "No" },
}.freeze
end

22
app/models/form/setup/questions/rent_type.rb

@ -0,0 +1,22 @@
class Form::Setup::Questions::RentType < ::Form::Question
def initialize(id, hsh, page)
super
@id = "rent_type"
@check_answer_label = "Rent type"
@header = "What is the rent type?"
@hint_text = ""
@type = "radio"
@answer_options = ANSWER_OPTIONS
@conditional_for = { "irproduct_other" => [5] }
@page = page
end
ANSWER_OPTIONS = {
"1" => { "value" => "Affordable Rent" },
"2" => { "value" => "London Affordable Rent" },
"4" => { "value" => "London Living Rent" },
"3" => { "value" => "Rent to Buy" },
"0" => { "value" => "Social Rent" },
"5" => { "value" => "Other intermediate rent product" },
}.freeze
end

10
app/models/form/setup/questions/tenancy_start_date.rb

@ -0,0 +1,10 @@
class Form::Setup::Questions::TenancyStartDate < ::Form::Question
def initialize(id, hsh, page)
super
@id = "startdate"
@check_answer_label = "Tenancy start date"
@header = "What is the tenancy start date?"
@type = "date"
@page = page
end
end

12
app/models/form/setup/questions/tenant_code.rb

@ -0,0 +1,12 @@
class Form::Setup::Questions::TenantCode < ::Form::Question
def initialize(id, hsh, page)
super
@id = "tenant_code"
@check_answer_label = "Tenant code"
@header = "What is the tenant code?"
@hint_text = "This is how you usually refer to this tenancy on your own systems."
@type = "text"
@width = 10
@page = page
end
end

10
app/models/form/setup/sections/setup.rb

@ -0,0 +1,10 @@
class Form::Sections::Setup < ::Form::Section
def initialize(id, hsh, form)
super
@id = "setup"
@label = "Before you start"
@description = ""
@form = form
@subsections = [Form::Setup::Subsections::Setup.new(nil, nil, self)]
end
end

20
app/models/form/setup/subsections/setup.rb

@ -0,0 +1,20 @@
class Form::Subsections::Setup < ::Form::Subsection
def initialize(id, hsh, section)
super
@id = "setup"
@label = "Set up this lettings log"
@pages = [pages]
@section = section
end
def pages
[
Form::Setup::Pages::NeedsType.new(nil, nil, self),
Form::Setup::Pages::Renewal.new(nil, nil, self),
Form::Setup::Pages::TenancyStartDate.new(nil, nil, self),
Form::Setup::Pages::RentType.new(nil, nil, self),
Form::Setup::Pages::TenantCode.new(nil, nil, self),
Form::Setup::Pages::PropertyReference.new(nil, nil, self),
]
end
end

8
app/models/form/subsection.rb

@ -3,10 +3,12 @@ class Form::Subsection
def initialize(id, hsh, section)
@id = id
@label = hsh["label"]
@depends_on = hsh["depends_on"]
@pages = hsh["pages"].map { |s_id, p| Form::Page.new(s_id, p, self) }
@section = section
if hsh
@label = hsh["label"]
@depends_on = hsh["depends_on"]
@pages = hsh["pages"].map { |s_id, p| Form::Page.new(s_id, p, self) }
end
end
delegate :form, to: :section

8
app/models/form_handler.rb

@ -21,18 +21,12 @@ private
directories.each do |directory|
Dir.glob("#{directory}/*.json").each do |form_path|
form_name = File.basename(form_path, ".json")
forms[form_name] = Form.new(form_path, form_name, setup_path)
forms[form_name] = Form.new(form_path, form_name)
end
end
forms
end
def setup_path
return "spec/fixtures/forms/setup/log_setup.json" if Rails.env.test?
"config/forms/setup/log_setup.json"
end
def directories
Rails.env.test? ? ["spec/fixtures/forms"] : ["config/forms"]
end

138
config/forms/setup/log_setup.json

@ -1,138 +0,0 @@
{
"form_type": "setup",
"sections": {
"setup": {
"label": "Before you start",
"subsections": {
"setup": {
"label": "Set up this lettings log",
"pages": {
"needs_type": {
"header": "",
"description": "",
"questions": {
"needstype": {
"check_answer_label": "Needs type",
"header": "What is the needs type?",
"hint_text": "",
"type": "radio",
"answer_options": {
"1": {
"value": "General needs"
},
"2": {
"value": "Supported housing"
}
}
}
},
"derived": true,
"depends_on": [
{
"supported_housing_schemes_enabled?" : true
}
]
},
"renewal": {
"header": "",
"description": "",
"questions": {
"renewal": {
"check_answer_label": "Property renewal",
"header": "Is this letting a renewal?",
"hint_text": "A renewal is a letting to the same tenant in the same property.",
"type": "radio",
"answer_options": {
"1": {
"value": "Yes"
},
"0": {
"value": "No"
}
}
}
}
},
"tenancy_start_date": {
"header": "",
"description": "",
"questions": {
"startdate": {
"check_answer_label": "Tenancy start date",
"header": "What is the tenancy start date?",
"type": "date"
}
}
},
"rent_type": {
"header": "",
"description": "",
"questions": {
"rent_type": {
"check_answer_label": "Rent type",
"header": "What is the rent type?",
"hint_text": "",
"type": "radio",
"answer_options": {
"1": {
"value": "Affordable Rent"
},
"2": {
"value": "London Affordable Rent"
},
"4": {
"value": "London Living Rent"
},
"3": {
"value": "Rent to Buy"
},
"0": {
"value": "Social Rent"
},
"5": {
"value": "Other intermediate rent product"
}
},
"conditional_for": {
"irproduct_other": [5]
}
},
"irproduct_other": {
"check_answer_label": "Product name",
"header": "Name of rent product",
"type": "text"
}
}
},
"tenant_code": {
"header": "",
"description": "",
"questions": {
"tenant_code": {
"check_answer_label": "Tenant code",
"header": "What is the tenant code?",
"hint_text": "This is how you usually refer to this tenancy on your own systems.",
"type": "text",
"width": 10
}
}
},
"property_reference": {
"header": "",
"description": "",
"questions": {
"propcode": {
"check_answer_label": "Property reference",
"header": "What is the property reference?",
"hint_text": "This is how you usually refer to this property on your own systems.",
"type": "text",
"width": 10
}
}
}
}
}
}
}
}
}

3
spec/features/form/check_answers_page_spec.rb

@ -194,6 +194,7 @@ RSpec.describe "Form Check Answers Page" do
:in_progress,
owning_organisation: user.organisation,
managing_organisation: user.organisation,
needstype: 1,
tenant_code: nil,
age1: nil,
layear: 2,
@ -226,7 +227,7 @@ RSpec.describe "Form Check Answers Page" do
it "they can click a button to cycle around to the next incomplete section" do
visit("/logs/#{cycle_sections_case_log.id}/declaration/check-answers")
click_link("Save and go to next incomplete section")
expect(page).to have_current_path("/logs/#{cycle_sections_case_log.id}/tenant-code")
expect(page).to have_current_path("/logs/#{cycle_sections_case_log.id}/tenant-code-test")
end
end
end

4
spec/features/form/form_navigation_spec.rb

@ -16,7 +16,7 @@ RSpec.describe "Form Navigation" do
let(:id) { case_log.id }
let(:question_answers) do
{
tenant_code: { type: "text", answer: "BZ737", path: "tenant-code" },
tenant_code: { type: "text", answer: "BZ737", path: "tenant-code-test" },
age1: { type: "numeric", answer: 25, path: "person-1-age" },
sex1: { type: "radio", answer: "Female", path: "person-1-gender" },
ecstat1: { type: "radio", answer: 3, path: "person-1-working-situation" },
@ -61,7 +61,7 @@ RSpec.describe "Form Navigation" do
end
it "go back to tenant code page from tenant age page", js: true do
visit("/logs/#{id}/tenant-code")
visit("/logs/#{id}/tenant-code-test")
click_button("Save and continue")
visit("/logs/#{id}/person-1-age")
click_link(text: "Back")

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

@ -10,7 +10,7 @@
"household_characteristics": {
"label": "Household characteristics",
"pages": {
"tenant_code": {
"tenant_code_test": {
"questions": {
"tenant_code": {
"check_answer_label": "Tenant code",
@ -27,7 +27,7 @@
{
"housingneeds_a": null
}
] },
]},
"person_1_age": {
"questions": {
"age1": {
@ -39,7 +39,15 @@
"step": 1,
"width": 2
}
}
},
"depends_on": [
{
"housingneeds_a": 1
},
{
"housingneeds_a": null
}
]
},
"person_1_gender": {
"questions": {

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

@ -9,7 +9,7 @@
"household_characteristics": {
"label": "Household characteristics",
"pages": {
"tenant_code": {
"tenant_code_test": {
"questions": {
"tenant_code": {
"check_answer_label": "Tenant code",

71
spec/fixtures/forms/setup/log_setup.json vendored

@ -1,71 +0,0 @@
{
"form_type": "setup",
"sections": {
"setup": {
"label": "Before you start",
"subsections": {
"setup": {
"label": "Set up this lettings log",
"pages": {
"renewal": {
"header": "",
"description": "",
"questions": {
"renewal": {
"check_answer_label": "Property renewal",
"header": "Is this a renewal to the same tenant in the same property?",
"hint_text": "",
"type": "radio",
"answer_options": {
"1": "Yes",
"0": "No"
}
}
}
},
"startdate": {
"header": "",
"description": "",
"questions": {
"startdate": {
"check_answer_label": "Tenancy start date",
"header": "What is the tenancy start date?",
"hint_text": "For example, 27 3 2007",
"type": "date"
}
}
},
"about_this_letting": {
"header": "Tell us about this letting",
"description": "",
"questions": {
"rent_type": {
"check_answer_label": "Rent type",
"header": "What is the rent type?",
"hint_text": "",
"type": "radio",
"answer_options": {
"0": "Social rent",
"1": "Affordable rent",
"2": "London Affordable rent",
"3": "Rent to buy",
"4": "London living rent",
"5": "Other intermediate rent product"
},
"conditional_for": {
"intermediate_rent_product_name": [5]
}
},
"intermediate_rent_product_name": {
"check_answer_label": "Product name",
"header": "What is intermediate rent product name?",
"type": "text"
}
}
}
}
}
}
}
}
}

10
spec/helpers/tasklist_helper_spec.rb

@ -6,12 +6,12 @@ RSpec.describe TasklistHelper do
describe "get next incomplete section" do
it "returns the first subsection name if it is not completed" do
expect(get_next_incomplete_section(case_log).id).to eq("household_characteristics")
expect(get_next_incomplete_section(case_log).id).to eq("setup")
end
it "returns the first subsection name if it is partially completed" do
case_log["tenant_code"] = 123
expect(get_next_incomplete_section(case_log).id).to eq("household_characteristics")
expect(get_next_incomplete_section(case_log).id).to eq("setup")
end
end
@ -29,7 +29,7 @@ RSpec.describe TasklistHelper do
end
it "returns the number of sections in progress" do
expect(get_subsections_count(case_log, :in_progress)).to eq(3)
expect(get_subsections_count(case_log, :in_progress)).to eq(4)
end
it "returns 0 for invalid state" do
@ -48,9 +48,9 @@ RSpec.describe TasklistHelper do
expect(next_page_or_check_answers(subsection, empty_case_log)).to match(/tenant-code/)
end
it "when first question being not routed to returns the second question link" do
it "when first question being not routed to returns the next routed question link" do
empty_case_log.housingneeds_a = "No"
expect(next_page_or_check_answers(subsection, empty_case_log)).to match(/person-1-age/)
expect(next_page_or_check_answers(subsection, empty_case_log)).to match(/person-1-gender/)
end
end

4
spec/models/case_log_spec.rb

@ -1700,10 +1700,10 @@ RSpec.describe CaseLog do
end
context "when the question type does not have answer options" do
let(:case_log) { FactoryBot.create(:case_log, :in_progress, housingneeds_a: 1, tenant_code: "test") }
let(:case_log) { FactoryBot.create(:case_log, :in_progress, housingneeds_a: 1, age1: 19) }
it "clears the answer" do
expect { case_log.update!(housingneeds_a: 0) }.to change(case_log, :tenant_code).from("test").to(nil)
expect { case_log.update!(housingneeds_a: 0) }.to change(case_log, :age1).from(19).to(nil)
end
end

37
spec/models/form/setup/pages/needs_type_spec.rb

@ -0,0 +1,37 @@
require "rails_helper"
RSpec.describe Form::Setup::Pages::NeedsType, 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[needstype])
end
it "has the correct id" do
expect(page.id).to eq("needs_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
it "has the correct depends_on" do
expect(page.depends_on).to eq([{ "supported_housing_schemes_enabled?" => true }])
end
it "has the correct derived" do
expect(page.derived).to be true
end
end

37
spec/models/form/setup/pages/property_reference_spec.rb

@ -0,0 +1,37 @@
require "rails_helper"
RSpec.describe Form::Setup::Pages::PropertyReference, 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[propcode])
end
it "has the correct id" do
expect(page.id).to eq("property_reference")
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 the correct depends_on" do
expect(page.depends_on).to be nil
end
it "has the correct derived" do
expect(page.derived).to be nil
end
end

37
spec/models/form/setup/pages/renewal_spec.rb

@ -0,0 +1,37 @@
require "rails_helper"
RSpec.describe Form::Setup::Pages::Renewal, 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[renewal])
end
it "has the correct id" do
expect(page.id).to eq("renewal")
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 the correct depends_on" do
expect(page.depends_on).to be nil
end
it "has the correct derived" do
expect(page.derived).to be nil
end
end

37
spec/models/form/setup/pages/rent_type_spec.rb

@ -0,0 +1,37 @@
require "rails_helper"
RSpec.describe Form::Setup::Pages::RentType, 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[rent_type irproduct_other])
end
it "has the correct id" do
expect(page.id).to eq("rent_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
it "has the correct depends_on" do
expect(page.depends_on).to eq([{ "supported_housing_schemes_enabled?" => true }])
end
it "has the correct derived" do
expect(page.derived).to be true
end
end

37
spec/models/form/setup/pages/tenancy_start_date_spec.rb

@ -0,0 +1,37 @@
require "rails_helper"
RSpec.describe Form::Setup::Pages::TenancyStartDate, 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[startdate])
end
it "has the correct id" do
expect(page.id).to eq("tenancy_start_date")
end
it "has the correct header" do
expect(page.header).to be nil
end
it "has the correct description" do
expect(page.description).to eq("")
end
it "has the correct depends_on" do
expect(page.depends_on).to be nil
end
it "has the correct derived" do
expect(page.derived).to be nil
end
end

37
spec/models/form/setup/pages/tenant_code_spec.rb

@ -0,0 +1,37 @@
require "rails_helper"
RSpec.describe Form::Setup::Pages::TenantCode, 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[tenant_code])
end
it "has the correct id" do
expect(page.id).to eq("tenant_code")
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 the correct depends_on" do
expect(page.depends_on).to be nil
end
it "has the correct derived" do
expect(page.derived).to be nil
end
end

29
spec/models/form/setup/questions/irproduct_other_spec.rb

@ -0,0 +1,29 @@
require "rails_helper"
RSpec.describe Form::Setup::Questions::IrproductOther, 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("irproduct_other")
end
it "has the correct header" do
expect(question.header).to eq("Name of rent product")
end
it "has the correct check_answer_label" do
expect(question.check_answer_label).to eq("Product name")
end
it "has the correct type" do
expect(question.type).to eq("text")
end
end

36
spec/models/form/setup/questions/needs_type_spec.rb

@ -0,0 +1,36 @@
require "rails_helper"
RSpec.describe Form::Setup::Questions::NeedsType, 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("needstype")
end
it "has the correct header" do
expect(question.header).to eq("What is the needs type?")
end
it "has the correct check_answer_label" do
expect(question.check_answer_label).to eq("Needs type")
end
it "has the correct type" do
expect(question.type).to eq("radio")
end
it "has the correct answer_options" do
expect(question.answer_options).to eq({
"1" => { "value" => "General needs" },
"2" => { "value" => "Supported housing" },
})
end
end

37
spec/models/form/setup/questions/property_reference_spec.rb

@ -0,0 +1,37 @@
require "rails_helper"
RSpec.describe Form::Setup::Questions::PropertyReference, 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("propcode")
end
it "has the correct header" do
expect(question.header).to eq("What is the property reference?")
end
it "has the correct check_answer_label" do
expect(question.check_answer_label).to eq("Property reference")
end
it "has the correct type" do
expect(question.type).to eq("text")
end
it "has the correct hint_text" do
expect(question.hint_text).to eq("This is how you usually refer to this property on your own systems.")
end
it "has the correct width" do
expect(question.width).to eq(10)
end
end

40
spec/models/form/setup/questions/renewal_spec.rb

@ -0,0 +1,40 @@
require "rails_helper"
RSpec.describe Form::Setup::Questions::Renewal, 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("renewal")
end
it "has the correct header" do
expect(question.header).to eq("Is this letting a renewal?")
end
it "has the correct check_answer_label" do
expect(question.check_answer_label).to eq("Property renewal")
end
it "has the correct type" do
expect(question.type).to eq("radio")
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" },
"0" => { "value" => "No" },
})
end
end

48
spec/models/form/setup/questions/rent_type_spec.rb

@ -0,0 +1,48 @@
require "rails_helper"
RSpec.describe Form::Setup::Questions::RentType, 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("rent_type")
end
it "has the correct header" do
expect(question.header).to eq("What is the rent type?")
end
it "has the correct check_answer_label" do
expect(question.check_answer_label).to eq("Rent type")
end
it "has the correct type" do
expect(question.type).to eq("radio")
end
it "has the correct hint_text" do
expect(question.hint_text).to eq("")
end
it "has the correct conditional_for" do
expect(question.conditional_for).to eq({ "irproduct_other" => [5] })
end
it "has the correct answer_options" do
expect(question.answer_options).to eq({
"1" => { "value" => "Affordable Rent" },
"2" => { "value" => "London Affordable Rent" },
"4" => { "value" => "London Living Rent" },
"3" => { "value" => "Rent to Buy" },
"0" => { "value" => "Social Rent" },
"5" => { "value" => "Other intermediate rent product" },
})
end
end

29
spec/models/form/setup/questions/tenancy_start_date_spec.rb

@ -0,0 +1,29 @@
require "rails_helper"
RSpec.describe Form::Setup::Questions::TenancyStartDate, 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("startdate")
end
it "has the correct header" do
expect(question.header).to eq("What is the tenancy start date?")
end
it "has the correct check_answer_label" do
expect(question.check_answer_label).to eq("Tenancy start date")
end
it "has the correct type" do
expect(question.type).to eq("date")
end
end

37
spec/models/form/setup/questions/tenant_code_spec.rb

@ -0,0 +1,37 @@
require "rails_helper"
RSpec.describe Form::Setup::Questions::TenantCode, 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("tenant_code")
end
it "has the correct header" do
expect(question.header).to eq("What is the tenant code?")
end
it "has the correct check_answer_label" do
expect(question.check_answer_label).to eq("Tenant code")
end
it "has the correct type" do
expect(question.type).to eq("text")
end
it "has the correct hint_text" do
expect(question.hint_text).to eq("This is how you usually refer to this tenancy on your own systems.")
end
it "has the correct width" do
expect(question.width).to eq(10)
end
end

29
spec/models/form/setup/sections/setup_spec.rb

@ -0,0 +1,29 @@
require "rails_helper"
RSpec.describe Form::Setup::Sections::Setup, type: :model do
subject(:setup) { described_class.new(section_id, section_definition, form) }
let(:section_id) { nil }
let(:section_definition) { nil }
let(:form) { instance_double(Form) }
it "has correct form" do
expect(setup.form).to eq(form)
end
it "has correct subsections" do
expect(setup.subsections.map(&:id)).to eq(%w[setup])
end
it "has the correct id" do
expect(setup.id).to eq("setup")
end
it "has the correct label" do
expect(setup.label).to eq("Before you start")
end
it "has the correct description" do
expect(setup.description).to eq("")
end
end

25
spec/models/form/setup/subsections/setup_spec.rb

@ -0,0 +1,25 @@
require "rails_helper"
RSpec.describe Form::Setup::Subsections::Setup, type: :model do
subject(:setup) { described_class.new(subsection_id, subsection_definition, section) }
let(:subsection_id) { nil }
let(:subsection_definition) { nil }
let(:section) { instance_double(Form::Setup::Sections::Setup) }
it "has correct section" do
expect(setup.section).to eq(section)
end
it "has correct pages" do
expect(setup.pages.map(&:id)).to eq(%w[needs_type renewal tenancy_start_date rent_type tenant_code property_reference])
end
it "has the correct id" do
expect(setup.id).to eq("setup")
end
it "has the correct label" do
expect(setup.label).to eq("Set up this lettings log")
end
end

2
spec/models/form/subsection_spec.rb

@ -25,7 +25,7 @@ RSpec.describe Form::Subsection, type: :model do
end
it "has pages" do
expected_pages = %w[tenant_code person_1_age person_1_gender person_1_working_situation household_number_of_members person_2_working_situation propcode]
expected_pages = %w[tenant_code_test person_1_age person_1_gender person_1_working_situation household_number_of_members person_2_working_situation propcode]
expect(subsection.pages.map(&:id)).to eq(expected_pages)
end

4
spec/models/form_handler_spec.rb

@ -17,7 +17,7 @@ RSpec.describe FormHandler do
form_handler = described_class.instance
form = form_handler.get_form(test_form_name)
expect(form).to be_a(Form)
expect(form.pages.count).to eq(38)
expect(form.pages.count).to eq(41)
end
end
@ -32,7 +32,7 @@ RSpec.describe FormHandler do
it "loads the form once at boot time" do
form_handler = described_class.instance
expect(Form).not_to receive(:new).with(:any, test_form_name, :any)
expect(Form).not_to receive(:new).with(:any, test_form_name)
expect(form_handler.get_form(test_form_name)).to be_a(Form)
end
end

1
spec/models/form_spec.rb

@ -134,6 +134,7 @@ RSpec.describe Form, type: :model do
case_log.relat2 = "P"
case_log.sex2 = "F"
case_log.ecstat2 = 1
case_log.needstype = 1
end
it "returns the first page of the next incomplete subsection if the subsection is not in progress" do

3
spec/models/rent_period_spec.rb

@ -2,8 +2,7 @@ require "rails_helper"
RSpec.describe RentPeriod, type: :model do
describe "rent period mapping" do
let(:setup_path) { "spec/fixtures/forms/setup/log_setup.json" }
let(:form) { Form.new("spec/fixtures/forms/2021_2022.json", "2021_2022", setup_path) }
let(:form) { Form.new("spec/fixtures/forms/2021_2022.json", "2021_2022") }
before do
allow(FormHandler.instance).to receive(:current_form).and_return(form)

6
spec/requests/case_logs_controller_spec.rb

@ -623,8 +623,8 @@ RSpec.describe CaseLogsController, type: :request do
end
it "displays a section status for a case log" do
assert_select ".govuk-tag", text: /Not started/, count: 8
assert_select ".govuk-tag", text: /In progress/, count: 1
assert_select ".govuk-tag", text: /Not started/, count: 7
assert_select ".govuk-tag", text: /In progress/, count: 2
assert_select ".govuk-tag", text: /Completed/, count: 0
assert_select ".govuk-tag", text: /Cannot start yet/, count: 1
end
@ -646,7 +646,7 @@ RSpec.describe CaseLogsController, type: :request do
end
it "displays a section status for a case log" do
assert_select ".govuk-tag", text: /Not started/, count: 8
assert_select ".govuk-tag", text: /Not started/, count: 7
assert_select ".govuk-tag", text: /Completed/, count: 1
assert_select ".govuk-tag", text: /Cannot start yet/, count: 1
end

4
spec/requests/form_controller_spec.rb

@ -80,9 +80,9 @@ RSpec.describe FormController, type: :request do
let(:case_log_year_2) { FactoryBot.create(:case_log, :about_completed, startdate: Time.zone.local(2022, 5, 1), owning_organisation: organisation) }
it "displays the correct question details for each case log based on form year" do
get "/logs/#{case_log_year_1.id}/tenant-code", headers: headers, params: {}
get "/logs/#{case_log_year_1.id}/tenant-code-test", headers: headers, params: {}
expect(response.body).to include("What is the tenant code?")
get "/logs/#{case_log_year_2.id}/tenant-code", headers: headers, params: {}
get "/logs/#{case_log_year_2.id}/tenant-code-test", headers: headers, params: {}
expect(response.body).to match("Different question header text for this year - 2023")
end
end

3
spec/services/imports/case_logs_field_import_service_spec.rb

@ -6,8 +6,7 @@ RSpec.describe Imports::CaseLogsFieldImportService do
let(:storage_service) { instance_double(StorageService) }
let(:logger) { instance_double(ActiveSupport::Logger) }
let(:real_setup_path) { "config/forms/setup/log_setup.json" }
let(:real_2021_2022_form) { Form.new("config/forms/2021_2022.json", "2021_2022", real_setup_path) }
let(:real_2021_2022_form) { Form.new("config/forms/2021_2022.json", "2021_2022") }
let(:fixture_directory) { "spec/fixtures/softwire_imports/case_logs" }
let(:case_log_id) { "0ead17cb-1668-442d-898c-0d52879ff592" }

5
spec/services/imports/case_logs_import_service_spec.rb

@ -6,9 +6,8 @@ RSpec.describe Imports::CaseLogsImportService do
let(:storage_service) { instance_double(StorageService) }
let(:logger) { instance_double(ActiveSupport::Logger) }
let(:real_setup_path) { "config/forms/setup/log_setup.json" }
let(:real_2021_2022_form) { Form.new("config/forms/2021_2022.json", "2021_2022", real_setup_path) }
let(:real_2022_2023_form) { Form.new("config/forms/2022_2023.json", "2022_2023", real_setup_path) }
let(:real_2021_2022_form) { Form.new("config/forms/2021_2022.json", "2021_2022") }
let(:real_2022_2023_form) { Form.new("config/forms/2022_2023.json", "2022_2023") }
let(:fixture_directory) { "spec/fixtures/softwire_imports/case_logs" }
def open_file(directory, filename)

9
yarn.lock

@ -1489,7 +1489,7 @@ braces@^3.0.2, braces@~3.0.2:
dependencies:
fill-range "^7.0.1"
browserslist@^4.14.5, browserslist@^4.20.2, browserslist@^4.20.3:
browserslist@^4.14.5, browserslist@^4.20.2, browserslist@^4.20.4:
version "4.20.4"
resolved "https://registry.yarnpkg.com/browserslist/-/browserslist-4.20.4.tgz#98096c9042af689ee1e0271333dbc564b8ce4477"
integrity sha512-ok1d+1WpnU24XYN7oC3QWgTyMhY/avPJ/r9T00xxvUOIparA/gc+UPUMaod3i+G6s+nI2nUb9xZ5k794uIwShw==
@ -2402,12 +2402,7 @@ globjoin@^0.1.4:
resolved "https://registry.yarnpkg.com/globjoin/-/globjoin-0.1.4.tgz#2f4494ac8919e3767c5cbb691e9f463324285d43"
integrity sha512-xYfnw62CKG8nLkZBfWbhWwDw02CHty86jfPcc2cr3ZfeuK9ysoVPPEUxf21bAD/rWAgk52SuBrLJlefNy8mvFg==
govuk-frontend@4.0.1:
version "4.0.1"
resolved "https://registry.yarnpkg.com/govuk-frontend/-/govuk-frontend-4.0.1.tgz#bceff58ecb399272cba32bd2b357fe16198e3249"
integrity sha512-X+B88mqYHoxAz0ID87Uxo3oHqdKBRnNHd3Cz8+u8nvQUAsrEzROFLK+t7sAu7e+fKqCCrJyIgx6Cmr6dIGnohQ==
govuk-frontend@^4.0.1:
govuk-frontend@4.0.1, govuk-frontend@^4.0.1:
version "4.0.1"
resolved "https://registry.yarnpkg.com/govuk-frontend/-/govuk-frontend-4.0.1.tgz#bceff58ecb399272cba32bd2b357fe16198e3249"
integrity sha512-X+B88mqYHoxAz0ID87Uxo3oHqdKBRnNHd3Cz8+u8nvQUAsrEzROFLK+t7sAu7e+fKqCCrJyIgx6Cmr6dIGnohQ==

Loading…
Cancel
Save