Submit social housing lettings and sales data (CORE)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

106 lines
3.3 KiB

require "rails_helper"
RSpec.describe Csv::MissingAddressesCsvService do
let(:organisation) { create(:organisation, name: "Address test") }
let(:user) { create(:user, organisation:, email: "testy@example.com") }
let(:service) { described_class.new(organisation) }
describe "#create_missing_lettings_addresses_csv" do
let!(:lettings_log) do
create(:lettings_log,
tenancycode: "tenancycode",
propcode: "propcode",
startdate: Time.zone.local(2023, 4, 5),
created_by: user,
owning_organisation: organisation,
managing_organisation: organisation,
address_line1: nil,
town_or_city: nil,
old_id: "old_id",
old_form_id: "old_form_id",
needstype: 1,
uprn_known: 0)
end
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)
expect(csv).to eq(expected_content)
end
end
context "when the organisation only has supported housing logs with missing addresses" do
before do
lettings_log.update!(needstype: 2)
end
it "returns nil" do
expect(service.create_missing_lettings_addresses_csv).to be_nil
end
end
context "when the organisation only has logs with missing addresses from 2022" do
before do
lettings_log.update!(startdate: Time.zone.local(2022, 4, 5))
end
it "returns nil" do
expect(service.create_missing_lettings_addresses_csv).to be_nil
end
end
context "when the organisation has any address fields filled in" do
before do
lettings_log.update!(address_line1: "address_line1")
end
it "returns nil" do
expect(service.create_missing_lettings_addresses_csv).to be_nil
end
end
end
describe "#create_missing_sales_addresses_csv" do
let!(:sales_log) do
create(:sales_log,
purchid: "purchaser code",
saledate: Time.zone.local(2023, 4, 5),
created_by: user,
owning_organisation: organisation,
address_line1: nil,
town_or_city: nil,
old_id: "old_id",
old_form_id: "old_form_id",
uprn_known: 0)
end
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)
expect(csv).to eq(expected_content)
end
end
context "when the organisation only has logs with missing addresses from 2022" do
before do
sales_log.update!(saledate: Time.zone.local(2022, 4, 5))
end
it "returns nil" do
expect(service.create_missing_sales_addresses_csv).to be_nil
end
end
context "when the organisation has any address fields filled in" do
before do
sales_log.update!(town_or_city: "town")
end
it "returns nil" do
expect(service.create_missing_sales_addresses_csv).to be_nil
end
end
end
end