|
|
|
@ -1,6 +1,16 @@ |
|
|
|
require "rails_helper" |
|
|
|
require "rails_helper" |
|
|
|
|
|
|
|
require "rake" |
|
|
|
|
|
|
|
|
|
|
|
RSpec.describe Csv::LettingsLogCsvService do |
|
|
|
RSpec.describe Csv::LettingsLogCsvService do |
|
|
|
|
|
|
|
subject(:task) { Rake::Task["data_import:add_variable_definitions"] } |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
before do |
|
|
|
|
|
|
|
Rake.application.rake_require("tasks/log_variable_definitions") |
|
|
|
|
|
|
|
Rake::Task.define_task(:environment) |
|
|
|
|
|
|
|
task.reenable |
|
|
|
|
|
|
|
task.invoke("spec/fixtures/variable_definitions") |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
context "when downloading a csv" do |
|
|
|
context "when downloading a csv" do |
|
|
|
let(:log) { create(:lettings_log) } |
|
|
|
let(:log) { create(:lettings_log) } |
|
|
|
let(:user) { create(:user, :support, email: "s.port@jeemayle.com") } |
|
|
|
let(:user) { create(:user, :support, email: "s.port@jeemayle.com") } |
|
|
|
@ -9,15 +19,20 @@ RSpec.describe Csv::LettingsLogCsvService do |
|
|
|
let(:year) { 2024 } |
|
|
|
let(:year) { 2024 } |
|
|
|
let(:csv) { CSV.parse(service.prepare_csv(LettingsLog.where(id: logs.map(&:id)))) } |
|
|
|
let(:csv) { CSV.parse(service.prepare_csv(LettingsLog.where(id: logs.map(&:id)))) } |
|
|
|
let(:logs) { [log] } |
|
|
|
let(:logs) { [log] } |
|
|
|
let(:headers) { csv.first } |
|
|
|
let(:definition_headers) { csv.first } |
|
|
|
|
|
|
|
let(:attribute_headers) { csv.second } |
|
|
|
|
|
|
|
|
|
|
|
it "returns a string" do |
|
|
|
it "returns a string" do |
|
|
|
result = service.prepare_csv(LettingsLog.all) |
|
|
|
result = service.prepare_csv(LettingsLog.all) |
|
|
|
expect(result).to be_a String |
|
|
|
expect(result).to be_a String |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
it "returns a csv with headers" do |
|
|
|
it "returns a csv with definition headers on the first line" do |
|
|
|
expect(csv.first.first).to eq "id" |
|
|
|
expect(csv.first.first).to eq "Log ID" |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
it "returns a csv with attribute headers on the second line" do |
|
|
|
|
|
|
|
expect(csv.second.first).to eq "id" |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
context "when stubbing :ordered_questions_for_year" do |
|
|
|
context "when stubbing :ordered_questions_for_year" do |
|
|
|
@ -50,13 +65,13 @@ RSpec.describe Csv::LettingsLogCsvService do |
|
|
|
let(:question_ids) { %w[prevten startdate brent rent_type] } |
|
|
|
let(:question_ids) { %w[prevten startdate brent rent_type] } |
|
|
|
|
|
|
|
|
|
|
|
it "includes log attributes related to questions to the headers" do |
|
|
|
it "includes log attributes related to questions to the headers" do |
|
|
|
expect(headers).to include(*question_ids.first(3)) |
|
|
|
expect(attribute_headers).to include(*question_ids.first(3)) |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
it "removes some log attributes related to questions from the headers and replaces them with their derived values in the correct order" do |
|
|
|
it "removes some log attributes related to questions from the headers and replaces them with their derived values in the correct order" do |
|
|
|
expect(headers).not_to include "rent_type" |
|
|
|
expect(attribute_headers).not_to include "rent_type" |
|
|
|
expect(headers).to include(*%w[wrent renttype renttype_detail]) |
|
|
|
expect(attribute_headers).to include(*%w[wrent renttype renttype_detail]) |
|
|
|
expect(headers).not_to include("rent_type_detail") |
|
|
|
expect(attribute_headers).not_to include("rent_type_detail") |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
@ -70,23 +85,23 @@ RSpec.describe Csv::LettingsLogCsvService do |
|
|
|
|
|
|
|
|
|
|
|
it "does not add the id of the checkbox question to the headers" do |
|
|
|
it "does not add the id of the checkbox question to the headers" do |
|
|
|
question_ids = questions.map(&:id) |
|
|
|
question_ids = questions.map(&:id) |
|
|
|
expect(headers).not_to include(*question_ids) |
|
|
|
expect(attribute_headers).not_to include(*question_ids) |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
it "adds the related log attributes from the answer options to the headers" do |
|
|
|
it "adds the related log attributes from the answer options to the headers" do |
|
|
|
log_attributes = questions.flat_map { |q| q.answer_options.keys } |
|
|
|
log_attributes = questions.flat_map { |q| q.answer_options.keys } |
|
|
|
expect(headers).to include(*log_attributes) |
|
|
|
expect(attribute_headers).to include(*log_attributes) |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
it "adds log attributes not related to questions to the headers" do |
|
|
|
it "adds log attributes not related to questions to the headers" do |
|
|
|
expect(headers.first(5)).to eq %w[id status duplicate_set_id created_by assigned_to] |
|
|
|
expect(attribute_headers.first(5)).to eq %w[id status duplicate_set_id created_by assigned_to] |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
it "adds attributes related to associated schemes and locations to the headers" do |
|
|
|
it "adds attributes related to associated schemes and locations to the headers" do |
|
|
|
expect(headers).to include(*%w[scheme_service_name scheme_confidential SCHTYPE scheme_registered_under_care_act]) |
|
|
|
expect(attribute_headers).to include(*%w[scheme_service_name scheme_confidential SCHTYPE scheme_registered_under_care_act]) |
|
|
|
expect(headers.last(5)).to eq %w[location_units location_type_of_unit location_mobility_type location_local_authority location_startdate] |
|
|
|
expect(attribute_headers.last(5)).to eq %w[location_units location_type_of_unit location_mobility_type location_local_authority location_startdate] |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
context "when there are many logs" do |
|
|
|
context "when there are many logs" do |
|
|
|
@ -94,7 +109,7 @@ RSpec.describe Csv::LettingsLogCsvService do |
|
|
|
let(:log_count) { 30 } |
|
|
|
let(:log_count) { 30 } |
|
|
|
|
|
|
|
|
|
|
|
it "creates a CSV with the correct number of logs" do |
|
|
|
it "creates a CSV with the correct number of logs" do |
|
|
|
expected_row_count_with_headers = log_count + 1 |
|
|
|
expected_row_count_with_headers = log_count + 2 |
|
|
|
expect(csv.size).to be expected_row_count_with_headers |
|
|
|
expect(csv.size).to be expected_row_count_with_headers |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
@ -104,32 +119,32 @@ RSpec.describe Csv::LettingsLogCsvService do |
|
|
|
let(:log) { create(:lettings_log, :setup_completed, hhmemb: 2, details_known_2: 0, relat2: "P", age1: 35, la: "E09000003", duplicate_set_id: 12_312) } |
|
|
|
let(:log) { create(:lettings_log, :setup_completed, hhmemb: 2, details_known_2: 0, relat2: "P", age1: 35, la: "E09000003", duplicate_set_id: 12_312) } |
|
|
|
|
|
|
|
|
|
|
|
it "gives answer to radio questions as labels" do |
|
|
|
it "gives answer to radio questions as labels" do |
|
|
|
relat2_column_index = csv.first.index("relat2") |
|
|
|
relat2_column_index = csv.second.index("relat2") |
|
|
|
relat2_value = csv.second[relat2_column_index] |
|
|
|
relat2_value = csv.third[relat2_column_index] |
|
|
|
expect(relat2_value).to eq "Partner" |
|
|
|
expect(relat2_value).to eq "Partner" |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
it "gives answers to free input questions as the user input" do |
|
|
|
it "gives answers to free input questions as the user input" do |
|
|
|
age1_column_index = csv.first.index("age1") |
|
|
|
age1_column_index = csv.second.index("age1") |
|
|
|
age1_value = csv.second[age1_column_index] |
|
|
|
age1_value = csv.third[age1_column_index] |
|
|
|
expect(age1_value).to eq 35.to_s |
|
|
|
expect(age1_value).to eq 35.to_s |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
it "exports the code for the local authority under the heading 'la'" do |
|
|
|
it "exports the code for the local authority under the heading 'la'" do |
|
|
|
la_column_index = csv.first.index("la") |
|
|
|
la_column_index = csv.second.index("la") |
|
|
|
la_value = csv.second[la_column_index] |
|
|
|
la_value = csv.third[la_column_index] |
|
|
|
expect(la_value).to eq "E09000003" |
|
|
|
expect(la_value).to eq "E09000003" |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
it "exports the label for the local authority under the heading 'la_label'" do |
|
|
|
it "exports the label for the local authority under the heading 'la_label'" do |
|
|
|
la_label_column_index = csv.first.index("la_label") |
|
|
|
la_label_column_index = csv.second.index("la_label") |
|
|
|
la_label_value = csv.second[la_label_column_index] |
|
|
|
la_label_value = csv.third[la_label_column_index] |
|
|
|
expect(la_label_value).to eq "Barnet" |
|
|
|
expect(la_label_value).to eq "Barnet" |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
it "exports the id for under the heading 'duplicate_set_id'" do |
|
|
|
it "exports the id for under the heading 'duplicate_set_id'" do |
|
|
|
duplicate_set_id_column_index = csv.first.index("duplicate_set_id") |
|
|
|
duplicate_set_id_column_index = csv.second.index("duplicate_set_id") |
|
|
|
duplicate_set_id_value = csv.second[duplicate_set_id_column_index] |
|
|
|
duplicate_set_id_value = csv.third[duplicate_set_id_column_index] |
|
|
|
expect(duplicate_set_id_value).to eq "12312" |
|
|
|
expect(duplicate_set_id_value).to eq "12312" |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
@ -139,32 +154,32 @@ RSpec.describe Csv::LettingsLogCsvService do |
|
|
|
let(:log) { create(:lettings_log, :setup_completed, hhmemb: 2, details_known_2: 0, relat2: "P", age1: 35, la: "E09000003", duplicate_set_id: 12_312) } |
|
|
|
let(:log) { create(:lettings_log, :setup_completed, hhmemb: 2, details_known_2: 0, relat2: "P", age1: 35, la: "E09000003", duplicate_set_id: 12_312) } |
|
|
|
|
|
|
|
|
|
|
|
it "gives answer to radio questions as labels" do |
|
|
|
it "gives answer to radio questions as labels" do |
|
|
|
relat2_column_index = csv.first.index("relat2") |
|
|
|
relat2_column_index = csv.second.index("relat2") |
|
|
|
relat2_value = csv.second[relat2_column_index] |
|
|
|
relat2_value = csv.third[relat2_column_index] |
|
|
|
expect(relat2_value).to eq "P" |
|
|
|
expect(relat2_value).to eq "P" |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
it "gives answers to free input questions as the user input" do |
|
|
|
it "gives answers to free input questions as the user input" do |
|
|
|
age1_column_index = csv.first.index("age1") |
|
|
|
age1_column_index = csv.second.index("age1") |
|
|
|
age1_value = csv.second[age1_column_index] |
|
|
|
age1_value = csv.third[age1_column_index] |
|
|
|
expect(age1_value).to eq 35.to_s |
|
|
|
expect(age1_value).to eq 35.to_s |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
it "exports the code for the local authority under the heading 'la'" do |
|
|
|
it "exports the code for the local authority under the heading 'la'" do |
|
|
|
la_column_index = csv.first.index("la") |
|
|
|
la_column_index = csv.second.index("la") |
|
|
|
la_value = csv.second[la_column_index] |
|
|
|
la_value = csv.third[la_column_index] |
|
|
|
expect(la_value).to eq "E09000003" |
|
|
|
expect(la_value).to eq "E09000003" |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
it "exports the label for the local authority under the heading 'la_label'" do |
|
|
|
it "exports the label for the local authority under the heading 'la_label'" do |
|
|
|
la_label_column_index = csv.first.index("la_label") |
|
|
|
la_label_column_index = csv.second.index("la_label") |
|
|
|
la_label_value = csv.second[la_label_column_index] |
|
|
|
la_label_value = csv.third[la_label_column_index] |
|
|
|
expect(la_label_value).to eq "Barnet" |
|
|
|
expect(la_label_value).to eq "Barnet" |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
it "exports the duplicate log reference under the heading 'duplicate_set_id'" do |
|
|
|
it "exports the duplicate log reference under the heading 'duplicate_set_id'" do |
|
|
|
duplicate_set_id_column_index = csv.first.index("duplicate_set_id") |
|
|
|
duplicate_set_id_column_index = csv.second.index("duplicate_set_id") |
|
|
|
duplicate_set_id_value = csv.second[duplicate_set_id_column_index] |
|
|
|
duplicate_set_id_value = csv.third[duplicate_set_id_column_index] |
|
|
|
expect(duplicate_set_id_value).to eq "12312" |
|
|
|
expect(duplicate_set_id_value).to eq "12312" |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
@ -173,7 +188,7 @@ RSpec.describe Csv::LettingsLogCsvService do |
|
|
|
let(:user) { create(:user, :data_coordinator, email: "choreographer@owtluk.com") } |
|
|
|
let(:user) { create(:user, :data_coordinator, email: "choreographer@owtluk.com") } |
|
|
|
|
|
|
|
|
|
|
|
it "does not include certain attributes in the headers" do |
|
|
|
it "does not include certain attributes in the headers" do |
|
|
|
expect(headers).not_to include(*%w[wrent wscharge wpschrge wsupchrg wtcharge]) |
|
|
|
expect(attribute_headers).not_to include(*%w[wrent wscharge wpschrge wsupchrg wtcharge]) |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
@ -316,8 +331,8 @@ RSpec.describe Csv::LettingsLogCsvService do |
|
|
|
expected_content = CSV.read("spec/fixtures/files/lettings_log_csv_export_labels_24.csv") |
|
|
|
expected_content = CSV.read("spec/fixtures/files/lettings_log_csv_export_labels_24.csv") |
|
|
|
values_to_delete = %w[id] |
|
|
|
values_to_delete = %w[id] |
|
|
|
values_to_delete.each do |attribute| |
|
|
|
values_to_delete.each do |attribute| |
|
|
|
index = csv.first.index(attribute) |
|
|
|
index = csv.second.index(attribute) |
|
|
|
csv.second[index] = nil |
|
|
|
csv.third[index] = nil |
|
|
|
end |
|
|
|
end |
|
|
|
expect(csv).to eq expected_content |
|
|
|
expect(csv).to eq expected_content |
|
|
|
end |
|
|
|
end |
|
|
|
@ -330,8 +345,8 @@ RSpec.describe Csv::LettingsLogCsvService do |
|
|
|
expected_content = CSV.read("spec/fixtures/files/lettings_log_csv_export_non_support_labels_24.csv") |
|
|
|
expected_content = CSV.read("spec/fixtures/files/lettings_log_csv_export_non_support_labels_24.csv") |
|
|
|
values_to_delete = %w[id] |
|
|
|
values_to_delete = %w[id] |
|
|
|
values_to_delete.each do |attribute| |
|
|
|
values_to_delete.each do |attribute| |
|
|
|
index = csv.first.index(attribute) |
|
|
|
index = csv.second.index(attribute) |
|
|
|
csv.second[index] = nil |
|
|
|
csv.third[index] = nil |
|
|
|
end |
|
|
|
end |
|
|
|
expect(csv).to eq expected_content |
|
|
|
expect(csv).to eq expected_content |
|
|
|
end |
|
|
|
end |
|
|
|
@ -348,8 +363,8 @@ RSpec.describe Csv::LettingsLogCsvService do |
|
|
|
expected_content = CSV.read("spec/fixtures/files/lettings_log_csv_export_codes_24.csv") |
|
|
|
expected_content = CSV.read("spec/fixtures/files/lettings_log_csv_export_codes_24.csv") |
|
|
|
values_to_delete = %w[id] |
|
|
|
values_to_delete = %w[id] |
|
|
|
values_to_delete.each do |attribute| |
|
|
|
values_to_delete.each do |attribute| |
|
|
|
index = csv.first.index(attribute) |
|
|
|
index = csv.second.index(attribute) |
|
|
|
csv.second[index] = nil |
|
|
|
csv.third[index] = nil |
|
|
|
end |
|
|
|
end |
|
|
|
expect(csv).to eq expected_content |
|
|
|
expect(csv).to eq expected_content |
|
|
|
end |
|
|
|
end |
|
|
|
@ -362,8 +377,8 @@ RSpec.describe Csv::LettingsLogCsvService do |
|
|
|
expected_content = CSV.read("spec/fixtures/files/lettings_log_csv_export_non_support_codes_24.csv") |
|
|
|
expected_content = CSV.read("spec/fixtures/files/lettings_log_csv_export_non_support_codes_24.csv") |
|
|
|
values_to_delete = %w[id] |
|
|
|
values_to_delete = %w[id] |
|
|
|
values_to_delete.each do |attribute| |
|
|
|
values_to_delete.each do |attribute| |
|
|
|
index = csv.first.index(attribute) |
|
|
|
index = csv.second.index(attribute) |
|
|
|
csv.second[index] = nil |
|
|
|
csv.third[index] = nil |
|
|
|
end |
|
|
|
end |
|
|
|
expect(csv).to eq expected_content |
|
|
|
expect(csv).to eq expected_content |
|
|
|
end |
|
|
|
end |
|
|
|
@ -504,8 +519,8 @@ RSpec.describe Csv::LettingsLogCsvService do |
|
|
|
expected_content = CSV.read("spec/fixtures/files/lettings_log_csv_export_labels_23.csv") |
|
|
|
expected_content = CSV.read("spec/fixtures/files/lettings_log_csv_export_labels_23.csv") |
|
|
|
values_to_delete = %w[id] |
|
|
|
values_to_delete = %w[id] |
|
|
|
values_to_delete.each do |attribute| |
|
|
|
values_to_delete.each do |attribute| |
|
|
|
index = csv.first.index(attribute) |
|
|
|
index = csv.second.index(attribute) |
|
|
|
csv.second[index] = nil |
|
|
|
csv.third[index] = nil |
|
|
|
end |
|
|
|
end |
|
|
|
expect(csv).to eq expected_content |
|
|
|
expect(csv).to eq expected_content |
|
|
|
end |
|
|
|
end |
|
|
|
@ -518,8 +533,8 @@ RSpec.describe Csv::LettingsLogCsvService do |
|
|
|
expected_content = CSV.read("spec/fixtures/files/lettings_log_csv_export_non_support_labels_23.csv") |
|
|
|
expected_content = CSV.read("spec/fixtures/files/lettings_log_csv_export_non_support_labels_23.csv") |
|
|
|
values_to_delete = %w[id] |
|
|
|
values_to_delete = %w[id] |
|
|
|
values_to_delete.each do |attribute| |
|
|
|
values_to_delete.each do |attribute| |
|
|
|
index = csv.first.index(attribute) |
|
|
|
index = csv.second.index(attribute) |
|
|
|
csv.second[index] = nil |
|
|
|
csv.third[index] = nil |
|
|
|
end |
|
|
|
end |
|
|
|
expect(csv).to eq expected_content |
|
|
|
expect(csv).to eq expected_content |
|
|
|
end |
|
|
|
end |
|
|
|
@ -536,8 +551,8 @@ RSpec.describe Csv::LettingsLogCsvService do |
|
|
|
expected_content = CSV.read("spec/fixtures/files/lettings_log_csv_export_codes_23.csv") |
|
|
|
expected_content = CSV.read("spec/fixtures/files/lettings_log_csv_export_codes_23.csv") |
|
|
|
values_to_delete = %w[id] |
|
|
|
values_to_delete = %w[id] |
|
|
|
values_to_delete.each do |attribute| |
|
|
|
values_to_delete.each do |attribute| |
|
|
|
index = csv.first.index(attribute) |
|
|
|
index = csv.second.index(attribute) |
|
|
|
csv.second[index] = nil |
|
|
|
csv.third[index] = nil |
|
|
|
end |
|
|
|
end |
|
|
|
expect(csv).to eq expected_content |
|
|
|
expect(csv).to eq expected_content |
|
|
|
end |
|
|
|
end |
|
|
|
@ -550,8 +565,8 @@ RSpec.describe Csv::LettingsLogCsvService do |
|
|
|
expected_content = CSV.read("spec/fixtures/files/lettings_log_csv_export_non_support_codes_23.csv") |
|
|
|
expected_content = CSV.read("spec/fixtures/files/lettings_log_csv_export_non_support_codes_23.csv") |
|
|
|
values_to_delete = %w[id] |
|
|
|
values_to_delete = %w[id] |
|
|
|
values_to_delete.each do |attribute| |
|
|
|
values_to_delete.each do |attribute| |
|
|
|
index = csv.first.index(attribute) |
|
|
|
index = csv.second.index(attribute) |
|
|
|
csv.second[index] = nil |
|
|
|
csv.third[index] = nil |
|
|
|
end |
|
|
|
end |
|
|
|
expect(csv).to eq expected_content |
|
|
|
expect(csv).to eq expected_content |
|
|
|
end |
|
|
|
end |
|
|
|
|