Browse Source

Cldc 1776 sales information sections (#1106)

* Mark subsection as completed if it is not displayed in the tasklist and hide it from the UI

* Add sale_information section

* add sales information subsections

* Cldc 1531 staircasing (#1109)

* Add staircase field to sales_logs table

* Add staircase question and page

* add staircase page to the shared ownership scheme subsection fix file name

* Cldc 1539 previous bedrooms (#1108)

* add frombeds field

* Add previous_bedrooms page and question

* add Previous Bedrooms page to the shared ownership subsection

* Cldc 1532 about staircasing (#1110)

* Add stairboughts and stairowned fields to the database

* Add about staircasing page and questions

* Add about staircasing page to the shared wnership scheme subsection

* Add a space before percent

* Cldc 1546 monthly rent (#1111)

* Add monthly rent column to sales logs table

* Add monthly rent question and page

* Add monthly rent page to the shared ownership scheme subsection

* Cldc 1535 exchange contracts (#1112)

* Add exdate to sales logs table

* Add exchange date page and question

* Add exchange contracts page to the shared ownership subsection

* derive exday, exmonth and exyear, tests and lint

* rebase tests

* Cldc 1538 la nominations (#1115)

* Add la nominations column to sales logs table

* Add La nominations page and questions

* Add la nominations to the shared ownership subsection

* Add accidentally removed files

* Cldc 1545 about the deposit (#1113)

* feat: add question(s) without depends_on behaviour

* feat: separate ids for diff sections

* test: update tests

* test: add tests

* tests: test tweaks

* refactor: linting

* Cldc 1538 la nominations (#1115)

* Add la nominations column to sales logs table

* Add La nominations page and questions

* Add la nominations to the shared ownership subsection

* Add accidentally removed files

* feat: add question(s) without depends_on behaviour

Co-authored-by: kosiakkatrina <54268893+kosiakkatrina@users.noreply.github.com>

* Cldc 1533 is resale (#1118)

* feat: add resale question and page

* tests: add new tests

* test: update previous tests

* refactor: linting

* refactor: linting

* Cldc 1576 buyer prp (#1117)

* Add soctenant field to sales logs

* Add buyer previous page and question

* Add buyer previous page to shared ownership scheme subsection

* rebase migrate

* rebase too

* Cldc 1540 about price (#1121)

* add price fields to the sales logs table

* Add about proce questions

* add about proce pages

* Add about price pages to sale information sections

* rebase changes

* happy new year

* Switch the order of sales log sections

* Cldc 1540 fixes (#1130)

* Update order of pages and remove wrong id's

* Add spacing to the hint text

* Cldc 1521 living before purchase (#1129)

* feat: add new page and question and update db

* test: add and update tests

* feat: reset db

* Only display from beds for social housing (#1131)

* Cldc 1544 mortgage amount (#1136)

* feat: add sales log seeds

* feat: add question and page and update db

* tests: add and update tests

* Cldc 1540 fixes part two (#1135)

* Change about_price_social_housing to about_price_shared_ownership and display it in all shared ownership cases

* Change about_price to purchase_price and display it for outright sale

* lint

* Move exchange contracts date page (#1143)

* feat: PO fix and tests (#1144)

* feat: PO fix and tests

* feat: simmplification

* refactor: linting

* feat: copy tweak

Co-authored-by: natdeanlewissoftwire <94526761+natdeanlewissoftwire@users.noreply.github.com>
Co-authored-by: natdeanlewissoftwire <nat.dean-lewis@softwire.com>
pull/1093/head
kosiakkatrina 2 years ago committed by GitHub
parent
commit
6102b50ebe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 5
      app/models/derived_variables/sales_log_variables.rb
  2. 17
      app/models/form/sales/pages/about_deposit_with_discount.rb
  3. 15
      app/models/form/sales/pages/about_deposit_without_discount.rb
  4. 19
      app/models/form/sales/pages/about_price_not_rtb.rb
  5. 19
      app/models/form/sales/pages/about_price_rtb.rb
  6. 16
      app/models/form/sales/pages/about_price_shared_ownership.rb
  7. 19
      app/models/form/sales/pages/about_staircase.rb
  8. 15
      app/models/form/sales/pages/buyer_previous.rb
  9. 18
      app/models/form/sales/pages/exchange_date.rb
  10. 15
      app/models/form/sales/pages/la_nominations.rb
  11. 14
      app/models/form/sales/pages/living_before_purchase.rb
  12. 15
      app/models/form/sales/pages/monthly_rent.rb
  13. 14
      app/models/form/sales/pages/mortgage_amount.rb
  14. 18
      app/models/form/sales/pages/previous_bedrooms.rb
  15. 15
      app/models/form/sales/pages/purchase_price.rb
  16. 23
      app/models/form/sales/pages/resale.rb
  17. 15
      app/models/form/sales/pages/staircase.rb
  18. 16
      app/models/form/sales/questions/buyer_previous.rb
  19. 14
      app/models/form/sales/questions/deposit_amount.rb
  20. 14
      app/models/form/sales/questions/deposit_discount.rb
  21. 17
      app/models/form/sales/questions/discount.rb
  22. 15
      app/models/form/sales/questions/equity.rb
  23. 10
      app/models/form/sales/questions/exchange_date.rb
  24. 14
      app/models/form/sales/questions/grant.rb
  25. 18
      app/models/form/sales/questions/la_nominations.rb
  26. 16
      app/models/form/sales/questions/living_before_purchase.rb
  27. 14
      app/models/form/sales/questions/monthly_rent.rb
  28. 14
      app/models/form/sales/questions/mortgage_amount.rb
  29. 13
      app/models/form/sales/questions/previous_bedrooms.rb
  30. 14
      app/models/form/sales/questions/purchase_price.rb
  31. 17
      app/models/form/sales/questions/resale.rb
  32. 18
      app/models/form/sales/questions/staircase.rb
  33. 14
      app/models/form/sales/questions/staircase_bought.rb
  34. 14
      app/models/form/sales/questions/staircase_owned.rb
  35. 14
      app/models/form/sales/questions/value.rb
  36. 14
      app/models/form/sales/sections/sale_information.rb
  37. 23
      app/models/form/sales/subsections/discounted_ownership_scheme.rb
  38. 21
      app/models/form/sales/subsections/outright_sale.rb
  39. 31
      app/models/form/sales/subsections/shared_ownership_scheme.rb
  40. 8
      app/models/form/subsection.rb
  41. 1
      app/models/form_handler.rb
  42. 2
      app/models/log.rb
  43. 8
      app/models/sales_log.rb
  44. 2
      app/views/logs/_tasklist.html.erb
  45. 7
      db/migrate/20221220155625_add_from_beds_to_sales.rb
  46. 7
      db/migrate/20221220174515_add_staircase_to_sales.rb
  47. 8
      db/migrate/20221221081709_add_staircase_fields_to_sales.rb
  48. 7
      db/migrate/20221221105502_add_rent_to_sales.rb
  49. 11
      db/migrate/20221221122233_add_exchange_contracts_to_sales.rb
  50. 8
      db/migrate/20221221164308_add_deposit_fields_to_sales.rb
  51. 7
      db/migrate/20221222081402_add_la_nominations.rb
  52. 7
      db/migrate/20221222120105_add_soctenant.rb
  53. 10
      db/migrate/20221222133600_add_price_fields.rb
  54. 7
      db/migrate/20230103094948_add_proplen_to_sales.rb
  55. 13
      db/migrate/20230104093057_change_mortgage_to_float.rb
  56. 23
      db/schema.rb
  57. 32
      db/seeds.rb
  58. 5
      spec/factories/sales_log.rb
  59. 35
      spec/models/form/sales/pages/about_deposit_with_discount_spec.rb
  60. 35
      spec/models/form/sales/pages/about_deposit_without_discount_spec.rb
  61. 35
      spec/models/form/sales/pages/about_price_not_rtb_spec.rb
  62. 35
      spec/models/form/sales/pages/about_price_rtb_spec.rb
  63. 33
      spec/models/form/sales/pages/about_price_shared_ownership_spec.rb
  64. 35
      spec/models/form/sales/pages/about_staircase_spec.rb
  65. 29
      spec/models/form/sales/pages/buyer_previous_spec.rb
  66. 35
      spec/models/form/sales/pages/exchange_date_spec.rb
  67. 29
      spec/models/form/sales/pages/la_nominations_spec.rb
  68. 33
      spec/models/form/sales/pages/living_before_purchase_spec.rb
  69. 33
      spec/models/form/sales/pages/monthly_rent_spec.rb
  70. 33
      spec/models/form/sales/pages/mortgage_amount_spec.rb
  71. 35
      spec/models/form/sales/pages/previous_bedrooms_spec.rb
  72. 33
      spec/models/form/sales/pages/purchase_price_spec.rb
  73. 40
      spec/models/form/sales/pages/resale_spec.rb
  74. 29
      spec/models/form/sales/pages/staircase_spec.rb
  75. 48
      spec/models/form/sales/questions/buyer_previous_spec.rb
  76. 49
      spec/models/form/sales/questions/deposit_amount_spec.rb
  77. 49
      spec/models/form/sales/questions/deposit_discount_spec.rb
  78. 55
      spec/models/form/sales/questions/discount_spec.rb
  79. 53
      spec/models/form/sales/questions/equity_spec.rb
  80. 33
      spec/models/form/sales/questions/exchange_date_spec.rb
  81. 49
      spec/models/form/sales/questions/grant_spec.rb
  82. 49
      spec/models/form/sales/questions/la_nominations_spec.rb
  83. 57
      spec/models/form/sales/questions/living_before_purchase_spec.rb
  84. 49
      spec/models/form/sales/questions/monthly_rent_spec.rb
  85. 49
      spec/models/form/sales/questions/mortgage_amount_spec.rb
  86. 45
      spec/models/form/sales/questions/previous_bedrooms_spec.rb
  87. 49
      spec/models/form/sales/questions/purchase_price_spec.rb
  88. 48
      spec/models/form/sales/questions/resale_spec.rb
  89. 57
      spec/models/form/sales/questions/staircase_bought_spec.rb
  90. 57
      spec/models/form/sales/questions/staircase_owned_spec.rb
  91. 49
      spec/models/form/sales/questions/staircase_spec.rb
  92. 49
      spec/models/form/sales/questions/value_spec.rb
  93. 33
      spec/models/form/sales/sections/sale_information_spec.rb
  94. 57
      spec/models/form/sales/subsections/discounted_ownership_scheme_spec.rb
  95. 53
      spec/models/form/sales/subsections/outright_sale_spec.rb
  96. 65
      spec/models/form/sales/subsections/shared_ownership_scheme_spec.rb
  97. 4
      spec/models/form_handler_spec.rb
  98. 15
      spec/models/lettings_log_spec.rb
  99. 15
      spec/models/sales_log_spec.rb

5
app/models/derived_variables/sales_log_variables.rb

@ -1,5 +1,10 @@
module DerivedVariables::SalesLogVariables
def set_derived_fields!
self.ethnic = 17 if ethnic_refused?
if exdate.present?
self.exday = exdate.day
self.exmonth = exdate.month
self.exyear = exdate.year
end
end
end

17
app/models/form/sales/pages/about_deposit_with_discount.rb

@ -0,0 +1,17 @@
class Form::Sales::Pages::AboutDepositWithDiscount < ::Form::Page
def initialize(id, hsh, subsection)
super
@id = "about_deposit_with_discount"
@header = "About the deposit"
@description = ""
@subsection = subsection
@depends_on = [{ "is_type_discount?" => true }]
end
def questions
@questions ||= [
Form::Sales::Questions::DepositAmount.new(nil, nil, self),
Form::Sales::Questions::DepositDiscount.new(nil, nil, self),
]
end
end

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

@ -0,0 +1,15 @@
class Form::Sales::Pages::AboutDepositWithoutDiscount < ::Form::Page
def initialize(id, hsh, subsection)
super
@header = "About the deposit"
@description = ""
@subsection = subsection
@depends_on = [{ "is_type_discount?" => false }]
end
def questions
@questions ||= [
Form::Sales::Questions::DepositAmount.new(nil, nil, self),
]
end
end

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

@ -0,0 +1,19 @@
class Form::Sales::Pages::AboutPriceNotRtb < ::Form::Page
def initialize(id, hsh, subsection)
super
@id = "about_price_not_rtb"
@header = "About the price of the property"
@description = ""
@subsection = subsection
@depends_on = [{
"right_to_buy?" => false,
}]
end
def questions
@questions ||= [
Form::Sales::Questions::Value.new(nil, nil, self),
Form::Sales::Questions::Grant.new(nil, nil, self),
]
end
end

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

@ -0,0 +1,19 @@
class Form::Sales::Pages::AboutPriceRtb < ::Form::Page
def initialize(id, hsh, subsection)
super
@id = "about_price_rtb"
@header = "About the price of the property"
@description = ""
@subsection = subsection
@depends_on = [{
"right_to_buy?" => true,
}]
end
def questions
@questions ||= [
Form::Sales::Questions::Value.new(nil, nil, self),
Form::Sales::Questions::Discount.new(nil, nil, self),
]
end
end

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

@ -0,0 +1,16 @@
class Form::Sales::Pages::AboutPriceSharedOwnership < ::Form::Page
def initialize(id, hsh, subsection)
super
@id = "about_price_shared_ownership"
@header = "About the price of the property"
@description = ""
@subsection = subsection
end
def questions
@questions ||= [
Form::Sales::Questions::Value.new(nil, nil, self),
Form::Sales::Questions::Equity.new(nil, nil, self),
]
end
end

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

@ -0,0 +1,19 @@
class Form::Sales::Pages::AboutStaircase < ::Form::Page
def initialize(id, hsh, subsection)
super
@id = "about_staircasing"
@header = "About the staircasing transaction"
@description = ""
@subsection = subsection
@depends_on = [{
"staircase" => 1,
}]
end
def questions
@questions ||= [
Form::Sales::Questions::StaircaseBought.new(nil, nil, self),
Form::Sales::Questions::StaircaseOwned.new(nil, nil, self),
]
end
end

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

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

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

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

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

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

14
app/models/form/sales/pages/living_before_purchase.rb

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

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

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

14
app/models/form/sales/pages/mortgage_amount.rb

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

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

@ -0,0 +1,18 @@
class Form::Sales::Pages::PreviousBedrooms < ::Form::Page
def initialize(id, hsh, subsection)
super
@id = "previous_bedrooms"
@header = "About the buyers’ previous property"
@description = ""
@subsection = subsection
@depends_on = [{
"soctenant" => 1,
}]
end
def questions
@questions ||= [
Form::Sales::Questions::PreviousBedrooms.new(nil, nil, self),
]
end
end

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

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

23
app/models/form/sales/pages/resale.rb

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

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

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

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

@ -0,0 +1,16 @@
class Form::Sales::Questions::BuyerPrevious < ::Form::Question
def initialize(id, hsh, page)
super
@id = "soctenant"
@check_answer_label = "Buyer was a registered provider, housing association or local authority tenant immediately before this sale?"
@header = "Was the buyer a private registered provider, housing association or local authority tenant immediately before this sale?"
@type = "radio"
@answer_options = ANSWER_OPTIONS
@page = page
end
ANSWER_OPTIONS = {
"1" => { "value" => "Yes" },
"2" => { "value" => "No" },
}.freeze
end

14
app/models/form/sales/questions/deposit_amount.rb

@ -0,0 +1,14 @@
class Form::Sales::Questions::DepositAmount < ::Form::Question
def initialize(id, hsh, page)
super
@id = "deposit"
@check_answer_label = "Cash deposit"
@header = "How much cash deposit was paid on the property?"
@type = "numeric"
@page = page
@min = 0
@width = 5
@prefix = "£"
@hint_text = "Enter the total cash sum paid by the buyer towards the property that was not funded by the mortgage"
end
end

14
app/models/form/sales/questions/deposit_discount.rb

@ -0,0 +1,14 @@
class Form::Sales::Questions::DepositDiscount < ::Form::Question
def initialize(id, hsh, page)
super
@id = "cashdis"
@check_answer_label = "Cash discount through SocialHomeBuy"
@header = "How much cash discount was given through Social HomeBuy?"
@type = "numeric"
@page = page
@min = 0
@width = 5
@prefix = "£"
@hint_text = "Enter the total cash discount given on the property being purchased through the Social HomeBuy scheme"
end
end

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

@ -0,0 +1,17 @@
class Form::Sales::Questions::Discount < ::Form::Question
def initialize(id, hsh, page)
super
@id = "discount"
@check_answer_label = "Percentage discount"
@header = "What was the percentage discount?"
@type = "numeric"
@page = page
@min = 0
@max = 100
@width = 5
@suffix = "%"
@hint_text = "For Right to Buy (RTB), Preserved Right to Buy (PRTB), and Voluntary Right to Buy (VRTB)</br></br>
If discount capped, enter capped %</br></br>
If the property is being sold to an existing tenant under the RTB, PRTB, or VRTB schemes, enter the % discount from the full market value that is being given."
end
end

15
app/models/form/sales/questions/equity.rb

@ -0,0 +1,15 @@
class Form::Sales::Questions::Equity < ::Form::Question
def initialize(id, hsh, page)
super
@id = "equity"
@check_answer_label = "Initial percentage equity stake"
@header = "What was the initial percentage equity stake purchased?"
@type = "numeric"
@page = page
@min = 0
@max = 100
@width = 5
@suffix = "%"
@hint_text = "Enter the amount of initial equity held by the purchaser (for example, 25% or 50%)"
end
end

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

@ -0,0 +1,10 @@
class Form::Sales::Questions::ExchangeDate < ::Form::Question
def initialize(id, hsh, page)
super
@id = "exdate"
@check_answer_label = "Exchange of contracts date"
@header = "What is the exchange of contracts date?"
@type = "date"
@page = page
end
end

14
app/models/form/sales/questions/grant.rb

@ -0,0 +1,14 @@
class Form::Sales::Questions::Grant < ::Form::Question
def initialize(id, hsh, page)
super
@id = "grant"
@check_answer_label = "Amount of any loan, grant or subsidy"
@header = "What was the amount of any loan, grant, discount or subsidy given?"
@type = "numeric"
@page = page
@min = 0
@width = 5
@prefix = "£"
@hint_text = "For all schemes except Right to Buy (RTB), Preserved Right to Buy (PRTB), Voluntary Right to Buy (VRTB)"
end
end

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

@ -0,0 +1,18 @@
class Form::Sales::Questions::LaNominations < ::Form::Question
def initialize(id, hsh, page)
super
@id = "lanomagr"
@check_answer_label = "Household rehoused under a local authority nominations agreement?"
@header = "Was the household rehoused under a 'local authority nominations agreement'?"
@type = "radio"
@answer_options = ANSWER_OPTIONS
@page = page
@hint_text = "A local authority nominations agreement is a written agreement between a local authority and private registered provider (PRP) that some or all of its sales vacancies are offered to local authorities for rehousing"
end
ANSWER_OPTIONS = {
"1" => { "value" => "Yes" },
"2" => { "value" => "No" },
"3" => { "value" => "Don’t know" },
}.freeze
end

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

@ -0,0 +1,16 @@
class Form::Sales::Questions::LivingBeforePurchase < ::Form::Question
def initialize(id, hsh, page)
super
@id = "proplen"
@check_answer_label = "Number of years living in the property before purchase"
@header = "How long did the buyer(s) live in the property before purchase?"
@hint_text = "You should round this up to the nearest year. If the buyers haven't been living in the property, enter '0'"
@type = "numeric"
@page = page
@min = 0
@max = 80
@step = 1
@width = 5
@suffix = " years"
end
end

14
app/models/form/sales/questions/monthly_rent.rb

@ -0,0 +1,14 @@
class Form::Sales::Questions::MonthlyRent < ::Form::Question
def initialize(id, hsh, page)
super
@id = "mrent"
@check_answer_label = "Monthly rent"
@header = "What is the basic monthly rent?"
@type = "numeric"
@page = page
@min = 0
@width = 5
@prefix = "£"
@hint_text = "Amount paid before any charges"
end
end

14
app/models/form/sales/questions/mortgage_amount.rb

@ -0,0 +1,14 @@
class Form::Sales::Questions::MortgageAmount < ::Form::Question
def initialize(id, hsh, page)
super
@id = "mortgage"
@check_answer_label = "Mortgage amount"
@header = "What is the mortgage amount?"
@type = "numeric"
@page = page
@min = 0
@width = 5
@prefix = "£"
@hint_text = ""
end
end

13
app/models/form/sales/questions/previous_bedrooms.rb

@ -0,0 +1,13 @@
class Form::Sales::Questions::PreviousBedrooms < ::Form::Question
def initialize(id, hsh, page)
super
@id = "frombeds"
@check_answer_label = "Number of bedrooms in previous property"
@header = "How many bedrooms did the property have?"
@type = "numeric"
@page = page
@width = 5
@min = 0
@hint_text = "For bedsits enter 1"
end
end

14
app/models/form/sales/questions/purchase_price.rb

@ -0,0 +1,14 @@
class Form::Sales::Questions::PurchasePrice < ::Form::Question
def initialize(id, hsh, page)
super
@id = "value"
@check_answer_label = "Purchase price"
@header = "What is the full purchase price?"
@type = "numeric"
@page = page
@min = 0
@width = 5
@prefix = "£"
@hint_text = ""
end
end

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

@ -0,0 +1,17 @@
class Form::Sales::Questions::Resale < ::Form::Question
def initialize(id, hsh, page)
super
@id = "resale"
@check_answer_label = "Is this a resale?"
@header = "Is this a resale?"
@type = "radio"
@answer_options = ANSWER_OPTIONS
@page = page
@hint_text = "If the social landlord has previously sold the property to another buyer and is now reselling the property, select 'yes'. If this is the first time the property has been sold, select 'no'."
end
ANSWER_OPTIONS = {
"1" => { "value" => "Yes" },
"2" => { "value" => "No" },
}.freeze
end

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

@ -0,0 +1,18 @@
class Form::Sales::Questions::Staircase < ::Form::Question
def initialize(id, hsh, page)
super
@id = "staircase"
@check_answer_label = "Staircasing transaction"
@header = "Is this a staircasing transaction?"
@type = "radio"
@answer_options = ANSWER_OPTIONS
@page = page
@hint_text = "A staircasing transaction is when the household purchases more shares in their property, increasing the proportion they own and decreasing the proportion the housing association owns. Once the household purchases 100% of the shares, they own the property"
end
ANSWER_OPTIONS = {
"1" => { "value" => "Yes" },
"2" => { "value" => "No" },
"3" => { "value" => "Don’t know" },
}.freeze
end

14
app/models/form/sales/questions/staircase_bought.rb

@ -0,0 +1,14 @@
class Form::Sales::Questions::StaircaseBought < ::Form::Question
def initialize(id, hsh, page)
super
@id = "stairbought"
@check_answer_label = "Percentage bought in this staircasing transaction"
@header = "What percentage of the property has been bought in this staircasing transaction?"
@type = "numeric"
@page = page
@width = 5
@min = 0
@max = 100
@suffix = " percent"
end
end

14
app/models/form/sales/questions/staircase_owned.rb

@ -0,0 +1,14 @@
class Form::Sales::Questions::StaircaseOwned < ::Form::Question
def initialize(id, hsh, page)
super
@id = "stairowned"
@check_answer_label = "Percentage the buyer now owns in total"
@header = "What percentage of the property does the buyer now own in total?"
@type = "numeric"
@page = page
@width = 5
@min = 0
@max = 100
@suffix = " percent"
end
end

14
app/models/form/sales/questions/value.rb

@ -0,0 +1,14 @@
class Form::Sales::Questions::Value < ::Form::Question
def initialize(id, hsh, page)
super
@id = "value"
@check_answer_label = "Full purchase price"
@header = "What was the full purchase price?"
@type = "numeric"
@page = page
@min = 0
@width = 5
@prefix = "£"
@hint_text = "Enter the full purchase price of the property before any discounts are applied. For shared ownership, enter the full purchase price paid for 100% equity (this is equal to the value of the share owned by the PRP plus the value bought by the purchaser)"
end
end

14
app/models/form/sales/sections/sale_information.rb

@ -0,0 +1,14 @@
class Form::Sales::Sections::SaleInformation < ::Form::Section
def initialize(id, hsh, form)
super
@id = "sale_information"
@label = "Sale information"
@description = ""
@form = form
@subsections = [
Form::Sales::Subsections::SharedOwnershipScheme.new(nil, nil, self),
Form::Sales::Subsections::DiscountedOwnershipScheme.new(nil, nil, self),
Form::Sales::Subsections::OutrightSale.new(nil, nil, self),
] || []
end
end

23
app/models/form/sales/subsections/discounted_ownership_scheme.rb

@ -0,0 +1,23 @@
class Form::Sales::Subsections::DiscountedOwnershipScheme < ::Form::Subsection
def initialize(id, hsh, section)
super
@id = "discounted_ownership_scheme"
@label = "Discounted ownership scheme"
@section = section
@depends_on = [{ "ownershipsch" => 2, "setup_completed?" => true }]
end
def pages
@pages ||= [
Form::Sales::Pages::LivingBeforePurchase.new("living_before_purchase_discounted_ownership", nil, self),
Form::Sales::Pages::AboutPriceRtb.new(nil, nil, self),
Form::Sales::Pages::AboutPriceNotRtb.new(nil, nil, self),
Form::Sales::Pages::MortgageAmount.new("mortgage_amount_discounted_ownership", nil, self),
Form::Sales::Pages::AboutDepositWithoutDiscount.new("about_deposit_discounted_ownership", nil, self),
]
end
def displayed_in_tasklist?(log)
log.ownershipsch == 2
end
end

21
app/models/form/sales/subsections/outright_sale.rb

@ -0,0 +1,21 @@
class Form::Sales::Subsections::OutrightSale < ::Form::Subsection
def initialize(id, hsh, section)
super
@id = "outright_sale"
@label = "Outright sale"
@section = section
@depends_on = [{ "ownershipsch" => 3, "setup_completed?" => true }]
end
def pages
@pages ||= [
Form::Sales::Pages::PurchasePrice.new(nil, nil, self),
Form::Sales::Pages::MortgageAmount.new("mortgage_amount_outright_sale", nil, self),
Form::Sales::Pages::AboutDepositWithoutDiscount.new("about_deposit_outright_sale", nil, self),
]
end
def displayed_in_tasklist?(log)
log.ownershipsch == 3
end
end

31
app/models/form/sales/subsections/shared_ownership_scheme.rb

@ -0,0 +1,31 @@
class Form::Sales::Subsections::SharedOwnershipScheme < ::Form::Subsection
def initialize(id, hsh, section)
super
@id = "shared_ownership_scheme"
@label = "Shared ownership scheme"
@section = section
@depends_on = [{ "ownershipsch" => 1, "setup_completed?" => true }]
end
def pages
@pages ||= [
Form::Sales::Pages::LivingBeforePurchase.new("living_before_purchase_shared_ownership", nil, self),
Form::Sales::Pages::Staircase.new(nil, nil, self),
Form::Sales::Pages::AboutStaircase.new(nil, nil, self),
Form::Sales::Pages::Resale.new(nil, nil, self),
Form::Sales::Pages::ExchangeDate.new(nil, nil, self),
Form::Sales::Pages::LaNominations.new(nil, nil, self),
Form::Sales::Pages::BuyerPrevious.new(nil, nil, self),
Form::Sales::Pages::PreviousBedrooms.new(nil, nil, self),
Form::Sales::Pages::AboutPriceSharedOwnership.new(nil, nil, self),
Form::Sales::Pages::MortgageAmount.new("mortgage_amount_shared_ownership", nil, self),
Form::Sales::Pages::AboutDepositWithDiscount.new(nil, nil, self),
Form::Sales::Pages::AboutDepositWithoutDiscount.new("about_deposit_shared_ownership", nil, self),
Form::Sales::Pages::MonthlyRent.new(nil, nil, self),
]
end
def displayed_in_tasklist?(log)
log.ownershipsch == 1
end
end

8
app/models/form/subsection.rb

@ -24,9 +24,7 @@ class Form::Subsection
end
def status(log)
unless enabled?(log)
return :cannot_start_yet
end
return :cannot_start_yet unless enabled?(log)
qs = applicable_questions(log)
qs_optional_removed = qs.reject { |q| log.optional_fields.include?(q.id) }
@ -49,4 +47,8 @@ class Form::Subsection
(q.displayed_to_user?(log) && !q.derived?) || q.has_inferred_check_answers_value?(log)
end
end
def displayed_in_tasklist?(_log)
true
end
end

1
app/models/form_handler.rb

@ -23,6 +23,7 @@ class FormHandler
Form::Sales::Sections::PropertyInformation,
Form::Sales::Sections::Household,
Form::Sales::Sections::Finances,
Form::Sales::Sections::SaleInformation,
]
current_form = Form.new(nil, current_collection_start_year, sales_sections, "sales")
previous_form = Form.new(nil, current_collection_start_year - 1, sales_sections, "sales")

2
app/models/log.rb

@ -63,7 +63,7 @@ private
end
def all_fields_completed?
subsection_statuses = form.subsections.map { |subsection| subsection.status(self) }.uniq
subsection_statuses = form.subsections.map { |subsection| subsection.status(self) if subsection.displayed_in_tasklist?(self) }.uniq.compact
subsection_statuses == [:completed]
end

8
app/models/sales_log.rb

@ -111,4 +111,12 @@ class SalesLog < Log
def income2_used_for_mortgage?
inc2mort == 1
end
def right_to_buy?
[9, 14, 27].include?(type)
end
def is_type_discount?
type == 18
end
end

2
app/views/logs/_tasklist.html.erb

@ -9,7 +9,7 @@
<% end %>
<ul class="app-task-list__items">
<% section.subsections.map do |subsection| %>
<% if subsection.applicable_questions(@log).count > 0 || !subsection.enabled?(@log) %>
<% if subsection.displayed_in_tasklist?(@log) && (subsection.applicable_questions(@log).count > 0 || !subsection.enabled?(@log)) %>
<% subsection_status = subsection.status(@log) %>
<li class="app-task-list__item">
<span class="app-task-list__task-name" id="<%= subsection.id.dasherize %>">

7
db/migrate/20221220155625_add_from_beds_to_sales.rb

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

7
db/migrate/20221220174515_add_staircase_to_sales.rb

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

8
db/migrate/20221221081709_add_staircase_fields_to_sales.rb

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

7
db/migrate/20221221105502_add_rent_to_sales.rb

@ -0,0 +1,7 @@
class AddRentToSales < ActiveRecord::Migration[7.0]
def change
change_table :sales_logs, bulk: true do |t|
t.column :mrent, :decimal, precision: 10, scale: 2
end
end
end

11
db/migrate/20221221122233_add_exchange_contracts_to_sales.rb

@ -0,0 +1,11 @@
class AddExchangeContractsToSales < ActiveRecord::Migration[7.0]
def change
change_table :sales_logs, bulk: true do |t|
t.column :exdate, :datetime
t.column :exday, :integer
t.column :exmonth, :integer
t.column :exyear, :integer
t.column :resale, :integer
end
end
end

8
db/migrate/20221221164308_add_deposit_fields_to_sales.rb

@ -0,0 +1,8 @@
class AddDepositFieldsToSales < ActiveRecord::Migration[7.0]
def change
change_table :sales_logs, bulk: true do |t|
t.column :deposit, :decimal, precision: 10, scale: 2
t.column :cashdis, :decimal, precision: 10, scale: 2
end
end
end

7
db/migrate/20221222081402_add_la_nominations.rb

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

7
db/migrate/20221222120105_add_soctenant.rb

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

10
db/migrate/20221222133600_add_price_fields.rb

@ -0,0 +1,10 @@
class AddPriceFields < ActiveRecord::Migration[7.0]
def change
change_table :sales_logs, bulk: true do |t|
t.column :value, :decimal, precision: 10, scale: 2
t.column :equity, :decimal, precision: 10, scale: 2
t.column :discount, :decimal, precision: 10, scale: 2
t.column :grant, :decimal, precision: 10, scale: 2
end
end
end

7
db/migrate/20230103094948_add_proplen_to_sales.rb

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

13
db/migrate/20230104093057_change_mortgage_to_float.rb

@ -0,0 +1,13 @@
class ChangeMortgageToFloat < ActiveRecord::Migration[7.0]
def self.up
change_table :sales_logs do |t|
t.change :mortgage, :decimal, precision: 10, scale: 2
end
end
def self.down
change_table :sales_logs do |t|
t.change :mortgage, :integer
end
end
end

23
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_12_21_172821) do
ActiveRecord::Schema[7.0].define(version: 2023_01_04_093057) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@ -408,14 +408,33 @@ ActiveRecord::Schema[7.0].define(version: 2022_12_21_172821) do
t.bigint "updated_by_id"
t.integer "details_known_1"
t.integer "income1_value_check"
t.integer "mortgage"
t.decimal "mortgage", precision: 10, scale: 2
t.integer "inc2mort"
t.integer "mortgage_value_check"
t.integer "ecstat3"
t.integer "ecstat4"
t.integer "ecstat5"
t.integer "ecstat6"
t.integer "frombeds"
t.integer "staircase"
t.integer "stairbought"
t.integer "stairowned"
t.decimal "mrent", precision: 10, scale: 2
t.datetime "exdate", precision: nil
t.integer "exday"
t.integer "exmonth"
t.integer "exyear"
t.integer "resale"
t.decimal "deposit", precision: 10, scale: 2
t.decimal "cashdis", precision: 10, scale: 2
t.integer "disabled"
t.integer "lanomagr"
t.integer "soctenant"
t.decimal "value", precision: 10, scale: 2
t.decimal "equity", precision: 10, scale: 2
t.decimal "discount", precision: 10, scale: 2
t.decimal "grant", precision: 10, scale: 2
t.integer "proplen"
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"

32
db/seeds.rb

@ -146,6 +146,36 @@ unless Rails.env.test?
child_organisation: managing_agent2,
)
if (Rails.env.development? || Rails.env.review?) && SalesLog.count.zero?
SalesLog.find_or_create_by!(
saledate: Date.new(1, 1, 1),
purchid: "1",
ownershipsch: 1,
type: 2,
jointpur: 1,
jointmore: 1,
)
SalesLog.find_or_create_by!(
saledate: Date.new(1, 1, 1),
purchid: "1",
ownershipsch: 2,
type: 8,
jointpur: 1,
jointmore: 1,
)
SalesLog.find_or_create_by!(
saledate: Date.new(1, 1, 1),
purchid: "1",
ownershipsch: 3,
type: 10,
companybuy: 1,
)
pp "Seeded a sales log of each type"
end
if Rails.env.development? || Rails.env.review?
User.find_or_create_by!(
name: "Provider",
@ -273,9 +303,9 @@ unless Rails.env.test?
units: 1,
mobility_type: "W",
)
pp "Seeded 3 dummy schemes"
end
pp "Seeded 3 dummy schemes"
if LaRentRange.count.zero?
Dir.glob("config/rent_range_data/*.csv").each do |path|
start_year = File.basename(path, ".csv")

5
spec/factories/sales_log.rb

@ -68,6 +68,11 @@ FactoryBot.define do
ecstat5 { 2 }
ecstat6 { 1 }
disabled { 2 }
deposit { 10_000 }
cashdis { 1_000 }
value { 110_000 }
grant { 1_000 }
proplen { 10 }
end
end
end

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

@ -0,0 +1,35 @@
require "rails_helper"
RSpec.describe Form::Sales::Pages::AboutDepositWithDiscount, 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[deposit cashdis])
end
it "has the correct id" do
expect(page.id).to eq("about_deposit_with_discount")
end
it "has the correct header" do
expect(page.header).to eq("About the deposit")
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(
[{ "is_type_discount?" => true }],
)
end
end

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

@ -0,0 +1,35 @@
require "rails_helper"
RSpec.describe Form::Sales::Pages::AboutDepositWithoutDiscount, 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[deposit])
end
it "has the correct id" do
expect(page.id).to eq(nil)
end
it "has the correct header" do
expect(page.header).to eq("About the deposit")
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(
[{ "is_type_discount?" => false }],
)
end
end

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

@ -0,0 +1,35 @@
require "rails_helper"
RSpec.describe Form::Sales::Pages::AboutPriceNotRtb, 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[value grant])
end
it "has the correct id" do
expect(page.id).to eq("about_price_not_rtb")
end
it "has the correct header" do
expect(page.header).to eq("About the price of the property")
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([{
"right_to_buy?" => false,
}])
end
end

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

@ -0,0 +1,35 @@
require "rails_helper"
RSpec.describe Form::Sales::Pages::AboutPriceRtb, 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[value discount])
end
it "has the correct id" do
expect(page.id).to eq("about_price_rtb")
end
it "has the correct header" do
expect(page.header).to eq("About the price of the property")
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([{
"right_to_buy?" => true,
}])
end
end

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

@ -0,0 +1,33 @@
require "rails_helper"
RSpec.describe Form::Sales::Pages::AboutPriceSharedOwnership, 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[value equity])
end
it "has the correct id" do
expect(page.id).to eq("about_price_shared_ownership")
end
it "has the correct header" do
expect(page.header).to eq("About the price of the property")
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

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

@ -0,0 +1,35 @@
require "rails_helper"
RSpec.describe Form::Sales::Pages::AboutStaircase, 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[stairbought stairowned])
end
it "has the correct id" do
expect(page.id).to eq("about_staircasing")
end
it "has the correct header" do
expect(page.header).to eq("About the staircasing transaction")
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([{
"staircase" => 1,
}])
end
end

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

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

@ -0,0 +1,35 @@
require "rails_helper"
RSpec.describe Form::Sales::Pages::ExchangeDate, 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[exdate])
end
it "has the correct id" do
expect(page.id).to eq("exchange_contracts")
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([{
"resale" => 2,
}])
end
end

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

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

@ -0,0 +1,33 @@
require "rails_helper"
RSpec.describe Form::Sales::Pages::LivingBeforePurchase, 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[proplen])
end
it "has the correct id" do
expect(page.id).to eq(nil)
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/monthly_rent_spec.rb

@ -0,0 +1,33 @@
require "rails_helper"
RSpec.describe Form::Sales::Pages::MonthlyRent, 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[mrent])
end
it "has the correct id" do
expect(page.id).to eq("monthly_rent")
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/mortgage_amount_spec.rb

@ -0,0 +1,33 @@
require "rails_helper"
RSpec.describe Form::Sales::Pages::MortgageAmount, 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[mortgage])
end
it "has the correct id" do
expect(page.id).to eq(nil)
end
it "has the correct header" do
expect(page.header).to eq("Mortgage Amount")
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

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

@ -0,0 +1,35 @@
require "rails_helper"
RSpec.describe Form::Sales::Pages::PreviousBedrooms, 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[frombeds])
end
it "has the correct id" do
expect(page.id).to eq("previous_bedrooms")
end
it "has the correct header" do
expect(page.header).to eq("About the buyers’ previous property")
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([{
"soctenant" => 1,
}])
end
end

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

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

40
spec/models/form/sales/pages/resale_spec.rb

@ -0,0 +1,40 @@
require "rails_helper"
RSpec.describe Form::Sales::Pages::Resale, 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[resale])
end
it "has the correct id" do
expect(page.id).to eq("resale")
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(
[{
"staircase" => 2,
},
{
"staircase" => 3,
}],
)
end
end

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

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

48
spec/models/form/sales/questions/buyer_previous_spec.rb

@ -0,0 +1,48 @@
require "rails_helper"
RSpec.describe Form::Sales::Questions::BuyerPrevious, 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("soctenant")
end
it "has the correct header" do
expect(question.header).to eq("Was the buyer a private registered provider, housing association or local authority tenant immediately before this sale?")
end
it "has the correct check_answer_label" do
expect(question.check_answer_label).to eq("Buyer was a registered provider, housing association or local authority tenant immediately before this sale?")
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" => "Yes" },
"2" => { "value" => "No" },
})
end
it "has correct conditional for" do
expect(question.conditional_for).to eq(nil)
end
it "has the correct hint" do
expect(question.hint_text).to eq(nil)
end
end

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

@ -0,0 +1,49 @@
require "rails_helper"
RSpec.describe Form::Sales::Questions::DepositAmount, 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("deposit")
end
it "has the correct header" do
expect(question.header).to eq("How much cash deposit was paid on the property?")
end
it "has the correct check_answer_label" do
expect(question.check_answer_label).to eq("Cash deposit")
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 eq("Enter the total cash sum paid by the buyer towards the property that was not funded by the mortgage")
end
it "has correct width" do
expect(question.width).to eq(5)
end
it "has correct prefix" do
expect(question.prefix).to eq("£")
end
it "has correct min" do
expect(question.min).to eq(0)
end
end

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

@ -0,0 +1,49 @@
require "rails_helper"
RSpec.describe Form::Sales::Questions::DepositDiscount, 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("cashdis")
end
it "has the correct header" do
expect(question.header).to eq("How much cash discount was given through Social HomeBuy?")
end
it "has the correct check_answer_label" do
expect(question.check_answer_label).to eq("Cash discount through SocialHomeBuy")
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 eq("Enter the total cash discount given on the property being purchased through the Social HomeBuy scheme")
end
it "has correct width" do
expect(question.width).to eq(5)
end
it "has correct prefix" do
expect(question.prefix).to eq("£")
end
it "has correct min" do
expect(question.min).to eq(0)
end
end

55
spec/models/form/sales/questions/discount_spec.rb

@ -0,0 +1,55 @@
require "rails_helper"
RSpec.describe Form::Sales::Questions::Discount, 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("discount")
end
it "has the correct header" do
expect(question.header).to eq("What was the percentage discount?")
end
it "has the correct check_answer_label" do
expect(question.check_answer_label).to eq("Percentage discount")
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 eq("For Right to Buy (RTB), Preserved Right to Buy (PRTB), and Voluntary Right to Buy (VRTB)</br></br>
If discount capped, enter capped %</br></br>
If the property is being sold to an existing tenant under the RTB, PRTB, or VRTB schemes, enter the % discount from the full market value that is being given.")
end
it "has correct width" do
expect(question.width).to eq(5)
end
it "has correct suffix" do
expect(question.suffix).to eq("%")
end
it "has correct min" do
expect(question.min).to eq(0)
end
it "has correct max" do
expect(question.max).to eq(100)
end
end

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

@ -0,0 +1,53 @@
require "rails_helper"
RSpec.describe Form::Sales::Questions::Equity, 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("equity")
end
it "has the correct header" do
expect(question.header).to eq("What was the initial percentage equity stake purchased?")
end
it "has the correct check_answer_label" do
expect(question.check_answer_label).to eq("Initial percentage equity stake")
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 eq("Enter the amount of initial equity held by the purchaser (for example, 25% or 50%)")
end
it "has correct width" do
expect(question.width).to eq(5)
end
it "has correct suffix" do
expect(question.suffix).to eq("%")
end
it "has correct min" do
expect(question.min).to eq(0)
end
it "has correct max" do
expect(question.max).to eq(100)
end
end

33
spec/models/form/sales/questions/exchange_date_spec.rb

@ -0,0 +1,33 @@
require "rails_helper"
RSpec.describe Form::Sales::Questions::ExchangeDate, 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("exdate")
end
it "has the correct header" do
expect(question.header).to eq("What is the exchange of contracts date?")
end
it "has the correct check_answer_label" do
expect(question.check_answer_label).to eq("Exchange of contracts date")
end
it "has the correct type" do
expect(question.type).to eq("date")
end
it "is not marked as derived" do
expect(question.derived?).to be false
end
end

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

@ -0,0 +1,49 @@
require "rails_helper"
RSpec.describe Form::Sales::Questions::Grant, 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("grant")
end
it "has the correct header" do
expect(question.header).to eq("What was the amount of any loan, grant, discount or subsidy given?")
end
it "has the correct check_answer_label" do
expect(question.check_answer_label).to eq("Amount of any loan, grant or subsidy")
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 eq("For all schemes except Right to Buy (RTB), Preserved Right to Buy (PRTB), Voluntary Right to Buy (VRTB)")
end
it "has correct width" do
expect(question.width).to eq(5)
end
it "has correct prefix" do
expect(question.prefix).to eq("£")
end
it "has correct min" do
expect(question.min).to eq(0)
end
end

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

@ -0,0 +1,49 @@
require "rails_helper"
RSpec.describe Form::Sales::Questions::LaNominations, 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("lanomagr")
end
it "has the correct header" do
expect(question.header).to eq("Was the household rehoused under a 'local authority nominations agreement'?")
end
it "has the correct check_answer_label" do
expect(question.check_answer_label).to eq("Household rehoused under a local authority nominations agreement?")
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" => "Yes" },
"2" => { "value" => "No" },
"3" => { "value" => "Don’t know" },
})
end
it "has correct conditional for" do
expect(question.conditional_for).to eq(nil)
end
it "has the correct hint" do
expect(question.hint_text).to eq("A local authority nominations agreement is a written agreement between a local authority and private registered provider (PRP) that some or all of its sales vacancies are offered to local authorities for rehousing")
end
end

57
spec/models/form/sales/questions/living_before_purchase_spec.rb

@ -0,0 +1,57 @@
require "rails_helper"
RSpec.describe Form::Sales::Questions::LivingBeforePurchase, 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("proplen")
end
it "has the correct header" do
expect(question.header).to eq("How long did the buyer(s) live in the property before purchase?")
end
it "has the correct check_answer_label" do
expect(question.check_answer_label).to eq("Number of years living in the property before purchase")
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 eq("You should round this up to the nearest year. If the buyers haven't been living in the property, enter '0'")
end
it "has correct width" do
expect(question.width).to eq(5)
end
it "has correct step" do
expect(question.step).to eq(1)
end
it "has correct suffix" do
expect(question.suffix).to eq(" years")
end
it "has correct min" do
expect(question.min).to eq(0)
end
it "has correct max" do
expect(question.max).to eq(80)
end
end

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

@ -0,0 +1,49 @@
require "rails_helper"
RSpec.describe Form::Sales::Questions::MonthlyRent, 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("mrent")
end
it "has the correct header" do
expect(question.header).to eq("What is the basic monthly rent?")
end
it "has the correct check_answer_label" do
expect(question.check_answer_label).to eq("Monthly rent")
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 eq("Amount paid before any charges")
end
it "has correct width" do
expect(question.width).to eq(5)
end
it "has correct prefix" do
expect(question.prefix).to eq("£")
end
it "has correct min" do
expect(question.min).to eq(0)
end
end

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

@ -0,0 +1,49 @@
require "rails_helper"
RSpec.describe Form::Sales::Questions::MortgageAmount, 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("mortgage")
end
it "has the correct header" do
expect(question.header).to eq("What is the mortgage amount?")
end
it "has the correct check_answer_label" do
expect(question.check_answer_label).to eq("Mortgage amount")
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 eq("")
end
it "has correct width" do
expect(question.width).to eq(5)
end
it "has correct prefix" do
expect(question.prefix).to eq("£")
end
it "has correct min" do
expect(question.min).to eq(0)
end
end

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

@ -0,0 +1,45 @@
require "rails_helper"
RSpec.describe Form::Sales::Questions::PreviousBedrooms, 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("frombeds")
end
it "has the correct header" do
expect(question.header).to eq("How many bedrooms did the property have?")
end
it "has the correct check_answer_label" do
expect(question.check_answer_label).to eq("Number of bedrooms in previous property")
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 eq("For bedsits enter 1")
end
it "has correct width" do
expect(question.width).to eq(5)
end
it "has correct min" do
expect(question.min).to eq(0)
end
end

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

@ -0,0 +1,49 @@
require "rails_helper"
RSpec.describe Form::Sales::Questions::PurchasePrice, 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("value")
end
it "has the correct header" do
expect(question.header).to eq("What is the full purchase price?")
end
it "has the correct check_answer_label" do
expect(question.check_answer_label).to eq("Purchase price")
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 eq("")
end
it "has correct width" do
expect(question.width).to eq(5)
end
it "has correct prefix" do
expect(question.prefix).to eq("£")
end
it "has correct min" do
expect(question.min).to eq(0)
end
end

48
spec/models/form/sales/questions/resale_spec.rb

@ -0,0 +1,48 @@
require "rails_helper"
RSpec.describe Form::Sales::Questions::Resale, 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("resale")
end
it "has the correct header" do
expect(question.header).to eq("Is this a resale?")
end
it "has the correct check_answer_label" do
expect(question.check_answer_label).to eq("Is this a resale?")
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" => "Yes" },
"2" => { "value" => "No" },
})
end
it "has correct conditional for" do
expect(question.conditional_for).to eq(nil)
end
it "has the correct hint" do
expect(question.hint_text).to eq("If the social landlord has previously sold the property to another buyer and is now reselling the property, select 'yes'. If this is the first time the property has been sold, select 'no'.")
end
end

57
spec/models/form/sales/questions/staircase_bought_spec.rb

@ -0,0 +1,57 @@
require "rails_helper"
RSpec.describe Form::Sales::Questions::StaircaseBought, 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("stairbought")
end
it "has the correct header" do
expect(question.header).to eq("What percentage of the property has been bought in this staircasing transaction?")
end
it "has the correct check_answer_label" do
expect(question.check_answer_label).to eq("Percentage bought in this staircasing transaction")
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(5)
end
it "has the correct inferred check answers value" do
expect(question.inferred_check_answers_value).to eq(nil)
end
it "has correct suffix" do
expect(question.suffix).to eq(" percent")
end
it "has correct min" do
expect(question.min).to eq(0)
end
it "has correct max" do
expect(question.max).to eq(100)
end
end

57
spec/models/form/sales/questions/staircase_owned_spec.rb

@ -0,0 +1,57 @@
require "rails_helper"
RSpec.describe Form::Sales::Questions::StaircaseOwned, 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("stairowned")
end
it "has the correct header" do
expect(question.header).to eq("What percentage of the property does the buyer now own in total?")
end
it "has the correct check_answer_label" do
expect(question.check_answer_label).to eq("Percentage the buyer now owns in total")
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(5)
end
it "has the correct inferred check answers value" do
expect(question.inferred_check_answers_value).to eq(nil)
end
it "has correct suffix" do
expect(question.suffix).to eq(" percent")
end
it "has correct min" do
expect(question.min).to eq(0)
end
it "has correct max" do
expect(question.max).to eq(100)
end
end

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

@ -0,0 +1,49 @@
require "rails_helper"
RSpec.describe Form::Sales::Questions::Staircase, 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("staircase")
end
it "has the correct header" do
expect(question.header).to eq("Is this a staircasing transaction?")
end
it "has the correct check_answer_label" do
expect(question.check_answer_label).to eq("Staircasing transaction")
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" => "Yes" },
"2" => { "value" => "No" },
"3" => { "value" => "Don’t know" },
})
end
it "has correct conditional for" do
expect(question.conditional_for).to eq(nil)
end
it "has the correct hint" do
expect(question.hint_text).to eq("A staircasing transaction is when the household purchases more shares in their property, increasing the proportion they own and decreasing the proportion the housing association owns. Once the household purchases 100% of the shares, they own the property")
end
end

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

@ -0,0 +1,49 @@
require "rails_helper"
RSpec.describe Form::Sales::Questions::Value, 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("value")
end
it "has the correct header" do
expect(question.header).to eq("What was the full purchase price?")
end
it "has the correct check_answer_label" do
expect(question.check_answer_label).to eq("Full purchase price")
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 eq("Enter the full purchase price of the property before any discounts are applied. For shared ownership, enter the full purchase price paid for 100% equity (this is equal to the value of the share owned by the PRP plus the value bought by the purchaser)")
end
it "has correct width" do
expect(question.width).to eq(5)
end
it "has correct prefix" do
expect(question.prefix).to eq("£")
end
it "has correct min" do
expect(question.min).to eq(0)
end
end

33
spec/models/form/sales/sections/sale_information_spec.rb

@ -0,0 +1,33 @@
require "rails_helper"
RSpec.describe Form::Sales::Sections::SaleInformation, type: :model do
subject(:sale_information) { 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(sale_information.form).to eq(form)
end
it "has correct subsections" do
expect(sale_information.subsections.map(&:id)).to eq(%w[
shared_ownership_scheme
discounted_ownership_scheme
outright_sale
])
end
it "has the correct id" do
expect(sale_information.id).to eq("sale_information")
end
it "has the correct label" do
expect(sale_information.label).to eq("Sale information")
end
it "has the correct description" do
expect(sale_information.description).to eq("")
end
end

57
spec/models/form/sales/subsections/discounted_ownership_scheme_spec.rb

@ -0,0 +1,57 @@
require "rails_helper"
RSpec.describe Form::Sales::Subsections::DiscountedOwnershipScheme, type: :model do
subject(:discounted_ownership_scheme) { described_class.new(subsection_id, subsection_definition, section) }
let(:subsection_id) { nil }
let(:subsection_definition) { nil }
let(:section) { instance_double(Form::Sales::Sections::SaleInformation) }
it "has correct section" do
expect(discounted_ownership_scheme.section).to eq(section)
end
it "has correct pages" do
expect(discounted_ownership_scheme.pages.map(&:id)).to eq(
%w[
living_before_purchase_discounted_ownership
about_price_rtb
about_price_not_rtb
mortgage_amount_discounted_ownership
about_deposit_discounted_ownership
],
)
end
it "has the correct id" do
expect(discounted_ownership_scheme.id).to eq("discounted_ownership_scheme")
end
it "has the correct label" do
expect(discounted_ownership_scheme.label).to eq("Discounted ownership scheme")
end
it "has the correct depends_on" do
expect(discounted_ownership_scheme.depends_on).to eq([
{
"ownershipsch" => 2, "setup_completed?" => true
},
])
end
context "when it is a discounted ownership scheme" do
let(:log) { FactoryBot.create(:sales_log, ownershipsch: 2) }
it "is displayed in tasklist" do
expect(discounted_ownership_scheme.displayed_in_tasklist?(log)).to eq(true)
end
end
context "when it is not a discounted ownership scheme" do
let(:log) { FactoryBot.create(:sales_log, ownershipsch: 1) }
it "is displayed in tasklist" do
expect(discounted_ownership_scheme.displayed_in_tasklist?(log)).to eq(false)
end
end
end

53
spec/models/form/sales/subsections/outright_sale_spec.rb

@ -0,0 +1,53 @@
require "rails_helper"
RSpec.describe Form::Sales::Subsections::OutrightSale, type: :model do
subject(:outright_sale) { described_class.new(subsection_id, subsection_definition, section) }
let(:subsection_id) { nil }
let(:subsection_definition) { nil }
let(:section) { instance_double(Form::Sales::Sections::SaleInformation) }
it "has correct section" do
expect(outright_sale.section).to eq(section)
end
it "has correct pages" do
expect(outright_sale.pages.map(&:id)).to eq(
%w[purchase_price
mortgage_amount_outright_sale
about_deposit_outright_sale],
)
end
it "has the correct id" do
expect(outright_sale.id).to eq("outright_sale")
end
it "has the correct label" do
expect(outright_sale.label).to eq("Outright sale")
end
it "has the correct depends_on" do
expect(outright_sale.depends_on).to eq([
{
"ownershipsch" => 3, "setup_completed?" => true
},
])
end
context "when it is a outright sale" do
let(:log) { FactoryBot.create(:sales_log, ownershipsch: 3) }
it "is displayed in tasklist" do
expect(outright_sale.displayed_in_tasklist?(log)).to eq(true)
end
end
context "when it is not a outright sale" do
let(:log) { FactoryBot.create(:sales_log, ownershipsch: 2) }
it "is displayed in tasklist" do
expect(outright_sale.displayed_in_tasklist?(log)).to eq(false)
end
end
end

65
spec/models/form/sales/subsections/shared_ownership_scheme_spec.rb

@ -0,0 +1,65 @@
require "rails_helper"
RSpec.describe Form::Sales::Subsections::SharedOwnershipScheme, type: :model do
subject(:shared_ownership_scheme) { described_class.new(subsection_id, subsection_definition, section) }
let(:subsection_id) { nil }
let(:subsection_definition) { nil }
let(:section) { instance_double(Form::Sales::Sections::SaleInformation) }
it "has correct section" do
expect(shared_ownership_scheme.section).to eq(section)
end
it "has correct pages" do
expect(shared_ownership_scheme.pages.map(&:id)).to eq(
%w[
living_before_purchase_shared_ownership
staircasing
about_staircasing
resale
exchange_contracts
la_nominations
buyer_previous
previous_bedrooms
about_price_shared_ownership
mortgage_amount_shared_ownership
about_deposit_with_discount
about_deposit_shared_ownership
monthly_rent
],
)
end
it "has the correct id" do
expect(shared_ownership_scheme.id).to eq("shared_ownership_scheme")
end
it "has the correct label" do
expect(shared_ownership_scheme.label).to eq("Shared ownership scheme")
end
it "has the correct depends_on" do
expect(shared_ownership_scheme.depends_on).to eq([
{
"ownershipsch" => 1, "setup_completed?" => true
},
])
end
context "when it is a shared ownership scheme" do
let(:log) { FactoryBot.create(:sales_log, ownershipsch: 1) }
it "is displayed in tasklist" do
expect(shared_ownership_scheme.displayed_in_tasklist?(log)).to eq(true)
end
end
context "when it is not a shared ownership scheme" do
let(:log) { FactoryBot.create(:sales_log, ownershipsch: 2) }
it "is displayed in tasklist" do
expect(shared_ownership_scheme.displayed_in_tasklist?(log)).to eq(false)
end
end
end

4
spec/models/form_handler_spec.rb

@ -52,14 +52,14 @@ RSpec.describe FormHandler do
it "is able to load a current sales form" do
form = form_handler.get_form("current_sales")
expect(form).to be_a(Form)
expect(form.pages.count).to eq(69)
expect(form.pages.count).to eq(90)
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(69)
expect(form.pages.count).to eq(90)
expect(form.name).to eq("2021_2022_sales")
end
end

15
spec/models/lettings_log_spec.rb

@ -184,6 +184,21 @@ RSpec.describe LettingsLog do
expect(completed_lettings_log.not_started?).to be(false)
expect(completed_lettings_log.completed?).to be(true)
end
context "when only a subsection that is hidden in tasklist is not completed" do
let(:household_characteristics_subsection) { completed_lettings_log.form.get_subsection("household_characteristics") }
before do
allow(household_characteristics_subsection).to receive(:displayed_in_tasklist?).and_return(false)
completed_lettings_log.update!(tenancycode: nil)
end
it "is set to completed" do
expect(completed_lettings_log.in_progress?).to be(false)
expect(completed_lettings_log.not_started?).to be(false)
expect(completed_lettings_log.completed?).to be(true)
end
end
end
describe "weekly_net_income" do

15
spec/models/sales_log_spec.rb

@ -90,4 +90,19 @@ RSpec.describe SalesLog, type: :model do
expect(described_class.filter_by_organisation([organisation_3]).count).to eq(0)
end
end
describe "derived variables" do
let!(:sales_log) do
described_class.create({
exdate: Time.gm(2022, 5, 4),
})
end
it "correctly derives and saves exday, exmonth and exyear" do
record_from_db = ActiveRecord::Base.connection.execute("select exday, exmonth, exyear from sales_logs where id=#{sales_log.id}").to_a[0]
expect(record_from_db["exday"]).to eq(4)
expect(record_from_db["exmonth"]).to eq(5)
expect(record_from_db["exyear"]).to eq(2022)
end
end
end

Loading…
Cancel
Save