From 5bc127918139b4635fd3cafb87ec57fd682bbc76 Mon Sep 17 00:00:00 2001 From: natdeanlewissoftwire <94526761+natdeanlewissoftwire@users.noreply.github.com> Date: Thu, 22 Dec 2022 15:02:22 +0000 Subject: [PATCH] Cldc 1533 is resale (#1118) * feat: add resale question and page * tests: add new tests * test: update previous tests * refactor: linting * refactor: linting --- app/models/form/sales/pages/resale.rb | 23 +++++++++ app/models/form/sales/questions/resale.rb | 17 +++++++ .../subsections/shared_ownership_scheme.rb | 1 + db/schema.rb | 2 +- spec/models/form/sales/pages/resale_spec.rb | 40 ++++++++++++++++ .../form/sales/questions/resale_spec.rb | 48 +++++++++++++++++++ .../shared_ownership_scheme_spec.rb | 1 + spec/models/form_handler_spec.rb | 4 +- 8 files changed, 133 insertions(+), 3 deletions(-) create mode 100644 app/models/form/sales/pages/resale.rb create mode 100644 app/models/form/sales/questions/resale.rb create mode 100644 spec/models/form/sales/pages/resale_spec.rb create mode 100644 spec/models/form/sales/questions/resale_spec.rb 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/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/subsections/shared_ownership_scheme.rb b/app/models/form/sales/subsections/shared_ownership_scheme.rb index 03cb88de4..6b990742c 100644 --- a/app/models/form/sales/subsections/shared_ownership_scheme.rb +++ b/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), diff --git a/db/schema.rb b/db/schema.rb index ab08c296e..91403c52f 100644 --- a/db/schema.rb +++ b/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" 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/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/subsections/shared_ownership_scheme_spec.rb b/spec/models/form/sales/subsections/shared_ownership_scheme_spec.rb index c56e5d3a2..1488df4bc 100644 --- a/spec/models/form/sales/subsections/shared_ownership_scheme_spec.rb +++ b/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 diff --git a/spec/models/form_handler_spec.rb b/spec/models/form_handler_spec.rb index e9ecc340e..2407e810c 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(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