Browse Source

feat: update tests and radio options

pull/1815/head
natdeanlewissoftwire 3 years ago
parent
commit
c001148ffe
  1. 27
      app/models/form/question.rb
  2. 1
      app/models/form/sales/questions/postcode_known.rb
  3. 2
      spec/fixtures/files/completed_2022_23_sales_bulk_upload.csv
  4. 30
      spec/models/form/question_spec.rb
  5. 2
      spec/requests/sales_logs_controller_spec.rb
  6. 2
      spec/services/bulk_upload/sales/validator_spec.rb
  7. 4
      spec/services/bulk_upload/sales/year2022/row_parser_spec.rb
  8. 4
      spec/services/bulk_upload/sales/year2023/row_parser_spec.rb

27
app/models/form/question.rb

@ -116,20 +116,20 @@ class Form::Question
if is_derived_or_has_inferred_check_answers_value?(log)
"Change"
elsif type == "checkbox"
answer_options.keys.any? { |key| value_is_yes?(log[key]) } ? "Change" : "Answer"
answer_options.keys.any? { |key| value_is_yes?(log[key], log.lettings?) } ? "Change" : "Answer"
else
log[id].blank? ? "Answer" : "Change"
end
end
def unanswered?(log)
return answer_options.keys.none? { |key| value_is_yes?(log[key]) } if type == "checkbox"
return answer_options.keys.none? { |key| value_is_yes?(log[key], log.lettings?) } if type == "checkbox"
log[id].blank?
end
def completed?(log)
return answer_options.keys.any? { |key| value_is_yes?(log[key]) } if type == "checkbox"
return answer_options.keys.any? { |key| value_is_yes?(log[key], log.lettings?) } if type == "checkbox"
log[id].present? || !log.respond_to?(id.to_sym) || has_inferred_display_value?(log)
end
@ -166,23 +166,23 @@ class Form::Question
label || value.to_s
end
def value_is_yes?(value)
def value_is_yes?(value, is_lettings)
case type
when "checkbox"
value == 1
when "radio"
RADIO_YES_VALUE[id.to_sym]&.include?(value)
is_lettings ? RADIO_YES_VALUE_LETTINGS[id.to_sym]&.include?(value) : RADIO_YES_VALUE_SALES[id.to_sym]&.include?(value)
else
%w[yes].include?(value.downcase)
end
end
def value_is_no?(value)
def value_is_no?(value, is_lettings)
case type
when "checkbox"
value && value.zero?
when "radio"
RADIO_NO_VALUE[id.to_sym]&.include?(value)
is_lettings ? RADIO_NO_VALUE_LETTINGS[id.to_sym]&.include?(value) : RADIO_NO_VALUE_SALES[id.to_sym]&.include?(value)
else
%w[no].include?(value.downcase)
end
@ -272,9 +272,9 @@ private
def checkbox_answer_label(log)
answer = []
return "Yes" if id == "declaration" && value_is_yes?(log["declaration"])
return "Yes" if id == "declaration" && value_is_yes?(log["declaration"], log.lettings?)
answer_options.each { |key, options| value_is_yes?(log[key]) ? answer << options["value"] : nil }
answer_options.each { |key, options| value_is_yes?(log[key], log.lettings?) ? answer << options["value"] : nil }
answer.join(", ")
end
@ -319,7 +319,7 @@ private
RADIO_YES_VALUE = {
renewal: [1],
postcode_known: [1],
ppcodenk: [1],
pcodenk: [0],
previous_la_known: [1],
first_time_property_let_as_social_housing: [1],
wchair: [1],
@ -343,7 +343,7 @@ private
RADIO_NO_VALUE = {
renewal: [0],
postcode_known: [0],
ppcodenk: [0],
pcodenk: [1],
previous_la_known: [0],
first_time_property_let_as_social_housing: [0],
wchair: [0],
@ -364,6 +364,11 @@ private
net_income_value_check: [1],
}.freeze
RADIO_YES_VALUE_LETTINGS = RADIO_YES_VALUE.merge({ ppcodenk: [1] })
RADIO_YES_VALUE_SALES = RADIO_YES_VALUE.merge({ ppcodenk: [0] })
RADIO_NO_VALUE_LETTINGS = RADIO_NO_VALUE.merge({ ppcodenk: [0] })
RADIO_NO_VALUE_SALES = RADIO_NO_VALUE.merge({ ppcodenk: [1] })
RADIO_DONT_KNOW_VALUE = {
sheltered: [3],
underoccupation_benefitcap: [3],

1
app/models/form/sales/questions/postcode_known.rb

@ -19,6 +19,7 @@ class Form::Sales::Questions::PostcodeKnown < ::Form::Question
},
],
}
@disable_clearing_if_not_routed_or_dynamic_answer_options = true
end
ANSWER_OPTIONS = {

2
spec/fixtures/files/completed_2022_23_sales_bulk_upload.csv vendored

@ -116,4 +116,4 @@ OR
If field 39 = 3 - 9",If field 113 = 2 or 3,If field 113 = 1 or 3,If field 113 = 1 or 2
Bulk upload format and duplicate check,Yes,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
Field number,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,123,124,125
,22 test BU,22,2,23,,1,32,32,,,,,M,F,,,,,R,,,,,1,2,,,,,12,18,30000,15000,1,1,20000,3,,1,E09000008,A1,1AA,1,,1,1,,3,3,2,1,1,E09000008,CR0,4BB,3,2,2,23,3,22,30,3,22,3,1,1,250000,25,42500,3,20000,,800,200,,,,,,,,,,,,,,,,,3,,,3,,5,1,,,,,,4,20,,,,2,5,1,1,1,,1,1,1,1,0,10,10,1,1,,
,22 test BU,22,2,23,,1,32,32,,,,,M,F,,,,,R,,,,,1,2,,,,,12,18,30000,15000,1,1,20000,3,,1,E09000008,A1,1AA,1,,1,1,,3,3,2,1,1,E09000008,CR0,4BB,3,2,2,23,3,22,30,3,22,3,1,1,250000,25,42500,3,20000,,800,200,,,,,,,,,,,,,,,,,123,,,3,,5,1,,,,,,4,20,,,,2,5,1,1,1,,1,1,1,1,0,10,10,1,1,,

1 Question What is the purchaser code? What is the day of the sale completion date? - DD What is the month of the sale completion date? - MM What is the year of the sale completion date? - YY [BLANK] Was the buyer interviewed for any of the answers you will provide on this log? Age of Buyer 1 Age of Buyer 2 or Person 2 Age of Person 3 Age of Person 4 Age of Person 5 Age of Person 6 Gender identity of Buyer 1 Gender identity of Buyer 2 or Person 2 Gender identity of Person 3 Gender identity of Person 4 Gender identity of Person 5 Gender identity of Person 6 Person 2's relationship to lead tenant Person 3's relationship to lead tenant Person 4's relationship to lead tenant Person 5's relationship to lead tenant Person 6's relationship to lead tenant Working situation of Buyer 1 Working situation of Buyer 2 or Person 2 Working situation of Person 3 Working situation of Person 4 Working situation of Person 5 Working situation of Person 6 What is the buyer 1's ethnic group? What is buyer 1's nationality? What is buyer 1's gross annual income? What is buyer 2's gross annual income? Was buyer 1's income used for a mortgage application? Was buyer 2's income used for a mortgage application? What is the total amount the buyers had in savings before they paid any deposit for the property? To the nearest £10 Have any of the buyers previously owned a property? [BLANK] What was buyer 1's previous tenure? What is the local authority of buyer 1's last settled home Part 1 of postcode of buyer 1's last settled home Part 2 of postcode of buyer 1's last settled home Do you know the postcode of buyer 1's last settled home? Was the buyer registered with their PRP (HA)? Was the buyer registered with the local authority? Was the buyer registered with a Help to Buy agent? Was the buyer registered with another PRP (HA)? Does anyone in the household consider themselves to have a disability? Does anyone in the household use a wheelchair? How many bedrooms does the property have? What type of unit is the property? Which type of building is the property? What is the local authority of the property? Part 1 of postcode of property Part 2 of postcode of property Is the property built or adapted to wheelchair-user standards? What is the type of shared ownership sale? Is this a resale? Shared ownership What is the day of the practical completion or handover date? - DD Shared ownership What is the month of the practical completion or handover date? - MM Shared ownership What is the year of the practical completion or handover date? - YY Shared ownership What is the day of the exchange of contracts date? - DD Shared ownership What is the month of the exchange of contracts date? - MM Shared ownership What is the year of the exchange of contracts date? - YY Shared ownership Was the household re-housed under a local authority nominations agreement? Shared ownership How many bedrooms did the buyer's previous property have? Shared ownership What was the type of the buyer's previous property? Shared ownership What was the full purchase price? Shared ownership What was the initial percentage equity stake purchased? Shared ownership What is the mortgage amount? Shared ownership Does this include any extra borrowing? Shared ownership How much was the cash deposit paid on the property? Shared ownership How much cash discount was given through Social Homebuy? Shared ownership What is the basic monthly rent? Shared ownership What are the total monthly leasehold charges for the property? Shared ownership What is the type of discounted ownership sale? What was the full purchase price? Discounted ownership What was the amount of any loan, grant, discount or subsidy given? Discounted ownership What was the percentage discount? Discounted ownership What is the mortgage amount? Discounted ownership Does this include any extra borrowing? Discounted ownership How much was the cash deposit paid on the property? Discounted ownership What are the total monthly leasehold charges for the property? Discounted ownership What is the type of outright sale? What is the 'other' type of outright sale? Outright sale [BLANK] What is the full purchase price? Outright sale What is the mortgage amount? Outright sale Does this include any extra borrowing? Outright sale How much was the cash deposit paid on the property? Outright sale What are the total monthly leasehold charges for the property? Outright sale Which organisation owned this property before the sale? Organisation's CORE ID Username BLANK Has the buyer ever served in the UK Armed Forces and for how long? [BLANK] Are any of the buyers a spouse or civil partner of a UK Armed Forces regular who died in service within the last 2 years? What is the name of the mortgage lender? Shared ownership What is the name of the 'other' mortgage lender? Shared ownership What is the name of the mortgage lender? Discounted ownership What is the name of the 'other' mortgage lender? Discounted ownership What is the name of the mortgage lender? Outright sale What is the name of the 'other' mortgage lender? Outright sale Were the buyers receiving any of these housing-related benefits immediately before buying this property? What is the length of the mortgage in years? Shared ownership What is the length of the mortgage in years? Discounted ownership What is the length of the mortgage in years? Outright sale How long have the buyers been living in the property before the purchase? Discounted ownership Are there more than two joint purchasers of this property? How long have the buyers been living in the property before the purchase? Shared ownership Is this a staircasing transaction? Data Protection question Was this purchase made through an ownership scheme? Is the buyer a company? Outright sale Will the buyers live in the property? Is this a joint purchase? Will buyer 1 live in the property? Will buyer 2 live in the property? Besides the buyers, how many people live in the property? What percentage of the property has been bought in this staircasing transaction? Shared ownership What percentage of the property does the buyer now own in total? Shared ownership What was the rent type of the buyer's previous property? Shared ownership Was a mortgage used for the purchase of this property? Shared ownership Was a mortgage used for the purchase of this property? Discounted ownership Was a mortgage used for the purchase of this property? Outright sale
116
117
118
119

30
spec/models/form/question_spec.rb

@ -60,15 +60,15 @@ RSpec.describe Form::Question, type: :model do
end
it "has a yes value helper" do
expect(question).to be_value_is_yes("Yes")
expect(question).to be_value_is_yes("YES")
expect(question).not_to be_value_is_yes("random")
expect(question).to be_value_is_yes("Yes", true)
expect(question).to be_value_is_yes("YES", true)
expect(question).not_to be_value_is_yes("random", true)
end
it "has a no value helper" do
expect(question).to be_value_is_no("No")
expect(question).to be_value_is_no("NO")
expect(question).not_to be_value_is_no("random")
expect(question).to be_value_is_no("No", true)
expect(question).to be_value_is_no("NO", true)
expect(question).not_to be_value_is_no("random", true)
end
context "when type is numeric" do
@ -108,10 +108,10 @@ RSpec.describe Form::Question, type: :model do
let(:question_id) { "illness" }
it "maps those options" do
expect(question).to be_value_is_yes(1)
expect(question).not_to be_value_is_no(1)
expect(question).to be_value_is_yes(1, true)
expect(question).not_to be_value_is_no(1, true)
expect(question).not_to be_value_is_refused(1)
expect(question).to be_value_is_no(2)
expect(question).to be_value_is_no(2, true)
expect(question).to be_value_is_dont_know(3)
end
end
@ -123,8 +123,8 @@ RSpec.describe Form::Question, type: :model do
let(:question_id) { "layear" }
it "maps those options" do
expect(question).not_to be_value_is_yes(7)
expect(question).not_to be_value_is_no(7)
expect(question).not_to be_value_is_yes(7, true)
expect(question).not_to be_value_is_no(7, true)
expect(question).not_to be_value_is_refused(7)
expect(question).to be_value_is_dont_know(7)
end
@ -209,13 +209,13 @@ RSpec.describe Form::Question, type: :model do
end
it "can map yes values" do
expect(question).to be_value_is_yes(1)
expect(question).not_to be_value_is_yes(0)
expect(question).to be_value_is_yes(1, true)
expect(question).not_to be_value_is_yes(0, true)
end
it "can map no values" do
expect(question).to be_value_is_no(0)
expect(question).not_to be_value_is_no(1)
expect(question).to be_value_is_no(0, true)
expect(question).not_to be_value_is_no(1, true)
end
end

2
spec/requests/sales_logs_controller_spec.rb

@ -65,6 +65,8 @@ RSpec.describe SalesLogsController, type: :request do
context "with a request containing invalid json parameters" do
let(:params) do
{
"owning_organisation_id": owning_organisation.id,
"created_by_id": user.id,
"saledate": Time.zone.today,
"purchid": "1",
"ownershipsch": 1,

2
spec/services/bulk_upload/sales/validator_spec.rb

@ -104,7 +104,7 @@ RSpec.describe BulkUpload::Sales::Validator do
error = BulkUploadError.find_by(row: "6", field: "field_92", category: "setup")
expect(error.field).to eql("field_92")
expect(error.error).to eql("The owning organisation code is incorrect")
expect(error.error).to eql("You must answer owning organisation")
expect(error.purchaser_code).to eql("22 test BU")
expect(error.row).to eql("6")
expect(error.cell).to eql("CO6")

4
spec/services/bulk_upload/sales/year2022/row_parser_spec.rb

@ -407,7 +407,7 @@ RSpec.describe BulkUpload::Sales::Year2022::RowParser do
it "is not permitted as setup error" do
setup_errors = parser.errors.select { |e| e.options[:category] == :setup }
expect(setup_errors.find { |e| e.attribute == :field_92 }.message).to eql("The owning organisation code is incorrect")
expect(setup_errors.find { |e| e.attribute == :field_92 }.message).to eql("You must answer owning organisation")
end
it "blocks log creation" do
@ -421,7 +421,7 @@ RSpec.describe BulkUpload::Sales::Year2022::RowParser do
it "is not permitted as a setup error" do
setup_errors = parser.errors.select { |e| e.options[:category] == :setup }
expect(setup_errors.find { |e| e.attribute == :field_92 }.message).to eql("The owning organisation code is incorrect")
expect(setup_errors.find { |e| e.attribute == :field_92 }.message).to eql("You must answer owning organisation")
end
it "blocks log creation" do

4
spec/services/bulk_upload/sales/year2023/row_parser_spec.rb

@ -384,7 +384,7 @@ RSpec.describe BulkUpload::Sales::Year2023::RowParser do
let(:attributes) { setup_section_params.merge(field_1: nil) }
it "is not permitted as setup error" do
expect(parser.errors.where(:field_1, category: :setup).map(&:message)).to eql(["The owning organisation code is incorrect"])
expect(parser.errors.where(:field_1, category: :setup).map(&:message)).to eql(["You must answer owning organisation"])
end
it "blocks log creation" do
@ -396,7 +396,7 @@ RSpec.describe BulkUpload::Sales::Year2023::RowParser do
let(:attributes) { { bulk_upload:, field_1: "donotexist" } }
it "is not permitted as a setup error" do
expect(parser.errors.where(:field_1, category: :setup).map(&:message)).to eql(["The owning organisation code is incorrect"])
expect(parser.errors.where(:field_1, category: :setup).map(&:message)).to eql(["You must answer owning organisation"])
end
it "blocks log creation" do

Loading…
Cancel
Save