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.
1283 lines
37 KiB
1283 lines
37 KiB
2 years ago
|
require "rails_helper"
|
||
|
|
||
2 years ago
|
RSpec.describe BulkUpload::Lettings::Year2023::RowParser do
|
||
2 years ago
|
subject(:parser) { described_class.new(attributes) }
|
||
|
|
||
2 years ago
|
let(:now) { Time.zone.today }
|
||
|
|
||
|
let(:attributes) { { bulk_upload: } }
|
||
2 years ago
|
let(:bulk_upload) { create(:bulk_upload, :lettings, user:, needstype: nil) }
|
||
2 years ago
|
let(:user) { create(:user, organisation: owning_org) }
|
||
2 years ago
|
|
||
2 years ago
|
let(:owning_org) { create(:organisation, :with_old_visible_id) }
|
||
|
let(:managing_org) { create(:organisation, :with_old_visible_id) }
|
||
2 years ago
|
let(:scheme) { create(:scheme, :with_old_visible_id, owning_organisation: owning_org) }
|
||
|
let(:location) { create(:location, :with_old_visible_id, scheme:) }
|
||
2 years ago
|
|
||
2 years ago
|
let(:setup_section_params) do
|
||
|
{
|
||
|
bulk_upload:,
|
||
2 years ago
|
field_1: owning_org.old_visible_id,
|
||
|
field_2: managing_org.old_visible_id,
|
||
|
field_4: "1",
|
||
|
field_5: "2",
|
||
|
field_6: "2",
|
||
|
field_7: now.day.to_s,
|
||
|
field_8: now.month.to_s,
|
||
|
field_9: now.strftime("%g"),
|
||
2 years ago
|
}
|
||
|
end
|
||
|
|
||
2 years ago
|
before do
|
||
|
create(:organisation_relationship, parent_organisation: owning_org, child_organisation: managing_org)
|
||
|
end
|
||
|
|
||
2 years ago
|
around do |example|
|
||
|
FormHandler.instance.use_real_forms!
|
||
|
|
||
|
example.run
|
||
|
|
||
|
FormHandler.instance.use_fake_forms!
|
||
|
end
|
||
|
|
||
2 years ago
|
describe "#blank_row?" do
|
||
|
context "when a new object" do
|
||
|
it "returns true" do
|
||
|
expect(parser).to be_blank_row
|
||
|
end
|
||
|
end
|
||
|
|
||
|
context "when any field is populated" do
|
||
|
before do
|
||
|
parser.field_1 = "1"
|
||
|
end
|
||
|
|
||
|
it "returns false" do
|
||
|
expect(parser).not_to be_blank_row
|
||
|
end
|
||
|
end
|
||
|
end
|
||
|
|
||
2 years ago
|
describe "validations" do
|
||
|
before do
|
||
2 years ago
|
stub_request(:get, /api.postcodes.io/)
|
||
|
.to_return(status: 200, body: "{\"status\":200,\"result\":{\"admin_district\":\"Manchester\", \"codes\":{\"admin_district\": \"E08000003\"}}}", headers: {})
|
||
|
|
||
2 years ago
|
parser.valid?
|
||
|
end
|
||
|
|
||
2 years ago
|
describe "#valid?" do
|
||
2 years ago
|
context "when the row is blank" do
|
||
|
let(:attributes) { { bulk_upload: } }
|
||
|
|
||
|
it "returns true" do
|
||
|
expect(parser).to be_valid
|
||
|
end
|
||
|
end
|
||
|
|
||
2 years ago
|
context "when calling the method multiple times" do
|
||
|
let(:attributes) { { bulk_upload:, field_134: 2 } }
|
||
|
|
||
|
it "does not add keep adding errors to the pile" do
|
||
|
expect { parser.valid? }.not_to change(parser.errors, :count)
|
||
|
end
|
||
|
end
|
||
|
|
||
|
context "when valid row" do
|
||
2 years ago
|
let(:attributes) do
|
||
|
{
|
||
|
bulk_upload:,
|
||
|
field_5: "1",
|
||
|
field_13: "123",
|
||
|
field_7: now.day.to_s,
|
||
|
field_8: now.month.to_s,
|
||
|
field_9: now.strftime("%g"),
|
||
|
field_23: "EC1N",
|
||
|
field_24: "2TD",
|
||
|
field_1: owning_org.old_visible_id,
|
||
|
field_2: managing_org.old_visible_id,
|
||
|
field_11: "1",
|
||
|
field_6: "2",
|
||
|
field_29: "2",
|
||
|
field_30: "1",
|
||
|
field_31: "1",
|
||
|
field_32: "1",
|
||
|
field_39: "2",
|
||
|
field_40: "1",
|
||
|
field_41: "2",
|
||
|
field_45: "1",
|
||
|
|
||
|
field_46: "42",
|
||
|
field_52: "41",
|
||
|
field_56: "20",
|
||
|
field_60: "18",
|
||
|
field_64: "16",
|
||
|
field_68: "14",
|
||
|
field_72: "12",
|
||
|
field_76: "20",
|
||
|
|
||
|
field_47: "F",
|
||
|
field_53: "M",
|
||
|
field_57: "F",
|
||
|
field_61: "M",
|
||
|
field_65: "F",
|
||
|
field_69: "M",
|
||
|
field_73: "F",
|
||
|
field_77: "M",
|
||
|
|
||
|
field_48: "17",
|
||
|
field_49: "18",
|
||
|
|
||
|
field_51: "P",
|
||
|
field_55: "C",
|
||
|
field_59: "X",
|
||
|
field_63: "R",
|
||
|
field_67: "C",
|
||
|
field_71: "C",
|
||
|
field_75: "X",
|
||
|
|
||
|
field_50: "1",
|
||
|
field_54: "2",
|
||
|
field_58: "6",
|
||
|
field_62: "7",
|
||
|
field_66: "8",
|
||
|
field_70: "9",
|
||
|
field_74: "0",
|
||
|
field_78: "10",
|
||
|
|
||
|
field_79: "1",
|
||
|
field_80: "4",
|
||
|
field_81: "1",
|
||
|
|
||
|
field_82: "1",
|
||
|
|
||
|
field_89: "2",
|
||
|
|
||
|
field_100: "5",
|
||
|
field_101: "2",
|
||
|
field_102: "31",
|
||
|
field_104: "3",
|
||
|
field_105: "12",
|
||
|
|
||
|
field_106: "1",
|
||
|
field_107: "EC1N",
|
||
|
field_108: "2TD",
|
||
|
|
||
|
field_110: "1",
|
||
|
field_111: "1",
|
||
|
field_112: "",
|
||
|
field_113: "1",
|
||
|
field_114: "",
|
||
|
field_115: "",
|
||
|
|
||
|
field_116: "1",
|
||
|
field_117: "2",
|
||
|
field_118: "2",
|
||
|
|
||
|
field_119: "2",
|
||
|
|
||
|
field_120: "1",
|
||
|
field_122: "2000",
|
||
|
field_121: "2",
|
||
|
field_123: "1",
|
||
|
field_124: "1",
|
||
|
|
||
|
field_126: "4",
|
||
|
field_128: "1234.56",
|
||
|
field_129: "43.32",
|
||
|
field_130: "13.14",
|
||
|
field_131: "101.11",
|
||
|
field_132: "1500.19",
|
||
|
field_133: "1",
|
||
|
field_134: "234.56",
|
||
|
|
||
|
field_27: "15",
|
||
|
field_28: "0",
|
||
|
field_33: now.day.to_s,
|
||
|
field_34: now.month.to_s,
|
||
|
field_35: now.strftime("%g"),
|
||
|
|
||
|
field_4: "1",
|
||
|
}
|
||
|
end
|
||
2 years ago
|
|
||
|
it "returns true" do
|
||
|
expect(parser).to be_valid
|
||
|
end
|
||
|
|
||
|
it "instantiates a log with everything completed", aggregate_failures: true do
|
||
|
questions = parser.send(:questions).reject do |q|
|
||
|
parser.send(:log).optional_fields.include?(q.id) || q.completed?(parser.send(:log))
|
||
|
end
|
||
|
|
||
|
expect(questions.map(&:id).size).to eq(0)
|
||
|
expect(questions.map(&:id)).to eql([])
|
||
|
end
|
||
|
end
|
||
|
end
|
||
|
|
||
2 years ago
|
context "when setup section not complete" do
|
||
2 years ago
|
let(:attributes) { { bulk_upload:, field_13: "123" } }
|
||
2 years ago
|
|
||
|
it "has errors on setup fields" do
|
||
|
errors = parser.errors.select { |e| e.options[:category] == :setup }.map(&:attribute)
|
||
|
|
||
2 years ago
|
expect(errors).to eql(%i[field_4 field_5 field_7 field_8 field_9 field_1 field_2])
|
||
2 years ago
|
end
|
||
|
end
|
||
|
|
||
2 years ago
|
describe "#field_5" do
|
||
2 years ago
|
context "when null" do
|
||
2 years ago
|
let(:attributes) { { bulk_upload:, field_5: nil, field_15: "1" } }
|
||
2 years ago
|
|
||
|
it "returns an error" do
|
||
2 years ago
|
expect(parser.errors[:field_5]).to be_present
|
||
2 years ago
|
end
|
||
|
end
|
||
|
|
||
|
context "when incorrect data type" do
|
||
2 years ago
|
let(:attributes) { { bulk_upload:, field_5: "foo" } }
|
||
2 years ago
|
|
||
|
it "returns an error" do
|
||
2 years ago
|
expect(parser.errors[:field_5]).to be_present
|
||
2 years ago
|
end
|
||
|
end
|
||
|
|
||
2 years ago
|
context "when unpermitted value" do
|
||
2 years ago
|
let(:attributes) { { bulk_upload:, field_5: "101" } }
|
||
2 years ago
|
|
||
|
it "returns an error" do
|
||
2 years ago
|
expect(parser.errors[:field_5]).to be_present
|
||
2 years ago
|
end
|
||
|
end
|
||
|
|
||
|
context "when valid" do
|
||
2 years ago
|
let(:attributes) { { bulk_upload:, field_5: "1", field_4: "1" } }
|
||
2 years ago
|
|
||
2 years ago
|
it "does not return any errors" do
|
||
2 years ago
|
expect(parser.errors[:field_5]).to be_blank
|
||
2 years ago
|
end
|
||
|
end
|
||
2 years ago
|
|
||
|
context "when bulk upload is for general needs" do
|
||
|
context "when general needs option selected" do
|
||
2 years ago
|
let(:attributes) { { bulk_upload:, field_5: "1", field_4: "1" } }
|
||
2 years ago
|
|
||
|
it "is permitted" do
|
||
2 years ago
|
expect(parser.errors[:field_5]).to be_blank
|
||
2 years ago
|
end
|
||
|
end
|
||
|
|
||
|
context "when supported housing option selected" do
|
||
2 years ago
|
let(:attributes) { { bulk_upload:, field_5: "2", field_4: "1" } }
|
||
2 years ago
|
|
||
|
it "is not permitted" do
|
||
2 years ago
|
expect(parser.errors[:field_5]).to include("Lettings type must be a general needs type because you selected general needs when uploading the file")
|
||
2 years ago
|
end
|
||
|
end
|
||
|
end
|
||
|
|
||
|
context "when bulk upload is for supported housing" do
|
||
2 years ago
|
let(:bulk_upload) { create(:bulk_upload, :lettings, user:) }
|
||
2 years ago
|
|
||
|
context "when general needs option selected" do
|
||
2 years ago
|
let(:attributes) { { bulk_upload:, field_5: "1", field_4: "2" } }
|
||
2 years ago
|
|
||
|
it "is not permitted" do
|
||
2 years ago
|
expect(parser.errors[:field_5]).to include("Lettings type must be a supported housing type because you selected supported housing when uploading the file")
|
||
2 years ago
|
end
|
||
|
end
|
||
|
|
||
|
context "when supported housing option selected" do
|
||
2 years ago
|
let(:attributes) { { bulk_upload:, field_5: "2", field_4: "2" } }
|
||
2 years ago
|
|
||
|
it "is permitted" do
|
||
2 years ago
|
expect(parser.errors[:field_5]).to be_blank
|
||
2 years ago
|
end
|
||
|
end
|
||
|
end
|
||
2 years ago
|
end
|
||
|
|
||
2 years ago
|
describe "#field_16" do
|
||
2 years ago
|
context "when nullable not permitted" do
|
||
2 years ago
|
let(:attributes) { { bulk_upload:, field_5: "2", field_16: nil } }
|
||
2 years ago
|
|
||
2 years ago
|
it "cannot be nulled" do
|
||
2 years ago
|
expect(parser.errors[:field_16]).to be_present
|
||
2 years ago
|
end
|
||
|
end
|
||
|
|
||
2 years ago
|
context "when nullable permitted" do
|
||
2 years ago
|
let(:attributes) { { bulk_upload:, field_5: "1", field_16: nil } }
|
||
2 years ago
|
|
||
|
it "can be nulled" do
|
||
2 years ago
|
expect(parser.errors[:field_15]).to be_blank
|
||
2 years ago
|
end
|
||
|
end
|
||
|
|
||
|
context "when matching scheme cannot be found" do
|
||
2 years ago
|
let(:attributes) { { bulk_upload:, field_5: "1", field_16: "123" } }
|
||
2 years ago
|
|
||
2 years ago
|
it "returns an error" do
|
||
2 years ago
|
expect(parser.errors[:field_16]).to be_present
|
||
2 years ago
|
end
|
||
|
end
|
||
2 years ago
|
|
||
|
context "when scheme belongs to someone else" do
|
||
|
let(:other_scheme) { create(:scheme, :with_old_visible_id) }
|
||
2 years ago
|
let(:attributes) { { bulk_upload:, field_5: "1", field_16: other_scheme.old_visible_id, field_1: owning_org.old_visible_id } }
|
||
2 years ago
|
|
||
|
it "returns an error" do
|
||
2 years ago
|
expect(parser.errors[:field_16]).to include("This management group code does not belong to your organisation, or any of your stock owners / managing agents")
|
||
2 years ago
|
end
|
||
|
end
|
||
|
|
||
|
context "when scheme belongs to owning org" do
|
||
|
let(:scheme) { create(:scheme, :with_old_visible_id, owning_organisation: owning_org) }
|
||
2 years ago
|
let(:attributes) { { bulk_upload:, field_5: "1", field_16: scheme.old_visible_id, field_1: owning_org.old_visible_id } }
|
||
2 years ago
|
|
||
|
it "does not return an error" do
|
||
2 years ago
|
expect(parser.errors[:field_16]).to be_blank
|
||
2 years ago
|
end
|
||
|
end
|
||
|
|
||
|
context "when scheme belongs to managing org" do
|
||
|
let(:scheme) { create(:scheme, :with_old_visible_id, owning_organisation: managing_org) }
|
||
2 years ago
|
let(:attributes) { { bulk_upload:, field_5: "1", field_16: scheme.old_visible_id, field_2: managing_org.old_visible_id } }
|
||
2 years ago
|
|
||
|
it "does not return an error" do
|
||
2 years ago
|
expect(parser.errors[:field_16]).to be_blank
|
||
2 years ago
|
end
|
||
|
end
|
||
|
end
|
||
|
|
||
2 years ago
|
describe "#field_17" do
|
||
2 years ago
|
context "when location does not exist" do
|
||
|
let(:scheme) { create(:scheme, :with_old_visible_id, owning_organisation: owning_org) }
|
||
|
let(:attributes) do
|
||
|
{
|
||
|
bulk_upload:,
|
||
2 years ago
|
field_5: "1",
|
||
|
field_16: scheme.old_visible_id,
|
||
|
field_17: "dontexist",
|
||
|
field_1: owning_org.old_visible_id,
|
||
2 years ago
|
}
|
||
|
end
|
||
|
|
||
|
it "returns an error" do
|
||
2 years ago
|
expect(parser.errors[:field_17]).to be_present
|
||
2 years ago
|
end
|
||
|
end
|
||
|
|
||
|
context "when location exists" do
|
||
|
let(:scheme) { create(:scheme, :with_old_visible_id, owning_organisation: owning_org) }
|
||
|
let(:attributes) do
|
||
|
{
|
||
|
bulk_upload:,
|
||
2 years ago
|
field_5: "1",
|
||
|
field_16: scheme.old_visible_id,
|
||
|
field_17: location.old_visible_id,
|
||
|
field_1: owning_org.old_visible_id,
|
||
2 years ago
|
}
|
||
|
end
|
||
|
|
||
|
it "does not return an error" do
|
||
2 years ago
|
expect(parser.errors[:field_17]).to be_blank
|
||
2 years ago
|
end
|
||
|
end
|
||
|
|
||
|
context "when location exists but not related" do
|
||
|
let(:location) { create(:scheme, :with_old_visible_id) }
|
||
|
let(:attributes) do
|
||
|
{
|
||
|
bulk_upload:,
|
||
2 years ago
|
field_5: "1",
|
||
|
field_16: scheme.old_visible_id,
|
||
|
field_17: location.old_visible_id,
|
||
|
field_1: owning_org.old_visible_id,
|
||
2 years ago
|
}
|
||
|
end
|
||
|
|
||
|
it "returns an error" do
|
||
2 years ago
|
expect(parser.errors[:field_17]).to be_present
|
||
2 years ago
|
end
|
||
|
end
|
||
|
end
|
||
|
|
||
2 years ago
|
describe "#field_102" do # leaving reason
|
||
|
context "when field_6 is 1 meaning it is a renewal" do
|
||
|
context "when field_102 is 40" do
|
||
|
let(:attributes) { { bulk_upload:, field_102: "40", field_6: "1" } }
|
||
2 years ago
|
|
||
|
it "is permitted" do
|
||
2 years ago
|
expect(parser.errors[:field_102]).to be_blank
|
||
2 years ago
|
end
|
||
|
end
|
||
|
|
||
2 years ago
|
context "when field_102 is 42" do
|
||
|
let(:attributes) { { bulk_upload:, field_102: "42", field_6: "1" } }
|
||
2 years ago
|
|
||
|
it "is permitted" do
|
||
2 years ago
|
expect(parser.errors[:field_102]).to be_blank
|
||
2 years ago
|
end
|
||
|
end
|
||
|
|
||
2 years ago
|
context "when field_102 is not 40 or 42" do
|
||
|
let(:attributes) { { bulk_upload:, field_102: "1", field_6: "1" } }
|
||
2 years ago
|
|
||
|
it "is not permitted" do
|
||
2 years ago
|
expect(parser.errors[:field_102]).to be_present
|
||
2 years ago
|
end
|
||
|
end
|
||
|
end
|
||
|
end
|
||
|
|
||
2 years ago
|
describe "#field_83, #field_84, #field_85" do
|
||
2 years ago
|
context "when more than one item selected" do
|
||
2 years ago
|
let(:attributes) { { bulk_upload:, field_83: "1", field_84: "1" } }
|
||
2 years ago
|
|
||
|
it "is not permitted" do
|
||
2 years ago
|
expect(parser.errors[:field_83]).to be_present
|
||
|
expect(parser.errors[:field_84]).to be_present
|
||
|
expect(parser.errors[:field_85]).to be_present
|
||
2 years ago
|
end
|
||
|
end
|
||
|
end
|
||
|
|
||
2 years ago
|
describe "#field_87" do
|
||
2 years ago
|
context "when 1 and another disability field selected" do
|
||
2 years ago
|
let(:attributes) { { bulk_upload:, field_87: "1", field_86: "1" } }
|
||
2 years ago
|
|
||
|
it "is not permitted" do
|
||
2 years ago
|
expect(parser.errors[:field_87]).to be_present
|
||
2 years ago
|
end
|
||
|
end
|
||
|
end
|
||
|
|
||
2 years ago
|
describe "#field_88" do
|
||
2 years ago
|
context "when 1 and another disability field selected" do
|
||
2 years ago
|
let(:attributes) { { bulk_upload:, field_88: "1", field_86: "1" } }
|
||
2 years ago
|
|
||
|
it "is not permitted" do
|
||
2 years ago
|
expect(parser.errors[:field_88]).to be_present
|
||
2 years ago
|
end
|
||
|
end
|
||
|
end
|
||
|
|
||
2 years ago
|
describe "#field_87, #field_88" do
|
||
2 years ago
|
context "when both 1" do
|
||
2 years ago
|
let(:attributes) { { bulk_upload:, field_87: "1", field_88: "1" } }
|
||
2 years ago
|
|
||
|
it "is not permitted" do
|
||
2 years ago
|
expect(parser.errors[:field_87]).to be_present
|
||
|
expect(parser.errors[:field_88]).to be_present
|
||
2 years ago
|
end
|
||
|
end
|
||
|
end
|
||
|
|
||
2 years ago
|
describe "#field_119" do # referral
|
||
2 years ago
|
context "when 3 ie PRP nominated by LA and owning org is LA" do
|
||
2 years ago
|
let(:attributes) { { bulk_upload:, field_119: "3", field_1: owning_org.old_visible_id } }
|
||
2 years ago
|
|
||
|
it "is not permitted" do
|
||
2 years ago
|
expect(parser.errors[:field_119]).to be_present
|
||
2 years ago
|
end
|
||
|
end
|
||
2 years ago
|
|
||
2 years ago
|
context "when 4 ie referred by LA and is general needs and owning org is LA" do
|
||
2 years ago
|
let(:attributes) { { bulk_upload:, field_119: "4", field_1: owning_org.old_visible_id.to_s, field_4: "1" } }
|
||
2 years ago
|
|
||
|
it "is not permitted" do
|
||
2 years ago
|
expect(parser.errors[:field_119]).to be_present
|
||
2 years ago
|
end
|
||
|
end
|
||
|
|
||
2 years ago
|
context "when 4 ie referred by LA and is general needs and owning org is PRP" do
|
||
|
let(:owning_org) { create(:organisation, :prp, :with_old_visible_id) }
|
||
|
|
||
2 years ago
|
let(:attributes) { { bulk_upload:, field_119: "4", field_1: owning_org.old_visible_id.to_s } }
|
||
2 years ago
|
|
||
|
it "is permitted" do
|
||
2 years ago
|
expect(parser.errors[:field_119]).to be_blank
|
||
2 years ago
|
end
|
||
|
end
|
||
|
|
||
2 years ago
|
context "when 4 ie referred by LA and is not general needs" do
|
||
2 years ago
|
let(:bulk_upload) { create(:bulk_upload, :lettings, user:) }
|
||
|
let(:attributes) { { bulk_upload:, field_119: "4", field_4: "2" } }
|
||
2 years ago
|
|
||
|
it "is permitted" do
|
||
2 years ago
|
expect(parser.errors[:field_119]).to be_blank
|
||
2 years ago
|
end
|
||
|
end
|
||
2 years ago
|
end
|
||
|
|
||
2 years ago
|
describe "fields 7, 8, 9 => startdate" do
|
||
|
context "when any one of these fields is blank" do
|
||
|
let(:attributes) { { bulk_upload:, field_5: "1", field_7: nil, field_8: nil, field_9: nil } }
|
||
2 years ago
|
|
||
2 years ago
|
it "returns an error" do
|
||
|
parser.valid?
|
||
2 years ago
|
|
||
2 years ago
|
expect(parser.errors[:field_7]).to be_present
|
||
|
expect(parser.errors[:field_8]).to be_present
|
||
|
expect(parser.errors[:field_9]).to be_present
|
||
2 years ago
|
end
|
||
|
end
|
||
|
|
||
2 years ago
|
context "when field_9 is 4 digits instead of 2" do
|
||
|
let(:attributes) { { bulk_upload:, field_9: "2022" } }
|
||
2 years ago
|
|
||
|
it "returns an error" do
|
||
2 years ago
|
parser.valid?
|
||
|
|
||
|
expect(parser.errors[:field_9]).to include("Tenancy start year must be 2 digits")
|
||
2 years ago
|
end
|
||
|
end
|
||
|
|
||
|
context "when invalid date given" do
|
||
2 years ago
|
let(:attributes) { { bulk_upload:, field_5: "1", field_7: "a", field_8: "12", field_9: "22" } }
|
||
2 years ago
|
|
||
|
it "does not raise an error" do
|
||
|
expect { parser.valid? }.not_to raise_error
|
||
|
end
|
||
|
end
|
||
|
|
||
2 years ago
|
context "when inside of collection year" do
|
||
2 years ago
|
let(:attributes) { { bulk_upload:, field_7: "1", field_8: "10", field_9: "22" } }
|
||
2 years ago
|
|
||
|
let(:bulk_upload) { create(:bulk_upload, :lettings, user:, year: 2022) }
|
||
|
|
||
|
it "does not return errors" do
|
||
2 years ago
|
parser.valid?
|
||
|
|
||
|
expect(parser.errors[:field_7]).not_to be_present
|
||
|
expect(parser.errors[:field_8]).not_to be_present
|
||
|
expect(parser.errors[:field_9]).not_to be_present
|
||
2 years ago
|
end
|
||
|
end
|
||
|
|
||
|
context "when outside of collection year" do
|
||
|
around do |example|
|
||
|
Timecop.freeze(Date.new(2022, 4, 2)) do
|
||
|
example.run
|
||
|
end
|
||
|
end
|
||
|
|
||
2 years ago
|
let(:attributes) { { bulk_upload:, field_7: "1", field_8: "1", field_9: "22" } }
|
||
2 years ago
|
|
||
|
let(:bulk_upload) { create(:bulk_upload, :lettings, user:, year: 2022) }
|
||
|
|
||
|
it "returns errors" do
|
||
2 years ago
|
parser.valid?
|
||
2 years ago
|
|
||
2 years ago
|
expect(parser.errors[:field_7]).to be_present
|
||
|
expect(parser.errors[:field_8]).to be_present
|
||
|
expect(parser.errors[:field_9]).to be_present
|
||
2 years ago
|
end
|
||
|
end
|
||
2 years ago
|
end
|
||
2 years ago
|
|
||
2 years ago
|
describe "#field_1" do # owning org
|
||
2 years ago
|
context "when cannot find owning org" do
|
||
2 years ago
|
let(:attributes) { { bulk_upload:, field_1: "donotexist" } }
|
||
2 years ago
|
|
||
|
it "is not permitted" do
|
||
2 years ago
|
expect(parser.errors[:field_1]).to eql(["The owning organisation code is incorrect"])
|
||
2 years ago
|
end
|
||
|
end
|
||
|
|
||
|
context "when org is not stock owning" do
|
||
|
let(:owning_org) { create(:organisation, :with_old_visible_id, :does_not_own_stock) }
|
||
|
|
||
2 years ago
|
let(:attributes) { { bulk_upload:, field_1: owning_org.old_visible_id } }
|
||
2 years ago
|
|
||
|
it "is not permitted" do
|
||
2 years ago
|
expect(parser.errors[:field_1]).to eql(["The owning organisation code provided is for an organisation that does not own stock"])
|
||
2 years ago
|
end
|
||
|
|
||
|
it "blocks log creation" do
|
||
|
expect(parser).to be_block_log_creation
|
||
|
end
|
||
|
end
|
||
|
|
||
|
context "when not affiliated with owning org" do
|
||
|
let(:unaffiliated_org) { create(:organisation, :with_old_visible_id) }
|
||
|
|
||
2 years ago
|
let(:attributes) { { bulk_upload:, field_1: unaffiliated_org.old_visible_id } }
|
||
2 years ago
|
|
||
|
it "is not permitted" do
|
||
2 years ago
|
expect(parser.errors[:field_1]).to eql(["You do not have permission to add logs for this owning organisation"])
|
||
2 years ago
|
end
|
||
|
|
||
|
it "blocks log creation" do
|
||
|
expect(parser).to be_block_log_creation
|
||
|
end
|
||
|
end
|
||
|
end
|
||
|
|
||
2 years ago
|
describe "#field_2" do # managing org
|
||
2 years ago
|
context "when cannot find managing org" do
|
||
2 years ago
|
let(:attributes) { { bulk_upload:, field_2: "donotexist" } }
|
||
2 years ago
|
|
||
|
it "is not permitted" do
|
||
2 years ago
|
expect(parser.errors[:field_2]).to eql(["The managing organisation code is incorrect"])
|
||
2 years ago
|
end
|
||
|
end
|
||
|
|
||
|
context "when not affiliated with managing org" do
|
||
|
let(:unaffiliated_org) { create(:organisation, :with_old_visible_id) }
|
||
|
|
||
2 years ago
|
let(:attributes) { { bulk_upload:, field_1: owning_org.old_visible_id, field_2: unaffiliated_org.old_visible_id } }
|
||
2 years ago
|
|
||
|
it "is not permitted" do
|
||
2 years ago
|
expect(parser.errors[:field_2]).to eql(["This managing organisation does not have a relationship with the owning organisation"])
|
||
2 years ago
|
end
|
||
|
|
||
|
it "blocks log creation" do
|
||
|
expect(parser).to be_block_log_creation
|
||
|
end
|
||
|
end
|
||
|
end
|
||
|
|
||
2 years ago
|
describe "#field_4" do
|
||
|
context "when blank" do
|
||
|
let(:attributes) { { bulk_upload:, field_4: nil, field_13: "123" } }
|
||
|
|
||
|
it "is reported as a setup error" do
|
||
|
errors = parser.errors.select { |e| e.options[:category] == :setup }
|
||
|
error = errors.find { |e| e.attribute == :field_4 }
|
||
|
|
||
|
expect(error).to be_present
|
||
|
expect(error.type).to eql("You must answer needs type")
|
||
|
end
|
||
|
end
|
||
|
end
|
||
|
|
||
|
describe "#field_6" do
|
||
2 years ago
|
context "when an unpermitted value" do
|
||
2 years ago
|
let(:attributes) { { bulk_upload:, field_6: "3" } }
|
||
2 years ago
|
|
||
|
it "has errors on the field" do
|
||
2 years ago
|
expect(parser.errors[:field_6]).to be_present
|
||
2 years ago
|
end
|
||
|
end
|
||
|
end
|
||
|
|
||
2 years ago
|
describe "#field_30" do
|
||
2 years ago
|
context "when null" do
|
||
2 years ago
|
let(:attributes) { setup_section_params.merge({ field_30: nil }) }
|
||
2 years ago
|
|
||
|
it "returns an error" do
|
||
2 years ago
|
expect(parser.errors[:field_30]).to be_present
|
||
2 years ago
|
end
|
||
2 years ago
|
|
||
|
it "populates with correct error message" do
|
||
2 years ago
|
expect(parser.errors[:field_30]).to eql(["You must answer type of building"])
|
||
2 years ago
|
end
|
||
2 years ago
|
end
|
||
|
|
||
|
context "when unpermitted values" do
|
||
2 years ago
|
let(:attributes) { setup_section_params.merge({ field_30: "4" }) }
|
||
2 years ago
|
|
||
|
it "returns an error" do
|
||
2 years ago
|
expect(parser.errors[:field_30]).to be_present
|
||
2 years ago
|
end
|
||
|
end
|
||
|
end
|
||
|
end
|
||
|
|
||
|
describe "#log" do
|
||
2 years ago
|
[
|
||
2 years ago
|
%w[age1_known age1 field_46],
|
||
|
%w[age2_known age2 field_52],
|
||
|
%w[age3_known age3 field_56],
|
||
|
%w[age4_known age4 field_60],
|
||
|
%w[age5_known age5 field_64],
|
||
|
%w[age6_known age6 field_68],
|
||
|
%w[age7_known age7 field_72],
|
||
|
%w[age8_known age8 field_76],
|
||
2 years ago
|
].each do |known, age, field|
|
||
|
describe "##{known} and ##{age}" do
|
||
|
context "when #{field} is R" do
|
||
|
let(:attributes) { { bulk_upload:, field.to_s => "R" } }
|
||
|
|
||
|
it "sets ##{known} 1" do
|
||
|
expect(parser.log.public_send(known)).to be(1)
|
||
|
end
|
||
|
|
||
|
it "sets ##{age} to nil" do
|
||
|
expect(parser.log.public_send(age)).to be_nil
|
||
|
end
|
||
|
end
|
||
|
|
||
|
context "when #{field} is a number" do
|
||
|
let(:attributes) { { bulk_upload:, field.to_s => "50" } }
|
||
|
|
||
|
it "sets ##{known} to 0" do
|
||
|
expect(parser.log.public_send(known)).to be(0)
|
||
|
end
|
||
|
|
||
|
it "sets ##{age} to given age" do
|
||
|
expect(parser.log.public_send(age)).to be(50)
|
||
|
end
|
||
|
end
|
||
|
end
|
||
|
end
|
||
|
|
||
2 years ago
|
describe "#location" do
|
||
|
context "when lookup is via new core id" do
|
||
2 years ago
|
let(:attributes) { { bulk_upload:, field_16: scheme.old_visible_id, field_17: location.id, field_1: owning_org } }
|
||
2 years ago
|
|
||
|
it "assigns the correct location" do
|
||
|
expect(parser.log.location).to eql(location)
|
||
|
end
|
||
|
end
|
||
|
end
|
||
|
|
||
|
describe "#scheme" do
|
||
|
context "when lookup is via id prefixed with S" do
|
||
2 years ago
|
let(:attributes) { { bulk_upload:, field_16: "S#{scheme.id}", field_1: owning_org } }
|
||
2 years ago
|
|
||
|
it "assigns the correct scheme" do
|
||
|
expect(parser.log.scheme).to eql(scheme)
|
||
|
end
|
||
|
end
|
||
|
end
|
||
|
|
||
2 years ago
|
describe "#owning_organisation" do
|
||
|
context "when lookup is via id prefixed with ORG" do
|
||
2 years ago
|
let(:attributes) { { bulk_upload:, field_1: "ORG#{owning_org.id}" } }
|
||
2 years ago
|
|
||
|
it "assigns the correct org" do
|
||
|
expect(parser.log.owning_organisation).to eql(owning_org)
|
||
|
end
|
||
|
end
|
||
|
end
|
||
|
|
||
|
describe "#managing_organisation" do
|
||
|
context "when lookup is via id prefixed with ORG" do
|
||
2 years ago
|
let(:attributes) { { bulk_upload:, field_2: "ORG#{managing_org.id}" } }
|
||
2 years ago
|
|
||
|
it "assigns the correct org" do
|
||
|
expect(parser.log.managing_organisation).to eql(managing_org)
|
||
|
end
|
||
|
end
|
||
|
end
|
||
|
|
||
2 years ago
|
describe "#cbl" do
|
||
2 years ago
|
context "when field_116 is yes ie 1" do
|
||
|
let(:attributes) { { bulk_upload:, field_116: 1 } }
|
||
2 years ago
|
|
||
|
it "sets value to 1" do
|
||
|
expect(parser.log.cbl).to be(1)
|
||
|
end
|
||
|
end
|
||
|
|
||
2 years ago
|
context "when field_116 is no ie 2" do
|
||
|
let(:attributes) { { bulk_upload:, field_116: 2 } }
|
||
2 years ago
|
|
||
|
it "sets value to 0" do
|
||
|
expect(parser.log.cbl).to be(0)
|
||
|
end
|
||
|
end
|
||
|
end
|
||
|
|
||
|
describe "#chr" do
|
||
2 years ago
|
context "when field_118 is yes ie 1" do
|
||
|
let(:attributes) { { bulk_upload:, field_118: 1 } }
|
||
2 years ago
|
|
||
|
it "sets value to 1" do
|
||
|
expect(parser.log.chr).to be(1)
|
||
|
end
|
||
|
end
|
||
|
|
||
2 years ago
|
context "when field_118 is no ie 2" do
|
||
|
let(:attributes) { { bulk_upload:, field_118: 2 } }
|
||
2 years ago
|
|
||
|
it "sets value to 0" do
|
||
|
expect(parser.log.chr).to be(0)
|
||
|
end
|
||
|
end
|
||
|
end
|
||
|
|
||
|
describe "#cap" do
|
||
2 years ago
|
context "when field_117 is yes ie 1" do
|
||
|
let(:attributes) { { bulk_upload:, field_117: 1 } }
|
||
2 years ago
|
|
||
|
it "sets value to 1" do
|
||
|
expect(parser.log.cap).to be(1)
|
||
|
end
|
||
|
end
|
||
|
|
||
2 years ago
|
context "when field_117 is no ie 2" do
|
||
|
let(:attributes) { { bulk_upload:, field_117: 2 } }
|
||
2 years ago
|
|
||
|
it "sets value to 0" do
|
||
|
expect(parser.log.cap).to be(0)
|
||
|
end
|
||
|
end
|
||
|
end
|
||
|
|
||
|
describe "#letting_allocation_unknown" do
|
||
2 years ago
|
context "when field_116, 117, 118 are no ie 2" do
|
||
|
let(:attributes) { { bulk_upload:, field_116: 2, field_117: 2, field_118: 2 } }
|
||
2 years ago
|
|
||
|
it "sets value to 1" do
|
||
|
expect(parser.log.letting_allocation_unknown).to be(1)
|
||
|
end
|
||
|
end
|
||
|
|
||
2 years ago
|
context "when any one of field_116, 117, 118 is yes ie 1" do
|
||
|
let(:attributes) { { bulk_upload:, field_116: 1 } }
|
||
2 years ago
|
|
||
|
it "sets value to 0" do
|
||
|
expect(parser.log.letting_allocation_unknown).to be(0)
|
||
|
end
|
||
|
end
|
||
|
end
|
||
|
|
||
|
describe "#renewal" do
|
||
2 years ago
|
context "when field_6 is no ie 2" do
|
||
|
let(:attributes) { { bulk_upload:, field_6: 2 } }
|
||
2 years ago
|
|
||
|
it "sets value to 0" do
|
||
|
expect(parser.log.renewal).to eq(0)
|
||
|
end
|
||
|
end
|
||
|
|
||
2 years ago
|
context "when field_6 is null but rsnvac/field_27 is 14" do
|
||
|
let(:attributes) { { bulk_upload:, field_6: "", field_27: "14" } }
|
||
2 years ago
|
|
||
|
it "sets renewal to 1" do
|
||
|
expect(parser.log.renewal).to eq(1)
|
||
|
end
|
||
|
end
|
||
|
end
|
||
|
|
||
|
describe "#sexN fields" do
|
||
|
let(:attributes) do
|
||
|
{
|
||
|
bulk_upload:,
|
||
2 years ago
|
field_47: "F",
|
||
|
field_53: "M",
|
||
|
field_57: "X",
|
||
|
field_61: "R",
|
||
|
field_65: "F",
|
||
|
field_69: "M",
|
||
|
field_73: "X",
|
||
|
field_77: "R",
|
||
2 years ago
|
}
|
||
|
end
|
||
|
|
||
|
it "sets value from correct mapping" do
|
||
|
expect(parser.log.sex1).to eql("F")
|
||
|
expect(parser.log.sex2).to eql("M")
|
||
|
expect(parser.log.sex3).to eql("X")
|
||
|
expect(parser.log.sex4).to eql("R")
|
||
|
expect(parser.log.sex5).to eql("F")
|
||
|
expect(parser.log.sex6).to eql("M")
|
||
|
expect(parser.log.sex7).to eql("X")
|
||
|
expect(parser.log.sex8).to eql("R")
|
||
|
end
|
||
|
end
|
||
|
|
||
|
describe "#ecstatN fields" do
|
||
|
let(:attributes) do
|
||
|
{
|
||
|
bulk_upload:,
|
||
2 years ago
|
field_50: "1",
|
||
|
field_54: "2",
|
||
|
field_58: "6",
|
||
|
field_62: "7",
|
||
|
field_66: "8",
|
||
|
field_70: "9",
|
||
|
field_74: "0",
|
||
|
field_78: "10",
|
||
2 years ago
|
}
|
||
|
end
|
||
|
|
||
|
it "sets value from correct mapping", aggregate_failures: true do
|
||
|
expect(parser.log.ecstat1).to eq(1)
|
||
|
expect(parser.log.ecstat2).to eq(2)
|
||
|
expect(parser.log.ecstat3).to eq(6)
|
||
|
expect(parser.log.ecstat4).to eq(7)
|
||
|
expect(parser.log.ecstat5).to eq(8)
|
||
|
expect(parser.log.ecstat6).to eq(9)
|
||
|
expect(parser.log.ecstat7).to eq(0)
|
||
|
expect(parser.log.ecstat8).to eq(10)
|
||
|
end
|
||
|
end
|
||
|
|
||
|
describe "#relatN fields" do
|
||
|
let(:attributes) do
|
||
|
{
|
||
|
bulk_upload:,
|
||
2 years ago
|
field_51: "P",
|
||
|
field_55: "C",
|
||
|
field_59: "X",
|
||
|
field_63: "R",
|
||
|
field_67: "P",
|
||
|
field_71: "C",
|
||
|
field_75: "X",
|
||
2 years ago
|
}
|
||
|
end
|
||
|
|
||
|
it "sets value from correct mapping", aggregate_failures: true do
|
||
|
expect(parser.log.relat2).to eq("P")
|
||
|
expect(parser.log.relat3).to eq("C")
|
||
|
expect(parser.log.relat4).to eq("X")
|
||
|
expect(parser.log.relat5).to eq("R")
|
||
|
expect(parser.log.relat6).to eq("P")
|
||
|
expect(parser.log.relat7).to eq("C")
|
||
|
expect(parser.log.relat8).to eq("X")
|
||
|
end
|
||
|
end
|
||
|
|
||
|
describe "#net_income_known" do
|
||
2 years ago
|
let(:attributes) { { bulk_upload:, field_120: "1" } }
|
||
2 years ago
|
|
||
|
it "sets value from correct mapping" do
|
||
|
expect(parser.log.net_income_known).to eq(0)
|
||
|
end
|
||
|
end
|
||
|
|
||
|
describe "#unitletas" do
|
||
2 years ago
|
let(:attributes) { { bulk_upload:, field_26: "1" } }
|
||
2 years ago
|
|
||
|
it "sets value from correct mapping" do
|
||
|
expect(parser.log.unitletas).to eq(1)
|
||
|
end
|
||
|
end
|
||
|
|
||
|
describe "#rsnvac" do
|
||
2 years ago
|
let(:attributes) { { bulk_upload:, field_27: "5" } }
|
||
2 years ago
|
|
||
|
it "sets value from correct mapping" do
|
||
|
expect(parser.log.rsnvac).to eq(5)
|
||
|
end
|
||
|
end
|
||
|
|
||
|
describe "#sheltered" do
|
||
2 years ago
|
let(:attributes) { { bulk_upload:, field_44: "1" } }
|
||
2 years ago
|
|
||
|
it "sets value from correct mapping" do
|
||
|
expect(parser.log.sheltered).to eq(1)
|
||
|
end
|
||
|
end
|
||
|
|
||
|
describe "illness fields" do
|
||
|
mapping = [
|
||
2 years ago
|
{ attribute: :illness_type_1, field: :field_98 },
|
||
|
{ attribute: :illness_type_2, field: :field_92 },
|
||
|
{ attribute: :illness_type_3, field: :field_95 },
|
||
|
{ attribute: :illness_type_4, field: :field_90 },
|
||
|
{ attribute: :illness_type_5, field: :field_91 },
|
||
|
{ attribute: :illness_type_6, field: :field_93 },
|
||
|
{ attribute: :illness_type_7, field: :field_94 },
|
||
|
{ attribute: :illness_type_8, field: :field_97 },
|
||
|
{ attribute: :illness_type_9, field: :field_96 },
|
||
|
{ attribute: :illness_type_10, field: :field_99 },
|
||
2 years ago
|
]
|
||
|
|
||
|
mapping.each do |hash|
|
||
|
describe "##{hash[:attribute]}" do
|
||
|
context "when yes" do
|
||
|
let(:attributes) { { bulk_upload:, hash[:field] => "1" } }
|
||
|
|
||
|
it "sets value from correct mapping" do
|
||
|
expect(parser.log.public_send(hash[:attribute])).to eq(1)
|
||
|
end
|
||
|
end
|
||
|
|
||
|
context "when no" do
|
||
|
let(:attributes) { { bulk_upload:, hash[:field] => "" } }
|
||
|
|
||
|
it "sets value from correct mapping" do
|
||
|
expect(parser.log.public_send(hash[:attribute])).to be_nil
|
||
|
end
|
||
|
end
|
||
|
end
|
||
|
end
|
||
|
end
|
||
|
|
||
|
describe "#irproduct_other" do
|
||
2 years ago
|
let(:attributes) { { bulk_upload:, field_12: "some other product" } }
|
||
2 years ago
|
|
||
|
it "sets value to given free text string" do
|
||
|
expect(parser.log.irproduct_other).to eql("some other product")
|
||
|
end
|
||
|
end
|
||
|
|
||
|
describe "#tenancyother" do
|
||
2 years ago
|
let(:attributes) { { bulk_upload:, field_42: "some other tenancy" } }
|
||
2 years ago
|
|
||
|
it "sets value to given free text string" do
|
||
|
expect(parser.log.tenancyother).to eql("some other tenancy")
|
||
|
end
|
||
|
end
|
||
|
|
||
|
describe "#tenancylength" do
|
||
2 years ago
|
let(:attributes) { { bulk_upload:, field_43: "2" } }
|
||
2 years ago
|
|
||
|
it "sets value to given free text string" do
|
||
|
expect(parser.log.tenancylength).to eq(2)
|
||
|
end
|
||
|
end
|
||
|
|
||
|
describe "#earnings" do
|
||
2 years ago
|
let(:attributes) { { bulk_upload:, field_122: "104.50" } }
|
||
2 years ago
|
|
||
|
it "rounds to the nearest whole pound" do
|
||
|
expect(parser.log.earnings).to eq(105)
|
||
|
end
|
||
|
end
|
||
|
|
||
|
describe "#reasonother" do
|
||
2 years ago
|
let(:attributes) { { bulk_upload:, field_103: "some other reason" } }
|
||
2 years ago
|
|
||
|
it "sets value to given free text string" do
|
||
|
expect(parser.log.reasonother).to eql("some other reason")
|
||
|
end
|
||
|
end
|
||
|
|
||
|
describe "#ppcodenk" do
|
||
2 years ago
|
let(:attributes) { { bulk_upload:, field_106: "2" } }
|
||
2 years ago
|
|
||
|
it "sets correct value from mapping" do
|
||
|
expect(parser.log.ppcodenk).to eq(0)
|
||
|
end
|
||
|
end
|
||
|
|
||
|
describe "#household_charge" do
|
||
2 years ago
|
let(:attributes) { { bulk_upload:, field_125: "1" } }
|
||
2 years ago
|
|
||
|
it "sets correct value from mapping" do
|
||
|
expect(parser.log.household_charge).to eq(1)
|
||
|
end
|
||
|
end
|
||
|
|
||
|
describe "#chcharge" do
|
||
2 years ago
|
let(:attributes) { { bulk_upload:, field_127: "123.45" } }
|
||
2 years ago
|
|
||
|
it "sets value given" do
|
||
|
expect(parser.log.chcharge).to eq(123.45)
|
||
|
end
|
||
|
end
|
||
|
|
||
|
describe "#tcharge" do
|
||
2 years ago
|
let(:attributes) { { bulk_upload:, field_132: "123.45" } }
|
||
2 years ago
|
|
||
|
it "sets value given" do
|
||
|
expect(parser.log.tcharge).to eq(123.45)
|
||
|
end
|
||
|
end
|
||
|
|
||
|
describe "#supcharg" do
|
||
2 years ago
|
let(:attributes) { { bulk_upload:, field_131: "123.45" } }
|
||
2 years ago
|
|
||
|
it "sets value given" do
|
||
|
expect(parser.log.supcharg).to eq(123.45)
|
||
|
end
|
||
|
end
|
||
|
|
||
|
describe "#pscharge" do
|
||
2 years ago
|
let(:attributes) { { bulk_upload:, field_130: "123.45" } }
|
||
2 years ago
|
|
||
|
it "sets value given" do
|
||
|
expect(parser.log.pscharge).to eq(123.45)
|
||
|
end
|
||
|
end
|
||
|
|
||
|
describe "#scharge" do
|
||
2 years ago
|
let(:attributes) { { bulk_upload:, field_129: "123.45" } }
|
||
2 years ago
|
|
||
|
it "sets value given" do
|
||
|
expect(parser.log.scharge).to eq(123.45)
|
||
|
end
|
||
|
end
|
||
|
|
||
|
describe "#offered" do
|
||
2 years ago
|
let(:attributes) { { bulk_upload:, field_28: "3" } }
|
||
2 years ago
|
|
||
|
it "sets value given" do
|
||
|
expect(parser.log.offered).to eq(3)
|
||
|
end
|
||
|
end
|
||
|
|
||
|
describe "#propcode" do
|
||
2 years ago
|
let(:attributes) { { bulk_upload:, field_14: "abc123" } }
|
||
2 years ago
|
|
||
|
it "sets value given" do
|
||
|
expect(parser.log.propcode).to eq("abc123")
|
||
|
end
|
||
|
end
|
||
|
|
||
|
describe "#mrcdate" do
|
||
2 years ago
|
let(:attributes) { { bulk_upload:, field_36: "13", field_37: "12", field_38: "22" } }
|
||
2 years ago
|
|
||
|
it "sets value given" do
|
||
|
expect(parser.log.mrcdate).to eq(Date.new(2022, 12, 13))
|
||
|
end
|
||
|
end
|
||
|
|
||
|
describe "#majorrepairs" do
|
||
|
context "when mrcdate given" do
|
||
2 years ago
|
let(:attributes) { { bulk_upload:, field_36: "13", field_37: "12", field_38: "22" } }
|
||
2 years ago
|
|
||
|
it "sets #majorrepairs to 1" do
|
||
|
expect(parser.log.majorrepairs).to eq(1)
|
||
|
end
|
||
|
end
|
||
|
|
||
|
context "when mrcdate not given" do
|
||
2 years ago
|
let(:attributes) { { bulk_upload:, field_36: "", field_37: "", field_38: "" } }
|
||
2 years ago
|
|
||
|
it "sets #majorrepairs to 0" do
|
||
|
expect(parser.log.majorrepairs).to eq(0)
|
||
|
end
|
||
|
end
|
||
|
end
|
||
|
|
||
|
describe "#voiddate" do
|
||
2 years ago
|
let(:attributes) { { bulk_upload:, field_33: "13", field_34: "12", field_35: "22" } }
|
||
2 years ago
|
|
||
|
it "sets value given" do
|
||
|
expect(parser.log.voiddate).to eq(Date.new(2022, 12, 13))
|
||
|
end
|
||
|
end
|
||
|
|
||
|
describe "#startdate" do
|
||
2 years ago
|
let(:attributes) { { bulk_upload:, field_7: now.day.to_s, field_8: now.month.to_s, field_9: now.strftime("%g") } }
|
||
2 years ago
|
|
||
|
it "sets value given" do
|
||
|
expect(parser.log.startdate).to eq(now)
|
||
|
end
|
||
|
end
|
||
|
|
||
|
describe "#postcode_full" do
|
||
2 years ago
|
let(:attributes) { { bulk_upload:, field_23: " EC1N ", field_24: " 2TD " } }
|
||
2 years ago
|
|
||
|
it "strips whitespace" do
|
||
|
expect(parser.log.postcode_full).to eql("EC1N 2TD")
|
||
|
end
|
||
|
end
|
||
|
|
||
|
describe "#la" do
|
||
2 years ago
|
let(:attributes) { { bulk_upload:, field_25: "E07000223" } }
|
||
2 years ago
|
|
||
|
it "sets to given value" do
|
||
|
expect(parser.log.la).to eql("E07000223")
|
||
|
end
|
||
|
end
|
||
|
|
||
|
describe "#prevloc" do
|
||
2 years ago
|
let(:attributes) { { bulk_upload:, field_109: "E07000223" } }
|
||
2 years ago
|
|
||
|
it "sets to given value" do
|
||
|
expect(parser.log.prevloc).to eql("E07000223")
|
||
|
end
|
||
|
end
|
||
|
|
||
|
describe "#previous_la_known" do
|
||
|
context "when known" do
|
||
2 years ago
|
let(:attributes) { { bulk_upload:, field_109: "E07000223" } }
|
||
2 years ago
|
|
||
|
it "sets to 1" do
|
||
|
expect(parser.log.previous_la_known).to eq(1)
|
||
|
end
|
||
|
end
|
||
|
|
||
|
context "when not known" do
|
||
2 years ago
|
let(:attributes) { { bulk_upload:, field_109: "" } }
|
||
2 years ago
|
|
||
|
it "sets to 0" do
|
||
|
expect(parser.log.previous_la_known).to eq(0)
|
||
|
end
|
||
|
end
|
||
|
end
|
||
|
|
||
|
describe "#first_time_property_let_as_social_housing" do
|
||
2 years ago
|
context "when field_27 is 15, 16, or 17" do
|
||
|
let(:attributes) { { bulk_upload:, field_27: %w[15 16 17].sample } }
|
||
2 years ago
|
|
||
2 years ago
|
it "sets to 1" do
|
||
|
expect(parser.log.first_time_property_let_as_social_housing).to eq(1)
|
||
2 years ago
|
end
|
||
|
end
|
||
2 years ago
|
|
||
2 years ago
|
context "when field_27 is not 15, 16, or 17" do
|
||
|
let(:attributes) { { bulk_upload:, field_27: "1" } }
|
||
2 years ago
|
|
||
|
it "sets to 0" do
|
||
|
expect(parser.log.first_time_property_let_as_social_housing).to eq(0)
|
||
|
end
|
||
|
end
|
||
2 years ago
|
end
|
||
2 years ago
|
|
||
|
describe "#housingneeds" do
|
||
|
context "when no disabled needs" do
|
||
2 years ago
|
let(:attributes) { { bulk_upload:, field_87: "1" } }
|
||
2 years ago
|
|
||
|
it "sets to 2" do
|
||
|
expect(parser.log.housingneeds).to eq(2)
|
||
|
end
|
||
|
end
|
||
|
|
||
|
context "when dont know about disabled needs" do
|
||
2 years ago
|
let(:attributes) { { bulk_upload:, field_88: "1" } }
|
||
2 years ago
|
|
||
|
it "sets to 3" do
|
||
|
expect(parser.log.housingneeds).to eq(3)
|
||
|
end
|
||
|
end
|
||
|
end
|
||
|
|
||
|
describe "#housingneeds_type" do
|
||
2 years ago
|
context "when field_83 is 1" do
|
||
|
let(:attributes) { { bulk_upload:, field_83: "1" } }
|
||
2 years ago
|
|
||
|
it "set to 0" do
|
||
|
expect(parser.log.housingneeds_type).to eq(0)
|
||
|
end
|
||
|
end
|
||
|
|
||
2 years ago
|
context "when field_84 is 1" do
|
||
|
let(:attributes) { { bulk_upload:, field_84: "1" } }
|
||
2 years ago
|
|
||
|
it "set to 1" do
|
||
|
expect(parser.log.housingneeds_type).to eq(1)
|
||
|
end
|
||
|
end
|
||
|
|
||
2 years ago
|
context "when field_85 is 1" do
|
||
|
let(:attributes) { { bulk_upload:, field_85: "1" } }
|
||
2 years ago
|
|
||
|
it "set to 2" do
|
||
|
expect(parser.log.housingneeds_type).to eq(2)
|
||
|
end
|
||
|
end
|
||
|
end
|
||
|
|
||
|
describe "#housingneeds_other" do
|
||
|
context "when field_58 is 1" do
|
||
2 years ago
|
let(:attributes) { { bulk_upload:, field_86: "1" } }
|
||
2 years ago
|
|
||
|
it "sets to 1" do
|
||
|
expect(parser.log.housingneeds_other).to eq(1)
|
||
|
end
|
||
|
end
|
||
|
end
|
||
2 years ago
|
end
|
||
2 years ago
|
|
||
|
describe "#start_date" do
|
||
|
context "when year of 9 is passed to represent 2009" do
|
||
2 years ago
|
let(:attributes) { { bulk_upload:, field_7: "1", field_8: "1", field_9: "9" } }
|
||
2 years ago
|
|
||
|
it "uses the year 2009" do
|
||
|
expect(parser.send(:start_date)).to eql(Date.new(2009, 1, 1))
|
||
|
end
|
||
|
end
|
||
|
end
|
||
2 years ago
|
end
|