From afa5ae7fdbf35901368cd0c8ea0aa517c0504a88 Mon Sep 17 00:00:00 2001 From: natdeanlewissoftwire <94526761+natdeanlewissoftwire@users.noreply.github.com> Date: Mon, 6 Nov 2023 17:04:58 +0000 Subject: [PATCH 1/2] Fix flaky tests (#2019) * feat: set encoding by bom for file IO before parsing * feat: set bom encoding for illness task as well * feat: use StringIOs in testing and fix row count bug found * feat: revert toheaders: false * feat: timecop around tests * feat: timecop around tests * feat: fix flaky merge test --- spec/lib/tasks/send_missing_addresses_csv_spec.rb | 13 +++++++------ .../merge/merge_organisations_service_spec.rb | 12 ++++-------- 2 files changed, 11 insertions(+), 14 deletions(-) diff --git a/spec/lib/tasks/send_missing_addresses_csv_spec.rb b/spec/lib/tasks/send_missing_addresses_csv_spec.rb index 78b3c25e6..3f2ab8529 100644 --- a/spec/lib/tasks/send_missing_addresses_csv_spec.rb +++ b/spec/lib/tasks/send_missing_addresses_csv_spec.rb @@ -5,9 +5,14 @@ RSpec.describe "correct_addresses" do describe ":send_missing_addresses_lettings_csv", type: :task do subject(:task) { Rake::Task["correct_addresses:send_missing_addresses_lettings_csv"] } + around do |example| + Timecop.freeze(Time.zone.local(2023, 10, 10)) do + Singleton.__init__(FormHandler) + example.run + end + end + before do - Timecop.travel(Time.zone.local(2023, 10, 10)) - Singleton.__init__(FormHandler) organisation.users.destroy_all Rake.application.rake_require("tasks/send_missing_addresses_csv") Rake::Task.define_task(:environment) @@ -44,10 +49,6 @@ RSpec.describe "correct_addresses" do .to_return(status: 200, body: body_2, headers: {}) end - after do - Timecop.return - end - context "when the rake task is run" do let(:organisation) { create(:organisation, name: "test organisation") } diff --git a/spec/services/merge/merge_organisations_service_spec.rb b/spec/services/merge/merge_organisations_service_spec.rb index 4e3300170..ad15975ad 100644 --- a/spec/services/merge/merge_organisations_service_spec.rb +++ b/spec/services/merge/merge_organisations_service_spec.rb @@ -141,7 +141,6 @@ RSpec.describe Merge::MergeOrganisationsService do let!(:owned_lettings_log_no_location) { create(:lettings_log, :sh, scheme:, startdate: Time.zone.tomorrow, owning_organisation: merging_organisation) } before do - create(:location, scheme:, name: "fake location", postcode: "A1 1AA") create(:location, scheme: deactivated_scheme) create(:scheme_deactivation_period, scheme: deactivated_scheme, deactivation_date: Time.zone.today - 1.month) create(:location_deactivation_period, location: deactivated_location, deactivation_date: Time.zone.today - 1.month) @@ -162,7 +161,7 @@ RSpec.describe Merge::MergeOrganisationsService do expect(absorbing_organisation.owned_schemes.first.service_name).to eq(scheme.service_name) expect(absorbing_organisation.owned_schemes.first.old_id).to be_nil expect(absorbing_organisation.owned_schemes.first.old_visible_id).to be_nil - expect(absorbing_organisation.owned_schemes.first.locations.count).to eq(2) + expect(absorbing_organisation.owned_schemes.first.locations.count).to eq(1) expect(absorbing_organisation.owned_schemes.first.locations.first.postcode).to eq(location.postcode) expect(absorbing_organisation.owned_schemes.first.locations.first.old_id).to be_nil expect(absorbing_organisation.owned_schemes.first.locations.first.old_visible_id).to be_nil @@ -312,7 +311,6 @@ RSpec.describe Merge::MergeOrganisationsService do let!(:owned_lettings_log_no_location) { create(:lettings_log, :sh, scheme:, startdate: Time.zone.tomorrow, owning_organisation: merging_organisation) } before do - create(:location, scheme:, name: "fake location", postcode: "A1 1AA") create(:location, scheme: deactivated_scheme) create(:scheme_deactivation_period, scheme: deactivated_scheme, deactivation_date: Time.zone.today - 1.month) create(:location_deactivation_period, location: deactivated_location, deactivation_date: Time.zone.today - 1.month) @@ -331,7 +329,7 @@ RSpec.describe Merge::MergeOrganisationsService do absorbing_organisation.reload expect(absorbing_organisation.owned_schemes.count).to eq(1) expect(absorbing_organisation.owned_schemes.first.service_name).to eq(scheme.service_name) - expect(absorbing_organisation.owned_schemes.first.locations.count).to eq(2) + expect(absorbing_organisation.owned_schemes.first.locations.count).to eq(1) expect(absorbing_organisation.owned_schemes.first.locations.first.postcode).to eq(location.postcode) expect(scheme.scheme_deactivation_periods.count).to eq(1) expect(scheme.scheme_deactivation_periods.first.deactivation_date.to_date).to eq(Time.zone.yesterday) @@ -652,7 +650,6 @@ RSpec.describe Merge::MergeOrganisationsService do let!(:owned_lettings_log_no_location) { create(:lettings_log, :sh, scheme:, startdate: Time.zone.tomorrow, owning_organisation: merging_organisation) } before do - create(:location, scheme:, name: "fake location", postcode: "A1 1AA") create(:location, scheme: deactivated_scheme) create(:scheme_deactivation_period, scheme: deactivated_scheme, deactivation_date: Time.zone.today - 1.month) create(:location_deactivation_period, location: deactivated_location, deactivation_date: Time.zone.today - 1.month) @@ -673,7 +670,7 @@ RSpec.describe Merge::MergeOrganisationsService do expect(new_absorbing_organisation.owned_schemes.first.service_name).to eq(scheme.service_name) expect(new_absorbing_organisation.owned_schemes.first.old_id).to be_nil expect(new_absorbing_organisation.owned_schemes.first.old_visible_id).to be_nil - expect(new_absorbing_organisation.owned_schemes.first.locations.count).to eq(2) + expect(new_absorbing_organisation.owned_schemes.first.locations.count).to eq(1) expect(new_absorbing_organisation.owned_schemes.first.locations.first.postcode).to eq(location.postcode) expect(new_absorbing_organisation.owned_schemes.first.locations.first.old_id).to be_nil expect(new_absorbing_organisation.owned_schemes.first.locations.first.old_visible_id).to be_nil @@ -823,7 +820,6 @@ RSpec.describe Merge::MergeOrganisationsService do let!(:owned_lettings_log_no_location) { create(:lettings_log, :sh, scheme:, startdate: Time.zone.tomorrow, owning_organisation: merging_organisation) } before do - create(:location, scheme:, name: "fake location", postcode: "A1 1AA") create(:location, scheme: deactivated_scheme) create(:scheme_deactivation_period, scheme: deactivated_scheme, deactivation_date: Time.zone.today - 1.month) create(:location_deactivation_period, location: deactivated_location, deactivation_date: Time.zone.today - 1.month) @@ -842,7 +838,7 @@ RSpec.describe Merge::MergeOrganisationsService do new_absorbing_organisation.reload expect(new_absorbing_organisation.owned_schemes.count).to eq(1) expect(new_absorbing_organisation.owned_schemes.first.service_name).to eq(scheme.service_name) - expect(new_absorbing_organisation.owned_schemes.first.locations.count).to eq(2) + expect(new_absorbing_organisation.owned_schemes.first.locations.count).to eq(1) expect(new_absorbing_organisation.owned_schemes.first.locations.first.postcode).to eq(location.postcode) expect(scheme.scheme_deactivation_periods.count).to eq(1) expect(scheme.scheme_deactivation_periods.first.deactivation_date.to_date).to eq(Time.zone.yesterday) From e6899d46d8884ad94dbc9374f8c995815d7c8d2e Mon Sep 17 00:00:00 2001 From: SamSeed-Softwire <63662292+SamSeed-Softwire@users.noreply.github.com> Date: Mon, 6 Nov 2023 17:37:17 +0000 Subject: [PATCH 2/2] CLDC-2862: Prepare maintenance page for PaaS app (#2006) * CLDC-2862: first attempt at creating maintenance page * CLDC-2907: try turning off maintenance mode to see if tests pass * CLDC-2862: write tests for MaintenanceController * CLDC-2862: test header bar links hidden in maintenance mode * CLDC-2862: lint * CLDC-2862: add requests tests * CLDC-2862: try disabling schduled job in maintenance mode * CLDC-2862: turn on maintenance mode temporarily * CLDC-2862: turn off maintenance mode again * CLDC-2862: ensure cookies, notices etc still available in maintenance mode * CLDC-2862: update content on maintenance page * CLDC-2862: destroy sidekiq cron jobs on shutdown * CLDC-2862: turn maintenance mode back on * CLDC-2862: try destroying cron jobs on startup * CLDC-2862: try destroying cron jobs on shutdown again, but with fix * CLDC-2862: turn maintenance mode off again * CLDC-2862: move job destruction to sidekiq server startup * CLDC-2862: turn MM back on * CLDC-2862: turn MM off again * CLDC-2862: update 'contact the helpdesk' content * CLDC-2862: check notices/statements still viewable in MM * CLDC-2862: check cookies page still viewable in MM * CLDC-2862: confirm cookie banner visible regardless of MM * CLDC-2862: reenable MM * CLDC-2862: turn maintenance mode off again --- app/controllers/application_controller.rb | 9 ++ app/controllers/maintenance_controller.rb | 7 ++ app/services/feature_toggle.rb | 4 + app/views/layouts/application.html.erb | 12 +-- .../maintenance/service_unavailable.html.erb | 11 +++ config/initializers/sidekiq.rb | 5 +- config/routes.rb | 1 + .../maintenance_controller_spec.rb | 27 ++++++ spec/features/user_spec.rb | 13 +++ spec/requests/content_controller_spec.rb | 84 ++++++++++++------ spec/requests/cookies_controller_spec.rb | 42 +++++++++ spec/requests/maintenance_controller_spec.rb | 85 +++++++++++++++++++ 12 files changed, 270 insertions(+), 30 deletions(-) create mode 100644 app/controllers/maintenance_controller.rb create mode 100644 app/views/maintenance/service_unavailable.html.erb create mode 100644 spec/controllers/maintenance_controller_spec.rb create mode 100644 spec/requests/cookies_controller_spec.rb create mode 100644 spec/requests/maintenance_controller_spec.rb diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index ff085e6dc..ae9e1beb9 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -3,8 +3,17 @@ class ApplicationController < ActionController::Base rescue_from Pundit::NotAuthorizedError, with: :render_not_authorized + before_action :check_maintenance before_action :set_paper_trail_whodunnit + def check_maintenance + if FeatureToggle.maintenance_mode_enabled? && !%w[service-unavailable accessibility-statement privacy-notice cookies].include?(request.fullpath.split("?")[0].delete("/")) + redirect_to service_unavailable_path + elsif !FeatureToggle.maintenance_mode_enabled? && request.fullpath.split("?")[0].delete("/") == "service-unavailable" + redirect_back(fallback_location: root_path) + end + end + def render_not_found render "errors/not_found", status: :not_found end diff --git a/app/controllers/maintenance_controller.rb b/app/controllers/maintenance_controller.rb new file mode 100644 index 000000000..bb6ae1f80 --- /dev/null +++ b/app/controllers/maintenance_controller.rb @@ -0,0 +1,7 @@ +class MaintenanceController < ApplicationController + def service_unavailable + if current_user + sign_out + end + end +end diff --git a/app/services/feature_toggle.rb b/app/services/feature_toggle.rb index 379f51905..3cad5dadb 100644 --- a/app/services/feature_toggle.rb +++ b/app/services/feature_toggle.rb @@ -37,4 +37,8 @@ class FeatureToggle def self.duplicate_summary_enabled? !Rails.env.production? end + + def self.maintenance_mode_enabled? + false + end end diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index ead90793a..d70c1e09a 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -91,11 +91,13 @@ navigation_classes: "govuk-header__navigation--end", ) do |component| component.product_name(name: t("service_name")) - if current_user.nil? - component.navigation_item(text: "Sign in", href: user_session_path) - else - component.navigation_item(text: "Your account", href: account_path) - component.navigation_item(text: "Sign out", href: destroy_user_session_path) + unless FeatureToggle.maintenance_mode_enabled? + if current_user.nil? + component.navigation_item(text: "Sign in", href: user_session_path) + else + component.navigation_item(text: "Your account", href: account_path) + component.navigation_item(text: "Sign out", href: destroy_user_session_path) + end end end %> diff --git a/app/views/maintenance/service_unavailable.html.erb b/app/views/maintenance/service_unavailable.html.erb new file mode 100644 index 000000000..cb106ce8d --- /dev/null +++ b/app/views/maintenance/service_unavailable.html.erb @@ -0,0 +1,11 @@ +
You will be able to use the service from 9am on Thursday 16 November 2023.
+Changes from the page you were on have not been saved. Changes on pages where you have selected 'save and continue' have been saved.
+<%= govuk_link_to "Contact the helpdesk", "https://dluhcdigital.atlassian.net/servicedesk/customer/portal/6/group/11" %> if you need help.
+