Browse Source

CLDC-2348 Purchaser code bug fix (#1638)

* feat: assign purchaser_code for each year

* refactor: lint

* feat: add test that checks purchaser code assignment without explicitly calling a field
pull/1644/head
natdeanlewissoftwire 2 years ago committed by GitHub
parent
commit
da00fa73f6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      app/services/bulk_upload/sales/validator.rb
  2. 6
      app/services/bulk_upload/sales/year2022/row_parser.rb
  3. 6
      app/services/bulk_upload/sales/year2023/row_parser.rb
  4. 19
      spec/services/bulk_upload/sales/year2022/row_parser_spec.rb
  5. 19
      spec/services/bulk_upload/sales/year2023/row_parser_spec.rb

2
app/services/bulk_upload/sales/validator.rb

@ -23,7 +23,7 @@ class BulkUpload::Sales::Validator
bulk_upload.bulk_upload_errors.create!(
field: error.attribute,
error: error.message,
purchaser_code: row_parser.field_1,
purchaser_code: row_parser.purchaser_code,
row:,
cell: "#{col}#{row}",
col:,

6
app/services/bulk_upload/sales/year2022/row_parser.rb

@ -344,6 +344,10 @@ class BulkUpload::Sales::Year2022::RowParser
.exists?(duplicate_check_fields.index_with { |field| log.public_send(field) })
end
def purchaser_code
field_1
end
private
def buyer_not_interviewed?
@ -487,7 +491,7 @@ private
def attributes_for_log
attributes = {}
attributes["purchid"] = field_1
attributes["purchid"] = purchaser_code
attributes["saledate"] = saledate
attributes["noint"] = field_6

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

@ -473,6 +473,10 @@ class BulkUpload::Sales::Year2023::RowParser
.exists?(duplicate_check_fields.index_with { |field| log.public_send(field) })
end
def purchaser_code
field_6
end
private
def prevtenbuy2
@ -695,7 +699,7 @@ private
def attributes_for_log
attributes = {}
attributes["purchid"] = field_6
attributes["purchid"] = purchaser_code
attributes["saledate"] = saledate
attributes["noint"] = 2 if field_28 == 1

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

@ -133,6 +133,25 @@ RSpec.describe BulkUpload::Sales::Year2022::RowParser do
end
end
describe "purchaser_code" do
before do
def purch_id_field
described_class::QUESTIONS.key("What is the purchaser code?").to_s
end
end
let(:attributes) do
{
bulk_upload:,
purch_id_field => "some purchaser code",
}
end
it "is linked to the correct field" do
expect(parser.purchaser_code).to eq("some purchaser code")
end
end
describe "validations" do
before do
stub_request(:get, /api.postcodes.io/)

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

@ -136,6 +136,25 @@ RSpec.describe BulkUpload::Sales::Year2023::RowParser do
end
end
describe "purchaser_code" do
before do
def purch_id_field
described_class::QUESTIONS.key("What is the purchaser code?").to_s
end
end
let(:attributes) do
{
bulk_upload:,
purch_id_field => "some purchaser code",
}
end
it "is linked to the correct field" do
expect(parser.purchaser_code).to eq("some purchaser code")
end
end
describe "validations" do
before do
stub_request(:get, /api.postcodes.io/)

Loading…
Cancel
Save