Browse Source

Refactor tests: change log id names

pull/1331/head
Kat 3 years ago
parent
commit
4a4771badd
  1. 61
      spec/services/imports/sales_logs_import_service_spec.rb

61
spec/services/imports/sales_logs_import_service_spec.rb

@ -10,6 +10,11 @@ RSpec.describe Imports::SalesLogsImportService do
let(:organisation) { FactoryBot.create(:organisation, old_visible_id: "1", provider_type: "PRP") } let(:organisation) { FactoryBot.create(:organisation, old_visible_id: "1", provider_type: "PRP") }
let(:managing_organisation) { FactoryBot.create(:organisation, old_visible_id: "2", provider_type: "PRP") } let(:managing_organisation) { FactoryBot.create(:organisation, old_visible_id: "2", provider_type: "PRP") }
let(:remote_folder) { "sales_logs" }
let(:shared_ownership_sales_log_id) { "0ead17cb-1668-442d-898c-0d52879ff592" }
let(:shared_ownership_sales_log_id2) { "166fc004-392e-47a8-acb8-1c018734882b" }
let(:outright_sale_sales_log_id) { "00d2343e-d5fa-4c89-8400-ec3854b0f2b4" }
let(:discounted_ownership_sales_log_id) { "0b4a68df-30cc-474a-93c0-a56ce8fdad3b" }
def open_file(directory, filename) def open_file(directory, filename)
File.open("#{directory}/#{filename}.xml") File.open("#{directory}/#{filename}.xml")
@ -29,28 +34,22 @@ RSpec.describe Imports::SalesLogsImportService do
end end
context "when importing sales logs" do context "when importing sales logs" do
let(:remote_folder) { "sales_logs" }
let(:sales_log_id) { "0ead17cb-1668-442d-898c-0d52879ff592" }
let(:sales_log_id2) { "166fc004-392e-47a8-acb8-1c018734882b" }
let(:sales_log_id3) { "00d2343e-d5fa-4c89-8400-ec3854b0f2b4" }
let(:sales_log_id4) { "0b4a68df-30cc-474a-93c0-a56ce8fdad3b" }
before do before do
# Stub the S3 file listing and download # Stub the S3 file listing and download
allow(storage_service).to receive(:list_files) allow(storage_service).to receive(:list_files)
.and_return(%W[#{remote_folder}/#{sales_log_id}.xml #{remote_folder}/#{sales_log_id2}.xml #{remote_folder}/#{sales_log_id3}.xml #{remote_folder}/#{sales_log_id4}.xml]) .and_return(%W[#{remote_folder}/#{shared_ownership_sales_log_id}.xml #{remote_folder}/#{shared_ownership_sales_log_id2}.xml #{remote_folder}/#{outright_sale_sales_log_id}.xml #{remote_folder}/#{discounted_ownership_sales_log_id}.xml])
allow(storage_service).to receive(:get_file_io) allow(storage_service).to receive(:get_file_io)
.with("#{remote_folder}/#{sales_log_id}.xml") .with("#{remote_folder}/#{shared_ownership_sales_log_id}.xml")
.and_return(open_file(fixture_directory, sales_log_id), open_file(fixture_directory, sales_log_id)) .and_return(open_file(fixture_directory, shared_ownership_sales_log_id), open_file(fixture_directory, shared_ownership_sales_log_id))
allow(storage_service).to receive(:get_file_io) allow(storage_service).to receive(:get_file_io)
.with("#{remote_folder}/#{sales_log_id2}.xml") .with("#{remote_folder}/#{shared_ownership_sales_log_id2}.xml")
.and_return(open_file(fixture_directory, sales_log_id2), open_file(fixture_directory, sales_log_id2)) .and_return(open_file(fixture_directory, shared_ownership_sales_log_id2), open_file(fixture_directory, shared_ownership_sales_log_id2))
allow(storage_service).to receive(:get_file_io) allow(storage_service).to receive(:get_file_io)
.with("#{remote_folder}/#{sales_log_id3}.xml") .with("#{remote_folder}/#{outright_sale_sales_log_id}.xml")
.and_return(open_file(fixture_directory, sales_log_id3), open_file(fixture_directory, sales_log_id3)) .and_return(open_file(fixture_directory, outright_sale_sales_log_id), open_file(fixture_directory, outright_sale_sales_log_id))
allow(storage_service).to receive(:get_file_io) allow(storage_service).to receive(:get_file_io)
.with("#{remote_folder}/#{sales_log_id4}.xml") .with("#{remote_folder}/#{discounted_ownership_sales_log_id}.xml")
.and_return(open_file(fixture_directory, sales_log_id4), open_file(fixture_directory, sales_log_id4)) .and_return(open_file(fixture_directory, discounted_ownership_sales_log_id), open_file(fixture_directory, discounted_ownership_sales_log_id))
end end
it "successfully creates all sales logs" do it "successfully creates all sales logs" do
@ -70,30 +69,30 @@ RSpec.describe Imports::SalesLogsImportService do
end end
context "when there are status discrepancies" do context "when there are status discrepancies" do
let(:sales_log_id5) { "893ufj2s-lq77-42m4-rty6-ej09gh585uy1" } let(:shared_ownership_sales_log_id3) { "893ufj2s-lq77-42m4-rty6-ej09gh585uy1" }
let(:sales_log_id6) { "5ybz29dj-l33t-k1l0-hj86-n4k4ma77xkcd" } let(:shared_ownership_sales_log_id4) { "5ybz29dj-l33t-k1l0-hj86-n4k4ma77xkcd" }
let(:sales_log_file) { open_file(fixture_directory, sales_log_id5) } let(:sales_log_file) { open_file(fixture_directory, shared_ownership_sales_log_id3) }
let(:sales_log_xml) { Nokogiri::XML(sales_log_file) } let(:sales_log_xml) { Nokogiri::XML(sales_log_file) }
before do before do
allow(storage_service).to receive(:get_file_io) allow(storage_service).to receive(:get_file_io)
.with("#{remote_folder}/#{sales_log_id5}.xml") .with("#{remote_folder}/#{shared_ownership_sales_log_id3}.xml")
.and_return(open_file(fixture_directory, sales_log_id5), open_file(fixture_directory, sales_log_id5)) .and_return(open_file(fixture_directory, shared_ownership_sales_log_id3), open_file(fixture_directory, shared_ownership_sales_log_id3))
allow(storage_service).to receive(:get_file_io) allow(storage_service).to receive(:get_file_io)
.with("#{remote_folder}/#{sales_log_id6}.xml") .with("#{remote_folder}/#{shared_ownership_sales_log_id4}.xml")
.and_return(open_file(fixture_directory, sales_log_id6), open_file(fixture_directory, sales_log_id6)) .and_return(open_file(fixture_directory, shared_ownership_sales_log_id4), open_file(fixture_directory, shared_ownership_sales_log_id4))
end end
it "the logger logs a warning with the sales log's old id/filename" do it "the logger logs a warning with the sales log's old id/filename" do
expect(logger).to receive(:warn).with(/is not completed/).once expect(logger).to receive(:warn).with(/is not completed/).once
expect(logger).to receive(:warn).with(/sales log with old id:#{sales_log_id5} is incomplete but status should be complete/).once expect(logger).to receive(:warn).with(/sales log with old id:#{shared_ownership_sales_log_id3} is incomplete but status should be complete/).once
sales_log_service.send(:create_log, sales_log_xml) sales_log_service.send(:create_log, sales_log_xml)
end end
it "on completion the ids of all logs with status discrepancies are logged in a warning" do it "on completion the ids of all logs with status discrepancies are logged in a warning" do
allow(storage_service).to receive(:list_files) allow(storage_service).to receive(:list_files)
.and_return(%W[#{remote_folder}/#{sales_log_id5}.xml #{remote_folder}/#{sales_log_id6}.xml]) .and_return(%W[#{remote_folder}/#{shared_ownership_sales_log_id3}.xml #{remote_folder}/#{shared_ownership_sales_log_id4}.xml])
expect(logger).to receive(:warn).with(/is not completed/).twice expect(logger).to receive(:warn).with(/is not completed/).twice
expect(logger).to receive(:warn).with(/is incomplete but status should be complete/).twice expect(logger).to receive(:warn).with(/is incomplete but status should be complete/).twice
expect(logger).to receive(:warn).with(/The following sales logs had status discrepancies: \[893ufj2s-lq77-42m4-rty6-ej09gh585uy1, 5ybz29dj-l33t-k1l0-hj86-n4k4ma77xkcd\]/) expect(logger).to receive(:warn).with(/The following sales logs had status discrepancies: \[893ufj2s-lq77-42m4-rty6-ej09gh585uy1, 5ybz29dj-l33t-k1l0-hj86-n4k4ma77xkcd\]/)
@ -108,7 +107,7 @@ RSpec.describe Imports::SalesLogsImportService do
let(:sales_log_xml) { Nokogiri::XML(sales_log_file) } let(:sales_log_xml) { Nokogiri::XML(sales_log_file) }
context "and the organisation legacy ID does not exist" do context "and the organisation legacy ID does not exist" do
let(:sales_log_id) { "0ead17cb-1668-442d-898c-0d52879ff592" } let(:sales_log_id) { shared_ownership_sales_log_id }
before { sales_log_xml.at_xpath("//xmlns:OWNINGORGID").content = 99_999 } before { sales_log_xml.at_xpath("//xmlns:OWNINGORGID").content = 99_999 }
@ -119,7 +118,7 @@ RSpec.describe Imports::SalesLogsImportService do
end end
context "when the mortgage lender is set to an existing option" do context "when the mortgage lender is set to an existing option" do
let(:sales_log_id) { "0b4a68df-30cc-474a-93c0-a56ce8fdad3b" } let(:sales_log_id) { discounted_ownership_sales_log_id }
before do before do
sales_log_xml.at_xpath("//xmlns:Q34a").content = "halifax" sales_log_xml.at_xpath("//xmlns:Q34a").content = "halifax"
@ -135,7 +134,7 @@ RSpec.describe Imports::SalesLogsImportService do
end end
context "when the mortgage lender is set to a non existing option" do context "when the mortgage lender is set to a non existing option" do
let(:sales_log_id) { "0b4a68df-30cc-474a-93c0-a56ce8fdad3b" } let(:sales_log_id) { discounted_ownership_sales_log_id }
before do before do
sales_log_xml.at_xpath("//xmlns:Q34a").content = "something else" sales_log_xml.at_xpath("//xmlns:Q34a").content = "something else"
@ -152,7 +151,7 @@ RSpec.describe Imports::SalesLogsImportService do
end end
context "when the armedforcesspouse is not answered" do context "when the armedforcesspouse is not answered" do
let(:sales_log_id) { "0b4a68df-30cc-474a-93c0-a56ce8fdad3b" } let(:sales_log_id) { discounted_ownership_sales_log_id }
before do before do
sales_log_xml.at_xpath("//xmlns:ARMEDFORCESSPOUSE").content = "" sales_log_xml.at_xpath("//xmlns:ARMEDFORCESSPOUSE").content = ""
@ -168,7 +167,7 @@ RSpec.describe Imports::SalesLogsImportService do
end end
context "with shared ownership type" do context "with shared ownership type" do
let(:sales_log_id) { "0ead17cb-1668-442d-898c-0d52879ff592" } let(:sales_log_id) { shared_ownership_sales_log_id }
it "successfully creates a completed shared ownership log" do it "successfully creates a completed shared ownership log" do
allow(logger).to receive(:warn).and_return(nil) allow(logger).to receive(:warn).and_return(nil)
@ -181,7 +180,7 @@ RSpec.describe Imports::SalesLogsImportService do
end end
context "with discounted ownership type" do context "with discounted ownership type" do
let(:sales_log_id) { "0b4a68df-30cc-474a-93c0-a56ce8fdad3b" } let(:sales_log_id) { discounted_ownership_sales_log_id }
it "successfully creates a completed discounted ownership log" do it "successfully creates a completed discounted ownership log" do
allow(logger).to receive(:warn).and_return(nil) allow(logger).to receive(:warn).and_return(nil)
@ -194,7 +193,7 @@ RSpec.describe Imports::SalesLogsImportService do
end end
context "with outright sale type" do context "with outright sale type" do
let(:sales_log_id) { "00d2343e-d5fa-4c89-8400-ec3854b0f2b4" } let(:sales_log_id) { outright_sale_sales_log_id }
it "successfully creates a completed outright sale log" do it "successfully creates a completed outright sale log" do
allow(logger).to receive(:warn).and_return(nil) allow(logger).to receive(:warn).and_return(nil)

Loading…
Cancel
Save