Browse Source

CLDC-1809 Add prevshared question (#1269)

* Add prevshared question

* Update CYA

* Add missing specs
pull/1286/head
Jack 2 years ago committed by GitHub
parent
commit
466d3fc2cf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 15
      app/models/form/sales/pages/previous_shared.rb
  2. 17
      app/models/form/sales/questions/prevshared.rb
  3. 11
      app/models/form/sales/subsections/income_benefits_and_savings.rb
  4. 7
      db/migrate/20230203153051_add_prev_shared_to_sales.rb
  5. 3
      db/schema.rb
  6. 1
      spec/factories/sales_log.rb
  7. 29
      spec/models/form/sales/pages/previous_shared_spec.rb
  8. 49
      spec/models/form/sales/questions/prevshared_spec.rb
  9. 1
      spec/models/form/sales/subsections/discounted_ownership_scheme_spec.rb
  10. 34
      spec/models/form/sales/subsections/income_benefits_and_savings_spec.rb
  11. 2
      spec/models/form_handler_spec.rb

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

@ -0,0 +1,15 @@
class Form::Sales::Pages::PreviousShared < ::Form::Page
def initialize(id, hsh, subsection)
super
@id = "previous_shared"
@depends_on = [
{ "prevown" => 1 },
]
end
def questions
@questions ||= [
Form::Sales::Questions::Prevshared.new(nil, nil, self),
]
end
end

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

@ -0,0 +1,17 @@
class Form::Sales::Questions::Prevshared < ::Form::Question
def initialize(id, hsh, page)
super
@id = "prevshared"
@check_answer_label = "Previous property shared ownership?"
@header = "Was the previous property a shared ownership property?"
@type = "radio"
@answer_options = ANSWER_OPTIONS
@hint = "For any buyer"
end
ANSWER_OPTIONS = {
"1" => { "value" => "Yes" },
"2" => { "value" => "No" },
"3" => { "value" => "Don’t know" },
}.freeze
end

11
app/models/form/sales/subsections/income_benefits_and_savings.rb

@ -22,6 +22,15 @@ class Form::Sales::Subsections::IncomeBenefitsAndSavings < ::Form::Subsection
Form::Sales::Pages::SavingsValueCheck.new("savings_value_check", nil, self),
Form::Sales::Pages::DepositValueCheck.new("savings_deposit_value_check", nil, self),
Form::Sales::Pages::PreviousOwnership.new(nil, nil, self),
]
previous_shared_page,
].compact
end
private
def previous_shared_page
if form.start_date.year >= 2023
Form::Sales::Pages::PreviousShared.new(nil, nil, self)
end
end
end

7
db/migrate/20230203153051_add_prev_shared_to_sales.rb

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

3
db/schema.rb

@ -521,9 +521,10 @@ ActiveRecord::Schema[7.0].define(version: 2023_02_03_174815) do
t.integer "old_persons_shared_ownership_value_check"
t.integer "staircase_bought_value_check"
t.integer "monthly_charges_value_check"
t.integer "saledate_check"
t.integer "details_known_5"
t.integer "details_known_6"
t.integer "saledate_check"
t.integer "prevshared"
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 ["owning_organisation_id"], name: "index_sales_logs_on_owning_organisation_id"

1
spec/factories/sales_log.rb

@ -60,6 +60,7 @@ FactoryBot.define do
la { "E09000003" }
savingsnk { 1 }
prevown { 1 }
prevshared { 2 }
sex3 { "X" }
sex4 { "X" }
sex5 { "X" }

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

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

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

@ -0,0 +1,49 @@
require "rails_helper"
RSpec.describe Form::Sales::Questions::Prevshared, 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("prevshared")
end
it "has the correct header" do
expect(question.header).to eq("Was the previous property a shared ownership property?")
end
it "has the correct check_answer_label" do
expect(question.check_answer_label).to eq("Previous property shared ownership?")
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

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

@ -12,7 +12,6 @@ RSpec.describe Form::Sales::Subsections::DiscountedOwnershipScheme, type: :model
end
it "has correct pages" do
puts discounted_ownership_scheme.pages.map(&:id)
expect(discounted_ownership_scheme.pages.map(&:id)).to eq(
%w[
living_before_purchase_discounted_ownership

34
spec/models/form/sales/subsections/income_benefits_and_savings_spec.rb

@ -11,6 +11,37 @@ RSpec.describe Form::Sales::Subsections::IncomeBenefitsAndSavings, type: :model
expect(subsection.section).to eq(section)
end
describe "pages" do
let(:section) { instance_double(Form::Sales::Sections::Household, form: instance_double(Form, start_date:)) }
context "when 2022" do
let(:start_date) { Time.utc(2022, 2, 8) }
it "has correct pages" do
expect(subsection.pages.compact.map(&:id)).to eq(
%w[
buyer_1_income
buyer_1_income_value_check
buyer_1_income_mortgage_value_check
buyer_1_mortgage
buyer_1_mortgage_value_check
buyer_2_income
buyer_2_income_mortgage_value_check
buyer_2_mortgage
buyer_2_mortgage_value_check
housing_benefits
savings
savings_value_check
savings_deposit_value_check
previous_ownership
],
)
end
end
context "when 2023" do
let(:start_date) { Time.utc(2023, 2, 8) }
it "has correct pages" do
expect(subsection.pages.map(&:id)).to eq(
%w[
@ -28,9 +59,12 @@ RSpec.describe Form::Sales::Subsections::IncomeBenefitsAndSavings, type: :model
savings_value_check
savings_deposit_value_check
previous_ownership
previous_shared
],
)
end
end
end
it "has the correct id" do
expect(subsection.id).to eq("income_benefits_and_savings")

2
spec/models/form_handler_spec.rb

@ -41,12 +41,14 @@ RSpec.describe FormHandler do
form = form_handler.get_form("current_lettings")
expect(form).to be_a(Form)
expect(form.pages.count).to eq(13)
expect(form.name).to eq("2022_2023_lettings")
end
it "is able to load a previous lettings form" do
form = form_handler.get_form("previous_lettings")
expect(form).to be_a(Form)
expect(form.pages.count).to eq(46)
expect(form.name).to eq("2021_2022_lettings")
end
it "is able to load a current sales form" do

Loading…
Cancel
Save