Browse Source

Cldc 1533 is resale (#1118)

* feat: add resale question and page

* tests: add new tests

* test: update previous tests

* refactor: linting

* refactor: linting
pull/1130/head
natdeanlewissoftwire 4 years ago committed by Kat
parent
commit
5bc1279181
  1. 23
      app/models/form/sales/pages/resale.rb
  2. 17
      app/models/form/sales/questions/resale.rb
  3. 1
      app/models/form/sales/subsections/shared_ownership_scheme.rb
  4. 2
      db/schema.rb
  5. 40
      spec/models/form/sales/pages/resale_spec.rb
  6. 48
      spec/models/form/sales/questions/resale_spec.rb
  7. 1
      spec/models/form/sales/subsections/shared_ownership_scheme_spec.rb
  8. 4
      spec/models/form_handler_spec.rb

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

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

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

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

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

@ -11,6 +11,7 @@ class Form::Sales::Subsections::SharedOwnershipScheme < ::Form::Subsection
@pages ||= [
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::LaNominations.new(nil, nil, self),
Form::Sales::Pages::PreviousBedrooms.new(nil, nil, self),
Form::Sales::Pages::AboutDeposit.new("about_deposit_shared_ownership", nil, self),

2
db/schema.rb

@ -420,6 +420,7 @@ ActiveRecord::Schema[7.0].define(version: 2022_12_21_172821) do
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"
@ -427,7 +428,6 @@ ActiveRecord::Schema[7.0].define(version: 2022_12_21_172821) do
t.integer "resale"
t.decimal "deposit", precision: 10, scale: 2
t.decimal "cashdis", precision: 10, scale: 2
t.decimal "mrent", precision: 10, scale: 2
t.integer "lanomagr"
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"

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

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

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

@ -0,0 +1,48 @@
require "rails_helper"
RSpec.describe Form::Sales::Questions::Resale, type: :model do
subject(:question) { described_class.new(question_id, question_definition, page) }
let(:question_id) { nil }
let(:question_definition) { nil }
let(:page) { instance_double(Form::Page) }
it "has correct page" do
expect(question.page).to eq(page)
end
it "has the correct id" do
expect(question.id).to eq("resale")
end
it "has the correct header" do
expect(question.header).to eq("Is this a resale?")
end
it "has the correct check_answer_label" do
expect(question.check_answer_label).to eq("Is this a resale?")
end
it "has the correct type" do
expect(question.type).to eq("radio")
end
it "is not marked as derived" do
expect(question.derived?).to be false
end
it "has the correct answer_options" do
expect(question.answer_options).to eq({
"1" => { "value" => "Yes" },
"2" => { "value" => "No" },
})
end
it "has correct conditional for" do
expect(question.conditional_for).to eq(nil)
end
it "has the correct hint" do
expect(question.hint_text).to eq("If the social landlord has previously sold the property to another buyer and is now reselling the property, select 'yes'. If this is the first time the property has been sold, select 'no'.")
end
end

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

@ -16,6 +16,7 @@ RSpec.describe Form::Sales::Subsections::SharedOwnershipScheme, type: :model do
%w[
staircasing
about_staircasing
resale
la_nominations
previous_bedrooms
about_deposit_shared_ownership

4
spec/models/form_handler_spec.rb

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

Loading…
Cancel
Save