Browse Source

CLDC-3550 Fix rent_type 2024 BU mapping (#2501)

* Fix rent_type 2024 BU mapping

* Correct rent_type values

* Reuse rent_type mapping

* Track updated bulk uploads

* Fix test
pull/2532/head
kosiakkatrina 6 months ago committed by GitHub
parent
commit
b9f900c98e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 2
      app/models/bulk_upload.rb
  2. 15
      app/services/bulk_upload/lettings/year2024/row_parser.rb
  3. 2
      app/services/bulk_upload/sales/log_creator.rb
  4. 5
      db/migrate/20240715072421_add_rent_fix_status.rb
  5. 3
      db/schema.rb
  6. 24
      lib/tasks/correct_noint_value.rake
  7. 21
      lib/tasks/correct_rent_type_value.rake
  8. 2
      spec/factories/bulk_upload.rb
  9. 87
      spec/lib/tasks/correct_noint_value_spec.rb
  10. 256
      spec/lib/tasks/correct_rent_type_value_spec.rb
  11. 50
      spec/services/bulk_upload/lettings/year2024/row_parser_spec.rb

2
app/models/bulk_upload.rb

@ -1,6 +1,6 @@
class BulkUpload < ApplicationRecord class BulkUpload < ApplicationRecord
enum log_type: { lettings: "lettings", sales: "sales" } enum log_type: { lettings: "lettings", sales: "sales" }
enum noint_fix_status: { not_applied: "not_applied", applied: "applied", not_needed: "not_needed" } enum rent_type_fix_status: { not_applied: "not_applied", applied: "applied", not_needed: "not_needed" }
belongs_to :user belongs_to :user

15
app/services/bulk_upload/lettings/year2024/row_parser.rb

@ -12,7 +12,7 @@ class BulkUpload::Lettings::Year2024::RowParser
field_8: "What is the tenancy start date?", field_8: "What is the tenancy start date?",
field_9: "What is the tenancy start date?", field_9: "What is the tenancy start date?",
field_10: "What is the tenancy start date?", field_10: "What is the tenancy start date?",
field_11: "Is this a London Affordable Rent letting?", field_11: "What is the rent type?",
field_12: "Which 'Other' type of Intermediate Rent is this letting?", field_12: "Which 'Other' type of Intermediate Rent is this letting?",
field_13: "What is the tenant code?", field_13: "What is the tenant code?",
field_14: "What is the property reference?", field_14: "What is the property reference?",
@ -136,6 +136,15 @@ class BulkUpload::Lettings::Year2024::RowParser
field_130: "What do you expect the outstanding amount to be?", field_130: "What do you expect the outstanding amount to be?",
}.freeze }.freeze
RENT_TYPE_BU_MAPPING = {
1 => 0,
2 => 1,
3 => 2,
4 => 3,
5 => 4,
6 => 5,
}.freeze
attribute :bulk_upload attribute :bulk_upload
attribute :block_log_creation, :boolean, default: -> { false } attribute :block_log_creation, :boolean, default: -> { false }
@ -280,7 +289,7 @@ class BulkUpload::Lettings::Year2024::RowParser
category: :setup, category: :setup,
}, },
inclusion: { inclusion: {
in: (0..5).to_a, in: (1..6).to_a,
message: I18n.t("validations.invalid_option", question: "rent type"), message: I18n.t("validations.invalid_option", question: "rent type"),
unless: -> { field_11.blank? }, unless: -> { field_11.blank? },
category: :setup, category: :setup,
@ -1134,7 +1143,7 @@ private
attributes["assigned_to"] = assigned_to || bulk_upload.user attributes["assigned_to"] = assigned_to || bulk_upload.user
attributes["created_by"] = bulk_upload.user attributes["created_by"] = bulk_upload.user
attributes["needstype"] = field_4 attributes["needstype"] = field_4
attributes["rent_type"] = field_11 attributes["rent_type"] = RENT_TYPE_BU_MAPPING[field_11]
attributes["startdate"] = startdate attributes["startdate"] = startdate
attributes["unittype_gn"] = field_26 attributes["unittype_gn"] = field_26
attributes["builtype"] = field_27 attributes["builtype"] = field_27

2
app/services/bulk_upload/sales/log_creator.rb

@ -7,7 +7,7 @@ class BulkUpload::Sales::LogCreator
end end
def call def call
@bulk_upload.update!(noint_fix_status: BulkUpload.noint_fix_statuses[:not_needed]) @bulk_upload.update!(rent_type_fix_status: BulkUpload.rent_type_fix_statuses[:not_needed])
row_parsers.each do |row_parser| row_parsers.each do |row_parser|
row_parser.valid? row_parser.valid?

5
db/migrate/20240715072421_add_rent_fix_status.rb

@ -0,0 +1,5 @@
class AddRentFixStatus < ActiveRecord::Migration[7.0]
def change
add_column :bulk_uploads, :rent_type_fix_status, :string, default: "not_applied"
end
end

3
db/schema.rb

@ -10,7 +10,7 @@
# #
# It's strongly recommended that you check this file into your version control system. # It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema[7.0].define(version: 2024_06_10_142812) do ActiveRecord::Schema[7.0].define(version: 2024_07_15_072421) do
# These are extensions that must be enabled in order to support this database # These are extensions that must be enabled in order to support this database
enable_extension "plpgsql" enable_extension "plpgsql"
@ -42,6 +42,7 @@ ActiveRecord::Schema[7.0].define(version: 2024_06_10_142812) do
t.text "choice" t.text "choice"
t.integer "total_logs_count" t.integer "total_logs_count"
t.string "noint_fix_status", default: "not_applied" t.string "noint_fix_status", default: "not_applied"
t.string "rent_type_fix_status", default: "not_applied"
t.index ["identifier"], name: "index_bulk_uploads_on_identifier", unique: true t.index ["identifier"], name: "index_bulk_uploads_on_identifier", unique: true
t.index ["user_id"], name: "index_bulk_uploads_on_user_id" t.index ["user_id"], name: "index_bulk_uploads_on_user_id"
end end

24
lib/tasks/correct_noint_value.rake

@ -1,24 +0,0 @@
desc "Alter noint values for bulk uploaded sales logs where these have not been set in the service"
task correct_noint_value: :environment do
update_counts = {
in_progress: 0,
completed: 0,
pending: 0,
deleted: 0,
}
affected_uploads = BulkUpload.where(log_type: "sales", noint_fix_status: BulkUpload.noint_fix_statuses[:not_applied])
affected_uploads.each do |upload|
upload.logs.where(noint: 2).each do |log|
noint_at_upload = log.versions.length == 1 ? log.noint : log.versions.first.next.reify.noint
next unless noint_at_upload == 2
Rails.logger.info("Updating noint value on log #{log.id}, owning org #{log.owning_organisation_id}")
update_counts[log.status.to_sym] += 1
log.noint = 1
log.skip_update_status = true
log.save!
end
upload.update!(noint_fix_status: BulkUpload.noint_fix_statuses[:applied])
end
Rails.logger.info("Logs updated; #{update_counts}")
end

21
lib/tasks/correct_rent_type_value.rake

@ -0,0 +1,21 @@
desc "Alter rent_type values for bulk uploaded lettings logs for 2024 where they were not mapped correctly"
task correct_rent_type_value: :environment do
affected_uploads = BulkUpload.where(log_type: "lettings", year: 2024, rent_type_fix_status: BulkUpload.rent_type_fix_statuses[:not_applied])
affected_uploads.each do |upload|
upload.logs.where.not(rent_type: nil).each do |log|
current_rent_type = log.rent_type
rent_type_at_upload = log.versions.length == 1 ? log.rent_type : log.versions.first.next.reify.rent_type
next unless rent_type_at_upload == current_rent_type
new_rent_type_value = BulkUpload::Lettings::Year2024::RowParser::RENT_TYPE_BU_MAPPING[rent_type_at_upload]
log.rent_type = new_rent_type_value
log.skip_update_status = true if log.status == "pending"
if log.save
Rails.logger.info("Log #{log.id} rent_type updated from #{rent_type_at_upload} to #{log.rent_type}")
else
Rails.logger.error("Log #{log.id} rent_type could not be updated from #{rent_type_at_upload} to #{log.rent_type}. Error: #{log.errors.full_messages.join(', ')}")
end
end
upload.update!(rent_type_fix_status: BulkUpload.rent_type_fix_statuses[:applied])
end
end

2
spec/factories/bulk_upload.rb

@ -8,7 +8,7 @@ FactoryBot.define do
identifier { SecureRandom.uuid } identifier { SecureRandom.uuid }
sequence(:filename) { |n| "bulk-upload-#{n}.csv" } sequence(:filename) { |n| "bulk-upload-#{n}.csv" }
needstype { 1 } needstype { 1 }
noint_fix_status { BulkUpload.noint_fix_statuses.values.sample } rent_type_fix_status { BulkUpload.rent_type_fix_statuses.values.sample }
trait(:sales) do trait(:sales) do
log_type { BulkUpload.log_types[:sales] } log_type { BulkUpload.log_types[:sales] }

87
spec/lib/tasks/correct_noint_value_spec.rb

@ -1,87 +0,0 @@
require "rails_helper"
require "rake"
RSpec.describe "correct_noint_value" do
describe ":correct_noint_value", type: :task do
subject(:task) { Rake::Task["correct_noint_value"] }
before do
Rake.application.rake_require("tasks/correct_noint_value")
Rake::Task.define_task(:environment)
task.reenable
end
context "when the rake task is run" do
context "and there is a sales bulk upload with the fix needed" do
let(:bulk_upload) { create(:bulk_upload, :sales, noint_fix_status: BulkUpload.noint_fix_statuses[:not_applied]) }
before do
bulk_upload.save!
end
it "updates the noint value on a log with noint = 2 where it was set to 2 on create" do
log = create(:sales_log, :completed, noint: 2, bulk_upload:)
task.invoke
log.reload
expect(log.noint).to be(1)
end
it "updates the noint value on a log with noint = 2 where it was set to 2 on create and other fields have since changed" do
log = create(:sales_log, :in_progress, noint: 2, bulk_upload:)
log.update!(status: Log.statuses[:completed])
task.invoke
log.reload
expect(log.noint).to be(1)
end
it "does not update the noint value on a log that has noint = 1" do
log = create(:sales_log, :completed, noint: 2, bulk_upload:)
log.update!(noint: 1)
task.invoke
log.reload
expect(log.noint).to be(1)
end
it "does not update the noint value on a log with noint = 2 where noint was nil on create" do
log = create(:sales_log, :completed, noint: nil, bulk_upload:)
log.update!(noint: 2)
task.invoke
log.reload
expect(log.noint).to be(2)
end
it "updates the noint_fix_status value on the bulk upload" do
task.invoke
bulk_upload.reload
expect(bulk_upload.noint_fix_status).to eq(BulkUpload.noint_fix_statuses[:applied])
end
end
context "and there is a sales bulk upload with the fix marked as not needed" do
let(:bulk_upload) { create(:bulk_upload, :sales, noint_fix_status: BulkUpload.noint_fix_statuses[:not_needed]) }
before do
bulk_upload.save!
end
it "does not update the noint values on logs" do
log = create(:sales_log, :completed, noint: 2, bulk_upload:)
task.invoke
log.reload
expect(log.noint).to be(2)
end
end
end
end
end

256
spec/lib/tasks/correct_rent_type_value_spec.rb

@ -0,0 +1,256 @@
require "rails_helper"
require "rake"
RSpec.describe "correct_rent_type_value" do
describe ":correct_rent_type_value", type: :task do
subject(:task) { Rake::Task["correct_rent_type_value"] }
before do
Rake.application.rake_require("tasks/correct_rent_type_value")
Rake::Task.define_task(:environment)
task.reenable
end
context "when the rake task is run" do
context "and rent_type is 1" do
let(:bulk_upload) { create(:bulk_upload, :lettings, year: 2024, rent_type_fix_status: BulkUpload.rent_type_fix_statuses[:not_applied]) }
let(:bulk_upload_2023) { create(:bulk_upload, :lettings, year: 2023, rent_type_fix_status: BulkUpload.rent_type_fix_statuses[:not_applied]) }
before do
bulk_upload.save!
end
it "updates the rent_type value on a log where it was set to 1 on create" do
log = create(:lettings_log, :completed, rent_type: 1, bulk_upload:)
initial_updated_at = log.updated_at
task.invoke
log.reload
expect(log.rent_type).to be(0)
expect(log.status).to eq("completed")
expect(log.updated_at).not_to eq(initial_updated_at)
expect(bulk_upload.reload.rent_type_fix_status).to eq(BulkUpload.rent_type_fix_statuses[:applied])
end
it "updates the rent_type value on a pending log where it was set to 1 on create" do
log = build(:lettings_log, :completed, rent_type: 1, bulk_upload:, status: "pending")
log.skip_update_status = true
log.save!
initial_updated_at = log.updated_at
expect(log.status).to eq("pending")
task.invoke
log.reload
expect(log.rent_type).to be(0)
expect(log.status).to eq("pending")
expect(log.updated_at).not_to eq(initial_updated_at)
expect(bulk_upload.reload.rent_type_fix_status).to eq(BulkUpload.rent_type_fix_statuses[:applied])
end
it "updates the rent_type value on a deleted log where it was set to 1 on create" do
log = create(:lettings_log, :completed, rent_type: 1, bulk_upload:, discarded_at: Time.zone.yesterday)
initial_updated_at = log.updated_at
expect(log.status).to eq("deleted")
task.invoke
log.reload
expect(log.rent_type).to be(0)
expect(log.status).to eq("deleted")
expect(log.updated_at).not_to eq(initial_updated_at)
expect(bulk_upload.reload.rent_type_fix_status).to eq(BulkUpload.rent_type_fix_statuses[:applied])
end
it "updates the rent_type value on a log where it was set to 1 on create and other fields have since changed" do
log = create(:lettings_log, :completed, rent_type: 1, bulk_upload:)
log.update!(tenancycode: "abc")
initial_updated_at = log.updated_at
task.invoke
log.reload
expect(log.rent_type).to be(0)
expect(log.status).to eq("completed")
expect(log.updated_at).not_to eq(initial_updated_at)
expect(bulk_upload.reload.rent_type_fix_status).to eq(BulkUpload.rent_type_fix_statuses[:applied])
end
it "does not update the rent_type value on a log if it has since been changed" do
log = create(:lettings_log, :completed, rent_type: 1, bulk_upload:)
log.update!(rent_type: 0)
initial_updated_at = log.updated_at
task.invoke
log.reload
expect(log.rent_type).to be(0)
expect(log.status).to eq("completed")
expect(log.updated_at).to eq(initial_updated_at)
end
it "does not update the rent_type value on a 2023 log turned 2024" do
log = build(:lettings_log, :completed, startdate: Time.zone.local(2023, 6, 6), rent_type: 1, bulk_upload: bulk_upload_2023)
log.save!(validate: false)
log.address_line1_input = log.address_line1
log.postcode_full_input = log.postcode_full
log.nationality_all_group = 826
log.uprn = "10033558653"
log.uprn_selection = 1
log.startdate = Time.zone.today
log.save!
initial_updated_at = log.updated_at
task.invoke
log.reload
expect(log.rent_type).to be(1)
expect(log.updated_at).to eq(initial_updated_at)
end
it "does not update and logs error if a validation triggers" do
log = build(:lettings_log, :completed, startdate: Time.zone.local(2021, 6, 6), rent_type: 1, bulk_upload:)
log.save!(validate: false)
initial_updated_at = log.updated_at
expect(Rails.logger).to receive(:error).with(/Log #{log.id} rent_type could not be updated from 1 to 0. Error: /)
task.invoke
log.reload
expect(log.rent_type).to be(1)
expect(log.updated_at).to eq(initial_updated_at)
end
context "when the rent_type_fix_status is not_needed" do
let(:bulk_upload) { create(:bulk_upload, :lettings, year: 2024, rent_type_fix_status: BulkUpload.rent_type_fix_statuses[:not_needed]) }
before do
bulk_upload.save!
end
it "does not update the rent_type values on logs" do
log = create(:lettings_log, :completed, rent_type: 1, bulk_upload:)
initial_updated_at = log.updated_at
task.invoke
log.reload
expect(log.rent_type).to be(1)
expect(log.updated_at).to eq(initial_updated_at)
expect(bulk_upload.reload.rent_type_fix_status).to eq(BulkUpload.rent_type_fix_statuses[:not_needed])
end
end
end
context "and rent_type is 2" do
let(:bulk_upload) { create(:bulk_upload, :lettings, year: 2024, rent_type_fix_status: BulkUpload.rent_type_fix_statuses[:not_applied]) }
let(:bulk_upload_2023) { create(:bulk_upload, :lettings, year: 2023, rent_type_fix_status: BulkUpload.rent_type_fix_statuses[:not_applied]) }
before do
bulk_upload.save!
end
it "updates the rent_type value on a log where it was set to 2 on create" do
log = create(:lettings_log, :completed, rent_type: 2, bulk_upload:)
initial_updated_at = log.updated_at
task.invoke
log.reload
expect(log.rent_type).to be(1)
expect(log.status).to eq("completed")
expect(log.updated_at).not_to eq(initial_updated_at)
end
it "updates the rent_type value on a pending log where it was set to 2 on create" do
log = build(:lettings_log, :completed, rent_type: 2, bulk_upload:, status: "pending")
log.skip_update_status = true
log.save!
initial_updated_at = log.updated_at
expect(log.status).to eq("pending")
task.invoke
log.reload
expect(log.rent_type).to be(1)
expect(log.status).to eq("pending")
expect(log.updated_at).not_to eq(initial_updated_at)
end
it "updates the rent_type value on a deleted log where it was set to 2 on create" do
log = create(:lettings_log, :completed, rent_type: 2, bulk_upload:, discarded_at: Time.zone.yesterday)
initial_updated_at = log.updated_at
expect(log.status).to eq("deleted")
task.invoke
log.reload
expect(log.rent_type).to be(1)
expect(log.status).to eq("deleted")
expect(log.updated_at).not_to eq(initial_updated_at)
end
it "updates the rent_type value on a log where it was set to 2 on create and other fields have since changed" do
log = create(:lettings_log, :completed, rent_type: 2, bulk_upload:)
log.update!(tenancycode: "abc")
initial_updated_at = log.updated_at
task.invoke
log.reload
expect(log.rent_type).to be(1)
expect(log.status).to eq("completed")
expect(log.updated_at).not_to eq(initial_updated_at)
end
it "does not update the rent_type value on a log if it has since been changed" do
log = create(:lettings_log, :completed, rent_type: 2, bulk_upload:)
log.update!(rent_type: 0)
initial_updated_at = log.updated_at
task.invoke
log.reload
expect(log.rent_type).to be(0)
expect(log.status).to eq("completed")
expect(log.updated_at).to eq(initial_updated_at)
end
it "does not update the rent_type value on a 2023 log turned 2024" do
log = build(:lettings_log, :completed, startdate: Time.zone.local(2023, 6, 6), rent_type: 2, bulk_upload: bulk_upload_2023)
log.save!(validate: false)
log.address_line1_input = log.address_line1
log.postcode_full_input = log.postcode_full
log.nationality_all_group = 826
log.uprn = "10033558653"
log.uprn_selection = 1
log.startdate = Time.zone.today
log.save!
initial_updated_at = log.updated_at
task.invoke
log.reload
expect(log.rent_type).to be(2)
expect(log.updated_at).to eq(initial_updated_at)
end
it "does not update and logs error if a validation triggers" do
log = build(:lettings_log, :completed, startdate: Time.zone.local(2021, 6, 6), rent_type: 2, bulk_upload:)
log.save!(validate: false)
initial_updated_at = log.updated_at
expect(Rails.logger).to receive(:error).with(/Log #{log.id} rent_type could not be updated from 2 to 1. Error: /)
task.invoke
log.reload
expect(log.rent_type).to be(2)
expect(log.updated_at).to eq(initial_updated_at)
end
end
end
end
end

50
spec/services/bulk_upload/lettings/year2024/row_parser_spec.rb

@ -24,7 +24,7 @@ RSpec.describe BulkUpload::Lettings::Year2024::RowParser do
field_8: now.day.to_s, field_8: now.day.to_s,
field_9: now.month.to_s, field_9: now.month.to_s,
field_10: now.strftime("%g"), field_10: now.strftime("%g"),
field_11: "0", field_11: "1",
field_15: "1", field_15: "1",
} }
end end
@ -136,7 +136,7 @@ RSpec.describe BulkUpload::Lettings::Year2024::RowParser do
field_22: "2TD", field_22: "2TD",
field_1: owning_org.old_visible_id, field_1: owning_org.old_visible_id,
field_2: managing_org.old_visible_id, field_2: managing_org.old_visible_id,
field_11: "0", field_11: "1",
field_7: "2", field_7: "2",
field_26: "2", field_26: "2",
field_27: "1", field_27: "1",
@ -412,7 +412,7 @@ RSpec.describe BulkUpload::Lettings::Year2024::RowParser do
let(:attributes) do let(:attributes) do
valid_attributes.merge({ field_5: "S#{scheme.id}", valid_attributes.merge({ field_5: "S#{scheme.id}",
field_4: "2", field_4: "2",
field_11: "1", field_11: "2",
field_6: location.old_visible_id, field_6: location.old_visible_id,
field_1: owning_org.old_visible_id, field_1: owning_org.old_visible_id,
field_122: 0, field_122: 0,
@ -461,7 +461,7 @@ RSpec.describe BulkUpload::Lettings::Year2024::RowParser do
let(:attributes) do let(:attributes) do
valid_attributes.merge({ field_5: "S#{scheme.id}", valid_attributes.merge({ field_5: "S#{scheme.id}",
field_4: "2", field_4: "2",
field_11: "1", field_11: "2",
field_6: location.old_visible_id, field_6: location.old_visible_id,
field_1: owning_org.old_visible_id, field_1: owning_org.old_visible_id,
field_122: 0, field_122: 0,
@ -471,7 +471,7 @@ RSpec.describe BulkUpload::Lettings::Year2024::RowParser do
let(:attributes_too) do let(:attributes_too) do
valid_attributes.merge({ field_5: "S#{scheme.id}", valid_attributes.merge({ field_5: "S#{scheme.id}",
field_4: "2", field_4: "2",
field_11: "1", field_11: "2",
field_6: location.old_visible_id, field_6: location.old_visible_id,
field_1: owning_org.old_visible_id, field_1: owning_org.old_visible_id,
field_122: 0, field_122: 0,
@ -554,7 +554,7 @@ RSpec.describe BulkUpload::Lettings::Year2024::RowParser do
let(:attributes) do let(:attributes) do
valid_attributes.merge({ field_5: "S#{scheme.id}", valid_attributes.merge({ field_5: "S#{scheme.id}",
field_4: "2", field_4: "2",
field_11: "1", field_11: "2",
field_6: location.id, field_6: location.id,
field_1: owning_org.old_visible_id, field_1: owning_org.old_visible_id,
field_122: 0, field_122: 0,
@ -603,7 +603,7 @@ RSpec.describe BulkUpload::Lettings::Year2024::RowParser do
let(:attributes) do let(:attributes) do
valid_attributes.merge({ field_5: "S#{scheme.id}", valid_attributes.merge({ field_5: "S#{scheme.id}",
field_4: "2", field_4: "2",
field_11: "1", field_11: "2",
field_6: location.id, field_6: location.id,
field_1: owning_org.old_visible_id, field_1: owning_org.old_visible_id,
field_122: 0, field_122: 0,
@ -613,7 +613,7 @@ RSpec.describe BulkUpload::Lettings::Year2024::RowParser do
let(:attributes_too) do let(:attributes_too) do
valid_attributes.merge({ field_5: "S#{scheme.id}", valid_attributes.merge({ field_5: "S#{scheme.id}",
field_4: "2", field_4: "2",
field_11: "1", field_11: "2",
field_6: location.id, field_6: location.id,
field_1: owning_org.old_visible_id, field_1: owning_org.old_visible_id,
field_122: 0, field_122: 0,
@ -665,7 +665,7 @@ RSpec.describe BulkUpload::Lettings::Year2024::RowParser do
field_123: 1, field_123: 1,
field_29: 1, field_29: 1,
field_4: 1, field_4: 1,
field_11: "1", field_11: "2",
field_23: "E09000008" }) field_23: "E09000008" })
end end
@ -712,7 +712,7 @@ RSpec.describe BulkUpload::Lettings::Year2024::RowParser do
allow(FeatureToggle).to receive(:bulk_upload_duplicate_log_check_enabled?).and_return(true) allow(FeatureToggle).to receive(:bulk_upload_duplicate_log_check_enabled?).and_return(true)
end end
let(:attributes) { valid_attributes.merge(field_11: "0.00") } let(:attributes) { valid_attributes.merge(field_11: "1.00") }
it "returns true" do it "returns true" do
expect(parser).to be_valid expect(parser).to be_valid
@ -724,7 +724,7 @@ RSpec.describe BulkUpload::Lettings::Year2024::RowParser do
allow(FeatureToggle).to receive(:bulk_upload_duplicate_log_check_enabled?).and_return(true) allow(FeatureToggle).to receive(:bulk_upload_duplicate_log_check_enabled?).and_return(true)
end end
let(:attributes) { valid_attributes.merge(field_11: "0.56") } let(:attributes) { valid_attributes.merge(field_11: "1.56") }
it "returns false" do it "returns false" do
expect(parser).not_to be_valid expect(parser).not_to be_valid
@ -872,7 +872,7 @@ RSpec.describe BulkUpload::Lettings::Year2024::RowParser do
describe "#field_5, field_6" do # scheme and location fields describe "#field_5, field_6" do # scheme and location fields
context "when nullable not permitted" do context "when nullable not permitted" do
let(:attributes) { { bulk_upload:, field_4: "2", field_11: "1", field_5: nil, field_6: nil } } let(:attributes) { { bulk_upload:, field_4: "2", field_11: "2", field_5: nil, field_6: nil } }
it "cannot be nulled" do it "cannot be nulled" do
parser.valid? parser.valid?
@ -882,7 +882,7 @@ RSpec.describe BulkUpload::Lettings::Year2024::RowParser do
end end
context "when nullable permitted" do context "when nullable permitted" do
let(:attributes) { { bulk_upload:, field_4: "1", field_11: "0", field_5: nil, field_6: nil } } let(:attributes) { { bulk_upload:, field_4: "1", field_11: "1", field_5: nil, field_6: nil } }
it "can be nulled" do it "can be nulled" do
parser.valid? parser.valid?
@ -900,7 +900,7 @@ RSpec.describe BulkUpload::Lettings::Year2024::RowParser do
end end
context "when matching scheme cannot be found" do context "when matching scheme cannot be found" do
let(:attributes) { { bulk_upload:, field_1: owning_org.old_visible_id, field_2: owning_org.old_visible_id, field_4: "2", field_11: "1", field_5: "S123", field_6: location.id } } let(:attributes) { { bulk_upload:, field_1: owning_org.old_visible_id, field_2: owning_org.old_visible_id, field_4: "2", field_11: "2", field_5: "S123", field_6: location.id } }
it "returns a setup error" do it "returns a setup error" do
expect(parser.errors.where(:field_5, category: :setup).map(&:message)).to eq(["This scheme code does not belong to the owning organisation or managing organisation"]) expect(parser.errors.where(:field_5, category: :setup).map(&:message)).to eq(["This scheme code does not belong to the owning organisation or managing organisation"])
@ -909,7 +909,7 @@ RSpec.describe BulkUpload::Lettings::Year2024::RowParser do
end end
context "when missing location" do context "when missing location" do
let(:attributes) { { bulk_upload:, field_1: owning_org.old_visible_id, field_2: owning_org.old_visible_id, field_4: "2", field_11: "1", field_5: "S#{scheme.id}", field_6: nil } } let(:attributes) { { bulk_upload:, field_1: owning_org.old_visible_id, field_2: owning_org.old_visible_id, field_4: "2", field_11: "2", field_5: "S#{scheme.id}", field_6: nil } }
it "returns a setup error" do it "returns a setup error" do
expect(parser.errors[:field_5]).to be_blank expect(parser.errors[:field_5]).to be_blank
@ -919,7 +919,7 @@ RSpec.describe BulkUpload::Lettings::Year2024::RowParser do
end end
context "when matching location cannot be found" do context "when matching location cannot be found" do
let(:attributes) { { bulk_upload:, field_1: owning_org.old_visible_id, field_2: owning_org.old_visible_id, field_4: "2", field_11: "1", field_5: "S#{scheme.id}", field_6: "123" } } let(:attributes) { { bulk_upload:, field_1: owning_org.old_visible_id, field_2: owning_org.old_visible_id, field_4: "2", field_11: "2", field_5: "S#{scheme.id}", field_6: "123" } }
it "returns a setup error" do it "returns a setup error" do
expect(parser.errors[:field_5]).to be_blank expect(parser.errors[:field_5]).to be_blank
@ -928,7 +928,7 @@ RSpec.describe BulkUpload::Lettings::Year2024::RowParser do
end end
context "when matching location exists" do context "when matching location exists" do
let(:attributes) { { bulk_upload:, field_1: owning_org.old_visible_id, field_2: owning_org.old_visible_id, field_4: "2", field_11: "1", field_5: "S#{scheme.id}", field_6: location.id } } let(:attributes) { { bulk_upload:, field_1: owning_org.old_visible_id, field_2: owning_org.old_visible_id, field_4: "2", field_11: "2", field_5: "S#{scheme.id}", field_6: location.id } }
it "does not return an error" do it "does not return an error" do
expect(parser.errors[:field_5]).to be_blank expect(parser.errors[:field_5]).to be_blank
@ -948,7 +948,7 @@ RSpec.describe BulkUpload::Lettings::Year2024::RowParser do
context "when location exists but not related" do context "when location exists but not related" do
let(:other_scheme) { create(:scheme, :with_old_visible_id) } let(:other_scheme) { create(:scheme, :with_old_visible_id) }
let(:other_location) { create(:location, :with_old_visible_id, scheme: other_scheme) } let(:other_location) { create(:location, :with_old_visible_id, scheme: other_scheme) }
let(:attributes) { { bulk_upload:, field_1: owning_org.old_visible_id, field_2: owning_org.old_visible_id, field_4: "2", field_11: "1", field_5: "S#{scheme.id}", field_6: other_location.id } } let(:attributes) { { bulk_upload:, field_1: owning_org.old_visible_id, field_2: owning_org.old_visible_id, field_4: "2", field_11: "2", field_5: "S#{scheme.id}", field_6: other_location.id } }
it "returns a setup error" do it "returns a setup error" do
expect(parser.errors[:field_5]).to be_blank expect(parser.errors[:field_5]).to be_blank
@ -959,7 +959,7 @@ RSpec.describe BulkUpload::Lettings::Year2024::RowParser do
context "when scheme belongs to someone else" do context "when scheme belongs to someone else" do
let(:other_scheme) { create(:scheme, :with_old_visible_id) } let(:other_scheme) { create(:scheme, :with_old_visible_id) }
let(:other_location) { create(:location, :with_old_visible_id, scheme: other_scheme) } let(:other_location) { create(:location, :with_old_visible_id, scheme: other_scheme) }
let(:attributes) { { bulk_upload:, field_4: "2", field_11: "1", field_5: "S#{other_scheme.id}", field_6: other_location.id, field_1: owning_org.old_visible_id, field_2: owning_org.old_visible_id } } let(:attributes) { { bulk_upload:, field_4: "2", field_11: "2", field_5: "S#{other_scheme.id}", field_6: other_location.id, field_1: owning_org.old_visible_id, field_2: owning_org.old_visible_id } }
it "returns a setup error" do it "returns a setup error" do
expect(parser.errors.where(:field_5, category: :setup).map(&:message)).to eq(["This scheme code does not belong to the owning organisation or managing organisation"]) expect(parser.errors.where(:field_5, category: :setup).map(&:message)).to eq(["This scheme code does not belong to the owning organisation or managing organisation"])
@ -968,7 +968,7 @@ RSpec.describe BulkUpload::Lettings::Year2024::RowParser do
end end
context "when scheme belongs to owning org" do context "when scheme belongs to owning org" do
let(:attributes) { { bulk_upload:, field_4: "2", field_11: "1", field_5: "S#{scheme.id}", field_6: location.id, field_1: owning_org.old_visible_id, field_2: owning_org.old_visible_id } } let(:attributes) { { bulk_upload:, field_4: "2", field_11: "2", field_5: "S#{scheme.id}", field_6: location.id, field_1: owning_org.old_visible_id, field_2: owning_org.old_visible_id } }
it "does not return an error" do it "does not return an error" do
expect(parser.errors[:field_5]).to be_blank expect(parser.errors[:field_5]).to be_blank
@ -979,7 +979,7 @@ RSpec.describe BulkUpload::Lettings::Year2024::RowParser do
context "when scheme belongs to managing org" do context "when scheme belongs to managing org" do
let(:managing_org_scheme) { create(:scheme, :with_old_visible_id, owning_organisation: managing_org) } let(:managing_org_scheme) { create(:scheme, :with_old_visible_id, owning_organisation: managing_org) }
let(:managing_org_location) { create(:location, :with_old_visible_id, scheme: managing_org_scheme) } let(:managing_org_location) { create(:location, :with_old_visible_id, scheme: managing_org_scheme) }
let(:attributes) { { bulk_upload:, field_4: "2", field_11: "1", field_5: "S#{managing_org_scheme.id}", field_6: managing_org_location.id, field_2: managing_org.old_visible_id } } let(:attributes) { { bulk_upload:, field_4: "2", field_11: "2", field_5: "S#{managing_org_scheme.id}", field_6: managing_org_location.id, field_2: managing_org.old_visible_id } }
it "clears the scheme answer" do it "clears the scheme answer" do
expect(parser.errors[:field_5]).to include("You must answer scheme name") expect(parser.errors[:field_5]).to include("You must answer scheme name")
@ -989,7 +989,7 @@ RSpec.describe BulkUpload::Lettings::Year2024::RowParser do
context "when matching location exists but is incomplete" do context "when matching location exists but is incomplete" do
let(:incomplete_location) { create(:location, :with_old_visible_id, :incomplete, scheme:) } let(:incomplete_location) { create(:location, :with_old_visible_id, :incomplete, scheme:) }
let(:attributes) { { bulk_upload:, field_1: owning_org.old_visible_id, field_2: owning_org.old_visible_id, field_4: "2", field_11: "1", field_5: "S#{scheme.id}", field_6: incomplete_location.id } } let(:attributes) { { bulk_upload:, field_1: owning_org.old_visible_id, field_2: owning_org.old_visible_id, field_4: "2", field_11: "2", field_5: "S#{scheme.id}", field_6: incomplete_location.id } }
it "returns a setup error for scheme" do it "returns a setup error for scheme" do
expect(parser.errors.where(:field_5).map(&:message)).to eq(["This location is incomplete. Select another location or update this one"]) expect(parser.errors.where(:field_5).map(&:message)).to eq(["This location is incomplete. Select another location or update this one"])
@ -1253,7 +1253,7 @@ RSpec.describe BulkUpload::Lettings::Year2024::RowParser do
describe "fields 7, 8, 9 => startdate" do describe "fields 7, 8, 9 => startdate" do
context "when any one of these fields is blank" do context "when any one of these fields is blank" do
let(:attributes) { { bulk_upload:, field_11: "0", field_8: nil, field_9: nil, field_10: nil } } let(:attributes) { { bulk_upload:, field_11: "1", field_8: nil, field_9: nil, field_10: nil } }
it "returns an error" do it "returns an error" do
parser.valid? parser.valid?
@ -1273,7 +1273,7 @@ RSpec.describe BulkUpload::Lettings::Year2024::RowParser do
end end
context "when invalid date given" do context "when invalid date given" do
let(:attributes) { { bulk_upload:, field_11: "0", field_8: "a", field_9: "12", field_10: "23" } } let(:attributes) { { bulk_upload:, field_11: "1", field_8: "a", field_9: "12", field_10: "23" } }
it "does not raise an error" do it "does not raise an error" do
expect { parser.valid? }.not_to raise_error expect { parser.valid? }.not_to raise_error
@ -1817,7 +1817,7 @@ RSpec.describe BulkUpload::Lettings::Year2024::RowParser do
end end
context "when soft validation is triggered and not required" do context "when soft validation is triggered and not required" do
let(:attributes) { setup_section_params.merge({ field_125: 120, field_126: 120, field_127: 120, field_128: 120, field_123: 1, field_29: 1, field_4: 1, field_11: "1", field_23: "E09000008" }) } let(:attributes) { setup_section_params.merge({ field_125: 120, field_126: 120, field_127: 120, field_128: 120, field_123: 1, field_29: 1, field_4: 1, field_11: "2", field_23: "E09000008" }) }
it "adds an error to the relevant fields" do it "adds an error to the relevant fields" do
parser.valid? parser.valid?

Loading…
Cancel
Save