Browse Source

Merge branch 'main' into CLDC-4141-lettings-sab-question

pull/3156/head
Nat Dean-Lewis 2 weeks ago
parent
commit
40a942bdd4
  1. 8
      app/helpers/collection_time_helper.rb
  2. 13
      app/models/scheme.rb
  3. 8
      app/views/schemes/details.html.erb
  4. 8
      app/views/schemes/new.html.erb
  5. 4
      lib/tasks/update_scheme_registered_under_care_value.rake
  6. 16
      spec/features/accessibility_spec.rb
  7. 2
      spec/features/schemes_helpers.rb
  8. 4
      spec/features/schemes_spec.rb
  9. 10
      spec/fixtures/files/original_schemes.csv
  10. 4
      spec/fixtures/files/updated_schemes.csv
  11. 3
      spec/helpers/check_answers_helper_spec.rb
  12. 16
      spec/helpers/collection_time_helper_spec.rb
  13. 146
      spec/helpers/filters_helper_spec.rb
  14. 1
      spec/helpers/locations_helper_spec.rb
  15. 21
      spec/lib/tasks/count_duplicates_spec.rb
  16. 6
      spec/lib/tasks/update_schemes_and_locations_from_csv_spec.rb
  17. 17
      spec/services/merge/merge_organisations_service_spec.rb

8
app/helpers/collection_time_helper.rb

@ -54,6 +54,10 @@ module CollectionTimeHelper
current_collection_start_year - 1 current_collection_start_year - 1
end end
def previous_collection_end_year
current_collection_end_year - 1
end
def previous_collection_start_date def previous_collection_start_date
current_collection_start_date - 1.year current_collection_start_date - 1.year
end end
@ -62,6 +66,10 @@ module CollectionTimeHelper
current_collection_start_year - 2 current_collection_start_year - 2
end end
def archived_collection_end_year
current_collection_end_year - 2
end
def previous_collection_new_logs_end_date def previous_collection_new_logs_end_date
FormHandler.instance.lettings_form_for_start_year(previous_collection_start_year).new_logs_end_date FormHandler.instance.lettings_form_for_start_year(previous_collection_start_year).new_logs_end_date
end end

13
app/models/scheme.rb

@ -148,9 +148,8 @@ class Scheme < ApplicationRecord
enum :sensitive, SENSITIVE, suffix: true enum :sensitive, SENSITIVE, suffix: true
REGISTERED_UNDER_CARE_ACT = { REGISTERED_UNDER_CARE_ACT = {
"Yes – registered care home providing nursing care": 4, "Yes": 5,
"Yes – registered care home providing personal care": 3, "Partially - some but not all units in the scheme are regulated by the CQC": 2,
"Yes – part registered as a care home": 2,
"No": 1, "No": 1,
}.freeze }.freeze
@ -251,7 +250,7 @@ class Scheme < ApplicationRecord
{ name: "Status", value: status, id: "status" }, { name: "Status", value: status, id: "status" },
{ name: "Confidential information", value: sensitive, id: "sensitive", edit: true }, { name: "Confidential information", value: sensitive, id: "sensitive", edit: true },
{ name: "Type of scheme", value: scheme_type, id: "scheme_type", edit: true }, { name: "Type of scheme", value: scheme_type, id: "scheme_type", edit: true },
{ name: "Registered under Care Standards Act 2000", value: registered_under_care_act, id: "registered_under_care_act", edit: true }, { name: "Regulated by the Care Quality Commission", value: registered_under_care_act, id: "registered_under_care_act", edit: true },
{ name: "Housing stock owned by", value: owning_organisation.name, id: "owning_organisation_id", edit: true }, { name: "Housing stock owned by", value: owning_organisation.name, id: "owning_organisation_id", edit: true },
{ name: "Support services provided by", value: arrangement_type, id: "arrangement_type", edit: true }, { name: "Support services provided by", value: arrangement_type, id: "arrangement_type", edit: true },
{ name: "Primary client group", value: primary_client_group, id: "primary_client_group", edit: true }, { name: "Primary client group", value: primary_client_group, id: "primary_client_group", edit: true },
@ -262,10 +261,8 @@ class Scheme < ApplicationRecord
] ]
end end
def care_acts_options_with_hints def self.care_acts_options
hints = { "Yes – part registered as a care home": "A proportion of units are registered as being a care home." } Scheme.registered_under_care_acts.keys.map { |key, _| OpenStruct.new(id: key, name: key.to_s) }
Scheme.registered_under_care_acts.keys.map { |key, _| OpenStruct.new(id: key, name: key.to_s.humanize, description: hints[key.to_sym]) }
end end
def support_level_options_with_hints def support_level_options_with_hints

8
app/views/schemes/details.html.erb

@ -38,16 +38,12 @@
:name, :name,
legend: { text: "What is this type of scheme?", size: "m" } %> legend: { text: "What is this type of scheme?", size: "m" } %>
<% care_acts_options_hints = { "Yes – part registered as a care home": "A proportion of units are registered as being a care home." } %>
<% care_acts_options_with_hints = Scheme.registered_under_care_acts.keys.map { |key, _| OpenStruct.new(id: key, name: key.to_s.humanize, description: care_acts_options_hints[key.to_sym]) } %>
<%= f.govuk_collection_radio_buttons :registered_under_care_act, <%= f.govuk_collection_radio_buttons :registered_under_care_act,
care_acts_options_with_hints, Scheme.care_acts_options,
:id, :id,
:name, :name,
:description, :description,
legend: { text: "Is this scheme registered under the Care Standards Act 2000?", size: "m" } %> legend: { text: "Is the scheme regulated by the Care Quality Commission (CQC)?", size: "m" } %>
<% scheme_owning_organisation_options = owning_organisation_options(current_user) %> <% scheme_owning_organisation_options = owning_organisation_options(current_user) %>

8
app/views/schemes/new.html.erb

@ -33,16 +33,12 @@
:name, :name,
legend: { text: "What is this type of scheme?", size: "m" } %> legend: { text: "What is this type of scheme?", size: "m" } %>
<% care_acts_options_hints = { "Yes – part registered as a care home": "A proportion of units are registered as being a care home." } %>
<% care_acts_options_with_hints = Scheme.registered_under_care_acts.keys.map { |key, _| OpenStruct.new(id: key, name: key.to_s.humanize, description: care_acts_options_hints[key.to_sym]) } %>
<%= f.govuk_collection_radio_buttons :registered_under_care_act, <%= f.govuk_collection_radio_buttons :registered_under_care_act,
care_acts_options_with_hints, Scheme.care_acts_options,
:id, :id,
:name, :name,
:description, :description,
legend: { text: "Is this scheme registered under the Care Standards Act 2000?", size: "m" } %> legend: { text: "Is the scheme regulated by the Care Quality Commission (CQC)?", size: "m" } %>
<% if current_user.data_coordinator? && current_user.organisation.stock_owners.count.zero? && !current_user.organisation.has_recent_absorbed_organisations? %> <% if current_user.data_coordinator? && current_user.organisation.stock_owners.count.zero? && !current_user.organisation.has_recent_absorbed_organisations? %>
<%= f.hidden_field :owning_organisation_id, value: current_user.organisation.id %> <%= f.hidden_field :owning_organisation_id, value: current_user.organisation.id %>

4
lib/tasks/update_scheme_registered_under_care_value.rake

@ -0,0 +1,4 @@
desc "Alter registered under care act values for schemes in the database to 5 if they are 3 or 4, as these options are being deprecated"
task update_scheme_registered_under_care_value: :environment do
Scheme.where(registered_under_care_act: [3, 4]).update_all(registered_under_care_act: 5)
end

16
spec/features/accessibility_spec.rb

@ -21,6 +21,22 @@ RSpec.describe "Accessibility", js: true do
end end
before do before do
# see https://github.com/dequelabs/axe-core-gems/issues/386#issuecomment-2135927504 for why this is needed
# axe-core will normally use 1 second page load timeout.
# see https://github.com/dequelabs/axe-core-gems/blob/87632f5e8e947214f10e35b57ea5e2c327f20612/packages/axe-core-api/lib/axe/api/run.rb#L36
# this causes timeout errors for slower pages
# so we override the page load timeout to 10 seconds for feature specs
# this is for the a11y tests, we can only scope to feature specs
page.driver.browser.manage.timeouts.instance_eval do
def page_load=(*)
# no-op don't want axe-core changing this
end
def page_load
10 # seconds
end
end
allow(Storage::S3Service).to receive(:new).and_return(storage_service) 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")) allow(storage_service).to receive(:configuration).and_return(OpenStruct.new(bucket_name: "core-test-collection-resources"))
allow(user).to receive(:need_two_factor_authentication?).and_return(false) allow(user).to receive(:need_two_factor_authentication?).and_return(false)

2
spec/features/schemes_helpers.rb

@ -29,7 +29,7 @@ module SchemesHelpers
fill_in "Scheme name", with: "FooBar" fill_in "Scheme name", with: "FooBar"
check "This scheme contains confidential information" check "This scheme contains confidential information"
choose "Direct access hostel" choose "Direct access hostel"
choose "Yes – registered care home providing nursing care" choose "Yes"
select organisation_name, from: "scheme-owning-organisation-id-field" select organisation_name, from: "scheme-owning-organisation-id-field"
choose answers["housing_stock_owners"].presence || "The same organisation that owns the housing stock" choose answers["housing_stock_owners"].presence || "The same organisation that owns the housing stock"
click_button "Save and continue" click_button "Save and continue"

4
spec/features/schemes_spec.rb

@ -446,7 +446,7 @@ RSpec.describe "Schemes scheme Features" do
expect(page).to have_content "This scheme contains confidential information" expect(page).to have_content "This scheme contains confidential information"
expect(page).to have_content "Which organisation owns the housing stock for this scheme?" expect(page).to have_content "Which organisation owns the housing stock for this scheme?"
expect(page).to have_content "What is this type of scheme?" expect(page).to have_content "What is this type of scheme?"
expect(page).to have_content "Is this scheme registered under the Care Standards Act 2000?" expect(page).to have_content "Is the scheme regulated by the Care Quality Commission (CQC)?"
expect(page).to have_content "Who provides the support services used by this scheme?" expect(page).to have_content "Who provides the support services used by this scheme?"
end end
@ -463,7 +463,7 @@ RSpec.describe "Schemes scheme Features" do
expect(page).to have_content "This scheme contains confidential information" expect(page).to have_content "This scheme contains confidential information"
expect(page).to have_content "What is this type of scheme?" expect(page).to have_content "What is this type of scheme?"
expect(page).to have_content "Who provides the support services used by this scheme?" expect(page).to have_content "Who provides the support services used by this scheme?"
expect(page).to have_content "Is this scheme registered under the Care Standards Act 2000?" expect(page).to have_content "Is the scheme regulated by the Care Quality Commission (CQC)?"
end end
it "returns to the primary client group question after amending scheme details" do it "returns to the primary client group question after amending scheme details" do

10
spec/fixtures/files/original_schemes.csv vendored

@ -1,6 +1,6 @@
scheme_code,scheme_service_name,scheme_status,scheme_confidential,scheme_type,scheme_registered_under_care_act,scheme_owning_organisation_name,scheme_support_services_provided_by,scheme_primary_client_group,scheme_has_other_client_group,scheme_secondary_client_group,scheme_support_type,scheme_intended_stay,scheme_created_at,scheme_active_dates scheme_code,scheme_service_name,scheme_status,scheme_confidential,scheme_type,scheme_registered_under_care_act,scheme_owning_organisation_name,scheme_support_services_provided_by,scheme_primary_client_group,scheme_has_other_client_group,scheme_secondary_client_group,scheme_support_type,scheme_intended_stay,scheme_created_at,scheme_active_dates
{id1},Test name,active,Yes,Housing for older people,Yes – registered care home providing nursing care,MHCLG,The same organisation that owns the housing stock,People with alcohol problems,Yes,Older people with support needs,High level,Medium stay,2021-04-01T00:00:00+01:00,"Active from 1 April 2020" {id1},Test name,active,Yes,Housing for older people,Yes,MHCLG,The same organisation that owns the housing stock,People with alcohol problems,Yes,Older people with support needs,High level,Medium stay,2021-04-01T00:00:00+01:00,"Active from 1 April 2020"
{id2},Test name,active,Yes,Housing for older people,Yes – registered care home providing nursing care,MHCLG,The same organisation that owns the housing stock,People with alcohol problems,Yes,Older people with support needs,High level,Medium stay,2021-04-01T00:00:00+01:00,"Active from 1 April 2020" {id2},Test name,active,Yes,Housing for older people,Yes,MHCLG,The same organisation that owns the housing stock,People with alcohol problems,Yes,Older people with support needs,High level,Medium stay,2021-04-01T00:00:00+01:00,"Active from 1 April 2020"
{id3},Test name,active,Yes,Housing for older people,Yes – registered care home providing nursing care,MHCLG,The same organisation that owns the housing stock,People with alcohol problems,Yes,Older people with support needs,High level,Medium stay,2021-04-01T00:00:00+01:00,"Active from 1 April 2020" {id3},Test name,active,Yes,Housing for older people,Yes,MHCLG,The same organisation that owns the housing stock,People with alcohol problems,Yes,Older people with support needs,High level,Medium stay,2021-04-01T00:00:00+01:00,"Active from 1 April 2020"
{id4},Incomplete scheme,incomplete,Yes,Housing for older people,Yes – registered care home providing nursing care,MHCLG,The same organisation that owns the housing stock,People with alcohol problems,,,,,2021-04-01T00:00:00+01:00,"Active from 1 April 2020" {id4},Incomplete scheme,incomplete,Yes,Housing for older people,Yes,MHCLG,The same organisation that owns the housing stock,People with alcohol problems,,,,,2021-04-01T00:00:00+01:00,"Active from 1 April 2020"
SWrong_id,Incomplete scheme,incomplete,Yes,Housing for older people,Yes – registered care home providing nursing care,MHCLG,The same organisation that owns the housing stock,People with alcohol problems,,,,,2021-04-01T00:00:00+01:00,"Active from 1 April 2020" SWrong_id,Incomplete scheme,incomplete,Yes,Housing for older people,Yes,MHCLG,The same organisation that owns the housing stock,People with alcohol problems,,,,,2021-04-01T00:00:00+01:00,"Active from 1 April 2020"

1 scheme_code scheme_service_name scheme_status scheme_confidential scheme_type scheme_registered_under_care_act scheme_owning_organisation_name scheme_support_services_provided_by scheme_primary_client_group scheme_has_other_client_group scheme_secondary_client_group scheme_support_type scheme_intended_stay scheme_created_at scheme_active_dates
2 {id1} Test name active Yes Housing for older people Yes – registered care home providing nursing care Yes MHCLG The same organisation that owns the housing stock People with alcohol problems Yes Older people with support needs High level Medium stay 2021-04-01T00:00:00+01:00 Active from 1 April 2020
3 {id2} Test name active Yes Housing for older people Yes – registered care home providing nursing care Yes MHCLG The same organisation that owns the housing stock People with alcohol problems Yes Older people with support needs High level Medium stay 2021-04-01T00:00:00+01:00 Active from 1 April 2020
4 {id3} Test name active Yes Housing for older people Yes – registered care home providing nursing care Yes MHCLG The same organisation that owns the housing stock People with alcohol problems Yes Older people with support needs High level Medium stay 2021-04-01T00:00:00+01:00 Active from 1 April 2020
5 {id4} Incomplete scheme incomplete Yes Housing for older people Yes – registered care home providing nursing care Yes MHCLG The same organisation that owns the housing stock People with alcohol problems 2021-04-01T00:00:00+01:00 Active from 1 April 2020
6 SWrong_id Incomplete scheme incomplete Yes Housing for older people Yes – registered care home providing nursing care Yes MHCLG The same organisation that owns the housing stock People with alcohol problems 2021-04-01T00:00:00+01:00 Active from 1 April 2020

4
spec/fixtures/files/updated_schemes.csv vendored

@ -1,6 +1,6 @@
scheme_code,scheme_service_name,scheme_status,scheme_confidential,scheme_type,scheme_registered_under_care_act,scheme_owning_organisation_name,scheme_support_services_provided_by,scheme_primary_client_group,scheme_has_other_client_group,scheme_secondary_client_group,scheme_support_type,scheme_intended_stay,scheme_created_at,scheme_active_dates scheme_code,scheme_service_name,scheme_status,scheme_confidential,scheme_type,scheme_registered_under_care_act,scheme_owning_organisation_name,scheme_support_services_provided_by,scheme_primary_client_group,scheme_has_other_client_group,scheme_secondary_client_group,scheme_support_type,scheme_intended_stay,scheme_created_at,scheme_active_dates
{id1},Updated test name,incomplete,No,Direct Access Hostel,No,Different organisation,Another registered stock owner,People with drug problems,No,Older people with support needs,Low level,Permanent,2022-04-01T00:00:00+01:00,"Active from 2 April 2020" {id1},Updated test name,incomplete,No,Direct Access Hostel,No,Different organisation,Another registered stock owner,People with drug problems,No,Older people with support needs,Low level,Permanent,2022-04-01T00:00:00+01:00,"Active from 2 April 2020"
{id2},Test name,active,Yes,Housing for older people,Yes – registered care home providing nursing care,MHCLG,The same organisation that owns the housing stock,People with alcohol problems,Yes,Older people with support needs,High level,Medium stay,2021-04-01T00:00:00+01:00,"Active from 1 April 2020" {id2},Test name,active,Yes,Housing for older people,Yes,MHCLG,The same organisation that owns the housing stock,People with alcohol problems,Yes,Older people with support needs,High level,Medium stay,2021-04-01T00:00:00+01:00,"Active from 1 April 2020"
{id3}, ,active,Yse,Direct access Hostel,Yes – registered care home providing nursing care,non existing org,wrong answer,FD,no,lder people with support needs,high,Permanent ,2021-04-01T00:00:00+01:00,"Active from 1 April 2020" {id3}, ,active,Yse,Direct access Hostel,Yes,non existing org,wrong answer,FD,no,lder people with support needs,high,Permanent ,2021-04-01T00:00:00+01:00,"Active from 1 April 2020"
Wrong_id,Incomplete scheme,incomplete,Yes,Housing for older people,No,MHCLG,The same organisation that owns the housing stock,People with alcohol problems,,,,,2021-04-01T00:00:00+01:00,"Active from 1 April 2020" Wrong_id,Incomplete scheme,incomplete,Yes,Housing for older people,No,MHCLG,The same organisation that owns the housing stock,People with alcohol problems,,,,,2021-04-01T00:00:00+01:00,"Active from 1 April 2020"
SWrong_id,Incomplete scheme,incomplete,Yes,Housing for older people,No,MHCLG,The same organisation that owns the housing stock,People with alcohol problems,,,,,2021-04-01T00:00:00+01:00,"Active from 1 April 2020" SWrong_id,Incomplete scheme,incomplete,Yes,Housing for older people,No,MHCLG,The same organisation that owns the housing stock,People with alcohol problems,,,,,2021-04-01T00:00:00+01:00,"Active from 1 April 2020"

1 scheme_code scheme_service_name scheme_status scheme_confidential scheme_type scheme_registered_under_care_act scheme_owning_organisation_name scheme_support_services_provided_by scheme_primary_client_group scheme_has_other_client_group scheme_secondary_client_group scheme_support_type scheme_intended_stay scheme_created_at scheme_active_dates
2 {id1} Updated test name incomplete No Direct Access Hostel No Different organisation Another registered stock owner People with drug problems No Older people with support needs Low level Permanent 2022-04-01T00:00:00+01:00 Active from 2 April 2020
3 {id2} Test name active Yes Housing for older people Yes – registered care home providing nursing care Yes MHCLG The same organisation that owns the housing stock People with alcohol problems Yes Older people with support needs High level Medium stay 2021-04-01T00:00:00+01:00 Active from 1 April 2020
4 {id3} active Yse Direct access Hostel Yes – registered care home providing nursing care Yes non existing org wrong answer FD no lder people with support needs high Permanent 2021-04-01T00:00:00+01:00 Active from 1 April 2020
5 Wrong_id Incomplete scheme incomplete Yes Housing for older people No MHCLG The same organisation that owns the housing stock People with alcohol problems 2021-04-01T00:00:00+01:00 Active from 1 April 2020
6 SWrong_id Incomplete scheme incomplete Yes Housing for older people No MHCLG The same organisation that owns the housing stock People with alcohol problems 2021-04-01T00:00:00+01:00 Active from 1 April 2020

3
spec/helpers/check_answers_helper_spec.rb

@ -41,7 +41,8 @@ RSpec.describe CheckAnswersHelper do
describe "#get_answer_label" do describe "#get_answer_label" do
context "when unanswered and bulk upload" do context "when unanswered and bulk upload" do
let(:question) { log.form.questions.reject { |q| log.optional_fields.include?(q.id) }.sample } # make sure to not include questions that override the answer label
let(:question) { log.form.questions.reject { |q| log.optional_fields.include?(q.id) || q.answer_label(log, current_user).present? }.sample }
let(:bulk_upload) { create(:bulk_upload) } let(:bulk_upload) { create(:bulk_upload) }
let(:log) { create(:sales_log, creation_method: "bulk upload", bulk_upload:) } let(:log) { create(:sales_log, creation_method: "bulk upload", bulk_upload:) }

16
spec/helpers/collection_time_helper_spec.rb

@ -152,7 +152,7 @@ RSpec.describe CollectionTimeHelper do
it "returns a different date within the collection year" do it "returns a different date within the collection year" do
result = generate_different_date_within_collection_year(date) result = generate_different_date_within_collection_year(date)
expect(result).not_to eq(date) expect(result).not_to eq(date)
expect(result).to be_between(Time.zone.local(2024, 4, 1), Time.zone.local(2025, 3, 31)).inclusive expect(result).to be_between(Date.new(2024, 4, 1), Date.new(2025, 3, 31)).inclusive
end end
end end
@ -162,7 +162,7 @@ RSpec.describe CollectionTimeHelper do
it "returns a different date within the collection year" do it "returns a different date within the collection year" do
result = generate_different_date_within_collection_year(date) result = generate_different_date_within_collection_year(date)
expect(result).not_to eq(date) expect(result).not_to eq(date)
expect(result).to be_between(Time.zone.local(2024, 4, 1), Time.zone.local(2025, 3, 31)).inclusive expect(result).to be_between(Date.new(2024, 4, 1), Date.new(2025, 3, 31)).inclusive
end end
end end
@ -170,7 +170,7 @@ RSpec.describe CollectionTimeHelper do
it "ignores the override and returns a different date within the collection year" do it "ignores the override and returns a different date within the collection year" do
result = generate_different_date_within_collection_year(date, start_date_override: Time.zone.local(2023, 12, 31)) result = generate_different_date_within_collection_year(date, start_date_override: Time.zone.local(2023, 12, 31))
expect(result).not_to eq(date) expect(result).not_to eq(date)
expect(result).to be_between(Time.zone.local(2024, 4, 1), Time.zone.local(2025, 3, 31)).inclusive expect(result).to be_between(Date.new(2024, 4, 1), Date.new(2025, 3, 31)).inclusive
end end
end end
@ -178,7 +178,7 @@ RSpec.describe CollectionTimeHelper do
it "ignores the override and returns a different date within the collection year" do it "ignores the override and returns a different date within the collection year" do
result = generate_different_date_within_collection_year(date, end_date_override: Time.zone.local(2025, 12, 1)) result = generate_different_date_within_collection_year(date, end_date_override: Time.zone.local(2025, 12, 1))
expect(result).not_to eq(date) expect(result).not_to eq(date)
expect(result).to be_between(Time.zone.local(2024, 4, 1), Time.zone.local(2025, 3, 31)).inclusive expect(result).to be_between(Date.new(2024, 4, 1), Date.new(2025, 3, 31)).inclusive
end end
end end
@ -186,7 +186,7 @@ RSpec.describe CollectionTimeHelper do
it "returns a different date within the overridden range" do it "returns a different date within the overridden range" do
result = generate_different_date_within_collection_year(date, start_date_override: Time.zone.local(2024, 8, 1), end_date_override: Time.zone.local(2024, 9, 1)) result = generate_different_date_within_collection_year(date, start_date_override: Time.zone.local(2024, 8, 1), end_date_override: Time.zone.local(2024, 9, 1))
expect(result).not_to eq(date) expect(result).not_to eq(date)
expect(result).to be_between(Time.zone.local(2024, 8, 1), Time.zone.local(2024, 9, 1)).inclusive expect(result).to be_between(Date.new(2024, 8, 1), Date.new(2024, 9, 1)).inclusive
end end
end end
@ -194,7 +194,7 @@ RSpec.describe CollectionTimeHelper do
it "ignores the start_date_override and returns a different date within the collection year" do it "ignores the start_date_override and returns a different date within the collection year" do
result = generate_different_date_within_collection_year(date, start_date_override: Time.zone.local(2023, 12, 31), end_date_override: Time.zone.local(2024, 5, 1)) result = generate_different_date_within_collection_year(date, start_date_override: Time.zone.local(2023, 12, 31), end_date_override: Time.zone.local(2024, 5, 1))
expect(result).not_to eq(date) expect(result).not_to eq(date)
expect(result).to be_between(Time.zone.local(2024, 4, 1), Time.zone.local(2024, 5, 1)).inclusive expect(result).to be_between(Date.new(2024, 4, 1), Date.new(2024, 5, 1)).inclusive
end end
end end
@ -202,7 +202,7 @@ RSpec.describe CollectionTimeHelper do
it "ignores the end_date_override and returns a different date within the collection year" do it "ignores the end_date_override and returns a different date within the collection year" do
result = generate_different_date_within_collection_year(date, start_date_override: Time.zone.local(2025, 3, 1), end_date_override: Time.zone.local(2025, 12, 1)) result = generate_different_date_within_collection_year(date, start_date_override: Time.zone.local(2025, 3, 1), end_date_override: Time.zone.local(2025, 12, 1))
expect(result).not_to eq(date) expect(result).not_to eq(date)
expect(result).to be_between(Time.zone.local(2025, 3, 1), Time.zone.local(2025, 3, 31)).inclusive expect(result).to be_between(Date.new(2025, 3, 1), Date.new(2025, 3, 31)).inclusive
end end
end end
@ -210,7 +210,7 @@ RSpec.describe CollectionTimeHelper do
it "ignores both overrides and returns a different date within the collection year" do it "ignores both overrides and returns a different date within the collection year" do
result = generate_different_date_within_collection_year(date, start_date_override: Time.zone.local(2023, 12, 31), end_date_override: Time.zone.local(2025, 12, 1)) result = generate_different_date_within_collection_year(date, start_date_override: Time.zone.local(2023, 12, 31), end_date_override: Time.zone.local(2025, 12, 1))
expect(result).not_to eq(date) expect(result).not_to eq(date)
expect(result).to be_between(Time.zone.local(2024, 4, 1), Time.zone.local(2025, 3, 31)).inclusive expect(result).to be_between(Date.new(2024, 4, 1), Date.new(2025, 3, 31)).inclusive
end end
end end
end end

146
spec/helpers/filters_helper_spec.rb

@ -478,136 +478,100 @@ RSpec.describe FiltersHelper do
end end
describe "#collection_year_options" do describe "#collection_year_options" do
context "with 23/24 as the current collection year" do context "and in crossover period" do
before do before do
allow(Time).to receive(:now).and_return(Time.zone.local(2023, 5, 1)) allow(FormHandler.instance).to receive(:in_crossover_period?).and_return(true)
end end
context "and in crossover period" do it "has the correct options" do
before do expect(collection_year_options).to eq(
allow(FormHandler.instance).to receive(:in_crossover_period?).and_return(true) {
end current_collection_start_year.to_s => "#{current_collection_start_year} to #{current_collection_end_year}",
previous_collection_start_year.to_s => "#{previous_collection_start_year} to #{previous_collection_end_year}",
it "has the correct options" do archived_collection_start_year.to_s => "#{archived_collection_start_year} to #{archived_collection_end_year}",
expect(collection_year_options).to eq( },
{ )
"2023" => "2023 to 2024", "2022" => "2022 to 2023", "2021" => "2021 to 2022"
},
)
end
end
context "and not in crossover period" do
before do
allow(FormHandler.instance).to receive(:in_crossover_period?).and_return(false)
end
it "has the correct options" do
expect(collection_year_options).to eq(
{
"2023" => "2023 to 2024", "2022" => "2022 to 2023"
},
)
end
end end
end end
context "with 24/25 as the current collection year" do context "and not in crossover period" do
before do before do
allow(Time).to receive(:now).and_return(Time.zone.local(2024, 5, 1)) allow(FormHandler.instance).to receive(:in_crossover_period?).and_return(false)
end end
context "and in crossover period" do it "has the correct options" do
before do expect(collection_year_options).to eq(
allow(FormHandler.instance).to receive(:in_crossover_period?).and_return(true) {
end current_collection_start_year.to_s => "#{current_collection_start_year} to #{current_collection_end_year}",
previous_collection_start_year.to_s => "#{previous_collection_start_year} to #{previous_collection_end_year}",
it "has the correct options" do },
expect(collection_year_options).to eq( )
{
"2024" => "2024 to 2025", "2023" => "2023 to 2024", "2022" => "2022 to 2023"
},
)
end
end end
context "and not in crossover period" do context "with future form use turned on" do
before do before do
allow(FormHandler.instance).to receive(:in_crossover_period?).and_return(false) allow(FeatureToggle).to receive(:allow_future_form_use?).and_return(true)
end end
it "has the correct options" do it "includes next year in the options" do
expect(collection_year_options).to eq( expect(collection_year_options).to eq(
{ {
"2024" => "2024 to 2025", "2023" => "2023 to 2024" next_collection_start_year.to_s => "#{next_collection_start_year} to #{next_collection_end_year}",
current_collection_start_year.to_s => "#{current_collection_start_year} to #{current_collection_end_year}",
previous_collection_start_year.to_s => "#{previous_collection_start_year} to #{previous_collection_end_year}",
}, },
) )
end end
context "with future form use turned on" do
before do
allow(FeatureToggle).to receive(:allow_future_form_use?).and_return(true)
end
it "includes next year in the options" do
expect(collection_year_options).to eq(
{
"2025" => "2025 to 2026", "2024" => "2024 to 2025", "2023" => "2023 to 2024"
},
)
end
end
end end
end end
end end
describe "#collection_year_radio_options" do describe "#collection_year_radio_options" do
context "with 23/24 as the current collection year" do context "and in crossover period" do
before do before do
allow(Time).to receive(:now).and_return(Time.zone.local(2023, 5, 1)) allow(FormHandler.instance).to receive(:in_crossover_period?).and_return(true)
end
context "and in crossover period" do
before do
allow(FormHandler.instance).to receive(:in_crossover_period?).and_return(true)
end
it "has the correct options" do
expect(collection_year_radio_options).to eq(
{
"2023" => { label: "2023 to 2024" }, "2022" => { label: "2022 to 2023" }, "2021" => { label: "2021 to 2022" }
},
)
end
end end
context "and not in crossover period" do it "has the correct options" do
before do expect(collection_year_radio_options).to eq(
allow(FormHandler.instance).to receive(:in_crossover_period?).and_return(false) {
end current_collection_start_year.to_s => { label: "#{current_collection_start_year} to #{current_collection_end_year}" },
previous_collection_start_year.to_s => { label: "#{previous_collection_start_year} to #{previous_collection_end_year}" },
it "has the correct options" do archived_collection_start_year.to_s => { label: "#{archived_collection_start_year} to #{archived_collection_end_year}" },
expect(collection_year_radio_options).to eq( },
{ )
"2023" => { label: "2023 to 2024" }, "2022" => { label: "2022 to 2023" }
},
)
end
end end
end end
context "with 24/25 as the current collection year" do context "and not in crossover period" do
before do before do
allow(Time).to receive(:now).and_return(Time.zone.local(2024, 5, 1)) allow(FormHandler.instance).to receive(:in_crossover_period?).and_return(false)
end end
it "has the correct options" do it "has the correct options" do
expect(collection_year_radio_options).to eq( expect(collection_year_radio_options).to eq(
{ {
"2024" => { label: "2024 to 2025" }, "2023" => { label: "2023 to 2024" }, "2022" => { label: "2022 to 2023" } current_collection_start_year.to_s => { label: "#{current_collection_start_year} to #{current_collection_end_year}" },
previous_collection_start_year.to_s => { label: "#{previous_collection_start_year} to #{previous_collection_end_year}" },
}, },
) )
end end
context "with future form use turned on" do
before do
allow(FeatureToggle).to receive(:allow_future_form_use?).and_return(true)
end
it "includes next year in the options" do
expect(collection_year_radio_options).to eq(
{
next_collection_start_year.to_s => { label: "#{next_collection_start_year} to #{next_collection_end_year}" },
current_collection_start_year.to_s => { label: "#{current_collection_start_year} to #{current_collection_end_year}" },
previous_collection_start_year.to_s => { label: "#{previous_collection_start_year} to #{previous_collection_end_year}" },
},
)
end
end
end end
end end

1
spec/helpers/locations_helper_spec.rb

@ -59,6 +59,7 @@ RSpec.describe LocationsHelper do
before do before do
allow(Time).to receive(:now).and_return(today) allow(Time).to receive(:now).and_return(today)
allow(FormHandler.instance).to receive(:lettings_in_crossover_period?).and_return(true) allow(FormHandler.instance).to receive(:lettings_in_crossover_period?).and_return(true)
Singleton.__init__(FormHandler)
end end
it "returns one active period without to date" do it "returns one active period without to date" do

21
spec/lib/tasks/count_duplicates_spec.rb

@ -101,7 +101,12 @@ RSpec.describe "count_duplicates" do
end end
it "creates a csv with correct duplicate numbers" do it "creates a csv with correct duplicate numbers" do
expect(storage_service).to receive(:write_file).with(/location-duplicates-.*\.csv/, "\uFEFFOrganisation id,Duplicate sets within individual schemes,Duplicate locations within individual schemes,All duplicate sets,All duplicates\n#{organisation.id},3,6,4,9\n#{organisation2.id},2,7,2,7\n") expect(storage_service).to receive(:write_file).with(/location-duplicates-.*\.csv/, satisfy do |s|
s.start_with?("\uFEFFOrganisation id,Duplicate sets within individual schemes,Duplicate locations within individual schemes,All duplicate sets,All duplicates") &&
s.include?("#{organisation.id},3,6,4,9") &&
s.include?("#{organisation2.id},2,7,2,7") &&
s.count("\n") == 3
end)
expect(Rails.logger).to receive(:info).with("Download URL: #{test_url}") expect(Rails.logger).to receive(:info).with("Download URL: #{test_url}")
task.invoke task.invoke
end end
@ -149,7 +154,12 @@ RSpec.describe "count_duplicates" do
end end
it "creates a csv with correct duplicate numbers" do it "creates a csv with correct duplicate numbers" do
expect(storage_service).to receive(:write_file).with(/scheme-duplicates-.*\.csv/, "\uFEFFOrganisation id,Number of duplicate sets,Total duplicate schemes\n#{organisation.id},2,5\n#{organisation2.id},1,5\n") expect(storage_service).to receive(:write_file).with(/scheme-duplicates-.*\.csv/, satisfy do |s|
s.start_with?("\uFEFFOrganisation id,Number of duplicate sets,Total duplicate schemes") &&
s.include?("#{organisation.id},2,5") &&
s.include?("#{organisation2.id},1,5") &&
s.count("\n") == 3
end)
expect(Rails.logger).to receive(:info).with("Download URL: #{test_url}") expect(Rails.logger).to receive(:info).with("Download URL: #{test_url}")
task.invoke task.invoke
end end
@ -211,7 +221,12 @@ RSpec.describe "count_duplicates" do
end end
it "creates a csv with correct duplicate numbers" do it "creates a csv with correct duplicate numbers" do
expect(storage_service).to receive(:write_file).with(/location-duplicates-.*\.csv/, "\uFEFFOrganisation id,Duplicate sets within individual schemes,Duplicate locations within individual schemes,All duplicate sets,All duplicates\n#{organisation.id},3,6,4,9\n#{organisation2.id},2,7,2,7\n") expect(storage_service).to receive(:write_file).with(/location-duplicates-.*\.csv/, satisfy do |s|
s.start_with?("\uFEFFOrganisation id,Duplicate sets within individual schemes,Duplicate locations within individual schemes,All duplicate sets,All duplicates")
s.include?("#{organisation.id},3,6,4,9") &&
s.include?("#{organisation2.id},2,7,2,7") &&
s.count("\n") == 3
end)
expect(Rails.logger).to receive(:info).with("Download URL: #{test_url}") expect(Rails.logger).to receive(:info).with("Download URL: #{test_url}")
task.invoke task.invoke
end end

6
spec/lib/tasks/update_schemes_and_locations_from_csv_spec.rb

@ -57,7 +57,7 @@ RSpec.describe "bulk_update" do
3, 3,
service_name: "Test name", service_name: "Test name",
sensitive: 1, sensitive: 1,
registered_under_care_act: 4, registered_under_care_act: 5,
support_type: 4, support_type: 4,
scheme_type: 7, scheme_type: 7,
arrangement_type: "D", arrangement_type: "D",
@ -123,7 +123,7 @@ RSpec.describe "bulk_update" do
schemes[1].reload schemes[1].reload
expect(schemes[1].service_name).to eq("Test name") expect(schemes[1].service_name).to eq("Test name")
expect(schemes[1].sensitive).to eq("Yes") expect(schemes[1].sensitive).to eq("Yes")
expect(schemes[1].registered_under_care_act).to eq("Yes – registered care home providing nursing care") expect(schemes[1].registered_under_care_act).to eq("Yes")
expect(schemes[1].support_type).to eq("High level") expect(schemes[1].support_type).to eq("High level")
expect(schemes[1].scheme_type).to eq("Housing for older people") expect(schemes[1].scheme_type).to eq("Housing for older people")
expect(schemes[1].arrangement_type).to eq("The same organisation that owns the housing stock") expect(schemes[1].arrangement_type).to eq("The same organisation that owns the housing stock")
@ -141,7 +141,7 @@ RSpec.describe "bulk_update" do
schemes[2].reload schemes[2].reload
expect(schemes[2].service_name).to eq("Test name") expect(schemes[2].service_name).to eq("Test name")
expect(schemes[2].sensitive).to eq("Yes") expect(schemes[2].sensitive).to eq("Yes")
expect(schemes[2].registered_under_care_act).to eq("Yes – registered care home providing nursing care") expect(schemes[2].registered_under_care_act).to eq("Yes")
expect(schemes[2].support_type).to eq("High level") expect(schemes[2].support_type).to eq("High level")
expect(schemes[2].scheme_type).to eq("Housing for older people") expect(schemes[2].scheme_type).to eq("Housing for older people")
expect(schemes[2].arrangement_type).to eq("The same organisation that owns the housing stock") expect(schemes[2].arrangement_type).to eq("The same organisation that owns the housing stock")

17
spec/services/merge/merge_organisations_service_spec.rb

@ -546,9 +546,12 @@ RSpec.describe Merge::MergeOrganisationsService do
merging_organisation.reload merging_organisation.reload
expect(absorbing_organisation.owned_lettings_logs.count).to eq(2) expect(absorbing_organisation.owned_lettings_logs.count).to eq(2)
expect(absorbing_organisation.managed_lettings_logs.count).to eq(1) expect(absorbing_organisation.managed_lettings_logs.count).to eq(1)
expect(absorbing_organisation.owned_lettings_logs.find(owned_lettings_log.id).scheme).to eq(absorbing_organisation.owned_schemes.first)
expect(absorbing_organisation.owned_lettings_logs.find(owned_lettings_log.id).location).to eq(absorbing_organisation.owned_schemes.first.locations.first) absorbed_active_scheme = absorbing_organisation.owned_schemes.find_by(service_name: scheme.service_name)
expect(absorbing_organisation.owned_lettings_logs.find(owned_lettings_log_no_location.id).scheme).to eq(absorbing_organisation.owned_schemes.first) absorbed_active_location = absorbed_active_scheme.locations.find_by(postcode: location.postcode)
expect(absorbing_organisation.owned_lettings_logs.find(owned_lettings_log.id).scheme).to eq(absorbed_active_scheme)
expect(absorbing_organisation.owned_lettings_logs.find(owned_lettings_log.id).location).to eq(absorbed_active_location)
expect(absorbing_organisation.owned_lettings_logs.find(owned_lettings_log_no_location.id).scheme).to eq(absorbed_active_scheme)
expect(absorbing_organisation.owned_lettings_logs.find(owned_lettings_log_no_location.id).location).to eq(nil) expect(absorbing_organisation.owned_lettings_logs.find(owned_lettings_log_no_location.id).location).to eq(nil)
end end
@ -814,12 +817,12 @@ RSpec.describe Merge::MergeOrganisationsService do
it "moves active schemes and locations to absorbing organisation" do it "moves active schemes and locations to absorbing organisation" do
expect(absorbing_organisation.owned_schemes.count).to eq(2) expect(absorbing_organisation.owned_schemes.count).to eq(2)
expect(absorbing_organisation.owned_schemes.first.locations.map(&:postcode)).to match_array([location, deactivated_location, location_without_startdate, location_with_past_startdate, location_with_future_startdate].map(&:postcode))
expect(absorbing_organisation.owned_schemes.first.locations.find_by(postcode: location_without_startdate.postcode).startdate).to eq(Time.zone.yesterday)
expect(absorbing_organisation.owned_schemes.first.locations.find_by(postcode: location_with_past_startdate.postcode).startdate).to eq(Time.zone.yesterday)
expect(absorbing_organisation.owned_schemes.first.locations.find_by(postcode: location_with_future_startdate.postcode).startdate.to_date).to eq(Time.zone.today + 2.months)
absorbed_active_scheme = absorbing_organisation.owned_schemes.find_by(service_name: scheme.service_name) absorbed_active_scheme = absorbing_organisation.owned_schemes.find_by(service_name: scheme.service_name)
absorbed_active_location = absorbed_active_scheme.locations.find_by(postcode: location.postcode) absorbed_active_location = absorbed_active_scheme.locations.find_by(postcode: location.postcode)
expect(absorbed_active_scheme.locations.map(&:postcode)).to match_array([location, deactivated_location, location_without_startdate, location_with_past_startdate, location_with_future_startdate].map(&:postcode))
expect(absorbed_active_scheme.locations.find_by(postcode: location_without_startdate.postcode).startdate).to eq(Time.zone.yesterday)
expect(absorbed_active_scheme.locations.find_by(postcode: location_with_past_startdate.postcode).startdate).to eq(Time.zone.yesterday)
expect(absorbed_active_scheme.locations.find_by(postcode: location_with_future_startdate.postcode).startdate.to_date).to eq(Time.zone.today + 2.months)
expect(absorbed_active_scheme.service_name).to eq(scheme.service_name) expect(absorbed_active_scheme.service_name).to eq(scheme.service_name)
expect(absorbed_active_scheme.old_id).to be_nil expect(absorbed_active_scheme.old_id).to be_nil
expect(absorbed_active_scheme.old_visible_id).to be_nil expect(absorbed_active_scheme.old_visible_id).to be_nil

Loading…
Cancel
Save