diff --git a/app/models/derived_variables/sales_log_variables.rb b/app/models/derived_variables/sales_log_variables.rb
index 2b3542813..88bad228f 100644
--- a/app/models/derived_variables/sales_log_variables.rb
+++ b/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
diff --git a/app/models/form/sales/pages/about_deposit_with_discount.rb b/app/models/form/sales/pages/about_deposit_with_discount.rb
new file mode 100644
index 000000000..1de5365aa
--- /dev/null
+++ b/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
diff --git a/app/models/form/sales/pages/about_deposit_without_discount.rb b/app/models/form/sales/pages/about_deposit_without_discount.rb
new file mode 100644
index 000000000..00f306208
--- /dev/null
+++ b/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
diff --git a/app/models/form/sales/pages/about_price_not_rtb.rb b/app/models/form/sales/pages/about_price_not_rtb.rb
new file mode 100644
index 000000000..795ed9226
--- /dev/null
+++ b/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
diff --git a/app/models/form/sales/pages/about_price_rtb.rb b/app/models/form/sales/pages/about_price_rtb.rb
new file mode 100644
index 000000000..ec90afa01
--- /dev/null
+++ b/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
diff --git a/app/models/form/sales/pages/about_price_shared_ownership.rb b/app/models/form/sales/pages/about_price_shared_ownership.rb
new file mode 100644
index 000000000..b3f34c121
--- /dev/null
+++ b/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
diff --git a/app/models/form/sales/pages/about_staircase.rb b/app/models/form/sales/pages/about_staircase.rb
new file mode 100644
index 000000000..03ea570f7
--- /dev/null
+++ b/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
diff --git a/app/models/form/sales/pages/buyer_previous.rb b/app/models/form/sales/pages/buyer_previous.rb
new file mode 100644
index 000000000..5a75787c8
--- /dev/null
+++ b/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
diff --git a/app/models/form/sales/pages/exchange_date.rb b/app/models/form/sales/pages/exchange_date.rb
new file mode 100644
index 000000000..59e23ab01
--- /dev/null
+++ b/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
diff --git a/app/models/form/sales/pages/la_nominations.rb b/app/models/form/sales/pages/la_nominations.rb
new file mode 100644
index 000000000..c5c775e9f
--- /dev/null
+++ b/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
diff --git a/app/models/form/sales/pages/living_before_purchase.rb b/app/models/form/sales/pages/living_before_purchase.rb
new file mode 100644
index 000000000..e76b8fd63
--- /dev/null
+++ b/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
diff --git a/app/models/form/sales/pages/monthly_rent.rb b/app/models/form/sales/pages/monthly_rent.rb
new file mode 100644
index 000000000..826314edf
--- /dev/null
+++ b/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
diff --git a/app/models/form/sales/pages/mortgage_amount.rb b/app/models/form/sales/pages/mortgage_amount.rb
new file mode 100644
index 000000000..1c80b2f52
--- /dev/null
+++ b/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
diff --git a/app/models/form/sales/pages/previous_bedrooms.rb b/app/models/form/sales/pages/previous_bedrooms.rb
new file mode 100644
index 000000000..3c6eb26b1
--- /dev/null
+++ b/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
diff --git a/app/models/form/sales/pages/purchase_price.rb b/app/models/form/sales/pages/purchase_price.rb
new file mode 100644
index 000000000..5eeb84138
--- /dev/null
+++ b/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
diff --git a/app/models/form/sales/pages/resale.rb b/app/models/form/sales/pages/resale.rb
new file mode 100644
index 000000000..031efd3d6
--- /dev/null
+++ b/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
diff --git a/app/models/form/sales/pages/staircase.rb b/app/models/form/sales/pages/staircase.rb
new file mode 100644
index 000000000..139bd7e40
--- /dev/null
+++ b/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
diff --git a/app/models/form/sales/questions/buyer_previous.rb b/app/models/form/sales/questions/buyer_previous.rb
new file mode 100644
index 000000000..ae9ac22ea
--- /dev/null
+++ b/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
diff --git a/app/models/form/sales/questions/deposit_amount.rb b/app/models/form/sales/questions/deposit_amount.rb
new file mode 100644
index 000000000..8252ad8d7
--- /dev/null
+++ b/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
diff --git a/app/models/form/sales/questions/deposit_discount.rb b/app/models/form/sales/questions/deposit_discount.rb
new file mode 100644
index 000000000..9496f90fd
--- /dev/null
+++ b/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
diff --git a/app/models/form/sales/questions/discount.rb b/app/models/form/sales/questions/discount.rb
new file mode 100644
index 000000000..d7b9fa33b
--- /dev/null
+++ b/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)
+ If discount capped, enter capped %
+ 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
diff --git a/app/models/form/sales/questions/equity.rb b/app/models/form/sales/questions/equity.rb
new file mode 100644
index 000000000..585a14c36
--- /dev/null
+++ b/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
diff --git a/app/models/form/sales/questions/exchange_date.rb b/app/models/form/sales/questions/exchange_date.rb
new file mode 100644
index 000000000..2c726e441
--- /dev/null
+++ b/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
diff --git a/app/models/form/sales/questions/grant.rb b/app/models/form/sales/questions/grant.rb
new file mode 100644
index 000000000..edab388ac
--- /dev/null
+++ b/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
diff --git a/app/models/form/sales/questions/la_nominations.rb b/app/models/form/sales/questions/la_nominations.rb
new file mode 100644
index 000000000..5db0178b6
--- /dev/null
+++ b/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
diff --git a/app/models/form/sales/questions/living_before_purchase.rb b/app/models/form/sales/questions/living_before_purchase.rb
new file mode 100644
index 000000000..0486fa4d7
--- /dev/null
+++ b/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
diff --git a/app/models/form/sales/questions/monthly_rent.rb b/app/models/form/sales/questions/monthly_rent.rb
new file mode 100644
index 000000000..4195b1238
--- /dev/null
+++ b/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
diff --git a/app/models/form/sales/questions/mortgage_amount.rb b/app/models/form/sales/questions/mortgage_amount.rb
new file mode 100644
index 000000000..c385563c5
--- /dev/null
+++ b/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
diff --git a/app/models/form/sales/questions/previous_bedrooms.rb b/app/models/form/sales/questions/previous_bedrooms.rb
new file mode 100644
index 000000000..60f361499
--- /dev/null
+++ b/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
diff --git a/app/models/form/sales/questions/purchase_price.rb b/app/models/form/sales/questions/purchase_price.rb
new file mode 100644
index 000000000..da714d9df
--- /dev/null
+++ b/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
diff --git a/app/models/form/sales/questions/resale.rb b/app/models/form/sales/questions/resale.rb
new file mode 100644
index 000000000..8da7d8abd
--- /dev/null
+++ b/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
diff --git a/app/models/form/sales/questions/staircase.rb b/app/models/form/sales/questions/staircase.rb
new file mode 100644
index 000000000..e204414b9
--- /dev/null
+++ b/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
diff --git a/app/models/form/sales/questions/staircase_bought.rb b/app/models/form/sales/questions/staircase_bought.rb
new file mode 100644
index 000000000..5afca794d
--- /dev/null
+++ b/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
diff --git a/app/models/form/sales/questions/staircase_owned.rb b/app/models/form/sales/questions/staircase_owned.rb
new file mode 100644
index 000000000..0fa37ec7a
--- /dev/null
+++ b/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
diff --git a/app/models/form/sales/questions/value.rb b/app/models/form/sales/questions/value.rb
new file mode 100644
index 000000000..0686d6610
--- /dev/null
+++ b/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
diff --git a/app/models/form/sales/sections/sale_information.rb b/app/models/form/sales/sections/sale_information.rb
new file mode 100644
index 000000000..941abad3a
--- /dev/null
+++ b/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
diff --git a/app/models/form/sales/subsections/discounted_ownership_scheme.rb b/app/models/form/sales/subsections/discounted_ownership_scheme.rb
new file mode 100644
index 000000000..4e317618e
--- /dev/null
+++ b/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
diff --git a/app/models/form/sales/subsections/outright_sale.rb b/app/models/form/sales/subsections/outright_sale.rb
new file mode 100644
index 000000000..c9c6bbf85
--- /dev/null
+++ b/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
diff --git a/app/models/form/sales/subsections/shared_ownership_scheme.rb b/app/models/form/sales/subsections/shared_ownership_scheme.rb
new file mode 100644
index 000000000..89a438487
--- /dev/null
+++ b/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
diff --git a/app/models/form/subsection.rb b/app/models/form/subsection.rb
index 07e7fe65c..0266fc448 100644
--- a/app/models/form/subsection.rb
+++ b/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
diff --git a/app/models/form_handler.rb b/app/models/form_handler.rb
index 69b05859e..1afa1d15f 100644
--- a/app/models/form_handler.rb
+++ b/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")
diff --git a/app/models/log.rb b/app/models/log.rb
index c09cdd46a..e9dc9c69a 100644
--- a/app/models/log.rb
+++ b/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
diff --git a/app/models/sales_log.rb b/app/models/sales_log.rb
index d3066974f..65175a802 100644
--- a/app/models/sales_log.rb
+++ b/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
diff --git a/app/views/logs/_tasklist.html.erb b/app/views/logs/_tasklist.html.erb
index 6c82eb377..df8a3afad 100644
--- a/app/views/logs/_tasklist.html.erb
+++ b/app/views/logs/_tasklist.html.erb
@@ -9,7 +9,7 @@
<% end %>
<% 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) %>
-
diff --git a/db/migrate/20221220155625_add_from_beds_to_sales.rb b/db/migrate/20221220155625_add_from_beds_to_sales.rb
new file mode 100644
index 000000000..462d7ba7d
--- /dev/null
+++ b/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
diff --git a/db/migrate/20221220174515_add_staircase_to_sales.rb b/db/migrate/20221220174515_add_staircase_to_sales.rb
new file mode 100644
index 000000000..de0b28996
--- /dev/null
+++ b/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
diff --git a/db/migrate/20221221081709_add_staircase_fields_to_sales.rb b/db/migrate/20221221081709_add_staircase_fields_to_sales.rb
new file mode 100644
index 000000000..0d6dd143e
--- /dev/null
+++ b/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
diff --git a/db/migrate/20221221105502_add_rent_to_sales.rb b/db/migrate/20221221105502_add_rent_to_sales.rb
new file mode 100644
index 000000000..2e5371055
--- /dev/null
+++ b/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
diff --git a/db/migrate/20221221122233_add_exchange_contracts_to_sales.rb b/db/migrate/20221221122233_add_exchange_contracts_to_sales.rb
new file mode 100644
index 000000000..51976d7ca
--- /dev/null
+++ b/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
diff --git a/db/migrate/20221221164308_add_deposit_fields_to_sales.rb b/db/migrate/20221221164308_add_deposit_fields_to_sales.rb
new file mode 100644
index 000000000..82087110f
--- /dev/null
+++ b/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
diff --git a/db/migrate/20221222081402_add_la_nominations.rb b/db/migrate/20221222081402_add_la_nominations.rb
new file mode 100644
index 000000000..1bc981183
--- /dev/null
+++ b/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
diff --git a/db/migrate/20221222120105_add_soctenant.rb b/db/migrate/20221222120105_add_soctenant.rb
new file mode 100644
index 000000000..43dfc56e5
--- /dev/null
+++ b/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
diff --git a/db/migrate/20221222133600_add_price_fields.rb b/db/migrate/20221222133600_add_price_fields.rb
new file mode 100644
index 000000000..43cc73ca4
--- /dev/null
+++ b/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
diff --git a/db/migrate/20230103094948_add_proplen_to_sales.rb b/db/migrate/20230103094948_add_proplen_to_sales.rb
new file mode 100644
index 000000000..f373d22a8
--- /dev/null
+++ b/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
diff --git a/db/migrate/20230104093057_change_mortgage_to_float.rb b/db/migrate/20230104093057_change_mortgage_to_float.rb
new file mode 100644
index 000000000..201031288
--- /dev/null
+++ b/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
diff --git a/db/schema.rb b/db/schema.rb
index a93ca7620..ee62f5656 100644
--- a/db/schema.rb
+++ b/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,18 +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.string "relat3"
- t.string "relat4"
- t.string "relat5"
- t.string "relat6"
+ 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"
diff --git a/db/seeds.rb b/db/seeds.rb
index 20975feb8..4d641d52b 100644
--- a/db/seeds.rb
+++ b/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")
diff --git a/spec/factories/sales_log.rb b/spec/factories/sales_log.rb
index a429f6f0b..a842c4f53 100644
--- a/spec/factories/sales_log.rb
+++ b/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 }
relat3 { "P" }
relat4 { "P" }
relat5 { "P" }
diff --git a/spec/models/form/sales/pages/about_deposit_with_discount_spec.rb b/spec/models/form/sales/pages/about_deposit_with_discount_spec.rb
new file mode 100644
index 000000000..692f17a75
--- /dev/null
+++ b/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
diff --git a/spec/models/form/sales/pages/about_deposit_without_discount_spec.rb b/spec/models/form/sales/pages/about_deposit_without_discount_spec.rb
new file mode 100644
index 000000000..07f9c983d
--- /dev/null
+++ b/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
diff --git a/spec/models/form/sales/pages/about_price_not_rtb_spec.rb b/spec/models/form/sales/pages/about_price_not_rtb_spec.rb
new file mode 100644
index 000000000..584455d25
--- /dev/null
+++ b/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
diff --git a/spec/models/form/sales/pages/about_price_rtb_spec.rb b/spec/models/form/sales/pages/about_price_rtb_spec.rb
new file mode 100644
index 000000000..29e59f52c
--- /dev/null
+++ b/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
diff --git a/spec/models/form/sales/pages/about_price_shared_ownership_spec.rb b/spec/models/form/sales/pages/about_price_shared_ownership_spec.rb
new file mode 100644
index 000000000..c4e8d6ccc
--- /dev/null
+++ b/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
diff --git a/spec/models/form/sales/pages/about_staircase_spec.rb b/spec/models/form/sales/pages/about_staircase_spec.rb
new file mode 100644
index 000000000..9fe34ba86
--- /dev/null
+++ b/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
diff --git a/spec/models/form/sales/pages/buyer_previous_spec.rb b/spec/models/form/sales/pages/buyer_previous_spec.rb
new file mode 100644
index 000000000..2954d54ae
--- /dev/null
+++ b/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
diff --git a/spec/models/form/sales/pages/exchange_date_spec.rb b/spec/models/form/sales/pages/exchange_date_spec.rb
new file mode 100644
index 000000000..21c4c3aab
--- /dev/null
+++ b/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
diff --git a/spec/models/form/sales/pages/la_nominations_spec.rb b/spec/models/form/sales/pages/la_nominations_spec.rb
new file mode 100644
index 000000000..02b44ccb5
--- /dev/null
+++ b/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
diff --git a/spec/models/form/sales/pages/living_before_purchase_spec.rb b/spec/models/form/sales/pages/living_before_purchase_spec.rb
new file mode 100644
index 000000000..b01e381e8
--- /dev/null
+++ b/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
diff --git a/spec/models/form/sales/pages/monthly_rent_spec.rb b/spec/models/form/sales/pages/monthly_rent_spec.rb
new file mode 100644
index 000000000..8d953e248
--- /dev/null
+++ b/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
diff --git a/spec/models/form/sales/pages/mortgage_amount_spec.rb b/spec/models/form/sales/pages/mortgage_amount_spec.rb
new file mode 100644
index 000000000..28c37908b
--- /dev/null
+++ b/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
diff --git a/spec/models/form/sales/pages/previous_bedrooms_spec.rb b/spec/models/form/sales/pages/previous_bedrooms_spec.rb
new file mode 100644
index 000000000..6fb8c3c5b
--- /dev/null
+++ b/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
diff --git a/spec/models/form/sales/pages/purchase_price_spec.rb b/spec/models/form/sales/pages/purchase_price_spec.rb
new file mode 100644
index 000000000..f6cdef219
--- /dev/null
+++ b/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
diff --git a/spec/models/form/sales/pages/resale_spec.rb b/spec/models/form/sales/pages/resale_spec.rb
new file mode 100644
index 000000000..ce2e81182
--- /dev/null
+++ b/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
diff --git a/spec/models/form/sales/pages/staircase_spec.rb b/spec/models/form/sales/pages/staircase_spec.rb
new file mode 100644
index 000000000..d2155f972
--- /dev/null
+++ b/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
diff --git a/spec/models/form/sales/questions/buyer_previous_spec.rb b/spec/models/form/sales/questions/buyer_previous_spec.rb
new file mode 100644
index 000000000..07d3685f8
--- /dev/null
+++ b/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
diff --git a/spec/models/form/sales/questions/deposit_amount_spec.rb b/spec/models/form/sales/questions/deposit_amount_spec.rb
new file mode 100644
index 000000000..9eaa628cf
--- /dev/null
+++ b/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
diff --git a/spec/models/form/sales/questions/deposit_discount_spec.rb b/spec/models/form/sales/questions/deposit_discount_spec.rb
new file mode 100644
index 000000000..b0f8899bf
--- /dev/null
+++ b/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
diff --git a/spec/models/form/sales/questions/discount_spec.rb b/spec/models/form/sales/questions/discount_spec.rb
new file mode 100644
index 000000000..f40b2eded
--- /dev/null
+++ b/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)
+ If discount capped, enter capped %
+ 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
diff --git a/spec/models/form/sales/questions/equity_spec.rb b/spec/models/form/sales/questions/equity_spec.rb
new file mode 100644
index 000000000..91308c745
--- /dev/null
+++ b/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
diff --git a/spec/models/form/sales/questions/exchange_date_spec.rb b/spec/models/form/sales/questions/exchange_date_spec.rb
new file mode 100644
index 000000000..53d5a8975
--- /dev/null
+++ b/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
diff --git a/spec/models/form/sales/questions/grant_spec.rb b/spec/models/form/sales/questions/grant_spec.rb
new file mode 100644
index 000000000..d4e92f703
--- /dev/null
+++ b/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
diff --git a/spec/models/form/sales/questions/la_nominations_spec.rb b/spec/models/form/sales/questions/la_nominations_spec.rb
new file mode 100644
index 000000000..bb06ef014
--- /dev/null
+++ b/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
diff --git a/spec/models/form/sales/questions/living_before_purchase_spec.rb b/spec/models/form/sales/questions/living_before_purchase_spec.rb
new file mode 100644
index 000000000..29f785c06
--- /dev/null
+++ b/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
diff --git a/spec/models/form/sales/questions/monthly_rent_spec.rb b/spec/models/form/sales/questions/monthly_rent_spec.rb
new file mode 100644
index 000000000..e33603099
--- /dev/null
+++ b/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
diff --git a/spec/models/form/sales/questions/mortgage_amount_spec.rb b/spec/models/form/sales/questions/mortgage_amount_spec.rb
new file mode 100644
index 000000000..ac1e5ad5e
--- /dev/null
+++ b/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
diff --git a/spec/models/form/sales/questions/previous_bedrooms_spec.rb b/spec/models/form/sales/questions/previous_bedrooms_spec.rb
new file mode 100644
index 000000000..bbfef7fab
--- /dev/null
+++ b/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
diff --git a/spec/models/form/sales/questions/purchase_price_spec.rb b/spec/models/form/sales/questions/purchase_price_spec.rb
new file mode 100644
index 000000000..1ee30b9a5
--- /dev/null
+++ b/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
diff --git a/spec/models/form/sales/questions/resale_spec.rb b/spec/models/form/sales/questions/resale_spec.rb
new file mode 100644
index 000000000..a52999fbb
--- /dev/null
+++ b/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
diff --git a/spec/models/form/sales/questions/staircase_bought_spec.rb b/spec/models/form/sales/questions/staircase_bought_spec.rb
new file mode 100644
index 000000000..96716dbd3
--- /dev/null
+++ b/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
diff --git a/spec/models/form/sales/questions/staircase_owned_spec.rb b/spec/models/form/sales/questions/staircase_owned_spec.rb
new file mode 100644
index 000000000..56b563990
--- /dev/null
+++ b/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
diff --git a/spec/models/form/sales/questions/staircase_spec.rb b/spec/models/form/sales/questions/staircase_spec.rb
new file mode 100644
index 000000000..845e5242e
--- /dev/null
+++ b/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
diff --git a/spec/models/form/sales/questions/value_spec.rb b/spec/models/form/sales/questions/value_spec.rb
new file mode 100644
index 000000000..f9da45db0
--- /dev/null
+++ b/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
diff --git a/spec/models/form/sales/sections/sale_information_spec.rb b/spec/models/form/sales/sections/sale_information_spec.rb
new file mode 100644
index 000000000..0b2ab4144
--- /dev/null
+++ b/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
diff --git a/spec/models/form/sales/subsections/discounted_ownership_scheme_spec.rb b/spec/models/form/sales/subsections/discounted_ownership_scheme_spec.rb
new file mode 100644
index 000000000..0adb25d3c
--- /dev/null
+++ b/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
diff --git a/spec/models/form/sales/subsections/outright_sale_spec.rb b/spec/models/form/sales/subsections/outright_sale_spec.rb
new file mode 100644
index 000000000..96a26ff93
--- /dev/null
+++ b/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
diff --git a/spec/models/form/sales/subsections/shared_ownership_scheme_spec.rb b/spec/models/form/sales/subsections/shared_ownership_scheme_spec.rb
new file mode 100644
index 000000000..4cdf0c468
--- /dev/null
+++ b/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
diff --git a/spec/models/form_handler_spec.rb b/spec/models/form_handler_spec.rb
index e9ecc340e..33e5dde47 100644
--- a/spec/models/form_handler_spec.rb
+++ b/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(77)
+ expect(form.pages.count).to eq(98)
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(77)
+ expect(form.pages.count).to eq(98)
expect(form.name).to eq("2021_2022_sales")
end
end
diff --git a/spec/models/lettings_log_spec.rb b/spec/models/lettings_log_spec.rb
index 953ec838b..999b4da3e 100644
--- a/spec/models/lettings_log_spec.rb
+++ b/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
diff --git a/spec/models/sales_log_spec.rb b/spec/models/sales_log_spec.rb
index 3ee033971..9e618a10e 100644
--- a/spec/models/sales_log_spec.rb
+++ b/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