Browse Source

Update mscharge question wording (#1532)

* rename mscharge known

* Update field name across the codebase

* Rename files

* Set has_mscharge to no if mscharge is 0

* update question wording
pull/1536/head
kosiakkatrina 2 years ago committed by GitHub
parent
commit
94dcc2ace8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      app/models/derived_variables/sales_log_variables.rb
  2. 2
      app/models/form/sales/pages/leasehold_charges.rb
  3. 10
      app/models/form/sales/questions/has_leasehold_charges.rb
  4. 4
      app/models/sales_log.rb
  5. 3
      app/services/imports/sales_logs_import_service.rb
  6. 5
      db/migrate/20230412143245_rename_mscharge_known.rb
  7. 4
      db/schema.rb
  8. 2
      spec/factories/sales_log.rb
  9. 2
      spec/models/form/sales/pages/leasehold_charges_spec.rb
  10. 10
      spec/models/form/sales/questions/has_leasehold_charges_spec.rb
  11. 34
      spec/services/imports/sales_logs_import_service_spec.rb

2
app/models/derived_variables/sales_log_variables.rb

@ -1,7 +1,7 @@
module DerivedVariables::SalesLogVariables module DerivedVariables::SalesLogVariables
def set_derived_fields! def set_derived_fields!
self.ethnic = 17 if ethnic_refused? self.ethnic = 17 if ethnic_refused?
self.mscharge = nil if monthly_leasehold_charges_unknown? self.mscharge = nil if no_monthly_leasehold_charges?
if exdate.present? if exdate.present?
self.exday = exdate.day self.exday = exdate.day
self.exmonth = exdate.month self.exmonth = exdate.month

2
app/models/form/sales/pages/leasehold_charges.rb

@ -6,7 +6,7 @@ class Form::Sales::Pages::LeaseholdCharges < ::Form::Page
def questions def questions
@questions ||= [ @questions ||= [
Form::Sales::Questions::LeaseholdChargesKnown.new(nil, nil, self, ownershipsch: @ownershipsch), Form::Sales::Questions::HasLeaseholdCharges.new(nil, nil, self, ownershipsch: @ownershipsch),
Form::Sales::Questions::LeaseholdCharges.new(nil, nil, self, ownershipsch: @ownershipsch), Form::Sales::Questions::LeaseholdCharges.new(nil, nil, self, ownershipsch: @ownershipsch),
] ]
end end

10
app/models/form/sales/questions/leasehold_charges_known.rb → app/models/form/sales/questions/has_leasehold_charges.rb

@ -1,9 +1,9 @@
class Form::Sales::Questions::LeaseholdChargesKnown < ::Form::Question class Form::Sales::Questions::HasLeaseholdCharges < ::Form::Question
def initialize(id, hsh, subsection, ownershipsch:) def initialize(id, hsh, subsection, ownershipsch:)
super(id, hsh, subsection) super(id, hsh, subsection)
@id = "mscharge_known" @id = "has_mscharge"
@check_answer_label = "Monthly leasehold charges known?" @check_answer_label = "Does the property have any monthly leasehold charges?"
@header = "Do you know the monthly leasehold charges for the property?" @header = "Does the property have any monthly leasehold charges?"
@hint_text = "For example, service and management charges" @hint_text = "For example, service and management charges"
@type = "radio" @type = "radio"
@answer_options = ANSWER_OPTIONS @answer_options = ANSWER_OPTIONS
@ -13,7 +13,7 @@ class Form::Sales::Questions::LeaseholdChargesKnown < ::Form::Question
@hidden_in_check_answers = { @hidden_in_check_answers = {
"depends_on" => [ "depends_on" => [
{ {
"mscharge_known" => 1, "has_mscharge" => 1,
}, },
], ],
} }

4
app/models/sales_log.rb

@ -292,8 +292,8 @@ class SalesLog < Log
companybuy == 1 companybuy == 1
end end
def monthly_leasehold_charges_unknown? def no_monthly_leasehold_charges?
mscharge_known&.zero? has_mscharge&.zero?
end end
def buyers_age_for_old_persons_shared_ownership_invalid? def buyers_age_for_old_persons_shared_ownership_invalid?

3
app/services/imports/sales_logs_import_service.rb

@ -107,7 +107,8 @@ module Imports
attributes["hhregresstill"] = still_serving(xml_doc) attributes["hhregresstill"] = still_serving(xml_doc)
attributes["proplen"] = safe_string_as_integer(xml_doc, "Q16aProplen2") || safe_string_as_integer(xml_doc, "Q16aProplensec2") attributes["proplen"] = safe_string_as_integer(xml_doc, "Q16aProplen2") || safe_string_as_integer(xml_doc, "Q16aProplensec2")
attributes["mscharge"] = monthly_charges(xml_doc, attributes) attributes["mscharge"] = monthly_charges(xml_doc, attributes)
attributes["mscharge_known"] = 1 if attributes["mscharge"].present? attributes["has_mscharge"] = 1 if attributes["mscharge"]&.positive?
attributes["has_mscharge"] = 0 if attributes["mscharge"].present? && attributes["mscharge"] <= 0
attributes["prevten"] = unsafe_string_as_integer(xml_doc, "Q6PrevTenure") attributes["prevten"] = unsafe_string_as_integer(xml_doc, "Q6PrevTenure")
attributes["mortlen"] = mortgage_length(xml_doc, attributes) attributes["mortlen"] = mortgage_length(xml_doc, attributes)
attributes["extrabor"] = borrowing(xml_doc, attributes) attributes["extrabor"] = borrowing(xml_doc, attributes)

5
db/migrate/20230412143245_rename_mscharge_known.rb

@ -0,0 +1,5 @@
class RenameMschargeKnown < ActiveRecord::Migration[7.0]
def change
rename_column :sales_logs, :mscharge_known, :has_mscharge
end
end

4
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_03_31_094840) do ActiveRecord::Schema[7.0].define(version: 2023_04_12_143245) 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"
@ -513,7 +513,7 @@ ActiveRecord::Schema[7.0].define(version: 2023_03_31_094840) do
t.integer "hhregres" t.integer "hhregres"
t.integer "hhregresstill" t.integer "hhregresstill"
t.integer "proplen" t.integer "proplen"
t.integer "mscharge_known" t.integer "has_mscharge"
t.decimal "mscharge", precision: 10, scale: 2 t.decimal "mscharge", precision: 10, scale: 2
t.integer "prevten" t.integer "prevten"
t.integer "mortgageused" t.integer "mortgageused"

2
spec/factories/sales_log.rb

@ -92,7 +92,7 @@ FactoryBot.define do
mortgageused { 1 } mortgageused { 1 }
wchair { 1 } wchair { 1 }
armedforcesspouse { 5 } armedforcesspouse { 5 }
mscharge_known { 1 } has_mscharge { 1 }
mscharge { 100 } mscharge { 100 }
mortlen { 10 } mortlen { 10 }
pcodenk { 1 } pcodenk { 1 }

2
spec/models/form/sales/pages/leasehold_charges_spec.rb

@ -12,7 +12,7 @@ RSpec.describe Form::Sales::Pages::LeaseholdCharges, type: :model do
end end
it "has correct questions" do it "has correct questions" do
expect(page.questions.map(&:id)).to eq(%w[mscharge_known mscharge]) expect(page.questions.map(&:id)).to eq(%w[has_mscharge mscharge])
end end
it "has the correct id" do it "has the correct id" do

10
spec/models/form/sales/questions/leasehold_charges_known_spec.rb → spec/models/form/sales/questions/has_leasehold_charges_spec.rb

@ -1,6 +1,6 @@
require "rails_helper" require "rails_helper"
RSpec.describe Form::Sales::Questions::LeaseholdChargesKnown, type: :model do RSpec.describe Form::Sales::Questions::HasLeaseholdCharges, type: :model do
subject(:question) { described_class.new(question_id, question_definition, page, ownershipsch: 1) } subject(:question) { described_class.new(question_id, question_definition, page, ownershipsch: 1) }
let(:question_id) { nil } let(:question_id) { nil }
@ -12,15 +12,15 @@ RSpec.describe Form::Sales::Questions::LeaseholdChargesKnown, type: :model do
end end
it "has the correct id" do it "has the correct id" do
expect(question.id).to eq("mscharge_known") expect(question.id).to eq("has_mscharge")
end end
it "has the correct header" do it "has the correct header" do
expect(question.header).to eq("Do you know the monthly leasehold charges for the property?") expect(question.header).to eq("Does the property have any monthly leasehold charges?")
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("Monthly leasehold charges known?") expect(question.check_answer_label).to eq("Does the property have any monthly leasehold charges?")
end end
it "has the correct type" do it "has the correct type" do
@ -52,7 +52,7 @@ RSpec.describe Form::Sales::Questions::LeaseholdChargesKnown, type: :model do
expect(question.hidden_in_check_answers).to eq({ expect(question.hidden_in_check_answers).to eq({
"depends_on" => [ "depends_on" => [
{ {
"mscharge_known" => 1, "has_mscharge" => 1,
}, },
], ],
}) })

34
spec/services/imports/sales_logs_import_service_spec.rb

@ -1478,6 +1478,40 @@ RSpec.describe Imports::SalesLogsImportService do
expect(sales_log&.jointmore).to eq(3) expect(sales_log&.jointmore).to eq(3)
end end
end end
context "when mscharge is 0" do
let(:sales_log_id) { "shared_ownership_sales_log" }
before do
sales_log_xml.at_xpath("//xmlns:Q29MonthlyCharges").content = "0"
allow(logger).to receive(:warn).and_return(nil)
end
it "sets has_mscharge to no" do
sales_log_service.send(:create_log, sales_log_xml)
sales_log = SalesLog.find_by(old_id: sales_log_id)
expect(sales_log&.has_mscharge).to be(0)
expect(sales_log&.mscharge).to be(nil)
end
end
context "when mscharge is more than 0" do
let(:sales_log_id) { "shared_ownership_sales_log" }
before do
sales_log_xml.at_xpath("//xmlns:Q29MonthlyCharges").content = "100"
allow(logger).to receive(:warn).and_return(nil)
end
it "sets has_mscharge to yes" do
sales_log_service.send(:create_log, sales_log_xml)
sales_log = SalesLog.find_by(old_id: sales_log_id)
expect(sales_log&.has_mscharge).to be(1)
expect(sales_log&.mscharge).to eq(100)
end
end
end end
end end
end end

Loading…
Cancel
Save