Browse Source

Renme end_date to new_logs_end_date

pull/1716/head
Kat 2 years ago
parent
commit
ab98d54325
  1. 22
      app/models/form.rb
  2. 4
      app/models/form_handler.rb
  3. 2
      app/models/log.rb
  4. 2
      app/services/bulk_upload/lettings/year2022/csv_parser.rb
  5. 2
      app/services/bulk_upload/sales/year2022/csv_parser.rb
  6. 2
      docs/adr/adr-019-form-end-dates.md
  7. 2
      spec/features/form/accessible_autocomplete_spec.rb
  8. 4
      spec/features/form/check_answers_page_lettings_logs_spec.rb
  9. 2
      spec/features/form/checkboxes_spec.rb
  10. 4
      spec/features/form/conditional_questions_spec.rb
  11. 4
      spec/features/form/form_navigation_spec.rb
  12. 2
      spec/features/form/page_routing_spec.rb
  13. 2
      spec/features/form/progressive_total_field_spec.rb
  14. 2
      spec/features/form/saving_data_spec.rb
  15. 2
      spec/features/form/tasklist_page_spec.rb
  16. 4
      spec/features/form/validations_spec.rb
  17. 4
      spec/models/form_spec.rb
  18. 4
      spec/models/lettings_log_spec.rb
  19. 4
      spec/models/sales_log_spec.rb
  20. 4
      spec/requests/form_controller_spec.rb
  21. 6
      spec/requests/lettings_logs_controller_spec.rb

22
app/models/form.rb

@ -1,16 +1,16 @@
class Form
attr_reader :form_definition, :sections, :subsections, :pages, :questions,
:start_date, :end_date, :submission_deadline, :type, :name, :setup_definition,
:start_date, :new_logs_end_date, :submission_deadline, :type, :name, :setup_definition,
:setup_sections, :form_sections, :unresolved_log_redirect_page_id, :edit_end_date
def initialize(form_path, start_year = "", sections_in_form = [], type = "lettings")
if sales_or_start_year_after_2022?(type, start_year)
@start_date = Time.zone.local(start_year, 4, 1)
@end_date = if start_year && start_year.to_i > 2022
Time.zone.local(start_year + 1, 6, 9)
else
Time.zone.local(start_year + 1, 8, 7)
end
@new_logs_end_date = if start_year && start_year.to_i > 2022
Time.zone.local(start_year + 1, 6, 9)
else
Time.zone.local(start_year + 1, 8, 7)
end
@submission_deadline = if start_year && start_year.to_i > 2022
Time.zone.local(start_year + 1, 6, 7)
else
@ -26,7 +26,7 @@ class Form
@form_definition = {
"form_type" => type,
"start_date" => start_date,
"end_date" => end_date,
"end_date" => new_logs_end_date,
"sections" => sections,
}
@unresolved_log_redirect_page_id = "tenancy_start_date" if type == "lettings"
@ -42,12 +42,12 @@ class Form
@pages = subsections.flat_map(&:pages)
@questions = pages.flat_map(&:questions)
@start_date = Time.iso8601(form_definition["start_date"])
@end_date = Time.iso8601(form_definition["end_date"])
@new_logs_end_date = Time.iso8601(form_definition["end_date"])
@submission_deadline = Time.zone.local(2023, 6, 9)
@unresolved_log_redirect_page_id = form_definition["unresolved_log_redirect_page_id"]
end
@edit_end_date = @end_date
@name = "#{start_date.year}_#{end_date.year}_#{type}"
@edit_end_date = @new_logs_end_date
@name = "#{start_date.year}_#{new_logs_end_date.year}_#{type}"
end
def get_subsection(id)
@ -304,7 +304,7 @@ class Form
end
def valid_start_date_for_form?(start_date)
start_date >= self.start_date && start_date <= end_date
start_date >= self.start_date && start_date <= new_logs_end_date
end
def sales_or_start_year_after_2022?(type, start_year)

4
app/models/form_handler.rb

@ -109,12 +109,12 @@ class FormHandler
def lettings_in_crossover_period?(now: Time.zone.now)
forms = lettings_forms.values
forms.count { |form| now.between?(form.start_date, form.end_date) } > 1
forms.count { |form| now.between?(form.start_date, form.new_logs_end_date) } > 1
end
def sales_in_crossover_period?(now: Time.zone.now)
forms = sales_forms.values
forms.count { |form| now.between?(form.start_date, form.end_date) } > 1
forms.count { |form| now.between?(form.start_date, form.new_logs_end_date) } > 1
end
def use_fake_forms!(fake_forms = nil)

2
app/models/log.rb

@ -94,7 +94,7 @@ class Log < ApplicationRecord
def collection_period_open?
return false if older_than_previous_collection_year?
form.end_date > Time.zone.today
form.new_logs_end_date > Time.zone.today
end
def blank_invalid_non_setup_fields!

2
app/services/bulk_upload/lettings/year2022/csv_parser.rb

@ -63,7 +63,7 @@ class BulkUpload::Lettings::Year2022::CsvParser
end
def wrong_template_for_year?
!(first_record_start_date >= form.start_date && first_record_start_date <= form.end_date)
!(first_record_start_date >= form.start_date && first_record_start_date <= form.new_logs_end_date)
end
private

2
app/services/bulk_upload/sales/year2022/csv_parser.rb

@ -45,7 +45,7 @@ class BulkUpload::Sales::Year2022::CsvParser
end
def wrong_template_for_year?
!(first_record_sale_date >= form.start_date && first_record_sale_date <= form.end_date)
!(first_record_sale_date >= form.start_date && first_record_sale_date <= form.new_logs_end_date)
end
private

2
docs/adr/adr-019-form-end-dates.md

@ -13,5 +13,5 @@ Also, if incorrect data is found during QA process, data providers might be aske
To accommodate the different end dates, we will now store 3 different dates on the form definition:
- Submission deadline (submission_deadline) - this is the date displayed at the top of a completed log in lettings and sales - "You can review and make changes to this log until 9 June 2024.". Nothing happens on this date
- New logs end date (end_date) - no new logs for that collection year can be submitted, but logs can be edited
- New logs end date (new_logs_end_date) - no new logs for that collection year can be submitted, but logs can be edited
- Edit and delete logs end date (edit_end_date) - logs can no longer be edited or deleted. Completed logs can still be viewed. Materials / references to the collection year are removed.

2
spec/features/form/accessible_autocomplete_spec.rb

@ -28,7 +28,7 @@ RSpec.describe "Accessible Autocomplete" do
end
before do
allow(lettings_log.form).to receive(:end_date).and_return(Time.zone.today + 1.day)
allow(lettings_log.form).to receive(:new_logs_end_date).and_return(Time.zone.today + 1.day)
sign_in user
end

4
spec/features/form/check_answers_page_lettings_logs_spec.rb

@ -51,8 +51,8 @@ RSpec.describe "Lettings Log Check Answers Page" do
let(:fake_2021_2022_form) { Form.new("spec/fixtures/forms/2021_2022.json") }
before do
allow(lettings_log.form).to receive(:end_date).and_return(Time.zone.today + 1.day)
allow(fake_2021_2022_form).to receive(:end_date).and_return(Time.zone.today + 1.day)
allow(lettings_log.form).to receive(:new_logs_end_date).and_return(Time.zone.today + 1.day)
allow(fake_2021_2022_form).to receive(:new_logs_end_date).and_return(Time.zone.today + 1.day)
sign_in user
allow(FormHandler.instance).to receive(:current_lettings_form).and_return(fake_2021_2022_form)
end

2
spec/features/form/checkboxes_spec.rb

@ -24,7 +24,7 @@ RSpec.describe "Checkboxes" do
end
before do
allow(lettings_log.form).to receive(:end_date).and_return(Time.zone.today + 1.day)
allow(lettings_log.form).to receive(:new_logs_end_date).and_return(Time.zone.today + 1.day)
RequestHelper.stub_http_requests
sign_in user
end

4
spec/features/form/conditional_questions_spec.rb

@ -33,8 +33,8 @@ RSpec.describe "Form Conditional Questions" do
before do
sign_in user
allow(sales_log.form).to receive(:end_date).and_return(Time.zone.today + 1.day)
allow(lettings_log.form).to receive(:end_date).and_return(Time.zone.today + 1.day)
allow(sales_log.form).to receive(:new_logs_end_date).and_return(Time.zone.today + 1.day)
allow(lettings_log.form).to receive(:new_logs_end_date).and_return(Time.zone.today + 1.day)
allow(FormHandler.instance).to receive(:current_lettings_form).and_return(fake_2021_2022_form)
end

4
spec/features/form/form_navigation_spec.rb

@ -44,8 +44,8 @@ RSpec.describe "Form Navigation" do
let(:fake_2021_2022_form) { Form.new("spec/fixtures/forms/2021_2022.json") }
before do
allow(lettings_log.form).to receive(:end_date).and_return(Time.zone.today + 1.day)
allow(fake_2021_2022_form).to receive(:end_date).and_return(Time.zone.today + 1.day)
allow(lettings_log.form).to receive(:new_logs_end_date).and_return(Time.zone.today + 1.day)
allow(fake_2021_2022_form).to receive(:new_logs_end_date).and_return(Time.zone.today + 1.day)
sign_in user
allow(FormHandler.instance).to receive(:current_lettings_form).and_return(fake_2021_2022_form)
end

2
spec/features/form/page_routing_spec.rb

@ -15,7 +15,7 @@ RSpec.describe "Form Page Routing" do
let(:validator) { lettings_log._validators[nil].first }
before do
allow(lettings_log.form).to receive(:end_date).and_return(Time.zone.today + 1.day)
allow(lettings_log.form).to receive(:new_logs_end_date).and_return(Time.zone.today + 1.day)
sign_in user
end

2
spec/features/form/progressive_total_field_spec.rb

@ -22,7 +22,7 @@ RSpec.describe "Accessible Autocomplete" do
end
before do
allow(lettings_log.form).to receive(:end_date).and_return(Time.zone.today + 1.day)
allow(lettings_log.form).to receive(:new_logs_end_date).and_return(Time.zone.today + 1.day)
sign_in user
end

2
spec/features/form/saving_data_spec.rb

@ -37,7 +37,7 @@ RSpec.describe "Form Saving Data" do
end
before do
allow(lettings_log.form).to receive(:end_date).and_return(Time.zone.today + 1.day)
allow(lettings_log.form).to receive(:new_logs_end_date).and_return(Time.zone.today + 1.day)
sign_in user
end

2
spec/features/form/tasklist_page_spec.rb

@ -54,7 +54,7 @@ RSpec.describe "Task List" do
before do
Timecop.freeze(Time.zone.local(2021, 5, 1))
setup_completed_log.update!(startdate: Time.zone.local(2021, 5, 1))
allow(lettings_log.form).to receive(:end_date).and_return(Time.zone.today + 1.day)
allow(lettings_log.form).to receive(:new_logs_end_date).and_return(Time.zone.today + 1.day)
sign_in user
end

4
spec/features/form/validations_spec.rb

@ -42,8 +42,8 @@ RSpec.describe "validations" do
let(:id) { lettings_log.id }
before do
allow(fake_2021_2022_form).to receive(:end_date).and_return(Time.zone.today + 1.day)
allow(lettings_log.form).to receive(:end_date).and_return(Time.zone.today + 1.day)
allow(fake_2021_2022_form).to receive(:new_logs_end_date).and_return(Time.zone.today + 1.day)
allow(lettings_log.form).to receive(:new_logs_end_date).and_return(Time.zone.today + 1.day)
sign_in user
allow(FormHandler.instance).to receive(:current_lettings_form).and_return(fake_2021_2022_form)
end

4
spec/models/form_spec.rb

@ -371,7 +371,9 @@ RSpec.describe Form, type: :model do
expect(form.questions.count).to eq(13)
expect(form.questions.first.id).to eq("owning_organisation_id")
expect(form.start_date).to eq(Time.zone.parse("2022-04-01"))
expect(form.end_date).to eq(Time.zone.parse("2023-08-07"))
expect(form.new_logs_end_date).to eq(Time.zone.parse("2023-08-07"))
expect(form.edit_end_date).to eq(Time.zone.parse("2023-08-07"))
expect(form.submission_deadline).to eq(Time.zone.parse("2023-06-09"))
expect(form.unresolved_log_redirect_page_id).to eq(nil)
end

4
spec/models/lettings_log_spec.rb

@ -3040,7 +3040,7 @@ RSpec.describe LettingsLog do
let(:startdate) { nil }
before do
allow(log).to receive_message_chain(:form, :end_date).and_return(Time.zone.now + 1.day)
allow(log).to receive_message_chain(:form, :new_logs_end_date).and_return(Time.zone.now + 1.day)
end
it "returns true" do
@ -3052,7 +3052,7 @@ RSpec.describe LettingsLog do
let(:startdate) { Time.zone.local(2020, 4, 1) }
before do
allow(log).to receive_message_chain(:form, :end_date).and_return(Time.zone.now - 1.day)
allow(log).to receive_message_chain(:form, :new_logs_end_date).and_return(Time.zone.now - 1.day)
end
it "returns false" do

4
spec/models/sales_log_spec.rb

@ -635,7 +635,7 @@ RSpec.describe SalesLog, type: :model do
let(:saledate) { nil }
before do
allow(log).to receive_message_chain(:form, :end_date).and_return(Time.zone.now + 1.day)
allow(log).to receive_message_chain(:form, :new_logs_end_date).and_return(Time.zone.now + 1.day)
end
it "returns true" do
@ -647,7 +647,7 @@ RSpec.describe SalesLog, type: :model do
let(:saledate) { Time.zone.local(2020, 4, 1) }
before do
allow(log).to receive_message_chain(:form, :end_date).and_return(Time.zone.now - 1.day)
allow(log).to receive_message_chain(:form, :new_logs_end_date).and_return(Time.zone.now - 1.day)
end
it "returns false" do

4
spec/requests/form_controller_spec.rb

@ -31,7 +31,7 @@ RSpec.describe FormController, type: :request do
let(:fake_2021_2022_form) { Form.new("spec/fixtures/forms/2021_2022.json") }
before do
allow(fake_2021_2022_form).to receive(:end_date).and_return(Time.zone.today + 1.day)
allow(fake_2021_2022_form).to receive(:new_logs_end_date).and_return(Time.zone.today + 1.day)
allow(FormHandler.instance).to receive(:current_lettings_form).and_return(fake_2021_2022_form)
end
@ -763,7 +763,7 @@ RSpec.describe FormController, type: :request do
before do
completed_lettings_log.update!(ecstat1: 1, earnings: 130, hhmemb: 1) # we're not routing to that page, so it gets cleared?
allow(completed_lettings_log).to receive(:net_income_soft_validation_triggered?).and_return(true)
allow(completed_lettings_log.form).to receive(:end_date).and_return(Time.zone.today + 1.day)
allow(completed_lettings_log.form).to receive(:new_logs_end_date).and_return(Time.zone.today + 1.day)
post "/lettings-logs/#{completed_lettings_log.id}/net-income-value-check", params: interrupt_params, headers: headers.merge({ "HTTP_REFERER" => referrer })
end

6
spec/requests/lettings_logs_controller_spec.rb

@ -937,14 +937,14 @@ RSpec.describe LettingsLogsController, type: :request do
completed_lettings_log.reload
get "/lettings-logs/#{completed_lettings_log.id}", headers:, params: {}
expect(completed_lettings_log.form.end_date).to eq(Time.zone.local(2023, 7, 1))
expect(completed_lettings_log.form.new_logs_end_date).to eq(Time.zone.local(2023, 7, 1))
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")
end
xit "displays a closed collection window message for previous collection year logs" do
get "/lettings-logs/#{completed_lettings_log.id}", headers:, params: {}
expect(completed_lettings_log.form.end_date).to eq(Time.zone.local(2022, 7, 1))
expect(completed_lettings_log.form.new_logs_end_date).to eq(Time.zone.local(2022, 7, 1))
expect(completed_lettings_log.status).to eq("completed")
expect(page).to have_content("This log is from the 2021/2022 collection window, which is now closed.")
end
@ -1198,7 +1198,7 @@ RSpec.describe LettingsLogsController, type: :request do
let(:headers) { { "Accept" => "text/html" } }
before do
allow(affected_lettings_log.form).to receive(:end_date).and_return(Time.zone.today + 1.day)
allow(affected_lettings_log.form).to receive(:new_logs_end_date).and_return(Time.zone.today + 1.day)
allow(user).to receive(:need_two_factor_authentication?).and_return(false)
sign_in user
end

Loading…
Cancel
Save