|
|
|
@ -194,6 +194,199 @@ RSpec.describe Csv::LettingsLogCsvService do
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
describe "the full CSV output" do |
|
|
|
|
context "when the requested log year is 2025" do |
|
|
|
|
let(:year) { 2025 } |
|
|
|
|
let(:organisation) { create(:organisation, provider_type: "LA", name: "MHCLG") } |
|
|
|
|
let(:log) do |
|
|
|
|
create( |
|
|
|
|
:lettings_log, |
|
|
|
|
:ignore_validation_errors, |
|
|
|
|
created_by: user, |
|
|
|
|
assigned_to: user, |
|
|
|
|
created_at: Time.zone.local(2025, 4, 1), |
|
|
|
|
updated_at: Time.zone.local(2025, 4, 1), |
|
|
|
|
owning_organisation: organisation, |
|
|
|
|
managing_organisation: organisation, |
|
|
|
|
needstype: 1, |
|
|
|
|
renewal: 0, |
|
|
|
|
startdate: Time.zone.local(2025, 4, 1), |
|
|
|
|
rent_type: 1, |
|
|
|
|
tenancycode: "HIJKLMN", |
|
|
|
|
propcode: "ABCDEFG", |
|
|
|
|
declaration: 1, |
|
|
|
|
address_line1: "Address line 1", |
|
|
|
|
town_or_city: "London", |
|
|
|
|
postcode_full: "NW9 5LL", |
|
|
|
|
la: "E09000003", |
|
|
|
|
is_la_inferred: false, |
|
|
|
|
address_line1_as_entered: "address line 1 as entered", |
|
|
|
|
address_line2_as_entered: "address line 2 as entered", |
|
|
|
|
town_or_city_as_entered: "town or city as entered", |
|
|
|
|
county_as_entered: "county as entered", |
|
|
|
|
postcode_full_as_entered: "AB1 2CD", |
|
|
|
|
la_as_entered: "la as entered", |
|
|
|
|
first_time_property_let_as_social_housing: 0, |
|
|
|
|
unitletas: 2, |
|
|
|
|
rsnvac: 6, |
|
|
|
|
unittype_gn: 7, |
|
|
|
|
builtype: 1, |
|
|
|
|
wchair: 1, |
|
|
|
|
beds: 3, |
|
|
|
|
voiddate: Time.zone.local(2025, 3, 30), |
|
|
|
|
majorrepairs: 1, |
|
|
|
|
mrcdate: Time.zone.local(2025, 3, 31), |
|
|
|
|
joint: 3, |
|
|
|
|
startertenancy: 1, |
|
|
|
|
tenancy: 4, |
|
|
|
|
tenancylength: 2, |
|
|
|
|
hhmemb: 4, |
|
|
|
|
age1_known: 0, |
|
|
|
|
age1: 35, |
|
|
|
|
sex1: "F", |
|
|
|
|
ethnic_group: 0, |
|
|
|
|
ethnic: 2, |
|
|
|
|
nationality_all: 36, |
|
|
|
|
ecstat1: 0, |
|
|
|
|
details_known_2: 0, |
|
|
|
|
relat2: "P", |
|
|
|
|
age2_known: 0, |
|
|
|
|
age2: 32, |
|
|
|
|
sex2: "M", |
|
|
|
|
ecstat2: 6, |
|
|
|
|
details_known_3: 1, |
|
|
|
|
details_known_4: 0, |
|
|
|
|
relat4: "R", |
|
|
|
|
age4_known: 1, |
|
|
|
|
sex4: "R", |
|
|
|
|
ecstat4: 10, |
|
|
|
|
armedforces: 1, |
|
|
|
|
leftreg: 4, |
|
|
|
|
reservist: 1, |
|
|
|
|
preg_occ: 2, |
|
|
|
|
housingneeds: 1, |
|
|
|
|
housingneeds_type: 0, |
|
|
|
|
housingneeds_a: 1, |
|
|
|
|
housingneeds_b: 0, |
|
|
|
|
housingneeds_c: 0, |
|
|
|
|
housingneeds_f: 0, |
|
|
|
|
housingneeds_g: 0, |
|
|
|
|
housingneeds_h: 0, |
|
|
|
|
housingneeds_other: 0, |
|
|
|
|
illness: 1, |
|
|
|
|
illness_type_1: 0, |
|
|
|
|
illness_type_2: 1, |
|
|
|
|
illness_type_3: 0, |
|
|
|
|
illness_type_4: 0, |
|
|
|
|
illness_type_5: 0, |
|
|
|
|
illness_type_6: 0, |
|
|
|
|
illness_type_7: 0, |
|
|
|
|
illness_type_8: 0, |
|
|
|
|
illness_type_9: 0, |
|
|
|
|
illness_type_10: 0, |
|
|
|
|
layear: 2, |
|
|
|
|
waityear: 7, |
|
|
|
|
reason: 4, |
|
|
|
|
prevten: 6, |
|
|
|
|
homeless: 1, |
|
|
|
|
ppcodenk: 1, |
|
|
|
|
ppostcode_full: "TN23 6LZ", |
|
|
|
|
previous_la_known: 1, |
|
|
|
|
prevloc: "E07000105", |
|
|
|
|
reasonpref: 1, |
|
|
|
|
rp_homeless: 0, |
|
|
|
|
rp_insan_unsat: 1, |
|
|
|
|
rp_medwel: 0, |
|
|
|
|
rp_hardship: 0, |
|
|
|
|
rp_dontknow: 0, |
|
|
|
|
cbl: 0, |
|
|
|
|
chr: 1, |
|
|
|
|
cap: 0, |
|
|
|
|
accessible_register: 0, |
|
|
|
|
referral: 2, |
|
|
|
|
net_income_known: 0, |
|
|
|
|
incref: 0, |
|
|
|
|
incfreq: 1, |
|
|
|
|
earnings: 268, |
|
|
|
|
hb: 6, |
|
|
|
|
has_benefits: 1, |
|
|
|
|
benefits: 1, |
|
|
|
|
period: 2, |
|
|
|
|
brent: 200, |
|
|
|
|
scharge: 50, |
|
|
|
|
pscharge: 40, |
|
|
|
|
supcharg: 35, |
|
|
|
|
tcharge: 325, |
|
|
|
|
hbrentshortfall: 1, |
|
|
|
|
tshortfall_known: 1, |
|
|
|
|
tshortfall: 12, |
|
|
|
|
) |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
context "when exporting with human readable labels" do |
|
|
|
|
let(:export_type) { "labels" } |
|
|
|
|
|
|
|
|
|
context "when the current user is a support user" do |
|
|
|
|
let(:user) { create(:user, :support, organisation:, email: "s.port@jeemayle.com") } |
|
|
|
|
|
|
|
|
|
it "exports the CSV with 2025 ordering and all values correct" do |
|
|
|
|
expected_content = CSV.read("spec/fixtures/files/lettings_log_csv_export_labels_25.csv") |
|
|
|
|
values_to_delete = %w[id] |
|
|
|
|
values_to_delete.each do |attribute| |
|
|
|
|
index = attribute_line.index(attribute) |
|
|
|
|
content_line[index] = nil |
|
|
|
|
end |
|
|
|
|
expect(csv).to eq expected_content |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
context "when the current user is not a support user" do |
|
|
|
|
let(:user) { create(:user, :data_provider, organisation:, email: "choreographer@owtluk.com") } |
|
|
|
|
|
|
|
|
|
it "exports the CSV with all values correct" do |
|
|
|
|
expected_content = CSV.read("spec/fixtures/files/lettings_log_csv_export_non_support_labels_25.csv") |
|
|
|
|
values_to_delete = %w[id] |
|
|
|
|
values_to_delete.each do |attribute| |
|
|
|
|
index = attribute_line.index(attribute) |
|
|
|
|
content_line[index] = nil |
|
|
|
|
end |
|
|
|
|
expect(csv).to eq expected_content |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
context "when exporting values as codes" do |
|
|
|
|
let(:export_type) { "codes" } |
|
|
|
|
|
|
|
|
|
context "when the current user is a support user" do |
|
|
|
|
let(:user) { create(:user, :support, organisation:, email: "s.port@jeemayle.com") } |
|
|
|
|
|
|
|
|
|
it "exports the CSV with all values correct" do |
|
|
|
|
expected_content = CSV.read("spec/fixtures/files/lettings_log_csv_export_codes_25.csv") |
|
|
|
|
values_to_delete = %w[id] |
|
|
|
|
values_to_delete.each do |attribute| |
|
|
|
|
index = attribute_line.index(attribute) |
|
|
|
|
content_line[index] = nil |
|
|
|
|
end |
|
|
|
|
expect(csv).to eq expected_content |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
context "when the current user is not a support user" do |
|
|
|
|
let(:user) { create(:user, :data_provider, organisation:, email: "choreographer@owtluk.com") } |
|
|
|
|
|
|
|
|
|
it "exports the CSV with all values correct" do |
|
|
|
|
expected_content = CSV.read("spec/fixtures/files/lettings_log_csv_export_non_support_codes_25.csv") |
|
|
|
|
values_to_delete = %w[id] |
|
|
|
|
values_to_delete.each do |attribute| |
|
|
|
|
index = attribute_line.index(attribute) |
|
|
|
|
content_line[index] = nil |
|
|
|
|
end |
|
|
|
|
expect(csv).to eq expected_content |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
context "when the requested log year is 2024" do |
|
|
|
|
let(:year) { 2024 } |
|
|
|
|
let(:organisation) { create(:organisation, provider_type: "LA", name: "MHCLG") } |
|
|
|
|