From becf74c8802e75961921fe82be0e38f1344fb167 Mon Sep 17 00:00:00 2001 From: Kat Date: Mon, 20 Mar 2023 10:18:21 +0000 Subject: [PATCH] Update import service --- .../imports/sales_logs_import_service.rb | 4 ++- .../imports/sales_logs_import_service_spec.rb | 29 ++++++++++++++----- 2 files changed, 24 insertions(+), 9 deletions(-) diff --git a/app/services/imports/sales_logs_import_service.rb b/app/services/imports/sales_logs_import_service.rb index 577e37e5f..46466126e 100644 --- a/app/services/imports/sales_logs_import_service.rb +++ b/app/services/imports/sales_logs_import_service.rb @@ -152,6 +152,7 @@ module Imports attributes["old_persons_shared_ownership_value_check"] = 0 attributes["income2_value_check"] = 0 attributes["monthly_charges_value_check"] = 0 + attributes["student_not_child_value_check"] = 0 # Sets the log creator owner_id = meta_field_value(xml_doc, "owner-user-id").strip @@ -242,7 +243,8 @@ module Imports staircase_bought_value_check monthly_charges_value_check hodate_check - saledate_check] + saledate_check + student_not_child_value_check] end def check_status_completed(sales_log, previous_status) diff --git a/spec/services/imports/sales_logs_import_service_spec.rb b/spec/services/imports/sales_logs_import_service_spec.rb index 2481cdce7..eaef329b9 100644 --- a/spec/services/imports/sales_logs_import_service_spec.rb +++ b/spec/services/imports/sales_logs_import_service_spec.rb @@ -363,20 +363,34 @@ RSpec.describe Imports::SalesLogsImportService do end end - context "and it has an invalid record with invalid child, student and 16-19 age combination" do + context "and the student not child soft validation is triggered (student_not_child_value_check)" do + let(:sales_log_id) { "shared_ownership_sales_log" } + + before do + sales_log_xml.at_xpath("//xmlns:P2Rel").content = "P" + sales_log_xml.at_xpath("//xmlns:P2Eco").content = "7" + sales_log_xml.at_xpath("//xmlns:P2Age").content = "16" + end + + it "completes the log" do + sales_log_service.send(:create_log, sales_log_xml) + sales_log = SalesLog.find_by(old_id: sales_log_id) + expect(sales_log.status).to eq("completed") + end + end + + context "and it has an invalid record with invalid child age" do let(:sales_log_id) { "discounted_ownership_sales_log" } before do sales_log_xml.at_xpath("//meta:status").content = "submitted-invalid" - sales_log_xml.at_xpath("//xmlns:P2Age").content = 16 - sales_log_xml.at_xpath("//xmlns:P2Eco").content = 7 - sales_log_xml.at_xpath("//xmlns:P2Rel").content = "X" + sales_log_xml.at_xpath("//xmlns:P2Age").content = 17 + sales_log_xml.at_xpath("//xmlns:P2Eco").content = 9 end it "intercepts the relevant validation error" do - expect(logger).to receive(:warn).with(/Removing field age2 from log triggering validation: Person cannot be aged 16-19 if they are a student but don't have relationship ‘child’/) - expect(logger).to receive(:warn).with(/Removing field relat2 from log triggering validation: Answer must be ‘child’ if the person is aged 16-19 and a student/) - expect(logger).to receive(:warn).with(/Removing field ecstat2 from log triggering validation: Person cannot be a student if they are aged 16-19 but don‘t have relationship ‘child’/) + expect(logger).to receive(:warn).with(/Log discounted_ownership_sales_log: Removing field ecstat2 from log triggering validation: Answer cannot be ‘child under 16’ as you told us the person 2 is older than 16/) + expect(logger).to receive(:warn).with(/Log discounted_ownership_sales_log: Removing field age2 from log triggering validation: Answer cannot be over 16 as person’s 2 working situation is ‘child under 16‘/) expect { sales_log_service.send(:create_log, sales_log_xml) } .not_to raise_error end @@ -389,7 +403,6 @@ RSpec.describe Imports::SalesLogsImportService do expect(sales_log).not_to be_nil expect(sales_log.age2).to be_nil - expect(sales_log.relat2).to be_nil expect(sales_log.ecstat2).to be_nil end end