Browse Source

Add IDs to the CSVs

pull/1953/head
Kat 3 years ago
parent
commit
c8590d576e
  1. 10
      app/services/csv/missing_addresses_csv_service.rb
  2. 4
      spec/fixtures/files/missing_lettings_logs_addresses.csv
  3. 4
      spec/fixtures/files/missing_lettings_logs_town_or_city.csv
  4. 4
      spec/fixtures/files/missing_sales_logs_addresses.csv
  5. 4
      spec/fixtures/files/missing_sales_logs_town_or_city.csv
  6. 20
      spec/services/csv/missing_addresses_csv_service_spec.rb

10
app/services/csv/missing_addresses_csv_service.rb

@ -36,10 +36,11 @@ module Csv
def generate_missing_lettings_addresses_csv(logs)
CSV.generate(headers: true) do |csv|
csv << ["Tenancy start date", "Tenant code", "Property code", "Log owner", "Owning organisation name", "Managing organisation name", "Address line 1", "Address line 2", "Town or City", "County", "Postcode", "Local authority"]
csv << ["Lettings log ID", "Tenancy start date", "Tenant code", "Property code", "Log owner", "Owning organisation name", "Managing organisation name", "Address line 1", "Address line 2", "Town or City", "County", "Postcode", "Local authority"]
logs.each do |log|
csv << [log.startdate&.to_date,
csv << [log.id,
log.startdate&.to_date,
log.tenancycode,
log.propcode,
log.created_by&.email,
@ -57,10 +58,11 @@ module Csv
def generate_missing_sales_addresses_csv(logs)
CSV.generate(headers: true) do |csv|
csv << ["Sale completion date", "Purchaser code", "Log owner", "Owning organisation name", "Address line 1", "Address line 2", "Town or City", "County", "Postcode", "Local authority"]
csv << ["Sales log ID", "Sale completion date", "Purchaser code", "Log owner", "Owning organisation name", "Address line 1", "Address line 2", "Town or City", "County", "Postcode", "Local authority"]
logs.each do |log|
csv << [log.saledate&.to_date,
csv << [log.id,
log.saledate&.to_date,
log.purchid,
log.created_by&.email,
log.owning_organisation&.name,

4
spec/fixtures/files/missing_lettings_logs_addresses.csv vendored

@ -1,2 +1,2 @@
Tenancy start date,Tenant code,Property code,Log owner,Owning organisation name,Managing organisation name,Address line 1,Address line 2,Town or City,County,Postcode,Local authority
2023-04-05,tenancycode,propcode,testy@example.com,Address test,Address test,,,,,,
Lettings log ID,Tenancy start date,Tenant code,Property code,Log owner,Owning organisation name,Managing organisation name,Address line 1,Address line 2,Town or City,County,Postcode,Local authority
{id},2023-04-05,tenancycode,propcode,testy@example.com,Address test,Address test,,,,,,

1 Lettings log ID Tenancy start date Tenant code Property code Log owner Owning organisation name Managing organisation name Address line 1 Address line 2 Town or City County Postcode Local authority
2 {id} 2023-04-05 tenancycode propcode testy@example.com Address test Address test

4
spec/fixtures/files/missing_lettings_logs_town_or_city.csv vendored

@ -1,2 +1,2 @@
Tenancy start date,Tenant code,Property code,Log owner,Owning organisation name,Managing organisation name,Address line 1,Address line 2,Town or City,County,Postcode,Local authority
2023-04-05,tenancycode,propcode,testy@example.com,Address test,Address test,existing address,,,,,
Lettings log ID,Tenancy start date,Tenant code,Property code,Log owner,Owning organisation name,Managing organisation name,Address line 1,Address line 2,Town or City,County,Postcode,Local authority
{id},2023-04-05,tenancycode,propcode,testy@example.com,Address test,Address test,existing address,,,,,

1 Lettings log ID Tenancy start date Tenant code Property code Log owner Owning organisation name Managing organisation name Address line 1 Address line 2 Town or City County Postcode Local authority
2 {id} 2023-04-05 tenancycode propcode testy@example.com Address test Address test existing address

4
spec/fixtures/files/missing_sales_logs_addresses.csv vendored

@ -1,2 +1,2 @@
Sale completion date,Purchaser code,Log owner,Owning organisation name,Address line 1,Address line 2,Town or City,County,Postcode,Local authority
2023-04-05,purchaser code,testy@example.com,Address test,,,,,,
Sales log ID,Sale completion date,Purchaser code,Log owner,Owning organisation name,Address line 1,Address line 2,Town or City,County,Postcode,Local authority
{id},2023-04-05,purchaser code,testy@example.com,Address test,,,,,,

1 Sales log ID Sale completion date Purchaser code Log owner Owning organisation name Address line 1 Address line 2 Town or City County Postcode Local authority
2 {id} 2023-04-05 purchaser code testy@example.com Address test

4
spec/fixtures/files/missing_sales_logs_town_or_city.csv vendored

@ -1,2 +1,2 @@
Sale completion date,Purchaser code,Log owner,Owning organisation name,Address line 1,Address line 2,Town or City,County,Postcode,Local authority
2023-04-05,purchaser code,testy@example.com,Address test,existing address line 1,,,,,
Sales log ID,Sale completion date,Purchaser code,Log owner,Owning organisation name,Address line 1,Address line 2,Town or City,County,Postcode,Local authority
{id},2023-04-05,purchaser code,testy@example.com,Address test,existing address line 1,,,,,

1 Sales log ID Sale completion date Purchaser code Log owner Owning organisation name Address line 1 Address line 2 Town or City County Postcode Local authority
2 {id} 2023-04-05 purchaser code testy@example.com Address test existing address line 1

20
spec/services/csv/missing_addresses_csv_service_spec.rb

@ -5,6 +5,10 @@ RSpec.describe Csv::MissingAddressesCsvService do
let(:user) { create(:user, organisation:, email: "testy@example.com") }
let(:service) { described_class.new(organisation) }
def replace_entity_ids(lettings_log, export_template)
export_template.sub!(/\{id\}/, lettings_log.id.to_s)
end
describe "#create_missing_lettings_addresses_csv" do
let!(:lettings_log) do
create(:lettings_log,
@ -24,8 +28,8 @@ RSpec.describe Csv::MissingAddressesCsvService do
context "when the organisation has logs with missing addresses" do
it "returns a csv with relevant logs" do
expected_content = CSV.read("spec/fixtures/files/missing_lettings_logs_addresses.csv")
csv = CSV.parse(service.create_missing_lettings_addresses_csv)
expected_content = replace_entity_ids(lettings_log, File.open("spec/fixtures/files/missing_lettings_logs_addresses.csv").read)
csv = service.create_missing_lettings_addresses_csv
expect(csv).to eq(expected_content)
end
end
@ -77,8 +81,8 @@ RSpec.describe Csv::MissingAddressesCsvService do
context "when the organisation has logs with missing addresses" do
it "returns a csv with relevant logs" do
expected_content = CSV.read("spec/fixtures/files/missing_sales_logs_addresses.csv")
csv = CSV.parse(service.create_missing_sales_addresses_csv)
expected_content = replace_entity_ids(sales_log, File.open("spec/fixtures/files/missing_sales_logs_addresses.csv").read)
csv = service.create_missing_sales_addresses_csv
expect(csv).to eq(expected_content)
end
end
@ -123,8 +127,8 @@ RSpec.describe Csv::MissingAddressesCsvService do
context "when the organisation has logs with missing town or city only" do
it "returns a csv with relevant logs" do
expected_content = CSV.read("spec/fixtures/files/missing_lettings_logs_town_or_city.csv")
csv = CSV.parse(service.create_missing_lettings_town_or_city_csv)
expected_content = replace_entity_ids(lettings_log, File.open("spec/fixtures/files/missing_lettings_logs_town_or_city.csv").read)
csv = service.create_missing_lettings_town_or_city_csv
expect(csv).to eq(expected_content)
end
end
@ -176,8 +180,8 @@ RSpec.describe Csv::MissingAddressesCsvService do
context "when the organisation has logs with missing town_or_city only" do
it "returns a csv with relevant logs" do
expected_content = CSV.read("spec/fixtures/files/missing_sales_logs_town_or_city.csv")
csv = CSV.parse(service.create_missing_sales_town_or_city_csv)
expected_content = replace_entity_ids(sales_log, File.open("spec/fixtures/files/missing_sales_logs_town_or_city.csv").read)
csv = service.create_missing_sales_town_or_city_csv
expect(csv).to eq(expected_content)
end
end

Loading…
Cancel
Save