Browse Source

Update new logs end date

pull/1716/head
Kat 2 years ago
parent
commit
c48bd78526
  1. 8
      app/models/form.rb
  2. 21
      spec/requests/locations_controller_spec.rb
  3. 2
      spec/requests/schemes_controller_spec.rb

8
app/models/form.rb

@ -6,11 +6,7 @@ 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 = if start_year && start_year.to_i > 2022 @new_logs_end_date = Time.zone.local(start_year + 1, 12, 29) # this is to be manually updated each year when we want to stop users from creating new logs
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 @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
@ -43,7 +39,7 @@ 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.iso8601(form_definition["end_date"]) @new_logs_end_date = Time.zone.local(@start_date.year + 1, 12, 29)
@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, 12, 31)
@unresolved_log_redirect_page_id = form_definition["unresolved_log_redirect_page_id"] @unresolved_log_redirect_page_id = form_definition["unresolved_log_redirect_page_id"]

21
spec/requests/locations_controller_spec.rb

@ -1401,7 +1401,7 @@ RSpec.describe LocationsController, type: :request do
let(:setup_locations) { nil } let(:setup_locations) { nil }
before do before do
Timecop.freeze(Time.utc(2022, 10, 10)) Timecop.freeze(Time.utc(2023, 10, 10))
sign_in user sign_in user
add_deactivations add_deactivations
setup_locations setup_locations
@ -1608,7 +1608,7 @@ RSpec.describe LocationsController, type: :request do
end end
end end
context "when the date is entered is before the beginning of current collection window" do context "when the date entered is before the beginning of current collection window" do
let(:params) { { location_deactivation_period: { deactivation_date_type: "other", "deactivation_date(3i)": "10", "deactivation_date(2i)": "4", "deactivation_date(1i)": "2020" } } } let(:params) { { location_deactivation_period: { deactivation_date_type: "other", "deactivation_date(3i)": "10", "deactivation_date(2i)": "4", "deactivation_date(1i)": "2020" } } }
it "displays the new page with an error message" do it "displays the new page with an error message" do
@ -1656,9 +1656,9 @@ RSpec.describe LocationsController, type: :request do
end end
context "when there is an earlier open deactivation" do context "when there is an earlier open deactivation" do
let(:deactivation_date) { Time.zone.local(2022, 10, 10) } let(:deactivation_date) { Time.zone.local(2023, 10, 10) }
let(:params) { { location_deactivation_period: { deactivation_date_type: "other", "deactivation_date(3i)": "8", "deactivation_date(2i)": "9", "deactivation_date(1i)": "2023" } } } let(:params) { { location_deactivation_period: { deactivation_date_type: "other", "deactivation_date(3i)": "8", "deactivation_date(2i)": "9", "deactivation_date(1i)": "2024" } } }
let(:add_deactivations) { create(:location_deactivation_period, deactivation_date: Time.zone.local(2023, 6, 5), reactivation_date: nil, location:) } let(:add_deactivations) { create(:location_deactivation_period, deactivation_date: Time.zone.local(2024, 6, 5), reactivation_date: nil, location:) }
it "redirects to the location page and updates the existing deactivation period" do it "redirects to the location page and updates the existing deactivation period" do
follow_redirect! follow_redirect!
@ -1667,14 +1667,13 @@ RSpec.describe LocationsController, type: :request do
expect(page).to have_css(".govuk-notification-banner.govuk-notification-banner--success") expect(page).to have_css(".govuk-notification-banner.govuk-notification-banner--success")
location.reload location.reload
expect(location.location_deactivation_periods.count).to eq(1) expect(location.location_deactivation_periods.count).to eq(1)
expect(location.location_deactivation_periods.first.deactivation_date).to eq(Time.zone.local(2023, 9, 8)) expect(location.location_deactivation_periods.first.deactivation_date).to eq(Time.zone.local(2024, 9, 8))
end end
end end
context "when there is a later open deactivation" do context "when there is a later open deactivation" do
let(:deactivation_date) { Time.zone.local(2022, 10, 10) }
let(:params) { { location_deactivation_period: { deactivation_date_type: "other", "deactivation_date(3i)": "8", "deactivation_date(2i)": "9", "deactivation_date(1i)": "2022" } } } let(:params) { { location_deactivation_period: { deactivation_date_type: "other", "deactivation_date(3i)": "8", "deactivation_date(2i)": "9", "deactivation_date(1i)": "2022" } } }
let(:add_deactivations) { create(:location_deactivation_period, deactivation_date: Time.zone.local(2023, 6, 5), reactivation_date: nil, location:) } let(:add_deactivations) { create(:location_deactivation_period, deactivation_date: Time.zone.local(2024, 6, 5), reactivation_date: nil, location:) }
it "redirects to the confirmation page" do it "redirects to the confirmation page" do
follow_redirect! follow_redirect!
@ -1833,7 +1832,7 @@ RSpec.describe LocationsController, type: :request do
let(:startdate) { Time.utc(2022, 9, 11) } let(:startdate) { Time.utc(2022, 9, 11) }
before do before do
Timecop.freeze(Time.utc(2022, 9, 10)) Timecop.freeze(Time.utc(2023, 1, 10))
sign_in user sign_in user
create(:location_deactivation_period, deactivation_date:, location:) create(:location_deactivation_period, deactivation_date:, location:)
location.save! location.save!
@ -1882,13 +1881,13 @@ RSpec.describe LocationsController, type: :request do
end end
context "with other future date" do context "with other future date" do
let(:params) { { location_deactivation_period: { reactivation_date_type: "other", "reactivation_date(3i)": "14", "reactivation_date(2i)": "12", "reactivation_date(1i)": "2022" } } } let(:params) { { location_deactivation_period: { reactivation_date_type: "other", "reactivation_date(3i)": "14", "reactivation_date(2i)": "12", "reactivation_date(1i)": "2023" } } }
it "redirects to the location page and displays a success banner" do it "redirects to the location page and displays a success banner" do
expect(response).to redirect_to("/schemes/#{scheme.id}/locations/#{location.id}") expect(response).to redirect_to("/schemes/#{scheme.id}/locations/#{location.id}")
follow_redirect! follow_redirect!
expect(page).to have_css(".govuk-notification-banner.govuk-notification-banner--success") expect(page).to have_css(".govuk-notification-banner.govuk-notification-banner--success")
expect(page).to have_content("#{location.name} will reactivate on 14 December 2022") expect(page).to have_content("#{location.name} will reactivate on 14 December 2023")
end end
end end

2
spec/requests/schemes_controller_spec.rb

@ -1893,7 +1893,7 @@ RSpec.describe SchemesController, type: :request do
let(:setup_schemes) { nil } let(:setup_schemes) { nil }
before do before do
Timecop.freeze(Time.utc(2022, 10, 10)) Timecop.freeze(Time.utc(2023, 10, 10))
sign_in user sign_in user
setup_schemes setup_schemes
patch "/schemes/#{scheme.id}/new-deactivation", params: patch "/schemes/#{scheme.id}/new-deactivation", params:

Loading…
Cancel
Save