From d30ade5e845d952fddaf642f8c8dad4f536b2369 Mon Sep 17 00:00:00 2001 From: natdeanlewissoftwire <94526761+natdeanlewissoftwire@users.noreply.github.com> Date: Fri, 17 Nov 2023 10:20:30 +0000 Subject: [PATCH 1/7] CLDC-3031 Put merge validations behind feature toggle (#2029) * feat: put merge validations behind feature toggle * feat: put merge validations behind feature toggle for sales * refactor: lint --- .../validations/sales/setup_validations.rb | 2 ++ app/models/validations/setup_validations.rb | 28 ++++++++++++++++--- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/app/models/validations/sales/setup_validations.rb b/app/models/validations/sales/setup_validations.rb index d52af8f9b..240528712 100644 --- a/app/models/validations/sales/setup_validations.rb +++ b/app/models/validations/sales/setup_validations.rb @@ -25,6 +25,7 @@ module Validations::Sales::SetupValidations end def validate_merged_organisations_saledate(record) + return unless FeatureToggle.merge_organisations_enabled? return unless record.saledate && date_valid?("saledate", record) if merged_owning_organisation_inactive?(record) @@ -42,6 +43,7 @@ module Validations::Sales::SetupValidations end def validate_organisation(record) + return unless FeatureToggle.merge_organisations_enabled? return unless record.saledate && record.owning_organisation if record.owning_organisation.present? diff --git a/app/models/validations/setup_validations.rb b/app/models/validations/setup_validations.rb index 3fd760c30..07765d2ce 100644 --- a/app/models/validations/setup_validations.rb +++ b/app/models/validations/setup_validations.rb @@ -48,13 +48,24 @@ module Validations::SetupValidations def validate_organisation(record) created_by, managing_organisation, owning_organisation = record.values_at("created_by", "managing_organisation", "owning_organisation") - unless [created_by, managing_organisation, owning_organisation].any?(&:blank?) || ((created_by.organisation.absorbed_organisations + [created_by.organisation]) & [managing_organisation, owning_organisation]).present? - record.errors.add :created_by, I18n.t("validations.setup.created_by.invalid") - record.errors.add :owning_organisation_id, I18n.t("validations.setup.owning_organisation.invalid") - record.errors.add :managing_organisation_id, I18n.t("validations.setup.managing_organisation.invalid") + if FeatureToggle.merge_organisations_enabled? + unless [created_by, managing_organisation, owning_organisation].any?(&:blank?) || ((created_by.organisation.absorbed_organisations + [created_by.organisation]) & [managing_organisation, owning_organisation]).present? + record.errors.add :created_by, I18n.t("validations.setup.created_by.invalid") + record.errors.add :owning_organisation_id, I18n.t("validations.setup.owning_organisation.invalid") + record.errors.add :managing_organisation_id, I18n.t("validations.setup.managing_organisation.invalid") + end + else + unless [created_by, managing_organisation, owning_organisation].any?(&:blank?) || ([created_by.organisation] & [managing_organisation, owning_organisation]).present? + record.errors.add :created_by, I18n.t("validations.setup.created_by.invalid") + record.errors.add :owning_organisation_id, I18n.t("validations.setup.owning_organisation.invalid") + record.errors.add :managing_organisation_id, I18n.t("validations.setup.managing_organisation.invalid") + end + end return unless record.startdate + return unless FeatureToggle.merge_organisations_enabled? + if owning_organisation.present? if owning_organisation&.merge_date.present? && owning_organisation.merge_date <= record.startdate record.errors.add :owning_organisation_id, I18n.t("validations.setup.owning_organisation.inactive_merged_organisation", @@ -134,6 +145,7 @@ private end def validate_merged_organisations_start_date(record) + return unless FeatureToggle.merge_organisations_enabled? return add_same_merge_organisation_error(record) if record.owning_organisation == record.managing_organisation return add_same_merge_error(record) if organisations_belong_to_same_merge?(record.owning_organisation, record.managing_organisation) @@ -142,6 +154,8 @@ private end def add_same_merge_organisation_error(record) + return unless FeatureToggle.merge_organisations_enabled? + if merged_owning_organisation_inactive?(record) record.errors.add :startdate, I18n.t("validations.setup.startdate.invalid_merged_organisations_start_date.same_organisation", owning_organisation: record.owning_organisation.name, @@ -155,6 +169,8 @@ private end def add_same_merge_error(record) + return unless FeatureToggle.merge_organisations_enabled? + if merged_owning_organisation_inactive?(record) record.errors.add :startdate, I18n.t("validations.setup.startdate.invalid_merged_organisations_start_date.same_merge", owning_organisation: record.owning_organisation.name, @@ -165,6 +181,8 @@ private end def add_merged_organisations_errors(record) + return unless FeatureToggle.merge_organisations_enabled? + if merged_owning_organisation_inactive?(record) && merged_managing_organisation_inactive?(record) record.errors.add :startdate, I18n.t("validations.setup.startdate.invalid_merged_organisations_start_date.different_merge", owning_organisation: record.owning_organisation.name, @@ -191,6 +209,8 @@ private end def add_absorbing_organisations_errors(record) + return unless FeatureToggle.merge_organisations_enabled? + if absorbing_owning_organisation_inactive?(record) && absorbing_managing_organisation_inactive?(record) record.errors.add :startdate, I18n.t("validations.setup.startdate.invalid_absorbing_organisations_start_date.different_organisations", owning_organisation: record.owning_organisation.name, From 283917bb8320b1de16f49ea9a08eddcd8ea217ba Mon Sep 17 00:00:00 2001 From: natdeanlewissoftwire <94526761+natdeanlewissoftwire@users.noreply.github.com> Date: Fri, 17 Nov 2023 11:16:37 +0000 Subject: [PATCH 2/7] Revert "CLDC-3031 Put merge validations behind feature toggle (#2029)" (#2041) This reverts commit d30ade5e845d952fddaf642f8c8dad4f536b2369. --- .../validations/sales/setup_validations.rb | 2 -- app/models/validations/setup_validations.rb | 28 +++---------------- 2 files changed, 4 insertions(+), 26 deletions(-) diff --git a/app/models/validations/sales/setup_validations.rb b/app/models/validations/sales/setup_validations.rb index 240528712..d52af8f9b 100644 --- a/app/models/validations/sales/setup_validations.rb +++ b/app/models/validations/sales/setup_validations.rb @@ -25,7 +25,6 @@ module Validations::Sales::SetupValidations end def validate_merged_organisations_saledate(record) - return unless FeatureToggle.merge_organisations_enabled? return unless record.saledate && date_valid?("saledate", record) if merged_owning_organisation_inactive?(record) @@ -43,7 +42,6 @@ module Validations::Sales::SetupValidations end def validate_organisation(record) - return unless FeatureToggle.merge_organisations_enabled? return unless record.saledate && record.owning_organisation if record.owning_organisation.present? diff --git a/app/models/validations/setup_validations.rb b/app/models/validations/setup_validations.rb index 07765d2ce..3fd760c30 100644 --- a/app/models/validations/setup_validations.rb +++ b/app/models/validations/setup_validations.rb @@ -48,24 +48,13 @@ module Validations::SetupValidations def validate_organisation(record) created_by, managing_organisation, owning_organisation = record.values_at("created_by", "managing_organisation", "owning_organisation") - if FeatureToggle.merge_organisations_enabled? - unless [created_by, managing_organisation, owning_organisation].any?(&:blank?) || ((created_by.organisation.absorbed_organisations + [created_by.organisation]) & [managing_organisation, owning_organisation]).present? - record.errors.add :created_by, I18n.t("validations.setup.created_by.invalid") - record.errors.add :owning_organisation_id, I18n.t("validations.setup.owning_organisation.invalid") - record.errors.add :managing_organisation_id, I18n.t("validations.setup.managing_organisation.invalid") - end - else - unless [created_by, managing_organisation, owning_organisation].any?(&:blank?) || ([created_by.organisation] & [managing_organisation, owning_organisation]).present? - record.errors.add :created_by, I18n.t("validations.setup.created_by.invalid") - record.errors.add :owning_organisation_id, I18n.t("validations.setup.owning_organisation.invalid") - record.errors.add :managing_organisation_id, I18n.t("validations.setup.managing_organisation.invalid") - end - + unless [created_by, managing_organisation, owning_organisation].any?(&:blank?) || ((created_by.organisation.absorbed_organisations + [created_by.organisation]) & [managing_organisation, owning_organisation]).present? + record.errors.add :created_by, I18n.t("validations.setup.created_by.invalid") + record.errors.add :owning_organisation_id, I18n.t("validations.setup.owning_organisation.invalid") + record.errors.add :managing_organisation_id, I18n.t("validations.setup.managing_organisation.invalid") end return unless record.startdate - return unless FeatureToggle.merge_organisations_enabled? - if owning_organisation.present? if owning_organisation&.merge_date.present? && owning_organisation.merge_date <= record.startdate record.errors.add :owning_organisation_id, I18n.t("validations.setup.owning_organisation.inactive_merged_organisation", @@ -145,7 +134,6 @@ private end def validate_merged_organisations_start_date(record) - return unless FeatureToggle.merge_organisations_enabled? return add_same_merge_organisation_error(record) if record.owning_organisation == record.managing_organisation return add_same_merge_error(record) if organisations_belong_to_same_merge?(record.owning_organisation, record.managing_organisation) @@ -154,8 +142,6 @@ private end def add_same_merge_organisation_error(record) - return unless FeatureToggle.merge_organisations_enabled? - if merged_owning_organisation_inactive?(record) record.errors.add :startdate, I18n.t("validations.setup.startdate.invalid_merged_organisations_start_date.same_organisation", owning_organisation: record.owning_organisation.name, @@ -169,8 +155,6 @@ private end def add_same_merge_error(record) - return unless FeatureToggle.merge_organisations_enabled? - if merged_owning_organisation_inactive?(record) record.errors.add :startdate, I18n.t("validations.setup.startdate.invalid_merged_organisations_start_date.same_merge", owning_organisation: record.owning_organisation.name, @@ -181,8 +165,6 @@ private end def add_merged_organisations_errors(record) - return unless FeatureToggle.merge_organisations_enabled? - if merged_owning_organisation_inactive?(record) && merged_managing_organisation_inactive?(record) record.errors.add :startdate, I18n.t("validations.setup.startdate.invalid_merged_organisations_start_date.different_merge", owning_organisation: record.owning_organisation.name, @@ -209,8 +191,6 @@ private end def add_absorbing_organisations_errors(record) - return unless FeatureToggle.merge_organisations_enabled? - if absorbing_owning_organisation_inactive?(record) && absorbing_managing_organisation_inactive?(record) record.errors.add :startdate, I18n.t("validations.setup.startdate.invalid_absorbing_organisations_start_date.different_organisations", owning_organisation: record.owning_organisation.name, From 190675749ccb3dda6405b022dde7e3b63bc07a4a Mon Sep 17 00:00:00 2001 From: kosiakkatrina <54268893+kosiakkatrina@users.noreply.github.com> Date: Mon, 20 Nov 2023 09:54:42 +0000 Subject: [PATCH 3/7] Make scheme search by code case insensitive (#2037) --- app/models/scheme.rb | 2 +- spec/models/scheme_spec.rb | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/app/models/scheme.rb b/app/models/scheme.rb index 254953c19..9d760998d 100644 --- a/app/models/scheme.rb +++ b/app/models/scheme.rb @@ -6,7 +6,7 @@ class Scheme < ApplicationRecord has_paper_trail - scope :filter_by_id, ->(id) { where(id: (id.start_with?("S") ? id[1..] : id)) } + scope :filter_by_id, ->(id) { where(id: (id.start_with?("S", "s") ? id[1..] : id)) } scope :search_by_service_name, ->(name) { where("service_name ILIKE ?", "%#{name}%") } scope :search_by_postcode, ->(postcode) { where("schemes.id IN (SELECT DISTINCT scheme_id FROM locations WHERE REPLACE(locations.postcode, ' ', '') ILIKE ?)", "%#{postcode.delete(' ')}%") } scope :search_by_location_name, ->(name) { where("schemes.id IN (SELECT DISTINCT scheme_id FROM locations WHERE locations.name ILIKE ?)", "%#{name}%") } diff --git a/spec/models/scheme_spec.rb b/spec/models/scheme_spec.rb index 70eccc5c2..cb9d74578 100644 --- a/spec/models/scheme_spec.rb +++ b/spec/models/scheme_spec.rb @@ -77,6 +77,8 @@ RSpec.describe Scheme, type: :model do it "returns case insensitive matching records" do expect(described_class.search_by(scheme_1.id.to_s).count).to eq(1) + expect(described_class.search_by("S#{scheme_1.id}").count).to eq(1) + expect(described_class.search_by("s#{scheme_1.id}").count).to eq(1) expect(described_class.search_by(scheme_1.id.to_s).first.id).to eq(scheme_1.id) expect(described_class.search_by(scheme_2.service_name.upcase).count).to eq(1) expect(described_class.search_by(scheme_2.service_name.downcase).count).to eq(1) From fbe41885f8f9aa43d809b5c953f3ae095ab026d3 Mon Sep 17 00:00:00 2001 From: kosiakkatrina <54268893+kosiakkatrina@users.noreply.github.com> Date: Mon, 20 Nov 2023 11:45:29 +0000 Subject: [PATCH 4/7] CLDC-2739 Clear filter for a specific organisation (#2038) * Clear filter for a specific organisation * Fix filter links --- app/controllers/sessions_controller.rb | 6 +++++- app/helpers/filters_helper.rb | 4 ++++ app/views/logs/_log_filters.html.erb | 2 +- app/views/schemes/_scheme_filters.html.erb | 4 ++-- app/views/users/_user_filters.html.erb | 4 ++-- spec/features/schemes_spec.rb | 2 +- spec/features/user_spec.rb | 4 ++-- spec/requests/organisations_controller_spec.rb | 10 ++++++++++ 8 files changed, 27 insertions(+), 9 deletions(-) diff --git a/app/controllers/sessions_controller.rb b/app/controllers/sessions_controller.rb index 1e350829a..868b4936d 100644 --- a/app/controllers/sessions_controller.rb +++ b/app/controllers/sessions_controller.rb @@ -3,7 +3,11 @@ class SessionsController < ApplicationController session[session_name_for(params[:filter_type])] = "{}" path_params = params[:path_params].presence || {} - redirect_to send("#{params[:filter_type]}_path", scheme_id: path_params[:scheme_id], search: path_params[:search]) + if path_params[:organisation_id].present? + redirect_to send("#{params[:filter_type]}_organisation_path", id: path_params[:organisation_id], scheme_id: path_params[:scheme_id], search: path_params[:search]) + else + redirect_to send("#{params[:filter_type]}_path", scheme_id: path_params[:scheme_id], search: path_params[:search]) + end end private diff --git a/app/helpers/filters_helper.rb b/app/helpers/filters_helper.rb index 91038dbc9..2df2d21b1 100644 --- a/app/helpers/filters_helper.rb +++ b/app/helpers/filters_helper.rb @@ -139,6 +139,10 @@ module FiltersHelper request.path.include?("/lettings-logs") end + def specific_organisation_path? + request.path.include?("/organisations") + end + def applied_filters_count(filter_type) filters_count(applied_filters(filter_type)) end diff --git a/app/views/logs/_log_filters.html.erb b/app/views/logs/_log_filters.html.erb index 96e9eeeff..72f73e47c 100644 --- a/app/views/logs/_log_filters.html.erb +++ b/app/views/logs/_log_filters.html.erb @@ -12,7 +12,7 @@ <%= filters_applied_text(@filter_type) %>

- <%= reset_filters_link(@filter_type, { search: request.params["search"] }.compact) %> + <%= reset_filters_link(@filter_type, { search: request.params["search"], organisation_id: @organisation&.id }.compact) %>

<% if bulk_upload_options(@bulk_upload).present? %> diff --git a/app/views/schemes/_scheme_filters.html.erb b/app/views/schemes/_scheme_filters.html.erb index 6e66e38ba..af9ed093f 100644 --- a/app/views/schemes/_scheme_filters.html.erb +++ b/app/views/schemes/_scheme_filters.html.erb @@ -5,13 +5,13 @@
- <%= form_with url: schemes_path, html: { method: :get } do |f| %> + <%= form_with url: specific_organisation_path? ? schemes_organisation_path(@organisation) : schemes_path, html: { method: :get } do |f| %>

<%= filters_applied_text(@filter_type) %>

- <%= reset_filters_link(@filter_type, { search: request.params["search"] }.compact) %> + <%= reset_filters_link(@filter_type, { search: request.params["search"], organisation_id: @organisation&.id }.compact) %>

diff --git a/app/views/users/_user_filters.html.erb b/app/views/users/_user_filters.html.erb index 9547cbc86..d047beac7 100644 --- a/app/views/users/_user_filters.html.erb +++ b/app/views/users/_user_filters.html.erb @@ -5,13 +5,13 @@
- <%= form_with url: users_path, html: { method: :get } do |f| %> + <%= form_with url: specific_organisation_path? ? users_organisation_path(@organisation) : users_path, html: { method: :get } do |f| %>

<%= filters_applied_text(@filter_type) %>

- <%= reset_filters_link(@filter_type, { search: request.params["search"] }.compact) %> + <%= reset_filters_link(@filter_type, { search: request.params["search"], organisation_id: @organisation&.id }.compact) %>

diff --git a/spec/features/schemes_spec.rb b/spec/features/schemes_spec.rb index d7a9609f8..5d57b31e6 100644 --- a/spec/features/schemes_spec.rb +++ b/spec/features/schemes_spec.rb @@ -81,7 +81,7 @@ RSpec.describe "Schemes scheme Features" do it "displays the filters component with a correct count and clear button" do expect(page).to have_content("2 filters applied") - expect(page).to have_link("Clear", href: "/clear-filters?filter_type=schemes") + expect(page).to have_link("Clear", href: /clear-filters\?filter_type=schemes/) end context "when clearing the filters" do diff --git a/spec/features/user_spec.rb b/spec/features/user_spec.rb index ce0e1317f..2da53970b 100644 --- a/spec/features/user_spec.rb +++ b/spec/features/user_spec.rb @@ -252,7 +252,7 @@ RSpec.describe "User Features" do context "when no filters are selected" do it "displays the filters component with no clear button" do expect(page).to have_content("No filters applied") - expect(page).not_to have_link("Clear", href: "/clear-filters?filter_type=users") + expect(page).not_to have_link("Clear", href: /clear-filters\?filter_type=users/) end end @@ -265,7 +265,7 @@ RSpec.describe "User Features" do it "displays the filters component with a correct count and clear button" do expect(page).to have_content("2 filters applied") - expect(page).to have_link("Clear", href: "/clear-filters?filter_type=users") + expect(page).to have_link("Clear", href: /clear-filters\?filter_type=users/) end context "when clearing the filters" do diff --git a/spec/requests/organisations_controller_spec.rb b/spec/requests/organisations_controller_spec.rb index 340f1facf..4bd6e0eb6 100644 --- a/spec/requests/organisations_controller_spec.rb +++ b/spec/requests/organisations_controller_spec.rb @@ -1440,6 +1440,16 @@ RSpec.describe OrganisationsController, type: :request do }.to enqueue_job(EmailCsvJob).with(user, nil, {}, false, organisation, codes_only_export_type) end end + + context "when filters are applied" do + before do + get lettings_logs_organisation_path(organisation, status: %w[completed]) + end + + it "has clear filters link" do + expect(page).to have_link("Clear", href: clear_filters_path(filter_type: "lettings_logs", path_params: { organisation_id: organisation.id })) + end + end end context "when they view the sales logs tab" do From 86fde672e38dd79e796523a803c7c4289708f69a Mon Sep 17 00:00:00 2001 From: kosiakkatrina <54268893+kosiakkatrina@users.noreply.github.com> Date: Mon, 20 Nov 2023 14:01:01 +0000 Subject: [PATCH 5/7] Do not display secondary client group if not given (#2040) --- app/helpers/schemes_helper.rb | 4 ++-- spec/helpers/schemes_helper_spec.rb | 25 +++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/app/helpers/schemes_helper.rb b/app/helpers/schemes_helper.rb index 6b069fbbb..aea892a18 100644 --- a/app/helpers/schemes_helper.rb +++ b/app/helpers/schemes_helper.rb @@ -11,11 +11,11 @@ module SchemesHelper { name: "Support services provided by", value: scheme.arrangement_type }, { name: "Primary client group", value: scheme.primary_client_group }, { name: "Has another client group", value: scheme.has_other_client_group }, - { name: "Secondary client group", value: scheme.secondary_client_group }, + scheme.has_other_client_group == "Yes" ? { name: "Secondary client group", value: scheme.secondary_client_group } : nil, { name: "Level of support given", value: scheme.support_type }, { name: "Intended length of stay", value: scheme.intended_stay }, { name: "Availability", value: scheme_availability(scheme) }, - ] + ].compact end def scheme_availability(scheme) diff --git a/spec/helpers/schemes_helper_spec.rb b/spec/helpers/schemes_helper_spec.rb index 5aa825e79..ab4b8da5b 100644 --- a/spec/helpers/schemes_helper_spec.rb +++ b/spec/helpers/schemes_helper_spec.rb @@ -266,6 +266,31 @@ RSpec.describe SchemesHelper do end end end + + context "when scheme has no secondary client group" do + before do + scheme.update!(has_other_client_group: 0) + end + + it "returns correct display attributes" do + attributes = [ + { name: "Scheme code", value: "S#{scheme.id}" }, + { name: "Name", value: "Test service_name", edit: true }, + { name: "Status", value: status_tag(:incomplete) }, + { name: "Confidential information", value: "No", edit: true }, + { name: "Type of scheme", value: "Housing for older people" }, + { name: "Registered under Care Standards Act 2000", value: "Yes – registered care home providing personal care" }, + { name: "Housing stock owned by", value: "Acme LTD Owning", edit: true }, + { name: "Support services provided by", value: "A registered charity or voluntary organisation" }, + { name: "Primary client group", value: "Rough sleepers" }, + { name: "Has another client group", value: "No" }, + { name: "Level of support given", value: "High level" }, + { name: "Intended length of stay", value: "Permanent" }, + { name: "Availability", value: "Active from 1 April 2021" }, + ] + expect(display_scheme_attributes(scheme)).to eq(attributes) + end + end end describe "edit_scheme_text" do From dcf980a22b3967c95c8cabddbab5b0a4f5a1e106 Mon Sep 17 00:00:00 2001 From: kosiakkatrina <54268893+kosiakkatrina@users.noreply.github.com> Date: Mon, 20 Nov 2023 16:32:10 +0000 Subject: [PATCH 6/7] CLDC-2830 Update devise error messages (#2042) * Update error messages * Udate invalid token message * Update validation/error message order for password --- app/models/user.rb | 2 +- config/locales/devise.en.yml | 2 +- config/locales/en.yml | 4 +++- spec/requests/auth/passwords_controller_spec.rb | 2 +- spec/requests/users_controller_spec.rb | 2 +- 5 files changed, 7 insertions(+), 5 deletions(-) diff --git a/app/models/user.rb b/app/models/user.rb index 7042034b4..135d85428 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -15,8 +15,8 @@ class User < ApplicationRecord validates :email, uniqueness: { allow_blank: true, case_sensitive: true, if: :will_save_change_to_email? } validates :email, format: { with: Devise.email_regexp, allow_blank: true, if: :will_save_change_to_email? } validates :password, presence: { if: :password_required? } - validates :password, confirmation: { if: :password_required? } validates :password, length: { within: Devise.password_length, allow_blank: true } + validates :password, confirmation: { if: :password_required? } after_validation :send_data_protection_confirmation_reminder, if: :is_dpo_changed? diff --git a/config/locales/devise.en.yml b/config/locales/devise.en.yml index 16299ea10..e40af1d37 100644 --- a/config/locales/devise.en.yml +++ b/config/locales/devise.en.yml @@ -62,7 +62,7 @@ en: messages: already_confirmed: "Email has already been confirmed. Sign in." blank: "can’t be blank" - confirmation: "Password confirmation doesn’t match new password" + confirmation: "The passwords you entered do not match. Try again." confirmation_period_expired: "Email needs to be confirmed within %{period}. Request a new link below." expired: "Token has expired. Request a new token." not_found: "was not found" diff --git a/config/locales/en.yml b/config/locales/en.yml index 69a4a8bb9..b420e3088 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -164,7 +164,9 @@ en: blank: "Select role" password: blank: Enter a password - too_short: Password is too short (minimum is %{count} characters) + too_short: The password you entered is too short. Enter a password that is %{count} characters or longer. + reset_password_token: + invalid: "That link is invalid. Check you are using the correct link." merge_request: attributes: absorbing_organisation_id: diff --git a/spec/requests/auth/passwords_controller_spec.rb b/spec/requests/auth/passwords_controller_spec.rb index 29a032395..92c36608c 100644 --- a/spec/requests/auth/passwords_controller_spec.rb +++ b/spec/requests/auth/passwords_controller_spec.rb @@ -107,7 +107,7 @@ RSpec.describe Auth::PasswordsController, type: :request do put "/account/password", headers: headers, params: params expect(response).to have_http_status(:unprocessable_entity) expect(page).to have_css("h1", text: "Reset your password") - expect(page).to have_content("doesn’t match new password") + expect(page).to have_content("passwords you entered do not match") end end diff --git a/spec/requests/users_controller_spec.rb b/spec/requests/users_controller_spec.rb index 958f2187a..aad0b9f28 100644 --- a/spec/requests/users_controller_spec.rb +++ b/spec/requests/users_controller_spec.rb @@ -67,7 +67,7 @@ RSpec.describe UsersController, type: :request do expect(response).to have_http_status(:unprocessable_entity) expect(page).to have_css("h1", class: "govuk-heading-l", text: "Change your password") expect(page).to have_selector("#error-summary-title") - expect(page).to have_content("Password confirmation doesn’t match new password") + expect(page).to have_content("passwords you entered do not match") end end end From 118be80f8b044ac2ea16cb5645f6167c97efeb43 Mon Sep 17 00:00:00 2001 From: natdeanlewissoftwire <94526761+natdeanlewissoftwire@users.noreply.github.com> Date: Tue, 21 Nov 2023 09:19:43 +0000 Subject: [PATCH 7/7] CLDC-2962 hide uneditable duplicate sets (#2027) * feat: only show editable duplicate sets for user and org * feat: simplify and refactor * feat: update tests * feat: add and update tests * feat: reset not routed questions twice to catch newly not routed questions after the first set are cleared * Revert "feat: reset not routed questions twice to catch newly not routed questions after the first set are cleared" This reverts commit 300728467079afbf0bfb44b6d1542424c6840ca1. * TEST FOR PO TO BE REVERTED * TEST FOR PO TO BE REVERTED (set back to dec 31) * TEST UPDATE TESTS * REVERT THIS TEST UPDATE * REVERT THIS TEST UPDATE * feat: timecop tests * refactor: lint * feat: add update methods * feat: update tests (and TO BE REVERTED: change collection year) * feat: update tests * feat: update tests * feat: update form end_date tests REVERT LATER * feat: update tests * refactor: lint * feat: revert to previous end dates now passed PO review * feat: use scoping to simplify editable set logic --- app/helpers/duplicate_logs_helper.rb | 8 +- app/models/form_handler.rb | 16 ++++ app/models/lettings_log.rb | 4 +- app/models/organisation.rb | 8 +- app/models/sales_log.rb | 4 +- app/models/user.rb | 8 +- .../blank_migrated_soctenant_values_spec.rb | 39 ++++++---- spec/models/lettings_log_spec.rb | 11 ++- .../duplicate_logs_controller_spec.rb | 32 ++++---- spec/requests/form_controller_spec.rb | 9 +++ .../requests/lettings_logs_controller_spec.rb | 35 ++++++++- spec/requests/sales_logs_controller_spec.rb | 75 +++++++++++++++++++ .../bulk_upload/lettings/log_creator_spec.rb | 7 ++ .../bulk_upload/lettings/validator_spec.rb | 7 ++ .../lettings/year2022/row_parser_spec.rb | 9 ++- .../lettings/year2023/row_parser_spec.rb | 8 +- spec/services/bulk_upload/processor_spec.rb | 7 ++ .../sales/year2023/row_parser_spec.rb | 4 +- .../csv/missing_addresses_csv_service_spec.rb | 7 ++ .../sales_logs_field_import_service_spec.rb | 7 ++ 20 files changed, 243 insertions(+), 62 deletions(-) diff --git a/app/helpers/duplicate_logs_helper.rb b/app/helpers/duplicate_logs_helper.rb index ec8ac9185..8df911103 100644 --- a/app/helpers/duplicate_logs_helper.rb +++ b/app/helpers/duplicate_logs_helper.rb @@ -33,15 +33,15 @@ module DuplicateLogsHelper def duplicates_for_user(user) { - lettings: user.duplicate_lettings_logs_sets, - sales: user.duplicate_sales_logs_sets, + lettings: user.editable_duplicate_lettings_logs_sets, + sales: user.editable_duplicate_sales_logs_sets, } end def duplicates_for_organisation(organisation) { - lettings: organisation.duplicate_lettings_logs_sets, - sales: organisation.duplicate_sales_logs_sets, + lettings: organisation.editable_duplicate_lettings_logs_sets, + sales: organisation.editable_duplicate_sales_logs_sets, } end diff --git a/app/models/form_handler.rb b/app/models/form_handler.rb index 645efb1b4..83bfb0f8a 100644 --- a/app/models/form_handler.rb +++ b/app/models/form_handler.rb @@ -178,6 +178,22 @@ class FormHandler end end + def lettings_earliest_open_for_editing_collection_start_date(now: Time.zone.now) + if lettings_in_edit_crossover_period?(now:) + collection_start_date(now) - 1.year + else + collection_start_date(now) + end + end + + def sales_earliest_open_for_editing_collection_start_date(now: Time.zone.now) + if sales_in_edit_crossover_period?(now:) + collection_start_date(now) - 1.year + else + collection_start_date(now) + end + end + private def get_all_forms diff --git a/app/models/lettings_log.rb b/app/models/lettings_log.rb index 51dc6ff4d..cba85320a 100644 --- a/app/models/lettings_log.rb +++ b/app/models/lettings_log.rb @@ -659,7 +659,7 @@ private not_required << "tshortfall" if tshortfall_unknown? not_required << "tenancylength" if tenancylength_optional? - not_required |= %w[address_line2 county postcode_full] if startdate && startdate.year >= 2023 + not_required |= %w[address_line2 county postcode_full] if startdate && collection_start_year_for_date(startdate) >= 2023 not_required end @@ -780,6 +780,6 @@ private end def should_process_uprn_change? - uprn && startdate && (uprn_changed? || startdate_changed?) && startdate.year >= 2023 + uprn && startdate && (uprn_changed? || startdate_changed?) && collection_start_year_for_date(startdate) >= 2023 end end diff --git a/app/models/organisation.rb b/app/models/organisation.rb index e17d0d6eb..1e05bddab 100644 --- a/app/models/organisation.rb +++ b/app/models/organisation.rb @@ -133,12 +133,12 @@ class Organisation < ApplicationRecord :active end - def duplicate_lettings_logs_sets - lettings_logs.duplicate_sets.map { |array_str| array_str ? array_str.map(&:to_i) : [] } + def editable_duplicate_lettings_logs_sets + lettings_logs.after_date(FormHandler.instance.lettings_earliest_open_for_editing_collection_start_date).duplicate_sets.map { |array_str| array_str ? array_str.map(&:to_i) : [] } end - def duplicate_sales_logs_sets - sales_logs.duplicate_sets.map { |array_str| array_str ? array_str.map(&:to_i) : [] } + def editable_duplicate_sales_logs_sets + sales_logs.after_date(FormHandler.instance.sales_earliest_open_for_editing_collection_start_date).duplicate_sets.map { |array_str| array_str ? array_str.map(&:to_i) : [] } end def recently_absorbed_organisations_grouped_by_merge_date diff --git a/app/models/sales_log.rb b/app/models/sales_log.rb index 905b7d5a1..bf059cc88 100644 --- a/app/models/sales_log.rb +++ b/app/models/sales_log.rb @@ -115,7 +115,7 @@ class SalesLog < Log not_required << "mortlen" if mortlen_optional? not_required << "frombeds" if frombeds_optional? - not_required |= %w[address_line2 county postcode_full] if saledate && saledate.year >= 2023 + not_required |= %w[address_line2 county postcode_full] if saledate && collection_start_year_for_date(saledate) >= 2023 not_required end @@ -393,7 +393,7 @@ class SalesLog < Log end def should_process_uprn_change? - uprn && saledate && (uprn_changed? || saledate_changed?) && saledate.year >= 2023 + uprn && saledate && (uprn_changed? || saledate_changed?) && collection_start_year_for_date(saledate) >= 2023 end def value_with_discount diff --git a/app/models/user.rb b/app/models/user.rb index 135d85428..52e2c850d 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -203,12 +203,12 @@ class User < ApplicationRecord super && active? end - def duplicate_lettings_logs_sets - lettings_logs.duplicate_sets(id).map { |array_str| array_str ? array_str.map(&:to_i) : [] } + def editable_duplicate_lettings_logs_sets + lettings_logs.after_date(FormHandler.instance.lettings_earliest_open_for_editing_collection_start_date).duplicate_sets(id).map { |array_str| array_str ? array_str.map(&:to_i) : [] } end - def duplicate_sales_logs_sets - sales_logs.duplicate_sets(id).map { |array_str| array_str ? array_str.map(&:to_i) : [] } + def editable_duplicate_sales_logs_sets + sales_logs.after_date(FormHandler.instance.sales_earliest_open_for_editing_collection_start_date).duplicate_sets(id).map { |array_str| array_str ? array_str.map(&:to_i) : [] } end protected diff --git a/spec/lib/tasks/blank_migrated_soctenant_values_spec.rb b/spec/lib/tasks/blank_migrated_soctenant_values_spec.rb index ddc5ca8e9..333a846cc 100644 --- a/spec/lib/tasks/blank_migrated_soctenant_values_spec.rb +++ b/spec/lib/tasks/blank_migrated_soctenant_values_spec.rb @@ -30,21 +30,30 @@ RSpec.describe "blank_migrated_soctenant_values" do expect(sales_log.values_updated_at).not_to be_nil end - it "does not blank soctenant (and subsequent questions) values from 2022 logs" do - sales_log.old_id = "404" - sales_log.frombeds = nil - sales_log.fromprop = 0 # don't know - sales_log.socprevten = 10 # don't know - sales_log.soctenant = 0 # don't know - sales_log.saledate = Time.zone.local(2022, 5, 5) - sales_log.save! - task.invoke - sales_log.reload - expect(sales_log.soctenant).to eq(0) - expect(sales_log.frombeds).to eq(nil) - expect(sales_log.fromprop).to eq(0) - expect(sales_log.socprevten).to eq(10) - expect(sales_log.values_updated_at).to be_nil + context "with 2022 logs" do + around do |example| + Timecop.freeze(Time.zone.local(2022, 5, 5)) do + Singleton.__init__(FormHandler) + example.run + end + end + + it "does not blank soctenant (and subsequent questions) values" do + sales_log.old_id = "404" + sales_log.frombeds = nil + sales_log.fromprop = 0 # don't know + sales_log.socprevten = 10 # don't know + sales_log.soctenant = 0 # don't know + sales_log.saledate = Time.zone.local(2022, 5, 5) + sales_log.save! + task.invoke + sales_log.reload + expect(sales_log.soctenant).to eq(0) + expect(sales_log.frombeds).to eq(nil) + expect(sales_log.fromprop).to eq(0) + expect(sales_log.socprevten).to eq(10) + expect(sales_log.values_updated_at).to be_nil + end end it "does not blank soctenant (and subsequent questions) values from non imported logs" do diff --git a/spec/models/lettings_log_spec.rb b/spec/models/lettings_log_spec.rb index 6c4d9b1e0..145155ee2 100644 --- a/spec/models/lettings_log_spec.rb +++ b/spec/models/lettings_log_spec.rb @@ -1576,7 +1576,7 @@ RSpec.describe LettingsLog do expect { lettings_log.update!(renewal: 1) }.to change(lettings_log, :underoccupation_benefitcap).to 2 Timecop.return Singleton.__init__(FormHandler) - expect { lettings_log.update!(startdate: Time.zone.local(2023, 1, 1)) }.to change(lettings_log, :underoccupation_benefitcap).from(2).to nil + expect { lettings_log.update!(startdate: Time.zone.local(2023, 4, 1)) }.to change(lettings_log, :underoccupation_benefitcap).from(2).to nil end context "when the log is general needs" do @@ -2122,10 +2122,15 @@ RSpec.describe LettingsLog do context "and the location no local authorities associated with the location_code" do before do + Timecop.freeze(Time.zone.local(2022, 4, 2)) location.update!(location_code: "E01231231") lettings_log.update!(location:) end + after do + Timecop.return + end + it "returns the correct la" do expect(location.location_code).to eq("E01231231") expect(lettings_log["location_id"]).to eq(location.id) @@ -2334,7 +2339,7 @@ RSpec.describe LettingsLog do end end - context "when saledate is before 2023" do + context "when startdate is before 2023" do let(:lettings_log) { build(:lettings_log, startdate: Time.zone.parse("2022-07-01")) } it "returns optional fields" do @@ -2347,7 +2352,7 @@ RSpec.describe LettingsLog do end end - context "when saledate is after 2023" do + context "when startdate is after 2023" do let(:lettings_log) { build(:lettings_log, startdate: Time.zone.parse("2023-07-01")) } it "returns optional fields" do diff --git a/spec/requests/duplicate_logs_controller_spec.rb b/spec/requests/duplicate_logs_controller_spec.rb index 933a0f54d..960b43a22 100644 --- a/spec/requests/duplicate_logs_controller_spec.rb +++ b/spec/requests/duplicate_logs_controller_spec.rb @@ -717,13 +717,13 @@ RSpec.describe DuplicateLogsController, type: :request do before do allow(Organisation).to receive(:find).with(user.organisation_id.to_s).and_return(user.organisation) - allow(user.organisation).to receive(:duplicate_lettings_logs_sets).and_return([[1, 2], [3, 4, 5]]) - allow(user.organisation).to receive(:duplicate_sales_logs_sets).and_return([[11, 12]]) + allow(user.organisation).to receive(:editable_duplicate_lettings_logs_sets).and_return([[1, 2], [3, 4, 5]]) + allow(user.organisation).to receive(:editable_duplicate_sales_logs_sets).and_return([[11, 12]]) end it "gets organisation duplicates" do - expect(user.organisation).to receive(:duplicate_lettings_logs_sets) - expect(user.organisation).to receive(:duplicate_sales_logs_sets) + expect(user.organisation).to receive(:editable_duplicate_lettings_logs_sets) + expect(user.organisation).to receive(:editable_duplicate_sales_logs_sets) get organisation_duplicates_path(organisation_id: user.organisation_id) end @@ -759,8 +759,8 @@ RSpec.describe DuplicateLogsController, type: :request do context "when there are no duplicate logs" do before do allow(Organisation).to receive(:find).with(user.organisation_id.to_s).and_return(user.organisation) - allow(user.organisation).to receive(:duplicate_lettings_logs_sets).and_return([]) - allow(user.organisation).to receive(:duplicate_sales_logs_sets).and_return([]) + allow(user.organisation).to receive(:editable_duplicate_lettings_logs_sets).and_return([]) + allow(user.organisation).to receive(:editable_duplicate_sales_logs_sets).and_return([]) get organisation_duplicates_path(organisation_id: user.organisation_id) end @@ -780,13 +780,13 @@ RSpec.describe DuplicateLogsController, type: :request do let(:user) { create(:user, :data_coordinator) } before do - allow(user.organisation).to receive(:duplicate_lettings_logs_sets).and_return([[1, 2], [3, 4, 5]]) - allow(user.organisation).to receive(:duplicate_sales_logs_sets).and_return([[11, 12]]) + allow(user.organisation).to receive(:editable_duplicate_lettings_logs_sets).and_return([[1, 2], [3, 4, 5]]) + allow(user.organisation).to receive(:editable_duplicate_sales_logs_sets).and_return([[11, 12]]) end it "gets organisation duplicates" do - expect(user.organisation).to receive(:duplicate_lettings_logs_sets) - expect(user.organisation).to receive(:duplicate_sales_logs_sets) + expect(user.organisation).to receive(:editable_duplicate_lettings_logs_sets) + expect(user.organisation).to receive(:editable_duplicate_sales_logs_sets) get duplicate_logs_path(organisation_id: user.organisation.id) end end @@ -795,13 +795,13 @@ RSpec.describe DuplicateLogsController, type: :request do let(:user) { create(:user) } before do - allow(user).to receive(:duplicate_lettings_logs_sets).and_return([[1, 2], [3, 4, 5]]) - allow(user).to receive(:duplicate_sales_logs_sets).and_return([[11, 12]]) + allow(user).to receive(:editable_duplicate_lettings_logs_sets).and_return([[1, 2], [3, 4, 5]]) + allow(user).to receive(:editable_duplicate_sales_logs_sets).and_return([[11, 12]]) end it "calls the helper method to retrieve duplicates for the current user" do - expect(user).to receive(:duplicate_lettings_logs_sets) - expect(user).to receive(:duplicate_sales_logs_sets) + expect(user).to receive(:editable_duplicate_lettings_logs_sets) + expect(user).to receive(:editable_duplicate_sales_logs_sets) get duplicate_logs_path end @@ -836,8 +836,8 @@ RSpec.describe DuplicateLogsController, type: :request do context "when there are no duplicate logs" do before do - allow(user).to receive(:duplicate_lettings_logs_sets).and_return([]) - allow(user).to receive(:duplicate_sales_logs_sets).and_return([]) + allow(user).to receive(:editable_duplicate_lettings_logs_sets).and_return([]) + allow(user).to receive(:editable_duplicate_sales_logs_sets).and_return([]) get duplicate_logs_path end diff --git a/spec/requests/form_controller_spec.rb b/spec/requests/form_controller_spec.rb index 5f0e7b273..fbe3dbb1d 100644 --- a/spec/requests/form_controller_spec.rb +++ b/spec/requests/form_controller_spec.rb @@ -254,6 +254,15 @@ RSpec.describe FormController, type: :request do end describe "GET" do + around do |example| + Timecop.freeze(Time.zone.local(2022, 5, 1)) do + Singleton.__init__(FormHandler) + example.run + end + Timecop.return + Singleton.__init__(FormHandler) + end + context "with form pages" do context "when forms exist" do let(:lettings_log) { create(:lettings_log, :setup_completed, startdate: Time.zone.local(2022, 5, 1), owning_organisation: organisation, created_by: user) } diff --git a/spec/requests/lettings_logs_controller_spec.rb b/spec/requests/lettings_logs_controller_spec.rb index ea9debdc1..6844ad6b4 100644 --- a/spec/requests/lettings_logs_controller_spec.rb +++ b/spec/requests/lettings_logs_controller_spec.rb @@ -889,14 +889,12 @@ RSpec.describe LettingsLogsController, type: :request do end context "and there are duplicate logs for this user" do - before do - FactoryBot.create_list(:lettings_log, 2, :duplicate, owning_organisation: user.organisation, created_by: user) - end + let!(:duplicate_logs) { FactoryBot.create_list(:lettings_log, 2, :duplicate, owning_organisation: user.organisation, created_by: user) } it "displays a notification banner with a link to review logs" do get lettings_logs_path expect(page).to have_content "duplicate logs" - expect(page).to have_link "Review logs" # add an href when routing done + expect(page).to have_link "Review logs", href: "/duplicate-logs?referrer=duplicate_logs_banner" end context "when there is one set of duplicates" do @@ -904,6 +902,20 @@ RSpec.describe LettingsLogsController, type: :request do get lettings_logs_path expect(page).to have_content "There is 1 set of duplicate logs" end + + context "when the set is not editable" do + before do + duplicate_logs.each do |log| + log.startdate = Time.zone.now - 3.years + log.save!(validate: false) + end + end + + it "does not display the banner" do + get lettings_logs_path + expect(page).not_to have_content "duplicate logs" + end + end end context "when there are multiple sets of duplicates" do @@ -914,6 +926,21 @@ RSpec.describe LettingsLogsController, type: :request do it "displays the correct copy in the banner" do get lettings_logs_path expect(page).to have_content "There are 2 sets of duplicate logs" + expect(page).to have_link "Review logs", href: "/duplicate-logs?referrer=duplicate_logs_banner" + end + + context "when one set is not editable" do + before do + log = duplicate_logs.first + log.startdate = Time.zone.now - 3.years + log.save!(validate: false) + end + + it "displays the correct copy in the banner" do + get lettings_logs_path + expect(page).to have_content "There is 1 set of duplicate logs" + expect(page).to have_link "Review logs", href: "/duplicate-logs?referrer=duplicate_logs_banner" + end end end end diff --git a/spec/requests/sales_logs_controller_spec.rb b/spec/requests/sales_logs_controller_spec.rb index 97c5851fd..2b7f6e172 100644 --- a/spec/requests/sales_logs_controller_spec.rb +++ b/spec/requests/sales_logs_controller_spec.rb @@ -235,6 +235,18 @@ RSpec.describe SalesLogsController, type: :request do expect(page).to have_link("Download (CSV, codes only)", href: "/sales-logs/csv-download?codes_only=true") end + context "when there are duplicate logs for this user" do + before do + FactoryBot.create_list(:sales_log, 2, :duplicate, owning_organisation: user.organisation, created_by: user) + end + + it "does not show a notification banner even if there are duplicate logs for this user" do + get sales_logs_path + expect(page).not_to have_content "duplicate logs" + expect(page).not_to have_link "Review logs" + end + end + context "when there are no logs in the database" do before do SalesLog.destroy_all @@ -566,6 +578,12 @@ RSpec.describe SalesLogsController, type: :request do expect(page).not_to have_link("Download (CSV, codes only)") end + it "does not show a notification banner even if there are duplicate logs for this user" do + get sales_logs_path + expect(page).not_to have_content "duplicate logs" + expect(page).not_to have_link "Review logs" + end + context "when using a search query" do let(:logs) { FactoryBot.create_list(:sales_log, 3, :completed, owning_organisation: user.organisation, created_by: user) } let(:log_to_search) { FactoryBot.create(:sales_log, :completed, owning_organisation: user.organisation, created_by: user) } @@ -727,6 +745,63 @@ RSpec.describe SalesLogsController, type: :request do end end end + + context "and there are duplicate logs for this user" do + let!(:duplicate_logs) { FactoryBot.create_list(:lettings_log, 2, :duplicate, owning_organisation: user.organisation, created_by: user) } + + it "displays a notification banner with a link to review logs" do + get sales_logs_path + expect(page).to have_content "duplicate logs" + expect(page).to have_link "Review logs", href: "/duplicate-logs?referrer=duplicate_logs_banner" + end + + context "when there is one set of duplicates" do + it "displays the correct copy in the banner" do + get sales_logs_path + expect(page).to have_content "There is 1 set of duplicate logs" + end + + context "when the set is not editable" do + before do + duplicate_logs.each do |log| + log.startdate = Time.zone.now - 3.years + log.save!(validate: false) + end + end + + it "does not display the banner" do + get sales_logs_path + expect(page).not_to have_content "duplicate logs" + end + end + end + + context "when there are multiple sets of duplicates" do + before do + FactoryBot.create_list(:sales_log, 2, :duplicate, owning_organisation: user.organisation, created_by: user) + end + + it "displays the correct copy in the banner" do + get sales_logs_path + expect(page).to have_content "There are 2 sets of duplicate logs" + expect(page).to have_link "Review logs", href: "/duplicate-logs?referrer=duplicate_logs_banner" + end + + context "when one set is not editable" do + before do + log = duplicate_logs.first + log.startdate = Time.zone.now - 3.years + log.save!(validate: false) + end + + it "displays the correct copy in the banner" do + get sales_logs_path + expect(page).to have_content "There is 1 set of duplicate logs" + expect(page).to have_link "Review logs", href: "/duplicate-logs?referrer=duplicate_logs_banner" + end + end + end + end end end diff --git a/spec/services/bulk_upload/lettings/log_creator_spec.rb b/spec/services/bulk_upload/lettings/log_creator_spec.rb index 6dfaff46c..c240caef8 100644 --- a/spec/services/bulk_upload/lettings/log_creator_spec.rb +++ b/spec/services/bulk_upload/lettings/log_creator_spec.rb @@ -9,6 +9,13 @@ RSpec.describe BulkUpload::Lettings::LogCreator do let(:bulk_upload) { create(:bulk_upload, :lettings, user:) } let(:path) { file_fixture("2022_23_lettings_bulk_upload.csv") } + around do |example| + Timecop.freeze(Time.zone.local(2023, 1, 1)) do + Singleton.__init__(FormHandler) + example.run + end + end + describe "#call" do context "when a valid csv with new log" do it "creates a new log" do diff --git a/spec/services/bulk_upload/lettings/validator_spec.rb b/spec/services/bulk_upload/lettings/validator_spec.rb index 595192210..8cbbae29a 100644 --- a/spec/services/bulk_upload/lettings/validator_spec.rb +++ b/spec/services/bulk_upload/lettings/validator_spec.rb @@ -10,6 +10,13 @@ RSpec.describe BulkUpload::Lettings::Validator do let(:path) { file.path } let(:file) { Tempfile.new } + around do |example| + Timecop.freeze(Date.new(2023, 10, 1)) do + example.run + end + Timecop.return + end + describe "validations" do context "when 2022" do let(:bulk_upload) { create(:bulk_upload, user:, year: 2022) } diff --git a/spec/services/bulk_upload/lettings/year2022/row_parser_spec.rb b/spec/services/bulk_upload/lettings/year2022/row_parser_spec.rb index 101a17b3b..9fdfab47d 100644 --- a/spec/services/bulk_upload/lettings/year2022/row_parser_spec.rb +++ b/spec/services/bulk_upload/lettings/year2022/row_parser_spec.rb @@ -153,11 +153,14 @@ RSpec.describe BulkUpload::Lettings::Year2022::RowParser do end around do |example| - FormHandler.instance.use_real_forms! + Timecop.freeze(Date.new(2023, 3, 1)) do + FormHandler.instance.use_real_forms! - example.run + example.run - FormHandler.instance.use_fake_forms! + FormHandler.instance.use_fake_forms! + end + Timecop.return end describe "#blank_row?" do diff --git a/spec/services/bulk_upload/lettings/year2023/row_parser_spec.rb b/spec/services/bulk_upload/lettings/year2023/row_parser_spec.rb index f24fa5010..dc7dbeaea 100644 --- a/spec/services/bulk_upload/lettings/year2023/row_parser_spec.rb +++ b/spec/services/bulk_upload/lettings/year2023/row_parser_spec.rb @@ -47,9 +47,11 @@ RSpec.describe BulkUpload::Lettings::Year2023::RowParser do end around do |example| - FormHandler.instance.use_real_forms! - - example.run + Timecop.freeze(Date.new(2023, 10, 1)) do + FormHandler.instance.use_real_forms! + example.run + end + Timecop.return end describe "#blank_row?" do diff --git a/spec/services/bulk_upload/processor_spec.rb b/spec/services/bulk_upload/processor_spec.rb index 9f287c592..c79599656 100644 --- a/spec/services/bulk_upload/processor_spec.rb +++ b/spec/services/bulk_upload/processor_spec.rb @@ -7,6 +7,13 @@ RSpec.describe BulkUpload::Processor do let(:user) { create(:user, organisation: owning_org) } let(:owning_org) { create(:organisation, old_visible_id: 123) } + around do |example| + Timecop.freeze(Time.utc(2023, 1, 1)) do + Singleton.__init__(FormHandler) + example.run + end + end + describe "#call" do context "when errors exist from prior job run" do let!(:existing_error) { create(:bulk_upload_error, bulk_upload:) } diff --git a/spec/services/bulk_upload/sales/year2023/row_parser_spec.rb b/spec/services/bulk_upload/sales/year2023/row_parser_spec.rb index 2e38e4f2c..0745274fc 100644 --- a/spec/services/bulk_upload/sales/year2023/row_parser_spec.rb +++ b/spec/services/bulk_upload/sales/year2023/row_parser_spec.rb @@ -3,7 +3,7 @@ require "rails_helper" RSpec.describe BulkUpload::Sales::Year2023::RowParser do subject(:parser) { described_class.new(attributes) } - let(:now) { Time.zone.parse("01/03/2023") } + let(:now) { Time.zone.parse("01/05/2023") } let(:attributes) { { bulk_upload: } } let(:bulk_upload) { create(:bulk_upload, :sales, user:, year: 2023) } @@ -760,7 +760,7 @@ RSpec.describe BulkUpload::Sales::Year2023::RowParser do let(:attributes) { setup_section_params.merge({ field_19: "3", data[:field] => nil }) } it "cannot be blank" do - expect(parser.errors[data[:field]]).not_to be_blank + expect(parser.errors[data[:field]]).to be_present end end end diff --git a/spec/services/csv/missing_addresses_csv_service_spec.rb b/spec/services/csv/missing_addresses_csv_service_spec.rb index e8482f4cb..453ee5370 100644 --- a/spec/services/csv/missing_addresses_csv_service_spec.rb +++ b/spec/services/csv/missing_addresses_csv_service_spec.rb @@ -38,6 +38,13 @@ RSpec.describe Csv::MissingAddressesCsvService do .to_return(status: 200, body: body_2, headers: {}) end + around do |example| + Timecop.freeze(Time.zone.local(2023, 4, 5)) do + Singleton.__init__(FormHandler) + example.run + end + end + def replace_entity_ids(lettings_log, export_template) export_template.sub!(/\{id\}/, lettings_log.id.to_s) end diff --git a/spec/services/imports/sales_logs_field_import_service_spec.rb b/spec/services/imports/sales_logs_field_import_service_spec.rb index ef7762da8..bee07b24a 100644 --- a/spec/services/imports/sales_logs_field_import_service_spec.rb +++ b/spec/services/imports/sales_logs_field_import_service_spec.rb @@ -27,6 +27,13 @@ RSpec.describe Imports::SalesLogsFieldImportService do .and_return(sales_log_file) end + around do |example| + Timecop.freeze(Time.zone.local(2023, 1, 17)) do + Singleton.__init__(FormHandler) + example.run + end + end + context "when updating creation method" do let(:field) { "creation_method" } let(:sales_log) { SalesLog.find_by(old_id: sales_log_filename) }