Browse Source

CLDC-1810 new staircasing followup (#1286)

* feat: behaviour

* feat: conditional year behaviour and test

* refactor: linting

* db: update
pull/1301/head
natdeanlewissoftwire 2 years ago committed by GitHub
parent
commit
6c0780291b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 9
      app/models/form/sales/pages/about_staircase.rb
  2. 16
      app/models/form/sales/questions/staircase_sale.rb
  3. 5
      db/migrate/20230210122037_add_staircasesale_to_sales_logs.rb
  4. 3
      db/schema.rb
  5. 20
      spec/models/form/sales/pages/about_staircase_spec.rb
  6. 49
      spec/models/form/sales/questions/staircase_sale_spec.rb

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

@ -12,6 +12,13 @@ class Form::Sales::Pages::AboutStaircase < ::Form::Page
@questions ||= [ @questions ||= [
Form::Sales::Questions::StaircaseBought.new(nil, nil, self), Form::Sales::Questions::StaircaseBought.new(nil, nil, self),
Form::Sales::Questions::StaircaseOwned.new(nil, nil, self), Form::Sales::Questions::StaircaseOwned.new(nil, nil, self),
] staircase_sale_question,
].compact
end
def staircase_sale_question
if form.start_date.year >= 2023
Form::Sales::Questions::StaircaseSale.new(nil, nil, self)
end
end end
end end

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

@ -0,0 +1,16 @@
class Form::Sales::Questions::StaircaseSale < ::Form::Question
def initialize(id, hsh, page)
super
@id = "staircasesale"
@check_answer_label = "Part of a back-to-back staircasing transaction"
@header = "Is this transaction part of a back-to-back staircasing transaction to facilitate sale of the home on the open market?"
@type = "radio"
@answer_options = ANSWER_OPTIONS
end
ANSWER_OPTIONS = {
"1" => { "value" => "Yes" },
"2" => { "value" => "No" },
"3" => { "value" => "Don't know" },
}.freeze
end

5
db/migrate/20230210122037_add_staircasesale_to_sales_logs.rb

@ -0,0 +1,5 @@
class AddStaircasesaleToSalesLogs < ActiveRecord::Migration[7.0]
def change
add_column :sales_logs, :staircasesale, :integer
end
end

3
db/schema.rb

@ -10,7 +10,7 @@
# #
# It's strongly recommended that you check this file into your version control system. # It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema[7.0].define(version: 2023_02_03_174815) do ActiveRecord::Schema[7.0].define(version: 2023_02_10_122037) do
# These are extensions that must be enabled in order to support this database # These are extensions that must be enabled in order to support this database
enable_extension "plpgsql" enable_extension "plpgsql"
@ -524,6 +524,7 @@ ActiveRecord::Schema[7.0].define(version: 2023_02_03_174815) do
t.integer "details_known_5" t.integer "details_known_5"
t.integer "details_known_6" t.integer "details_known_6"
t.integer "saledate_check" t.integer "saledate_check"
t.integer "staircasesale"
t.integer "prevshared" t.integer "prevshared"
t.index ["bulk_upload_id"], name: "index_sales_logs_on_bulk_upload_id" t.index ["bulk_upload_id"], name: "index_sales_logs_on_bulk_upload_id"
t.index ["created_by_id"], name: "index_sales_logs_on_created_by_id" t.index ["created_by_id"], name: "index_sales_logs_on_created_by_id"

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

@ -11,8 +11,24 @@ RSpec.describe Form::Sales::Pages::AboutStaircase, type: :model do
expect(page.subsection).to eq(subsection) expect(page.subsection).to eq(subsection)
end end
it "has correct questions" do describe "questions" do
expect(page.questions.map(&:id)).to eq(%w[stairbought stairowned]) let(:subsection) { instance_double(Form::Subsection, form: instance_double(Form, start_date:)) }
context "when 2022" do
let(:start_date) { Time.utc(2022, 2, 8) }
it "has correct questions" do
expect(page.questions.map(&:id)).to eq(%w[stairbought stairowned])
end
end
context "when 2023" do
let(:start_date) { Time.utc(2023, 2, 8) }
it "has correct questions" do
expect(page.questions.map(&:id)).to eq(%w[stairbought stairowned staircasesale])
end
end
end end
it "has the correct id" do it "has the correct id" do

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

@ -0,0 +1,49 @@
require "rails_helper"
RSpec.describe Form::Sales::Questions::StaircaseSale, 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("staircasesale")
end
it "has the correct header" do
expect(question.header).to eq("Is this transaction part of a back-to-back staircasing transaction to facilitate sale of the home on the open market?")
end
it "has the correct check_answer_label" do
expect(question.check_answer_label).to eq("Part of a back-to-back 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 be_nil
end
end
Loading…
Cancel
Save