Browse Source

Add don't know options (#1356)

* Add don't know options

* Add mortgage length known question

* Update mortgage known question options

* Display fewer answer options

* Add don't know undisplayed answer option to mortgage used

* Run validations even if mortgageused is don't know

* Remove unconfirmed changes

* Add a hidden pregblank option to buyers_organisations
pull/1360/head
kosiakkatrina 2 years ago committed by GitHub
parent
commit
6db3b06d8f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 12
      app/models/form/sales/questions/buyer1_mortgage.rb
  2. 4
      app/models/form/sales/questions/buyer1_previous_tenure.rb
  3. 12
      app/models/form/sales/questions/buyer2_mortgage.rb
  4. 10
      app/models/form/sales/questions/buyers_organisations.rb
  5. 8
      app/models/form/sales/questions/mortgageused.rb
  6. 2
      app/models/validations/sales/sale_information_validations.rb
  7. 2
      app/models/validations/sales/soft_validations.rb
  8. 5
      db/migrate/20230301144555_add_pregblank.rb
  9. 3
      db/schema.rb
  10. 13
      spec/models/form/sales/questions/buyer1_mortgage_spec.rb
  11. 5
      spec/models/form/sales/questions/buyer1_previous_tenure_spec.rb
  12. 13
      spec/models/form/sales/questions/buyer2_mortgage_spec.rb
  13. 12
      spec/models/form/sales/questions/buyers_organisations_spec.rb
  14. 9
      spec/models/form/sales/questions/mortgageused_spec.rb

12
app/models/form/sales/questions/buyer1_mortgage.rb

@ -2,8 +2,8 @@ class Form::Sales::Questions::Buyer1Mortgage < ::Form::Question
def initialize(id, hsh, page) def initialize(id, hsh, page)
super super
@id = "inc1mort" @id = "inc1mort"
@check_answer_label = "Buyer 1's income used for mortgage application" @check_answer_label = "Buyer 1s income used for mortgage application"
@header = "Was buyer 1's income used for a mortgage application?" @header = "Was buyer 1s income used for a mortgage application?"
@type = "radio" @type = "radio"
@answer_options = ANSWER_OPTIONS @answer_options = ANSWER_OPTIONS
@check_answers_card_number = 1 @check_answers_card_number = 1
@ -12,5 +12,13 @@ class Form::Sales::Questions::Buyer1Mortgage < ::Form::Question
ANSWER_OPTIONS = { ANSWER_OPTIONS = {
"1" => { "value" => "Yes" }, "1" => { "value" => "Yes" },
"2" => { "value" => "No" }, "2" => { "value" => "No" },
"3" => { "value" => "Don’t know" },
}.freeze }.freeze
def displayed_answer_options(_log, _user = nil)
{
"1" => { "value" => "Yes" },
"2" => { "value" => "No" },
}
end
end end

4
app/models/form/sales/questions/buyer1_previous_tenure.rb

@ -2,8 +2,8 @@ class Form::Sales::Questions::Buyer1PreviousTenure < ::Form::Question
def initialize(id, hsh, page) def initialize(id, hsh, page)
super super
@id = "prevten" @id = "prevten"
@check_answer_label = "Buyer 1's previous tenure" @check_answer_label = "Buyer 1s previous tenure"
@header = "What was buyer 1's previous tenure?" @header = "What was buyer 1s previous tenure?"
@type = "radio" @type = "radio"
@answer_options = ANSWER_OPTIONS @answer_options = ANSWER_OPTIONS
end end

12
app/models/form/sales/questions/buyer2_mortgage.rb

@ -2,8 +2,8 @@ class Form::Sales::Questions::Buyer2Mortgage < ::Form::Question
def initialize(id, hsh, page) def initialize(id, hsh, page)
super super
@id = "inc2mort" @id = "inc2mort"
@check_answer_label = "Buyer 2's income used for mortgage application" @check_answer_label = "Buyer 2s income used for mortgage application"
@header = "Was buyer 2's income used for a mortgage application?" @header = "Was buyer 2s income used for a mortgage application?"
@type = "radio" @type = "radio"
@answer_options = ANSWER_OPTIONS @answer_options = ANSWER_OPTIONS
@check_answers_card_number = 2 @check_answers_card_number = 2
@ -12,5 +12,13 @@ class Form::Sales::Questions::Buyer2Mortgage < ::Form::Question
ANSWER_OPTIONS = { ANSWER_OPTIONS = {
"1" => { "value" => "Yes" }, "1" => { "value" => "Yes" },
"2" => { "value" => "No" }, "2" => { "value" => "No" },
"3" => { "value" => "Don’t know" },
}.freeze }.freeze
def displayed_answer_options(_log, _user = nil)
{
"1" => { "value" => "Yes" },
"2" => { "value" => "No" },
}
end
end end

10
app/models/form/sales/questions/buyers_organisations.rb

@ -14,8 +14,18 @@ class Form::Sales::Questions::BuyersOrganisations < ::Form::Question
"pregother" => { "value" => "Other private registered provider (PRP) - housing association" }, "pregother" => { "value" => "Other private registered provider (PRP) - housing association" },
"pregla" => { "value" => "Local Authority" }, "pregla" => { "value" => "Local Authority" },
"pregghb" => { "value" => "Help to Buy Agent" }, "pregghb" => { "value" => "Help to Buy Agent" },
"pregblank" => { "value" => "None of the above" },
}.freeze }.freeze
def displayed_answer_options(_log, _user = nil)
{
"pregyrha" => { "value" => "Their private registered provider (PRP) - housing association" },
"pregother" => { "value" => "Other private registered provider (PRP) - housing association" },
"pregla" => { "value" => "Local Authority" },
"pregghb" => { "value" => "Help to Buy Agent" },
}
end
def unanswered_error_message def unanswered_error_message
"At least one option must be selected of these four" "At least one option must be selected of these four"
end end

8
app/models/form/sales/questions/mortgageused.rb

@ -11,5 +11,13 @@ class Form::Sales::Questions::Mortgageused < ::Form::Question
ANSWER_OPTIONS = { ANSWER_OPTIONS = {
"1" => { "value" => "Yes" }, "1" => { "value" => "Yes" },
"2" => { "value" => "No" }, "2" => { "value" => "No" },
"3" => { "value" => "Don’t know" },
}.freeze }.freeze
def displayed_answer_options(_log, _user = nil)
{
"1" => { "value" => "Yes" },
"2" => { "value" => "No" },
}
end
end end

2
app/models/validations/sales/sale_information_validations.rb

@ -46,7 +46,7 @@ module Validations::Sales::SaleInformationValidations
def validate_discounted_ownership_value(record) def validate_discounted_ownership_value(record)
return unless record.value && record.deposit && record.ownershipsch return unless record.value && record.deposit && record.ownershipsch
return unless record.mortgage || record.mortgageused == 2 return unless record.mortgage || record.mortgageused == 2 || record.mortgageused == 3
return unless record.discount || record.grant || record.type == 29 return unless record.discount || record.grant || record.type == 29
discount_amount = record.discount ? record.value * record.discount / 100 : 0 discount_amount = record.discount ? record.value * record.discount / 100 : 0

2
app/models/validations/sales/soft_validations.rb

@ -60,7 +60,7 @@ module Validations::Sales::SoftValidations
end end
def shared_ownership_deposit_invalid? def shared_ownership_deposit_invalid?
return unless mortgage || mortgageused == 2 return unless mortgage || mortgageused == 2 || mortgageused == 3
return unless cashdis || !is_type_discount? return unless cashdis || !is_type_discount?
return unless deposit && value && equity return unless deposit && value && equity

5
db/migrate/20230301144555_add_pregblank.rb

@ -0,0 +1,5 @@
class AddPregblank < ActiveRecord::Migration[7.0]
def change
add_column :sales_logs, :pregblank, :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_15_112932) do ActiveRecord::Schema[7.0].define(version: 2023_03_01_144555) 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"
@ -531,6 +531,7 @@ ActiveRecord::Schema[7.0].define(version: 2023_02_15_112932) do
t.integer "prevshared" t.integer "prevshared"
t.integer "staircasesale" t.integer "staircasesale"
t.string "old_id" t.string "old_id"
t.integer "pregblank"
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"
t.index ["old_id"], name: "index_sales_logs_on_old_id", unique: true t.index ["old_id"], name: "index_sales_logs_on_old_id", unique: true

13
spec/models/form/sales/questions/buyer1_mortgage_spec.rb

@ -6,6 +6,7 @@ RSpec.describe Form::Sales::Questions::Buyer1Mortgage, type: :model do
let(:question_id) { nil } let(:question_id) { nil }
let(:question_definition) { nil } let(:question_definition) { nil }
let(:page) { instance_double(Form::Page) } let(:page) { instance_double(Form::Page) }
let(:log) { create(:sales_log) }
it "has correct page" do it "has correct page" do
expect(question.page).to eq(page) expect(question.page).to eq(page)
@ -16,11 +17,11 @@ RSpec.describe Form::Sales::Questions::Buyer1Mortgage, type: :model do
end end
it "has the correct header" do it "has the correct header" do
expect(question.header).to eq("Was buyer 1's income used for a mortgage application?") expect(question.header).to eq("Was buyer 1s income used for a mortgage application?")
end end
it "has the correct check_answer_label" do it "has the correct check_answer_label" do
expect(question.check_answer_label).to eq("Buyer 1's income used for mortgage application") expect(question.check_answer_label).to eq("Buyer 1s income used for mortgage application")
end end
it "has the correct type" do it "has the correct type" do
@ -35,6 +36,14 @@ RSpec.describe Form::Sales::Questions::Buyer1Mortgage, type: :model do
expect(question.answer_options).to eq({ expect(question.answer_options).to eq({
"1" => { "value" => "Yes" }, "1" => { "value" => "Yes" },
"2" => { "value" => "No" }, "2" => { "value" => "No" },
"3" => { "value" => "Don’t know" },
})
end
it "has the correct displayed_answer_options" do
expect(question.displayed_answer_options(log)).to eq({
"1" => { "value" => "Yes" },
"2" => { "value" => "No" },
}) })
end end

5
spec/models/form/sales/questions/buyer1_previous_tenure_spec.rb

@ -6,6 +6,7 @@ RSpec.describe Form::Sales::Questions::Buyer1PreviousTenure, type: :model do
let(:question_id) { nil } let(:question_id) { nil }
let(:question_definition) { nil } let(:question_definition) { nil }
let(:page) { instance_double(Form::Page) } let(:page) { instance_double(Form::Page) }
let(:log) { create(:sales_log) }
it "has correct page" do it "has correct page" do
expect(question.page).to eq(page) expect(question.page).to eq(page)
@ -16,11 +17,11 @@ RSpec.describe Form::Sales::Questions::Buyer1PreviousTenure, type: :model do
end end
it "has the correct header" do it "has the correct header" do
expect(question.header).to eq("What was buyer 1's previous tenure?") expect(question.header).to eq("What was buyer 1s previous tenure?")
end end
it "has the correct check_answer_label" do it "has the correct check_answer_label" do
expect(question.check_answer_label).to eq("Buyer 1's previous tenure") expect(question.check_answer_label).to eq("Buyer 1s previous tenure")
end end
it "has the correct type" do it "has the correct type" do

13
spec/models/form/sales/questions/buyer2_mortgage_spec.rb

@ -6,6 +6,7 @@ RSpec.describe Form::Sales::Questions::Buyer2Mortgage, type: :model do
let(:question_id) { nil } let(:question_id) { nil }
let(:question_definition) { nil } let(:question_definition) { nil }
let(:page) { instance_double(Form::Page) } let(:page) { instance_double(Form::Page) }
let(:log) { create(:sales_log) }
it "has correct page" do it "has correct page" do
expect(question.page).to eq(page) expect(question.page).to eq(page)
@ -16,11 +17,11 @@ RSpec.describe Form::Sales::Questions::Buyer2Mortgage, type: :model do
end end
it "has the correct header" do it "has the correct header" do
expect(question.header).to eq("Was buyer 2's income used for a mortgage application?") expect(question.header).to eq("Was buyer 2s income used for a mortgage application?")
end end
it "has the correct check_answer_label" do it "has the correct check_answer_label" do
expect(question.check_answer_label).to eq("Buyer 2's income used for mortgage application") expect(question.check_answer_label).to eq("Buyer 2s income used for mortgage application")
end end
it "has the correct type" do it "has the correct type" do
@ -35,6 +36,14 @@ RSpec.describe Form::Sales::Questions::Buyer2Mortgage, type: :model do
expect(question.answer_options).to eq({ expect(question.answer_options).to eq({
"1" => { "value" => "Yes" }, "1" => { "value" => "Yes" },
"2" => { "value" => "No" }, "2" => { "value" => "No" },
"3" => { "value" => "Don’t know" },
})
end
it "has the correct displayed_answer_options" do
expect(question.displayed_answer_options(log)).to eq({
"1" => { "value" => "Yes" },
"2" => { "value" => "No" },
}) })
end end

12
spec/models/form/sales/questions/buyers_organisations_spec.rb

@ -41,6 +41,18 @@ RSpec.describe Form::Sales::Questions::BuyersOrganisations, type: :model do
it "has the correct answer_options" do it "has the correct answer_options" do
expect(question.answer_options).to eq( expect(question.answer_options).to eq(
{
"pregyrha" => { "value" => "Their private registered provider (PRP) - housing association" },
"pregother" => { "value" => "Other private registered provider (PRP) - housing association" },
"pregla" => { "value" => "Local Authority" },
"pregghb" => { "value" => "Help to Buy Agent" },
"pregblank" => { "value" => "None of the above" },
},
)
end
it "has the correct displayed_answer_options" do
expect(question.displayed_answer_options(FactoryBot.create(:sales_log))).to eq(
{ {
"pregyrha" => { "value" => "Their private registered provider (PRP) - housing association" }, "pregyrha" => { "value" => "Their private registered provider (PRP) - housing association" },
"pregother" => { "value" => "Other private registered provider (PRP) - housing association" }, "pregother" => { "value" => "Other private registered provider (PRP) - housing association" },

9
spec/models/form/sales/questions/mortgageused_spec.rb

@ -6,6 +6,7 @@ RSpec.describe Form::Sales::Questions::Mortgageused, type: :model do
let(:question_id) { nil } let(:question_id) { nil }
let(:question_definition) { nil } let(:question_definition) { nil }
let(:page) { instance_double(Form::Page) } let(:page) { instance_double(Form::Page) }
let(:log) { create(:sales_log) }
it "has correct page" do it "has correct page" do
expect(question.page).to eq(page) expect(question.page).to eq(page)
@ -35,6 +36,7 @@ RSpec.describe Form::Sales::Questions::Mortgageused, type: :model do
expect(question.answer_options).to eq({ expect(question.answer_options).to eq({
"1" => { "value" => "Yes" }, "1" => { "value" => "Yes" },
"2" => { "value" => "No" }, "2" => { "value" => "No" },
"3" => { "value" => "Don’t know" },
}) })
end end
@ -45,4 +47,11 @@ RSpec.describe Form::Sales::Questions::Mortgageused, type: :model do
it "has the correct hint" do it "has the correct hint" do
expect(question.hint_text).to be_nil expect(question.hint_text).to be_nil
end end
it "has the correct displayed_answer_options" do
expect(question.displayed_answer_options(log)).to eq({
"1" => { "value" => "Yes" },
"2" => { "value" => "No" },
})
end
end end

Loading…
Cancel
Save