From da00fa73f65e8f9202b4784efc050d55b4d99b09 Mon Sep 17 00:00:00 2001 From: natdeanlewissoftwire <94526761+natdeanlewissoftwire@users.noreply.github.com> Date: Wed, 17 May 2023 17:20:38 +0100 Subject: [PATCH] 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 --- app/services/bulk_upload/sales/validator.rb | 2 +- .../bulk_upload/sales/year2022/row_parser.rb | 6 +++++- .../bulk_upload/sales/year2023/row_parser.rb | 6 +++++- .../sales/year2022/row_parser_spec.rb | 19 +++++++++++++++++++ .../sales/year2023/row_parser_spec.rb | 19 +++++++++++++++++++ 5 files changed, 49 insertions(+), 3 deletions(-) diff --git a/app/services/bulk_upload/sales/validator.rb b/app/services/bulk_upload/sales/validator.rb index 2aa3bfd61..e6ea92bf1 100644 --- a/app/services/bulk_upload/sales/validator.rb +++ b/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:, diff --git a/app/services/bulk_upload/sales/year2022/row_parser.rb b/app/services/bulk_upload/sales/year2022/row_parser.rb index 4fba0d53a..02427fe10 100644 --- a/app/services/bulk_upload/sales/year2022/row_parser.rb +++ b/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 diff --git a/app/services/bulk_upload/sales/year2023/row_parser.rb b/app/services/bulk_upload/sales/year2023/row_parser.rb index cb65fa94c..994542bc4 100644 --- a/app/services/bulk_upload/sales/year2023/row_parser.rb +++ b/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 diff --git a/spec/services/bulk_upload/sales/year2022/row_parser_spec.rb b/spec/services/bulk_upload/sales/year2022/row_parser_spec.rb index 8ff75852e..e83419ad6 100644 --- a/spec/services/bulk_upload/sales/year2022/row_parser_spec.rb +++ b/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/) diff --git a/spec/services/bulk_upload/sales/year2023/row_parser_spec.rb b/spec/services/bulk_upload/sales/year2023/row_parser_spec.rb index d49d78f4d..84e0e0cc5 100644 --- a/spec/services/bulk_upload/sales/year2023/row_parser_spec.rb +++ b/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/)