From c21a46a1983359d4b74b38e4e18cd3e84451b670 Mon Sep 17 00:00:00 2001 From: Manny Dinssa <44172848+Dinssa@users.noreply.github.com> Date: Wed, 8 Jan 2025 16:15:49 +0000 Subject: [PATCH] Change quarterly deadlines --- app/helpers/collection_time_helper.rb | 58 +++++++++++-- app/helpers/home_helper.rb | 9 ++ app/models/form.rb | 15 ++++ app/views/home/_upcoming_deadlines.html.erb | 15 ++-- spec/features/home_page_spec.rb | 96 +++++++++++++++++++++ spec/rails_helper.rb | 3 + 6 files changed, 183 insertions(+), 13 deletions(-) create mode 100644 app/helpers/home_helper.rb create mode 100644 spec/features/home_page_spec.rb diff --git a/app/helpers/collection_time_helper.rb b/app/helpers/collection_time_helper.rb index 809cae5e7..05f834d86 100644 --- a/app/helpers/collection_time_helper.rb +++ b/app/helpers/collection_time_helper.rb @@ -30,6 +30,10 @@ module CollectionTimeHelper Time.zone.local(current_collection_start_year + 1, 3, 31).end_of_day end + def current_collection_end_year + current_collection_start_year + 1 + end + def previous_collection_end_date current_collection_end_date - 1.year end @@ -50,12 +54,56 @@ module CollectionTimeHelper current_collection_start_year - 2 end - def quarter_for_date(date: Time.zone.now) - quarters = [ - { quarter: "Q1", cutoff_date: Time.zone.local(2024, 7, 12), start_date: Time.zone.local(2024, 4, 1), end_date: Time.zone.local(2024, 6, 30) }, - { quarter: "Q2", cutoff_date: Time.zone.local(2024, 10, 11), start_date: Time.zone.local(2024, 7, 1), end_date: Time.zone.local(2024, 9, 30) }, - { quarter: "Q3", cutoff_date: Time.zone.local(2025, 1, 10), start_date: Time.zone.local(2024, 10, 1), end_date: Time.zone.local(2024, 12, 31) }, + def quarter_deadlines + Form::QUARTERLY_DEADLINES + end + + def quarter_deadlines_for_year(year) + quarter_deadlines[year] + end + + def first_quarter(year) + { + cutoff_date: quarter_deadlines_for_year(year)[:first_quarter_deadline], + start_date: Time.zone.local(year, 4, 1), + end_date: Time.zone.local(year, 6, 30), + } + end + + def second_quarter(year) + { + cutoff_date: quarter_deadlines_for_year(year)[:second_quarter_deadline], + start_date: Time.zone.local(year, 7, 1), + end_date: Time.zone.local(year, 9, 30), + } + end + + def third_quarter(year) + { + cutoff_date: quarter_deadlines_for_year(year)[:third_quarter_deadline], + start_date: Time.zone.local(year, 10, 1), + end_date: Time.zone.local(year, 12, 31), + } + end + + def fourth_quarter(year) + { + cutoff_date: quarter_deadlines_for_year(year)[:fourth_quarter_deadline], + start_date: Time.zone.local(year + 1, 1, 1), + end_date: Time.zone.local(year + 1, 3, 31), + } + end + + def quarter_dates(year) + [ + first_quarter(year).merge(quarter: "Q1"), + second_quarter(year).merge(quarter: "Q2"), + third_quarter(year).merge(quarter: "Q3"), ] + end + + def quarter_for_date(date: Time.zone.now) + quarters = quarter_dates(current_collection_start_year) quarter = quarters.find { |q| date.between?(q[:start_date], q[:cutoff_date] + 1.day) } diff --git a/app/helpers/home_helper.rb b/app/helpers/home_helper.rb new file mode 100644 index 000000000..79b314fff --- /dev/null +++ b/app/helpers/home_helper.rb @@ -0,0 +1,9 @@ +module HomeHelper + def quarterly_cutoff_date(quarter, year) + send("#{quarter}_quarter", year)[:cutoff_date].strftime("%A %-d %B %Y") + end + + def formatted_deadline + quarterly_cutoff_date("fourth", current_collection_start_year) + end +end diff --git a/app/models/form.rb b/app/models/form.rb index ce77378ca..f75159f25 100644 --- a/app/models/form.rb +++ b/app/models/form.rb @@ -24,6 +24,21 @@ class Form }, }.freeze + QUARTERLY_DEADLINES = { + 2024 => { + first_quarter_deadline: Time.zone.local(2024, 7, 12), + second_quarter_deadline: Time.zone.local(2024, 10, 11), + third_quarter_deadline: Time.zone.local(2025, 1, 10), + fourth_quarter_deadline: Time.zone.local(2025, 6, 6), # Same as submission deadline, can be refactored + }, + 2025 => { + first_quarter_deadline: Time.zone.local(2025, 7, 11), + second_quarter_deadline: Time.zone.local(2025, 10, 10), + third_quarter_deadline: Time.zone.local(2026, 1, 16), + fourth_quarter_deadline: Time.zone.local(2026, 6, 5), # Same as submission deadline, can be refactored + }, + }.freeze + 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) diff --git a/app/views/home/_upcoming_deadlines.html.erb b/app/views/home/_upcoming_deadlines.html.erb index dbed05bfd..822b80f20 100644 --- a/app/views/home/_upcoming_deadlines.html.erb +++ b/app/views/home/_upcoming_deadlines.html.erb @@ -1,7 +1,6 @@
End of year deadline - <%= formatted_deadline %>: Deadline to submit logs for tenancies starting between <%= open_lettings_form.start_date.to_formatted_s(:govuk_date) %> to <%= collection_end_date(open_lettings_form.start_date).to_formatted_s(:govuk_date) %>
<% end %> @@ -11,7 +10,7 @@<%= "#{current_quarter.quarter} - #{current_quarter.cutoff_date.strftime('%A')} #{current_quarter.cutoff_date.to_formatted_s(:govuk_date)}" %>: Quarterly cut off date for tenancies and sales starting between <%= current_quarter.quarter_start_date.to_formatted_s(:govuk_date) %> and <%= current_quarter.quarter_end_date.to_formatted_s(:govuk_date) %>.
<% end %> -<% if !FormHandler.instance.in_crossover_period? %> +<% unless FormHandler.instance.in_crossover_period? %>Try to complete your logs for each quarter by the cut-off date.
You can still create logs for a previous quarter after its cut-off date, as long as you complete them by the end-of-year deadline: <%= formatted_deadline %>.
<% end %> @@ -21,13 +20,13 @@Prioritise completing logs for the closing collection year. You must complete all <%= previous_lettings_form.start_date.year %> to <%= previous_lettings_form.submission_deadline.year %> logs must by the end-of-year deadline. You can still create <%= open_lettings_form.start_date.year %> to <%= open_lettings_form.submission_deadline.year %> logs for this quarter after the quarterly cut-off date.
<% end %> -<%= govuk_details(summary_text: "Quarterly cut-off dates for 2024 to 2025") do %> -The 2024 to 2025 quarterly cut-off dates are:
+<%= govuk_details(summary_text: "Quarterly cut-off dates for #{current_collection_start_year} to #{current_collection_end_year}") do %> +The <%= current_collection_start_year %> to <%= current_collection_end_year %> quarterly cut-off dates are:
It is important that you meet these cut-off dates because we submit data to the Office for National Statistics quarterly, helping them create essential inflation statistics.
Meeting these cut-off dates also gives you more accurate data for your own analysis, and reduces the burden at the end of the year.
diff --git a/spec/features/home_page_spec.rb b/spec/features/home_page_spec.rb new file mode 100644 index 000000000..60bab113e --- /dev/null +++ b/spec/features/home_page_spec.rb @@ -0,0 +1,96 @@ +require "rails_helper" + +RSpec.describe "Home Page Features" do + include CollectionTimeHelper + + let!(:user) { FactoryBot.create(:user) } + let(:storage_service) { instance_double(Storage::S3Service, get_file_metadata: nil) } + let(:current_collection_year) { 2024 } + let(:next_collection_year) { 2025 } + + before do + sign_in user + allow(Storage::S3Service).to receive(:new).and_return(storage_service) + allow(storage_service).to receive(:configuration).and_return(OpenStruct.new(bucket_name: "core-test-collection-resources")) + end + + context "when visiting during the current collection year" do + before do + allow(FormHandler.instance).to receive(:in_crossover_period?).and_return(false) + allow_any_instance_of(CollectionTimeHelper).to receive(:current_collection_start_year).and_return(current_collection_year) + allow_any_instance_of(CollectionTimeHelper).to receive(:current_collection_end_year).and_return(current_collection_year + 1) + visit root_path + find("span.govuk-details__summary-text", text: "Quarterly cut-off dates for 2024 to 2025").click + end + + after { travel_back } + + scenario "displays correct text for Q1" do + travel_to Time.zone.local(current_collection_year, 4, 1) do + expect(page).to have_content("Q1 - Friday 12 July 2024") + expect(page).to have_content("You can still create logs for a previous quarter after its cut-off date, as long as you complete them by the end-of-year deadline: Friday 6 June 2025.") + end + end + + scenario "displays correct text for Q2" do + travel_to Time.zone.local(current_collection_year, 7, 1) do + expect(page).to have_content("Q2 - Friday 11 October 2024") + expect(page).to have_content("You can still create logs for a previous quarter after its cut-off date, as long as you complete them by the end-of-year deadline: Friday 6 June 2025.") + end + end + + scenario "displays correct text for Q3" do + travel_to Time.zone.local(current_collection_year, 10, 1) do + expect(page).to have_content("Q3 - Friday 10 January 2025") + expect(page).to have_content("You can still create logs for a previous quarter after its cut-off date, as long as you complete them by the end-of-year deadline: Friday 6 June 2025.") + end + end + + scenario "displays correct text for Q4" do + travel_to Time.zone.local(current_collection_year + 1, 3, 1) do + expect(page).to have_content("End of year deadline - Friday 6 June 2025") + expect(page).to have_content("You can still create logs for a previous quarter after its cut-off date, as long as you complete them by the end-of-year deadline: Friday 6 June 2025.") + end + end + end + + context "when visiting during the next collection year" do + before do + allow(FormHandler.instance).to receive(:in_crossover_period?).and_return(false) + allow_any_instance_of(CollectionTimeHelper).to receive(:current_collection_start_year).and_return(next_collection_year) + allow_any_instance_of(CollectionTimeHelper).to receive(:current_collection_end_year).and_return(next_collection_year + 1) + visit root_path + find("span.govuk-details__summary-text", text: "Quarterly cut-off dates for 2025 to 2026").click + end + + after { travel_back } + + scenario "displays correct text for Q1" do + travel_to Time.zone.local(next_collection_year, 4, 1) do + expect(page).to have_content("Q1 - Friday 11 July 2025") + expect(page).to have_content("You can still create logs for a previous quarter after its cut-off date, as long as you complete them by the end-of-year deadline: Friday 5 June 2026.") + end + end + + scenario "displays correct text for Q2" do + travel_to Time.zone.local(next_collection_year, 7, 1) do + expect(page).to have_content("Q2 - Friday 10 October 2025") + expect(page).to have_content("You can still create logs for a previous quarter after its cut-off date, as long as you complete them by the end-of-year deadline: Friday 5 June 2026.") + end + end + + scenario "displays correct text for Q3" do + travel_to Time.zone.local(next_collection_year, 10, 1) do + expect(page).to have_content("Q3 - Friday 16 January 2026") + expect(page).to have_content("You can still create logs for a previous quarter after its cut-off date, as long as you complete them by the end-of-year deadline: Friday 5 June 2026.") + end + end + + scenario "displays correct text for Q4" do + travel_to Time.zone.local(next_collection_year + 1, 3, 1) do + expect(page).to have_content("End of year deadline - Friday 5 June 2026") + expect(page).to have_content("You can still create logs for a previous quarter after its cut-off date, as long as you complete them by the end-of-year deadline: Friday 5 June 2026.") + end + end + end +end diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index c663087d5..10ae7fced 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -50,6 +50,9 @@ rescue ActiveRecord::PendingMigrationError => e exit 1 end RSpec.configure do |config| + + config.include ActiveSupport::Testing::TimeHelpers + # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures config.fixture_paths = ["#{::Rails.root}/spec/fixtures"]