Browse Source

bulk upload error shows correct question

- depending on log type it will show relevant question for the field
  concerned
pull/1091/head
Phil Lee 3 years ago
parent
commit
20a99355f0
  1. 13
      app/components/bulk_upload_error_row_component.rb
  2. 4
      app/services/bulk_upload/sales_validator.rb
  3. 15
      spec/components/bulk_upload_error_row_component_spec.rb

13
app/components/bulk_upload_error_row_component.rb

@ -20,6 +20,17 @@ class BulkUploadErrorRowComponent < ViewComponent::Base
end end
def question_for_field(field) def question_for_field(field)
BulkUpload::LettingsValidator.question_for_field(field.to_sym) case bulk_upload.log_type
when "lettings"
BulkUpload::LettingsValidator.question_for_field(field.to_sym)
when "sales"
BulkUpload::SalesValidator.question_for_field(field.to_sym)
else
"Unknown question"
end
end
def bulk_upload
bulk_upload_errors.first.bulk_upload
end end
end end

4
app/services/bulk_upload/sales_validator.rb

@ -126,4 +126,8 @@ class BulkUpload::SalesValidator
field_124: "Was a mortgage used for the purchase of this property? - Discounted ownership", field_124: "Was a mortgage used for the purchase of this property? - Discounted ownership",
field_125: "Was a mortgage used for the purchase of this property? - Outright sale", field_125: "Was a mortgage used for the purchase of this property? - Outright sale",
}.freeze }.freeze
def self.question_for_field(field)
QUESTIONS[field]
end
end end

15
spec/components/bulk_upload_error_row_component_spec.rb

@ -7,10 +7,12 @@ RSpec.describe BulkUploadErrorRowComponent, type: :component do
let(:property_ref) { SecureRandom.hex(4) } let(:property_ref) { SecureRandom.hex(4) }
let(:field) { :field_134 } let(:field) { :field_134 }
let(:error) { "some error" } let(:error) { "some error" }
let(:bulk_upload) { create(:bulk_upload, :lettings) }
let(:bulk_upload_errors) do let(:bulk_upload_errors) do
[ [
FactoryBot.build( FactoryBot.build(
:bulk_upload_error, :bulk_upload_error,
bulk_upload:,
row:, row:,
tenant_code:, tenant_code:,
property_ref:, property_ref:,
@ -41,12 +43,23 @@ RSpec.describe BulkUploadErrorRowComponent, type: :component do
expect(result).to have_content(expected) expect(result).to have_content(expected)
end end
it "renders the question" do it "renders the question for lettings" do
expected = "Is this letting a renewal?" expected = "Is this letting a renewal?"
result = render_inline(described_class.new(bulk_upload_errors:)) result = render_inline(described_class.new(bulk_upload_errors:))
expect(result).to have_content(expected) expect(result).to have_content(expected)
end end
context "when a sales bulk upload" do
let(:bulk_upload) { create(:bulk_upload, :sales) }
let(:field) { :field_87 }
it "renders the question for sales" do
expected = "What is the full purchase price?"
result = render_inline(described_class.new(bulk_upload_errors:))
expect(result).to have_content(expected)
end
end
it "renders the error" do it "renders the error" do
expected = error expected = error
result = render_inline(described_class.new(bulk_upload_errors:)) result = render_inline(described_class.new(bulk_upload_errors:))

Loading…
Cancel
Save