Browse Source

Merge branch 'main' into CLDC-1971-update-ethnic-group-copy

pull/2265/head
Robert Sullivan 2 years ago committed by GitHub
parent
commit
6dd37a3aba
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 2
      app/models/form/sales/questions/age1.rb
  2. 2
      app/models/form/sales/questions/buyer1_age_known.rb
  3. 9
      app/models/form/sales/questions/number_joint_buyers.rb
  4. 1
      app/models/log.rb
  5. 8
      app/models/validations/sales/soft_validations.rb
  6. 21
      app/services/bulk_upload/lettings/year2023/row_parser.rb
  7. 20
      app/services/bulk_upload/lettings/year2024/row_parser.rb
  8. 1
      config/locales/en.yml
  9. 2
      spec/models/form/sales/questions/age1_spec.rb
  10. 2
      spec/models/form/sales/questions/buyer1_age_known_spec.rb
  11. 16
      spec/models/form/sales/questions/number_joint_buyers_spec.rb
  12. 20
      spec/models/lettings_log_spec.rb
  13. 50
      spec/models/log_spec.rb
  14. 23
      spec/models/validations/sales/soft_validations_spec.rb
  15. 14
      spec/requests/duplicate_logs_controller_spec.rb
  16. 105
      spec/services/bulk_upload/lettings/year2023/row_parser_spec.rb
  17. 59
      spec/services/bulk_upload/lettings/year2024/row_parser_spec.rb

2
app/models/form/sales/questions/age1.rb

@ -2,7 +2,7 @@ class Form::Sales::Questions::Age1 < ::Form::Question
def initialize(id, hsh, page) def initialize(id, hsh, page)
super super
@id = "age1" @id = "age1"
@check_answer_label = "Lead buyer’s age" @check_answer_label = "Buyer 1’s age"
@header = "Age" @header = "Age"
@type = "numeric" @type = "numeric"
@width = 2 @width = 2

2
app/models/form/sales/questions/buyer1_age_known.rb

@ -2,7 +2,7 @@ class Form::Sales::Questions::Buyer1AgeKnown < ::Form::Question
def initialize(id, hsh, page) def initialize(id, hsh, page)
super super
@id = "age1_known" @id = "age1_known"
@check_answer_label = "Lead buyer’s age" @check_answer_label = "Buyer 1’s age"
@header = "Do you know buyer 1’s age?" @header = "Do you know buyer 1’s age?"
@type = "radio" @type = "radio"
@answer_options = ANSWER_OPTIONS @answer_options = ANSWER_OPTIONS

9
app/models/form/sales/questions/number_joint_buyers.rb

@ -4,7 +4,6 @@ class Form::Sales::Questions::NumberJointBuyers < ::Form::Question
@id = "jointmore" @id = "jointmore"
@check_answer_label = "More than 2 joint buyers" @check_answer_label = "More than 2 joint buyers"
@header = "Are there more than 2 joint buyers of this property?" @header = "Are there more than 2 joint buyers of this property?"
@hint_text = "You should still try to answer all questions even if the buyer wasn't interviewed in person"
@type = "radio" @type = "radio"
@answer_options = ANSWER_OPTIONS @answer_options = ANSWER_OPTIONS
@question_number = 10 @question_number = 10
@ -15,4 +14,12 @@ class Form::Sales::Questions::NumberJointBuyers < ::Form::Question
"2" => { "value" => "No" }, "2" => { "value" => "No" },
"3" => { "value" => "Don’t know" }, "3" => { "value" => "Don’t know" },
}.freeze }.freeze
def hint_text
if form.start_year_after_2024?
nil
else
"You should still try to answer all questions even if the buyer wasn't interviewed in person"
end
end
end end

1
app/models/log.rb

@ -179,6 +179,7 @@ class Log < ApplicationRecord
def blank_compound_invalid_non_setup_fields! def blank_compound_invalid_non_setup_fields!
self.ppcodenk = nil if errors.attribute_names.include? :ppostcode_full self.ppcodenk = nil if errors.attribute_names.include? :ppostcode_full
self.previous_la_known = nil if errors.attribute_names.include? :prevloc
if errors.of_kind?(:uprn, :uprn_error) if errors.of_kind?(:uprn, :uprn_error)
self.uprn_known = nil self.uprn_known = nil

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

@ -89,9 +89,11 @@ module Validations::Sales::SoftValidations
return unless cashdis || !is_type_discount? return unless cashdis || !is_type_discount?
return unless deposit && value && equity return unless deposit && value && equity
cash_discount = cashdis || 0 !within_tolerance?(mortgage_deposit_and_discount_total, value * equity / 100, 1)
mortgage_value = mortgage || 0 end
mortgage_value + deposit + cash_discount != value * equity / 100
def within_tolerance?(expected, actual, tolerance)
(expected - actual).abs <= tolerance
end end
def mortgage_plus_deposit_less_than_discounted_value? def mortgage_plus_deposit_less_than_discounted_value?

21
app/services/bulk_upload/lettings/year2023/row_parser.rb

@ -391,6 +391,7 @@ class BulkUpload::Lettings::Year2023::RowParser
validate :validate_correct_intermediate_rent_type, on: :after_log, if: proc { renttype == :intermediate } validate :validate_correct_intermediate_rent_type, on: :after_log, if: proc { renttype == :intermediate }
validate :validate_correct_affordable_rent_type, on: :after_log, if: proc { renttype == :affordable } validate :validate_correct_affordable_rent_type, on: :after_log, if: proc { renttype == :affordable }
validate :validate_all_charges_given, on: :after_log, if: proc { is_carehome.zero? }
def self.question_for_field(field) def self.question_for_field(field)
QUESTIONS[field] QUESTIONS[field]
@ -854,6 +855,20 @@ private
end end
end end
def validate_all_charges_given
return if supported_housing? && field_125 == 1
{ field_128: "basic rent",
field_129: "service charge",
field_130: "personal service charge",
field_131: "support charge",
field_132: "total charge" }.each do |field, charge|
if public_send(field.to_sym).blank?
errors.add(field, I18n.t("validations.financial.charges.missing_charges", question: charge))
end
end
end
def setup_question?(question) def setup_question?(question)
log.form.setup_sections[0].subsections[0].questions.include?(question) log.form.setup_sections[0].subsections[0].questions.include?(question)
end end
@ -1192,7 +1207,7 @@ private
attributes["supcharg"] = field_131 attributes["supcharg"] = field_131
attributes["tcharge"] = field_132 attributes["tcharge"] = field_132
attributes["chcharge"] = field_127 attributes["chcharge"] = field_127
attributes["is_carehome"] = field_127.present? ? 1 : 0 attributes["is_carehome"] = is_carehome
attributes["household_charge"] = supported_housing? ? field_125 : nil attributes["household_charge"] = supported_housing? ? field_125 : nil
attributes["hbrentshortfall"] = field_133 attributes["hbrentshortfall"] = field_133
attributes["tshortfall_known"] = tshortfall_known attributes["tshortfall_known"] = tshortfall_known
@ -1574,4 +1589,8 @@ private
0 0
end end
end end
def is_carehome
field_127.present? ? 1 : 0
end
end end

20
app/services/bulk_upload/lettings/year2024/row_parser.rb

@ -382,6 +382,7 @@ class BulkUpload::Lettings::Year2024::RowParser
validate :validate_uprn_exists_if_any_key_address_fields_are_blank, on: :after_log, unless: -> { supported_housing? } validate :validate_uprn_exists_if_any_key_address_fields_are_blank, on: :after_log, unless: -> { supported_housing? }
validate :validate_incomplete_soft_validations, on: :after_log validate :validate_incomplete_soft_validations, on: :after_log
validate :validate_all_charges_given, on: :after_log, if: proc { is_carehome.zero? }
def self.question_for_field(field) def self.question_for_field(field)
QUESTIONS[field] QUESTIONS[field]
@ -810,6 +811,19 @@ private
end end
end end
def validate_all_charges_given
return if supported_housing? && field_125 == 1
{ field_125: "basic rent",
field_126: "service charge",
field_127: "personal service charge",
field_128: "support charge" }.each do |field, charge|
if public_send(field.to_sym).blank?
errors.add(field, I18n.t("validations.financial.charges.missing_charges", question: charge))
end
end
end
def setup_question?(question) def setup_question?(question)
log.form.setup_sections[0].subsections[0].questions.include?(question) log.form.setup_sections[0].subsections[0].questions.include?(question)
end end
@ -1152,7 +1166,7 @@ private
attributes["pscharge"] = field_127 attributes["pscharge"] = field_127
attributes["supcharg"] = field_128 attributes["supcharg"] = field_128
attributes["chcharge"] = field_124 attributes["chcharge"] = field_124
attributes["is_carehome"] = field_124.present? ? 1 : 0 attributes["is_carehome"] = is_carehome
attributes["household_charge"] = supported_housing? ? field_122 : nil attributes["household_charge"] = supported_housing? ? field_122 : nil
attributes["hbrentshortfall"] = field_129 attributes["hbrentshortfall"] = field_129
attributes["tshortfall_known"] = tshortfall_known attributes["tshortfall_known"] = tshortfall_known
@ -1479,4 +1493,8 @@ private
12 12
end end
def is_carehome
field_124.present? ? 1 : 0
end
end end

1
config/locales/en.yml

@ -418,6 +418,7 @@ en:
above_hard_max: "Rent is higher than the absolute maximum expected for a property of this type based on this period" above_hard_max: "Rent is higher than the absolute maximum expected for a property of this type based on this period"
charges: charges:
complete_1_of_3: "Answer either the ‘household rent and charges’ question or ‘is this accommodation a care home‘, or select ‘no’ for ‘does the household pay rent or charges for the accommodation?’" complete_1_of_3: "Answer either the ‘household rent and charges’ question or ‘is this accommodation a care home‘, or select ‘no’ for ‘does the household pay rent or charges for the accommodation?’"
missing_charges: "Please enter the %{question}. If there is no %{question}, please enter '0'."
tcharge: tcharge:
under_10: "Enter a total charge that is at least £10.00 per week" under_10: "Enter a total charge that is at least £10.00 per week"
rent_period: rent_period:

2
spec/models/form/sales/questions/age1_spec.rb

@ -20,7 +20,7 @@ RSpec.describe Form::Sales::Questions::Age1, type: :model do
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("Lead buyer’s age") expect(question.check_answer_label).to eq("Buyer 1’s age")
end end
it "has the correct type" do it "has the correct type" do

2
spec/models/form/sales/questions/buyer1_age_known_spec.rb

@ -20,7 +20,7 @@ RSpec.describe Form::Sales::Questions::Buyer1AgeKnown, type: :model do
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("Lead buyer’s age") expect(question.check_answer_label).to eq("Buyer 1’s age")
end end
it "has the correct type" do it "has the correct type" do

16
spec/models/form/sales/questions/number_joint_buyers_spec.rb

@ -6,6 +6,12 @@ RSpec.describe Form::Sales::Questions::NumberJointBuyers, 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(:subsection) { instance_double(Form::Subsection) }
before do
allow(page).to receive(:subsection).and_return(subsection)
allow(subsection).to receive(:form).and_return(instance_double(Form, start_year_after_2024?: false))
end
it "has correct page" do it "has correct page" do
expect(question.page).to eq(page) expect(question.page).to eq(page)
@ -42,4 +48,14 @@ RSpec.describe Form::Sales::Questions::NumberJointBuyers, type: :model do
"3" => { "value" => "Don’t know" }, "3" => { "value" => "Don’t know" },
}) })
end end
context "with 2024 form" do
before do
allow(subsection).to receive(:form).and_return(instance_double(Form, start_year_after_2024?: true))
end
it "has no hint_text" do
expect(question.hint_text).to be_nil
end
end
end end

20
spec/models/lettings_log_spec.rb

@ -3382,26 +3382,6 @@ RSpec.describe LettingsLog do
end end
end end
describe "#blank_invalid_non_setup_fields!" do
context "when a setup field is invalid" do
subject(:model) { described_class.new(needstype: 404) }
it "does not blank it" do
model.valid?
expect { model.blank_invalid_non_setup_fields! }.not_to change(model, :needstype)
end
end
context "when a non setup field is invalid" do
subject(:model) { build(:lettings_log, :completed, offered: 234) }
it "blanks it" do
model.valid?
expect { model.blank_invalid_non_setup_fields! }.to change(model, :offered)
end
end
end
describe "#beds_for_la_rent_range" do describe "#beds_for_la_rent_range" do
context "when beds nil" do context "when beds nil" do
let(:lettings_log) { build(:lettings_log, beds: nil) } let(:lettings_log) { build(:lettings_log, beds: nil) }

50
spec/models/log_spec.rb

@ -27,4 +27,54 @@ RSpec.describe Log, type: :model do
expect(in_progress_lettings_log.calculate_status).to eq "in_progress" expect(in_progress_lettings_log.calculate_status).to eq "in_progress"
end end
end end
describe "#blank_invalid_non_setup_fields!" do
context "when a setup field is invalid for a lettings log" do
subject(:model) { build(:lettings_log, needstype: 404) }
it "does not blank it" do
model.valid?
expect { model.blank_invalid_non_setup_fields! }.not_to change(model, :needstype)
end
end
context "when a setup field is invalid for a sales log" do
subject(:model) { build(:sales_log, companybuy: 404) }
it "does not blank it" do
model.valid?
expect { model.blank_invalid_non_setup_fields! }.not_to change(model, :companybuy)
end
end
context "when a non setup field is invalid for a lettings log" do
subject(:model) { build(:lettings_log, :completed, offered: 234) }
it "blanks it" do
model.valid?
model.blank_invalid_non_setup_fields!
expect(model.offered).to be_nil
end
end
context "when a non setup field is invalid for a sales log" do
subject(:model) { build(:sales_log, :completed, age1: 10) }
it "blanks it" do
model.valid?
model.blank_invalid_non_setup_fields!
expect(model.age1).to be_nil
end
end
context "when prevloc is invalid for a lettings log" do
subject(:model) { build(:lettings_log, :completed, previous_la_known: 1, prevloc: nil) }
it "blanks previous_la_known" do
model.valid?
model.blank_invalid_non_setup_fields!
expect(model.previous_la_known).to be_nil
end
end
end
end end

23
spec/models/validations/sales/soft_validations_spec.rb

@ -415,6 +415,17 @@ RSpec.describe Validations::Sales::SoftValidations do
.not_to be_shared_ownership_deposit_invalid .not_to be_shared_ownership_deposit_invalid
end end
it "returns false if MORTGAGE + DEPOSIT + CASHDIS are within 1£ of VALUE * EQUITY/100" do
record.mortgage = 500
record.deposit = 500
record.cashdis = 500
record.value = 3001
record.equity = 50
expect(record)
.not_to be_shared_ownership_deposit_invalid
end
it "returns false if mortgage is used and no mortgage is given" do it "returns false if mortgage is used and no mortgage is given" do
record.mortgage = nil record.mortgage = nil
record.deposit = 1000 record.deposit = 1000
@ -473,6 +484,18 @@ RSpec.describe Validations::Sales::SoftValidations do
.to be_shared_ownership_deposit_invalid .to be_shared_ownership_deposit_invalid
end end
it "returns false if no cashdis not routed to and MORTGAGE + DEPOSIT are within 1£ of VALUE * EQUITY/100" do
record.mortgage = 500
record.deposit = 500
record.type = 2
record.cashdis = nil
record.value = 1999
record.equity = 50
expect(record)
.not_to be_shared_ownership_deposit_invalid
end
it "returns false if no value is given" do it "returns false if no value is given" do
record.mortgage = 1000 record.mortgage = 1000
record.deposit = 1000 record.deposit = 1000

14
spec/requests/duplicate_logs_controller_spec.rb

@ -169,7 +169,7 @@ RSpec.describe DuplicateLogsController, type: :request do
it "displays check your answers for each log with correct questions" do it "displays check your answers for each log with correct questions" do
expect(page).to have_content("Q1 - Sale completion date", count: 3) expect(page).to have_content("Q1 - Sale completion date", count: 3)
expect(page).to have_content("Q2 - Purchaser code", count: 3) expect(page).to have_content("Q2 - Purchaser code", count: 3)
expect(page).to have_content("Q20 - Lead buyer’s age", count: 3) expect(page).to have_content("Q20 - Buyer 1’s age", count: 3)
expect(page).to have_content("Q21 - Buyer 1’s gender identity", count: 3) expect(page).to have_content("Q21 - Buyer 1’s gender identity", count: 3)
expect(page).to have_content("Q25 - Buyer 1's working situation", count: 3) expect(page).to have_content("Q25 - Buyer 1's working situation", count: 3)
expect(page).to have_content("Q15 - Postcode", count: 3) expect(page).to have_content("Q15 - Postcode", count: 3)
@ -187,7 +187,7 @@ RSpec.describe DuplicateLogsController, type: :request do
expect(page).to have_content("Q1 - Sale completion date", count: 3) expect(page).to have_content("Q1 - Sale completion date", count: 3)
expect(page).to have_content("Q2 - Purchaser code", count: 3) expect(page).to have_content("Q2 - Purchaser code", count: 3)
expect(page).to have_content("Q20 - Lead buyer’s age", count: 3) expect(page).to have_content("Q20 - Buyer 1’s age", count: 3)
expect(page).to have_content("Q21 - Buyer 1’s gender identity", count: 3) expect(page).to have_content("Q21 - Buyer 1’s gender identity", count: 3)
expect(page).to have_content("Q25 - Buyer 1's working situation", count: 3) expect(page).to have_content("Q25 - Buyer 1's working situation", count: 3)
expect(page).to have_content("Postcode (from UPRN)", count: 3) expect(page).to have_content("Postcode (from UPRN)", count: 3)
@ -215,7 +215,7 @@ RSpec.describe DuplicateLogsController, type: :request do
it "displays check your answers for each log with correct questions" do it "displays check your answers for each log with correct questions" do
expect(page).to have_content("Q1 - Sale completion date", count: 1) expect(page).to have_content("Q1 - Sale completion date", count: 1)
expect(page).to have_content("Q2 - Purchaser code", count: 1) expect(page).to have_content("Q2 - Purchaser code", count: 1)
expect(page).to have_content("Q20 - Lead buyer’s age", count: 1) expect(page).to have_content("Q20 - Buyer 1’s age", count: 1)
expect(page).to have_content("Q21 - Buyer 1’s gender identity", count: 1) expect(page).to have_content("Q21 - Buyer 1’s gender identity", count: 1)
expect(page).to have_content("Q25 - Buyer 1's working situation", count: 1) expect(page).to have_content("Q25 - Buyer 1's working situation", count: 1)
expect(page).to have_content("Q15 - Postcode", count: 1) expect(page).to have_content("Q15 - Postcode", count: 1)
@ -241,7 +241,7 @@ RSpec.describe DuplicateLogsController, type: :request do
it "displays check your answers for each log with correct questions" do it "displays check your answers for each log with correct questions" do
expect(page).to have_content("Q1 - Sale completion date", count: 1) expect(page).to have_content("Q1 - Sale completion date", count: 1)
expect(page).to have_content("Q2 - Purchaser code", count: 1) expect(page).to have_content("Q2 - Purchaser code", count: 1)
expect(page).to have_content("Q20 - Lead buyer’s age", count: 1) expect(page).to have_content("Q20 - Buyer 1’s age", count: 1)
expect(page).to have_content("Q21 - Buyer 1’s gender identity", count: 1) expect(page).to have_content("Q21 - Buyer 1’s gender identity", count: 1)
expect(page).to have_content("Q25 - Buyer 1's working situation", count: 1) expect(page).to have_content("Q25 - Buyer 1's working situation", count: 1)
expect(page).to have_content("Q15 - Postcode", count: 1) expect(page).to have_content("Q15 - Postcode", count: 1)
@ -379,7 +379,7 @@ RSpec.describe DuplicateLogsController, type: :request do
it "displays check your answers for each log with correct questions" do it "displays check your answers for each log with correct questions" do
expect(page).to have_content("Q1 - Sale completion date", count: 3) expect(page).to have_content("Q1 - Sale completion date", count: 3)
expect(page).to have_content("Q2 - Purchaser code", count: 3) expect(page).to have_content("Q2 - Purchaser code", count: 3)
expect(page).to have_content("Q20 - Lead buyer’s age", count: 3) expect(page).to have_content("Q20 - Buyer 1’s age", count: 3)
expect(page).to have_content("Q21 - Buyer 1’s gender identity", count: 3) expect(page).to have_content("Q21 - Buyer 1’s gender identity", count: 3)
expect(page).to have_content("Q25 - Buyer 1's working situation", count: 3) expect(page).to have_content("Q25 - Buyer 1's working situation", count: 3)
expect(page).to have_content("Q15 - Postcode", count: 3) expect(page).to have_content("Q15 - Postcode", count: 3)
@ -407,7 +407,7 @@ RSpec.describe DuplicateLogsController, type: :request do
it "displays check your answers for each log with correct questions" do it "displays check your answers for each log with correct questions" do
expect(page).to have_content("Q1 - Sale completion date", count: 1) expect(page).to have_content("Q1 - Sale completion date", count: 1)
expect(page).to have_content("Q2 - Purchaser code", count: 1) expect(page).to have_content("Q2 - Purchaser code", count: 1)
expect(page).to have_content("Q20 - Lead buyer’s age", count: 1) expect(page).to have_content("Q20 - Buyer 1’s age", count: 1)
expect(page).to have_content("Q21 - Buyer 1’s gender identity", count: 1) expect(page).to have_content("Q21 - Buyer 1’s gender identity", count: 1)
expect(page).to have_content("Q25 - Buyer 1's working situation", count: 1) expect(page).to have_content("Q25 - Buyer 1's working situation", count: 1)
expect(page).to have_content("Q15 - Postcode", count: 1) expect(page).to have_content("Q15 - Postcode", count: 1)
@ -433,7 +433,7 @@ RSpec.describe DuplicateLogsController, type: :request do
it "displays check your answers for each log with correct questions" do it "displays check your answers for each log with correct questions" do
expect(page).to have_content("Q1 - Sale completion date", count: 1) expect(page).to have_content("Q1 - Sale completion date", count: 1)
expect(page).to have_content("Q2 - Purchaser code", count: 1) expect(page).to have_content("Q2 - Purchaser code", count: 1)
expect(page).to have_content("Q20 - Lead buyer’s age", count: 1) expect(page).to have_content("Q20 - Buyer 1’s age", count: 1)
expect(page).to have_content("Q21 - Buyer 1’s gender identity", count: 1) expect(page).to have_content("Q21 - Buyer 1’s gender identity", count: 1)
expect(page).to have_content("Q25 - Buyer 1's working situation", count: 1) expect(page).to have_content("Q25 - Buyer 1's working situation", count: 1)
expect(page).to have_content("Q15 - Postcode", count: 1) expect(page).to have_content("Q15 - Postcode", count: 1)

105
spec/services/bulk_upload/lettings/year2023/row_parser_spec.rb

@ -2294,19 +2294,76 @@ RSpec.describe BulkUpload::Lettings::Year2023::RowParser do
end end
describe "#chcharge" do describe "#chcharge" do
let(:attributes) { { bulk_upload:, field_127: "123.45" } } let(:attributes) { { bulk_upload:, field_127: "123.45", field_131: "123.45", field_130: "123.45", field_129: "123.45", field_128: "123.45" } }
it "sets value given" do it "sets value given" do
expect(parser.log.chcharge).to eq(123.45) expect(parser.log.chcharge).to eq(123.45)
end end
it "sets is care home to yes" do
expect(parser.log.is_carehome).to eq(1)
end
it "clears any other given charges" do
parser.log.save!
expect(parser.log.tcharge).to be_nil
expect(parser.log.brent).to be_nil
expect(parser.log.supcharg).to be_nil
expect(parser.log.pscharge).to be_nil
expect(parser.log.scharge).to be_nil
end
end end
describe "#tcharge" do describe "#tcharge" do
let(:attributes) { { bulk_upload:, field_132: "123.45" } } let(:attributes) { { bulk_upload:, field_132: "123.45", field_127: "123.45", field_128: "123.45", field_129: "123.45", field_130: "123.45", field_131: "123.45" } }
it "sets value given" do it "sets value given" do
expect(parser.log.tcharge).to eq(123.45) expect(parser.log.tcharge).to eq(123.45)
end end
context "when other charges are not given" do
context "and it is carehome" do
let(:attributes) { { bulk_upload:, field_132: "123.45", field_127: "123.45", field_128: nil, field_129: nil, field_130: nil, field_131: nil } }
it "does not set charges values" do
parser.log.save!
expect(parser.log.tcharge).to be_nil
expect(parser.log.brent).to be_nil
expect(parser.log.supcharg).to be_nil
expect(parser.log.pscharge).to be_nil
expect(parser.log.scharge).to be_nil
end
it "does not add errors to missing charges" do
parser.valid?
expect(parser.errors[:field_128]).to be_empty
expect(parser.errors[:field_129]).to be_empty
expect(parser.errors[:field_130]).to be_empty
expect(parser.errors[:field_131]).to be_empty
end
end
context "and it is not carehome" do
let(:attributes) { { bulk_upload:, field_132: "123.45", field_127: nil, field_128: nil, field_129: nil, field_130: nil, field_131: nil } }
it "does not set charges values" do
parser.log.save!
expect(parser.log.tcharge).to be_nil
expect(parser.log.brent).to be_nil
expect(parser.log.supcharg).to be_nil
expect(parser.log.pscharge).to be_nil
expect(parser.log.scharge).to be_nil
end
it "adds an error to all missing charges" do
parser.valid?
expect(parser.errors[:field_128]).to eql(["Please enter the basic rent. If there is no basic rent, please enter '0'."])
expect(parser.errors[:field_129]).to eql(["Please enter the service charge. If there is no service charge, please enter '0'."])
expect(parser.errors[:field_130]).to eql(["Please enter the personal service charge. If there is no personal service charge, please enter '0'."])
expect(parser.errors[:field_131]).to eql(["Please enter the support charge. If there is no support charge, please enter '0'."])
end
end
end
end end
describe "#supcharg" do describe "#supcharg" do
@ -2315,6 +2372,50 @@ RSpec.describe BulkUpload::Lettings::Year2023::RowParser do
it "sets value given" do it "sets value given" do
expect(parser.log.supcharg).to eq(123.45) expect(parser.log.supcharg).to eq(123.45)
end end
context "when other charges are not given" do
context "and it is carehome" do
let(:attributes) { { bulk_upload:, field_132: nil, field_127: "123.45", field_128: nil, field_129: nil, field_130: nil, field_131: "123.45" } }
it "does not set charges values" do
parser.log.save!
expect(parser.log.tcharge).to be_nil
expect(parser.log.brent).to be_nil
expect(parser.log.supcharg).to be_nil
expect(parser.log.pscharge).to be_nil
expect(parser.log.scharge).to be_nil
end
it "does not add errors to missing charges" do
parser.valid?
expect(parser.errors[:field_128]).to be_empty
expect(parser.errors[:field_129]).to be_empty
expect(parser.errors[:field_130]).to be_empty
expect(parser.errors[:field_131]).to be_empty
end
end
context "and it is not carehome" do
let(:attributes) { { bulk_upload:, field_132: "123.45", field_127: nil, field_128: nil, field_129: nil, field_130: nil, field_131: nil } }
it "does not set charges values" do
parser.log.save!
expect(parser.log.tcharge).to be_nil
expect(parser.log.brent).to be_nil
expect(parser.log.supcharg).to be_nil
expect(parser.log.pscharge).to be_nil
expect(parser.log.scharge).to be_nil
end
it "adds an error to all missing charges" do
parser.valid?
expect(parser.errors[:field_128]).to eql(["Please enter the basic rent. If there is no basic rent, please enter '0'."])
expect(parser.errors[:field_129]).to eql(["Please enter the service charge. If there is no service charge, please enter '0'."])
expect(parser.errors[:field_130]).to eql(["Please enter the personal service charge. If there is no personal service charge, please enter '0'."])
expect(parser.errors[:field_131]).to eql(["Please enter the support charge. If there is no support charge, please enter '0'."])
end
end
end
end end
describe "#pscharge" do describe "#pscharge" do

59
spec/services/bulk_upload/lettings/year2024/row_parser_spec.rb

@ -2159,11 +2159,24 @@ RSpec.describe BulkUpload::Lettings::Year2024::RowParser do
end end
describe "#chcharge" do describe "#chcharge" do
let(:attributes) { { bulk_upload:, field_124: "123.45" } } let(:attributes) { { bulk_upload:, field_124: "123.45", field_125: "123.45", field_126: "123.45", field_127: "123.45", field_128: "123.45" } }
it "sets value given" do it "sets value given" do
expect(parser.log.chcharge).to eq(123.45) expect(parser.log.chcharge).to eq(123.45)
end end
it "sets is care home to yes" do
expect(parser.log.is_carehome).to eq(1)
end
it "clears any other given charges" do
parser.log.save!
expect(parser.log.tcharge).to be_nil
expect(parser.log.brent).to be_nil
expect(parser.log.supcharg).to be_nil
expect(parser.log.pscharge).to be_nil
expect(parser.log.scharge).to be_nil
end
end end
describe "#supcharg" do describe "#supcharg" do
@ -2172,6 +2185,50 @@ RSpec.describe BulkUpload::Lettings::Year2024::RowParser do
it "sets value given" do it "sets value given" do
expect(parser.log.supcharg).to eq(123.45) expect(parser.log.supcharg).to eq(123.45)
end end
context "when other charges are not given" do
context "and it is carehome" do
let(:attributes) { { bulk_upload:, field_128: "123.45", field_124: "123.45", field_125: nil, field_126: nil, field_127: nil } }
it "does not set charges values" do
parser.log.save!
expect(parser.log.tcharge).to be_nil
expect(parser.log.brent).to be_nil
expect(parser.log.supcharg).to be_nil
expect(parser.log.pscharge).to be_nil
expect(parser.log.scharge).to be_nil
end
it "does not add errors to missing charges" do
parser.valid?
expect(parser.errors[:field_125]).to be_empty
expect(parser.errors[:field_126]).to be_empty
expect(parser.errors[:field_127]).to be_empty
expect(parser.errors[:field_128]).to be_empty
end
end
context "and it is not carehome" do
let(:attributes) { { bulk_upload:, field_128: "123.45", field_124: nil, field_125: nil, field_126: nil, field_127: nil } }
it "does not set charges values" do
parser.log.save!
expect(parser.log.tcharge).to be_nil
expect(parser.log.brent).to be_nil
expect(parser.log.supcharg).to be_nil
expect(parser.log.pscharge).to be_nil
expect(parser.log.scharge).to be_nil
end
it "adds an error to all missing charges" do
parser.valid?
expect(parser.errors[:field_125]).to eql(["Please enter the basic rent. If there is no basic rent, please enter '0'."])
expect(parser.errors[:field_126]).to eql(["Please enter the service charge. If there is no service charge, please enter '0'."])
expect(parser.errors[:field_127]).to eql(["Please enter the personal service charge. If there is no personal service charge, please enter '0'."])
expect(parser.errors[:field_128]).to be_empty
end
end
end
end end
describe "#pscharge" do describe "#pscharge" do

Loading…
Cancel
Save