Browse Source

CLDC-3245: Fix issue with bulk uploads

pull/2271/head
Robert Sullivan 2 years ago
parent
commit
09c7e6c0fd
  1. 1
      app/controllers/form_controller.rb
  2. 8
      app/models/form/question.rb
  3. 2
      app/models/form/sales/questions/buyers_organisations.rb
  4. 7
      app/services/bulk_upload/sales/year2023/row_parser.rb
  5. 7
      app/services/bulk_upload/sales/year2024/row_parser.rb
  6. 10
      spec/models/form/sales/questions/buyers_organisations_spec.rb
  7. 17
      spec/services/bulk_upload/sales/year2023/row_parser_spec.rb
  8. 19
      spec/services/bulk_upload/sales/year2024/row_parser_spec.rb

1
app/controllers/form_controller.rb

@ -92,7 +92,6 @@ private
Date.new(0, 1, 1) Date.new(0, 1, 1)
end end
end end
next unless question_params next unless question_params
if %w[checkbox validation_override].include?(question.type) if %w[checkbox validation_override].include?(question.type)

8
app/models/form/question.rb

@ -1,10 +1,12 @@
class Form::Question class Form::Question
attr_accessor :id, :header, :hint_text, :description, :questions, :disable_clearing_if_not_routed_or_dynamic_answer_options, attr_accessor :id, :header, :hint_text, :description, :questions, :disable_clearing_if_not_routed_or_dynamic_answer_options,
:type, :min, :max, :step, :width, :fields_to_add, :result_field, :default_answer, :type, :min, :max, :step, :width, :fields_to_add, :result_field,
:conditional_for, :readonly, :answer_options, :page, :check_answer_label, :conditional_for, :readonly, :answer_options, :page, :check_answer_label,
:inferred_answers, :hidden_in_check_answers, :inferred_check_answers_value, :inferred_answers, :hidden_in_check_answers, :inferred_check_answers_value,
:top_guidance_partial, :bottom_guidance_partial, :prefix, :suffix, :requires_js, :fields_added, :derived, :top_guidance_partial, :bottom_guidance_partial, :prefix, :suffix,
:check_answers_card_number, :unresolved_hint_text, :question_number, :hide_question_number_on_page, :plain_label, :error_label :requires_js, :fields_added, :derived, :check_answers_card_number,
:unresolved_hint_text, :question_number, :hide_question_number_on_page,
:plain_label, :error_label, :default_answer
def initialize(id, hsh, page) def initialize(id, hsh, page)
@id = id @id = id

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

@ -16,7 +16,7 @@ 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 selected" }, "pregblank" => { "value" => "None of the above" },
}.freeze }.freeze
def displayed_answer_options(_log, _user = nil) def displayed_answer_options(_log, _user = nil)

7
app/services/bulk_upload/sales/year2023/row_parser.rb

@ -854,8 +854,7 @@ private
attributes["pregla"] = field_69 attributes["pregla"] = field_69
attributes["pregghb"] = field_70 attributes["pregghb"] = field_70
attributes["pregother"] = field_68 attributes["pregother"] = field_68
organisations_fields = %i[field_67 field_68 field_69 field_70] attributes["pregblank"] = no_buyer_organisation
attributes["pregblank"] = organisations_fields.all? { |field| attributes[field.to_s].blank? }
attributes["disabled"] = field_76 attributes["disabled"] = field_76
attributes["wheel"] = field_77 attributes["wheel"] = field_77
@ -1122,6 +1121,10 @@ private
0 if field_63 == 1 0 if field_63 == 1
end end
def no_buyer_organisation
[field_67, field_68, field_69, field_70].all?(&:blank?) ? 1 : nil?
end
def block_log_creation! def block_log_creation!
self.block_log_creation = true self.block_log_creation = true
end end

7
app/services/bulk_upload/sales/year2024/row_parser.rb

@ -849,8 +849,7 @@ private
attributes["pregla"] = field_68 attributes["pregla"] = field_68
attributes["pregghb"] = field_69 attributes["pregghb"] = field_69
attributes["pregother"] = field_67 attributes["pregother"] = field_67
organisations_fields = %i[field_67 field_68 field_69 field_70] attributes["pregblank"] = no_buyer_organisation
attributes["pregblank"] = organisations_fields.all? { |field| attributes[field.to_s].blank? }
attributes["disabled"] = field_75 attributes["disabled"] = field_75
attributes["wheel"] = field_76 attributes["wheel"] = field_76
@ -1125,6 +1124,10 @@ private
end end
end end
def no_buyer_organisation
[field_66, field_67, field_68, field_69].all?(&:blank?) ? 1 : nil?
end
def block_log_creation! def block_log_creation!
self.block_log_creation = true self.block_log_creation = true
end end

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

@ -35,7 +35,7 @@ RSpec.describe Form::Sales::Questions::BuyersOrganisations, type: :model do
expect(question.hint_text).to eq("Select all that apply. This question is optional. If no options are applicable, leave the options blank, and select save and continue.") expect(question.hint_text).to eq("Select all that apply. This question is optional. If no options are applicable, leave the options blank, and select save and continue.")
end end
it "has the correct default answer" do it "has the correct default" do
expect(question.default_answer).to eq("pregblank") expect(question.default_answer).to eq("pregblank")
end end
@ -46,18 +46,18 @@ RSpec.describe Form::Sales::Questions::BuyersOrganisations, type: :model do
"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 selected" }, "pregblank" => { "value" => "None of the above" },
}, },
) )
end end
it "has the correct displayed_answer_options" do it "has the correct displayed answer_options" do
expect(question.displayed_answer_options(FactoryBot.create(:sales_log))).to eq( expect(question.answer_options).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" },
"pregla" => { "value" => "Local Authority" }, "pregla" => { "value" => "Local Authority" },
"pregghb" => { "value" => "Help to Buy Agent" }, "pregghb" => { "value" => "Help to Buy Agent" }
}, },
) )
end end

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

@ -959,13 +959,26 @@ RSpec.describe BulkUpload::Sales::Year2023::RowParser do
end end
describe "#field_67 - 70" do # buyers organisations describe "#field_67 - 70" do # buyers organisations
context "when all nil" do let(:empty_organisation_params) { setup_section_params.merge(field_67: nil, field_68: nil, field_69: nil, field_70: nil) }
let(:attributes) { setup_section_params.merge(field_67: nil, field_68: nil, field_69: nil, field_70: nil) }
context "when all empty" do
let(:attributes) { empty_organisation_params }
it "sets pregblank field" do it "sets pregblank field" do
expect(parser.log.pregblank).to be(1) expect(parser.log.pregblank).to be(1)
end end
end end
%i[field_67 field_68 field_69 field_70].each do |field_number|
context "when #{field_number} present" do
let(:attributes) { empty_organisation_params.merge({ field_number => 1 }) }
it "does not set pregblank field" do
attributes[:field_number] = 1
expect(parser.log.pregblank).to be(0)
end
end
end
end end
describe "soft validations" do describe "soft validations" do

19
spec/services/bulk_upload/sales/year2024/row_parser_spec.rb

@ -965,14 +965,27 @@ RSpec.describe BulkUpload::Sales::Year2024::RowParser do
end end
end end
describe "#field_66 - 70" do # buyers organisations describe "#field_66 - 69" do # buyers organisations
context "when all nil" do let(:empty_organisation_params) { setup_section_params.merge(field_66: nil, field_67: nil, field_68: nil, field_69: nil) }
let(:attributes) { setup_section_params.merge(field_66: nil, field_67: nil, field_68: nil, field_69: nil) }
context "when all empty" do
let(:attributes) { empty_organisation_params }
it "sets pregblank field" do it "sets pregblank field" do
expect(parser.log.pregblank).to be(1) expect(parser.log.pregblank).to be(1)
end end
end end
%i[field_66 field_67 field_68 field_69].each do |field_number|
context "when #{field_number} present" do
let(:attributes) { empty_organisation_params.merge({ field_number => 1 }) }
it "does not set pregblank field" do
attributes[:field_number] = 1
expect(parser.log.pregblank).to be(0)
end
end
end
end end
describe "#field_103" do # shared ownership mortgageused describe "#field_103" do # shared ownership mortgageused

Loading…
Cancel
Save