Browse Source

CLDC-2986 Close 2022/23 collection period (#2044)

* Update end date for 2022/23

* Update feature toggles
pull/2050/head
kosiakkatrina 1 year ago committed by GitHub
parent
commit
e20f1f9f2a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 16
      app/models/form.rb
  2. 6
      app/services/feature_toggle.rb
  3. 6
      db/seeds.rb
  4. 2
      spec/features/schemes_spec.rb
  5. 12
      spec/helpers/locations_helper_spec.rb
  6. 12
      spec/helpers/schemes_helper_spec.rb
  7. 15
      spec/models/form/lettings/questions/stock_owner_spec.rb
  8. 20
      spec/models/form/sales/questions/owning_organisation_id_spec.rb
  9. 4
      spec/models/form_spec.rb
  10. 3
      spec/models/lettings_log_spec.rb
  11. 13
      spec/models/validations/date_validations_spec.rb
  12. 24
      spec/models/validations/setup_validations_spec.rb
  13. 4
      spec/requests/lettings_logs_controller_spec.rb
  14. 2
      spec/requests/locations_controller_spec.rb
  15. 4
      spec/requests/schemes_controller_spec.rb
  16. 9
      spec/services/bulk_upload/lettings/log_creator_spec.rb
  17. 9
      spec/services/bulk_upload/processor_spec.rb
  18. 34
      spec/services/csv/missing_addresses_csv_service_spec.rb
  19. 7
      spec/services/imports/sales_logs_field_import_service_spec.rb

16
app/models/form.rb

@ -6,7 +6,11 @@ class Form
def initialize(form_path, start_year = "", sections_in_form = [], type = "lettings") def initialize(form_path, start_year = "", sections_in_form = [], type = "lettings")
if sales_or_start_year_after_2022?(type, start_year) if sales_or_start_year_after_2022?(type, start_year)
@start_date = Time.zone.local(start_year, 4, 1) @start_date = Time.zone.local(start_year, 4, 1)
@new_logs_end_date = Time.zone.local(start_year + 1, 12, 31) # this is to be manually updated each year when we want to stop users from creating new logs @new_logs_end_date = if start_year && start_year.to_i == 2022
Time.zone.local(start_year + 1, 11, 20)
else
Time.zone.local(start_year + 1, 12, 31)
end
@submission_deadline = if start_year && start_year.to_i > 2022 @submission_deadline = if start_year && start_year.to_i > 2022
Time.zone.local(start_year + 1, 6, 7) Time.zone.local(start_year + 1, 6, 7)
else else
@ -26,7 +30,11 @@ class Form
"sections" => sections, "sections" => sections,
} }
@unresolved_log_redirect_page_id = "tenancy_start_date" if type == "lettings" @unresolved_log_redirect_page_id = "tenancy_start_date" if type == "lettings"
@edit_end_date = Time.zone.local(start_year + 1, 12, 31) # this is to be manually updated each year when we want to stop users from editing logs @edit_end_date = if start_year && start_year.to_i == 2022
Time.zone.local(start_year + 1, 11, 20)
else
Time.zone.local(start_year + 1, 12, 31)
end
else else
raise "No form definition file exists for given year".freeze unless File.exist?(form_path) raise "No form definition file exists for given year".freeze unless File.exist?(form_path)
@ -39,9 +47,9 @@ class Form
@pages = subsections.flat_map(&:pages) @pages = subsections.flat_map(&:pages)
@questions = pages.flat_map(&:questions) @questions = pages.flat_map(&:questions)
@start_date = Time.iso8601(form_definition["start_date"]) @start_date = Time.iso8601(form_definition["start_date"])
@new_logs_end_date = Time.zone.local(@start_date.year + 1, 12, 31) @new_logs_end_date = Time.zone.local(@start_date.year + 1, 11, 20)
@submission_deadline = Time.zone.local(@start_date.year + 1, 6, 9) @submission_deadline = Time.zone.local(@start_date.year + 1, 6, 9)
@edit_end_date = Time.zone.local(@start_date.year + 1, 12, 31) @edit_end_date = Time.zone.local(@start_date.year + 1, 11, 20)
@unresolved_log_redirect_page_id = form_definition["unresolved_log_redirect_page_id"] @unresolved_log_redirect_page_id = form_definition["unresolved_log_redirect_page_id"]
end end
@name = "#{start_date.year}_#{new_logs_end_date.year}_#{type}" @name = "#{start_date.year}_#{new_logs_end_date.year}_#{type}"

6
app/services/feature_toggle.rb

@ -1,7 +1,7 @@
class FeatureToggle class FeatureToggle
# Disable check on preview apps to allow for testing of future forms # Disable check on preview apps to allow for testing of future forms
def self.saledate_collection_window_validation_enabled? def self.saledate_collection_window_validation_enabled?
Rails.env.production? || Rails.env.test? || Rails.env.staging? true
end end
def self.startdate_two_week_validation_enabled? def self.startdate_two_week_validation_enabled?
@ -21,9 +21,7 @@ class FeatureToggle
end end
def self.force_crossover? def self.force_crossover?
return false if Rails.env.test? false
!Rails.env.production?
end end
def self.merge_organisations_enabled? def self.merge_organisations_enabled?

6
db/seeds.rb

@ -200,7 +200,7 @@ unless Rails.env.test?
SalesLog.find_or_create_by!( SalesLog.find_or_create_by!(
created_by: support_user, created_by: support_user,
owning_organisation: org, owning_organisation: org,
saledate: Date.new(2023, 1, 1), saledate: Date.new(2023, 4, 1),
purchid: "1", purchid: "1",
ownershipsch: 1, ownershipsch: 1,
type: 2, type: 2,
@ -211,7 +211,7 @@ unless Rails.env.test?
SalesLog.find_or_create_by!( SalesLog.find_or_create_by!(
created_by: support_user, created_by: support_user,
owning_organisation: org, owning_organisation: org,
saledate: Date.new(2023, 1, 1), saledate: Date.new(2023, 4, 1),
purchid: "1", purchid: "1",
ownershipsch: 2, ownershipsch: 2,
type: 9, type: 9,
@ -222,7 +222,7 @@ unless Rails.env.test?
SalesLog.find_or_create_by!( SalesLog.find_or_create_by!(
created_by: support_user, created_by: support_user,
owning_organisation: org, owning_organisation: org,
saledate: Date.new(2023, 1, 1), saledate: Date.new(2023, 4, 1),
purchid: "1", purchid: "1",
ownershipsch: 3, ownershipsch: 3,
type: 10, type: 10,

2
spec/features/schemes_spec.rb

@ -745,7 +745,9 @@ RSpec.describe "Schemes scheme Features" do
let!(:deactivated_location) { FactoryBot.create(:location, startdate: Time.zone.local(2022, 4, 4), scheme:) } let!(:deactivated_location) { FactoryBot.create(:location, startdate: Time.zone.local(2022, 4, 4), scheme:) }
before do before do
Timecop.freeze(Time.zone.local(2023, 10, 10))
FactoryBot.create(:location_deactivation_period, deactivation_date: Time.zone.local(2022, 6, 4), location: deactivated_location) FactoryBot.create(:location_deactivation_period, deactivation_date: Time.zone.local(2022, 6, 4), location: deactivated_location)
Timecop.unfreeze
click_link(scheme.service_name) click_link(scheme.service_name)
end end

12
spec/helpers/locations_helper_spec.rb

@ -219,8 +219,10 @@ RSpec.describe LocationsHelper do
context "with previous deactivations" do context "with previous deactivations" do
context "and all reactivated deactivations" do context "and all reactivated deactivations" do
before do before do
Timecop.freeze(Time.zone.local(2023, 11, 10))
FactoryBot.create(:location_deactivation_period, deactivation_date: Time.zone.local(2022, 8, 10), reactivation_date: Time.zone.local(2022, 9, 1), location:) FactoryBot.create(:location_deactivation_period, deactivation_date: Time.zone.local(2022, 8, 10), reactivation_date: Time.zone.local(2022, 9, 1), location:)
FactoryBot.create(:location_deactivation_period, deactivation_date: Time.zone.local(2022, 9, 15), reactivation_date: Time.zone.local(2022, 9, 28), location:) FactoryBot.create(:location_deactivation_period, deactivation_date: Time.zone.local(2022, 9, 15), reactivation_date: Time.zone.local(2022, 9, 28), location:)
Timecop.return
location.reload location.reload
end end
@ -233,8 +235,10 @@ RSpec.describe LocationsHelper do
context "and non reactivated deactivation" do context "and non reactivated deactivation" do
before do before do
Timecop.freeze(Time.zone.local(2023, 11, 10))
FactoryBot.create(:location_deactivation_period, deactivation_date: Time.zone.local(2022, 8, 10), reactivation_date: Time.zone.local(2022, 9, 1), location:) FactoryBot.create(:location_deactivation_period, deactivation_date: Time.zone.local(2022, 8, 10), reactivation_date: Time.zone.local(2022, 9, 1), location:)
FactoryBot.create(:location_deactivation_period, deactivation_date: Time.zone.local(2022, 9, 15), reactivation_date: nil, location:) FactoryBot.create(:location_deactivation_period, deactivation_date: Time.zone.local(2022, 9, 15), reactivation_date: nil, location:)
Timecop.return
location.reload location.reload
end end
@ -249,8 +253,10 @@ RSpec.describe LocationsHelper do
context "with out of order deactivations" do context "with out of order deactivations" do
context "and all reactivated deactivations" do context "and all reactivated deactivations" do
before do before do
Timecop.freeze(Time.zone.local(2023, 11, 10))
FactoryBot.create(:location_deactivation_period, deactivation_date: Time.zone.local(2022, 9, 24), reactivation_date: Time.zone.local(2022, 9, 28), location:) FactoryBot.create(:location_deactivation_period, deactivation_date: Time.zone.local(2022, 9, 24), reactivation_date: Time.zone.local(2022, 9, 28), location:)
FactoryBot.create(:location_deactivation_period, deactivation_date: Time.zone.local(2022, 6, 15), reactivation_date: Time.zone.local(2022, 6, 18), location:) FactoryBot.create(:location_deactivation_period, deactivation_date: Time.zone.local(2022, 6, 15), reactivation_date: Time.zone.local(2022, 6, 18), location:)
Timecop.return
location.reload location.reload
end end
@ -263,8 +269,10 @@ RSpec.describe LocationsHelper do
context "and one non reactivated deactivation" do context "and one non reactivated deactivation" do
before do before do
Timecop.freeze(Time.zone.local(2023, 11, 10))
FactoryBot.create(:location_deactivation_period, deactivation_date: Time.zone.local(2022, 9, 24), reactivation_date: Time.zone.local(2022, 9, 28), location:) FactoryBot.create(:location_deactivation_period, deactivation_date: Time.zone.local(2022, 9, 24), reactivation_date: Time.zone.local(2022, 9, 28), location:)
FactoryBot.create(:location_deactivation_period, deactivation_date: Time.zone.local(2022, 6, 15), reactivation_date: nil, location:) FactoryBot.create(:location_deactivation_period, deactivation_date: Time.zone.local(2022, 6, 15), reactivation_date: nil, location:)
Timecop.return
location.reload location.reload
end end
@ -279,9 +287,11 @@ RSpec.describe LocationsHelper do
context "with multiple out of order deactivations" do context "with multiple out of order deactivations" do
context "and one non reactivated deactivation" do context "and one non reactivated deactivation" do
before do before do
Timecop.freeze(Time.zone.local(2023, 11, 10))
FactoryBot.create(:location_deactivation_period, deactivation_date: Time.zone.local(2022, 9, 24), reactivation_date: Time.zone.local(2022, 9, 28), location:) FactoryBot.create(:location_deactivation_period, deactivation_date: Time.zone.local(2022, 9, 24), reactivation_date: Time.zone.local(2022, 9, 28), location:)
FactoryBot.create(:location_deactivation_period, deactivation_date: Time.zone.local(2022, 10, 24), reactivation_date: Time.zone.local(2022, 10, 28), location:) FactoryBot.create(:location_deactivation_period, deactivation_date: Time.zone.local(2022, 10, 24), reactivation_date: Time.zone.local(2022, 10, 28), location:)
FactoryBot.create(:location_deactivation_period, deactivation_date: Time.zone.local(2022, 6, 15), reactivation_date: nil, location:) FactoryBot.create(:location_deactivation_period, deactivation_date: Time.zone.local(2022, 6, 15), reactivation_date: nil, location:)
Timecop.return
location.reload location.reload
end end
@ -295,8 +305,10 @@ RSpec.describe LocationsHelper do
context "with intersecting deactivations" do context "with intersecting deactivations" do
before do before do
Timecop.freeze(Time.zone.local(2023, 11, 10))
FactoryBot.create(:location_deactivation_period, deactivation_date: Time.zone.local(2022, 10, 10), reactivation_date: Time.zone.local(2022, 12, 1), location:) FactoryBot.create(:location_deactivation_period, deactivation_date: Time.zone.local(2022, 10, 10), reactivation_date: Time.zone.local(2022, 12, 1), location:)
FactoryBot.create(:location_deactivation_period, deactivation_date: Time.zone.local(2022, 11, 11), reactivation_date: Time.zone.local(2022, 12, 11), location:) FactoryBot.create(:location_deactivation_period, deactivation_date: Time.zone.local(2022, 11, 11), reactivation_date: Time.zone.local(2022, 12, 11), location:)
Timecop.return
location.reload location.reload
end end

12
spec/helpers/schemes_helper_spec.rb

@ -177,8 +177,10 @@ RSpec.describe SchemesHelper do
context "with previous deactivations" do context "with previous deactivations" do
context "and all reactivated deactivations" do context "and all reactivated deactivations" do
before do before do
Timecop.freeze(Time.zone.local(2023, 11, 10))
FactoryBot.create(:scheme_deactivation_period, deactivation_date: Time.zone.local(2022, 8, 10), reactivation_date: Time.zone.local(2022, 9, 1), scheme:) FactoryBot.create(:scheme_deactivation_period, deactivation_date: Time.zone.local(2022, 8, 10), reactivation_date: Time.zone.local(2022, 9, 1), scheme:)
FactoryBot.create(:scheme_deactivation_period, deactivation_date: Time.zone.local(2022, 9, 15), reactivation_date: Time.zone.local(2022, 9, 28), scheme:) FactoryBot.create(:scheme_deactivation_period, deactivation_date: Time.zone.local(2022, 9, 15), reactivation_date: Time.zone.local(2022, 9, 28), scheme:)
Timecop.return
scheme.reload scheme.reload
end end
@ -191,8 +193,10 @@ RSpec.describe SchemesHelper do
context "and non reactivated deactivation" do context "and non reactivated deactivation" do
before do before do
Timecop.freeze(Time.zone.local(2023, 11, 10))
FactoryBot.create(:scheme_deactivation_period, deactivation_date: Time.zone.local(2022, 8, 10), reactivation_date: Time.zone.local(2022, 9, 1), scheme:) FactoryBot.create(:scheme_deactivation_period, deactivation_date: Time.zone.local(2022, 8, 10), reactivation_date: Time.zone.local(2022, 9, 1), scheme:)
FactoryBot.create(:scheme_deactivation_period, deactivation_date: Time.zone.local(2022, 9, 15), reactivation_date: nil, scheme:) FactoryBot.create(:scheme_deactivation_period, deactivation_date: Time.zone.local(2022, 9, 15), reactivation_date: nil, scheme:)
Timecop.return
scheme.reload scheme.reload
end end
@ -207,8 +211,10 @@ RSpec.describe SchemesHelper do
context "with out of order deactivations" do context "with out of order deactivations" do
context "and all reactivated deactivations" do context "and all reactivated deactivations" do
before do before do
Timecop.freeze(Time.zone.local(2023, 11, 10))
FactoryBot.create(:scheme_deactivation_period, deactivation_date: Time.zone.local(2022, 9, 24), reactivation_date: Time.zone.local(2022, 9, 28), scheme:) FactoryBot.create(:scheme_deactivation_period, deactivation_date: Time.zone.local(2022, 9, 24), reactivation_date: Time.zone.local(2022, 9, 28), scheme:)
FactoryBot.create(:scheme_deactivation_period, deactivation_date: Time.zone.local(2022, 6, 15), reactivation_date: Time.zone.local(2022, 6, 18), scheme:) FactoryBot.create(:scheme_deactivation_period, deactivation_date: Time.zone.local(2022, 6, 15), reactivation_date: Time.zone.local(2022, 6, 18), scheme:)
Timecop.return
scheme.reload scheme.reload
end end
@ -221,8 +227,10 @@ RSpec.describe SchemesHelper do
context "and one non reactivated deactivation" do context "and one non reactivated deactivation" do
before do before do
Timecop.freeze(Time.zone.local(2023, 11, 10))
FactoryBot.create(:scheme_deactivation_period, deactivation_date: Time.zone.local(2022, 9, 24), reactivation_date: Time.zone.local(2022, 9, 28), scheme:) FactoryBot.create(:scheme_deactivation_period, deactivation_date: Time.zone.local(2022, 9, 24), reactivation_date: Time.zone.local(2022, 9, 28), scheme:)
FactoryBot.create(:scheme_deactivation_period, deactivation_date: Time.zone.local(2022, 6, 15), reactivation_date: nil, scheme:) FactoryBot.create(:scheme_deactivation_period, deactivation_date: Time.zone.local(2022, 6, 15), reactivation_date: nil, scheme:)
Timecop.return
scheme.reload scheme.reload
end end
@ -237,9 +245,11 @@ RSpec.describe SchemesHelper do
context "with multiple out of order deactivations" do context "with multiple out of order deactivations" do
context "and one non reactivated deactivation" do context "and one non reactivated deactivation" do
before do before do
Timecop.freeze(Time.zone.local(2023, 11, 10))
FactoryBot.create(:scheme_deactivation_period, deactivation_date: Time.zone.local(2022, 9, 24), reactivation_date: Time.zone.local(2022, 9, 28), scheme:) FactoryBot.create(:scheme_deactivation_period, deactivation_date: Time.zone.local(2022, 9, 24), reactivation_date: Time.zone.local(2022, 9, 28), scheme:)
FactoryBot.create(:scheme_deactivation_period, deactivation_date: Time.zone.local(2022, 10, 24), reactivation_date: Time.zone.local(2022, 10, 28), scheme:) FactoryBot.create(:scheme_deactivation_period, deactivation_date: Time.zone.local(2022, 10, 24), reactivation_date: Time.zone.local(2022, 10, 28), scheme:)
FactoryBot.create(:scheme_deactivation_period, deactivation_date: Time.zone.local(2022, 6, 15), reactivation_date: nil, scheme:) FactoryBot.create(:scheme_deactivation_period, deactivation_date: Time.zone.local(2022, 6, 15), reactivation_date: nil, scheme:)
Timecop.return
scheme.reload scheme.reload
end end
@ -253,8 +263,10 @@ RSpec.describe SchemesHelper do
context "with intersecting deactivations" do context "with intersecting deactivations" do
before do before do
Timecop.freeze(Time.zone.local(2023, 11, 10))
FactoryBot.create(:scheme_deactivation_period, deactivation_date: Time.zone.local(2022, 10, 10), reactivation_date: Time.zone.local(2022, 12, 1), scheme:) FactoryBot.create(:scheme_deactivation_period, deactivation_date: Time.zone.local(2022, 10, 10), reactivation_date: Time.zone.local(2022, 12, 1), scheme:)
FactoryBot.create(:scheme_deactivation_period, deactivation_date: Time.zone.local(2022, 11, 11), reactivation_date: Time.zone.local(2022, 12, 11), scheme:) FactoryBot.create(:scheme_deactivation_period, deactivation_date: Time.zone.local(2022, 11, 11), reactivation_date: Time.zone.local(2022, 12, 11), scheme:)
Timecop.return
scheme.reload scheme.reload
end end

15
spec/models/form/lettings/questions/stock_owner_spec.rb

@ -116,6 +116,11 @@ RSpec.describe Form::Lettings::Questions::StockOwner, type: :model do
before do before do
merged_organisation.update!(merge_date: Time.zone.local(2023, 2, 2), absorbing_organisation: user.organisation) merged_organisation.update!(merge_date: Time.zone.local(2023, 2, 2), absorbing_organisation: user.organisation)
user.organisation.update!(available_from: Time.zone.local(2021, 2, 2)) user.organisation.update!(available_from: Time.zone.local(2021, 2, 2))
Timecop.freeze(Time.zone.local(2023, 11, 10))
end
after do
Timecop.return
end end
it "shows merged organisation as an option" do it "shows merged organisation as an option" do
@ -137,6 +142,11 @@ RSpec.describe Form::Lettings::Questions::StockOwner, type: :model do
before do before do
merged_organisation.update!(merge_date: Time.zone.local(2023, 2, 2), absorbing_organisation: user.organisation) merged_organisation.update!(merge_date: Time.zone.local(2023, 2, 2), absorbing_organisation: user.organisation)
Timecop.freeze(Time.zone.local(2023, 11, 10))
end
after do
Timecop.return
end end
it "shows merged organisation as an option" do it "shows merged organisation as an option" do
@ -156,11 +166,16 @@ RSpec.describe Form::Lettings::Questions::StockOwner, type: :model do
end end
before do before do
Timecop.freeze(Time.zone.local(2023, 11, 10))
org_rel.update!(child_organisation: merged_organisation) org_rel.update!(child_organisation: merged_organisation)
merged_organisation.update!(merge_date: Time.zone.local(2023, 2, 2), absorbing_organisation: user.organisation) merged_organisation.update!(merge_date: Time.zone.local(2023, 2, 2), absorbing_organisation: user.organisation)
user.organisation.update!(available_from: Time.zone.local(2021, 2, 2)) user.organisation.update!(available_from: Time.zone.local(2021, 2, 2))
end end
after do
Timecop.return
end
it "does not show merged organisations stock owners as options" do it "does not show merged organisations stock owners as options" do
expect(question.displayed_answer_options(log, user)).to eq(options) expect(question.displayed_answer_options(log, user)).to eq(options)
end end

20
spec/models/form/sales/questions/owning_organisation_id_spec.rb

@ -106,6 +106,11 @@ RSpec.describe Form::Sales::Questions::OwningOrganisationId, type: :model do
before do before do
merged_organisation.update!(merge_date: Time.zone.local(2023, 2, 2), absorbing_organisation: user.organisation) merged_organisation.update!(merge_date: Time.zone.local(2023, 2, 2), absorbing_organisation: user.organisation)
Timecop.freeze(Time.zone.local(2023, 11, 10))
end
after do
Timecop.return
end end
it "shows merged organisation as an option" do it "shows merged organisation as an option" do
@ -127,6 +132,11 @@ RSpec.describe Form::Sales::Questions::OwningOrganisationId, type: :model do
before do before do
merged_organisation.update!(merge_date: Time.zone.local(2023, 2, 2), absorbing_organisation: user.organisation) merged_organisation.update!(merge_date: Time.zone.local(2023, 2, 2), absorbing_organisation: user.organisation)
user.organisation.update!(available_from: Time.zone.local(2021, 2, 2)) user.organisation.update!(available_from: Time.zone.local(2021, 2, 2))
Timecop.freeze(Time.zone.local(2023, 11, 10))
end
after do
Timecop.return
end end
it "shows available from date if it is given" do it "shows available from date if it is given" do
@ -148,6 +158,11 @@ RSpec.describe Form::Sales::Questions::OwningOrganisationId, type: :model do
before do before do
org_rel.update!(child_organisation: merged_organisation) org_rel.update!(child_organisation: merged_organisation)
merged_organisation.update!(merge_date: Time.zone.local(2023, 2, 2), absorbing_organisation: user.organisation) merged_organisation.update!(merge_date: Time.zone.local(2023, 2, 2), absorbing_organisation: user.organisation)
Timecop.freeze(Time.zone.local(2023, 11, 10))
end
after do
Timecop.return
end end
it "does not show merged organisations stock owners as options" do it "does not show merged organisations stock owners as options" do
@ -210,6 +225,11 @@ RSpec.describe Form::Sales::Questions::OwningOrganisationId, type: :model do
before do before do
merged_organisation.update!(merge_date: Time.zone.local(2023, 2, 2), absorbing_organisation: organisation_1) merged_organisation.update!(merge_date: Time.zone.local(2023, 2, 2), absorbing_organisation: organisation_1)
organisation_1.update!(created_at: Time.zone.local(2021, 2, 2)) organisation_1.update!(created_at: Time.zone.local(2021, 2, 2))
Timecop.freeze(Time.zone.local(2023, 11, 10))
end
after do
Timecop.return
end end
it "shows merged organisation as an option" do it "shows merged organisation as an option" do

4
spec/models/form_spec.rb

@ -392,8 +392,8 @@ RSpec.describe Form, type: :model do
expect(form.questions.count).to eq(13) expect(form.questions.count).to eq(13)
expect(form.questions.first.id).to eq("owning_organisation_id") expect(form.questions.first.id).to eq("owning_organisation_id")
expect(form.start_date).to eq(Time.zone.parse("2022-04-01")) expect(form.start_date).to eq(Time.zone.parse("2022-04-01"))
expect(form.new_logs_end_date).to eq(Time.zone.parse("2023-12-31")) expect(form.new_logs_end_date).to eq(Time.zone.parse("2023-11-20"))
expect(form.edit_end_date).to eq(Time.zone.parse("2023-12-31")) expect(form.edit_end_date).to eq(Time.zone.parse("2023-11-20"))
expect(form.submission_deadline).to eq(Time.zone.parse("2023-06-09")) expect(form.submission_deadline).to eq(Time.zone.parse("2023-06-09"))
expect(form.unresolved_log_redirect_page_id).to eq(nil) expect(form.unresolved_log_redirect_page_id).to eq(nil)
end end

3
spec/models/lettings_log_spec.rb

@ -2077,6 +2077,9 @@ RSpec.describe LettingsLog do
Timecop.freeze(Time.zone.local(2022, 4, 2)) Timecop.freeze(Time.zone.local(2022, 4, 2))
Singleton.__init__(FormHandler) Singleton.__init__(FormHandler)
lettings_log.update!(startdate: Time.zone.local(2022, 4, 2), scheme:) lettings_log.update!(startdate: Time.zone.local(2022, 4, 2), scheme:)
end
after do
Timecop.unfreeze Timecop.unfreeze
end end

13
spec/models/validations/date_validations_spec.rb

@ -9,6 +9,15 @@ RSpec.describe Validations::DateValidations do
let(:scheme_no_end_date) { create(:scheme, end_date: nil) } let(:scheme_no_end_date) { create(:scheme, end_date: nil) }
describe "tenancy start date" do describe "tenancy start date" do
before do
Timecop.freeze(Time.zone.local(2023, 11, 10))
Singleton.__init__(FormHandler)
end
after do
Timecop.return
end
it "must be a valid date" do it "must be a valid date" do
record.startdate = Time.zone.local(0, 7, 1) record.startdate = Time.zone.local(0, 7, 1)
date_validator.validate_startdate(record) date_validator.validate_startdate(record)
@ -131,9 +140,9 @@ RSpec.describe Validations::DateValidations do
let(:location) { create(:location, scheme:) } let(:location) { create(:location, scheme:) }
before do before do
create(:location_deactivation_period, deactivation_date: Time.zone.local(2022, 6, 1), reactivation_date: Time.zone.local(2022, 9, 4), location:)
create(:location_deactivation_period, deactivation_date: Time.zone.local(2022, 6, 4), reactivation_date: Time.zone.local(2022, 8, 4), location:) create(:location_deactivation_period, deactivation_date: Time.zone.local(2022, 6, 4), reactivation_date: Time.zone.local(2022, 8, 4), location:)
create(:location_deactivation_period, deactivation_date: Time.zone.local(2022, 6, 2), reactivation_date: Time.zone.local(2022, 8, 3), location:) create(:location_deactivation_period, deactivation_date: Time.zone.local(2022, 6, 2), reactivation_date: Time.zone.local(2022, 8, 3), location:)
create(:location_deactivation_period, deactivation_date: Time.zone.local(2022, 6, 1), reactivation_date: Time.zone.local(2022, 9, 4), location:)
location.reload location.reload
end end
@ -246,9 +255,9 @@ RSpec.describe Validations::DateValidations do
before do before do
create(:location, scheme:) create(:location, scheme:)
create(:scheme_deactivation_period, deactivation_date: Time.zone.local(2022, 6, 1), reactivation_date: Time.zone.local(2022, 9, 4), scheme:)
create(:scheme_deactivation_period, deactivation_date: Time.zone.local(2022, 6, 4), reactivation_date: Time.zone.local(2022, 8, 4), scheme:) create(:scheme_deactivation_period, deactivation_date: Time.zone.local(2022, 6, 4), reactivation_date: Time.zone.local(2022, 8, 4), scheme:)
create(:scheme_deactivation_period, deactivation_date: Time.zone.local(2022, 6, 2), reactivation_date: Time.zone.local(2022, 8, 3), scheme:) create(:scheme_deactivation_period, deactivation_date: Time.zone.local(2022, 6, 2), reactivation_date: Time.zone.local(2022, 8, 3), scheme:)
create(:scheme_deactivation_period, deactivation_date: Time.zone.local(2022, 6, 1), reactivation_date: Time.zone.local(2022, 9, 4), scheme:)
scheme.reload scheme.reload
end end

24
spec/models/validations/setup_validations_spec.rb

@ -375,7 +375,9 @@ RSpec.describe Validations::SetupValidations do
before do before do
create(:location, scheme:) create(:location, scheme:)
Timecop.freeze(Time.zone.local(2023, 11, 10))
create(:scheme_deactivation_period, deactivation_date: Time.zone.local(2022, 6, 4), scheme:) create(:scheme_deactivation_period, deactivation_date: Time.zone.local(2022, 6, 4), scheme:)
Timecop.return
scheme.reload scheme.reload
end end
@ -403,7 +405,9 @@ RSpec.describe Validations::SetupValidations do
before do before do
create(:location, scheme:) create(:location, scheme:)
Timecop.freeze(Time.zone.local(2023, 11, 10))
create(:scheme_deactivation_period, deactivation_date: Time.zone.local(2022, 6, 4), reactivation_date: Time.zone.local(2022, 8, 4), scheme:) create(:scheme_deactivation_period, deactivation_date: Time.zone.local(2022, 6, 4), reactivation_date: Time.zone.local(2022, 8, 4), scheme:)
Timecop.return
scheme.reload scheme.reload
end end
@ -431,9 +435,11 @@ RSpec.describe Validations::SetupValidations do
before do before do
create(:location, scheme:) create(:location, scheme:)
Timecop.freeze(Time.zone.local(2023, 11, 10))
create(:scheme_deactivation_period, deactivation_date: Time.zone.local(2022, 6, 1), reactivation_date: Time.zone.local(2022, 9, 4), scheme:)
create(:scheme_deactivation_period, deactivation_date: Time.zone.local(2022, 6, 4), reactivation_date: Time.zone.local(2022, 8, 4), scheme:) create(:scheme_deactivation_period, deactivation_date: Time.zone.local(2022, 6, 4), reactivation_date: Time.zone.local(2022, 8, 4), scheme:)
create(:scheme_deactivation_period, deactivation_date: Time.zone.local(2022, 6, 2), reactivation_date: Time.zone.local(2022, 8, 3), scheme:) create(:scheme_deactivation_period, deactivation_date: Time.zone.local(2022, 6, 2), reactivation_date: Time.zone.local(2022, 8, 3), scheme:)
create(:scheme_deactivation_period, deactivation_date: Time.zone.local(2022, 6, 1), reactivation_date: Time.zone.local(2022, 9, 4), scheme:) Timecop.return
scheme.reload scheme.reload
end end
@ -461,7 +467,9 @@ RSpec.describe Validations::SetupValidations do
let(:location) { create(:location, scheme:) } let(:location) { create(:location, scheme:) }
before do before do
Timecop.freeze(Time.zone.local(2023, 11, 10))
create(:location_deactivation_period, deactivation_date: Time.zone.local(2022, 6, 4), location:) create(:location_deactivation_period, deactivation_date: Time.zone.local(2022, 6, 4), location:)
Timecop.return
location.reload location.reload
end end
@ -489,7 +497,9 @@ RSpec.describe Validations::SetupValidations do
let(:location) { create(:location, scheme:) } let(:location) { create(:location, scheme:) }
before do before do
Timecop.freeze(Time.zone.local(2023, 11, 10))
create(:location_deactivation_period, deactivation_date: Time.zone.local(2022, 6, 4), reactivation_date: Time.zone.local(2022, 8, 4), location:) create(:location_deactivation_period, deactivation_date: Time.zone.local(2022, 6, 4), reactivation_date: Time.zone.local(2022, 8, 4), location:)
Timecop.return
location.reload location.reload
end end
@ -517,9 +527,11 @@ RSpec.describe Validations::SetupValidations do
let(:location) { create(:location, scheme:) } let(:location) { create(:location, scheme:) }
before do before do
Timecop.freeze(Time.zone.local(2023, 11, 10))
create(:location_deactivation_period, deactivation_date: Time.zone.local(2022, 6, 1), reactivation_date: Time.zone.local(2022, 9, 4), location:)
create(:location_deactivation_period, deactivation_date: Time.zone.local(2022, 6, 4), reactivation_date: Time.zone.local(2022, 8, 4), location:) create(:location_deactivation_period, deactivation_date: Time.zone.local(2022, 6, 4), reactivation_date: Time.zone.local(2022, 8, 4), location:)
create(:location_deactivation_period, deactivation_date: Time.zone.local(2022, 6, 2), reactivation_date: Time.zone.local(2022, 8, 3), location:) create(:location_deactivation_period, deactivation_date: Time.zone.local(2022, 6, 2), reactivation_date: Time.zone.local(2022, 8, 3), location:)
create(:location_deactivation_period, deactivation_date: Time.zone.local(2022, 6, 1), reactivation_date: Time.zone.local(2022, 9, 4), location:) Timecop.return
location.reload location.reload
end end
@ -572,7 +584,9 @@ RSpec.describe Validations::SetupValidations do
let(:location) { create(:location, scheme:) } let(:location) { create(:location, scheme:) }
before do before do
Timecop.freeze(Time.zone.local(2023, 11, 10))
create(:location_deactivation_period, deactivation_date: Time.zone.local(2022, 6, 4), location:) create(:location_deactivation_period, deactivation_date: Time.zone.local(2022, 6, 4), location:)
Timecop.return
location.reload location.reload
end end
@ -600,7 +614,9 @@ RSpec.describe Validations::SetupValidations do
let(:location) { create(:location, scheme:) } let(:location) { create(:location, scheme:) }
before do before do
Timecop.freeze(Time.zone.local(2023, 11, 10))
create(:location_deactivation_period, deactivation_date: Time.zone.local(2022, 6, 4), reactivation_date: Time.zone.local(2022, 8, 4), location:) create(:location_deactivation_period, deactivation_date: Time.zone.local(2022, 6, 4), reactivation_date: Time.zone.local(2022, 8, 4), location:)
Timecop.return
location.reload location.reload
end end
@ -628,9 +644,11 @@ RSpec.describe Validations::SetupValidations do
let(:location) { create(:location, scheme:) } let(:location) { create(:location, scheme:) }
before do before do
Timecop.freeze(Time.zone.local(2023, 11, 10))
create(:location_deactivation_period, deactivation_date: Time.zone.local(2022, 6, 1), reactivation_date: Time.zone.local(2022, 9, 4), location:)
create(:location_deactivation_period, deactivation_date: Time.zone.local(2022, 6, 4), reactivation_date: Time.zone.local(2022, 8, 4), location:) create(:location_deactivation_period, deactivation_date: Time.zone.local(2022, 6, 4), reactivation_date: Time.zone.local(2022, 8, 4), location:)
create(:location_deactivation_period, deactivation_date: Time.zone.local(2022, 6, 2), reactivation_date: Time.zone.local(2022, 8, 3), location:) create(:location_deactivation_period, deactivation_date: Time.zone.local(2022, 6, 2), reactivation_date: Time.zone.local(2022, 8, 3), location:)
create(:location_deactivation_period, deactivation_date: Time.zone.local(2022, 6, 1), reactivation_date: Time.zone.local(2022, 9, 4), location:) Timecop.return
location.reload location.reload
end end

4
spec/requests/lettings_logs_controller_spec.rb

@ -1036,7 +1036,7 @@ RSpec.describe LettingsLogsController, type: :request do
completed_lettings_log.reload completed_lettings_log.reload
get "/lettings-logs/#{completed_lettings_log.id}", headers:, params: {} get "/lettings-logs/#{completed_lettings_log.id}", headers:, params: {}
expect(completed_lettings_log.form.new_logs_end_date).to eq(Time.zone.local(2022, 12, 31)) expect(completed_lettings_log.form.new_logs_end_date).to eq(Time.zone.local(2022, 11, 20))
expect(completed_lettings_log.status).to eq("completed") expect(completed_lettings_log.status).to eq("completed")
expect(page).to have_link("review and make changes to this log", href: "/lettings-logs/#{completed_lettings_log.id}/review") expect(page).to have_link("review and make changes to this log", href: "/lettings-logs/#{completed_lettings_log.id}/review")
end end
@ -1074,7 +1074,7 @@ RSpec.describe LettingsLogsController, type: :request do
it "displays a closed collection window message for previous collection year logs" do it "displays a closed collection window message for previous collection year logs" do
get "/lettings-logs/#{completed_lettings_log.id}", headers:, params: {} get "/lettings-logs/#{completed_lettings_log.id}", headers:, params: {}
expect(completed_lettings_log.form.new_logs_end_date).to eq(Time.zone.local(2022, 12, 31)) expect(completed_lettings_log.form.new_logs_end_date).to eq(Time.zone.local(2022, 11, 20))
expect(completed_lettings_log.status).to eq("completed") expect(completed_lettings_log.status).to eq("completed")
follow_redirect! follow_redirect!
expect(page).to have_content("This log is from the 2021/2022 collection window, which is now closed.") expect(page).to have_content("This log is from the 2021/2022 collection window, which is now closed.")

2
spec/requests/locations_controller_spec.rb

@ -128,7 +128,9 @@ RSpec.describe LocationsController, type: :request do
let!(:deactivated_location) { create(:location, scheme:, startdate: Time.zone.local(2022, 4, 1)) } let!(:deactivated_location) { create(:location, scheme:, startdate: Time.zone.local(2022, 4, 1)) }
before do before do
Timecop.freeze(Time.zone.local(2023, 11, 10))
create(:location_deactivation_period, deactivation_date: Time.zone.local(2022, 4, 1), location: deactivated_location) create(:location_deactivation_period, deactivation_date: Time.zone.local(2022, 4, 1), location: deactivated_location)
Timecop.return
end end
it "shows locations for multiple selected statuses" do it "shows locations for multiple selected statuses" do

4
spec/requests/schemes_controller_spec.rb

@ -126,7 +126,9 @@ RSpec.describe SchemesController, type: :request do
before do before do
create(:location, scheme: active_scheme) create(:location, scheme: active_scheme)
Timecop.freeze(Time.zone.local(2023, 11, 10))
create(:scheme_deactivation_period, scheme: deactivated_scheme, deactivation_date: Time.zone.local(2022, 4, 1)) create(:scheme_deactivation_period, scheme: deactivated_scheme, deactivation_date: Time.zone.local(2022, 4, 1))
Timecop.return
end end
it "shows schemes for multiple selected statuses" do it "shows schemes for multiple selected statuses" do
@ -371,7 +373,9 @@ RSpec.describe SchemesController, type: :request do
before do before do
create(:location, scheme: active_scheme) create(:location, scheme: active_scheme)
Timecop.freeze(Time.zone.local(2023, 11, 10))
create(:scheme_deactivation_period, scheme: deactivated_scheme, deactivation_date: Time.zone.local(2022, 4, 1)) create(:scheme_deactivation_period, scheme: deactivated_scheme, deactivation_date: Time.zone.local(2022, 4, 1))
Timecop.return
end end
it "shows schemes for multiple selected statuses" do it "shows schemes for multiple selected statuses" do

9
spec/services/bulk_upload/lettings/log_creator_spec.rb

@ -17,6 +17,15 @@ RSpec.describe BulkUpload::Lettings::LogCreator do
end end
describe "#call" do describe "#call" do
before do
Timecop.freeze(Time.zone.local(2023, 11, 10))
Singleton.__init__(FormHandler)
end
after do
Timecop.return
end
context "when a valid csv with new log" do context "when a valid csv with new log" do
it "creates a new log" do it "creates a new log" do
expect { service.call }.to change(LettingsLog, :count) expect { service.call }.to change(LettingsLog, :count)

9
spec/services/bulk_upload/processor_spec.rb

@ -15,6 +15,15 @@ RSpec.describe BulkUpload::Processor do
end end
describe "#call" do describe "#call" do
before do
Timecop.freeze(Time.zone.local(2023, 11, 10))
Singleton.__init__(FormHandler)
end
after do
Timecop.return
end
context "when errors exist from prior job run" do context "when errors exist from prior job run" do
let!(:existing_error) { create(:bulk_upload_error, bulk_upload:) } let!(:existing_error) { create(:bulk_upload_error, bulk_upload:) }

34
spec/services/csv/missing_addresses_csv_service_spec.rb

@ -168,9 +168,12 @@ RSpec.describe Csv::MissingAddressesCsvService do
context "when the organisation only has logs with missing addresses or town or city from 2022" do context "when the organisation only has logs with missing addresses or town or city from 2022" do
before do before do
lettings_log.update!(startdate: Time.zone.local(2022, 4, 5)) lettings_log.startdate = Time.zone.local(2022, 4, 5)
lettings_log_missing_town.update!(startdate: Time.zone.local(2022, 4, 5)) lettings_log.save!(validate: false)
lettings_log_wrong_uprn.update!(startdate: Time.zone.local(2022, 4, 5)) lettings_log_missing_town.startdate = Time.zone.local(2022, 4, 5)
lettings_log_missing_town.save!(validate: false)
lettings_log_wrong_uprn.startdate = Time.zone.local(2022, 4, 5)
lettings_log_wrong_uprn.save!(validate: false)
end end
it "returns nil" do it "returns nil" do
@ -293,9 +296,12 @@ RSpec.describe Csv::MissingAddressesCsvService do
context "when the organisation only has logs with missing addresses from 2022" do context "when the organisation only has logs with missing addresses from 2022" do
before do before do
sales_log.update!(saledate: Time.zone.local(2022, 4, 5)) sales_log.saledate = Time.zone.local(2022, 4, 5)
sales_log_missing_town.update!(saledate: Time.zone.local(2022, 4, 5)) sales_log.save!(validate: false)
sales_log_wrong_uprn.update!(saledate: Time.zone.local(2022, 4, 5)) sales_log_missing_town.saledate = Time.zone.local(2022, 4, 5)
sales_log_missing_town.save!(validate: false)
sales_log_wrong_uprn.saledate = Time.zone.local(2022, 4, 5)
sales_log_wrong_uprn.save!(validate: false)
end end
it "returns nil" do it "returns nil" do
@ -394,7 +400,9 @@ RSpec.describe Csv::MissingAddressesCsvService do
end end
before do before do
create(:lettings_log, managing_organisation: organisation, old_id: "exists", startdate: Time.zone.local(2022, 4, 5)) lettings_log = create(:lettings_log, managing_organisation: organisation, old_id: "exists")
lettings_log.startdate = Time.zone.local(2022, 4, 5)
lettings_log.save!(validate: false)
end end
it "returns a csv with relevant logs" do it "returns a csv with relevant logs" do
@ -410,7 +418,9 @@ RSpec.describe Csv::MissingAddressesCsvService do
context "when the organisation does not have relevant lettings logs" do context "when the organisation does not have relevant lettings logs" do
before do before do
create(:lettings_log, managing_organisation: organisation, startdate: Time.zone.local(2022, 4, 5)) lettings_log = create(:lettings_log, managing_organisation: organisation)
lettings_log.startdate = Time.zone.local(2022, 4, 5)
lettings_log.save!(validate: false)
end end
it "returns only headers" do it "returns only headers" do
@ -491,7 +501,9 @@ RSpec.describe Csv::MissingAddressesCsvService do
end end
before do before do
create(:sales_log, :completed, saledate: Time.zone.local(2022, 4, 5)) sales_log = create(:sales_log, :completed)
sales_log.saledate = Time.zone.local(2022, 4, 5)
sales_log.save!(validate: false)
end end
it "returns a csv with relevant logs" do it "returns a csv with relevant logs" do
@ -507,7 +519,9 @@ RSpec.describe Csv::MissingAddressesCsvService do
context "when the organisation does not have relevant sales logs" do context "when the organisation does not have relevant sales logs" do
before do before do
create(:sales_log, :completed, saledate: Time.zone.local(2022, 4, 5)) sales_log = create(:sales_log, :completed)
sales_log.saledate = Time.zone.local(2022, 4, 5)
sales_log.save!(validate: false)
end end
it "returns only headers" do it "returns only headers" do

7
spec/services/imports/sales_logs_field_import_service_spec.rb

@ -25,6 +25,13 @@ RSpec.describe Imports::SalesLogsFieldImportService do
.to receive(:get_file_io) .to receive(:get_file_io)
.with("#{sales_log_filename}.xml") .with("#{sales_log_filename}.xml")
.and_return(sales_log_file) .and_return(sales_log_file)
Timecop.freeze(Time.zone.local(2023, 11, 10))
Singleton.__init__(FormHandler)
end
after do
Timecop.return
end end
around do |example| around do |example|

Loading…
Cancel
Save