Browse Source

CLDC-1428 Prevent creation of new 2021/22 logs (#853)

pull/862/head
David May-Miller 2 years ago committed by GitHub
parent
commit
ae850fa20e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 14
      app/models/validations/date_validations.rb
  2. 2
      config/forms/2021_2022.json
  3. 3
      spec/models/lettings_log_spec.rb
  4. 5
      spec/requests/lettings_logs_controller_spec.rb
  5. 2
      spec/services/csv/lettings_log_csv_service_spec.rb

14
app/models/validations/date_validations.rb

@ -31,6 +31,12 @@ module Validations::DateValidations
def validate_startdate(record)
return unless record.startdate && date_valid?("startdate", record)
created_at = record.created_at || Time.zone.now
if created_at > first_collection_end_date && record.startdate < second_collection_start_date
record.errors.add :startdate, I18n.t("validations.date.outside_collection_window")
end
if record.startdate < first_collection_start_date || record.startdate > second_collection_end_date
record.errors.add :startdate, I18n.t("validations.date.outside_collection_window")
end
@ -57,6 +63,14 @@ private
@first_collection_start_date ||= FormHandler.instance.forms.map { |form| form.second.start_date }.compact.min
end
def first_collection_end_date
@first_collection_end_date ||= FormHandler.instance.forms.map { |form| form.second.end_date }.compact.min
end
def second_collection_start_date
@second_collection_start_date ||= FormHandler.instance.forms.map { |form| form.second.start_date }.compact.max
end
def second_collection_end_date
@second_collection_end_date ||= FormHandler.instance.forms.map { |form| form.second.end_date }.compact.max
end

2
config/forms/2021_2022.json

@ -1,7 +1,7 @@
{
"form_type": "lettings",
"start_date": "2021-04-01T00:00:00.000+01:00",
"end_date": "2022-07-01T00:00:00.000+01:00",
"end_date": "2022-09-05T00:00:00.000+01:00",
"sections": {
"tenancy_and_property": {
"label": "Property and tenancy information",

3
spec/models/lettings_log_spec.rb

@ -204,6 +204,7 @@ RSpec.describe LettingsLog do
rent_type: 4,
hb: 1,
hbrentshortfall: 1,
created_at: Time.utc(2022, 2, 8, 16, 52, 15),
})
end
@ -1378,6 +1379,7 @@ RSpec.describe LettingsLog do
created_by: created_by_user,
renewal: 1,
startdate: Time.zone.local(2021, 4, 10),
created_at: Time.utc(2022, 2, 8, 16, 52, 15),
})
end
@ -1712,6 +1714,7 @@ RSpec.describe LettingsLog do
location_id: location.id,
renewal: 1,
startdate: Time.zone.now,
created_at: Time.utc(2022, 2, 8, 16, 52, 15),
})
end

5
spec/requests/lettings_logs_controller_spec.rb

@ -49,9 +49,14 @@ RSpec.describe LettingsLogsController, type: :request do
end
before do
Timecop.freeze(Time.utc(2022, 2, 8))
post "/logs", headers:, params: params.to_json
end
after do
Timecop.unfreeze
end
it "returns http success" do
expect(response).to have_http_status(:success)
end

2
spec/services/csv/lettings_log_csv_service_spec.rb

@ -6,7 +6,7 @@ RSpec.describe Csv::LettingsLogCsvService do
let(:real_2021_2022_form) { Form.new("config/forms/2021_2022.json", "2021_2022") }
before do
LettingsLog.create!(startdate: "2021-10-10")
LettingsLog.create!(startdate: "2021-10-10", created_at: Time.utc(2022, 2, 8, 16, 52, 15))
allow(FormHandler.instance).to receive(:get_form).and_return(real_2021_2022_form)
end

Loading…
Cancel
Save