Browse Source

CLDC-3505 further fixes to tests for year hard end (#2493)

* further fixes

* Fix date / crossover issues

* Try changing form end dates

* Revert "Try changing form end dates"

This reverts commit e027e29cf0.

* Make use of :ignore-validation-errors trait

* Try with end dates in past

* Revert "Try with end dates in past"

This reverts commit 6b87938d70.

---------

Co-authored-by: Rachael Booth <rachael.booth@softwire.com>
pull/2505/head
Arthur Campbell 6 months ago committed by GitHub
parent
commit
f423ec1cd5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 6
      db/seeds.rb
  2. 25
      lib/tasks/fix_nil_letting_allocation_values.rake
  3. 1
      spec/factories/lettings_log.rb
  4. 20
      spec/helpers/locations_helper_spec.rb
  5. 73
      spec/lib/tasks/fix_nil_letting_allocation_values_spec.rb
  6. 84
      spec/models/form/sales/questions/deposit_amount_spec.rb
  7. 10
      spec/requests/start_controller_spec.rb
  8. 6
      spec/services/csv/sales_log_csv_service_spec.rb

6
db/seeds.rb

@ -255,7 +255,7 @@ unless Rails.env.test?
assigned_to: support_user, assigned_to: support_user,
owning_organisation: org, owning_organisation: org,
managing_organisation: org, managing_organisation: org,
saledate: Date.new(2023, 4, 1), saledate: Time.zone.today,
purchid: "1", purchid: "1",
ownershipsch: 1, ownershipsch: 1,
type: 2, type: 2,
@ -267,7 +267,7 @@ unless Rails.env.test?
assigned_to: support_user, assigned_to: support_user,
owning_organisation: org, owning_organisation: org,
managing_organisation: org, managing_organisation: org,
saledate: Date.new(2023, 4, 1), saledate: Time.zone.today,
purchid: "1", purchid: "1",
ownershipsch: 2, ownershipsch: 2,
type: 9, type: 9,
@ -279,7 +279,7 @@ unless Rails.env.test?
assigned_to: support_user, assigned_to: support_user,
owning_organisation: org, owning_organisation: org,
managing_organisation: org, managing_organisation: org,
saledate: Date.new(2023, 4, 1), saledate: Time.zone.today,
purchid: "1", purchid: "1",
ownershipsch: 3, ownershipsch: 3,
type: 10, type: 10,

25
lib/tasks/fix_nil_letting_allocation_values.rake

@ -1,25 +0,0 @@
desc "Infer nil letting allocation values as no"
task fix_nil_letting_allocation_values: :environment do
LettingsLog.where(cbl: nil)
.or(LettingsLog.where(chr: nil))
.or(LettingsLog.where(cap: nil))
.or(LettingsLog.filter_by_year(2024).where(accessible_register: nil))
.find_each do |log|
next unless log.cbl.present? || log.chr.present? || log.cap.present? || log.accessible_register.present? || log.letting_allocation_unknown.present?
log.cbl = 0 if log.cbl.blank?
log.chr = 0 if log.chr.blank?
log.cap = 0 if log.cap.blank?
log.accessible_register = 0 if log.form.start_year_after_2024? && log.accessible_register.blank?
log.letting_allocation_unknown = if log.cbl == 1 || log.chr == 1 || log.cap == 1 || log.accessible_register == 1
0
else
1
end
next if log.save
Rails.logger.info("NilLettingsAllocationValues: Unable to save changes to log #{log.id}")
end
end

1
spec/factories/lettings_log.rb

@ -216,6 +216,7 @@ FactoryBot.define do
trait :ignore_validation_errors do trait :ignore_validation_errors do
to_create do |instance| to_create do |instance|
instance.valid? instance.valid?
instance.errors.clear
instance.save!(validate: false) instance.save!(validate: false)
end end
end end

20
spec/helpers/locations_helper_spec.rb

@ -1,6 +1,8 @@
require "rails_helper" require "rails_helper"
RSpec.describe LocationsHelper do RSpec.describe LocationsHelper do
include CollectionTimeHelper
describe "mobility type selection" do describe "mobility type selection" do
expected_selection = [OpenStruct.new(id: "Wheelchair-user standard", name: "Wheelchair-user standard", description: "Suitable for someone who uses a wheelchair and offers the full use of all rooms and facilities."), expected_selection = [OpenStruct.new(id: "Wheelchair-user standard", name: "Wheelchair-user standard", description: "Suitable for someone who uses a wheelchair and offers the full use of all rooms and facilities."),
OpenStruct.new(id: "Fitted with equipment and adaptations", name: "Fitted with equipment and adaptations", description: "Fitted with stairlifts, ramps, level access showers or grab rails."), OpenStruct.new(id: "Fitted with equipment and adaptations", name: "Fitted with equipment and adaptations", description: "Fitted with stairlifts, ramps, level access showers or grab rails."),
@ -201,18 +203,26 @@ RSpec.describe LocationsHelper do
context "when viewing availability" do context "when viewing availability" do
context "with no deactivations" do context "with no deactivations" do
it "displays current collection start date as availability date if created_at is later than collection start date" do before do
location.update!(startdate: nil, created_at: Time.zone.local(2024, 1, 16)) allow(Time).to receive(:now).and_call_original
end
it "displays current collection start date as availability date if created_at is later than collection start date and not in a crossover period" do
allow(FormHandler.instance).to receive(:in_crossover_period?).with(anything).and_return(false)
location.update!(startdate: nil, created_at: current_collection_start_date + 6.months)
availability_attribute = display_location_attributes(location).find { |x| x[:name] == "Availability" }[:value] availability_attribute = display_location_attributes(location).find { |x| x[:name] == "Availability" }[:value]
expect(availability_attribute).to eq("Active from 1 April 2023") expect(availability_attribute).to eq("Active from 1 April #{current_collection_start_date.year}")
end end
it "displays previous collection start date as availability date if created_at is later than collection start date and in crossover" do it "displays previous collection start date as availability date if created_at is later than collection start date and in crossover" do
location.update!(startdate: nil, created_at: Time.zone.local(2023, 4, 16)) allow(FormHandler.instance).to receive(:in_crossover_period?).with(anything).and_return(true)
location.update!(startdate: nil, created_at: current_collection_start_date + 1.week)
availability_attribute = display_location_attributes(location).find { |x| x[:name] == "Availability" }[:value] availability_attribute = display_location_attributes(location).find { |x| x[:name] == "Availability" }[:value]
expect(availability_attribute).to eq("Active from 1 April 2022") expect(availability_attribute).to eq("Active from 1 April #{previous_collection_start_date.year}")
end end
context "when location was merged" do context "when location was merged" do

73
spec/lib/tasks/fix_nil_letting_allocation_values_spec.rb

@ -1,73 +0,0 @@
require "rails_helper"
require "rake"
RSpec.describe "fix_nil_letting_allocation_values" do
describe ":fix_nil_letting_allocation_values", type: :task do
subject(:task) { Rake::Task["fix_nil_letting_allocation_values"] }
before do
Rake.application.rake_require("tasks/fix_nil_letting_allocation_values")
Rake::Task.define_task(:environment)
task.reenable
end
it "sets nil values to 0 when one allocation type value is non-nil" do
log = create(:lettings_log, :setup_completed, :startdate_today, cbl: nil, chr: nil, cap: 1, accessible_register: nil, letting_allocation_unknown: nil)
task.invoke
log.reload
expect(log.cbl).to be 0
expect(log.chr).to be 0
expect(log.cap).to be 1
expect(log.accessible_register).to be 0
expect(log.letting_allocation_unknown).to be 0
end
it "sets nil values to 0 and letting_allocation_unknown to 1 when non-nil allocation type values are 0" do
log = create(:lettings_log, :setup_completed, :startdate_today, cbl: 0, chr: 0, cap: nil, accessible_register: nil, letting_allocation_unknown: nil)
task.invoke
log.reload
expect(log.cbl).to be 0
expect(log.chr).to be 0
expect(log.cap).to be 0
expect(log.accessible_register).to be 0
expect(log.letting_allocation_unknown).to be 1
end
it "does not set anything when question has not been answered at all" do
log = create(:lettings_log, :setup_completed, :startdate_today, cbl: nil, chr: nil, cap: nil, accessible_register: nil, letting_allocation_unknown: nil)
task.invoke
log.reload
expect(log.cbl).to be_nil
expect(log.chr).to be_nil
expect(log.cap).to be_nil
expect(log.accessible_register).to be_nil
expect(log.letting_allocation_unknown).to be_nil
end
it "does not set accessible_register for logs before 2024" do
log = create(:lettings_log, :setup_completed, startdate: Time.zone.local(2023, 5, 1), cbl: 1, chr: nil, cap: nil, accessible_register: nil, letting_allocation_unknown: nil)
task.invoke
log.reload
expect(log.cbl).to be 1
expect(log.chr).to be 0
expect(log.cap).to be 0
expect(log.accessible_register).to be_nil
expect(log.letting_allocation_unknown).to be 0
end
it "logs the log id if the change cannot be saved" do
log = create(:lettings_log, :ignore_validation_errors, :setup_completed, startdate: Time.zone.local(2022, 4, 1), cbl: 1, chr: nil, cap: nil, letting_allocation_unknown: nil)
expect(Rails.logger).to receive(:info).with(match(/log #{log.id}/))
task.invoke
end
end
end

84
spec/models/form/sales/questions/deposit_amount_spec.rb

@ -1,32 +1,13 @@
require "rails_helper" require "rails_helper"
RSpec.describe Form::Sales::Questions::DepositAmount, type: :model do RSpec.describe Form::Sales::Questions::DepositAmount, type: :model do
subject(:question) { described_class.new(question_id, question_definition, page, ownershipsch: 1, optional: false) } subject(:question) { described_class.new(question_id, question_definition, page, ownershipsch: 1, optional:) }
let(:optional) { false }
let(:question_id) { nil } let(:question_id) { nil }
let(:question_definition) { nil } let(:question_definition) { nil }
let(:page) { instance_double(Form::Page, subsection: instance_double(Form::Subsection, form: instance_double(Form, start_date: Time.zone.local(2023, 4, 1)))) } let(:page) { instance_double(Form::Page, subsection: instance_double(Form::Subsection, form: instance_double(Form, start_date: Time.zone.local(2023, 4, 1)))) }
it "has correct page" do
expect(question.page).to eq(page)
end
it "has the correct id" do
expect(question.id).to eq("deposit")
end
it "has the correct header" do
expect(question.header).to eq("How much cash deposit was paid on the property?")
end
it "has the correct check_answer_label" do
expect(question.check_answer_label).to eq("Cash deposit")
end
it "has the correct type" do
expect(question.type).to eq("numeric")
end
context "when the ownership type is shared" do context "when the ownership type is shared" do
let(:log) { build(:sales_log, :completed, ownershipsch: 1, mortgageused: 2) } let(:log) { build(:sales_log, :completed, ownershipsch: 1, mortgageused: 2) }
@ -44,49 +25,48 @@ RSpec.describe Form::Sales::Questions::DepositAmount, type: :model do
end end
context "when the ownership type is outright" do context "when the ownership type is outright" do
let(:log) { build(:sales_log, :completed, ownershipsch: 3, mortgageused: 2) } let(:log) { build(:sales_log, :outright_sale_setup_complete, mortgageused:) }
it "is not marked as derived when a mortgage is used" do context "when a mortgage is used" do
log.mortgageused = 1 let(:mortgageused) { 1 }
expect(question.derived?(log)).to be false
end
it "is marked as derived when a mortgage is not used" do it "is not marked as derived " do
log.mortgageused = 2 expect(question.derived?(log)).to be false
expect(question.derived?(log)).to be true end
end end
it "is marked as derived when the mortgage use is unknown" do context "when a mortgage is not used" do
log.mortgageused = 3 let(:mortgageused) { 2 }
expect(question.derived?(log)).to be true
end
end
it "has the correct hint" do it "is marked as derived " do
expect(question.hint_text).to eq("Enter the total cash sum paid by the buyer towards the property that was not funded by the mortgage. This excludes any grant or loan") expect(question.derived?(log)).to be true
end end
end
it "has correct width" do context "when the mortgage use is unknown" do
expect(question.width).to eq(5) let(:mortgageused) { 3 }
end
it "has correct prefix" do it "is marked as derived " do
expect(question.prefix).to eq("£") expect(question.derived?(log)).to be true
end
end
end end
it "has correct min" do describe "hint text" do
expect(question.min).to eq(0) context "when optional is false" do
end let(:optional) { false }
it "has correct max" do it "has the correct hint" do
expect(question.max).to eq(999_999) expect(question.hint_text).to eq("Enter the total cash sum paid by the buyer towards the property that was not funded by the mortgage. This excludes any grant or loan")
end end
end
context "when optional iis true" do context "when optional is true" do
subject(:question) { described_class.new(question_id, question_definition, page, ownershipsch: 1, optional: true) } let(:optional) { true }
it "has a correct hint_text" do it "has the correct hint" do
expect(question.hint_text).to eq("Enter the total cash sum paid by the buyer towards the property that was not funded by the mortgage. This excludes any grant or loan. As this is a fully staircased sale this question is optional. If you do not have the information available click save and continue") expect(question.hint_text).to eq("Enter the total cash sum paid by the buyer towards the property that was not funded by the mortgage. This excludes any grant or loan. As this is a fully staircased sale this question is optional. If you do not have the information available click save and continue")
end
end end
end end
end end

10
spec/requests/start_controller_spec.rb

@ -203,7 +203,7 @@ RSpec.describe StartController, type: :request do
it "shows the correct counts of logs created by them" do it "shows the correct counts of logs created by them" do
last_year_in_progress_count = 2 last_year_in_progress_count = 2
this_year_in_progress_count = 3 this_year_in_progress_count = 3
create_list(:lettings_log, last_year_in_progress_count, :in_progress, assigned_to: provider_1, startdate: Time.zone.today - 1.year) create_list(:lettings_log, last_year_in_progress_count, :in_progress, :ignore_validation_errors, assigned_to: provider_1, startdate: Time.zone.today - 1.year)
create_list(:lettings_log, this_year_in_progress_count, :in_progress, assigned_to: provider_1, startdate: Time.zone.today) create_list(:lettings_log, this_year_in_progress_count, :in_progress, assigned_to: provider_1, startdate: Time.zone.today)
get root_path get root_path
@ -217,7 +217,7 @@ RSpec.describe StartController, type: :request do
end end
it "does not include logs created by other users in the count, whether in their organisation or not" do it "does not include logs created by other users in the count, whether in their organisation or not" do
create(:lettings_log, :in_progress, assigned_to: coordinator, startdate: Time.zone.today - 1.year) create(:lettings_log, :in_progress, :ignore_validation_errors, assigned_to: coordinator, startdate: Time.zone.today - 1.year)
create(:lettings_log, :in_progress, assigned_to: provider_2, startdate: Time.zone.today) create(:lettings_log, :in_progress, assigned_to: provider_2, startdate: Time.zone.today)
get root_path get root_path
@ -237,7 +237,7 @@ RSpec.describe StartController, type: :request do
it "shows the correct counts of logs created by all users in their organisation" do it "shows the correct counts of logs created by all users in their organisation" do
last_year_in_progress_count = 2 last_year_in_progress_count = 2
this_year_in_progress_count = 3 this_year_in_progress_count = 3
create_list(:lettings_log, last_year_in_progress_count, :in_progress, assigned_to: provider_1, startdate: Time.zone.today - 1.year) create_list(:lettings_log, last_year_in_progress_count, :in_progress, :ignore_validation_errors, assigned_to: provider_1, startdate: Time.zone.today - 1.year)
create_list(:lettings_log, this_year_in_progress_count, :in_progress, assigned_to: coordinator, startdate: Time.zone.today) create_list(:lettings_log, this_year_in_progress_count, :in_progress, assigned_to: coordinator, startdate: Time.zone.today)
get root_path get root_path
@ -288,9 +288,9 @@ RSpec.describe StartController, type: :request do
coordinator_lettings_this_year_in_progress_count = 3 coordinator_lettings_this_year_in_progress_count = 3
provider_2_lettings_last_year_in_progress_count = 2 provider_2_lettings_last_year_in_progress_count = 2
provider_2_sales_this_year_in_progress_count = 3 provider_2_sales_this_year_in_progress_count = 3
create_list(:lettings_log, provider_1_lettings_last_year_in_progress_count, :in_progress, assigned_to: provider_1, startdate: Time.zone.today - 1.year) create_list(:lettings_log, provider_1_lettings_last_year_in_progress_count, :in_progress, :ignore_validation_errors, assigned_to: provider_1, startdate: Time.zone.today - 1.year)
create_list(:lettings_log, coordinator_lettings_this_year_in_progress_count, :in_progress, assigned_to: coordinator, startdate: Time.zone.today) create_list(:lettings_log, coordinator_lettings_this_year_in_progress_count, :in_progress, assigned_to: coordinator, startdate: Time.zone.today)
create_list(:lettings_log, provider_2_lettings_last_year_in_progress_count, :in_progress, assigned_to: provider_2, startdate: Time.zone.today - 1.year) create_list(:lettings_log, provider_2_lettings_last_year_in_progress_count, :in_progress, :ignore_validation_errors, assigned_to: provider_2, startdate: Time.zone.today - 1.year)
create_list(:sales_log, provider_2_sales_this_year_in_progress_count, :in_progress, assigned_to: provider_2, saledate: Time.zone.today) create_list(:sales_log, provider_2_sales_this_year_in_progress_count, :in_progress, assigned_to: provider_2, saledate: Time.zone.today)
get root_path get root_path

6
spec/services/csv/sales_log_csv_service_spec.rb

@ -3,7 +3,7 @@ require "rails_helper"
RSpec.describe Csv::SalesLogCsvService do RSpec.describe Csv::SalesLogCsvService do
let(:form_handler_mock) { instance_double(FormHandler) } let(:form_handler_mock) { instance_double(FormHandler) }
let(:organisation) { create(:organisation) } let(:organisation) { create(:organisation) }
let(:fixed_time) { Time.zone.local(2023, 12, 8) } let(:fixed_time) { now }
let(:now) { Time.zone.now } let(:now) { Time.zone.now }
let(:user) { create(:user, :support, email: "billyboy@eyeKLAUD.com") } let(:user) { create(:user, :support, email: "billyboy@eyeKLAUD.com") }
let(:log) do let(:log) do
@ -134,6 +134,8 @@ RSpec.describe Csv::SalesLogCsvService do
context "when exporting with human readable labels" do context "when exporting with human readable labels" do
let(:year) { 2023 } let(:year) { 2023 }
let(:fixed_time) { Time.zone.local(2023, 12, 8) }
let(:now) { fixed_time }
it "gives answers to radio questions as their labels" do it "gives answers to radio questions as their labels" do
national_column_index = csv.first.index("NATIONAL") national_column_index = csv.first.index("NATIONAL")
@ -220,6 +222,8 @@ RSpec.describe Csv::SalesLogCsvService do
context "when exporting values as codes" do context "when exporting values as codes" do
let(:service) { described_class.new(user:, export_type: "codes", year:) } let(:service) { described_class.new(user:, export_type: "codes", year:) }
let(:year) { 2023 } let(:year) { 2023 }
let(:fixed_time) { Time.zone.local(2023, 12, 8) }
let(:now) { fixed_time }
it "gives answers to radio questions as their codes" do it "gives answers to radio questions as their codes" do
national_column_index = csv.first.index("NATIONAL") national_column_index = csv.first.index("NATIONAL")

Loading…
Cancel
Save