<%= f.govuk_error_summary %>
@@ -21,13 +21,13 @@
label: { text: "Email address", size: "m" },
autocomplete: "email",
spellcheck: "false",
- value: @resource.email %>
+ value: @user.email %>
<%= f.govuk_phone_field :phone,
label: { text: "Telephone number", size: "m" },
autocomplete: "phone",
spellcheck: "false",
- value: @resource.phone %>
+ value: @user.phone %>
<% if current_user.support? %>
<% null_option = [OpenStruct.new(id: "", name: "Select an option")] %>
diff --git a/config/forms/2021_2022.json b/config/forms/2021_2022.json
index 006a716de..37e796e04 100644
--- a/config/forms/2021_2022.json
+++ b/config/forms/2021_2022.json
@@ -7074,7 +7074,8 @@
"type": "radio",
"answer_options": {
"1": {
- "value": "Internal transfer"
+ "value": "Internal transfer",
+ "hint": "Where the tenant has moved to another social property owned by the same landlord."
},
"2": {
"value": "Tenant applied directly (no referral or nomination)"
@@ -7131,7 +7132,8 @@
"type": "radio",
"answer_options": {
"1": {
- "value": "Internal transfer"
+ "value": "Internal transfer",
+ "hint": "Where the tenant has moved to another social property owned by the same landlord."
},
"2": {
"value": "Tenant applied directly (no nomination)"
@@ -7194,7 +7196,8 @@
"type": "radio",
"answer_options": {
"1": {
- "value": "Internal transfer"
+ "value": "Internal transfer",
+ "hint": "Where the tenant has moved to another social property owned by the same landlord."
},
"2": {
"value": "Tenant applied directly (no referral)"
@@ -7254,7 +7257,8 @@
"type": "radio",
"answer_options": {
"1": {
- "value": "Internal transfer"
+ "value": "Internal transfer",
+ "hint": "Where the tenant has moved to another social property owned by the same landlord."
},
"2": {
"value": "Tenant applied directly (no referral or nomination)"
diff --git a/config/forms/2022_2023.json b/config/forms/2022_2023.json
index 5dc249050..affc18971 100644
--- a/config/forms/2022_2023.json
+++ b/config/forms/2022_2023.json
@@ -6991,7 +6991,8 @@
"type": "radio",
"answer_options": {
"1": {
- "value": "Internal transfer"
+ "value": "Internal transfer",
+ "hint": "Where the tenant has moved to another social property owned by the same landlord."
},
"2": {
"value": "Tenant applied directly (no referral or nomination)"
@@ -7048,7 +7049,8 @@
"type": "radio",
"answer_options": {
"1": {
- "value": "Internal transfer"
+ "value": "Internal transfer",
+ "hint": "Where the tenant has moved to another social property owned by the same landlord."
},
"2": {
"value": "Tenant applied directly (no nomination)"
@@ -7056,8 +7058,8 @@
"3": {
"value": "Nominated by a local housing authority"
},
- "4" : {
- "value" : "Referred by local authority housing department"
+ "4" : {
+ "value" : "Referred by local authority housing department"
},
"8": {
"value": "Re-located through official housing mobility scheme"
@@ -7111,7 +7113,8 @@
"type": "radio",
"answer_options": {
"1": {
- "value": "Internal transfer"
+ "value": "Internal transfer",
+ "hint": "Where the tenant has moved to another social property owned by the same landlord."
},
"2": {
"value": "Tenant applied directly (no referral)"
@@ -7171,7 +7174,8 @@
"type": "radio",
"answer_options": {
"1": {
- "value": "Internal transfer"
+ "value": "Internal transfer",
+ "hint": "Where the tenant has moved to another social property owned by the same landlord."
},
"2": {
"value": "Tenant applied directly (no referral or nomination)"
@@ -8316,7 +8320,7 @@
}
}
},
- "interruption_screen_question_ids": ["brent", "startdate", "la", "beds", "rent_type", "needstype"]
+ "interruption_screen_question_ids": ["brent", "period", "startdate", "la", "beds", "rent_type", "needstype"]
},
"max_rent_value_check": {
"depends_on": [
@@ -8361,7 +8365,7 @@
}
}
},
- "interruption_screen_question_ids": ["brent", "startdate", "la", "beds", "rent_type", "needstype"]
+ "interruption_screen_question_ids": ["brent", "period", "startdate", "la", "beds", "rent_type", "needstype"]
},
"scharge_value_check": {
"depends_on": [
diff --git a/config/initializers/sidekiq.rb b/config/initializers/sidekiq.rb
index 74e6ce9a2..60cc29b3a 100644
--- a/config/initializers/sidekiq.rb
+++ b/config/initializers/sidekiq.rb
@@ -32,7 +32,10 @@ Redis.silence_deprecations = true
Sidekiq.configure_server do |config|
config.on(:startup) do
- Sidekiq::Cron::Job.load_from_hash YAML.load_file("config/sidekiq_cron_schedule.yml")
+ Sidekiq::Cron::Job.all.each(&:destroy)
+ unless FeatureToggle.maintenance_mode_enabled?
+ Sidekiq::Cron::Job.load_from_hash YAML.load_file("config/sidekiq_cron_schedule.yml")
+ end
end
config.on(:shutdown) do
diff --git a/config/locales/en.yml b/config/locales/en.yml
index 2890f3bde..69a4a8bb9 100644
--- a/config/locales/en.yml
+++ b/config/locales/en.yml
@@ -265,7 +265,7 @@ en:
owning_organisation: "Enter a date when the owning organisation was active. %{owning_organisation} became inactive on %{owning_organisation_merge_date} and was replaced by %{owning_absorbing_organisation}."
managing_organisation: "Enter a date when the managing organisation was active. %{managing_organisation} became inactive on %{managing_organisation_merge_date} and was replaced by %{managing_absorbing_organisation}."
different_merge: "Enter a date when the owning and managing organisations were active. %{owning_organisation} became inactive on %{owning_organisation_merge_date} and was replaced by %{owning_absorbing_organisation}. %{managing_organisation} became inactive on %{managing_organisation_merge_date} and was replaced by %{managing_absorbing_organisation}."
- invalid_absorbing_organisations_start_date:
+ invalid_absorbing_organisations_start_date:
same_organisation: "Enter a date when the owning and managing organisation was active. %{owning_organisation} became active on %{owning_organisation_available_from}."
owning_organisation: "Enter a date when the owning organisation was active. %{owning_organisation} became active on %{owning_organisation_available_from}."
managing_organisation: "Enter a date when the managing organisation was active. %{managing_organisation} became active on %{managing_organisation_available_from}."
@@ -367,27 +367,7 @@ en:
negative_currency: "Enter an amount above 0"
rent:
less_than_shortfall: "Enter an amount that is more than the shortfall in basic rent"
- scharge:
- private_registered_provider:
- general_needs: "Enter a value for the service charge between £0 and £800 per week if the landlord is a private registered provider and it is a general needs letting"
- supported_housing: "Enter a value for the service charge between £0 and £800 per week if the landlord is a private registered provider and it is a supported housing letting"
- local_authority:
- general_needs: "Enter a value for the service charge between £0 and £500 per week if the landlord is a local authority and it is a general needs letting"
- supported_housing: "Enter a value for the service charge between £0 and £500 per week if the landlord is a local authority and it is a supported housing letting"
- pscharge:
- private_registered_provider:
- general_needs: "Enter a value for the personal service charge between £0 and £700 per week if the landlord is a private registered provider and it is a general needs letting"
- supported_housing: "Enter a value for the personal service charge between £0 and £700 per week if the landlord is a private registered provider and it is a supported housing letting"
- local_authority:
- general_needs: "Enter a value for the personal service charge between £0 and £200 per week if the landlord is a local authority and it is a general needs letting"
- supported_housing: "Enter a value for the personal service charge between £0 and £200 per week if the landlord is a local authority and it is a supported housing letting"
- supcharg:
- private_registered_provider:
- general_needs: "Enter a value for the support charge between £0 and £800 per week if the landlord is a private registered provider and it is a general needs letting"
- supported_housing: "Enter a value for the support charge between £0 and £800 per week if the landlord is a private registered provider and it is a supported housing letting"
- local_authority:
- general_needs: "Enter a value for the support charge between £0 and £200 per week if the landlord is a local authority and it is a general needs letting"
- supported_housing: "Enter a value for the support charge between £0 and £200 per week if the landlord is a local authority and it is a supported housing letting"
+ out_of_range: "Enter a value for the %{charge_name} between £0 and %{maximum_per_period} paid %{frequency}. %{maximum_per_period} is the max limit for rent and charges paid %{frequency} for %{letting_type} lettings owned by a %{provider_type}."
ecstat:
over_hard_max: "Net income of %{hard_max} per week is too high given the tenant’s working situation"
brent:
@@ -722,7 +702,7 @@ Make sure these answers are correct."
charges:
informative_text: "This is higher than we would expect."
hint_text: "Check the following:
- the decimal point
- the frequency, for example every week or every calendar month
- the needs type
"
-
+
devise:
email:
diff --git a/config/routes.rb b/config/routes.rb
index 621ee820c..498e7d9a2 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -35,6 +35,7 @@ Rails.application.routes.draw do
get "/accessibility-statement", to: "content#accessibility_statement"
get "/privacy-notice", to: "content#privacy_notice"
get "/data-sharing-agreement", to: "content#data_sharing_agreement"
+ get "/service-unavailable", to: "maintenance#service_unavailable"
get "/download-23-24-lettings-form", to: "start#download_23_24_lettings_form"
get "/download-22-23-lettings-form", to: "start#download_22_23_lettings_form"
diff --git a/db/migrate/20231023142854_add_available_from_to_org.rb b/db/migrate/20231023142854_add_available_from_to_org.rb
new file mode 100644
index 000000000..7cfb4b1aa
--- /dev/null
+++ b/db/migrate/20231023142854_add_available_from_to_org.rb
@@ -0,0 +1,5 @@
+class AddAvailableFromToOrg < ActiveRecord::Migration[7.0]
+ def change
+ add_column :organisations, :available_from, :datetime
+ end
+end
diff --git a/db/schema.rb b/db/schema.rb
index e353ff9c7..7eda570d1 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
-ActiveRecord::Schema[7.0].define(version: 2023_09_13_093443) do
+ActiveRecord::Schema[7.0].define(version: 2023_10_23_142854) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@@ -440,6 +440,7 @@ ActiveRecord::Schema[7.0].define(version: 2023_09_13_093443) do
t.string "old_visible_id"
t.datetime "merge_date"
t.bigint "absorbing_organisation_id"
+ t.datetime "available_from"
t.index ["absorbing_organisation_id"], name: "index_organisations_on_absorbing_organisation_id"
t.index ["old_visible_id"], name: "index_organisations_on_old_visible_id", unique: true
end
diff --git a/docs/adr/index.md b/docs/adr/index.md
index 13abde54b..edb60b688 100644
--- a/docs/adr/index.md
+++ b/docs/adr/index.md
@@ -1,6 +1,6 @@
---
has_children: true
-nav_order: 9
+nav_order: 10
---
# Architecture decisions
diff --git a/docs/app_api.md b/docs/app_api.md
new file mode 100644
index 000000000..093fd918f
--- /dev/null
+++ b/docs/app_api.md
@@ -0,0 +1,15 @@
+---
+nav_order: 8
+---
+
+# Using the App API
+
+In order to use the app as an API, you will need to configure requests to the API as so:
+
+* Configure your request with Basic Auth. Set the username to be the same as `API_USER` and password as the `API_KEY` (`API_USER` and `API_KEY` are environment variables that should be set for the application)
+* Check the endpoint you are calling is an action that is `create`, `show` or `update`
+* Check you are setting the following request headers:
+ * `Content-Type = application/json`
+ * `Action = application/json` N.B. If you use `*/*` instead, the request won't be recognised as an API request`
+
+Currently only the logs controller is configured to accept and authenticate API requests, when the above API environment variables are set.
diff --git a/docs/documentation_website.md b/docs/documentation_website.md
index ed1f1633e..9eb763050 100644
--- a/docs/documentation_website.md
+++ b/docs/documentation_website.md
@@ -1,5 +1,5 @@
---
-nav_order: 10
+nav_order: 11
---
# This documentation website
diff --git a/docs/form/index.md b/docs/form/index.md
index 148ffb1c4..664b136c7 100644
--- a/docs/form/index.md
+++ b/docs/form/index.md
@@ -1,6 +1,6 @@
---
has_children: true
-nav_order: 8
+nav_order: 9
---
# Generating forms
diff --git a/docs/setup.md b/docs/setup.md
index 9b5c049c1..25d28dcf4 100644
--- a/docs/setup.md
+++ b/docs/setup.md
@@ -1,5 +1,5 @@
---
-nav_order: 2
+nav_order: 3
---
# Local development
diff --git a/lib/tasks/correct_illness_from_csv.rake b/lib/tasks/correct_illness_from_csv.rake
index 2fc3eec74..92bbb8921 100644
--- a/lib/tasks/correct_illness_from_csv.rake
+++ b/lib/tasks/correct_illness_from_csv.rake
@@ -20,7 +20,9 @@ namespace :correct_illness do
raise "Usage: rake correct_illness:correct_illness_from_csv['csv_file_name']" if file_name.blank?
s3_service = Storage::S3Service.new(PlatformHelper.is_paas? ? Configuration::PaasConfigurationService.new : Configuration::EnvConfigurationService.new, ENV["IMPORT_PAAS_INSTANCE"])
- illness_csv = CSV.parse(s3_service.get_file_io(file_name), headers: false)
+ file_io = s3_service.get_file_io(file_name)
+ file_io.set_encoding_by_bom
+ illness_csv = CSV.parse(file_io, headers: false)
illness_csv.each_with_index do |row, index|
next if index < 3
diff --git a/lib/tasks/import_address_from_csv.rake b/lib/tasks/import_address_from_csv.rake
index 57496a56c..c81cc2162 100644
--- a/lib/tasks/import_address_from_csv.rake
+++ b/lib/tasks/import_address_from_csv.rake
@@ -6,7 +6,9 @@ namespace :data_import do
raise "Usage: rake data_import:import_lettings_addresses_from_csv['csv_file_name']" if file_name.blank?
s3_service = Storage::S3Service.new(PlatformHelper.is_paas? ? Configuration::PaasConfigurationService.new : Configuration::EnvConfigurationService.new, ENV["IMPORT_PAAS_INSTANCE"])
- addresses_csv = CSV.parse(s3_service.get_file_io(file_name), headers: true)
+ file_io = s3_service.get_file_io(file_name)
+ file_io.set_encoding_by_bom
+ addresses_csv = CSV.parse(file_io, headers: true)
contains_issue_type = addresses_csv.headers.include?("Issue type")
addresses_csv.each do |row|
@@ -53,8 +55,11 @@ namespace :data_import do
lettings_log.send("process_postcode_changes!")
lettings_log.values_updated_at = Time.zone.now
- lettings_log.save!
- Rails.logger.info("Updated lettings log #{lettings_log_id}, with address: #{[lettings_log.address_line1, lettings_log.address_line2, lettings_log.town_or_city, lettings_log.county, lettings_log.postcode_full].join(', ')}")
+ if lettings_log.save
+ Rails.logger.info("Updated lettings log #{lettings_log_id}, with address: #{[lettings_log.address_line1, lettings_log.address_line2, lettings_log.town_or_city, lettings_log.county, lettings_log.postcode_full].join(', ')}")
+ else
+ Rails.logger.error("Validation failed for lettings log with ID #{lettings_log.id}: #{lettings_log.errors.full_messages.join(', ')}}")
+ end
end
end
@@ -65,7 +70,9 @@ namespace :data_import do
raise "Usage: rake data_import:import_sales_addresses_from_csv['csv_file_name']" if file_name.blank?
s3_service = Storage::S3Service.new(PlatformHelper.is_paas? ? Configuration::PaasConfigurationService.new : Configuration::EnvConfigurationService.new, ENV["IMPORT_PAAS_INSTANCE"])
- addresses_csv = CSV.parse(s3_service.get_file_io(file_name), headers: true)
+ file_io = s3_service.get_file_io(file_name)
+ file_io.set_encoding_by_bom
+ addresses_csv = CSV.parse(file_io, headers: true)
contains_issue_type = addresses_csv.headers.include?("Issue type")
addresses_csv.each do |row|
@@ -112,8 +119,11 @@ namespace :data_import do
sales_log.send("process_postcode_changes!")
sales_log.values_updated_at = Time.zone.now
- sales_log.save!
- Rails.logger.info("Updated sales log #{sales_log_id}, with address: #{[sales_log.address_line1, sales_log.address_line2, sales_log.town_or_city, sales_log.county, sales_log.postcode_full].join(', ')}")
+ if sales_log.save
+ Rails.logger.info("Updated sales log #{sales_log_id}, with address: #{[sales_log.address_line1, sales_log.address_line2, sales_log.town_or_city, sales_log.county, sales_log.postcode_full].join(', ')}")
+ else
+ Rails.logger.error("Validation failed for sales log with ID #{sales_log.id}: #{sales_log.errors.full_messages.join(', ')}}")
+ end
end
end
end
diff --git a/lib/tasks/merge_organisations.rake b/lib/tasks/merge_organisations.rake
index 820343883..07b17dffd 100644
--- a/lib/tasks/merge_organisations.rake
+++ b/lib/tasks/merge_organisations.rake
@@ -1,12 +1,37 @@
namespace :merge do
- desc "Merge organisations into one"
- task :merge_organisations, %i[absorbing_organisation_id merging_organisation_ids] => :environment do |_task, args|
+ desc "Merge organisations into an existing organisation"
+ task :merge_organisations, %i[absorbing_organisation_id merging_organisation_ids merge_date] => :environment do |_task, args|
absorbing_organisation_id = args[:absorbing_organisation_id]
merging_organisation_ids = args[:merging_organisation_ids]&.split(" ")&.map(&:to_i)
+ begin
+ merge_date = args[:merge_date].present? ? Date.parse(args[:merge_date]) : nil
+ rescue StandardError
+ raise "Usage: rake merge:merge_organisations[absorbing_organisation_id, merging_organisation_ids, merge_date]. Merge date must be in format YYYY-MM-DD"
+ end
- raise "Usage: rake merge:merge_organisations[absorbing_organisation_id, merging_organisation_ids]" if merging_organisation_ids.blank? || absorbing_organisation_id.blank?
+ if merging_organisation_ids.blank? || absorbing_organisation_id.blank?
+ raise "Usage: rake merge:merge_organisations[absorbing_organisation_id, merging_organisation_ids, merge_date]"
+ end
- service = Merge::MergeOrganisationsService.new(absorbing_organisation_id:, merging_organisation_ids:)
+ service = Merge::MergeOrganisationsService.new(absorbing_organisation_id:, merging_organisation_ids:, merge_date:)
+ service.call
+ end
+
+ desc "Merge organisations into an existing organisation, make the absorbing organisation active from merge date only"
+ task :merge_organisations_into_new_organisation, %i[absorbing_organisation_id merging_organisation_ids merge_date] => :environment do |_task, args|
+ absorbing_organisation_id = args[:absorbing_organisation_id]
+ merging_organisation_ids = args[:merging_organisation_ids]&.split(" ")&.map(&:to_i)
+ begin
+ merge_date = args[:merge_date].present? ? Date.parse(args[:merge_date]) : nil
+ rescue StandardError
+ raise "Usage: rake merge:merge_organisations_into_new_organisation[absorbing_organisation_id, merging_organisation_ids, merge_date]. Merge date must be in format YYYY-MM-DD"
+ end
+
+ if merging_organisation_ids.blank? || absorbing_organisation_id.blank?
+ raise "Usage: rake merge:merge_organisations_into_new_organisation[absorbing_organisation_id, merging_organisation_ids, merge_date]"
+ end
+
+ service = Merge::MergeOrganisationsService.new(absorbing_organisation_id:, merging_organisation_ids:, merge_date:, absorbing_organisation_active_from_merge_date: true)
service.call
end
end
diff --git a/lib/tasks/recalculate_irproduct_values.rake b/lib/tasks/recalculate_irproduct_values.rake
new file mode 100644
index 000000000..751eae432
--- /dev/null
+++ b/lib/tasks/recalculate_irproduct_values.rake
@@ -0,0 +1,18 @@
+desc "Forces to recalculate irproduct values"
+task recalculate_irproduct_values: :environment do
+ LettingsLog.exportable.where(rent_type: [3, 4, 5]).where(irproduct: nil).each do |log| # irproduct was never set
+ Rails.logger.info("Could not update irproduct for LettingsLog #{log.id}") unless log.update(values_updated_at: Time.zone.now)
+ end
+ LettingsLog.exportable.where(rent_type: 3).where.not(irproduct: 1).each do |log| # irproduct was set wrong
+ Rails.logger.info("Could not update irproduct for LettingsLog #{log.id}") unless log.update(values_updated_at: Time.zone.now)
+ end
+ LettingsLog.exportable.where(rent_type: 4).where.not(irproduct: 2).each do |log| # irproduct was set wrong
+ Rails.logger.info("Could not update irproduct for LettingsLog #{log.id}") unless log.update(values_updated_at: Time.zone.now)
+ end
+ LettingsLog.exportable.where(rent_type: 5).where.not(irproduct: 3).each do |log| # irproduct was set wrong
+ Rails.logger.info("Could not update irproduct for LettingsLog #{log.id}") unless log.update(values_updated_at: Time.zone.now)
+ end
+ LettingsLog.exportable.where.not(rent_type: [3, 4, 5]).where.not(irproduct: nil).each do |log| # irproduct was set when it should have been nil
+ Rails.logger.info("Could not update irproduct for LettingsLog #{log.id}") unless log.update(values_updated_at: Time.zone.now)
+ end
+end
diff --git a/lib/tasks/recalculate_lar_values.rake b/lib/tasks/recalculate_lar_values.rake
new file mode 100644
index 000000000..f08a38726
--- /dev/null
+++ b/lib/tasks/recalculate_lar_values.rake
@@ -0,0 +1,13 @@
+desc "Forces to recalculate lar values for affordable rent types and clears irrelevant lar values"
+task recalculate_lar_values: :environment do
+ LettingsLog.exportable.where(rent_type: [1, 2], lar: nil).each do |log| # lar was never set
+ Rails.logger.info("Could not update lar for LettingsLog #{log.id}") unless log.update(values_updated_at: Time.zone.now)
+ end
+ LettingsLog.exportable.where(rent_type: 1).where.not(lar: 2).each do |log| # lar was set wrong
+ Rails.logger.info("Could not update lar for LettingsLog #{log.id}") unless log.update(values_updated_at: Time.zone.now)
+ end
+ LettingsLog.exportable.where(rent_type: 2).where.not(lar: 1).each do |log| # lar was set wrong
+ Rails.logger.info("Could not update lar for LettingsLog #{log.id}") unless log.update(values_updated_at: Time.zone.now)
+ end
+ LettingsLog.exportable.where.not(rent_type: [1, 2]).where.not(lar: nil).update_all(lar: nil) # lar was set to 2 but should never have been set
+end
diff --git a/lib/tasks/squish_names.rake b/lib/tasks/squish_names.rake
new file mode 100644
index 000000000..697bc7d7b
--- /dev/null
+++ b/lib/tasks/squish_names.rake
@@ -0,0 +1,35 @@
+desc "Squish names of locations, schemes, users, and organisations"
+task squish_names: :environment do
+ Location.where("name LIKE ?", "% %").each do |location|
+ location.name&.squish!
+ begin
+ location.save!
+ rescue StandardError => e
+ Sentry.capture_exception(e)
+ end
+ end
+ Scheme.where("service_name LIKE ?", "% %").each do |scheme|
+ scheme.service_name&.squish!
+ begin
+ scheme.save!
+ rescue StandardError => e
+ Sentry.capture_exception(e)
+ end
+ end
+ User.where("name LIKE ?", "% %").each do |user|
+ user.name&.squish!
+ begin
+ user.save!
+ rescue StandardError => e
+ Sentry.capture_exception(e)
+ end
+ end
+ Organisation.where("name LIKE ?", "% %").each do |organisation|
+ organisation.name&.squish!
+ begin
+ organisation.save!
+ rescue StandardError => e
+ Sentry.capture_exception(e)
+ end
+ end
+end
diff --git a/spec/components/search_result_caption_component_spec.rb b/spec/components/search_result_caption_component_spec.rb
index ed4934633..3e6baaada 100644
--- a/spec/components/search_result_caption_component_spec.rb
+++ b/spec/components/search_result_caption_component_spec.rb
@@ -6,20 +6,53 @@ RSpec.describe SearchResultCaptionComponent, type: :component do
let(:item_label) { "user" }
let(:total_count) { 3 }
let(:item) { "schemes" }
- let(:path) { "path" }
+ let(:filters_count) { 1 }
+ let(:result) { render_inline(described_class.new(searched:, count:, item_label:, total_count:, item:, filters_count:)) }
- it "renders table caption including the search results and total" do
- result = render_inline(described_class.new(searched:, count:, item_label:, total_count:, item:, path:))
- expect(result.to_html).to eq("
\n #{count} #{item_label} found matching ‘#{searched}’ of #{total_count} total #{item}. Clear search\n\n")
+ context "when search and filter results are found" do
+ it "renders table caption including the search results and total" do
+ expect(result.to_html).to eq("
\n 2 users matching search and filters
\n\n")
+ end
+ end
+
+ context "when search results are found" do
+ let(:filters_count) { nil }
+
+ it "renders table caption including the search results and total" do
+ expect(result.to_html).to eq("
\n 2 users matching search
\n\n")
+ end
+ end
+
+ context "when filter results are found" do
+ let(:searched) { nil }
+
+ it "renders table caption including the search results and total" do
+ expect(result.to_html).to eq("
\n 2 users matching filters
\n\n")
+ end
end
- context "when no search results are found" do
+ context "when no search/filter is applied" do
let(:searched) { nil }
+ let(:filters_count) { nil }
it "renders table caption with total count only" do
- result = render_inline(described_class.new(searched:, count:, item_label:, total_count:, item:, path:))
+ expect(result.to_html).to eq("
\n #{count} matching #{item}\n\n")
+ end
+ end
+
+ context "when nothing is found" do
+ let(:count) { 0 }
- expect(result.to_html).to eq("
\n #{count} total #{item}\n\n")
+ it "renders table caption with total count only" do
+ expect(result.to_html).to eq("
\n 0 users matching search and filters
\n\n")
+ end
+ end
+
+ context "when 1 record is found" do
+ let(:count) { 1 }
+
+ it "renders table caption with total count only" do
+ expect(result.to_html).to eq("
\n 1 user matching search and filters
\n\n")
end
end
end
diff --git a/spec/controllers/maintenance_controller_spec.rb b/spec/controllers/maintenance_controller_spec.rb
new file mode 100644
index 000000000..032ac4858
--- /dev/null
+++ b/spec/controllers/maintenance_controller_spec.rb
@@ -0,0 +1,27 @@
+require "rails_helper"
+
+RSpec.describe MaintenanceController do
+ let(:user) { FactoryBot.create(:user) }
+
+ describe "GET #service_unavailable" do
+ context "when maintenance mode is enabled" do
+ it "logs the user out" do
+ allow(FeatureToggle).to receive(:maintenance_mode_enabled?).and_return(true)
+ sign_in user
+ expect(controller).to be_user_signed_in
+ get :service_unavailable
+ expect(controller).not_to be_user_signed_in
+ end
+ end
+
+ context "when maintenance mode is disabled" do
+ it "doesn't log the user out" do
+ allow(FeatureToggle).to receive(:maintenance_mode_enabled?).and_return(false)
+ sign_in user
+ expect(controller).to be_user_signed_in
+ get :service_unavailable
+ expect(controller).to be_user_signed_in
+ end
+ end
+ end
+end
diff --git a/spec/factories/lettings_log.rb b/spec/factories/lettings_log.rb
index e661645c7..f01d6b4a4 100644
--- a/spec/factories/lettings_log.rb
+++ b/spec/factories/lettings_log.rb
@@ -3,7 +3,10 @@ FactoryBot.define do
created_by { FactoryBot.create(:user) }
owning_organisation { created_by.organisation }
managing_organisation { created_by.organisation }
+ created_at { Time.zone.today }
+ updated_at { Time.zone.today }
trait :setup_completed do
+ startdate_today
renewal { 0 }
needstype { 1 }
rent_type { 1 }
@@ -206,7 +209,5 @@ FactoryBot.define do
illness_type_9 { false }
illness_type_10 { false }
end
- created_at { Time.zone.today }
- updated_at { Time.zone.today }
end
end
diff --git a/spec/factories/user.rb b/spec/factories/user.rb
index 7f9b45932..935bd30f6 100644
--- a/spec/factories/user.rb
+++ b/spec/factories/user.rb
@@ -5,6 +5,7 @@ FactoryBot.define do
password { "pAssword1" }
organisation
role { "data_provider" }
+ phone { "1234512345123" }
trait :data_coordinator do
role { "data_coordinator" }
end
diff --git a/spec/features/form/form_navigation_spec.rb b/spec/features/form/form_navigation_spec.rb
index 9a9f14383..a5784d1ec 100644
--- a/spec/features/form/form_navigation_spec.rb
+++ b/spec/features/form/form_navigation_spec.rb
@@ -176,4 +176,18 @@ RSpec.describe "Form Navigation" do
end
end
end
+
+ describe "fixing duplicate logs" do
+ it "shows a correct cancel link" do
+ visit("lettings-logs/#{id}/tenant-code-test?first_remaining_duplicate_id=x&original_log_id=#{id}&referrer=duplicate_logs")
+ click_link(text: "Cancel")
+ expect(page).to have_current_path("/lettings-logs/#{id}/duplicate-logs?original_log_id=#{id}")
+ end
+
+ it "shows a correct Save Changes buttons" do
+ visit("lettings-logs/#{id}/tenant-code-test?first_remaining_duplicate_id=#{id}&original_log_id=#{id}&referrer=duplicate_logs")
+ click_button(text: "Save changes")
+ expect(page).to have_current_path("/lettings-logs/#{id}/duplicate-logs?original_log_id=#{id}&referrer=duplicate_logs")
+ end
+ end
end
diff --git a/spec/features/lettings_log_spec.rb b/spec/features/lettings_log_spec.rb
index 9f8cfbb77..5790ed1f6 100644
--- a/spec/features/lettings_log_spec.rb
+++ b/spec/features/lettings_log_spec.rb
@@ -79,7 +79,7 @@ RSpec.describe "Lettings Log 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_content("Clear")
+ expect(page).not_to have_link("Clear", href: "/clear-filters?filter_type=lettings_logs")
end
end
@@ -97,7 +97,7 @@ RSpec.describe "Lettings Log Features" do
it "displays the filters component with a correct count and clear button" do
expect(page).to have_content("5 filters applied")
- expect(page).to have_content("Clear")
+ expect(page).to have_link("Clear", href: "/clear-filters?filter_type=lettings_logs")
end
context "when clearing the filters" do
@@ -107,7 +107,7 @@ RSpec.describe "Lettings Log Features" do
it "clears the filters and displays the filter component as before" do
expect(page).to have_content("No filters applied")
- expect(page).not_to have_content("Clear")
+ expect(page).not_to have_link("Clear", href: "/clear-filters?filter_type=lettings_logs")
end
end
end
@@ -467,7 +467,7 @@ RSpec.describe "Lettings Log Features" do
expect(duplicate_log.deleted?).to be true
expect(page).to have_css(".govuk-notification-banner.govuk-notification-banner--success")
expect(page).to have_content("Log #{duplicate_log.id} has been deleted.")
- expect(page).to have_current_path("/lettings-logs/#{lettings_log.id}/duplicate-logs?original_log_id=#{lettings_log.id}")
+ expect(page).to have_current_path("/lettings-logs/#{lettings_log.id}/duplicate-logs?organisation_id=&original_log_id=#{lettings_log.id}&referrer=")
expect(page).not_to have_content("These logs are duplicates")
expect(page).not_to have_link("Keep this log and delete duplicates")
expect(page).to have_link("Back to Log #{lettings_log.id}", href: "/lettings-logs/#{lettings_log.id}")
@@ -491,7 +491,7 @@ RSpec.describe "Lettings Log Features" do
expect(lettings_log.status).to eq("deleted")
expect(page).to have_css(".govuk-notification-banner.govuk-notification-banner--success")
expect(page).to have_content("Log #{lettings_log.id} has been deleted.")
- expect(page).to have_current_path("/lettings-logs/#{duplicate_log.id}/duplicate-logs?original_log_id=#{lettings_log.id}")
+ expect(page).to have_current_path("/lettings-logs/#{duplicate_log.id}/duplicate-logs?organisation_id=&original_log_id=#{lettings_log.id}&referrer=")
expect(page).not_to have_content("These logs are duplicates")
expect(page).not_to have_link("Keep this log and delete duplicates")
expect(page).to have_link("Back to lettings logs", href: "/lettings-logs")
@@ -510,8 +510,8 @@ RSpec.describe "Lettings Log Features" do
expect(page).to have_current_path("/lettings-logs/#{lettings_log.id}/duplicate-logs?original_log_id=#{lettings_log.id}")
click_link("Change", href: "/lettings-logs/#{duplicate_log.id}/tenant-code?first_remaining_duplicate_id=#{lettings_log.id}&original_log_id=#{lettings_log.id}&referrer=duplicate_logs")
fill_in("lettings-log-tenancycode-field", with: "something else")
- click_button("Save and continue")
- expect(page).to have_current_path("/lettings-logs/#{lettings_log.id}/duplicate-logs?original_log_id=#{lettings_log.id}")
+ click_button("Save changes")
+ expect(page).to have_current_path("/lettings-logs/#{lettings_log.id}/duplicate-logs?original_log_id=#{lettings_log.id}&referrer=duplicate_logs")
expect(page).to have_link("Back to Log #{lettings_log.id}", href: "/lettings-logs/#{lettings_log.id}")
expect(page).to have_css(".govuk-notification-banner.govuk-notification-banner--success")
expect(page).to have_content("Log #{duplicate_log.id} is no longer a duplicate and has been removed from the list")
@@ -521,8 +521,8 @@ RSpec.describe "Lettings Log Features" do
it "allows deduplicating logs by changing the answers on the original log" do
click_link("Change", href: "/lettings-logs/#{lettings_log.id}/tenant-code?first_remaining_duplicate_id=#{duplicate_log.id}&original_log_id=#{lettings_log.id}&referrer=duplicate_logs")
fill_in("lettings-log-tenancycode-field", with: "something else")
- click_button("Save and continue")
- expect(page).to have_current_path("/lettings-logs/#{duplicate_log.id}/duplicate-logs?original_log_id=#{lettings_log.id}")
+ click_button("Save changes")
+ expect(page).to have_current_path("/lettings-logs/#{duplicate_log.id}/duplicate-logs?original_log_id=#{lettings_log.id}&referrer=duplicate_logs")
expect(page).to have_link("Back to Log #{lettings_log.id}", href: "/lettings-logs/#{lettings_log.id}")
expect(page).to have_css(".govuk-notification-banner.govuk-notification-banner--success")
expect(page).to have_content("Log #{lettings_log.id} is no longer a duplicate and has been removed from the list")
diff --git a/spec/features/organisation_spec.rb b/spec/features/organisation_spec.rb
index 6b4efb80c..9c24f2470 100644
--- a/spec/features/organisation_spec.rb
+++ b/spec/features/organisation_spec.rb
@@ -126,7 +126,8 @@ RSpec.describe "User Features" do
context "when viewing lettings logs for specific organisation" do
let(:first_log) { organisation.lettings_logs.first }
let!(:log_to_search) { FactoryBot.create(:lettings_log, created_by: user) }
- let!(:other_logs) { FactoryBot.create_list(:lettings_log, 4, created_by: user) }
+ let!(:other_general_needs_logs) { FactoryBot.create_list(:lettings_log, 4, created_by: user, needstype: 1) }
+ let!(:other_supported_housing_logs) { FactoryBot.create_list(:lettings_log, 4, created_by: user, needstype: 2) }
let(:number_of_lettings_logs) { LettingsLog.count }
before do
@@ -148,7 +149,7 @@ RSpec.describe "User Features" do
context "when searching for specific logs" do
it "displays the logs belonging to the same organisation" do
expect(page).to have_content(log_to_search.id)
- other_logs.each do |log|
+ (other_general_needs_logs + other_supported_housing_logs).each do |log|
expect(page).to have_content(log.id)
end
end
@@ -168,7 +169,7 @@ RSpec.describe "User Features" do
it "displays log matching the log ID" do
expect(page).to have_link(log_to_search.id.to_s)
- other_logs.each do |log|
+ (other_general_needs_logs + other_supported_housing_logs).each do |log|
expect(page).not_to have_link(log.id.to_s)
end
end
@@ -187,16 +188,31 @@ RSpec.describe "User Features" do
end
end
- it "can filter lettings logs" do
- expect(page).to have_content("#{number_of_lettings_logs} total logs")
+ it "has correct page details" do
+ expect(page).to have_content("#{number_of_lettings_logs} matching logs")
organisation.lettings_logs.map(&:id).each do |lettings_log_id|
expect(page).to have_link lettings_log_id.to_s, href: "/lettings-logs/#{lettings_log_id}"
end
+ end
+
+ it "can filter lettings logs by year" do
check("years-2021-field")
click_button("Apply filters")
- expect(page).to have_current_path("/organisations/#{org_id}/lettings-logs?years[]=&years[]=2021&status[]=&assigned_to=all&user=&owning_organisation_select=all&owning_organisation=")
+ expect(page).to have_current_path("/organisations/#{org_id}/lettings-logs?years[]=&years[]=2021&status[]=&needstypes[]=&assigned_to=all&user=&owning_organisation_select=all&owning_organisation=&managing_organisation_select=all&managing_organisation=")
expect(page).not_to have_link first_log.id.to_s, href: "/lettings-logs/#{first_log.id}"
end
+
+ it "can filter lettings logs by needstype" do
+ check("needstypes-1-field")
+ click_button("Apply filters")
+ expect(page).to have_current_path("/organisations/#{org_id}/lettings-logs?years[]=&status[]=&needstypes[]=&needstypes[]=1&assigned_to=all&user=&owning_organisation_select=all&owning_organisation=&managing_organisation_select=all&managing_organisation=")
+ other_general_needs_logs.each do |general_needs_log|
+ expect(page).to have_link general_needs_log.id.to_s, href: "/lettings-logs/#{general_needs_log.id}"
+ end
+ other_supported_housing_logs.each do |supported_housing_log|
+ expect(page).not_to have_link supported_housing_log.id.to_s, href: "/lettings-logs/#{supported_housing_log.id}"
+ end
+ end
end
context "when viewing sales logs for specific organisation" do
@@ -221,7 +237,7 @@ RSpec.describe "User Features" do
end
it "can filter sales logs" do
- expect(page).to have_content("#{number_of_sales_logs} total logs")
+ expect(page).to have_content("#{number_of_sales_logs} matching logs")
organisation.sales_logs.map(&:id).each do |sales_log_id|
expect(page).to have_link sales_log_id.to_s, href: "/sales-logs/#{sales_log_id}"
end
diff --git a/spec/features/sales_log_spec.rb b/spec/features/sales_log_spec.rb
index f03287723..9e12082a7 100644
--- a/spec/features/sales_log_spec.rb
+++ b/spec/features/sales_log_spec.rb
@@ -108,7 +108,7 @@ RSpec.describe "Sales Log 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_content("Clear")
+ expect(page).not_to have_link("Clear", href: "/clear-filters?filter_type=sales_logs")
end
end
@@ -122,7 +122,7 @@ RSpec.describe "Sales Log Features" do
it "displays the filters component with a correct count and clear button" do
expect(page).to have_content("3 filters applied")
- expect(page).to have_content("Clear")
+ expect(page).to have_link("Clear", href: "/clear-filters?filter_type=sales_logs")
end
context "when clearing the filters" do
@@ -132,7 +132,7 @@ RSpec.describe "Sales Log Features" do
it "clears the filters and displays the filter component as before" do
expect(page).to have_content("No filters applied")
- expect(page).not_to have_content("Clear")
+ expect(page).not_to have_link("Clear", href: "/clear-filters?filter_type=sales_logs")
end
end
end
@@ -206,7 +206,7 @@ RSpec.describe "Sales Log Features" do
expect(duplicate_log.deleted?).to be true
expect(page).to have_css(".govuk-notification-banner.govuk-notification-banner--success")
expect(page).to have_content("Log #{duplicate_log.id} has been deleted.")
- expect(page).to have_current_path("/sales-logs/#{sales_log.id}/duplicate-logs?original_log_id=#{sales_log.id}")
+ expect(page).to have_current_path("/sales-logs/#{sales_log.id}/duplicate-logs?organisation_id=&original_log_id=#{sales_log.id}&referrer=")
expect(page).not_to have_content("These logs are duplicates")
expect(page).not_to have_link("Keep this log and delete duplicates")
expect(page).to have_link("Back to Log #{sales_log.id}", href: "/sales-logs/#{sales_log.id}")
@@ -230,7 +230,7 @@ RSpec.describe "Sales Log Features" do
expect(sales_log.status).to eq("deleted")
expect(page).to have_css(".govuk-notification-banner.govuk-notification-banner--success")
expect(page).to have_content("Log #{sales_log.id} has been deleted.")
- expect(page).to have_current_path("/sales-logs/#{duplicate_log.id}/duplicate-logs?original_log_id=#{sales_log.id}")
+ expect(page).to have_current_path("/sales-logs/#{duplicate_log.id}/duplicate-logs?organisation_id=&original_log_id=#{sales_log.id}&referrer=")
expect(page).not_to have_content("These logs are duplicates")
expect(page).not_to have_link("Keep this log and delete duplicates")
expect(page).to have_link("Back to sales logs", href: "/sales-logs")
@@ -249,8 +249,8 @@ RSpec.describe "Sales Log Features" do
expect(page).to have_current_path("/sales-logs/#{sales_log.id}/duplicate-logs?original_log_id=#{sales_log.id}")
click_link("Change", href: "/sales-logs/#{duplicate_log.id}/purchaser-code?first_remaining_duplicate_id=#{sales_log.id}&original_log_id=#{sales_log.id}&referrer=duplicate_logs")
fill_in("sales-log-purchid-field", with: "something else")
- click_button("Save and continue")
- expect(page).to have_current_path("/sales-logs/#{sales_log.id}/duplicate-logs?original_log_id=#{sales_log.id}")
+ click_button("Save changes")
+ expect(page).to have_current_path("/sales-logs/#{sales_log.id}/duplicate-logs?original_log_id=#{sales_log.id}&referrer=duplicate_logs")
expect(page).to have_link("Back to Log #{sales_log.id}", href: "/sales-logs/#{sales_log.id}")
expect(page).to have_css(".govuk-notification-banner.govuk-notification-banner--success")
expect(page).to have_content("Log #{duplicate_log.id} is no longer a duplicate and has been removed from the list")
@@ -260,8 +260,8 @@ RSpec.describe "Sales Log Features" do
it "allows deduplicating logs by changing the answers on the original log" do
click_link("Change", href: "/sales-logs/#{sales_log.id}/purchaser-code?first_remaining_duplicate_id=#{duplicate_log.id}&original_log_id=#{sales_log.id}&referrer=duplicate_logs")
fill_in("sales-log-purchid-field", with: "something else")
- click_button("Save and continue")
- expect(page).to have_current_path("/sales-logs/#{duplicate_log.id}/duplicate-logs?original_log_id=#{sales_log.id}")
+ click_button("Save changes")
+ expect(page).to have_current_path("/sales-logs/#{duplicate_log.id}/duplicate-logs?original_log_id=#{sales_log.id}&referrer=duplicate_logs")
expect(page).to have_link("Back to Log #{sales_log.id}", href: "/sales-logs/#{sales_log.id}")
expect(page).to have_css(".govuk-notification-banner.govuk-notification-banner--success")
expect(page).to have_content("Log #{sales_log.id} is no longer a duplicate and has been removed from the list")
diff --git a/spec/features/schemes_spec.rb b/spec/features/schemes_spec.rb
index b293171d6..d7a9609f8 100644
--- a/spec/features/schemes_spec.rb
+++ b/spec/features/schemes_spec.rb
@@ -68,7 +68,7 @@ RSpec.describe "Schemes scheme 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_content("Clear")
+ expect(page).not_to have_link("Clear", href: "/clear-filters?filter_type=schemes")
end
end
@@ -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_content("Clear")
+ expect(page).to have_link("Clear", href: "/clear-filters?filter_type=schemes")
end
context "when clearing the filters" do
@@ -91,7 +91,7 @@ RSpec.describe "Schemes scheme Features" do
it "clears the filters and displays the filter component as before" do
expect(page).to have_content("No filters applied")
- expect(page).not_to have_content("Clear")
+ expect(page).not_to have_link("Clear", href: "/clear-filters?filter_type=schemes")
end
end
end
@@ -292,7 +292,7 @@ RSpec.describe "Schemes scheme 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_content("Clear")
+ expect(page).not_to have_link("Clear", href: /\/clear-filters\?filter_type=scheme_locations/)
end
end
@@ -305,7 +305,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_content("Clear")
+ expect(page).to have_link("Clear", href: /\/clear-filters\?filter_type=scheme_locations/)
end
context "when clearing the filters" do
@@ -315,7 +315,7 @@ RSpec.describe "Schemes scheme Features" do
it "clears the filters and displays the filter component as before" do
expect(page).to have_content("No filters applied")
- expect(page).not_to have_content("Clear")
+ expect(page).not_to have_link("Clear", href: /\/clear-filters\?filter_type=scheme_locations/)
end
end
end
@@ -572,7 +572,7 @@ RSpec.describe "Schemes scheme Features" do
it "displays information about a single location" do
expect(page).to have_content "Locations"
- expect(page).to have_content "#{scheme.locations.count} total location"
+ expect(page).to have_content "#{scheme.locations.count} matching location"
end
it "displays information about the first created location" do
@@ -585,7 +585,7 @@ RSpec.describe "Schemes scheme Features" do
fill_in_and_save_second_location
click_button "Save and return to locations"
expect(page).to have_content "Locations"
- expect(page).to have_content "#{scheme.locations.count} total location"
+ expect(page).to have_content "#{scheme.locations.count} matching location"
end
it "displays information about newly created location" do
diff --git a/spec/features/user_spec.rb b/spec/features/user_spec.rb
index b3ee773d1..ca4e01ac6 100644
--- a/spec/features/user_spec.rb
+++ b/spec/features/user_spec.rb
@@ -139,6 +139,12 @@ RSpec.describe "User Features" do
visit("/users/#{user.id}")
expect(page).to have_content("Sign in to your account to submit CORE data")
end
+
+ it "does not show 'Sign in' link if maintenance mode is enabled" do
+ allow(FeatureToggle).to receive(:maintenance_mode_enabled?).and_return(true)
+ visit("/lettings-logs")
+ expect(page).not_to have_link("Sign in")
+ end
end
context "when the user is trying to log in with incorrect credentials" do
@@ -233,7 +239,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_content("Clear")
+ expect(page).not_to have_link("Clear", href: "/clear-filters?filter_type=users")
end
end
@@ -246,7 +252,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_content("Clear")
+ expect(page).to have_link("Clear", href: "/clear-filters?filter_type=users")
end
context "when clearing the filters" do
@@ -256,7 +262,7 @@ RSpec.describe "User Features" do
it "clears the filters and displays the filter component as before" do
expect(page).to have_content("No filters applied")
- expect(page).not_to have_content("Clear")
+ expect(page).not_to have_link("Clear", href: "/clear-filters?filter_type=users")
end
end
end
@@ -324,6 +330,13 @@ RSpec.describe "User Features" do
expect(page).to have_selector('[data-qa="change-data-protection-officer"]')
expect(page).to have_selector('[data-qa="change-key-contact"]')
end
+
+ it "does not show 'Your account' or 'Sign out' links if maintenance mode is enabled" do
+ allow(FeatureToggle).to receive(:maintenance_mode_enabled?).and_return(true)
+ visit("/lettings-logs")
+ expect(page).not_to have_link("Your account")
+ expect(page).not_to have_link("Sign out")
+ end
end
context "when adding a new user" do
@@ -756,10 +769,10 @@ RSpec.describe "User Features" do
expect(page).to have_field("owning-organisation-field", with: "")
find("#owning-organisation-field").click.native.send_keys("F", "i", "l", "t", :down, :enter)
click_button("Apply filters")
- expect(page).to have_current_path("/lettings-logs?%5Byears%5D%5B%5D=&%5Bstatus%5D%5B%5D=&assigned_to=all&owning_organisation_select=specific_org&owning_organisation=#{parent_organisation.id}&managing_organisation_select=all")
+ expect(page).to have_current_path("/lettings-logs?%5Byears%5D%5B%5D=&%5Bstatus%5D%5B%5D=&%5Bneedstypes%5D%5B%5D=&assigned_to=all&owning_organisation_select=specific_org&owning_organisation=#{parent_organisation.id}&managing_organisation_select=all")
choose("owning-organisation-select-all-field", allow_label_click: true)
click_button("Apply filters")
- expect(page).to have_current_path("/lettings-logs?%5Byears%5D%5B%5D=&%5Bstatus%5D%5B%5D=&assigned_to=all&owning_organisation_select=all&managing_organisation_select=all")
+ expect(page).to have_current_path("/lettings-logs?%5Byears%5D%5B%5D=&%5Bstatus%5D%5B%5D=&%5Bneedstypes%5D%5B%5D=&assigned_to=all&owning_organisation_select=all&managing_organisation_select=all")
end
end
end
diff --git a/spec/fixtures/exports/general_needs_log.xml b/spec/fixtures/exports/general_needs_log.xml
index 27a995304..fe7985668 100644
--- a/spec/fixtures/exports/general_needs_log.xml
+++ b/spec/fixtures/exports/general_needs_log.xml
@@ -129,7 +129,7 @@
-
+
2
4
diff --git a/spec/fixtures/exports/general_needs_log_23_24.xml b/spec/fixtures/exports/general_needs_log_23_24.xml
index aa3ca758a..ab4871a94 100644
--- a/spec/fixtures/exports/general_needs_log_23_24.xml
+++ b/spec/fixtures/exports/general_needs_log_23_24.xml
@@ -129,7 +129,7 @@
-
+
2
3
diff --git a/spec/fixtures/exports/supported_housing_logs.xml b/spec/fixtures/exports/supported_housing_logs.xml
index 0f7065b62..c05f2c76a 100644
--- a/spec/fixtures/exports/supported_housing_logs.xml
+++ b/spec/fixtures/exports/supported_housing_logs.xml
@@ -128,7 +128,7 @@
-
+
2
1
4
diff --git a/spec/fixtures/files/lettings_log_csv_export_codes.csv b/spec/fixtures/files/lettings_log_csv_export_codes.csv
index 1a6292a3b..54ac02412 100644
--- a/spec/fixtures/files/lettings_log_csv_export_codes.csv
+++ b/spec/fixtures/files/lettings_log_csv_export_codes.csv
@@ -1,2 +1,2 @@
id,status,created_by,is_dpo,created_at,updated_by,updated_at,creation_method,old_id,old_form_id,collection_start_year,owning_organisation_name,managing_organisation_name,needstype,lettype,renewal,startdate,renttype,rent_type_detail,irproduct,irproduct_other,lar,tenancycode,propcode,uprn_known,uprn,uprn_confirmed,address_line1,address_line2,town_or_city,county,postcode_full,is_la_inferred,la_label,la,first_time_property_let_as_social_housing,unitletas,rsnvac,newprop,offered,unittype_gn,builtype,wchair,beds,voiddate,vacdays,void_date_value_check,majorrepairs,mrcdate,major_repairs_date_value_check,joint,startertenancy,tenancy,tenancyother,tenancylength,sheltered,declaration,hhmemb,pregnancy_value_check,refused,hhtype,totchild,totelder,totadult,age1,retirement_value_check,sex1,ethnic_group,ethnic,national,ecstat1,details_known_2,relat2,age2,sex2,ecstat2,details_known_3,relat3,age3,sex3,ecstat3,details_known_4,relat4,age4,sex4,ecstat4,details_known_5,relat5,age5,sex5,ecstat5,details_known_6,relat6,age6,sex6,ecstat6,details_known_7,relat7,age7,sex7,ecstat7,details_known_8,relat8,age8,sex8,ecstat8,armedforces,leftreg,reservist,preg_occ,housingneeds,housingneeds_type,housingneeds_a,housingneeds_b,housingneeds_c,housingneeds_f,housingneeds_g,housingneeds_h,housingneeds_other,illness,illness_type_4,illness_type_5,illness_type_2,illness_type_6,illness_type_7,illness_type_3,illness_type_9,illness_type_8,illness_type_1,illness_type_10,layear,waityear,reason,reasonother,prevten,new_old,homeless,ppcodenk,ppostcode_full,previous_la_known,is_previous_la_inferred,prevloc_label,prevloc,reasonpref,rp_homeless,rp_insan_unsat,rp_medwel,rp_hardship,rp_dontknow,cbl,cap,chr,letting_allocation_unknown,referral,referral_value_check,net_income_known,incref,earnings,incfreq,net_income_value_check,hb,has_benefits,benefits,household_charge,nocharge,period,is_carehome,chcharge,wchchrg,carehome_charges_value_check,brent,wrent,rent_value_check,scharge,wscharge,pscharge,wpschrge,supcharg,wsupchrg,tcharge,wtcharge,scharge_value_check,pscharge_value_check,supcharg_value_check,hbrentshortfall,tshortfall_known,tshortfall,wtshortfall,scheme_code,scheme_service_name,scheme_sensitive,SCHTYPE,scheme_registered_under_care_act,scheme_owning_organisation_name,scheme_primary_client_group,scheme_has_other_client_group,scheme_secondary_client_group,scheme_support_type,scheme_intended_stay,scheme_created_at,location_code,location_postcode,location_name,location_units,location_type_of_unit,location_mobility_type,location_admin_district,location_startdate
-,completed,s.port@jeemayle.com,false,2023-06-26T00:00:00+01:00,,2023-06-26T00:00:00+01:00,1,,,2023,DLUHC,DLUHC,1,7,0,2023-06-26,2,1,,,,HIJKLMN,ABCDEFG,0,,,fake address,,London,,NW9 5LL,false,Barnet,E09000003,0,2,6,2,2,7,1,1,3,2023-06-24,,,1,2023-06-25,,3,1,4,,2,,1,4,,1,4,0,0,2,35,,F,0,2,13,0,0,P,32,M,6,1,R,-9,R,10,0,R,-9,R,10,,,,,,,,,,,,,,,,,,,,,1,4,1,2,1,0,1,0,0,0,0,0,0,1,0,0,1,0,0,0,0,0,0,0,2,7,4,,6,2,1,0,TN23 6LZ,1,false,Ashford,E07000105,1,0,1,0,0,0,0,0,1,,2,,0,0,68,1,,6,1,1,,0,2,,,,,200.0,100.0,,50.0,25.0,40.0,20.0,35.0,17.5,325.0,162.5,,,,1,0,12.0,6.0,,,,,,,,,,,,,,,,,,,,
+,completed,s.port@jeemayle.com,false,2023-06-26T00:00:00+01:00,,2023-06-26T00:00:00+01:00,1,,,2023,DLUHC,DLUHC,1,7,0,2023-06-26,2,1,,,2,HIJKLMN,ABCDEFG,0,,,fake address,,London,,NW9 5LL,false,Barnet,E09000003,0,2,6,2,2,7,1,1,3,2023-06-24,,,1,2023-06-25,,3,1,4,,2,,1,4,,1,4,0,0,2,35,,F,0,2,13,0,0,P,32,M,6,1,R,-9,R,10,0,R,-9,R,10,,,,,,,,,,,,,,,,,,,,,1,4,1,2,1,0,1,0,0,0,0,0,0,1,0,0,1,0,0,0,0,0,0,0,2,7,4,,6,2,1,0,TN23 6LZ,1,false,Ashford,E07000105,1,0,1,0,0,0,0,0,1,,2,,0,0,68,1,,6,1,1,,0,2,,,,,200.0,100.0,,50.0,25.0,40.0,20.0,35.0,17.5,325.0,162.5,,,,1,0,12.0,6.0,,,,,,,,,,,,,,,,,,,,
diff --git a/spec/fixtures/files/lettings_log_csv_export_labels.csv b/spec/fixtures/files/lettings_log_csv_export_labels.csv
index fd93b4015..8d9a2d240 100644
--- a/spec/fixtures/files/lettings_log_csv_export_labels.csv
+++ b/spec/fixtures/files/lettings_log_csv_export_labels.csv
@@ -1,2 +1,2 @@
id,status,created_by,is_dpo,created_at,updated_by,updated_at,creation_method,old_id,old_form_id,collection_start_year,owning_organisation_name,managing_organisation_name,needstype,lettype,renewal,startdate,renttype,rent_type_detail,irproduct,irproduct_other,lar,tenancycode,propcode,uprn_known,uprn,uprn_confirmed,address_line1,address_line2,town_or_city,county,postcode_full,is_la_inferred,la_label,la,first_time_property_let_as_social_housing,unitletas,rsnvac,newprop,offered,unittype_gn,builtype,wchair,beds,voiddate,vacdays,void_date_value_check,majorrepairs,mrcdate,major_repairs_date_value_check,joint,startertenancy,tenancy,tenancyother,tenancylength,sheltered,declaration,hhmemb,pregnancy_value_check,refused,hhtype,totchild,totelder,totadult,age1,retirement_value_check,sex1,ethnic_group,ethnic,national,ecstat1,details_known_2,relat2,age2,sex2,ecstat2,details_known_3,relat3,age3,sex3,ecstat3,details_known_4,relat4,age4,sex4,ecstat4,details_known_5,relat5,age5,sex5,ecstat5,details_known_6,relat6,age6,sex6,ecstat6,details_known_7,relat7,age7,sex7,ecstat7,details_known_8,relat8,age8,sex8,ecstat8,armedforces,leftreg,reservist,preg_occ,housingneeds,housingneeds_type,housingneeds_a,housingneeds_b,housingneeds_c,housingneeds_f,housingneeds_g,housingneeds_h,housingneeds_other,illness,illness_type_4,illness_type_5,illness_type_2,illness_type_6,illness_type_7,illness_type_3,illness_type_9,illness_type_8,illness_type_1,illness_type_10,layear,waityear,reason,reasonother,prevten,new_old,homeless,ppcodenk,ppostcode_full,previous_la_known,is_previous_la_inferred,prevloc_label,prevloc,reasonpref,rp_homeless,rp_insan_unsat,rp_medwel,rp_hardship,rp_dontknow,cbl,cap,chr,letting_allocation_unknown,referral,referral_value_check,net_income_known,incref,earnings,incfreq,net_income_value_check,hb,has_benefits,benefits,household_charge,nocharge,period,is_carehome,chcharge,wchchrg,carehome_charges_value_check,brent,wrent,rent_value_check,scharge,wscharge,pscharge,wpschrge,supcharg,wsupchrg,tcharge,wtcharge,scharge_value_check,pscharge_value_check,supcharg_value_check,hbrentshortfall,tshortfall_known,tshortfall,wtshortfall,scheme_code,scheme_service_name,scheme_sensitive,SCHTYPE,scheme_registered_under_care_act,scheme_owning_organisation_name,scheme_primary_client_group,scheme_has_other_client_group,scheme_secondary_client_group,scheme_support_type,scheme_intended_stay,scheme_created_at,location_code,location_postcode,location_name,location_units,location_type_of_unit,location_mobility_type,location_admin_district,location_startdate
-,completed,s.port@jeemayle.com,false,2023-06-26T00:00:00+01:00,,2023-06-26T00:00:00+01:00,single log,,,2023,DLUHC,DLUHC,General needs,7,No,2023-06-26,2,Affordable Rent,,,,HIJKLMN,ABCDEFG,No,,,fake address,,London,,NW9 5LL,No,Barnet,E09000003,No,Affordable rent basis,Tenant abandoned property,2,2,House,Purpose built,Yes,3,2023-06-24,,,Yes,2023-06-25,,Don’t know,Yes,Assured Shorthold Tenancy (AST) – Fixed term,,2,,1,4,,1,4,0,0,2,35,,Female,White,Irish,Tenant prefers not to say,Other,Yes,Partner,32,Male,Not seeking work,No,Prefers not to say,Not known,Prefers not to say,Prefers not to say,Yes,Person prefers not to say,Not known,Person prefers not to say,Person prefers not to say,,,,,,,,,,,,,,,,,,,,,Yes – the person is a current or former regular,No – they left up to and including 5 years ago,Yes,No,Yes,Fully wheelchair accessible housing,1,0,0,0,0,0,No,Yes,0,0,1,0,0,0,0,0,0,0,Less than 1 year,1 year but under 2 years,Loss of tied accommodation,,Other supported housing,2,No,Yes,TN23 6LZ,Yes,No,Ashford,E07000105,Yes,0,1,0,0,0,0,0,1,,Tenant applied directly (no referral or nomination),,Yes,0,68,Weekly,,Universal Credit housing element,1,All,,0,Every 2 weeks,,,,,200.0,100.0,,50.0,25.0,40.0,20.0,35.0,17.5,325.0,162.5,,,,Yes,Yes,12.0,6.0,,,,,,,,,,,,,,,,,,,,
+,completed,s.port@jeemayle.com,false,2023-06-26T00:00:00+01:00,,2023-06-26T00:00:00+01:00,single log,,,2023,DLUHC,DLUHC,General needs,7,No,2023-06-26,2,Affordable Rent,,,2,HIJKLMN,ABCDEFG,No,,,fake address,,London,,NW9 5LL,No,Barnet,E09000003,No,Affordable rent basis,Tenant abandoned property,2,2,House,Purpose built,Yes,3,2023-06-24,,,Yes,2023-06-25,,Don’t know,Yes,Assured Shorthold Tenancy (AST) – Fixed term,,2,,1,4,,1,4,0,0,2,35,,Female,White,Irish,Tenant prefers not to say,Other,Yes,Partner,32,Male,Not seeking work,No,Prefers not to say,Not known,Prefers not to say,Prefers not to say,Yes,Person prefers not to say,Not known,Person prefers not to say,Person prefers not to say,,,,,,,,,,,,,,,,,,,,,Yes – the person is a current or former regular,No – they left up to and including 5 years ago,Yes,No,Yes,Fully wheelchair accessible housing,1,0,0,0,0,0,No,Yes,0,0,1,0,0,0,0,0,0,0,Less than 1 year,1 year but under 2 years,Loss of tied accommodation,,Other supported housing,2,No,Yes,TN23 6LZ,Yes,No,Ashford,E07000105,Yes,0,1,0,0,0,0,0,1,,Tenant applied directly (no referral or nomination),,Yes,0,68,Weekly,,Universal Credit housing element,1,All,,0,Every 2 weeks,,,,,200.0,100.0,,50.0,25.0,40.0,20.0,35.0,17.5,325.0,162.5,,,,Yes,Yes,12.0,6.0,,,,,,,,,,,,,,,,,,,,
diff --git a/spec/fixtures/files/lettings_log_csv_export_non_support_codes.csv b/spec/fixtures/files/lettings_log_csv_export_non_support_codes.csv
index 20629ded7..5e47f5fe8 100644
--- a/spec/fixtures/files/lettings_log_csv_export_non_support_codes.csv
+++ b/spec/fixtures/files/lettings_log_csv_export_non_support_codes.csv
@@ -1,2 +1,2 @@
id,status,created_by,is_dpo,created_at,updated_by,updated_at,creation_method,collection_start_year,owning_organisation_name,managing_organisation_name,lettype,renewal,startdate,irproduct,irproduct_other,lar,tenancycode,propcode,uprn_known,uprn,address_line1,address_line2,town_or_city,county,postcode_full,la_label,unitletas,rsnvac,newprop,offered,unittype_gn,builtype,wchair,beds,voiddate,vacdays,void_date_value_check,majorrepairs,mrcdate,major_repairs_date_value_check,joint,startertenancy,tenancy,tenancyother,tenancylength,sheltered,declaration,refused,age1,sex1,ethnic_group,ethnic,national,ecstat1,relat2,age2,sex2,ecstat2,relat3,age3,sex3,ecstat3,relat4,age4,sex4,ecstat4,relat5,age5,sex5,ecstat5,relat6,age6,sex6,ecstat6,relat7,age7,sex7,ecstat7,relat8,age8,sex8,ecstat8,armedforces,leftreg,reservist,preg_occ,housingneeds,housingneeds_type,housingneeds_a,housingneeds_b,housingneeds_c,housingneeds_f,housingneeds_g,housingneeds_h,housingneeds_other,illness,illness_type_4,illness_type_5,illness_type_2,illness_type_6,illness_type_7,illness_type_3,illness_type_9,illness_type_8,illness_type_1,illness_type_10,layear,waityear,reason,reasonother,prevten,homeless,ppcodenk,ppostcode_full,prevloc_label,reasonpref,rp_homeless,rp_insan_unsat,rp_medwel,rp_hardship,rp_dontknow,cbl,cap,chr,referral,referral_value_check,incref,earnings,incfreq,hb,has_benefits,benefits,household_charge,nocharge,period,chcharge,wchchrg,carehome_charges_value_check,brent,scharge,pscharge,supcharg,tcharge,scharge_value_check,pscharge_value_check,supcharg_value_check,hbrentshortfall,tshortfall,scheme_code,scheme_service_name,scheme_sensitive,SCHTYPE,scheme_registered_under_care_act,scheme_owning_organisation_name,scheme_primary_client_group,scheme_has_other_client_group,scheme_secondary_client_group,scheme_support_type,scheme_intended_stay,scheme_created_at,location_code,location_postcode,location_name,location_units,location_type_of_unit,location_mobility_type,location_admin_district,location_startdate
-,completed,choreographer@owtluk.com,false,2023-06-26T00:00:00+01:00,,2023-06-26T00:00:00+01:00,1,2023,DLUHC,DLUHC,7,0,2023-06-26,,,,HIJKLMN,ABCDEFG,0,,fake address,,London,,NW9 5LL,Barnet,2,6,2,2,7,1,1,3,2023-06-24,1,,1,2023-06-25,,3,1,4,,2,,1,1,35,F,0,2,13,0,P,32,M,6,R,-9,R,10,R,-9,R,10,,,,,,,,,,,,,,,,,1,4,1,2,1,0,1,0,0,0,0,0,0,1,0,0,1,0,0,0,0,0,0,0,2,7,4,,6,1,0,TN23 6LZ,Ashford,1,0,1,0,0,0,0,0,1,2,,0,68,1,6,1,1,,0,2,,,,200.0,50.0,40.0,35.0,325.0,,,,1,12.0,,,,,,,,,,,,,,,,,,,,
+,completed,choreographer@owtluk.com,false,2023-06-26T00:00:00+01:00,,2023-06-26T00:00:00+01:00,1,2023,DLUHC,DLUHC,7,0,2023-06-26,,,2,HIJKLMN,ABCDEFG,0,,fake address,,London,,NW9 5LL,Barnet,2,6,2,2,7,1,1,3,2023-06-24,1,,1,2023-06-25,,3,1,4,,2,,1,1,35,F,0,2,13,0,P,32,M,6,R,-9,R,10,R,-9,R,10,,,,,,,,,,,,,,,,,1,4,1,2,1,0,1,0,0,0,0,0,0,1,0,0,1,0,0,0,0,0,0,0,2,7,4,,6,1,0,TN23 6LZ,Ashford,1,0,1,0,0,0,0,0,1,2,,0,68,1,6,1,1,,0,2,,,,200.0,50.0,40.0,35.0,325.0,,,,1,12.0,,,,,,,,,,,,,,,,,,,,
diff --git a/spec/fixtures/files/lettings_log_csv_export_non_support_labels.csv b/spec/fixtures/files/lettings_log_csv_export_non_support_labels.csv
index 5fd2c3cf1..57e395cd1 100644
--- a/spec/fixtures/files/lettings_log_csv_export_non_support_labels.csv
+++ b/spec/fixtures/files/lettings_log_csv_export_non_support_labels.csv
@@ -1,2 +1,2 @@
id,status,created_by,is_dpo,created_at,updated_by,updated_at,creation_method,collection_start_year,owning_organisation_name,managing_organisation_name,lettype,renewal,startdate,irproduct,irproduct_other,lar,tenancycode,propcode,uprn_known,uprn,address_line1,address_line2,town_or_city,county,postcode_full,la_label,unitletas,rsnvac,newprop,offered,unittype_gn,builtype,wchair,beds,voiddate,vacdays,void_date_value_check,majorrepairs,mrcdate,major_repairs_date_value_check,joint,startertenancy,tenancy,tenancyother,tenancylength,sheltered,declaration,refused,age1,sex1,ethnic_group,ethnic,national,ecstat1,relat2,age2,sex2,ecstat2,relat3,age3,sex3,ecstat3,relat4,age4,sex4,ecstat4,relat5,age5,sex5,ecstat5,relat6,age6,sex6,ecstat6,relat7,age7,sex7,ecstat7,relat8,age8,sex8,ecstat8,armedforces,leftreg,reservist,preg_occ,housingneeds,housingneeds_type,housingneeds_a,housingneeds_b,housingneeds_c,housingneeds_f,housingneeds_g,housingneeds_h,housingneeds_other,illness,illness_type_4,illness_type_5,illness_type_2,illness_type_6,illness_type_7,illness_type_3,illness_type_9,illness_type_8,illness_type_1,illness_type_10,layear,waityear,reason,reasonother,prevten,homeless,ppcodenk,ppostcode_full,prevloc_label,reasonpref,rp_homeless,rp_insan_unsat,rp_medwel,rp_hardship,rp_dontknow,cbl,cap,chr,referral,referral_value_check,incref,earnings,incfreq,hb,has_benefits,benefits,household_charge,nocharge,period,chcharge,wchchrg,carehome_charges_value_check,brent,scharge,pscharge,supcharg,tcharge,scharge_value_check,pscharge_value_check,supcharg_value_check,hbrentshortfall,tshortfall,scheme_code,scheme_service_name,scheme_sensitive,SCHTYPE,scheme_registered_under_care_act,scheme_owning_organisation_name,scheme_primary_client_group,scheme_has_other_client_group,scheme_secondary_client_group,scheme_support_type,scheme_intended_stay,scheme_created_at,location_code,location_postcode,location_name,location_units,location_type_of_unit,location_mobility_type,location_admin_district,location_startdate
-,completed,choreographer@owtluk.com,false,2023-06-26T00:00:00+01:00,,2023-06-26T00:00:00+01:00,single log,2023,DLUHC,DLUHC,7,No,2023-06-26,,,,HIJKLMN,ABCDEFG,No,,fake address,,London,,NW9 5LL,Barnet,Affordable rent basis,Tenant abandoned property,2,2,House,Purpose built,Yes,3,2023-06-24,1,,Yes,2023-06-25,,Don’t know,Yes,Assured Shorthold Tenancy (AST) – Fixed term,,2,,1,1,35,Female,White,Irish,Tenant prefers not to say,Other,Partner,32,Male,Not seeking work,Prefers not to say,Not known,Prefers not to say,Prefers not to say,Person prefers not to say,Not known,Person prefers not to say,Person prefers not to say,,,,,,,,,,,,,,,,,Yes – the person is a current or former regular,No – they left up to and including 5 years ago,Yes,No,Yes,Fully wheelchair accessible housing,1,0,0,0,0,0,No,Yes,0,0,1,0,0,0,0,0,0,0,Less than 1 year,1 year but under 2 years,Loss of tied accommodation,,Other supported housing,No,Yes,TN23 6LZ,Ashford,Yes,0,1,0,0,0,0,0,1,Tenant applied directly (no referral or nomination),,0,68,Weekly,Universal Credit housing element,1,All,,0,Every 2 weeks,,,,200.0,50.0,40.0,35.0,325.0,,,,Yes,12.0,,,,,,,,,,,,,,,,,,,,
+,completed,choreographer@owtluk.com,false,2023-06-26T00:00:00+01:00,,2023-06-26T00:00:00+01:00,single log,2023,DLUHC,DLUHC,7,No,2023-06-26,,,2,HIJKLMN,ABCDEFG,No,,fake address,,London,,NW9 5LL,Barnet,Affordable rent basis,Tenant abandoned property,2,2,House,Purpose built,Yes,3,2023-06-24,1,,Yes,2023-06-25,,Don’t know,Yes,Assured Shorthold Tenancy (AST) – Fixed term,,2,,1,1,35,Female,White,Irish,Tenant prefers not to say,Other,Partner,32,Male,Not seeking work,Prefers not to say,Not known,Prefers not to say,Prefers not to say,Person prefers not to say,Not known,Person prefers not to say,Person prefers not to say,,,,,,,,,,,,,,,,,Yes – the person is a current or former regular,No – they left up to and including 5 years ago,Yes,No,Yes,Fully wheelchair accessible housing,1,0,0,0,0,0,No,Yes,0,0,1,0,0,0,0,0,0,0,Less than 1 year,1 year but under 2 years,Loss of tied accommodation,,Other supported housing,No,Yes,TN23 6LZ,Ashford,Yes,0,1,0,0,0,0,0,1,Tenant applied directly (no referral or nomination),,0,68,Weekly,Universal Credit housing element,1,All,,0,Every 2 weeks,,,,200.0,50.0,40.0,35.0,325.0,,,,Yes,12.0,,,,,,,,,,,,,,,,,,,,
diff --git a/spec/lib/tasks/correct_address_from_csv_spec.rb b/spec/lib/tasks/correct_address_from_csv_spec.rb
index 294ce535b..fca5b79fb 100644
--- a/spec/lib/tasks/correct_address_from_csv_spec.rb
+++ b/spec/lib/tasks/correct_address_from_csv_spec.rb
@@ -91,11 +91,11 @@ RSpec.describe "data_import" do
before do
allow(storage_service).to receive(:get_file_io)
.with("addresses_reimport_123.csv")
- .and_return(replace_entity_ids(lettings_log, lettings_logs[0], lettings_logs[1], lettings_logs[2], File.open("./spec/fixtures/files/addresses_reimport.csv").read))
+ .and_return(StringIO.new(replace_entity_ids(lettings_log, lettings_logs[0], lettings_logs[1], lettings_logs[2], File.open("./spec/fixtures/files/addresses_reimport.csv").read)))
allow(storage_service).to receive(:get_file_io)
.with("all_addresses_reimport_123.csv")
- .and_return(replace_entity_ids(lettings_log, lettings_logs[0], lettings_logs[1], lettings_logs[2], File.open("./spec/fixtures/files/addresses_reimport_all_logs.csv").read))
+ .and_return(StringIO.new(replace_entity_ids(lettings_log, lettings_logs[0], lettings_logs[1], lettings_logs[2], File.open("./spec/fixtures/files/addresses_reimport_all_logs.csv").read)))
end
context "when the file contains issue type column" do
@@ -184,6 +184,14 @@ RSpec.describe "data_import" do
it "raises an error when no path is given" do
expect { task.invoke(nil) }.to raise_error(RuntimeError, "Usage: rake data_import:import_lettings_addresses_from_csv['csv_file_name']")
end
+
+ it "logs an error if a validation fails" do
+ lettings_log.ppcodenk = 0
+ lettings_log.ppostcode_full = "invalid_format"
+ lettings_log.save!(validate: false)
+ expect(Rails.logger).to receive(:error).with(/Validation failed for lettings log with ID #{lettings_log.id}: Ppostcode full/)
+ task.invoke(addresses_csv_path)
+ end
end
context "when the file does not contain issue type column" do
@@ -272,6 +280,14 @@ RSpec.describe "data_import" do
it "raises an error when no path is given" do
expect { task.invoke(nil) }.to raise_error(RuntimeError, "Usage: rake data_import:import_lettings_addresses_from_csv['csv_file_name']")
end
+
+ it "logs an error if a validation fails" do
+ lettings_log.ppcodenk = 0
+ lettings_log.ppostcode_full = "invalid_format"
+ lettings_log.save!(validate: false)
+ expect(Rails.logger).to receive(:error).with(/Validation failed for lettings log with ID #{lettings_log.id}: Ppostcode full/)
+ task.invoke(addresses_csv_path)
+ end
end
end
end
@@ -312,11 +328,11 @@ RSpec.describe "data_import" do
before do
allow(storage_service).to receive(:get_file_io)
.with("addresses_reimport_123.csv")
- .and_return(replace_entity_ids(sales_log, sales_logs[0], sales_logs[1], sales_logs[2], File.open("./spec/fixtures/files/sales_addresses_reimport.csv").read))
+ .and_return(StringIO.new(replace_entity_ids(sales_log, sales_logs[0], sales_logs[1], sales_logs[2], File.open("./spec/fixtures/files/sales_addresses_reimport.csv").read)))
allow(storage_service).to receive(:get_file_io)
.with("all_addresses_reimport_123.csv")
- .and_return(replace_entity_ids(sales_log, sales_logs[0], sales_logs[1], sales_logs[2], File.open("./spec/fixtures/files/sales_addresses_reimport_all_logs.csv").read))
+ .and_return(StringIO.new(replace_entity_ids(sales_log, sales_logs[0], sales_logs[1], sales_logs[2], File.open("./spec/fixtures/files/sales_addresses_reimport_all_logs.csv").read)))
end
context "when the file contains issue type column" do
@@ -405,6 +421,14 @@ RSpec.describe "data_import" do
it "raises an error when no path is given" do
expect { task.invoke(nil) }.to raise_error(RuntimeError, "Usage: rake data_import:import_sales_addresses_from_csv['csv_file_name']")
end
+
+ it "logs an error if a validation fails" do
+ sales_log.ppcodenk = 0
+ sales_log.ppostcode_full = "invalid_format"
+ sales_log.save!(validate: false)
+ expect(Rails.logger).to receive(:error).with(/Validation failed for sales log with ID #{sales_log.id}: Ppostcode full/)
+ task.invoke(addresses_csv_path)
+ end
end
context "when the file does not contain issue type column" do
@@ -493,6 +517,14 @@ RSpec.describe "data_import" do
it "raises an error when no path is given" do
expect { task.invoke(nil) }.to raise_error(RuntimeError, "Usage: rake data_import:import_sales_addresses_from_csv['csv_file_name']")
end
+
+ it "logs an error if a validation fails" do
+ sales_log.ppcodenk = 0
+ sales_log.ppostcode_full = "invalid_format"
+ sales_log.save!(validate: false)
+ expect(Rails.logger).to receive(:error).with(/Validation failed for sales log with ID #{sales_log.id}: Ppostcode full/)
+ task.invoke(addresses_csv_path)
+ end
end
end
end
diff --git a/spec/lib/tasks/correct_illness_from_csv_spec.rb b/spec/lib/tasks/correct_illness_from_csv_spec.rb
index ef7e82a65..e7b9f3c72 100644
--- a/spec/lib/tasks/correct_illness_from_csv_spec.rb
+++ b/spec/lib/tasks/correct_illness_from_csv_spec.rb
@@ -96,7 +96,7 @@ RSpec.describe "correct_illness" do
before do
allow(storage_service).to receive(:get_file_io)
.with("illness_123.csv")
- .and_return(replace_entity_ids(lettings_log, second_lettings_log, third_lettings_log, File.open("./spec/fixtures/files/illness_update.csv").read))
+ .and_return(StringIO.new(replace_entity_ids(lettings_log, second_lettings_log, third_lettings_log, File.open("./spec/fixtures/files/illness_update.csv").read)))
end
it "sets illness to yes and sets correct illness type" do
diff --git a/spec/lib/tasks/merge_organisations_spec.rb b/spec/lib/tasks/merge_organisations_spec.rb
index 4155a4389..d78b3d32e 100644
--- a/spec/lib/tasks/merge_organisations_spec.rb
+++ b/spec/lib/tasks/merge_organisations_spec.rb
@@ -20,22 +20,79 @@ RSpec.describe "emails" do
context "when the rake task is run" do
it "raises an error when no parameters are given" do
- expect { task.invoke(nil) }.to raise_error(RuntimeError, "Usage: rake merge:merge_organisations[absorbing_organisation_id, merging_organisation_ids]")
+ expect { task.invoke(nil) }.to raise_error(RuntimeError, "Usage: rake merge:merge_organisations[absorbing_organisation_id, merging_organisation_ids, merge_date]")
end
it "raises an error when only absorbing organisation is given" do
- expect { task.invoke(1, nil) }.to raise_error(RuntimeError, "Usage: rake merge:merge_organisations[absorbing_organisation_id, merging_organisation_ids]")
+ expect { task.invoke(1, nil) }.to raise_error(RuntimeError, "Usage: rake merge:merge_organisations[absorbing_organisation_id, merging_organisation_ids, merge_date]")
end
it "raises an error when only merging organisations are given" do
- expect { task.invoke(nil, "1 2") }.to raise_error(RuntimeError, "Usage: rake merge:merge_organisations[absorbing_organisation_id, merging_organisation_ids]")
+ expect { task.invoke(nil, "1 2") }.to raise_error(RuntimeError, "Usage: rake merge:merge_organisations[absorbing_organisation_id, merging_organisation_ids, merge_date]")
end
- it "raises runs the service with correct organisation IDs" do
- expect(Merge::MergeOrganisationsService).to receive(:new).with(absorbing_organisation_id: 1, merging_organisation_ids: [2, 3]).once
+ it "raises an error when the merge date given is not valid" do
+ expect { task.invoke("3", "1 2", "invalid_date") }.to raise_error(RuntimeError, "Usage: rake merge:merge_organisations[absorbing_organisation_id, merging_organisation_ids, merge_date]. Merge date must be in format YYYY-MM-DD")
+ end
+
+ it "runs the service with correct organisation IDs" do
+ expect(Merge::MergeOrganisationsService).to receive(:new).with(absorbing_organisation_id: 1, merging_organisation_ids: [2, 3], merge_date: nil).once
+ expect(merge_organisations_service).to receive(:call).once
+ task.invoke(1, "2 3")
+ end
+
+ it "runs the service with correct date when date is given" do
+ expect(Merge::MergeOrganisationsService).to receive(:new).with(absorbing_organisation_id: 1, merging_organisation_ids: [2, 3], merge_date: Time.zone.local(2021, 1, 13)).once
+ expect(merge_organisations_service).to receive(:call).once
+ task.invoke(1, "2 3", "2021-01-13")
+ end
+ end
+ end
+
+ describe ":merge_organisations_into_new_organisation", type: :task do
+ subject(:task) { Rake::Task["merge:merge_organisations_into_new_organisation"] }
+
+ let(:organisation) { create(:organisation) }
+ let(:merging_organisation) { create(:organisation) }
+
+ let(:merge_organisations_service) { Merge::MergeOrganisationsService.new(absorbing_organisation_id: organisation.id, merging_organisation_ids: [merging_organisation.id]) }
+
+ before do
+ allow(Merge::MergeOrganisationsService).to receive(:new).and_return(merge_organisations_service)
+ allow(merge_organisations_service).to receive(:call).and_return(nil)
+ Rake.application.rake_require("tasks/merge_organisations")
+ Rake::Task.define_task(:environment)
+ task.reenable
+ end
+
+ context "when the rake task is run" do
+ it "raises an error when no parameters are given" do
+ expect { task.invoke(nil) }.to raise_error(RuntimeError, "Usage: rake merge:merge_organisations_into_new_organisation[absorbing_organisation_id, merging_organisation_ids, merge_date]")
+ end
+
+ it "raises an error when only absorbing organisation is given" do
+ expect { task.invoke(1, nil) }.to raise_error(RuntimeError, "Usage: rake merge:merge_organisations_into_new_organisation[absorbing_organisation_id, merging_organisation_ids, merge_date]")
+ end
+
+ it "raises an error when only merging organisations are given" do
+ expect { task.invoke(nil, "1 2") }.to raise_error(RuntimeError, "Usage: rake merge:merge_organisations_into_new_organisation[absorbing_organisation_id, merging_organisation_ids, merge_date]")
+ end
+
+ it "raises an error when the merge date given is not valid" do
+ expect { task.invoke("3", "1 2", "invalid_date") }.to raise_error(RuntimeError, "Usage: rake merge:merge_organisations_into_new_organisation[absorbing_organisation_id, merging_organisation_ids, merge_date]. Merge date must be in format YYYY-MM-DD")
+ end
+
+ it "runs the service with correct organisation IDs" do
+ expect(Merge::MergeOrganisationsService).to receive(:new).with(absorbing_organisation_id: 1, merging_organisation_ids: [2, 3], merge_date: nil, absorbing_organisation_active_from_merge_date: true).once
expect(merge_organisations_service).to receive(:call).once
task.invoke(1, "2 3")
end
+
+ it "runs the service with correct date when date is given" do
+ expect(Merge::MergeOrganisationsService).to receive(:new).with(absorbing_organisation_id: 1, merging_organisation_ids: [2, 3], merge_date: Time.zone.local(2021, 1, 13), absorbing_organisation_active_from_merge_date: true).once
+ expect(merge_organisations_service).to receive(:call).once
+ task.invoke(1, "2 3", "2021-01-13")
+ end
end
end
end
diff --git a/spec/lib/tasks/recalculate_irproduct_values_spec.rb b/spec/lib/tasks/recalculate_irproduct_values_spec.rb
new file mode 100644
index 000000000..957496fa0
--- /dev/null
+++ b/spec/lib/tasks/recalculate_irproduct_values_spec.rb
@@ -0,0 +1,132 @@
+require "rails_helper"
+require "rake"
+
+RSpec.describe "recalculate_irproduct_values" do
+ describe ":recalculate_irproduct_values", type: :task do
+ subject(:task) { Rake::Task["recalculate_irproduct_values"] }
+
+ before do
+ Rake.application.rake_require("tasks/recalculate_irproduct_values")
+ Rake::Task.define_task(:environment)
+ task.reenable
+ end
+
+ context "when the rake task is run" do
+ let!(:lettings_log) { create(:lettings_log, :completed, values_updated_at: nil) }
+
+ it "updates irproduct to nil if it's set to 1 but rent type is not 3, 4 or 5" do
+ lettings_log.irproduct = 1
+ lettings_log.rent_type = 2
+ lettings_log.save!(validate: false)
+ task.invoke
+ lettings_log.reload
+ expect(lettings_log.irproduct).to eq(nil)
+ expect(lettings_log.values_updated_at).not_to be_nil
+ end
+
+ it "updates irproduct to nil if it's set to 2 but rent type is not 3, 4 or 5" do
+ lettings_log.irproduct = 2
+ lettings_log.rent_type = 2
+ lettings_log.save!(validate: false)
+ task.invoke
+ lettings_log.reload
+ expect(lettings_log.irproduct).to eq(nil)
+ expect(lettings_log.values_updated_at).not_to be_nil
+ end
+
+ it "updates irproduct to nil if it's set to 3 but rent type is not 3, 4 or 5" do
+ lettings_log.irproduct = 3
+ lettings_log.rent_type = 2
+ lettings_log.save!(validate: false)
+ task.invoke
+ lettings_log.reload
+ expect(lettings_log.irproduct).to eq(nil)
+ expect(lettings_log.values_updated_at).not_to be_nil
+ end
+
+ it "updates irproduct to 1 if it's set to nil but rent type is 3" do
+ lettings_log.irproduct = nil
+ lettings_log.rent_type = 3
+ lettings_log.save!(validate: false)
+ task.invoke
+ lettings_log.reload
+ expect(lettings_log.irproduct).to eq(1)
+ expect(lettings_log.values_updated_at).not_to be_nil
+ end
+
+ it "updates irproduct to 1 if it's set to something else but rent type is 3" do
+ lettings_log.irproduct = 2
+ lettings_log.rent_type = 3
+ lettings_log.save!(validate: false)
+ task.invoke
+ lettings_log.reload
+ expect(lettings_log.irproduct).to eq(1)
+ expect(lettings_log.values_updated_at).not_to be_nil
+ end
+
+ it "updates irproduct to 2 if it's set to nil but rent type is 4" do
+ lettings_log.irproduct = nil
+ lettings_log.rent_type = 4
+ lettings_log.save!(validate: false)
+ task.invoke
+ lettings_log.reload
+ expect(lettings_log.irproduct).to eq(2)
+ expect(lettings_log.values_updated_at).not_to be_nil
+ end
+
+ it "updates irproduct to 2 if it's set to something else but rent type is 4" do
+ lettings_log.irproduct = 1
+ lettings_log.rent_type = 4
+ lettings_log.save!(validate: false)
+ task.invoke
+ lettings_log.reload
+ expect(lettings_log.irproduct).to eq(2)
+ expect(lettings_log.values_updated_at).not_to be_nil
+ end
+
+ it "updates irproduct to 3 if it's set to nil but rent type is 5" do
+ lettings_log.irproduct = nil
+ lettings_log.rent_type = 5
+ lettings_log.irproduct_other = "other"
+ lettings_log.save!(validate: false)
+ task.invoke
+ lettings_log.reload
+ expect(lettings_log.irproduct).to eq(3)
+ expect(lettings_log.values_updated_at).not_to be_nil
+ end
+
+ it "updates irproduct to 3 if it's set to something else but rent type is 5" do
+ lettings_log.irproduct = 2
+ lettings_log.rent_type = 5
+ lettings_log.irproduct_other = "other"
+ lettings_log.save!(validate: false)
+ task.invoke
+ lettings_log.reload
+ expect(lettings_log.irproduct).to eq(3)
+ expect(lettings_log.values_updated_at).not_to be_nil
+ end
+
+ it "does not update irproduct if rent_type is not 3, 4 or 5 and irproduct is nil" do
+ lettings_log.irproduct = nil
+ lettings_log.rent_type = 2
+ lettings_log.save!(validate: false)
+ task.invoke
+ lettings_log.reload
+ expect(lettings_log.irproduct).to eq(nil)
+ expect(lettings_log.values_updated_at).to be_nil
+ end
+
+ it "does not update irproduct if a different validation is triggering" do
+ lettings_log.irproduct = 2
+ lettings_log.rent_type = 5
+ lettings_log.postcode_full = "invalid"
+ lettings_log.save!(validate: false)
+ expect(Rails.logger).to receive(:info).with("Could not update irproduct for LettingsLog #{lettings_log.id}")
+ task.invoke
+ lettings_log.reload
+ expect(lettings_log.irproduct).to eq(2)
+ expect(lettings_log.values_updated_at).to be_nil
+ end
+ end
+ end
+end
diff --git a/spec/lib/tasks/recalculate_lar_values_spec.rb b/spec/lib/tasks/recalculate_lar_values_spec.rb
new file mode 100644
index 000000000..7831e34d2
--- /dev/null
+++ b/spec/lib/tasks/recalculate_lar_values_spec.rb
@@ -0,0 +1,100 @@
+require "rails_helper"
+require "rake"
+
+RSpec.describe "recalculate_lar_values" do
+ describe ":recalculate_lar_values", type: :task do
+ subject(:task) { Rake::Task["recalculate_lar_values"] }
+
+ before do
+ Rake.application.rake_require("tasks/recalculate_lar_values")
+ Rake::Task.define_task(:environment)
+ task.reenable
+ end
+
+ context "when the rake task is run" do
+ let!(:lettings_log) { create(:lettings_log, :completed, values_updated_at: nil) }
+
+ it "updates lar to nil if it's not afordable rent or london afordable rent and lar is 1 but does not set it to export" do
+ lettings_log.lar = 1
+ lettings_log.rent_type = 3
+ lettings_log.save!(validate: false)
+ task.invoke
+ lettings_log.reload
+ expect(lettings_log.lar).to eq(nil)
+ expect(lettings_log.values_updated_at).to be_nil
+ end
+
+ it "updates lar to nil if it's not afordable rent or london afordable rent and lar is 2 but does not set it to export" do
+ lettings_log.lar = 2
+ lettings_log.rent_type = 4
+ lettings_log.save!(validate: false)
+ task.invoke
+ lettings_log.reload
+ expect(lettings_log.lar).to eq(nil)
+ expect(lettings_log.values_updated_at).to be_nil
+ end
+
+ it "does not update lar if it's not london afordable rent or affordable rent and lar is nil" do
+ lettings_log.lar = nil
+ lettings_log.rent_type = 3
+ lettings_log.save!(validate: false)
+ task.invoke
+ lettings_log.reload
+ expect(lettings_log.lar).to eq(nil)
+ expect(lettings_log.values_updated_at).to be_nil
+ end
+
+ it "updates lar to 1 if it's london afordable rent and lar is currently nil" do
+ lettings_log.lar = nil
+ lettings_log.rent_type = 2
+ lettings_log.save!(validate: false)
+ task.invoke
+ lettings_log.reload
+ expect(lettings_log.lar).to eq(1)
+ expect(lettings_log.values_updated_at).not_to be_nil
+ end
+
+ it "updates lar to 1 if it's london afordable rent and lar is currently 2" do
+ lettings_log.lar = 2
+ lettings_log.rent_type = 2
+ lettings_log.save!(validate: false)
+ task.invoke
+ lettings_log.reload
+ expect(lettings_log.lar).to eq(1)
+ expect(lettings_log.values_updated_at).not_to be_nil
+ end
+
+ it "updates lar to 2 if it's afordable rent and lar is currently nil" do
+ lettings_log.lar = nil
+ lettings_log.rent_type = 1
+ lettings_log.save!(validate: false)
+ task.invoke
+ lettings_log.reload
+ expect(lettings_log.lar).to eq(2)
+ expect(lettings_log.values_updated_at).not_to be_nil
+ end
+
+ it "updates lar to 2 if it's afordable rent and lar is currently 1" do
+ lettings_log.lar = 1
+ lettings_log.rent_type = 1
+ lettings_log.save!(validate: false)
+ task.invoke
+ lettings_log.reload
+ expect(lettings_log.lar).to eq(2)
+ expect(lettings_log.values_updated_at).not_to be_nil
+ end
+
+ it "does not update lar if a different validation is triggering" do
+ lettings_log.lar = 1
+ lettings_log.rent_type = 1
+ lettings_log.postcode_full = "invalid"
+ lettings_log.save!(validate: false)
+ expect(Rails.logger).to receive(:info).with("Could not update lar for LettingsLog #{lettings_log.id}")
+ task.invoke
+ lettings_log.reload
+ expect(lettings_log.lar).to eq(1)
+ expect(lettings_log.values_updated_at).to be_nil
+ end
+ end
+ end
+end
diff --git a/spec/lib/tasks/send_missing_addresses_csv_spec.rb b/spec/lib/tasks/send_missing_addresses_csv_spec.rb
index dab36f1ad..640faf374 100644
--- a/spec/lib/tasks/send_missing_addresses_csv_spec.rb
+++ b/spec/lib/tasks/send_missing_addresses_csv_spec.rb
@@ -2,6 +2,13 @@ require "rails_helper"
require "rake"
RSpec.describe "correct_addresses" do
+ around do |example|
+ Timecop.freeze(Time.zone.local(2023, 10, 10)) do
+ Singleton.__init__(FormHandler)
+ example.run
+ end
+ end
+
describe ":send_missing_addresses_lettings_csv", type: :task do
subject(:task) { Rake::Task["correct_addresses:send_missing_addresses_lettings_csv"] }
diff --git a/spec/lib/tasks/squish_names_spec.rb b/spec/lib/tasks/squish_names_spec.rb
new file mode 100644
index 000000000..5b1fcb028
--- /dev/null
+++ b/spec/lib/tasks/squish_names_spec.rb
@@ -0,0 +1,65 @@
+require "rails_helper"
+require "rake"
+
+RSpec.describe "squish_names" do
+ describe ":squish_names", type: :task do
+ subject(:task) { Rake::Task["squish_names"] }
+
+ before do
+ Rake.application.rake_require("tasks/squish_names")
+ Rake::Task.define_task(:environment)
+ task.reenable
+ end
+
+ context "when the rake task is run" do
+ let!(:scheme) { create(:scheme) }
+ let!(:location) { create(:location) }
+ let!(:user) { create(:user) }
+ let!(:organisation) { create(:organisation) }
+
+ it "updates names with multiple spaces to only have one" do
+ scheme.service_name = "test test"
+ location.name = "test test test"
+ user.name = "test test"
+ organisation.name = "test test test"
+
+ scheme.save!(validate: false)
+ location.save!(validate: false)
+ user.save!(validate: false)
+ organisation.save!(validate: false)
+
+ task.invoke
+ scheme.reload
+ location.reload
+ user.reload
+ organisation.reload
+ expect(scheme.service_name).to eq("test test")
+ expect(location.name).to eq("test test test")
+ expect(user.name).to eq("test test")
+ expect(organisation.name).to eq("test test test")
+ end
+
+ it "does not update names without multiple spaces" do
+ scheme.service_name = "test test"
+ location.name = "test test test"
+ user.name = "test test"
+ organisation.name = "test test test"
+
+ scheme.save!(validate: false)
+ location.save!(validate: false)
+ user.save!(validate: false)
+ organisation.save!(validate: false)
+
+ task.invoke
+ scheme.reload
+ location.reload
+ user.reload
+ organisation.reload
+ expect(scheme.service_name).to eq("test test")
+ expect(location.name).to eq("test test test")
+ expect(user.name).to eq("test test")
+ expect(organisation.name).to eq("test test test")
+ end
+ end
+ end
+end
diff --git a/spec/models/form/lettings/pages/address_spec.rb b/spec/models/form/lettings/pages/address_spec.rb
index 276b5c756..71f61d2e8 100644
--- a/spec/models/form/lettings/pages/address_spec.rb
+++ b/spec/models/form/lettings/pages/address_spec.rb
@@ -35,14 +35,14 @@ RSpec.describe Form::Lettings::Pages::Address, type: :model do
context "when uprn_known == nil" do
let(:log) { create(:lettings_log, uprn_known: nil) }
- it "returns false" do
- expect(page.routed_to?(log)).to eq(false)
+ it "returns true" do
+ expect(page.routed_to?(log)).to eq(true)
end
end
context "when uprn_confirmed != 1" do
let(:log) do
- create(:lettings_log, uprn_known: 1, uprn_confirmed: 0)
+ create(:lettings_log, uprn_known: 1, uprn: "12345", uprn_confirmed: 0)
end
it "returns true" do
@@ -62,10 +62,10 @@ RSpec.describe Form::Lettings::Pages::Address, type: :model do
context "when uprn_confirmed == 1 && uprn_known != 0" do
let(:log) do
- create(:lettings_log, uprn_known: 1, uprn_confirmed: 1, uprn: "123456789")
+ create(:lettings_log, uprn_known: 1, uprn: "12345", uprn_confirmed: 1)
end
- it "returns true" do
+ it "returns false" do
expect(page.routed_to?(log)).to eq(false)
end
end
diff --git a/spec/models/form/lettings/pages/location_spec.rb b/spec/models/form/lettings/pages/location_spec.rb
index 659a4dd26..65bca4636 100644
--- a/spec/models/form/lettings/pages/location_spec.rb
+++ b/spec/models/form/lettings/pages/location_spec.rb
@@ -26,7 +26,7 @@ RSpec.describe Form::Lettings::Pages::Location, type: :model do
end
it "has the correct header" do
- expect(page.header).to be_nil
+ expect(page.header).to eq("Location")
end
it "has the correct description" do
diff --git a/spec/models/form/lettings/pages/max_rent_value_check_spec.rb b/spec/models/form/lettings/pages/max_rent_value_check_spec.rb
index 4bbe3d18f..45caf16a3 100644
--- a/spec/models/form/lettings/pages/max_rent_value_check_spec.rb
+++ b/spec/models/form/lettings/pages/max_rent_value_check_spec.rb
@@ -32,6 +32,6 @@ RSpec.describe Form::Lettings::Pages::MaxRentValueCheck, type: :model do
end
it "has the correct interruption_screen_question_ids" do
- expect(page.interruption_screen_question_ids).to eq(%w[brent startdate uprn postcode_full la beds rent_type needstype])
+ expect(page.interruption_screen_question_ids).to eq(%w[brent period startdate uprn postcode_full la beds rent_type needstype])
end
end
diff --git a/spec/models/form/lettings/pages/min_rent_value_check_spec.rb b/spec/models/form/lettings/pages/min_rent_value_check_spec.rb
index 613c907e9..2f953c4cb 100644
--- a/spec/models/form/lettings/pages/min_rent_value_check_spec.rb
+++ b/spec/models/form/lettings/pages/min_rent_value_check_spec.rb
@@ -41,6 +41,6 @@ RSpec.describe Form::Lettings::Pages::MinRentValueCheck, type: :model do
end
it "has the correct interruption_screen_question_ids" do
- expect(page.interruption_screen_question_ids).to eq(%w[brent startdate uprn postcode_full la beds rent_type needstype])
+ expect(page.interruption_screen_question_ids).to eq(%w[brent period startdate uprn postcode_full la beds rent_type needstype])
end
end
diff --git a/spec/models/form/lettings/questions/location_id_spec.rb b/spec/models/form/lettings/questions/location_id_spec.rb
index f31e16806..0d3f8d1c8 100644
--- a/spec/models/form/lettings/questions/location_id_spec.rb
+++ b/spec/models/form/lettings/questions/location_id_spec.rb
@@ -151,4 +151,15 @@ RSpec.describe Form::Lettings::Questions::LocationId, type: :model do
expect(question.header).to eq("Which location is this letting for?")
end
end
+
+ describe "partial guidance" do
+ it "shows shows correct top_guidance_partial" do
+ expect(question.top_guidance_partial).to eq("finding_location")
+ end
+
+ it "is at the top" do
+ expect(question.top_guidance?).to eq(true)
+ expect(question.bottom_guidance?).to eq(false)
+ end
+ end
end
diff --git a/spec/models/form/lettings/questions/managing_organisation_spec.rb b/spec/models/form/lettings/questions/managing_organisation_spec.rb
index 64bb84181..dcd142151 100644
--- a/spec/models/form/lettings/questions/managing_organisation_spec.rb
+++ b/spec/models/form/lettings/questions/managing_organisation_spec.rb
@@ -163,7 +163,7 @@ RSpec.describe Form::Lettings::Questions::ManagingOrganisation, type: :model do
end
context "when organisation has merged" do
- let(:absorbing_org) { create(:organisation, name: "Absorbing org", holds_own_stock: true, created_at: Time.zone.local(2023, 8, 3)) }
+ let(:absorbing_org) { create(:organisation, name: "Absorbing org", holds_own_stock: true) }
let!(:merged_org) { create(:organisation, name: "Merged org", holds_own_stock: false) }
let(:user) { create(:user, :data_coordinator, organisation: absorbing_org) }
@@ -173,6 +173,17 @@ RSpec.describe Form::Lettings::Questions::ManagingOrganisation, type: :model do
end
it "displays merged organisation on the list of choices" do
+ options = {
+ "" => "Select an option",
+ absorbing_org.id => "Absorbing org (Your organisation)",
+ merged_org.id => "Merged org (inactive as of 2 August 2023)",
+ merged_org.id => "Merged org (inactive as of 2 August 2023)",
+ }
+ expect(question.displayed_answer_options(log, user)).to eq(options)
+ end
+
+ it "displays active date for absorbing organisation if available from is given" do
+ absorbing_org.update!(available_from: Time.zone.local(2023, 8, 3))
options = {
"" => "Select an option",
absorbing_org.id => "Absorbing org (Your organisation, active as of 3 August 2023)",
@@ -189,7 +200,7 @@ RSpec.describe Form::Lettings::Questions::ManagingOrganisation, type: :model do
options = {
"" => "Select an option",
merged_org.id => "Merged org (inactive as of 2 August 2023)",
- absorbing_org.id => "Absorbing org (Your organisation, active as of 3 August 2023)",
+ absorbing_org.id => "Absorbing org (Your organisation)",
managing_agent.id => "Managing org 1",
}
diff --git a/spec/models/form/lettings/questions/stock_owner_spec.rb b/spec/models/form/lettings/questions/stock_owner_spec.rb
index ed05c5139..6957a293a 100644
--- a/spec/models/form/lettings/questions/stock_owner_spec.rb
+++ b/spec/models/form/lettings/questions/stock_owner_spec.rb
@@ -100,6 +100,93 @@ RSpec.describe Form::Lettings::Questions::StockOwner, type: :model do
expect(question.displayed_answer_options(log, user)).to eq(options)
end
end
+
+ context "when user's org has recently absorbed other orgs and has available_from date" do
+ let(:merged_organisation) { create(:organisation, name: "Merged org") }
+ let(:options) do
+ {
+ "" => "Select an option",
+ user.organisation.id => "User org (Your organisation, active as of 2 February 2021)",
+ owning_org_2.id => "Owning org 2",
+ owning_org_1.id => "Owning org 1",
+ merged_organisation.id => "Merged org (inactive as of 2 February 2023)",
+ }
+ end
+
+ before do
+ merged_organisation.update!(merge_date: Time.zone.local(2023, 2, 2), absorbing_organisation: user.organisation)
+ user.organisation.update!(available_from: Time.zone.local(2021, 2, 2))
+ end
+
+ it "shows merged organisation as an option" do
+ expect(question.displayed_answer_options(log, user)).to eq(options)
+ end
+ end
+
+ context "when user's org has recently absorbed other orgs and does not have available from date" do
+ let(:merged_organisation) { create(:organisation, name: "Merged org") }
+ let(:options) do
+ {
+ "" => "Select an option",
+ user.organisation.id => "User org (Your organisation)",
+ owning_org_2.id => "Owning org 2",
+ owning_org_1.id => "Owning org 1",
+ merged_organisation.id => "Merged org (inactive as of 2 February 2023)",
+ }
+ end
+
+ before do
+ merged_organisation.update!(merge_date: Time.zone.local(2023, 2, 2), absorbing_organisation: user.organisation)
+ end
+
+ it "shows merged organisation as an option" do
+ expect(question.displayed_answer_options(log, user)).to eq(options)
+ end
+ end
+
+ context "when user's org has recently absorbed other orgs with parent organisations" do
+ let(:merged_organisation) { create(:organisation, name: "Merged org") }
+ let(:options) do
+ {
+ "" => "Select an option",
+ user.organisation.id => "User org (Your organisation, active as of 2 February 2021)",
+ owning_org_1.id => "Owning org 1",
+ merged_organisation.id => "Merged org (inactive as of 2 February 2023)",
+ }
+ end
+
+ before do
+ org_rel.update!(child_organisation: merged_organisation)
+ merged_organisation.update!(merge_date: Time.zone.local(2023, 2, 2), absorbing_organisation: user.organisation)
+ user.organisation.update!(available_from: Time.zone.local(2021, 2, 2))
+ end
+
+ it "does not show merged organisations stock owners as options" do
+ expect(question.displayed_answer_options(log, user)).to eq(options)
+ end
+ end
+
+ context "when user's org has absorbed other orgs with parent organisations during closed collection periods" do
+ let(:merged_organisation) { create(:organisation, name: "Merged org") }
+ let(:options) do
+ {
+ "" => "Select an option",
+ user.organisation.id => "User org (Your organisation)",
+ owning_org_1.id => "Owning org 1",
+ }
+ end
+
+ before do
+ Timecop.freeze(Time.zone.local(2023, 4, 2))
+ org_rel.update!(child_organisation: merged_organisation)
+ merged_organisation.update!(merge_date: Time.zone.local(2021, 6, 2), absorbing_organisation: user.organisation)
+ user.organisation.update!(available_from: Time.zone.local(2021, 2, 2))
+ end
+
+ it "shows merged organisation as an option" do
+ expect(question.displayed_answer_options(log, user)).to eq(options)
+ end
+ end
end
context "when user is support" do
diff --git a/spec/models/form/sales/pages/address_spec.rb b/spec/models/form/sales/pages/address_spec.rb
index 165952cfb..9bdd5f432 100644
--- a/spec/models/form/sales/pages/address_spec.rb
+++ b/spec/models/form/sales/pages/address_spec.rb
@@ -35,8 +35,8 @@ RSpec.describe Form::Sales::Pages::Address, type: :model do
context "when uprn_known == nil" do
let(:log) { create(:sales_log, uprn_known: nil) }
- it "returns false" do
- expect(page.routed_to?(log)).to eq(false)
+ it "returns true" do
+ expect(page.routed_to?(log)).to eq(true)
end
end
@@ -66,7 +66,7 @@ RSpec.describe Form::Sales::Pages::Address, type: :model do
create(:sales_log, uprn_known: 1, uprn: "12345", uprn_confirmed: 1)
end
- it "returns true" do
+ it "returns false" do
expect(page.routed_to?(log)).to eq(false)
end
end
diff --git a/spec/models/form/sales/questions/owning_organisation_id_spec.rb b/spec/models/form/sales/questions/owning_organisation_id_spec.rb
index 9cfefbf8b..c82508324 100644
--- a/spec/models/form/sales/questions/owning_organisation_id_spec.rb
+++ b/spec/models/form/sales/questions/owning_organisation_id_spec.rb
@@ -98,7 +98,7 @@ RSpec.describe Form::Sales::Questions::OwningOrganisationId, type: :model do
let(:options) do
{
"" => "Select an option",
- user.organisation.id => "User org (Your organisation, active as of 2 February 2021)",
+ user.organisation.id => "User org (Your organisation)",
owning_org_1.id => "Owning org 1",
merged_organisation.id => "Merged org (inactive as of 2 February 2023)",
}
@@ -106,7 +106,6 @@ RSpec.describe Form::Sales::Questions::OwningOrganisationId, type: :model do
before do
merged_organisation.update!(merge_date: Time.zone.local(2023, 2, 2), absorbing_organisation: user.organisation)
- user.organisation.update!(created_at: Time.zone.local(2021, 2, 2))
end
it "shows merged organisation as an option" do
@@ -114,7 +113,7 @@ RSpec.describe Form::Sales::Questions::OwningOrganisationId, type: :model do
end
end
- context "when user's org has recently absorbed other orgs with parent organisations" do
+ context "when user's org has recently absorbed other orgs and it has available from date" do
let(:merged_organisation) { create(:organisation, name: "Merged org") }
let(:options) do
{
@@ -125,10 +124,30 @@ RSpec.describe Form::Sales::Questions::OwningOrganisationId, type: :model do
}
end
+ before do
+ merged_organisation.update!(merge_date: Time.zone.local(2023, 2, 2), absorbing_organisation: user.organisation)
+ user.organisation.update!(available_from: Time.zone.local(2021, 2, 2))
+ end
+
+ it "shows available from date if it is given" do
+ expect(question.displayed_answer_options(log, user)).to eq(options)
+ end
+ end
+
+ context "when user's org has recently absorbed other orgs with parent organisations" do
+ let(:merged_organisation) { create(:organisation, name: "Merged org") }
+ let(:options) do
+ {
+ "" => "Select an option",
+ user.organisation.id => "User org (Your organisation)",
+ owning_org_1.id => "Owning org 1",
+ merged_organisation.id => "Merged org (inactive as of 2 February 2023)",
+ }
+ end
+
before do
org_rel.update!(child_organisation: merged_organisation)
merged_organisation.update!(merge_date: Time.zone.local(2023, 2, 2), absorbing_organisation: user.organisation)
- user.organisation.update!(created_at: Time.zone.local(2021, 2, 2))
end
it "does not show merged organisations stock owners as options" do
@@ -150,7 +169,7 @@ RSpec.describe Form::Sales::Questions::OwningOrganisationId, type: :model do
Timecop.freeze(Time.zone.local(2023, 4, 2))
org_rel.update!(child_organisation: merged_organisation)
merged_organisation.update!(merge_date: Time.zone.local(2021, 6, 2), absorbing_organisation: user.organisation)
- user.organisation.update!(created_at: Time.zone.local(2021, 2, 2))
+ user.organisation.update!(available_from: Time.zone.local(2021, 2, 2))
end
it "shows merged organisation as an option" do
diff --git a/spec/models/lettings_log_spec.rb b/spec/models/lettings_log_spec.rb
index 82cc254cb..6c4d9b1e0 100644
--- a/spec/models/lettings_log_spec.rb
+++ b/spec/models/lettings_log_spec.rb
@@ -2270,6 +2270,58 @@ RSpec.describe LettingsLog do
expect(lettings_log["housingneeds_g"]).to eq(1)
end
end
+
+ context "when saving rent_type" do
+ it "derives lar as yes (1) if rent_type is london affordable rent" do
+ lettings_log.update!({ rent_type: 2 })
+ record_from_db = described_class.find(lettings_log.id)
+ expect(record_from_db["lar"]).to eq(1)
+ end
+
+ it "derives lar as no (2) if rent_type is affordable rent" do
+ lettings_log.update!({ rent_type: 1 })
+ record_from_db = described_class.find(lettings_log.id)
+ expect(record_from_db["lar"]).to eq(2)
+ end
+
+ it "clears previously set lar if rent_type is not affordable rent" do
+ lettings_log.update!({ rent_type: 2 })
+ record_from_db = described_class.find(lettings_log.id)
+ expect(record_from_db["lar"]).to eq(1)
+
+ lettings_log.update!({ rent_type: 3 })
+ record_from_db = described_class.find(lettings_log.id)
+ expect(record_from_db["lar"]).to eq(nil)
+ end
+
+ it "derives irproduct as rent_to_buy (1) if rent_type is rent_to_buy (3)" do
+ lettings_log.update!({ rent_type: 3 })
+ record_from_db = described_class.find(lettings_log.id)
+ expect(record_from_db["irproduct"]).to eq(1)
+ end
+
+ it "derives irproduct as london_living_rent (2) if rent_type is london_living_rent (4)" do
+ lettings_log.update!({ rent_type: 4 })
+ record_from_db = described_class.find(lettings_log.id)
+ expect(record_from_db["irproduct"]).to eq(2)
+ end
+
+ it "derives irproduct as other_intermediate_rent_product (3) if rent_type is other_intermediate_rent_product (5)" do
+ lettings_log.update!({ rent_type: 5, irproduct_other: "other" })
+ record_from_db = described_class.find(lettings_log.id)
+ expect(record_from_db["irproduct"]).to eq(3)
+ end
+
+ it "clears previously set irproduct if rent_type is intermediate rent" do
+ lettings_log.update!({ rent_type: 4 })
+ record_from_db = described_class.find(lettings_log.id)
+ expect(record_from_db["irproduct"]).to eq(2)
+
+ lettings_log.update!({ rent_type: 2 })
+ record_from_db = described_class.find(lettings_log.id)
+ expect(record_from_db["irproduct"]).to eq(nil)
+ end
+ end
end
describe "optional fields" do
diff --git a/spec/models/location_spec.rb b/spec/models/location_spec.rb
index 4425e1a6c..1b9edb9bf 100644
--- a/spec/models/location_spec.rb
+++ b/spec/models/location_spec.rb
@@ -930,6 +930,29 @@ RSpec.describe Location, type: :model do
end
end
+ describe "status_at" do
+ let(:location) { FactoryBot.build(:location, startdate: Time.zone.local(2022, 4, 1)) }
+
+ before do
+ Timecop.freeze(2022, 6, 7)
+ end
+
+ after do
+ Timecop.unfreeze
+ end
+
+ context "when there have been previous deactivations" do
+ before do
+ FactoryBot.create(:location_deactivation_period, deactivation_date: Time.zone.local(2022, 5, 4), reactivation_date: Time.zone.local(2022, 6, 5), location:)
+ location.save!
+ end
+
+ it "returns active if the location has no relevant deactivation records" do
+ expect(location.status_at(Time.zone.local(2022, 4, 4))).to eq(:active)
+ end
+ end
+ end
+
describe "filter by status" do
let!(:incomplete_location) { FactoryBot.create(:location, :incomplete, startdate: Time.zone.local(2022, 4, 1)) }
let!(:incomplete_location_with_nil_confirmed) { FactoryBot.create(:location, :incomplete, startdate: Time.zone.local(2022, 4, 1), confirmed: nil) }
diff --git a/spec/models/scheme_spec.rb b/spec/models/scheme_spec.rb
index b63866675..70eccc5c2 100644
--- a/spec/models/scheme_spec.rb
+++ b/spec/models/scheme_spec.rb
@@ -290,6 +290,29 @@ RSpec.describe Scheme, type: :model do
end
end
+ describe "status_at" do
+ let(:scheme) { FactoryBot.build(:scheme) }
+
+ before do
+ FactoryBot.create(:location, scheme:)
+ Timecop.freeze(2022, 6, 7)
+ end
+
+ after do
+ Timecop.unfreeze
+ end
+
+ context "when there have been previous deactivations" do
+ before do
+ FactoryBot.create(:scheme_deactivation_period, deactivation_date: Time.zone.local(2022, 6, 4), reactivation_date: Time.zone.local(2022, 6, 5), scheme:)
+ end
+
+ it "returns active if the scheme has no relevant deactivation records" do
+ expect(scheme.status_at(Time.zone.local(2022, 5, 5))).to eq(:active)
+ end
+ end
+ end
+
describe "available_from" do
context "when the scheme was created at the start of the 2022/23 collection window" do
let(:scheme) { FactoryBot.build(:scheme, created_at: Time.zone.local(2022, 4, 6)) }
diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb
index 63ea72dca..c272320b2 100644
--- a/spec/models/user_spec.rb
+++ b/spec/models/user_spec.rb
@@ -163,7 +163,7 @@ RSpec.describe User, type: :model do
end
it "can filter lettings logs by user, year and status" do
- expect(user.logs_filters).to eq(%w[status years assigned_to user bulk_upload_id])
+ expect(user.logs_filters).to match_array(%w[years status needstypes assigned_to user bulk_upload_id])
end
end
@@ -173,7 +173,7 @@ RSpec.describe User, type: :model do
end
it "can filter lettings logs by user, year, status, managing_organisation and owning_organisation" do
- expect(user.logs_filters).to match_array(%w[status years assigned_to user managing_organisation owning_organisation bulk_upload_id])
+ expect(user.logs_filters).to match_array(%w[years status needstypes assigned_to user managing_organisation owning_organisation bulk_upload_id])
end
end
end
@@ -214,7 +214,7 @@ RSpec.describe User, type: :model do
end
it "can filter lettings logs by user, year, status, managing_organisation and owning_organisation" do
- expect(user.logs_filters).to match_array(%w[status years assigned_to user owning_organisation managing_organisation bulk_upload_id])
+ expect(user.logs_filters).to match_array(%w[years status needstypes assigned_to user owning_organisation managing_organisation bulk_upload_id])
end
end
diff --git a/spec/models/validations/financial_validations_spec.rb b/spec/models/validations/financial_validations_spec.rb
index 3e645f164..f419137a2 100644
--- a/spec/models/validations/financial_validations_spec.rb
+++ b/spec/models/validations/financial_validations_spec.rb
@@ -262,56 +262,74 @@ RSpec.describe Validations::FinancialValidations do
before { record.needstype = 1 }
[{
- period: { label: "weekly", value: 1 },
+ period: { label: "weekly for 52 weeks", value: 1 },
charge: { field: "scharge", value: 801 },
+ charge_name: "service charge",
+ maximum_per_period: "£800.00",
},
{
- period: { label: "monthly", value: 4 },
+ period: { label: "every calendar month", value: 4 },
charge: { field: "scharge", value: 3471 },
+ charge_name: "service charge",
+ maximum_per_period: "£3,466.00",
},
{
period: { label: "every 2 weeks", value: 2 },
charge: { field: "scharge", value: 1601 },
+ charge_name: "service charge",
+ maximum_per_period: "£1,600.00",
},
{
- period: { label: "weekly", value: 1 },
+ period: { label: "weekly for 52 weeks", value: 1 },
charge: { field: "pscharge", value: 701 },
+ charge_name: "personal service charge",
+ maximum_per_period: "£700.00",
},
{
- period: { label: "monthly", value: 4 },
+ period: { label: "every calendar month", value: 4 },
charge: { field: "pscharge", value: 3200 },
+ charge_name: "personal service charge",
+ maximum_per_period: "£3,033.00",
},
{
period: { label: "every 2 weeks", value: 2 },
charge: { field: "pscharge", value: 1401 },
+ charge_name: "personal service charge",
+ maximum_per_period: "£1,400.00",
},
{
- period: { label: "weekly", value: 1 },
+ period: { label: "weekly for 52 weeks", value: 1 },
charge: { field: "supcharg", value: 801 },
+ charge_name: "support charge",
+ maximum_per_period: "£800.00",
},
{
- period: { label: "monthly", value: 4 },
+ period: { label: "every calendar month", value: 4 },
charge: { field: "supcharg", value: 3471 },
+ charge_name: "support charge",
+ maximum_per_period: "£3,466.00",
},
{
period: { label: "every 2 weeks", value: 2 },
charge: { field: "supcharg", value: 1601 },
+ charge_name: "support charge",
+ maximum_per_period: "£1,600.00",
}].each do |test_case|
it "does not allow charges outside the range when period is #{test_case[:period][:label]}" do
record.period = test_case[:period][:value]
record[test_case[:charge][:field]] = test_case[:charge][:value]
financial_validator.validate_rent_amount(record)
expect(record.errors[test_case[:charge][:field]])
- .to include(match I18n.t("validations.financial.rent.#{test_case[:charge][:field]}.private_registered_provider.general_needs"))
+ .to include(match I18n.t("validations.financial.rent.out_of_range", charge_name: test_case[:charge_name], maximum_per_period: test_case[:maximum_per_period], frequency: test_case[:period][:label], letting_type: "general needs", provider_type: "private registered provider"))
end
end
[{
- period: { label: "weekly", value: 1 },
+ period: { label: "weekly for 52 weeks", value: 1 },
charge: { field: "scharge", value: 799 },
},
{
- period: { label: "monthly", value: 4 },
+ period: { label: "every calendar month", value: 4 },
charge: { field: "scharge", value: 3400 },
},
{
@@ -319,11 +337,11 @@ RSpec.describe Validations::FinancialValidations do
charge: { field: "scharge", value: 1599 },
},
{
- period: { label: "weekly", value: 1 },
+ period: { label: "weekly for 52 weeks", value: 1 },
charge: { field: "pscharge", value: 699 },
},
{
- period: { label: "monthly", value: 4 },
+ period: { label: "every calendar month", value: 4 },
charge: { field: "pscharge", value: 2500 },
},
{
@@ -331,11 +349,11 @@ RSpec.describe Validations::FinancialValidations do
charge: { field: "pscharge", value: 1399 },
},
{
- period: { label: "weekly", value: 1 },
+ period: { label: "weekly for 52 weeks", value: 1 },
charge: { field: "supcharg", value: 799 },
},
{
- period: { label: "monthly", value: 4 },
+ period: { label: "every calendar month", value: 4 },
charge: { field: "supcharg", value: 3000 },
},
{
@@ -356,56 +374,74 @@ RSpec.describe Validations::FinancialValidations do
before { record.needstype = 2 }
[{
- period: { label: "weekly", value: 1 },
+ period: { label: "weekly for 52 weeks", value: 1 },
charge: { field: "scharge", value: 801 },
+ charge_name: "service charge",
+ maximum_per_period: "£800.00",
},
{
- period: { label: "monthly", value: 4 },
+ period: { label: "every calendar month", value: 4 },
charge: { field: "scharge", value: 3471 },
+ charge_name: "service charge",
+ maximum_per_period: "£3,466.00",
},
{
period: { label: "every 2 weeks", value: 2 },
charge: { field: "scharge", value: 1601 },
+ charge_name: "service charge",
+ maximum_per_period: "£1,600.00",
},
{
- period: { label: "weekly", value: 1 },
+ period: { label: "weekly for 52 weeks", value: 1 },
charge: { field: "pscharge", value: 701 },
+ charge_name: "personal service charge",
+ maximum_per_period: "£700.00",
},
{
- period: { label: "monthly", value: 4 },
+ period: { label: "every calendar month", value: 4 },
charge: { field: "pscharge", value: 3200 },
+ charge_name: "personal service charge",
+ maximum_per_period: "£3,033.00",
},
{
period: { label: "every 2 weeks", value: 2 },
charge: { field: "pscharge", value: 1401 },
+ charge_name: "personal service charge",
+ maximum_per_period: "£1,400.00",
},
{
- period: { label: "weekly", value: 1 },
+ period: { label: "weekly for 52 weeks", value: 1 },
charge: { field: "supcharg", value: 801 },
+ charge_name: "support charge",
+ maximum_per_period: "£800.00",
},
{
- period: { label: "monthly", value: 4 },
+ period: { label: "every calendar month", value: 4 },
charge: { field: "supcharg", value: 3471 },
+ charge_name: "support charge",
+ maximum_per_period: "£3,466.00",
},
{
period: { label: "every 2 weeks", value: 2 },
charge: { field: "supcharg", value: 1601 },
+ charge_name: "support charge",
+ maximum_per_period: "£1,600.00",
}].each do |test_case|
it "does not allow charges outside the range when period is #{test_case[:period][:label]}" do
record.period = test_case[:period][:value]
record[test_case[:charge][:field]] = test_case[:charge][:value]
financial_validator.validate_rent_amount(record)
expect(record.errors[test_case[:charge][:field]])
- .to include(match I18n.t("validations.financial.rent.#{test_case[:charge][:field]}.private_registered_provider.supported_housing"))
+ .to include(match I18n.t("validations.financial.rent.out_of_range", charge_name: test_case[:charge_name], maximum_per_period: test_case[:maximum_per_period], frequency: test_case[:period][:label], letting_type: "supported housing", provider_type: "private registered provider"))
end
end
[{
- period: { label: "weekly", value: 1 },
+ period: { label: "weekly for 52 weeks", value: 1 },
charge: { field: "scharge", value: 799 },
},
{
- period: { label: "monthly", value: 4 },
+ period: { label: "every calendar month", value: 4 },
charge: { field: "scharge", value: 3400 },
},
{
@@ -413,11 +449,11 @@ RSpec.describe Validations::FinancialValidations do
charge: { field: "scharge", value: 1599 },
},
{
- period: { label: "weekly", value: 1 },
+ period: { label: "weekly for 52 weeks", value: 1 },
charge: { field: "pscharge", value: 699 },
},
{
- period: { label: "monthly", value: 4 },
+ period: { label: "every calendar month", value: 4 },
charge: { field: "pscharge", value: 2500 },
},
{
@@ -425,11 +461,11 @@ RSpec.describe Validations::FinancialValidations do
charge: { field: "pscharge", value: 1399 },
},
{
- period: { label: "weekly", value: 1 },
+ period: { label: "weekly for 52 weeks", value: 1 },
charge: { field: "supcharg", value: 799 },
},
{
- period: { label: "monthly", value: 4 },
+ period: { label: "every calendar month", value: 4 },
charge: { field: "supcharg", value: 3400 },
},
{
@@ -454,56 +490,74 @@ RSpec.describe Validations::FinancialValidations do
before { record.needstype = 1 }
[{
- period: { label: "weekly", value: 1 },
+ period: { label: "weekly for 52 weeks", value: 1 },
charge: { field: "scharge", value: 501 },
+ charge_name: "service charge",
+ maximum_per_period: "£500.00",
},
{
- period: { label: "monthly", value: 4 },
+ period: { label: "every calendar month", value: 4 },
charge: { field: "scharge", value: 2300 },
+ charge_name: "service charge",
+ maximum_per_period: "£2,166.00",
},
{
period: { label: "every 2 weeks", value: 2 },
charge: { field: "scharge", value: 1001 },
+ charge_name: "service charge",
+ maximum_per_period: "£1,000.00",
},
{
- period: { label: "weekly", value: 1 },
+ period: { label: "weekly for 52 weeks", value: 1 },
charge: { field: "pscharge", value: 201 },
+ charge_name: "personal service charge",
+ maximum_per_period: "£200.00",
},
{
- period: { label: "monthly", value: 4 },
+ period: { label: "every calendar month", value: 4 },
charge: { field: "pscharge", value: 1000 },
+ charge_name: "personal service charge",
+ maximum_per_period: "£866.00",
},
{
period: { label: "every 2 weeks", value: 2 },
charge: { field: "pscharge", value: 401 },
+ charge_name: "personal service charge",
+ maximum_per_period: "£400.00",
},
{
- period: { label: "weekly", value: 1 },
+ period: { label: "weekly for 52 weeks", value: 1 },
charge: { field: "supcharg", value: 201 },
+ charge_name: "support charge",
+ maximum_per_period: "£200.00",
},
{
- period: { label: "monthly", value: 4 },
+ period: { label: "every calendar month", value: 4 },
charge: { field: "supcharg", value: 1000 },
+ charge_name: "support charge",
+ maximum_per_period: "£866.00",
},
{
period: { label: "every 2 weeks", value: 2 },
charge: { field: "supcharg", value: 401 },
+ charge_name: "support charge",
+ maximum_per_period: "£400.00",
}].each do |test_case|
it "does not allow charges outside the range when period is #{test_case[:period][:label]}" do
record.period = test_case[:period][:value]
record[test_case[:charge][:field]] = test_case[:charge][:value]
financial_validator.validate_rent_amount(record)
expect(record.errors[test_case[:charge][:field]])
- .to include(match I18n.t("validations.financial.rent.#{test_case[:charge][:field]}.local_authority.general_needs"))
+ .to include(match I18n.t("validations.financial.rent.out_of_range", charge_name: test_case[:charge_name], maximum_per_period: test_case[:maximum_per_period], frequency: test_case[:period][:label], letting_type: "general needs", provider_type: "local authority"))
end
end
[{
- period: { label: "weekly", value: 1 },
+ period: { label: "weekly for 52 weeks", value: 1 },
charge: { field: "scharge", value: 499 },
},
{
- period: { label: "monthly", value: 4 },
+ period: { label: "every calendar month", value: 4 },
charge: { field: "scharge", value: 2000 },
},
{
@@ -511,11 +565,11 @@ RSpec.describe Validations::FinancialValidations do
charge: { field: "scharge", value: 999 },
},
{
- period: { label: "weekly", value: 1 },
+ period: { label: "weekly for 52 weeks", value: 1 },
charge: { field: "pscharge", value: 199 },
},
{
- period: { label: "monthly", value: 4 },
+ period: { label: "every calendar month", value: 4 },
charge: { field: "pscharge", value: 800 },
},
{
@@ -523,11 +577,11 @@ RSpec.describe Validations::FinancialValidations do
charge: { field: "pscharge", value: 399 },
},
{
- period: { label: "weekly", value: 1 },
+ period: { label: "weekly for 52 weeks", value: 1 },
charge: { field: "supcharg", value: 199.99 },
},
{
- period: { label: "monthly", value: 4 },
+ period: { label: "every calendar month", value: 4 },
charge: { field: "supcharg", value: 800 },
},
{
@@ -548,61 +602,79 @@ RSpec.describe Validations::FinancialValidations do
before { record.needstype = 2 }
[{
- period: { label: "weekly", value: 1 },
+ period: { label: "weekly for 52 weeks", value: 1 },
charge: { field: "scharge", value: 501 },
+ charge_name: "service charge",
+ maximum_per_period: "£500.00",
},
{
- period: { label: "monthly", value: 4 },
+ period: { label: "every calendar month", value: 4 },
charge: { field: "scharge", value: 2300 },
+ charge_name: "service charge",
+ maximum_per_period: "£2,166.00",
},
{
period: { label: "every 2 weeks", value: 2 },
charge: { field: "scharge", value: 1001 },
+ charge_name: "service charge",
+ maximum_per_period: "£1,000.00",
},
{
- period: { label: "weekly", value: 1 },
+ period: { label: "weekly for 52 weeks", value: 1 },
charge: { field: "pscharge", value: 201 },
+ charge_name: "personal service charge",
+ maximum_per_period: "£200.00",
},
{
- period: { label: "monthly", value: 4 },
+ period: { label: "every calendar month", value: 4 },
charge: { field: "pscharge", value: 1000 },
+ charge_name: "personal service charge",
+ maximum_per_period: "£866.00",
},
{
period: { label: "every 2 weeks", value: 2 },
charge: { field: "pscharge", value: 401 },
+ charge_name: "personal service charge",
+ maximum_per_period: "£400.00",
},
{
- period: { label: "weekly", value: 1 },
+ period: { label: "weekly for 52 weeks", value: 1 },
charge: { field: "supcharg", value: 201 },
+ charge_name: "support charge",
+ maximum_per_period: "£200.00",
},
{
- period: { label: "monthly", value: 4 },
+ period: { label: "every calendar month", value: 4 },
charge: { field: "supcharg", value: 1000 },
+ charge_name: "support charge",
+ maximum_per_period: "£866.00",
},
{
period: { label: "every 2 weeks", value: 2 },
charge: { field: "supcharg", value: 401 },
+ charge_name: "support charge",
+ maximum_per_period: "£400.00",
}].each do |test_case|
it "does not allow charges outside the range when period is #{test_case[:period][:label]}" do
record.period = test_case[:period][:value]
record[test_case[:charge][:field]] = test_case[:charge][:value]
financial_validator.validate_rent_amount(record)
expect(record.errors[test_case[:charge][:field]])
- .to include(match I18n.t("validations.financial.rent.#{test_case[:charge][:field]}.local_authority.supported_housing"))
+ .to include(match I18n.t("validations.financial.rent.out_of_range", charge_name: test_case[:charge_name], maximum_per_period: test_case[:maximum_per_period], frequency: test_case[:period][:label], letting_type: "supported housing", provider_type: "local authority"))
end
end
context "when charges are not given" do
[{
- period: { label: "weekly", value: 1 },
+ period: { label: "weekly for 52 weeks", value: 1 },
charge: { field: "scharge", value: nil },
},
{
- period: { label: "weekly", value: 1 },
+ period: { label: "weekly for 52 weeks", value: 1 },
charge: { field: "pscharge", value: nil },
},
{
- period: { label: "weekly", value: 1 },
+ period: { label: "weekly for 52 weeks", value: 1 },
charge: { field: "supcharg", value: nil },
}].each do |test_case|
it "does not error" do
@@ -616,11 +688,11 @@ RSpec.describe Validations::FinancialValidations do
end
[{
- period: { label: "weekly", value: 1 },
+ period: { label: "weekly for 52 weeks", value: 1 },
charge: { field: "scharge", value: 499 },
},
{
- period: { label: "monthly", value: 4 },
+ period: { label: "every calendar month", value: 4 },
charge: { field: "scharge", value: 2000 },
},
{
@@ -628,11 +700,11 @@ RSpec.describe Validations::FinancialValidations do
charge: { field: "scharge", value: 999 },
},
{
- period: { label: "weekly", value: 1 },
+ period: { label: "weekly for 52 weeks", value: 1 },
charge: { field: "pscharge", value: 199 },
},
{
- period: { label: "monthly", value: 4 },
+ period: { label: "every calendar month", value: 4 },
charge: { field: "pscharge", value: 800 },
},
{
@@ -640,11 +712,11 @@ RSpec.describe Validations::FinancialValidations do
charge: { field: "pscharge", value: 399 },
},
{
- period: { label: "weekly", value: 1 },
+ period: { label: "weekly for 52 weeks", value: 1 },
charge: { field: "supcharg", value: 199.99 },
},
{
- period: { label: "monthly", value: 4 },
+ period: { label: "every calendar month", value: 4 },
charge: { field: "supcharg", value: 800 },
},
{
diff --git a/spec/models/validations/sales/setup_validations_spec.rb b/spec/models/validations/sales/setup_validations_spec.rb
index f7f01eaf7..526024ae3 100644
--- a/spec/models/validations/sales/setup_validations_spec.rb
+++ b/spec/models/validations/sales/setup_validations_spec.rb
@@ -188,7 +188,7 @@ RSpec.describe Validations::Sales::SetupValidations do
describe "#validate_merged_organisations_saledate" do
let(:record) { build(:sales_log) }
- let(:absorbing_organisation) { create(:organisation, created_at: Time.zone.local(2023, 2, 1), name: "Absorbing org") }
+ let(:absorbing_organisation) { create(:organisation, created_at: Time.zone.local(2023, 2, 1), available_from: Time.zone.local(2023, 2, 1), name: "Absorbing org") }
let(:merged_organisation) { create(:organisation, name: "Merged org") }
around do |example|
@@ -218,19 +218,27 @@ RSpec.describe Validations::Sales::SetupValidations do
end
context "and owning organisation is not yet active during the saledate" do
- it "does not allow saledate before absorbing organisation has been created" do
+ it "does not allow saledate before absorbing organisation has become available" do
record.saledate = Time.zone.local(2023, 1, 1)
record.owning_organisation_id = absorbing_organisation.id
setup_validator.validate_merged_organisations_saledate(record)
expect(record.errors["saledate"]).to include(match "Enter a date when the owning organisation was active. Absorbing org became active on 1 February 2023.")
end
- it "allows saledate after absorbing organisation has been created" do
+ it "allows saledate after absorbing organisation has become available" do
record.saledate = Time.zone.local(2023, 2, 2)
record.owning_organisation_id = absorbing_organisation.id
setup_validator.validate_merged_organisations_saledate(record)
expect(record.errors["saledate"]).to be_empty
end
+
+ it "allows saledate if available from is not given" do
+ record.saledate = Time.zone.local(2023, 1, 1)
+ absorbing_organisation.update!(available_from: nil)
+ record.owning_organisation_id = absorbing_organisation.id
+ setup_validator.validate_merged_organisations_saledate(record)
+ expect(record.errors["saledate"]).to be_empty
+ end
end
end
@@ -238,7 +246,7 @@ RSpec.describe Validations::Sales::SetupValidations do
let(:record) { build(:sales_log) }
context "when organisations are merged" do
- let(:absorbing_organisation) { create(:organisation, created_at: Time.zone.local(2023, 2, 1), name: "Absorbing org") }
+ let(:absorbing_organisation) { create(:organisation, created_at: Time.zone.local(2023, 2, 1), available_from: Time.zone.local(2023, 2, 1), name: "Absorbing org") }
let(:merged_organisation) { create(:organisation, name: "Merged org") }
around do |example|
@@ -265,19 +273,27 @@ RSpec.describe Validations::Sales::SetupValidations do
end
context "and owning organisation is not yet active during the saledate" do
- it "does not allow absorbing organisation before it had been created" do
+ it "does not allow absorbing organisation before it has become available" do
record.saledate = Time.zone.local(2023, 1, 1)
record.owning_organisation_id = absorbing_organisation.id
setup_validator.validate_organisation(record)
expect(record.errors["owning_organisation_id"]).to include(match "The owning organisation must be active on the sale completion date. Absorbing org became active on 1 February 2023.")
end
- it "allows absorbing organisation after it has been created" do
+ it "allows absorbing organisation after it has become available" do
record.saledate = Time.zone.local(2023, 2, 2)
record.owning_organisation_id = absorbing_organisation.id
setup_validator.validate_organisation(record)
expect(record.errors["owning_organisation_id"]).to be_empty
end
+
+ it "allows absorbing organisation if available from is not given" do
+ record.saledate = Time.zone.local(2023, 1, 1)
+ absorbing_organisation.update!(available_from: nil)
+ record.owning_organisation_id = absorbing_organisation.id
+ setup_validator.validate_organisation(record)
+ expect(record.errors["owning_organisation_id"]).to be_empty
+ end
end
end
end
diff --git a/spec/models/validations/setup_validations_spec.rb b/spec/models/validations/setup_validations_spec.rb
index 75b890b24..9228e2ee4 100644
--- a/spec/models/validations/setup_validations_spec.rb
+++ b/spec/models/validations/setup_validations_spec.rb
@@ -136,8 +136,8 @@ RSpec.describe Validations::SetupValidations do
Timecop.return
end
- let(:absorbing_organisation) { create(:organisation, created_at: Time.zone.local(2023, 2, 1, 4, 5, 6), name: "Absorbing org") }
- let(:absorbing_organisation_2) { create(:organisation, created_at: Time.zone.local(2023, 2, 1), name: "Absorbing org 2") }
+ let(:absorbing_organisation) { create(:organisation, created_at: Time.zone.local(2023, 2, 1, 4, 5, 6), available_from: Time.zone.local(2023, 2, 1, 4, 5, 6), name: "Absorbing org") }
+ let(:absorbing_organisation_2) { create(:organisation, created_at: Time.zone.local(2023, 2, 1), available_from: Time.zone.local(2023, 2, 1), name: "Absorbing org 2") }
let(:merged_organisation) { create(:organisation, name: "Merged org") }
let(:merged_organisation_2) { create(:organisation, name: "Merged org 2") }
@@ -147,14 +147,14 @@ RSpec.describe Validations::SetupValidations do
end
context "and owning organisation is no longer active" do
- it "does not allow startate after organisation has been merged" do
+ it "does not allow startdate after organisation has been merged" do
record.startdate = Time.zone.local(2023, 3, 1)
record.owning_organisation_id = merged_organisation.id
setup_validator.validate_startdate_setup(record)
expect(record.errors["startdate"]).to include(match "Enter a date when the owning organisation was active. Merged org became inactive on 2 February 2023 and was replaced by Absorbing org.")
end
- it "allows startate before organisation has been merged" do
+ it "allows startdate before organisation has been merged" do
record.startdate = Time.zone.local(2023, 1, 1)
record.owning_organisation_id = merged_organisation.id
setup_validator.validate_startdate_setup(record)
@@ -163,30 +163,38 @@ RSpec.describe Validations::SetupValidations do
end
context "and owning organisation is not yet active during the startdate" do
- it "does not allow startate before absorbing organisation has been created" do
+ it "does not allow startdate before absorbing organisation has become available" do
record.startdate = Time.zone.local(2023, 1, 1)
record.owning_organisation_id = absorbing_organisation.id
setup_validator.validate_startdate_setup(record)
expect(record.errors["startdate"]).to include(match "Enter a date when the owning organisation was active. Absorbing org became active on 1 February 2023.")
end
- it "allows startate after absorbing organisation has been created" do
+ it "allows startdate after absorbing organisation has become available" do
record.startdate = Time.zone.local(2023, 2, 2)
record.owning_organisation_id = absorbing_organisation.id
setup_validator.validate_startdate_setup(record)
expect(record.errors["startdate"]).to be_empty
end
+
+ it "allows startdate if organisation does not have available from date" do
+ record.startdate = Time.zone.local(2023, 1, 1)
+ absorbing_organisation.update!(available_from: nil)
+ record.owning_organisation_id = absorbing_organisation.id
+ setup_validator.validate_startdate_setup(record)
+ expect(record.errors["startdate"]).to be_empty
+ end
end
context "and managing organisation is no longer active during the startdate" do
- it "does not allow startate after organisation has been merged" do
+ it "does not allow startdate after organisation has been merged" do
record.startdate = Time.zone.local(2023, 3, 1)
record.managing_organisation_id = merged_organisation.id
setup_validator.validate_startdate_setup(record)
expect(record.errors["startdate"]).to include(match "Enter a date when the managing organisation was active. Merged org became inactive on 2 February 2023 and was replaced by Absorbing org.")
end
- it "allows startate before organisation has been merged" do
+ it "allows startdate before organisation has been merged" do
record.startdate = Time.zone.local(2023, 1, 1)
record.managing_organisation_id = merged_organisation.id
setup_validator.validate_startdate_setup(record)
@@ -195,23 +203,31 @@ RSpec.describe Validations::SetupValidations do
end
context "and managing organisation is not yet active during the startdate" do
- it "does not allow startate before absorbing organisation has been created" do
+ it "does not allow startdate before absorbing organisation has become available'" do
record.startdate = Time.zone.local(2023, 1, 1)
record.managing_organisation_id = absorbing_organisation.id
setup_validator.validate_startdate_setup(record)
expect(record.errors["startdate"]).to include(match "Enter a date when the managing organisation was active. Absorbing org became active on 1 February 2023.")
end
- it "allows startate after absorbing organisation has been created" do
+ it "allows startdate after absorbing organisation has become available" do
record.startdate = Time.zone.local(2023, 2, 2)
record.managing_organisation_id = absorbing_organisation.id
setup_validator.validate_startdate_setup(record)
expect(record.errors["startdate"]).to be_empty
end
+
+ it "allows startdate if organisation does not have available from date" do
+ record.startdate = Time.zone.local(2023, 1, 1)
+ absorbing_organisation.update!(available_from: nil)
+ record.managing_organisation_id = absorbing_organisation.id
+ setup_validator.validate_startdate_setup(record)
+ expect(record.errors["startdate"]).to be_empty
+ end
end
context "and owning and managing organisation is no longer active during the startdate" do
- it "does not allow startate after organisation has been merged" do
+ it "does not allow startdate after organisation has been merged" do
record.startdate = Time.zone.local(2023, 3, 1)
record.managing_organisation_id = merged_organisation.id
record.owning_organisation_id = merged_organisation.id
@@ -219,7 +235,7 @@ RSpec.describe Validations::SetupValidations do
expect(record.errors["startdate"]).to include(match "Enter a date when the owning and managing organisation was active. Merged org became inactive on 2 February 2023 and was replaced by Absorbing org.")
end
- it "allows startate before organisation has been merged" do
+ it "allows startdate before organisation has been merged" do
record.startdate = Time.zone.local(2023, 1, 1)
record.managing_organisation_id = merged_organisation.id
record.owning_organisation_id = merged_organisation.id
@@ -229,7 +245,7 @@ RSpec.describe Validations::SetupValidations do
end
context "and owning and managing organisation is not yet active during the startdate" do
- it "does not allow startate before absorbing organisation has been created" do
+ it "does not allow startdate before absorbing organisation has become available" do
record.startdate = Time.zone.local(2023, 1, 1)
record.managing_organisation_id = absorbing_organisation.id
record.owning_organisation_id = absorbing_organisation.id
@@ -237,17 +253,26 @@ RSpec.describe Validations::SetupValidations do
expect(record.errors["startdate"]).to include(match "Enter a date when the owning and managing organisation was active. Absorbing org became active on 1 February 2023.")
end
- it "allows startate after absorbing organisation has been created" do
+ it "allows startdate after absorbing organisation has become available" do
record.startdate = Time.zone.local(2023, 2, 1)
record.managing_organisation_id = absorbing_organisation.id
record.owning_organisation_id = absorbing_organisation.id
setup_validator.validate_startdate_setup(record)
expect(record.errors["startdate"]).to be_empty
end
+
+ it "allows startdate if organisation does not have available from date" do
+ record.startdate = Time.zone.local(2023, 1, 1)
+ absorbing_organisation.update!(available_from: nil)
+ record.managing_organisation_id = absorbing_organisation.id
+ record.owning_organisation_id = absorbing_organisation.id
+ setup_validator.validate_startdate_setup(record)
+ expect(record.errors["startdate"]).to be_empty
+ end
end
context "and owning and managing organisations are no longer active during the startdate" do
- it "does not allow startate after organisation have been merged" do
+ it "does not allow startdate after organisation have been merged" do
record.startdate = Time.zone.local(2023, 2, 2)
record.managing_organisation_id = merged_organisation.id
record.owning_organisation_id = merged_organisation_2.id
@@ -255,7 +280,7 @@ RSpec.describe Validations::SetupValidations do
expect(record.errors["startdate"]).to include(match "Enter a date when the owning and managing organisations were active. Merged org 2 and Merged org became inactive on 2 February 2023 and were replaced by Absorbing org.")
end
- it "allows startate before organisations have been merged" do
+ it "allows startdate before organisations have been merged" do
record.startdate = Time.zone.local(2023, 1, 1)
record.managing_organisation_id = merged_organisation.id
record.owning_organisation_id = merged_organisation_2.id
@@ -269,7 +294,7 @@ RSpec.describe Validations::SetupValidations do
merged_organisation_2.update!(absorbing_organisation: absorbing_organisation_2, merge_date: Time.zone.local(2023, 2, 2))
end
- it "does not allow startate after organisations have been merged" do
+ it "does not allow startdate after organisations have been merged" do
record.startdate = Time.zone.local(2023, 3, 1)
record.managing_organisation_id = merged_organisation.id
record.owning_organisation_id = merged_organisation_2.id
@@ -277,7 +302,7 @@ RSpec.describe Validations::SetupValidations do
expect(record.errors["startdate"]).to include(match "Enter a date when the owning and managing organisations were active. Merged org 2 became inactive on 2 February 2023 and was replaced by Absorbing org 2. Merged org became inactive on 2 February 2023 and was replaced by Absorbing org.")
end
- it "allows startate before organisations have been merged" do
+ it "allows startdate before organisations have been merged" do
record.startdate = Time.zone.local(2023, 1, 1)
record.managing_organisation_id = merged_organisation.id
record.owning_organisation_id = merged_organisation_2.id
@@ -291,7 +316,7 @@ RSpec.describe Validations::SetupValidations do
merged_organisation_2.update!(absorbing_organisation: absorbing_organisation_2, merge_date: Time.zone.local(2023, 2, 2))
end
- it "does not allow startate before absorbing organisation has been created" do
+ it "does not allow startdate before absorbing organisation has become available" do
record.startdate = Time.zone.local(2023, 1, 1)
record.managing_organisation_id = absorbing_organisation.id
record.owning_organisation_id = absorbing_organisation_2.id
@@ -299,13 +324,22 @@ RSpec.describe Validations::SetupValidations do
expect(record.errors["startdate"]).to include(match "Enter a date when the owning and managing organisations were active. Absorbing org 2 became active on 1 February 2023, and Absorbing org became active on 1 February 2023.")
end
- it "allows startate after absorbing organisation has been created" do
+ it "allows startdate after absorbing organisation has become available" do
record.startdate = Time.zone.local(2023, 2, 2)
record.managing_organisation_id = absorbing_organisation.id
record.owning_organisation_id = absorbing_organisation.id
setup_validator.validate_startdate_setup(record)
expect(record.errors["startdate"]).to be_empty
end
+
+ it "allows startdate if organisation does not have available from date" do
+ absorbing_organisation.update!(available_from: nil)
+ record.startdate = Time.zone.local(2023, 1, 1)
+ record.managing_organisation_id = absorbing_organisation.id
+ record.owning_organisation_id = absorbing_organisation.id
+ setup_validator.validate_startdate_setup(record)
+ expect(record.errors["startdate"]).to be_empty
+ end
end
end
end
@@ -723,7 +757,7 @@ RSpec.describe Validations::SetupValidations do
end
context "when organisations are merged" do
- let(:absorbing_organisation) { create(:organisation, created_at: Time.zone.local(2023, 2, 1, 4, 5, 6), name: "Absorbing org") }
+ let(:absorbing_organisation) { create(:organisation, created_at: Time.zone.local(2023, 2, 1, 4, 5, 6), available_from: Time.zone.local(2023, 2, 1, 4, 5, 6), name: "Absorbing org") }
let(:merged_organisation) { create(:organisation, name: "Merged org") }
around do |example|
@@ -750,19 +784,27 @@ RSpec.describe Validations::SetupValidations do
end
context "and owning organisation is not yet active during the startdate" do
- it "does not allow absorbing organisation before it had been created" do
+ it "does not allow absorbing organisation before it has become available'" do
record.startdate = Time.zone.local(2023, 1, 1)
record.owning_organisation_id = absorbing_organisation.id
setup_validator.validate_organisation(record)
expect(record.errors["owning_organisation_id"]).to include(match "The owning organisation must be active on the tenancy start date. Absorbing org became active on 1 February 2023.")
end
- it "allows absorbing organisation after it has been created" do
+ it "allows absorbing organisation after it has become available" do
record.startdate = Time.zone.local(2023, 2, 2)
record.owning_organisation_id = absorbing_organisation.id
setup_validator.validate_organisation(record)
expect(record.errors["owning_organisation_id"]).to be_empty
end
+
+ it "allows startdate if organisation does not have available from date" do
+ absorbing_organisation.update!(available_from: nil)
+ record.startdate = Time.zone.local(2023, 1, 1)
+ record.owning_organisation_id = absorbing_organisation.id
+ setup_validator.validate_organisation(record)
+ expect(record.errors["owning_organisation_id"]).to be_empty
+ end
end
context "when managing organisation is no longer active" do
@@ -782,19 +824,27 @@ RSpec.describe Validations::SetupValidations do
end
context "when managing organisation is not yet active during the startdate" do
- it "does not allow absorbing organisation before it had been created" do
+ it "does not allow absorbing organisation before it has become available" do
record.startdate = Time.zone.local(2023, 1, 1)
record.managing_organisation_id = absorbing_organisation.id
setup_validator.validate_organisation(record)
expect(record.errors["managing_organisation_id"]).to include(match "The managing organisation must be active on the tenancy start date. Absorbing org became active on 1 February 2023.")
end
- it "allows absorbing organisation after it has been created" do
+ it "allows absorbing organisation after it has become available'" do
record.startdate = Time.zone.local(2023, 2, 2)
record.managing_organisation_id = absorbing_organisation.id
setup_validator.validate_organisation(record)
expect(record.errors["managing_organisation_id"]).to be_empty
end
+
+ it "allows startdate if organisation does not have available from date" do
+ absorbing_organisation.update!(available_from: nil)
+ record.startdate = Time.zone.local(2023, 1, 1)
+ record.managing_organisation_id = absorbing_organisation.id
+ setup_validator.validate_organisation(record)
+ expect(record.errors["managing_organisation_id"]).to be_empty
+ end
end
end
end
diff --git a/spec/requests/content_controller_spec.rb b/spec/requests/content_controller_spec.rb
index 07be4256b..c978ecaa9 100644
--- a/spec/requests/content_controller_spec.rb
+++ b/spec/requests/content_controller_spec.rb
@@ -4,45 +4,81 @@ RSpec.describe ContentController, type: :request do
let(:headers) { { "Accept" => "text/html" } }
let(:page) { Capybara::Node::Simple.new(response.body) }
- describe "render privacy notice content page" do
- before do
- get "/privacy-notice", headers:, params: {}
- end
+ describe "when maintenance mode is disabled" do
+ describe "render privacy notice content page" do
+ before do
+ get "/privacy-notice", headers:, params: {}
+ end
- it "returns a 200" do
- expect(response).to have_http_status(:success)
- end
+ it "returns a 200" do
+ expect(response).to have_http_status(:success)
+ end
- it "returns the page" do
- expect(page).to have_title("Privacy notice")
+ it "returns the page" do
+ expect(page).to have_title("Privacy notice")
+ end
end
- end
- describe "render accessibility statement content page" do
- before do
- get "/accessibility-statement", headers:, params: {}
- end
+ describe "render accessibility statement content page" do
+ before do
+ get "/accessibility-statement", headers:, params: {}
+ end
+
+ it "returns a 200" do
+ expect(response).to have_http_status(:success)
+ end
- it "returns a 200" do
- expect(response).to have_http_status(:success)
+ it "returns the page" do
+ expect(page).to have_title("Accessibility statement")
+ end
end
- it "returns the page" do
- expect(page).to have_title("Accessibility statement")
+ describe "render data sharing agreement" do
+ before do
+ get "/data-sharing-agreement", headers:, params: {}
+ end
+
+ it "returns a 200" do
+ expect(response).to have_http_status(:success)
+ end
+
+ it "returns the page" do
+ expect(page).to have_title("Data sharing agreement")
+ end
end
end
- describe "render data sharing agreement" do
+ describe "when maintenance mode is enabled" do
before do
- get "/data-sharing-agreement", headers:, params: {}
+ allow(FeatureToggle).to receive(:maintenance_mode_enabled?).and_return(true)
end
- it "returns a 200" do
- expect(response).to have_http_status(:success)
+ describe "render privacy notice content page" do
+ before do
+ get "/privacy-notice", headers:, params: {}
+ end
+
+ it "returns a 200" do
+ expect(response).to have_http_status(:success)
+ end
+
+ it "returns the page" do
+ expect(page).to have_title("Privacy notice")
+ end
end
- it "returns the page" do
- expect(page).to have_title("Data sharing agreement")
+ describe "render accessibility statement content page" do
+ before do
+ get "/accessibility-statement", headers:, params: {}
+ end
+
+ it "returns a 200" do
+ expect(response).to have_http_status(:success)
+ end
+
+ it "returns the page" do
+ expect(page).to have_title("Accessibility statement")
+ end
end
end
end
diff --git a/spec/requests/cookies_controller_spec.rb b/spec/requests/cookies_controller_spec.rb
new file mode 100644
index 000000000..82cf06a10
--- /dev/null
+++ b/spec/requests/cookies_controller_spec.rb
@@ -0,0 +1,42 @@
+require "rails_helper"
+
+RSpec.describe CookiesController, type: :request do
+ let(:headers) { { "Accept" => "text/html" } }
+ let(:page) { Capybara::Node::Simple.new(response.body) }
+
+ describe "when maintenance mode is disabled" do
+ describe "render cookies page" do
+ before do
+ get "/cookies", headers:, params: {}
+ end
+
+ it "returns a 200" do
+ expect(response).to have_http_status(:success)
+ end
+
+ it "returns the page" do
+ expect(page).to have_title("Cookies")
+ end
+ end
+ end
+
+ describe "when maintenance mode is enabled" do
+ before do
+ allow(FeatureToggle).to receive(:maintenance_mode_enabled?).and_return(true)
+ end
+
+ describe "render cookies page" do
+ before do
+ get "/cookies", headers:, params: {}
+ end
+
+ it "returns a 200" do
+ expect(response).to have_http_status(:success)
+ end
+
+ it "returns the page" do
+ expect(page).to have_title("Cookies")
+ end
+ end
+ end
+end
diff --git a/spec/requests/duplicate_logs_controller_spec.rb b/spec/requests/duplicate_logs_controller_spec.rb
index 9df134e76..933a0f54d 100644
--- a/spec/requests/duplicate_logs_controller_spec.rb
+++ b/spec/requests/duplicate_logs_controller_spec.rb
@@ -30,144 +30,452 @@ RSpec.describe DuplicateLogsController, type: :request do
context "when user is signed in" do
before do
- allow(user).to receive(:need_two_factor_authentication?).and_return(false)
- sign_in user
+ body = {
+ results: [
+ {
+ DPA: {
+ "POSTCODE": "LS16 6FT",
+ "POST_TOWN": "Westminster",
+ "PO_BOX_NUMBER": "321",
+ "DOUBLE_DEPENDENT_LOCALITY": "Double Dependent Locality",
+ },
+ },
+ ],
+ }.to_json
+
+ stub_request(:get, "https://api.os.uk/search/places/v1/uprn?key=OS_DATA_KEY&uprn=123")
+ .to_return(status: 200, body:, headers: {})
end
- context "when viewing lettings logs duplicates" do
- context "when there are multiple duplicate logs" do
- let(:duplicate_logs) { create_list(:lettings_log, 2, :completed) }
+ context "when user is support" do
+ let(:support_user_org) { create(:organisation) }
+ let(:user) { create(:user, :support, organisation: support_user_org) }
- before do
- allow(LettingsLog).to receive(:duplicate_logs).and_return(duplicate_logs)
- get "/lettings-logs/#{lettings_log.id}/duplicate-logs?original_log_id=#{lettings_log.id}"
- end
-
- it "displays links to all the duplicate logs" do
- expect(page).to have_link("Log #{lettings_log.id}", href: "/lettings-logs/#{lettings_log.id}")
- expect(page).to have_link("Log #{duplicate_logs.first.id}", href: "/lettings-logs/#{duplicate_logs.first.id}")
- expect(page).to have_link("Log #{duplicate_logs.second.id}", href: "/lettings-logs/#{duplicate_logs.second.id}")
- end
-
- it "displays check your answers for each log with correct questions" do
- expect(page).to have_content("Q5 - Tenancy start date", count: 3)
- expect(page).to have_content("Q7 - Tenant code", count: 3)
- expect(page).to have_content("Q12 - Postcode", count: 3)
- expect(page).to have_content("Q32 - Lead tenant’s age", count: 3)
- expect(page).to have_content("Q33 - Lead tenant’s gender identity", count: 3)
- expect(page).to have_content("Q37 - Lead tenant’s working situation", count: 3)
- expect(page).to have_content("Household rent and charges", count: 3)
- expect(page).to have_link("Change", count: 21)
- expect(page).to have_link("Change", href: "/lettings-logs/#{lettings_log.id}/tenant-code?first_remaining_duplicate_id=#{duplicate_logs[0].id}&original_log_id=#{lettings_log.id}&referrer=duplicate_logs")
- expect(page).to have_link("Change", href: "/lettings-logs/#{duplicate_logs[0].id}/tenant-code?first_remaining_duplicate_id=#{lettings_log.id}&original_log_id=#{lettings_log.id}&referrer=duplicate_logs")
- expect(page).to have_link("Change", href: "/lettings-logs/#{duplicate_logs[1].id}/tenant-code?first_remaining_duplicate_id=#{lettings_log.id}&original_log_id=#{lettings_log.id}&referrer=duplicate_logs")
- end
-
- it "displays buttons to delete" do
- expect(page).to have_link("Keep this log and delete duplicates", count: 3)
- expect(page).to have_link("Keep this log and delete duplicates", href: "/lettings-logs/#{lettings_log.id}/delete-duplicates?original_log_id=#{lettings_log.id}")
- expect(page).to have_link("Keep this log and delete duplicates", href: "/lettings-logs/#{duplicate_logs.first.id}/delete-duplicates?original_log_id=#{lettings_log.id}")
- expect(page).to have_link("Keep this log and delete duplicates", href: "/lettings-logs/#{duplicate_logs.second.id}/delete-duplicates?original_log_id=#{lettings_log.id}")
- end
+ before do
+ allow(user).to receive(:need_two_factor_authentication?).and_return(false)
+ sign_in user
end
- context "when there are no more duplicate logs" do
- before do
- allow(LettingsLog).to receive(:duplicate_logs).and_return(LettingsLog.none)
- get "/lettings-logs/#{lettings_log.id}/duplicate-logs?original_log_id=#{lettings_log.id}"
+ context "when viewing lettings logs duplicates" do
+ context "when there are multiple duplicate logs" do
+ let(:duplicate_logs) { create_list(:lettings_log, 2, :completed) }
+
+ before do
+ allow(LettingsLog).to receive(:duplicate_logs).and_return(duplicate_logs)
+ get "/lettings-logs/#{lettings_log.id}/duplicate-logs?original_log_id=#{lettings_log.id}&organisation_id=#{lettings_log.owning_organisation_id}"
+ end
+
+ it "displays links to all the duplicate logs" do
+ expect(page).to have_link("Log #{lettings_log.id}", href: "/lettings-logs/#{lettings_log.id}")
+ expect(page).to have_link("Log #{duplicate_logs.first.id}", href: "/lettings-logs/#{duplicate_logs.first.id}")
+ expect(page).to have_link("Log #{duplicate_logs.second.id}", href: "/lettings-logs/#{duplicate_logs.second.id}")
+ end
+
+ it "displays check your answers for each log with correct questions" do
+ expect(page).to have_content("Q5 - Tenancy start date", count: 3)
+ expect(page).to have_content("Q7 - Tenant code", count: 3)
+ expect(page).to have_content("Q12 - Postcode", count: 3)
+ expect(page).to have_content("Q32 - Lead tenant’s age", count: 3)
+ expect(page).to have_content("Q33 - Lead tenant’s gender identity", count: 3)
+ expect(page).to have_content("Q37 - Lead tenant’s working situation", count: 3)
+ expect(page).to have_content("Household rent and charges", count: 3)
+ expect(page).to have_link("Change", count: 24)
+ expect(page).to have_link("Change", href: "/lettings-logs/#{lettings_log.id}/tenant-code?first_remaining_duplicate_id=#{duplicate_logs[0].id}&organisation_id=#{lettings_log.owning_organisation_id}&original_log_id=#{lettings_log.id}&referrer=duplicate_logs")
+ expect(page).to have_link("Change", href: "/lettings-logs/#{duplicate_logs[0].id}/tenant-code?first_remaining_duplicate_id=#{lettings_log.id}&organisation_id=#{lettings_log.owning_organisation_id}&original_log_id=#{lettings_log.id}&referrer=duplicate_logs")
+ expect(page).to have_link("Change", href: "/lettings-logs/#{duplicate_logs[1].id}/tenant-code?first_remaining_duplicate_id=#{lettings_log.id}&organisation_id=#{lettings_log.owning_organisation_id}&original_log_id=#{lettings_log.id}&referrer=duplicate_logs")
+ end
+
+ it "displays check your answers for each log with correct questions where UPRN is given" do
+ lettings_log.update!(uprn: "123", uprn_known: 1, uprn_confirmed: 1)
+ duplicate_logs[0].update!(uprn: "123", uprn_known: 1, uprn_confirmed: 1)
+ get "/lettings-logs/#{lettings_log.id}/duplicate-logs?original_log_id=#{lettings_log.id}"
+
+ expect(page).to have_content("Q5 - Tenancy start date", count: 3)
+ expect(page).to have_content("Q7 - Tenant code", count: 3)
+ expect(page).to have_content("Q12 - Postcode", count: 1)
+ expect(page).to have_content("Postcode (from UPRN)", count: 2)
+ expect(page).to have_content("Q32 - Lead tenant’s age", count: 3)
+ expect(page).to have_content("Q33 - Lead tenant’s gender identity", count: 3)
+ expect(page).to have_content("Q37 - Lead tenant’s working situation", count: 3)
+ expect(page).to have_content("Household rent and charges", count: 3)
+ expect(page).to have_link("Change", count: 24)
+ expect(page).to have_link("Change", href: "/lettings-logs/#{lettings_log.id}/tenant-code?first_remaining_duplicate_id=#{duplicate_logs[0].id}&original_log_id=#{lettings_log.id}&referrer=duplicate_logs")
+ expect(page).to have_link("Change", href: "/lettings-logs/#{duplicate_logs[0].id}/tenant-code?first_remaining_duplicate_id=#{lettings_log.id}&original_log_id=#{lettings_log.id}&referrer=duplicate_logs")
+ expect(page).to have_link("Change", href: "/lettings-logs/#{duplicate_logs[1].id}/tenant-code?first_remaining_duplicate_id=#{lettings_log.id}&original_log_id=#{lettings_log.id}&referrer=duplicate_logs")
+ end
+
+ it "displays buttons to delete" do
+ expect(page).to have_link("Keep this log and delete duplicates", count: 3)
+ expect(page).to have_link("Keep this log and delete duplicates", href: "/lettings-logs/#{lettings_log.id}/delete-duplicates?organisation_id=#{lettings_log.owning_organisation_id}&original_log_id=#{lettings_log.id}")
+ expect(page).to have_link("Keep this log and delete duplicates", href: "/lettings-logs/#{duplicate_logs.first.id}/delete-duplicates?organisation_id=#{lettings_log.owning_organisation_id}&original_log_id=#{lettings_log.id}")
+ expect(page).to have_link("Keep this log and delete duplicates", href: "/lettings-logs/#{duplicate_logs.second.id}/delete-duplicates?organisation_id=#{lettings_log.owning_organisation_id}&original_log_id=#{lettings_log.id}")
+ end
end
- it "displays check your answers for each log with correct questions" do
- expect(page).to have_content("Q5 - Tenancy start date", count: 1)
- expect(page).to have_content("Q7 - Tenant code", count: 1)
- expect(page).to have_content("Q12 - Postcode", count: 1)
- expect(page).to have_content("Q32 - Lead tenant’s age", count: 1)
- expect(page).to have_content("Q33 - Lead tenant’s gender identity", count: 1)
- expect(page).to have_content("Q37 - Lead tenant’s working situation", count: 1)
- expect(page).to have_content("Household rent and charges", count: 1)
- expect(page).to have_link("Change", count: 7)
- expect(page).to have_link("Change", href: "/lettings-logs/#{lettings_log.id}/tenant-code?original_log_id=#{lettings_log.id}&referrer=interruption_screen")
+ context "when there are no more duplicate logs" do
+ context "when accessed from the duplicate logs banner flow" do
+ before do
+ allow(LettingsLog).to receive(:duplicate_logs).and_return(LettingsLog.none)
+ get "/lettings-logs/#{lettings_log.id}/duplicate-logs?original_log_id=#{lettings_log.id}&organisation_id=#{lettings_log.owning_organisation_id}&referrer=duplicate_logs_banner"
+ end
+
+ it "displays check your answers for each log with correct questions" do
+ expect(page).to have_content("Q5 - Tenancy start date", count: 1)
+ expect(page).to have_content("Q7 - Tenant code", count: 1)
+ expect(page).to have_content("Q12 - Postcode", count: 1)
+ expect(page).to have_content("Q32 - Lead tenant’s age", count: 1)
+ expect(page).to have_content("Q33 - Lead tenant’s gender identity", count: 1)
+ expect(page).to have_content("Q37 - Lead tenant’s working situation", count: 1)
+ expect(page).to have_content("Household rent and charges", count: 1)
+ expect(page).to have_link("Change", count: 8)
+ expect(page).to have_link("Change", href: "/lettings-logs/#{lettings_log.id}/tenant-code?original_log_id=#{lettings_log.id}&referrer=interruption_screen")
+ end
+
+ it "displays button to review other duplicates" do
+ expect(page).to have_link("Review other duplicates", href: "/organisations/#{lettings_log.owning_organisation_id}/duplicates?referrer=duplicate_logs_banner")
+ end
+
+ it "displays no duplicates banner" do
+ expect(page).to have_content("This log had the same answers but it is no longer a duplicate. Make sure the answers are correct.")
+ end
+ end
+
+ context "when accessed from the single log submission flow" do
+ before do
+ allow(LettingsLog).to receive(:duplicate_logs).and_return(LettingsLog.none)
+ get "/lettings-logs/#{lettings_log.id}/duplicate-logs?original_log_id=#{lettings_log.id}&organisation_id=#{lettings_log.owning_organisation_id}"
+ end
+
+ it "displays check your answers for each log with correct questions" do
+ expect(page).to have_content("Q5 - Tenancy start date", count: 1)
+ expect(page).to have_content("Q7 - Tenant code", count: 1)
+ expect(page).to have_content("Q12 - Postcode", count: 1)
+ expect(page).to have_content("Q32 - Lead tenant’s age", count: 1)
+ expect(page).to have_content("Q33 - Lead tenant’s gender identity", count: 1)
+ expect(page).to have_content("Q37 - Lead tenant’s working situation", count: 1)
+ expect(page).to have_content("Household rent and charges", count: 1)
+ expect(page).to have_link("Change", count: 8)
+ expect(page).to have_link("Change", href: "/lettings-logs/#{lettings_log.id}/tenant-code?original_log_id=#{lettings_log.id}&referrer=interruption_screen")
+ end
+
+ it "displays button to return to log" do
+ expect(page).to have_link("Back to Log #{lettings_log.id}", href: "/lettings-logs/#{lettings_log.id}")
+ end
+
+ it "displays no duplicates banner" do
+ expect(page).to have_content("This log had the same answers but it is no longer a duplicate. Make sure the answers are correct.")
+ end
+ end
end
+ end
- it "displays buttons to return to log" do
- expect(page).to have_link("Back to Log #{lettings_log.id}", href: "/lettings-logs/#{lettings_log.id}")
+ context "when viewing sales logs duplicates" do
+ context "when there are multiple duplicate logs" do
+ let(:duplicate_logs) { create_list(:sales_log, 2, :completed) }
+
+ before do
+ allow(SalesLog).to receive(:duplicate_logs).and_return(duplicate_logs)
+ get "/sales-logs/#{sales_log.id}/duplicate-logs?original_log_id=#{sales_log.id}&organisation_id=#{sales_log.owning_organisation_id}"
+ end
+
+ it "displays links to all the duplicate logs" do
+ expect(page).to have_link("Log #{sales_log.id}", href: "/sales-logs/#{sales_log.id}")
+ expect(page).to have_link("Log #{duplicate_logs.first.id}", href: "/sales-logs/#{duplicate_logs.first.id}")
+ expect(page).to have_link("Log #{duplicate_logs.second.id}", href: "/sales-logs/#{duplicate_logs.second.id}")
+ end
+
+ it "displays check your answers for each log with correct questions" do
+ expect(page).to have_content("Q1 - Sale completion date", count: 3)
+ expect(page).to have_content("Q2 - Purchaser code", count: 3)
+ expect(page).to have_content("Q20 - Lead buyer’s age", count: 3)
+ expect(page).to have_content("Q21 - Buyer 1’s gender identity", count: 3)
+ expect(page).to have_content("Q25 - Buyer 1's working situation", count: 3)
+ expect(page).to have_content("Q15 - Postcode", count: 3)
+ expect(page).to have_link("Change", count: 21)
+ expect(page).to have_link("Change", href: "/sales-logs/#{sales_log.id}/purchaser-code?first_remaining_duplicate_id=#{duplicate_logs[0].id}&organisation_id=#{sales_log.owning_organisation_id}&original_log_id=#{sales_log.id}&referrer=duplicate_logs")
+ expect(page).to have_link("Change", href: "/sales-logs/#{duplicate_logs[0].id}/purchaser-code?first_remaining_duplicate_id=#{sales_log.id}&organisation_id=#{sales_log.owning_organisation_id}&original_log_id=#{sales_log.id}&referrer=duplicate_logs")
+ expect(page).to have_link("Change", href: "/sales-logs/#{duplicate_logs[1].id}/purchaser-code?first_remaining_duplicate_id=#{sales_log.id}&organisation_id=#{sales_log.owning_organisation_id}&original_log_id=#{sales_log.id}&referrer=duplicate_logs")
+ end
+
+ it "displays check your answers for each log with correct questions when UPRN is given" do
+ sales_log.update!(uprn: "123", uprn_known: 1)
+ duplicate_logs[0].update!(uprn: "123", uprn_known: 1)
+ duplicate_logs[1].update!(uprn: "123", uprn_known: 1)
+ get "/sales-logs/#{sales_log.id}/duplicate-logs?original_log_id=#{sales_log.id}"
+
+ expect(page).to have_content("Q1 - Sale completion date", count: 3)
+ expect(page).to have_content("Q2 - Purchaser code", count: 3)
+ expect(page).to have_content("Q20 - Lead buyer’s age", count: 3)
+ expect(page).to have_content("Q21 - Buyer 1’s gender identity", count: 3)
+ expect(page).to have_content("Q25 - Buyer 1's working situation", count: 3)
+ expect(page).to have_content("Postcode (from UPRN)", count: 3)
+ expect(page).to have_link("Change", count: 21)
+ expect(page).to have_link("Change", href: "/sales-logs/#{sales_log.id}/purchaser-code?first_remaining_duplicate_id=#{duplicate_logs[0].id}&original_log_id=#{sales_log.id}&referrer=duplicate_logs")
+ expect(page).to have_link("Change", href: "/sales-logs/#{duplicate_logs[0].id}/purchaser-code?first_remaining_duplicate_id=#{sales_log.id}&original_log_id=#{sales_log.id}&referrer=duplicate_logs")
+ expect(page).to have_link("Change", href: "/sales-logs/#{duplicate_logs[1].id}/purchaser-code?first_remaining_duplicate_id=#{sales_log.id}&original_log_id=#{sales_log.id}&referrer=duplicate_logs")
+ end
+
+ it "displays buttons to delete" do
+ expect(page).to have_link("Keep this log and delete duplicates", count: 3)
+ expect(page).to have_link("Keep this log and delete duplicates", href: "/sales-logs/#{sales_log.id}/delete-duplicates?organisation_id=#{sales_log.owning_organisation_id}&original_log_id=#{sales_log.id}")
+ expect(page).to have_link("Keep this log and delete duplicates", href: "/sales-logs/#{duplicate_logs.first.id}/delete-duplicates?organisation_id=#{sales_log.owning_organisation_id}&original_log_id=#{sales_log.id}")
+ expect(page).to have_link("Keep this log and delete duplicates", href: "/sales-logs/#{duplicate_logs.second.id}/delete-duplicates?organisation_id=#{sales_log.owning_organisation_id}&original_log_id=#{sales_log.id}")
+ end
end
- it "displays no duplicates banner" do
- expect(page).to have_content("This log had the same answers but it is no longer a duplicate. Make sure the answers are correct.")
+ context "when there are no more duplicate logs" do
+ context "when accessed from the duplicate logs banner flow" do
+ before do
+ allow(SalesLog).to receive(:duplicate_logs).and_return(SalesLog.none)
+ get "/sales-logs/#{sales_log.id}/duplicate-logs?original_log_id=#{sales_log.id}&referrer=duplicate_logs_banner&organisation_id=#{sales_log.owning_organisation_id}"
+ end
+
+ it "displays check your answers for each log with correct questions" do
+ expect(page).to have_content("Q1 - Sale completion date", count: 1)
+ expect(page).to have_content("Q2 - Purchaser code", count: 1)
+ expect(page).to have_content("Q20 - Lead buyer’s age", count: 1)
+ expect(page).to have_content("Q21 - Buyer 1’s gender identity", count: 1)
+ expect(page).to have_content("Q25 - Buyer 1's working situation", count: 1)
+ expect(page).to have_content("Q15 - Postcode", count: 1)
+ expect(page).to have_link("Change", count: 7)
+ expect(page).to have_link("Change", href: "/sales-logs/#{sales_log.id}/purchaser-code?original_log_id=#{sales_log.id}&referrer=interruption_screen")
+ end
+
+ it "displays button to review other duplicates" do
+ expect(page).to have_link("Review other duplicates", href: "/organisations/#{sales_log.owning_organisation_id}/duplicates?referrer=duplicate_logs_banner")
+ end
+
+ it "displays no duplicates banner" do
+ expect(page).to have_content("This log had the same answers but it is no longer a duplicate. Make sure the answers are correct.")
+ end
+ end
+
+ context "when accessed from the single log submission flow" do
+ before do
+ allow(SalesLog).to receive(:duplicate_logs).and_return(SalesLog.none)
+ get "/sales-logs/#{sales_log.id}/duplicate-logs?original_log_id=#{sales_log.id}&organisation_id=#{sales_log.owning_organisation_id}"
+ end
+
+ it "displays check your answers for each log with correct questions" do
+ expect(page).to have_content("Q1 - Sale completion date", count: 1)
+ expect(page).to have_content("Q2 - Purchaser code", count: 1)
+ expect(page).to have_content("Q20 - Lead buyer’s age", count: 1)
+ expect(page).to have_content("Q21 - Buyer 1’s gender identity", count: 1)
+ expect(page).to have_content("Q25 - Buyer 1's working situation", count: 1)
+ expect(page).to have_content("Q15 - Postcode", count: 1)
+ expect(page).to have_link("Change", count: 7)
+ expect(page).to have_link("Change", href: "/sales-logs/#{sales_log.id}/purchaser-code?original_log_id=#{sales_log.id}&referrer=interruption_screen")
+ end
+
+ it "displays button to return to log" do
+ expect(page).to have_link("Back to Log #{sales_log.id}", href: "/sales-logs/#{sales_log.id}")
+ end
+
+ it "displays no duplicates banner" do
+ expect(page).to have_content("This log had the same answers but it is no longer a duplicate. Make sure the answers are correct.")
+ end
+ end
end
end
end
- context "when viewing sales logs duplicates" do
- context "when there are multiple duplicate logs" do
- let(:duplicate_logs) { create_list(:sales_log, 2, :completed) }
-
- before do
- allow(SalesLog).to receive(:duplicate_logs).and_return(duplicate_logs)
- get "/sales-logs/#{sales_log.id}/duplicate-logs?original_log_id=#{sales_log.id}"
- end
-
- it "displays links to all the duplicate logs" do
- expect(page).to have_link("Log #{sales_log.id}", href: "/sales-logs/#{sales_log.id}")
- expect(page).to have_link("Log #{duplicate_logs.first.id}", href: "/sales-logs/#{duplicate_logs.first.id}")
- expect(page).to have_link("Log #{duplicate_logs.second.id}", href: "/sales-logs/#{duplicate_logs.second.id}")
- end
-
- it "displays check your answers for each log with correct questions" do
- expect(page).to have_content("Q1 - Sale completion date", count: 3)
- expect(page).to have_content("Q2 - Purchaser code", count: 3)
- expect(page).to have_content("Q20 - Lead buyer’s age", count: 3)
- expect(page).to have_content("Q21 - Buyer 1’s gender identity", count: 3)
- expect(page).to have_content("Q25 - Buyer 1's working situation", count: 3)
- expect(page).to have_content("Q15 - Postcode", count: 3)
- expect(page).to have_link("Change", count: 18)
- expect(page).to have_link("Change", href: "/sales-logs/#{sales_log.id}/purchaser-code?first_remaining_duplicate_id=#{duplicate_logs[0].id}&original_log_id=#{sales_log.id}&referrer=duplicate_logs")
- expect(page).to have_link("Change", href: "/sales-logs/#{duplicate_logs[0].id}/purchaser-code?first_remaining_duplicate_id=#{sales_log.id}&original_log_id=#{sales_log.id}&referrer=duplicate_logs")
- expect(page).to have_link("Change", href: "/sales-logs/#{duplicate_logs[1].id}/purchaser-code?first_remaining_duplicate_id=#{sales_log.id}&original_log_id=#{sales_log.id}&referrer=duplicate_logs")
- end
-
- it "displays buttons to delete" do
- expect(page).to have_link("Keep this log and delete duplicates", count: 3)
- expect(page).to have_link("Keep this log and delete duplicates", href: "/sales-logs/#{sales_log.id}/delete-duplicates?original_log_id=#{sales_log.id}")
- expect(page).to have_link("Keep this log and delete duplicates", href: "/sales-logs/#{duplicate_logs.first.id}/delete-duplicates?original_log_id=#{sales_log.id}")
- expect(page).to have_link("Keep this log and delete duplicates", href: "/sales-logs/#{duplicate_logs.second.id}/delete-duplicates?original_log_id=#{sales_log.id}")
- end
+ context "when user is a data provider" do
+ before do
+ allow(user).to receive(:need_two_factor_authentication?).and_return(false)
+ sign_in user
end
- context "when there are no more duplicate logs" do
- before do
- allow(SalesLog).to receive(:duplicate_logs).and_return(SalesLog.none)
- get "/sales-logs/#{sales_log.id}/duplicate-logs?original_log_id=#{sales_log.id}"
+ context "when viewing lettings logs duplicates" do
+ context "when there are multiple duplicate logs" do
+ let(:duplicate_logs) { create_list(:lettings_log, 2, :completed) }
+
+ before do
+ allow(LettingsLog).to receive(:duplicate_logs).and_return(duplicate_logs)
+ get "/lettings-logs/#{lettings_log.id}/duplicate-logs?original_log_id=#{lettings_log.id}"
+ end
+
+ it "displays links to all the duplicate logs" do
+ expect(page).to have_link("Log #{lettings_log.id}", href: "/lettings-logs/#{lettings_log.id}")
+ expect(page).to have_link("Log #{duplicate_logs.first.id}", href: "/lettings-logs/#{duplicate_logs.first.id}")
+ expect(page).to have_link("Log #{duplicate_logs.second.id}", href: "/lettings-logs/#{duplicate_logs.second.id}")
+ end
+
+ it "displays check your answers for each log with correct questions" do
+ expect(page).to have_content("Q5 - Tenancy start date", count: 3)
+ expect(page).to have_content("Q7 - Tenant code", count: 3)
+ expect(page).to have_content("Q12 - Postcode", count: 3)
+ expect(page).to have_content("Q32 - Lead tenant’s age", count: 3)
+ expect(page).to have_content("Q33 - Lead tenant’s gender identity", count: 3)
+ expect(page).to have_content("Q37 - Lead tenant’s working situation", count: 3)
+ expect(page).to have_content("Household rent and charges", count: 3)
+ expect(page).to have_link("Change", count: 21)
+ expect(page).to have_link("Change", href: "/lettings-logs/#{lettings_log.id}/tenant-code?first_remaining_duplicate_id=#{duplicate_logs[0].id}&original_log_id=#{lettings_log.id}&referrer=duplicate_logs")
+ expect(page).to have_link("Change", href: "/lettings-logs/#{duplicate_logs[0].id}/tenant-code?first_remaining_duplicate_id=#{lettings_log.id}&original_log_id=#{lettings_log.id}&referrer=duplicate_logs")
+ expect(page).to have_link("Change", href: "/lettings-logs/#{duplicate_logs[1].id}/tenant-code?first_remaining_duplicate_id=#{lettings_log.id}&original_log_id=#{lettings_log.id}&referrer=duplicate_logs")
+ end
+
+ it "displays buttons to delete" do
+ expect(page).to have_link("Keep this log and delete duplicates", count: 3)
+ expect(page).to have_link("Keep this log and delete duplicates", href: "/lettings-logs/#{lettings_log.id}/delete-duplicates?original_log_id=#{lettings_log.id}")
+ expect(page).to have_link("Keep this log and delete duplicates", href: "/lettings-logs/#{duplicate_logs.first.id}/delete-duplicates?original_log_id=#{lettings_log.id}")
+ expect(page).to have_link("Keep this log and delete duplicates", href: "/lettings-logs/#{duplicate_logs.second.id}/delete-duplicates?original_log_id=#{lettings_log.id}")
+ end
end
- it "displays check your answers for each log with correct questions" do
- expect(page).to have_content("Q1 - Sale completion date", count: 1)
- expect(page).to have_content("Q2 - Purchaser code", count: 1)
- expect(page).to have_content("Q20 - Lead buyer’s age", count: 1)
- expect(page).to have_content("Q21 - Buyer 1’s gender identity", count: 1)
- expect(page).to have_content("Q25 - Buyer 1's working situation", count: 1)
- expect(page).to have_content("Q15 - Postcode", count: 1)
- expect(page).to have_link("Change", count: 6)
- expect(page).to have_link("Change", href: "/sales-logs/#{sales_log.id}/purchaser-code?original_log_id=#{sales_log.id}&referrer=interruption_screen")
+ context "when there are no more duplicate logs" do
+ context "when accessed from the duplicate logs banner flow" do
+ before do
+ allow(LettingsLog).to receive(:duplicate_logs).and_return(LettingsLog.none)
+ get "/lettings-logs/#{lettings_log.id}/duplicate-logs?original_log_id=#{lettings_log.id}&referrer=duplicate_logs_banner"
+ end
+
+ it "displays check your answers for each log with correct questions" do
+ expect(page).to have_content("Q5 - Tenancy start date", count: 1)
+ expect(page).to have_content("Q7 - Tenant code", count: 1)
+ expect(page).to have_content("Q12 - Postcode", count: 1)
+ expect(page).to have_content("Q32 - Lead tenant’s age", count: 1)
+ expect(page).to have_content("Q33 - Lead tenant’s gender identity", count: 1)
+ expect(page).to have_content("Q37 - Lead tenant’s working situation", count: 1)
+ expect(page).to have_content("Household rent and charges", count: 1)
+ expect(page).to have_link("Change", count: 7)
+ expect(page).to have_link("Change", href: "/lettings-logs/#{lettings_log.id}/tenant-code?original_log_id=#{lettings_log.id}&referrer=interruption_screen")
+ end
+
+ it "displays button to review other duplicates" do
+ expect(page).to have_link("Review other duplicates", href: "/duplicate-logs?referrer=duplicate_logs_banner")
+ end
+
+ it "displays no duplicates banner" do
+ expect(page).to have_content("This log had the same answers but it is no longer a duplicate. Make sure the answers are correct.")
+ end
+ end
+
+ context "when accessed from the single log submission flow" do
+ before do
+ allow(LettingsLog).to receive(:duplicate_logs).and_return(LettingsLog.none)
+ get "/lettings-logs/#{lettings_log.id}/duplicate-logs?original_log_id=#{lettings_log.id}"
+ end
+
+ it "displays check your answers for each log with correct questions" do
+ expect(page).to have_content("Q5 - Tenancy start date", count: 1)
+ expect(page).to have_content("Q7 - Tenant code", count: 1)
+ expect(page).to have_content("Q12 - Postcode", count: 1)
+ expect(page).to have_content("Q32 - Lead tenant’s age", count: 1)
+ expect(page).to have_content("Q33 - Lead tenant’s gender identity", count: 1)
+ expect(page).to have_content("Q37 - Lead tenant’s working situation", count: 1)
+ expect(page).to have_content("Household rent and charges", count: 1)
+ expect(page).to have_link("Change", count: 7)
+ expect(page).to have_link("Change", href: "/lettings-logs/#{lettings_log.id}/tenant-code?original_log_id=#{lettings_log.id}&referrer=interruption_screen")
+ end
+
+ it "displays button to return to log" do
+ expect(page).to have_link("Back to Log #{lettings_log.id}", href: "/lettings-logs/#{lettings_log.id}")
+ end
+
+ it "displays no duplicates banner" do
+ expect(page).to have_content("This log had the same answers but it is no longer a duplicate. Make sure the answers are correct.")
+ end
+ end
end
+ end
- it "displays buttons to return to log" do
- expect(page).to have_link("Back to Log #{sales_log.id}", href: "/sales-logs/#{sales_log.id}")
+ context "when viewing sales logs duplicates" do
+ context "when there are multiple duplicate logs" do
+ let(:duplicate_logs) { create_list(:sales_log, 2, :completed) }
+
+ before do
+ allow(SalesLog).to receive(:duplicate_logs).and_return(duplicate_logs)
+ get "/sales-logs/#{sales_log.id}/duplicate-logs?original_log_id=#{sales_log.id}"
+ end
+
+ it "displays links to all the duplicate logs" do
+ expect(page).to have_link("Log #{sales_log.id}", href: "/sales-logs/#{sales_log.id}")
+ expect(page).to have_link("Log #{duplicate_logs.first.id}", href: "/sales-logs/#{duplicate_logs.first.id}")
+ expect(page).to have_link("Log #{duplicate_logs.second.id}", href: "/sales-logs/#{duplicate_logs.second.id}")
+ end
+
+ it "displays check your answers for each log with correct questions" do
+ expect(page).to have_content("Q1 - Sale completion date", count: 3)
+ expect(page).to have_content("Q2 - Purchaser code", count: 3)
+ expect(page).to have_content("Q20 - Lead buyer’s age", count: 3)
+ expect(page).to have_content("Q21 - Buyer 1’s gender identity", count: 3)
+ expect(page).to have_content("Q25 - Buyer 1's working situation", count: 3)
+ expect(page).to have_content("Q15 - Postcode", count: 3)
+ expect(page).to have_link("Change", count: 18)
+ expect(page).to have_link("Change", href: "/sales-logs/#{sales_log.id}/purchaser-code?first_remaining_duplicate_id=#{duplicate_logs[0].id}&original_log_id=#{sales_log.id}&referrer=duplicate_logs")
+ expect(page).to have_link("Change", href: "/sales-logs/#{duplicate_logs[0].id}/purchaser-code?first_remaining_duplicate_id=#{sales_log.id}&original_log_id=#{sales_log.id}&referrer=duplicate_logs")
+ expect(page).to have_link("Change", href: "/sales-logs/#{duplicate_logs[1].id}/purchaser-code?first_remaining_duplicate_id=#{sales_log.id}&original_log_id=#{sales_log.id}&referrer=duplicate_logs")
+ end
+
+ it "displays buttons to delete" do
+ expect(page).to have_link("Keep this log and delete duplicates", count: 3)
+ expect(page).to have_link("Keep this log and delete duplicates", href: "/sales-logs/#{sales_log.id}/delete-duplicates?original_log_id=#{sales_log.id}")
+ expect(page).to have_link("Keep this log and delete duplicates", href: "/sales-logs/#{duplicate_logs.first.id}/delete-duplicates?original_log_id=#{sales_log.id}")
+ expect(page).to have_link("Keep this log and delete duplicates", href: "/sales-logs/#{duplicate_logs.second.id}/delete-duplicates?original_log_id=#{sales_log.id}")
+ end
end
- it "displays no duplicates banner" do
- expect(page).to have_content("This log had the same answers but it is no longer a duplicate. Make sure the answers are correct.")
+ context "when there are no more duplicate logs" do
+ context "when accessed from the duplicate logs banner flow" do
+ before do
+ allow(SalesLog).to receive(:duplicate_logs).and_return(SalesLog.none)
+ get "/sales-logs/#{sales_log.id}/duplicate-logs?original_log_id=#{sales_log.id}&referrer=duplicate_logs_banner"
+ end
+
+ it "displays check your answers for each log with correct questions" do
+ expect(page).to have_content("Q1 - Sale completion date", count: 1)
+ expect(page).to have_content("Q2 - Purchaser code", count: 1)
+ expect(page).to have_content("Q20 - Lead buyer’s age", count: 1)
+ expect(page).to have_content("Q21 - Buyer 1’s gender identity", count: 1)
+ expect(page).to have_content("Q25 - Buyer 1's working situation", count: 1)
+ expect(page).to have_content("Q15 - Postcode", count: 1)
+ expect(page).to have_link("Change", count: 6)
+ expect(page).to have_link("Change", href: "/sales-logs/#{sales_log.id}/purchaser-code?original_log_id=#{sales_log.id}&referrer=interruption_screen")
+ end
+
+ it "displays button to review other duplicates" do
+ expect(page).to have_link("Review other duplicates", href: "/duplicate-logs?referrer=duplicate_logs_banner")
+ end
+
+ it "displays no duplicates banner" do
+ expect(page).to have_content("This log had the same answers but it is no longer a duplicate. Make sure the answers are correct.")
+ end
+ end
+
+ context "when accessed from the single log submission flow" do
+ before do
+ allow(SalesLog).to receive(:duplicate_logs).and_return(SalesLog.none)
+ get "/sales-logs/#{sales_log.id}/duplicate-logs?original_log_id=#{sales_log.id}"
+ end
+
+ it "displays check your answers for each log with correct questions" do
+ expect(page).to have_content("Q1 - Sale completion date", count: 1)
+ expect(page).to have_content("Q2 - Purchaser code", count: 1)
+ expect(page).to have_content("Q20 - Lead buyer’s age", count: 1)
+ expect(page).to have_content("Q21 - Buyer 1’s gender identity", count: 1)
+ expect(page).to have_content("Q25 - Buyer 1's working situation", count: 1)
+ expect(page).to have_content("Q15 - Postcode", count: 1)
+ expect(page).to have_link("Change", count: 6)
+ expect(page).to have_link("Change", href: "/sales-logs/#{sales_log.id}/purchaser-code?original_log_id=#{sales_log.id}&referrer=interruption_screen")
+ end
+
+ it "displays button to return to log" do
+ expect(page).to have_link("Back to Log #{sales_log.id}", href: "/sales-logs/#{sales_log.id}")
+ end
+
+ it "displays no duplicates banner" do
+ expect(page).to have_content("This log had the same answers but it is no longer a duplicate. Make sure the answers are correct.")
+ end
+ end
end
end
end
end
end
- describe "GET sales delete-duplicates" do
- let(:headers) { { "Accept" => "text/html" } }
- let(:id) { sales_log.id }
- let(:request) { get "/sales-logs/#{id}/delete-duplicates?original_log_id=#{id}" }
+ describe "GET lettings delete-duplicates" do
+ let(:id) { lettings_log.id }
+ let(:request) { get "/lettings-logs/#{id}/delete-duplicates?original_log_id=#{id}" }
before do
allow(user).to receive(:need_two_factor_authentication?).and_return(false)
@@ -175,43 +483,85 @@ RSpec.describe DuplicateLogsController, type: :request do
end
context "when there are no duplicate logs" do
- it "renders not found" do
+ it "renders page not found" do
request
expect(response).to have_http_status(:not_found)
end
end
- context "when there is 1 duplicate log being deleted" do
- let!(:duplicate_log) { create(:sales_log, :duplicate, created_by: user) }
+ context "when accessed from the duplicate logs banner flow" do
+ let(:request) { get "/lettings-logs/#{id}/delete-duplicates?original_log_id=#{id}&referrer=duplicate_logs_banner" }
- it "renders page" do
- request
- expect(response).to have_http_status(:ok)
-
- expect(page).to have_content("Are you sure you want to delete this duplicate log?")
- expect(page).to have_button(text: "Delete this log")
- expect(page).to have_link(text: "Log #{duplicate_log.id}", href: sales_log_path(duplicate_log.id))
- expect(page).not_to have_link(text: "Log #{id}", href: sales_log_path(id))
- expect(page).to have_link(text: "Cancel", href: sales_log_duplicate_logs_path(id, original_log_id: id))
- expect(page).to have_link(text: "Back", href: sales_log_duplicate_logs_path(id, original_log_id: id))
+ context "when there is 1 duplicate log being deleted" do
+ let!(:duplicate_log) { create(:lettings_log, :duplicate, created_by: user) }
+
+ it "renders page with correct link params" do
+ request
+ expect(response).to have_http_status(:ok)
+
+ expect(page).to have_content("Are you sure you want to delete this duplicate log?")
+ expect(page).to have_content("This log will be deleted:")
+ expect(page).to have_button(text: "Delete this log")
+ expect(page).to have_link(text: "Log #{duplicate_log.id}", href: lettings_log_path(duplicate_log.id))
+ expect(page).not_to have_link(text: "Log #{id}", href: lettings_log_path(id))
+ expect(page).to have_link(text: "Cancel", href: lettings_log_duplicate_logs_path(id, original_log_id: id, referrer: "duplicate_logs_banner"))
+ expect(page).to have_link(text: "Back", href: lettings_log_duplicate_logs_path(id, original_log_id: id, referrer: "duplicate_logs_banner"))
+ end
+ end
+
+ context "when there are multiple duplicate logs being deleted" do
+ let!(:duplicate_log) { create(:lettings_log, :duplicate, created_by: user) }
+ let!(:duplicate_log_2) { create(:lettings_log, :duplicate, created_by: user) }
+
+ it "renders page with correct link params" do
+ request
+ expect(response).to have_http_status(:ok)
+
+ expect(page).to have_content("Are you sure you want to delete these duplicate logs?")
+ expect(page).to have_content("These logs will be deleted:")
+ expect(page).to have_button(text: "Delete these logs")
+ expect(page).to have_link(text: "Log #{duplicate_log.id}", href: lettings_log_path(duplicate_log.id))
+ expect(page).to have_link(text: "Log #{duplicate_log_2.id}", href: lettings_log_path(duplicate_log_2.id))
+ expect(page).to have_link(text: "Cancel", href: lettings_log_duplicate_logs_path(id, original_log_id: id, referrer: "duplicate_logs_banner"))
+ expect(page).to have_link(text: "Back", href: lettings_log_duplicate_logs_path(id, original_log_id: id, referrer: "duplicate_logs_banner"))
+ end
end
end
- context "when there are multiple duplicate logs being deleted" do
- let!(:duplicate_log) { create(:sales_log, :duplicate, created_by: user) }
- let!(:duplicate_log_2) { create(:sales_log, :duplicate, created_by: user) }
+ context "when accessed from the single log submission flow" do
+ context "when there is 1 duplicate log being deleted" do
+ let!(:duplicate_log) { create(:lettings_log, :duplicate, created_by: user) }
+
+ it "renders page" do
+ request
+ expect(response).to have_http_status(:ok)
+
+ expect(page).to have_content("Are you sure you want to delete this duplicate log?")
+ expect(page).to have_content("This log will be deleted:")
+ expect(page).to have_button(text: "Delete this log")
+ expect(page).to have_link(text: "Log #{duplicate_log.id}", href: lettings_log_path(duplicate_log.id))
+ expect(page).not_to have_link(text: "Log #{id}", href: lettings_log_path(id))
+ expect(page).to have_link(text: "Cancel", href: lettings_log_duplicate_logs_path(id, original_log_id: id))
+ expect(page).to have_link(text: "Back", href: lettings_log_duplicate_logs_path(id, original_log_id: id))
+ end
+ end
- it "renders page" do
- request
- expect(response).to have_http_status(:ok)
-
- expect(page).to have_content("Are you sure you want to delete these duplicate logs?")
- expect(page).to have_content("These logs will be deleted:")
- expect(page).to have_button(text: "Delete these logs")
- expect(page).to have_link(text: "Log #{duplicate_log.id}", href: sales_log_path(duplicate_log.id))
- expect(page).to have_link(text: "Log #{duplicate_log_2.id}", href: sales_log_path(duplicate_log_2.id))
- expect(page).to have_link(text: "Cancel", href: sales_log_duplicate_logs_path(id, original_log_id: id))
- expect(page).to have_link(text: "Back", href: sales_log_duplicate_logs_path(id, original_log_id: id))
+ context "when there are multiple duplicate logs being deleted" do
+ let!(:duplicate_log) { create(:lettings_log, :duplicate, created_by: user) }
+ let!(:duplicate_log_2) { create(:lettings_log, :duplicate, created_by: user) }
+
+ it "renders page" do
+ request
+ expect(response).to have_http_status(:ok)
+
+ expect(page).to have_content("Are you sure you want to delete these duplicate logs?")
+ expect(page).to have_content("These logs will be deleted:")
+ expect(page).to have_button(text: "Delete these logs")
+ expect(page).to have_link(text: "Log #{duplicate_log.id}", href: lettings_log_path(duplicate_log.id))
+ expect(page).to have_link(text: "Log #{duplicate_log_2.id}", href: lettings_log_path(duplicate_log_2.id))
+ expect(page).to have_link(text: "Cancel", href: lettings_log_duplicate_logs_path(id, original_log_id: id))
+ expect(page).to have_link(text: "Back", href: lettings_log_duplicate_logs_path(id, original_log_id: id))
+ end
end
end
@@ -239,9 +589,10 @@ RSpec.describe DuplicateLogsController, type: :request do
end
end
- describe "GET lettings delete-duplicates" do
- let(:id) { lettings_log.id }
- let(:request) { get "/lettings-logs/#{id}/delete-duplicates?original_log_id=#{id}" }
+ describe "GET sales delete-duplicates" do
+ let(:headers) { { "Accept" => "text/html" } }
+ let(:id) { sales_log.id }
+ let(:request) { get "/sales-logs/#{id}/delete-duplicates?original_log_id=#{id}" }
before do
allow(user).to receive(:need_two_factor_authentication?).and_return(false)
@@ -249,44 +600,85 @@ RSpec.describe DuplicateLogsController, type: :request do
end
context "when there are no duplicate logs" do
- it "renders page not found" do
+ it "renders not found" do
request
expect(response).to have_http_status(:not_found)
end
end
- context "when there is 1 duplicate log being deleted" do
- let!(:duplicate_log) { create(:lettings_log, :duplicate, created_by: user) }
+ context "when accessed from the duplicate logs banner flow" do
+ let(:request) { get "/sales-logs/#{id}/delete-duplicates?original_log_id=#{id}&referrer=duplicate_logs_banner" }
- it "renders page" do
- request
- expect(response).to have_http_status(:ok)
-
- expect(page).to have_content("Are you sure you want to delete this duplicate log?")
- expect(page).to have_content("This log will be deleted:")
- expect(page).to have_button(text: "Delete this log")
- expect(page).to have_link(text: "Log #{duplicate_log.id}", href: lettings_log_path(duplicate_log.id))
- expect(page).not_to have_link(text: "Log #{id}", href: lettings_log_path(id))
- expect(page).to have_link(text: "Cancel", href: lettings_log_duplicate_logs_path(id, original_log_id: id))
- expect(page).to have_link(text: "Back", href: lettings_log_duplicate_logs_path(id, original_log_id: id))
+ context "when there is 1 duplicate log being deleted" do
+ let!(:duplicate_log) { create(:sales_log, :duplicate, created_by: user) }
+
+ it "renders page with correct link params" do
+ request
+ expect(response).to have_http_status(:ok)
+
+ expect(page).to have_content("Are you sure you want to delete this duplicate log?")
+ expect(page).to have_content("This log will be deleted:")
+ expect(page).to have_button(text: "Delete this log")
+ expect(page).to have_link(text: "Log #{duplicate_log.id}", href: sales_log_path(duplicate_log.id))
+ expect(page).not_to have_link(text: "Log #{id}", href: sales_log_path(id))
+ expect(page).to have_link(text: "Cancel", href: sales_log_duplicate_logs_path(id, original_log_id: id, referrer: "duplicate_logs_banner"))
+ expect(page).to have_link(text: "Back", href: sales_log_duplicate_logs_path(id, original_log_id: id, referrer: "duplicate_logs_banner"))
+ end
+ end
+
+ context "when there are multiple duplicate logs being deleted" do
+ let!(:duplicate_log) { create(:sales_log, :duplicate, created_by: user) }
+ let!(:duplicate_log_2) { create(:sales_log, :duplicate, created_by: user) }
+
+ it "renders page with correct link params" do
+ request
+ expect(response).to have_http_status(:ok)
+
+ expect(page).to have_content("Are you sure you want to delete these duplicate logs?")
+ expect(page).to have_content("These logs will be deleted:")
+ expect(page).to have_button(text: "Delete these logs")
+ expect(page).to have_link(text: "Log #{duplicate_log.id}", href: sales_log_path(duplicate_log.id))
+ expect(page).to have_link(text: "Log #{duplicate_log_2.id}", href: sales_log_path(duplicate_log_2.id))
+ expect(page).to have_link(text: "Cancel", href: sales_log_duplicate_logs_path(id, original_log_id: id, referrer: "duplicate_logs_banner"))
+ expect(page).to have_link(text: "Back", href: sales_log_duplicate_logs_path(id, original_log_id: id, referrer: "duplicate_logs_banner"))
+ end
end
end
- context "when there are multiple duplicate logs being deleted" do
- let!(:duplicate_log) { create(:lettings_log, :duplicate, created_by: user) }
- let!(:duplicate_log_2) { create(:lettings_log, :duplicate, created_by: user) }
+ context "when accessed from the single log submission flow" do
+ context "when there is 1 duplicate log being deleted" do
+ let!(:duplicate_log) { create(:sales_log, :duplicate, created_by: user) }
+
+ it "renders page" do
+ request
+ expect(response).to have_http_status(:ok)
+
+ expect(page).to have_content("Are you sure you want to delete this duplicate log?")
+ expect(page).to have_content("This log will be deleted:")
+ expect(page).to have_button(text: "Delete this log")
+ expect(page).to have_link(text: "Log #{duplicate_log.id}", href: sales_log_path(duplicate_log.id))
+ expect(page).not_to have_link(text: "Log #{id}", href: sales_log_path(id))
+ expect(page).to have_link(text: "Cancel", href: sales_log_duplicate_logs_path(id, original_log_id: id))
+ expect(page).to have_link(text: "Back", href: sales_log_duplicate_logs_path(id, original_log_id: id))
+ end
+ end
- it "renders page" do
- request
- expect(response).to have_http_status(:ok)
-
- expect(page).to have_content("Are you sure you want to delete these duplicate logs?")
- expect(page).to have_content("These logs will be deleted:")
- expect(page).to have_button(text: "Delete these logs")
- expect(page).to have_link(text: "Log #{duplicate_log.id}", href: lettings_log_path(duplicate_log.id))
- expect(page).to have_link(text: "Log #{duplicate_log_2.id}", href: lettings_log_path(duplicate_log_2.id))
- expect(page).to have_link(text: "Cancel", href: lettings_log_duplicate_logs_path(id, original_log_id: id))
- expect(page).to have_link(text: "Back", href: lettings_log_duplicate_logs_path(id, original_log_id: id))
+ context "when there are multiple duplicate logs being deleted" do
+ let!(:duplicate_log) { create(:sales_log, :duplicate, created_by: user) }
+ let!(:duplicate_log_2) { create(:sales_log, :duplicate, created_by: user) }
+
+ it "renders page" do
+ request
+ expect(response).to have_http_status(:ok)
+
+ expect(page).to have_content("Are you sure you want to delete these duplicate logs?")
+ expect(page).to have_content("These logs will be deleted:")
+ expect(page).to have_button(text: "Delete these logs")
+ expect(page).to have_link(text: "Log #{duplicate_log.id}", href: sales_log_path(duplicate_log.id))
+ expect(page).to have_link(text: "Log #{duplicate_log_2.id}", href: sales_log_path(duplicate_log_2.id))
+ expect(page).to have_link(text: "Cancel", href: sales_log_duplicate_logs_path(id, original_log_id: id))
+ expect(page).to have_link(text: "Back", href: sales_log_duplicate_logs_path(id, original_log_id: id))
+ end
end
end
@@ -323,9 +715,64 @@ RSpec.describe DuplicateLogsController, type: :request do
context "when the user is support" do
let(:user) { create(:user, :support) }
- it "renders not found" do
- get duplicate_logs_path(organisation_id: user.organisation.id)
- expect(response).to have_http_status(:not_found)
+ 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]])
+ end
+
+ it "gets organisation duplicates" do
+ expect(user.organisation).to receive(:duplicate_lettings_logs_sets)
+ expect(user.organisation).to receive(:duplicate_sales_logs_sets)
+ get organisation_duplicates_path(organisation_id: user.organisation_id)
+ end
+
+ describe "viewing the page" do
+ context "when there are duplicate logs" do
+ before do
+ get organisation_duplicates_path(organisation_id: user.organisation_id)
+ end
+
+ it "has the correct headers" do
+ expect(page).to have_content("Type of logs")
+ expect(page).to have_content("Log IDs")
+ end
+
+ it "has the correct number of rows for each log type" do
+ expect(page).to have_selector("tbody tr td", text: "Lettings", count: 2)
+ expect(page).to have_selector("tbody tr td", text: "Sales", count: 1)
+ end
+
+ it "shows the log ids for each set of duplicates" do
+ expect(page).to have_content("Log 1, Log 2")
+ expect(page).to have_content("Log 3, Log 4, Log 5")
+ expect(page).to have_content("Log 11, Log 12")
+ end
+
+ it "shows links for each set of duplicates" do
+ expect(page).to have_link("Review logs", href: lettings_log_duplicate_logs_path(1, original_log_id: 1, organisation_id: user.organisation_id))
+ expect(page).to have_link("Review logs", href: lettings_log_duplicate_logs_path(3, original_log_id: 3, organisation_id: user.organisation_id))
+ expect(page).to have_link("Review logs", href: sales_log_duplicate_logs_path(11, original_log_id: 11, organisation_id: user.organisation_id))
+ end
+ end
+
+ 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([])
+ get organisation_duplicates_path(organisation_id: user.organisation_id)
+ end
+
+ it "has the correct headers" do
+ expect(page).to have_content("There are no more duplicate logs")
+ expect(page).to have_content("You have either changed or deleted all the duplicate logs.")
+ end
+
+ it "shows back to all logs button" do
+ expect(page).to have_link("Back to all logs", href: lettings_logs_path)
+ end
+ end
end
end
@@ -359,30 +806,49 @@ RSpec.describe DuplicateLogsController, type: :request do
end
describe "viewing the page" do
- before do
- get duplicate_logs_path
- end
+ context "when there are duplicate logs" do
+ before do
+ get duplicate_logs_path
+ end
- it "has the correct headers" do
- expect(page).to have_content("Type of logs")
- expect(page).to have_content("Log IDs")
- end
+ it "has the correct headers" do
+ expect(page).to have_content("Type of logs")
+ expect(page).to have_content("Log IDs")
+ end
- it "has the correct number of rows for each log type" do
- expect(page).to have_selector("tbody tr td", text: "Lettings", count: 2)
- expect(page).to have_selector("tbody tr td", text: "Sales", count: 1)
- end
+ it "has the correct number of rows for each log type" do
+ expect(page).to have_selector("tbody tr td", text: "Lettings", count: 2)
+ expect(page).to have_selector("tbody tr td", text: "Sales", count: 1)
+ end
+
+ it "shows the log ids for each set of duplicates" do
+ expect(page).to have_content("Log 1, Log 2")
+ expect(page).to have_content("Log 3, Log 4, Log 5")
+ expect(page).to have_content("Log 11, Log 12")
+ end
- it "shows the log ids for each set of duplicates" do
- expect(page).to have_content("Log 1, Log 2")
- expect(page).to have_content("Log 3, Log 4, Log 5")
- expect(page).to have_content("Log 11, Log 12")
+ it "shows links for each set of duplicates" do
+ expect(page).to have_link("Review logs", href: lettings_log_duplicate_logs_path(1, original_log_id: 1))
+ expect(page).to have_link("Review logs", href: lettings_log_duplicate_logs_path(3, original_log_id: 3))
+ expect(page).to have_link("Review logs", href: sales_log_duplicate_logs_path(11, original_log_id: 11))
+ end
end
- it "shows links for each set of duplciates" do
- expect(page).to have_link("Review logs", href: lettings_log_duplicate_logs_path(1, original_log_id: 1))
- expect(page).to have_link("Review logs", href: lettings_log_duplicate_logs_path(3, original_log_id: 3))
- expect(page).to have_link("Review logs", href: sales_log_duplicate_logs_path(11, original_log_id: 11))
+ 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([])
+ get duplicate_logs_path
+ end
+
+ it "has the correct headers" do
+ expect(page).to have_content("There are no more duplicate logs")
+ expect(page).to have_content("You have either changed or deleted all the duplicate logs.")
+ end
+
+ it "shows back to all logs button" do
+ expect(page).to have_link("Back to all logs", href: lettings_logs_path)
+ end
end
end
end
diff --git a/spec/requests/lettings_logs_controller_spec.rb b/spec/requests/lettings_logs_controller_spec.rb
index b4701517f..ea9debdc1 100644
--- a/spec/requests/lettings_logs_controller_spec.rb
+++ b/spec/requests/lettings_logs_controller_spec.rb
@@ -774,7 +774,7 @@ RSpec.describe LettingsLogsController, type: :request do
end
it "shows the total log count" do
- expect(CGI.unescape_html(response.body)).to match("
1 total logs")
+ expect(CGI.unescape_html(response.body)).to match("
1 matching logs")
end
it "does not show the pagination links" do
@@ -868,7 +868,7 @@ RSpec.describe LettingsLogsController, type: :request do
end
it "shows the total log count" do
- expect(CGI.unescape_html(response.body)).to match("
26 total logs")
+ expect(CGI.unescape_html(response.body)).to match("
26 matching logs")
end
it "has pagination links" do
diff --git a/spec/requests/locations_controller_spec.rb b/spec/requests/locations_controller_spec.rb
index fd3bd48e5..2570866cf 100644
--- a/spec/requests/locations_controller_spec.rb
+++ b/spec/requests/locations_controller_spec.rb
@@ -274,7 +274,7 @@ RSpec.describe LocationsController, type: :request do
end
it "updates the table caption" do
- expect(page).to have_content("1 location found matching ‘#{search_param}’")
+ expect(page).to have_content("1 location matching search")
end
it "has search in the title" do
@@ -402,7 +402,7 @@ RSpec.describe LocationsController, type: :request do
end
it "updates the table caption" do
- expect(page).to have_content("1 location found matching ‘#{search_param}’")
+ expect(page).to have_content("1 location matching search")
end
it "has search in the title" do
diff --git a/spec/requests/maintenance_controller_spec.rb b/spec/requests/maintenance_controller_spec.rb
new file mode 100644
index 000000000..d900df3c5
--- /dev/null
+++ b/spec/requests/maintenance_controller_spec.rb
@@ -0,0 +1,85 @@
+require "rails_helper"
+
+RSpec.describe MaintenanceController, type: :request do
+ let(:page) { Capybara::Node::Simple.new(response.body) }
+ let(:user) { FactoryBot.create(:user) }
+
+ before do
+ sign_in user
+ end
+
+ describe "when maintenance mode is enabled" do
+ before do
+ allow(FeatureToggle).to receive(:maintenance_mode_enabled?).and_return(true)
+ end
+
+ context "when a user visits a page other than the maintenance page" do
+ before do
+ get "/lettings-logs"
+ end
+
+ it "redirects the user to the maintenance page" do
+ expect(response).to redirect_to(service_unavailable_path)
+ follow_redirect!
+ expect(page).to have_content("Sorry, the service is unavailable")
+ end
+
+ it "the cookie banner is visible" do
+ follow_redirect!
+ expect(page).to have_content("We’d like to use analytics cookies so we can understand how you use the service and make improvements.")
+ end
+ end
+
+ context "when a user visits the maintenance page" do
+ before do
+ get "/service-unavailable"
+ end
+
+ it "keeps the user on the maintenance page" do
+ expect(response).not_to redirect_to(service_unavailable_path)
+ expect(page).to have_content("Sorry, the service is unavailable")
+ end
+
+ it "the cookie banner is visible" do
+ expect(page).to have_content("We’d like to use analytics cookies so we can understand how you use the service and make improvements.")
+ end
+ end
+ end
+
+ describe "when maintenance mode is disabled" do
+ before do
+ allow(FeatureToggle).to receive(:maintenance_mode_enabled?).and_return(false)
+ end
+
+ context "when a user visits a page other than the maintenance page" do
+ before do
+ get "/lettings-logs"
+ end
+
+ it "doesn't redirect the user to the maintenance page" do
+ expect(response).not_to redirect_to(service_unavailable_path)
+ expect(page).to have_content("Create a new lettings log")
+ end
+
+ it "the cookie banner is visible" do
+ expect(page).to have_content("We’d like to use analytics cookies so we can understand how you use the service and make improvements.")
+ end
+ end
+
+ context "when a user visits the maintenance page" do
+ before do
+ get "/service-unavailable"
+ end
+
+ it "redirects the user to the start page" do
+ expect(response).to redirect_to(root_path)
+ end
+
+ it "the cookie banner is visible" do
+ follow_redirect!
+ follow_redirect!
+ expect(page).to have_content("We’d like to use analytics cookies so we can understand how you use the service and make improvements.")
+ end
+ end
+ end
+end
diff --git a/spec/requests/organisation_relationships_controller_spec.rb b/spec/requests/organisation_relationships_controller_spec.rb
index a93e77d76..dcf99efce 100644
--- a/spec/requests/organisation_relationships_controller_spec.rb
+++ b/spec/requests/organisation_relationships_controller_spec.rb
@@ -47,7 +47,7 @@ RSpec.describe OrganisationRelationshipsController, type: :request do
end
it "shows the pagination count" do
- expect(page).to have_content("1 total stock owners")
+ expect(page).to have_content("1 matching stock owners")
end
context "when adding a stock owner" do
@@ -113,7 +113,7 @@ RSpec.describe OrganisationRelationshipsController, type: :request do
end
it "shows the pagination count" do
- expect(page).to have_content("1 total agents")
+ expect(page).to have_content("1 matching agents")
end
end
@@ -285,7 +285,7 @@ RSpec.describe OrganisationRelationshipsController, type: :request do
end
it "shows the pagination count" do
- expect(page).to have_content("1 total stock owners")
+ expect(page).to have_content("1 matching stock owners")
end
end
@@ -421,7 +421,7 @@ RSpec.describe OrganisationRelationshipsController, type: :request do
end
it "shows the pagination count" do
- expect(page).to have_content("1 total agents")
+ expect(page).to have_content("1 matching agents")
end
end
@@ -587,7 +587,7 @@ RSpec.describe OrganisationRelationshipsController, type: :request do
end
it "shows the pagination count" do
- expect(page).to have_content("1 total stock owners")
+ expect(page).to have_content("1 matching stock owners")
end
context "when adding a stock owner" do
@@ -637,7 +637,7 @@ RSpec.describe OrganisationRelationshipsController, type: :request do
end
it "shows the pagination count" do
- expect(page).to have_content("1 total agents")
+ expect(page).to have_content("1 matching agents")
end
it "shows remove link(s)" do
diff --git a/spec/requests/organisations_controller_spec.rb b/spec/requests/organisations_controller_spec.rb
index cbc5a7f49..340f1facf 100644
--- a/spec/requests/organisations_controller_spec.rb
+++ b/spec/requests/organisations_controller_spec.rb
@@ -89,7 +89,7 @@ RSpec.describe OrganisationsController, type: :request do
end
it "updates the table caption" do
- expect(page).to have_content("1 scheme found matching ‘#{search_param}’")
+ expect(page).to have_content("1 scheme matching search")
end
it "has search in the title" do
@@ -171,7 +171,7 @@ RSpec.describe OrganisationsController, type: :request do
end
it "updates the table caption" do
- expect(page).to have_content("1 scheme found matching ‘#{search_param}’")
+ expect(page).to have_content("1 scheme matching search")
end
it "has search in the title" do
@@ -279,6 +279,89 @@ RSpec.describe OrganisationsController, type: :request do
expect(page).to have_content("To report a merge or update your organisation details, ")
expect(page).to have_link("contact the helpdesk", href: "https://dluhcdigital.atlassian.net/servicedesk/customer/portal/6/group/11")
end
+
+ it "does not display merge history if there is none" do
+ expect(page).not_to have_content("View all organisations that were merged into #{organisation.name}")
+ end
+
+ context "when the organisation has absorbed other organisations" do
+ let!(:absorbed_organisation) { create(:organisation, name: "First Absorbed Organisation") }
+ let!(:other_absorbed_organisation) { create(:organisation, name: "Other Absorbed Organisation") }
+ let!(:previously_absorbed_organisation) { create(:organisation, name: "Previously Absorbed Organisation") }
+
+ before do
+ absorbed_organisation.update!(merge_date: Time.zone.local(2023, 4, 3), absorbing_organisation: organisation)
+ other_absorbed_organisation.update!(merge_date: Time.zone.local(2023, 4, 3), absorbing_organisation: organisation)
+ previously_absorbed_organisation.update!(merge_date: Time.zone.local(2023, 4, 2), absorbing_organisation: organisation)
+ get "/organisations/#{organisation.id}/details", headers:, params: {}
+ end
+
+ it "displays separate lists of absorbed organisations" do
+ expect(page).to have_content("View all organisations that were merged into #{organisation.name}")
+ expect(page).to have_content("Merge date: 3 April 2023")
+ expect(page).to have_content("First Absorbed Organisation")
+ expect(page).to have_content("Other Absorbed Organisation")
+ expect(page).to have_content("Previously Absorbed Organisation")
+ expect(page).to have_content("ORG#{absorbed_organisation.id}")
+ expect(page).to have_content("ORG#{other_absorbed_organisation.id}")
+ expect(page).to have_content("Merge date: 2 April 2023")
+ expect(page).to have_content("ORG#{previously_absorbed_organisation.id}")
+ end
+ end
+
+ context "when the organisation has absorbed other organisations during a closed collection period" do
+ let!(:absorbed_organisation) { create(:organisation, name: "First Absorbed Organisation") }
+ let!(:other_absorbed_organisation) { create(:organisation, name: "Other Absorbed Organisation") }
+
+ before do
+ absorbed_organisation.update!(merge_date: Time.zone.local(2021, 4, 3), absorbing_organisation: organisation)
+ other_absorbed_organisation.update!(merge_date: Time.zone.local(2021, 4, 3), absorbing_organisation: organisation)
+ get "/organisations/#{organisation.id}/details", headers:, params: {}
+ end
+
+ it "does not display absorbed organisations" do
+ expect(page).not_to have_content("View all organisations that were merged into #{organisation.name}")
+ expect(page).not_to have_content("Merge date: 3 April 2021")
+ expect(page).not_to have_content("First Absorbed Organisation")
+ expect(page).not_to have_content("Other Absorbed Organisation")
+ end
+ end
+
+ context "when the organisation has absorbed other organisations without merge dates" do
+ let!(:absorbed_organisation) { create(:organisation, name: "First Absorbed Organisation") }
+ let!(:other_absorbed_organisation) { create(:organisation, name: "Other Absorbed Organisation") }
+
+ before do
+ absorbed_organisation.update!(merge_date: Time.zone.local(2023, 4, 3), absorbing_organisation: organisation)
+ other_absorbed_organisation.update!(merge_date: Time.zone.local(2023, 4, 3), absorbing_organisation: organisation)
+ get "/organisations/#{organisation.id}/details", headers:, params: {}
+ end
+
+ it "displays a list of absorbed organisations" do
+ expect(page).to have_content("View all organisations that were merged into #{organisation.name}")
+ expect(page).to have_content("Merge date:")
+ expect(page).to have_content("First Absorbed Organisation")
+ expect(page).to have_content("Other Absorbed Organisation")
+ expect(page).to have_content("ORG#{absorbed_organisation.id}")
+ expect(page).to have_content("ORG#{other_absorbed_organisation.id}")
+ end
+ end
+
+ context "when viewing absorbed organisation" do
+ let(:absorbing_organisation) { create(:organisation, name: "First Absorbing Organisation") }
+
+ context "and your organisation was absorbed" do
+ before do
+ organisation.update!(merge_date: Time.zone.local(2023, 4, 3), absorbing_organisation:)
+ get "/organisations/#{organisation.id}/details", headers:, params: {}
+ end
+
+ it "displays the organisation merge details" do
+ expect(response).not_to have_http_status(:not_found)
+ expect(page).to have_content("#{organisation.name} was merged into First Absorbing Organisation on 3 April 2023.")
+ end
+ end
+ end
end
context "with organisation that are not in scope for the user, i.e. that they do not belong to" do
@@ -332,7 +415,7 @@ RSpec.describe OrganisationsController, type: :request do
end
it "shows the pagination count" do
- expect(page).to have_content("#{user.organisation.users.count} total users")
+ expect(page).to have_content("#{user.organisation.users.count} matching users")
end
end
@@ -716,7 +799,7 @@ RSpec.describe OrganisationsController, type: :request do
total_number_of_orgs = Organisation.all.count
expect(page).to have_link organisation.name, href: "organisations/#{organisation.id}/lettings-logs"
expect(page).to have_link unauthorised_organisation.name, href: "organisations/#{unauthorised_organisation.id}/lettings-logs"
- expect(page).to have_content("#{total_number_of_orgs} total organisations")
+ expect(page).to have_content("#{total_number_of_orgs} matching organisations")
end
it "shows a search bar" do
@@ -745,7 +828,7 @@ RSpec.describe OrganisationsController, type: :request do
end
it "only shows logs for that organisation" do
- expect(page).to have_content("#{total_number_of_org1_logs} total logs")
+ expect(page).to have_content("#{total_number_of_org1_logs} matching logs")
organisation.lettings_logs.visible.map(&:id).each do |lettings_log_id|
expect(page).to have_link lettings_log_id.to_s, href: "/lettings-logs/#{lettings_log_id}"
@@ -784,6 +867,11 @@ RSpec.describe OrganisationsController, type: :request do
expect(page).to have_title("#{organisation.name} (1 logs matching ‘#{log_to_search.id}’) - Submit social housing lettings and sales data (CORE) - GOV.UK")
end
+ it "has search term in the search box" do
+ get "/organisations/#{organisation.id}/lettings-logs?search=#{log_to_search.id}", headers: headers, params: {}
+ expect(page).to have_field("search", with: log_to_search.id.to_s)
+ end
+
it "shows lettings logs matching the id" do
get "/organisations/#{organisation.id}/lettings-logs?search=#{log_to_search.id}", headers: headers, params: {}
expect(page).to have_link(log_to_search.id.to_s)
@@ -894,7 +982,7 @@ RSpec.describe OrganisationsController, type: :request do
end
it "only shows logs for that organisation" do
- expect(page).to have_content("#{number_of_org1_sales_logs} total logs")
+ expect(page).to have_content("#{number_of_org1_sales_logs} matching logs")
organisation.sales_logs.map(&:id).each do |sales_log_id|
expect(page).to have_link sales_log_id.to_s, href: "/sales-logs/#{sales_log_id}"
end
@@ -1028,7 +1116,7 @@ RSpec.describe OrganisationsController, type: :request do
end
it "updates the table caption" do
- expect(page).to have_content("1 user found matching ‘#{search_param}’ of #{org_user_count} total users.")
+ expect(page).to have_content("1 user matching search")
end
context "when we need case insensitive search" do
@@ -1048,7 +1136,7 @@ RSpec.describe OrganisationsController, type: :request do
end
it "updates the table caption" do
- expect(page).to have_content("1 user found matching ‘#{search_param}’ of #{org_user_count} total users.")
+ expect(page).to have_content("1 user matching search")
end
end
end
@@ -1070,13 +1158,13 @@ RSpec.describe OrganisationsController, type: :request do
end
it "updates the table caption" do
- expect(page).to have_content("1 user found matching ‘#{search_param}’ of #{org_user_count} total users.")
+ expect(page).to have_content("1 user matching search")
end
context "when our search term matches an email and a name" do
let!(:matching_user) { create(:user, organisation:, name: "Foobar", email: "some@example.com") }
let!(:another_matching_user) { create(:user, organisation:, name: "Joe", email: "foobar@example.com") }
- let!(:org_user_count) { User.where(organisation:).count }
+ let(:org_user_count) { User.where(organisation:).count }
let(:search_param) { "Foobar" }
before do
@@ -1098,7 +1186,7 @@ RSpec.describe OrganisationsController, type: :request do
end
it "updates the table caption" do
- expect(page).to have_content("2 users found matching ‘#{search_param}’ of #{org_user_count} total users.")
+ expect(page).to have_content("2 users matching search")
end
end
end
@@ -1155,7 +1243,7 @@ RSpec.describe OrganisationsController, type: :request do
end
it "shows the total organisations count" do
- expect(CGI.unescape_html(response.body)).to match("
#{total_organisations_count} total organisations")
+ expect(CGI.unescape_html(response.body)).to match("
#{total_organisations_count} matching organisations")
end
it "has pagination links" do
@@ -1189,7 +1277,7 @@ RSpec.describe OrganisationsController, type: :request do
end
it "updates the table caption" do
- expect(page).to have_content("1 organisations found matching ‘#{search_param}’")
+ expect(page).to have_content("1 organisations matching search")
end
it "has search in the title" do
@@ -1205,7 +1293,7 @@ RSpec.describe OrganisationsController, type: :request do
end
it "updates the table caption" do
- expect(page).to have_content("2 organisations found matching ‘#{search_param}’")
+ expect(page).to have_content("2 organisations matching search")
end
it "has search in the title" do
diff --git a/spec/requests/sales_logs_controller_spec.rb b/spec/requests/sales_logs_controller_spec.rb
index 919f70725..97c5851fd 100644
--- a/spec/requests/sales_logs_controller_spec.rb
+++ b/spec/requests/sales_logs_controller_spec.rb
@@ -655,7 +655,7 @@ RSpec.describe SalesLogsController, type: :request do
end
it "shows the total log count" do
- expect(CGI.unescape_html(response.body)).to match("
1 total logs")
+ expect(CGI.unescape_html(response.body)).to match("
1 matching logs")
end
it "does not show the pagination links" do
@@ -708,7 +708,7 @@ RSpec.describe SalesLogsController, type: :request do
end
it "shows the total log count" do
- expect(CGI.unescape_html(response.body)).to match("
26 total logs")
+ expect(CGI.unescape_html(response.body)).to match("
26 matching logs")
end
it "has pagination links" do
diff --git a/spec/requests/schemes_controller_spec.rb b/spec/requests/schemes_controller_spec.rb
index 33e0dcfd5..9ba00aa43 100644
--- a/spec/requests/schemes_controller_spec.rb
+++ b/spec/requests/schemes_controller_spec.rb
@@ -234,7 +234,7 @@ RSpec.describe SchemesController, type: :request do
end
it "shows the total organisations count" do
- expect(CGI.unescape_html(response.body)).to match("
#{schemes.count} total schemes")
+ expect(CGI.unescape_html(response.body)).to match("
#{schemes.count} matching schemes")
end
context "when paginating over 20 results" do
@@ -250,7 +250,7 @@ RSpec.describe SchemesController, type: :request do
end
it "shows the total schemes count" do
- expect(CGI.unescape_html(response.body)).to match("
#{total_schemes_count} total schemes")
+ expect(CGI.unescape_html(response.body)).to match("
#{total_schemes_count} matching schemes")
end
it "shows which schemes are being shown on the current page" do
@@ -275,7 +275,7 @@ RSpec.describe SchemesController, type: :request do
end
it "shows the total schemes count" do
- expect(CGI.unescape_html(response.body)).to match("
#{total_schemes_count} total schemes")
+ expect(CGI.unescape_html(response.body)).to match("
#{total_schemes_count} matching schemes")
end
it "has pagination links" do
@@ -321,7 +321,7 @@ RSpec.describe SchemesController, type: :request do
end
it "updates the table caption" do
- expect(page).to have_content("1 scheme found matching ‘#{search_param}’")
+ expect(page).to have_content("1 scheme matching search")
end
it "has search in the title" do
diff --git a/spec/requests/users_controller_spec.rb b/spec/requests/users_controller_spec.rb
index f35be6b0e..958f2187a 100644
--- a/spec/requests/users_controller_spec.rb
+++ b/spec/requests/users_controller_spec.rb
@@ -430,7 +430,7 @@ RSpec.describe UsersController, type: :request do
end
it "updates the table caption" do
- expect(page).to have_content("1 user found matching ‘filter’ of 4 total users.")
+ expect(page).to have_content("1 user matching search")
end
end
@@ -466,7 +466,7 @@ RSpec.describe UsersController, type: :request do
end
it "updates the table caption" do
- expect(page).to have_content("2 users found matching ‘joe’ of 4 total users.")
+ expect(page).to have_content("2 users matching search")
end
end
end
@@ -894,6 +894,64 @@ RSpec.describe UsersController, type: :request do
expect(response).to have_http_status(:unprocessable_entity)
end
end
+
+ context "when updating telephone numbers" do
+ let(:params) do
+ {
+ "user": {
+ phone:,
+ },
+ }
+ end
+
+ before do
+ sign_in user
+ patch "/users/#{user.id}", headers:, params:
+ end
+
+ context "when telephone number is not given" do
+ let(:phone) { "" }
+
+ it "validates telephone number" do
+ expect(response).to have_http_status(:unprocessable_entity)
+ expect(page).to have_content(I18n.t("activerecord.errors.models.user.attributes.phone.blank"))
+ end
+ end
+
+ context "when telephone number is not numeric" do
+ let(:phone) { "randomstring" }
+
+ it "validates telephone number" do
+ expect(response).to have_http_status(:unprocessable_entity)
+ expect(page).to have_content(I18n.t("activerecord.errors.models.user.attributes.phone.invalid"))
+ end
+ end
+
+ context "when telephone number is shorter than 11 digits" do
+ let(:phone) { "123" }
+
+ it "validates telephone number" do
+ expect(response).to have_http_status(:unprocessable_entity)
+ expect(page).to have_content(I18n.t("activerecord.errors.models.user.attributes.phone.invalid"))
+ end
+ end
+
+ context "when telephone number is in correct format" do
+ let(:phone) { "012345678919" }
+
+ it "validates telephone number" do
+ expect(page).not_to have_content(I18n.t("activerecord.errors.models.user.attributes.phone.invalid"))
+ end
+ end
+
+ context "when telephone number is in correct format and includes +" do
+ let(:phone) { "+12345678919" }
+
+ it "validates telephone number" do
+ expect(page).not_to have_content(I18n.t("activerecord.errors.models.user.attributes.phone.invalid"))
+ end
+ end
+ end
end
describe "#create" do
@@ -1136,7 +1194,7 @@ RSpec.describe UsersController, type: :request do
end
it "shows the pagination count" do
- expect(page).to have_content("4 total users")
+ expect(page).to have_content("4 matching users")
end
it "shows the download csv link" do
@@ -1164,7 +1222,7 @@ RSpec.describe UsersController, type: :request do
end
it "updates the table caption" do
- expect(page).to have_content("1 user found matching ‘#{search_param}’ of 4 total users.")
+ expect(page).to have_content("1 user matching search")
end
it "includes the search term in the CSV download link" do
@@ -1207,7 +1265,7 @@ RSpec.describe UsersController, type: :request do
end
it "updates the table caption" do
- expect(page).to have_content("2 users found matching ‘joe’ of 4 total users.")
+ expect(page).to have_content("2 users matching search")
end
end
end
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 f699b730a..101a17b3b 100644
--- a/spec/services/bulk_upload/lettings/year2022/row_parser_spec.rb
+++ b/spec/services/bulk_upload/lettings/year2022/row_parser_spec.rb
@@ -269,7 +269,7 @@ RSpec.describe BulkUpload::Lettings::Year2022::RowParser do
context "when a supported housing log already exists in the db" do
let(:scheme) { create(:scheme, :with_old_visible_id, owning_organisation: owning_org) }
let(:location) { create(:location, :with_old_visible_id, scheme:) }
- let(:attributes) { valid_attributes.merge({ field_4: scheme.old_visible_id, field_5: location.old_visible_id, field_111: owning_org.old_visible_id }) }
+ let(:attributes) { valid_attributes.merge({ field_4: scheme.old_visible_id, field_5: location.old_visible_id, field_111: owning_org.old_visible_id, field_113: owning_org.old_visible_id }) }
before do
parser.bulk_upload.needstype = "2"
@@ -639,7 +639,7 @@ RSpec.describe BulkUpload::Lettings::Year2022::RowParser do
end
context "when matching scheme cannot be found" do
- let(:attributes) { { bulk_upload:, field_1: "1", field_4: "123" } }
+ let(:attributes) { { bulk_upload:, field_1: "1", field_4: "123", field_111: owning_org.old_visible_id, field_113: owning_org.old_visible_id } }
it "returns an error" do
expect(parser.errors.where(:field_4, category: :setup)).to be_present
@@ -648,16 +648,16 @@ RSpec.describe BulkUpload::Lettings::Year2022::RowParser do
context "when scheme belongs to someone else" do
let(:other_scheme) { create(:scheme, :with_old_visible_id) }
- let(:attributes) { { bulk_upload:, field_1: "1", field_4: other_scheme.old_visible_id, field_111: owning_org.old_visible_id } }
+ let(:attributes) { { bulk_upload:, field_1: "1", field_4: other_scheme.old_visible_id, field_111: owning_org.old_visible_id, field_113: owning_org.old_visible_id } }
it "returns an error" do
- expect(parser.errors.where(:field_4, category: :setup).map(&:message)).to include("This management group code does not belong to your organisation, or any of your stock owners / managing agents")
+ expect(parser.errors.where(:field_4, category: :setup).map(&:message)).to include("This management group code does not belong to the owning organisation or managing organisation")
end
end
context "when scheme belongs to owning org" do
let(:scheme) { create(:scheme, :with_old_visible_id, owning_organisation: owning_org) }
- let(:attributes) { { bulk_upload:, field_1: "1", field_4: scheme.old_visible_id, field_111: owning_org.old_visible_id } }
+ let(:attributes) { { bulk_upload:, field_1: "1", field_4: scheme.old_visible_id, field_111: owning_org.old_visible_id, field_113: owning_org.old_visible_id } }
it "does not return an error" do
expect(parser.errors[:field_4]).to be_blank
@@ -693,6 +693,7 @@ RSpec.describe BulkUpload::Lettings::Year2022::RowParser do
field_4: scheme.old_visible_id,
field_5: "dontexist",
field_111: owning_org.old_visible_id,
+ field_113: owning_org.old_visible_id,
}
end
@@ -710,6 +711,7 @@ RSpec.describe BulkUpload::Lettings::Year2022::RowParser do
field_4: scheme.old_visible_id,
field_5: location.old_visible_id,
field_111: owning_org.old_visible_id,
+ field_113: owning_org.old_visible_id,
}
end
@@ -719,7 +721,7 @@ RSpec.describe BulkUpload::Lettings::Year2022::RowParser do
end
context "when location exists but not related" do
- let(:location) { create(:scheme, :with_old_visible_id) }
+ let(:location) { create(:location, :with_old_visible_id) }
let(:attributes) do
{
bulk_upload:,
@@ -727,11 +729,12 @@ RSpec.describe BulkUpload::Lettings::Year2022::RowParser do
field_4: scheme.old_visible_id,
field_5: location.old_visible_id,
field_111: owning_org.old_visible_id,
+ field_113: owning_org.old_visible_id,
}
end
it "returns as setup error" do
- expect(parser.errors.where(:field_5, category: :setup).map(&:message)).to eql(["Location could not be found with the provided scheme code"])
+ expect(parser.errors.where(:field_5, category: :setup).map(&:message)).to eql(["Scheme code must relate to a scheme that is owned by the owning organisation or managing organisation"])
end
end
end
@@ -880,7 +883,7 @@ RSpec.describe BulkUpload::Lettings::Year2022::RowParser do
describe "#field_78" do # referral
context "when 3 ie PRP nominated by LA and owning org is LA" do
- let(:attributes) { { bulk_upload:, field_78: "3", field_111: owning_org.old_visible_id } }
+ let(:attributes) { { bulk_upload:, field_78: "3", field_111: owning_org.old_visible_id, field_113: owning_org.old_visible_id } }
it "is not permitted" do
expect(parser.errors[:field_78]).to be_present
@@ -888,7 +891,7 @@ RSpec.describe BulkUpload::Lettings::Year2022::RowParser do
end
context "when 4 ie referred by LA and is general needs and owning org is LA" do
- let(:attributes) { { bulk_upload:, field_78: "4", field_111: owning_org.old_visible_id.to_s } }
+ let(:attributes) { { bulk_upload:, field_78: "4", field_111: owning_org.old_visible_id, field_113: owning_org.old_visible_id } }
it "is not permitted" do
expect(parser.errors[:field_78]).to be_present
@@ -898,7 +901,7 @@ RSpec.describe BulkUpload::Lettings::Year2022::RowParser do
context "when 4 ie referred by LA and is general needs and owning org is PRP" do
let(:owning_org) { create(:organisation, :prp, :with_old_visible_id) }
- let(:attributes) { { bulk_upload:, field_78: "4", field_111: owning_org.old_visible_id.to_s } }
+ let(:attributes) { { bulk_upload:, field_78: "4", field_111: owning_org.old_visible_id, field_113: owning_org.old_visible_id } }
it "is permitted" do
expect(parser.errors[:field_78]).to be_blank
@@ -1125,6 +1128,16 @@ RSpec.describe BulkUpload::Lettings::Year2022::RowParser do
end
end
+ context "when email matches other than casing" do
+ let(:other_user) { create(:user, organisation: owning_org) }
+
+ let(:attributes) { { bulk_upload:, field_111: owning_org.old_visible_id, field_112: other_user.email.upcase!, field_113: managing_org.old_visible_id } }
+
+ it "is permitted" do
+ expect(parser.errors[:field_112]).to be_blank
+ end
+ end
+
context "when an user part of managing org" do
let(:other_user) { create(:user, organisation: managing_org) }
@@ -1364,21 +1377,89 @@ RSpec.describe BulkUpload::Lettings::Year2022::RowParser do
describe "#location" do
context "when lookup is via new core id" do
- let(:attributes) { { bulk_upload:, field_4: scheme.old_visible_id, field_5: location.id, field_111: owning_org } }
+ let(:attributes) { { bulk_upload:, field_4: "S#{scheme.id}", field_5: location.id, field_111: "ORG#{owning_org.id}", field_113: "ORG#{owning_org.id}" } }
it "assigns the correct location" do
expect(parser.log.location).to eql(location)
end
end
+
+ context "when lookup is via old core id" do
+ let(:attributes) { { bulk_upload:, field_4: scheme.old_visible_id, field_5: location.old_visible_id, field_111: owning_org.old_visible_id, field_113: owning_org.old_visible_id } }
+
+ it "assigns the correct location" do
+ expect(parser.log.location).to eql(location)
+ end
+
+ context "when location had leading zeroes in its id in Old CORE" do
+ let(:attributes) { { bulk_upload:, field_4: scheme.old_visible_id, field_5: "123", field_111: owning_org.old_visible_id, field_113: owning_org.old_visible_id } }
+
+ before do
+ location.old_visible_id = "00123"
+ location.save!
+ end
+
+ it "assigns the correct location" do
+ expect(parser.log.location).to eql(location)
+ end
+ end
+
+ context "when the user provides an id with leading zeroes" do
+ let(:attributes) { { bulk_upload:, field_4: scheme.old_visible_id, field_5: "00123", field_111: owning_org.old_visible_id, field_113: owning_org.old_visible_id } }
+
+ before do
+ location.old_visible_id = "123"
+ location.save!
+ end
+
+ it "assigns the correct location" do
+ expect(parser.log.location).to eql(location)
+ end
+ end
+ end
end
describe "#scheme" do
- context "when lookup is via id prefixed with S" do
- let(:attributes) { { bulk_upload:, field_4: "S#{scheme.id}", field_111: owning_org } }
+ context "when lookup is via new core id" do
+ let(:attributes) { { bulk_upload:, field_4: "S#{scheme.id}", field_5: location.id, field_113: "ORG#{owning_org.id}", field_111: "ORG#{owning_org.id}" } }
+
+ it "assigns the correct scheme" do
+ expect(parser.log.scheme).to eql(scheme)
+ end
+ end
+
+ context "when lookup is via old core id" do
+ let(:attributes) { { bulk_upload:, field_4: scheme.old_visible_id, field_5: location.old_visible_id, field_111: owning_org.old_visible_id, field_113: owning_org.old_visible_id } }
it "assigns the correct scheme" do
expect(parser.log.scheme).to eql(scheme)
end
+
+ context "when scheme had leading zeroes in its id in Old CORE" do
+ let(:attributes) { { bulk_upload:, field_4: "10", field_5: location.old_visible_id, field_111: owning_org.old_visible_id, field_113: owning_org.old_visible_id } }
+
+ before do
+ scheme.old_visible_id = "010"
+ scheme.save!
+ end
+
+ it "assigns the correct scheme" do
+ expect(parser.log.scheme).to eql(scheme)
+ end
+ end
+
+ context "when the user provides an id with leading zeroes" do
+ let(:attributes) { { bulk_upload:, field_4: "010", field_5: location.old_visible_id, field_111: owning_org.old_visible_id, field_113: owning_org.old_visible_id } }
+
+ before do
+ scheme.old_visible_id = "10"
+ scheme.save!
+ end
+
+ it "assigns the correct scheme" do
+ expect(parser.log.scheme).to eql(scheme)
+ end
+ end
end
end
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 6959dff29..f24fa5010 100644
--- a/spec/services/bulk_upload/lettings/year2023/row_parser_spec.rb
+++ b/spec/services/bulk_upload/lettings/year2023/row_parser_spec.rb
@@ -753,6 +753,16 @@ RSpec.describe BulkUpload::Lettings::Year2023::RowParser do
end
end
+ context "when email matches other than casing" do
+ let(:other_user) { create(:user, organisation: owning_org) }
+
+ let(:attributes) { { bulk_upload:, field_1: owning_org.old_visible_id, field_3: other_user.email.upcase!, field_2: managing_org.old_visible_id } }
+
+ it "is permitted" do
+ expect(parser.errors[:field_3]).to be_blank
+ end
+ end
+
context "when an user part of managing org" do
let(:other_user) { create(:user, organisation: managing_org) }
@@ -862,17 +872,17 @@ RSpec.describe BulkUpload::Lettings::Year2023::RowParser do
let(:location) { create(:location, :with_old_visible_id, scheme:) }
context "when matching scheme cannot be found" do
- let(:attributes) { { bulk_upload:, field_1: owning_org.old_visible_id, field_4: "2", field_5: "2", field_16: "S123", field_17: location.id } }
+ let(:attributes) { { bulk_upload:, field_1: owning_org.old_visible_id, field_2: owning_org.old_visible_id, field_4: "2", field_5: "2", field_16: "S123", field_17: location.id } }
it "returns a setup error" do
expect(parser.errors[:field_15]).to be_blank
- expect(parser.errors.where(:field_16, category: :setup).map(&:message)).to eq(["The scheme code is not correct"])
+ expect(parser.errors.where(:field_16, category: :setup).map(&:message)).to eq(["This scheme code does not belong to the owning organisation or managing organisation"])
expect(parser.errors[:field_17]).to be_blank
end
end
context "when missing location" do
- let(:attributes) { { bulk_upload:, field_1: owning_org.old_visible_id, field_4: "2", field_5: "2", field_16: "S#{scheme.id}", field_17: nil } }
+ let(:attributes) { { bulk_upload:, field_1: owning_org.old_visible_id, field_2: owning_org.old_visible_id, field_4: "2", field_5: "2", field_16: "S#{scheme.id}", field_17: nil } }
it "returns a setup error" do
expect(parser.errors[:field_15]).to be_blank
@@ -882,17 +892,17 @@ RSpec.describe BulkUpload::Lettings::Year2023::RowParser do
end
context "when matching location cannot be found" do
- let(:attributes) { { bulk_upload:, field_1: owning_org.old_visible_id, field_4: "2", field_5: "2", field_16: "S#{scheme.id}", field_17: "123" } }
+ let(:attributes) { { bulk_upload:, field_1: owning_org.old_visible_id, field_2: owning_org.old_visible_id, field_4: "2", field_5: "2", field_16: "S#{scheme.id}", field_17: "123" } }
it "returns a setup error" do
expect(parser.errors[:field_15]).to be_blank
expect(parser.errors[:field_16]).to be_blank
- expect(parser.errors.where(:field_17, category: :setup).map(&:message)).to eq(["Location could not be found with the provided scheme code"])
+ expect(parser.errors.where(:field_17, category: :setup).map(&:message)).to eq(["Location code must relate to a location that is owned by the owning organisation or managing organisation"])
end
end
context "when matching location exists" do
- let(:attributes) { { bulk_upload:, field_1: owning_org.old_visible_id, field_4: "2", field_5: "2", field_16: "S#{scheme.id}", field_17: location.id } }
+ let(:attributes) { { bulk_upload:, field_1: owning_org.old_visible_id, field_2: owning_org.old_visible_id, field_4: "2", field_5: "2", field_16: "S#{scheme.id}", field_17: location.id } }
it "does not return an error" do
expect(parser.errors[:field_15]).to be_blank
@@ -904,29 +914,29 @@ RSpec.describe BulkUpload::Lettings::Year2023::RowParser do
context "when location exists but not related" do
let(:other_scheme) { create(:scheme, :with_old_visible_id) }
let(:other_location) { create(:location, :with_old_visible_id, scheme: other_scheme) }
- let(:attributes) { { bulk_upload:, field_1: owning_org.old_visible_id, field_4: "2", field_5: "2", field_16: "S#{scheme.id}", field_17: other_location.id } }
+ let(:attributes) { { bulk_upload:, field_1: owning_org.old_visible_id, field_2: owning_org.old_visible_id, field_4: "2", field_5: "2", field_16: "S#{scheme.id}", field_17: other_location.id } }
it "returns a setup error" do
expect(parser.errors[:field_15]).to be_blank
expect(parser.errors[:field_16]).to be_blank
- expect(parser.errors.where(:field_17, category: :setup).map(&:message)).to eq(["Location could not be found with the provided scheme code"])
+ expect(parser.errors.where(:field_17, category: :setup).map(&:message)).to eq(["Location code must relate to a location that is owned by the owning organisation or managing organisation"])
end
end
context "when scheme belongs to someone else" do
let(:other_scheme) { create(:scheme, :with_old_visible_id) }
let(:other_location) { create(:location, :with_old_visible_id, scheme: other_scheme) }
- let(:attributes) { { bulk_upload:, field_4: "2", field_5: "2", field_16: "S#{other_scheme.id}", field_17: other_location.id, field_1: owning_org.old_visible_id } }
+ let(:attributes) { { bulk_upload:, field_4: "2", field_5: "2", field_16: "S#{other_scheme.id}", field_17: other_location.id, field_1: owning_org.old_visible_id, field_2: owning_org.old_visible_id } }
it "returns a setup error" do
expect(parser.errors[:field_15]).to be_blank
- expect(parser.errors.where(:field_16, category: :setup).map(&:message)).to eq(["This scheme code does not belong to your organisation, or any of your stock owners / managing agents"])
+ expect(parser.errors.where(:field_16, category: :setup).map(&:message)).to eq(["This scheme code does not belong to the owning organisation or managing organisation"])
expect(parser.errors[:field_17]).to be_blank
end
end
context "when scheme belongs to owning org" do
- let(:attributes) { { bulk_upload:, field_4: "2", field_5: "2", field_16: "S#{scheme.id}", field_17: location.id, field_1: owning_org.old_visible_id } }
+ let(:attributes) { { bulk_upload:, field_4: "2", field_5: "2", field_16: "S#{scheme.id}", field_17: location.id, field_1: owning_org.old_visible_id, field_2: owning_org.old_visible_id } }
it "does not return an error" do
expect(parser.errors[:field_15]).to be_blank
@@ -953,17 +963,17 @@ RSpec.describe BulkUpload::Lettings::Year2023::RowParser do
let(:location) { create(:location, :with_old_visible_id, scheme:) }
context "when matching scheme cannot be found" do
- let(:attributes) { { bulk_upload:, field_1: owning_org.old_visible_id, field_4: "2", field_5: "2", field_15: "123", field_16: location.old_visible_id } }
+ let(:attributes) { { bulk_upload:, field_1: owning_org.old_visible_id, field_2: owning_org.old_visible_id, field_4: "2", field_5: "2", field_15: "123", field_16: location.old_visible_id } }
it "returns a setup error" do
- expect(parser.errors.where(:field_15, category: :setup).map(&:message)).to eq(["The management group code is not correct"])
+ expect(parser.errors.where(:field_15, category: :setup).map(&:message)).to eq(["This management group code does not belong to the owning organisation or managing organisation"])
expect(parser.errors[:field_16]).to be_blank
expect(parser.errors[:field_17]).to be_blank
end
end
context "when missing location" do
- let(:attributes) { { bulk_upload:, field_1: owning_org.old_visible_id, field_4: "2", field_5: "2", field_15: scheme.old_visible_id, field_16: nil } }
+ let(:attributes) { { bulk_upload:, field_1: owning_org.old_visible_id, field_2: owning_org.old_visible_id, field_4: "2", field_5: "2", field_15: scheme.old_visible_id, field_16: nil } }
it "returns a setup error" do
expect(parser.errors[:field_15]).to be_blank
@@ -973,17 +983,17 @@ RSpec.describe BulkUpload::Lettings::Year2023::RowParser do
end
context "when matching location cannot be found" do
- let(:attributes) { { bulk_upload:, field_1: owning_org.old_visible_id, field_4: "2", field_5: "2", field_15: scheme.old_visible_id, field_16: "123" } }
+ let(:attributes) { { bulk_upload:, field_1: owning_org.old_visible_id, field_2: owning_org.old_visible_id, field_4: "2", field_5: "2", field_15: scheme.old_visible_id, field_16: "123" } }
it "returns a setup error" do
expect(parser.errors[:field_15]).to be_blank
- expect(parser.errors.where(:field_16, category: :setup).map(&:message)).to eq(["Scheme could not be found with the provided management group code"])
+ expect(parser.errors.where(:field_16, category: :setup).map(&:message)).to eq(["Scheme code must relate to a scheme that is owned by the owning organisation or managing organisation"])
expect(parser.errors[:field_17]).to be_blank
end
end
context "when matching location exists" do
- let(:attributes) { { bulk_upload:, field_1: owning_org.old_visible_id, field_4: "2", field_5: "2", field_15: scheme.old_visible_id, field_16: location.old_visible_id } }
+ let(:attributes) { { bulk_upload:, field_1: owning_org.old_visible_id, field_2: owning_org.old_visible_id, field_4: "2", field_5: "2", field_15: scheme.old_visible_id, field_16: location.old_visible_id } }
it "does not return an error" do
expect(parser.errors[:field_15]).to be_blank
@@ -995,11 +1005,11 @@ RSpec.describe BulkUpload::Lettings::Year2023::RowParser do
context "when location exists but not related" do
let(:other_scheme) { create(:scheme, :with_old_visible_id) }
let(:other_location) { create(:location, :with_old_visible_id, scheme: other_scheme) }
- let(:attributes) { { bulk_upload:, field_1: owning_org.old_visible_id, field_4: "2", field_5: "2", field_15: scheme.old_visible_id, field_16: other_location.old_visible_id } }
+ let(:attributes) { { bulk_upload:, field_1: owning_org.old_visible_id, field_2: owning_org.old_visible_id, field_4: "2", field_5: "2", field_15: scheme.old_visible_id, field_16: other_location.old_visible_id } }
it "returns a setup error" do
expect(parser.errors[:field_15]).to be_blank
- expect(parser.errors.where(:field_16, category: :setup).map(&:message)).to eq(["Scheme could not be found with the provided management group code"])
+ expect(parser.errors.where(:field_16, category: :setup).map(&:message)).to eq(["Scheme code must relate to a scheme that is owned by the owning organisation or managing organisation"])
expect(parser.errors[:field_17]).to be_blank
end
end
@@ -1007,17 +1017,17 @@ RSpec.describe BulkUpload::Lettings::Year2023::RowParser do
context "when scheme belongs to someone else" do
let(:other_scheme) { create(:scheme, :with_old_visible_id) }
let(:other_location) { create(:location, :with_old_visible_id, scheme: other_scheme) }
- let(:attributes) { { bulk_upload:, field_4: "2", field_5: "2", field_15: other_scheme.old_visible_id, field_16: other_location.old_visible_id, field_1: owning_org.old_visible_id } }
+ let(:attributes) { { bulk_upload:, field_4: "2", field_5: "2", field_15: other_scheme.old_visible_id, field_16: other_location.old_visible_id, field_1: owning_org.old_visible_id, field_2: owning_org.old_visible_id } }
it "returns a setup error" do
- expect(parser.errors.where(:field_15, category: :setup).map(&:message)).to eq(["This management group code does not belong to your organisation, or any of your stock owners / managing agents"])
+ expect(parser.errors.where(:field_15, category: :setup).map(&:message)).to eq(["This management group code does not belong to the owning organisation or managing organisation"])
expect(parser.errors[:field_16]).to be_blank
expect(parser.errors[:field_17]).to be_blank
end
end
context "when scheme belongs to owning org" do
- let(:attributes) { { bulk_upload:, field_4: "2", field_5: "2", field_15: scheme.old_visible_id, field_16: location.old_visible_id, field_1: owning_org.old_visible_id } }
+ let(:attributes) { { bulk_upload:, field_4: "2", field_5: "2", field_15: scheme.old_visible_id, field_16: location.old_visible_id, field_1: owning_org.old_visible_id, field_2: owning_org.old_visible_id } }
it "does not return an error" do
expect(parser.errors[:field_15]).to be_blank
@@ -1204,7 +1214,7 @@ RSpec.describe BulkUpload::Lettings::Year2023::RowParser do
describe "#field_119" do # referral
context "when 3 ie PRP nominated by LA and owning org is LA" do
- let(:attributes) { { bulk_upload:, field_119: "3", field_1: owning_org.old_visible_id } }
+ let(:attributes) { { bulk_upload:, field_119: "3", field_1: owning_org.old_visible_id, field_2: owning_org.old_visible_id } }
it "is not permitted" do
expect(parser.errors[:field_119]).to be_present
@@ -1212,7 +1222,7 @@ RSpec.describe BulkUpload::Lettings::Year2023::RowParser do
end
context "when 4 ie referred by LA and is general needs and owning org is LA" do
- let(:attributes) { { bulk_upload:, field_119: "4", field_1: owning_org.old_visible_id.to_s, field_4: "1" } }
+ let(:attributes) { { bulk_upload:, field_119: "4", field_1: owning_org.old_visible_id, field_2: owning_org.old_visible_id, field_4: "1" } }
it "is not permitted" do
expect(parser.errors[:field_119]).to be_present
@@ -1222,7 +1232,7 @@ RSpec.describe BulkUpload::Lettings::Year2023::RowParser do
context "when 4 ie referred by LA and is general needs and owning org is PRP" do
let(:owning_org) { create(:organisation, :prp, :with_old_visible_id) }
- let(:attributes) { { bulk_upload:, field_119: "4", field_1: owning_org.old_visible_id.to_s } }
+ let(:attributes) { { bulk_upload:, field_119: "4", field_1: owning_org.old_visible_id, field_2: owning_org.old_visible_id } }
it "is permitted" do
expect(parser.errors[:field_119]).to be_blank
@@ -1327,7 +1337,7 @@ RSpec.describe BulkUpload::Lettings::Year2023::RowParser do
context "when org is not stock owning" do
let(:owning_org) { create(:organisation, :with_old_visible_id, :does_not_own_stock) }
- let(:attributes) { { bulk_upload:, field_1: owning_org.old_visible_id } }
+ let(:attributes) { { bulk_upload:, field_1: owning_org.old_visible_id, field_2: owning_org.old_visible_id } }
it "is not permitted as setup error" do
setup_errors = parser.errors.select { |e| e.options[:category] == :setup }
@@ -1415,7 +1425,7 @@ RSpec.describe BulkUpload::Lettings::Year2023::RowParser do
describe "#field_6" do # renewal
context "when blank" do
- let(:attributes) { { bulk_upload:, field_1: owning_org.old_visible_id, field_6: "" } }
+ let(:attributes) { { bulk_upload:, field_1: owning_org.old_visible_id, field_2: owning_org.old_visible_id, field_6: "" } }
it "has setup errors on the field" do
expect(parser.errors.where(:field_6, category: :setup).map(&:message)).to eql(["You must answer property renewal"])
@@ -1455,6 +1465,24 @@ RSpec.describe BulkUpload::Lettings::Year2023::RowParser do
end
end
+ context "when neither UPRN nor address fields are given for a supported housing record" do
+ let(:bulk_upload) { create(:bulk_upload, :lettings, user:, needstype: 2) }
+ let(:attributes) do
+ { bulk_upload:,
+ field_15: scheme.old_visible_id,
+ field_4: "2",
+ field_5: "2",
+ field_16: location.old_visible_id,
+ field_1: "1" }
+ end
+
+ it "does not add UPRN errors" do
+ expect(parser.errors[:field_18]).to be_empty
+ expect(parser.errors[:field_19]).to be_empty
+ expect(parser.errors[:field_21]).to be_empty
+ end
+ end
+
context "when UPRN is given but address fields are not" do
let(:attributes) do
{
@@ -1692,7 +1720,7 @@ RSpec.describe BulkUpload::Lettings::Year2023::RowParser do
describe "#location" do
context "when lookup is via new core id" do
- let(:attributes) { { bulk_upload:, field_16: "S#{scheme.id}", field_17: location.id, field_1: owning_org } }
+ let(:attributes) { { bulk_upload:, field_16: "S#{scheme.id}", field_17: location.id, field_1: "ORG#{owning_org.id}", field_2: "ORG#{owning_org.id}" } }
it "assigns the correct location" do
expect(parser.log.location).to eql(location)
@@ -1700,17 +1728,43 @@ RSpec.describe BulkUpload::Lettings::Year2023::RowParser do
end
context "when lookup is via old core id" do
- let(:attributes) { { bulk_upload:, field_15: scheme.old_visible_id, field_16: location.old_visible_id, field_1: owning_org } }
+ let(:attributes) { { bulk_upload:, field_15: scheme.old_visible_id, field_16: location.old_visible_id, field_1: owning_org.old_visible_id, field_2: owning_org.old_visible_id } }
it "assigns the correct location" do
expect(parser.log.location).to eql(location)
end
+
+ context "when location had leading zeroes in its id in Old CORE" do
+ let(:attributes) { { bulk_upload:, field_15: scheme.old_visible_id, field_16: "123", field_1: owning_org.old_visible_id, field_2: owning_org.old_visible_id } }
+
+ before do
+ location.old_visible_id = "00123"
+ location.save!
+ end
+
+ it "assigns the correct location" do
+ expect(parser.log.location).to eql(location)
+ end
+ end
+
+ context "when the user provides an id with leading zeroes" do
+ let(:attributes) { { bulk_upload:, field_15: scheme.old_visible_id, field_16: "00123", field_1: owning_org.old_visible_id, field_2: owning_org.old_visible_id } }
+
+ before do
+ location.old_visible_id = "123"
+ location.save!
+ end
+
+ it "assigns the correct location" do
+ expect(parser.log.location).to eql(location)
+ end
+ end
end
end
describe "#scheme" do
context "when lookup is via new core id" do
- let(:attributes) { { bulk_upload:, field_16: "S#{scheme.id}", field_1: owning_org } }
+ let(:attributes) { { bulk_upload:, field_16: "S#{scheme.id}", field_1: "ORG#{owning_org.id}", field_2: "ORG#{owning_org.id}" } }
it "assigns the correct scheme" do
expect(parser.log.scheme).to eql(scheme)
@@ -1718,11 +1772,37 @@ RSpec.describe BulkUpload::Lettings::Year2023::RowParser do
end
context "when lookup is via old core id" do
- let(:attributes) { { bulk_upload:, field_15: scheme.old_visible_id, field_16: location.old_visible_id, field_1: owning_org } }
+ let(:attributes) { { bulk_upload:, field_15: scheme.old_visible_id, field_16: location.old_visible_id, field_1: owning_org.old_visible_id, field_2: owning_org.old_visible_id } }
it "assigns the correct scheme" do
expect(parser.log.scheme).to eql(scheme)
end
+
+ context "when scheme had leading zeroes in its id in Old CORE" do
+ let(:attributes) { { bulk_upload:, field_15: "10", field_16: location.old_visible_id, field_1: owning_org.old_visible_id, field_2: owning_org.old_visible_id } }
+
+ before do
+ scheme.old_visible_id = "010"
+ scheme.save!
+ end
+
+ it "assigns the correct scheme" do
+ expect(parser.log.scheme).to eql(scheme)
+ end
+ end
+
+ context "when the user provides an id with leading zeroes" do
+ let(:attributes) { { bulk_upload:, field_15: "010", field_16: location.old_visible_id, field_1: owning_org.old_visible_id, field_2: owning_org.old_visible_id } }
+
+ before do
+ scheme.old_visible_id = "10"
+ scheme.save!
+ end
+
+ it "assigns the correct scheme" do
+ expect(parser.log.scheme).to eql(scheme)
+ end
+ end
end
end
diff --git a/spec/services/bulk_upload/sales/year2022/row_parser_spec.rb b/spec/services/bulk_upload/sales/year2022/row_parser_spec.rb
index 3b18333df..c305c67ed 100644
--- a/spec/services/bulk_upload/sales/year2022/row_parser_spec.rb
+++ b/spec/services/bulk_upload/sales/year2022/row_parser_spec.rb
@@ -510,6 +510,16 @@ RSpec.describe BulkUpload::Sales::Year2022::RowParser do
expect(parser.errors[:field_93]).to be_blank
end
end
+
+ context "when email matches other than casing" do
+ let(:other_user) { create(:user, organisation: owning_org) }
+
+ let(:attributes) { { bulk_upload:, field_92: owning_org.old_visible_id, field_93: other_user.email.upcase! } }
+
+ it "is permitted" do
+ expect(parser.errors[:field_93]).to be_blank
+ end
+ end
end
[
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 e1137ea84..2e38e4f2c 100644
--- a/spec/services/bulk_upload/sales/year2023/row_parser_spec.rb
+++ b/spec/services/bulk_upload/sales/year2023/row_parser_spec.rb
@@ -459,6 +459,16 @@ RSpec.describe BulkUpload::Sales::Year2023::RowParser do
expect(parser.errors[:field_2]).to be_blank
end
end
+
+ context "when email matches other than casing" do
+ let(:other_user) { create(:user, organisation: owning_org) }
+
+ let(:attributes) { { bulk_upload:, field_1: owning_org.old_visible_id, field_2: other_user.email.upcase! } }
+
+ it "is permitted" do
+ expect(parser.errors[:field_2]).to be_blank
+ end
+ end
end
describe "fields 3, 4, 5 => saledate" do
diff --git a/spec/services/imports/scheme_location_import_service_spec.rb b/spec/services/imports/scheme_location_import_service_spec.rb
index f0cbde6fe..603e572d1 100644
--- a/spec/services/imports/scheme_location_import_service_spec.rb
+++ b/spec/services/imports/scheme_location_import_service_spec.rb
@@ -229,6 +229,15 @@ RSpec.describe Imports::SchemeLocationImportService do
end
end
+ context "and support_type is floating support" do
+ before { location_xml.at_xpath("//scheme:support-type").content = "6" }
+
+ it "correctly sets the support type" do
+ location = location_service.create_scheme_location(location_xml)
+ expect(location.scheme.support_type).to eq("Floating support")
+ end
+ end
+
context "and postcode does not return a location code" do
before { location_xml.at_xpath("//scheme:postcode").content = "A1 1AA" }
diff --git a/spec/services/merge/merge_organisations_service_spec.rb b/spec/services/merge/merge_organisations_service_spec.rb
index 2c2af0f3e..ad15975ad 100644
--- a/spec/services/merge/merge_organisations_service_spec.rb
+++ b/spec/services/merge/merge_organisations_service_spec.rb
@@ -1,13 +1,13 @@
require "rails_helper"
RSpec.describe Merge::MergeOrganisationsService do
- subject(:merge_organisations_service) { described_class.new(absorbing_organisation_id: absorbing_organisation.id, merging_organisation_ids: [merging_organisation_ids]) }
-
- let(:absorbing_organisation) { create(:organisation, holds_own_stock: false) }
- let(:absorbing_organisation_user) { create(:user, organisation: absorbing_organisation) }
-
describe "#call" do
context "when merging a single organisation into an existing organisation" do
+ subject(:merge_organisations_service) { described_class.new(absorbing_organisation_id: absorbing_organisation.id, merging_organisation_ids: [merging_organisation_ids], merge_date: nil) }
+
+ let(:absorbing_organisation) { create(:organisation, holds_own_stock: false) }
+ let(:absorbing_organisation_user) { create(:user, organisation: absorbing_organisation) }
+
let(:merging_organisation) { create(:organisation, holds_own_stock: true, name: "fake org") }
let(:merging_organisation_ids) { [merging_organisation.id] }
@@ -54,6 +54,13 @@ RSpec.describe Merge::MergeOrganisationsService do
expect(merging_organisation_user.organisation).to eq(merging_organisation)
end
+ it "does not set available_from for absorbing organisation" do
+ merge_organisations_service.call
+
+ absorbing_organisation.reload
+ expect(absorbing_organisation.available_from).to be_nil
+ end
+
context "and merging organisation rent periods" do
before do
OrganisationRentPeriod.create!(organisation: absorbing_organisation, rent_period: 1)
@@ -126,15 +133,14 @@ RSpec.describe Merge::MergeOrganisationsService do
end
context "and merging organisation schemes and locations" do
- let!(:scheme) { create(:scheme, owning_organisation: merging_organisation) }
- let!(:location) { create(:location, scheme:) }
+ let!(:scheme) { create(:scheme, owning_organisation: merging_organisation, old_id: "scheme_old_id", old_visible_id: "scheme_old_visible_id") }
+ let!(:location) { create(:location, scheme:, old_id: "location_old_id", old_visible_id: "location_old_visible_id") }
let!(:deactivated_location) { create(:location, scheme:) }
let!(:deactivated_scheme) { create(:scheme, owning_organisation: merging_organisation) }
let!(:owned_lettings_log) { create(:lettings_log, :sh, scheme:, location:, startdate: Time.zone.tomorrow, owning_organisation: merging_organisation) }
let!(:owned_lettings_log_no_location) { create(:lettings_log, :sh, scheme:, startdate: Time.zone.tomorrow, owning_organisation: merging_organisation) }
before do
- create(:location, scheme:, name: "fake location", postcode: "A1 1AA")
create(:location, scheme: deactivated_scheme)
create(:scheme_deactivation_period, scheme: deactivated_scheme, deactivation_date: Time.zone.today - 1.month)
create(:location_deactivation_period, location: deactivated_location, deactivation_date: Time.zone.today - 1.month)
@@ -153,8 +159,12 @@ RSpec.describe Merge::MergeOrganisationsService do
absorbing_organisation.reload
expect(absorbing_organisation.owned_schemes.count).to eq(1)
expect(absorbing_organisation.owned_schemes.first.service_name).to eq(scheme.service_name)
- expect(absorbing_organisation.owned_schemes.first.locations.count).to eq(2)
+ expect(absorbing_organisation.owned_schemes.first.old_id).to be_nil
+ expect(absorbing_organisation.owned_schemes.first.old_visible_id).to be_nil
+ expect(absorbing_organisation.owned_schemes.first.locations.count).to eq(1)
expect(absorbing_organisation.owned_schemes.first.locations.first.postcode).to eq(location.postcode)
+ expect(absorbing_organisation.owned_schemes.first.locations.first.old_id).to be_nil
+ expect(absorbing_organisation.owned_schemes.first.locations.first.old_visible_id).to be_nil
expect(scheme.scheme_deactivation_periods.count).to eq(1)
expect(scheme.scheme_deactivation_periods.first.deactivation_date.to_date).to eq(Time.zone.today)
end
@@ -215,9 +225,175 @@ RSpec.describe Merge::MergeOrganisationsService do
expect(sales_log.owning_organisation).to eq(merging_organisation)
end
end
+
+ context "and merge date is provided" do
+ subject(:merge_organisations_service) { described_class.new(absorbing_organisation_id: absorbing_organisation.id, merging_organisation_ids: [merging_organisation_ids], merge_date: Time.zone.yesterday) }
+
+ it "sets merge date on merged organisation" do
+ merge_organisations_service.call
+
+ merging_organisation.reload
+ expect(merging_organisation.merge_date.to_date).to eq(Time.zone.yesterday)
+ expect(merging_organisation.absorbing_organisation_id).to eq(absorbing_organisation.id)
+ end
+
+ context "and merging sales logs" do
+ let!(:sales_log) { create(:sales_log, saledate: Time.zone.today, owning_organisation: merging_organisation) }
+
+ before do
+ create(:sales_log, saledate: Time.zone.today - 2.days, owning_organisation: merging_organisation)
+ end
+
+ it "moves relevant logs" do
+ merge_organisations_service.call
+
+ absorbing_organisation.reload
+ expect(SalesLog.filter_by_owning_organisation(absorbing_organisation).count).to eq(1)
+ expect(SalesLog.filter_by_owning_organisation(absorbing_organisation).first).to eq(sales_log)
+ end
+
+ it "rolls back if there's an error" do
+ allow(Organisation).to receive(:find).with([merging_organisation_ids]).and_return(Organisation.find(merging_organisation_ids))
+ allow(Organisation).to receive(:find).with(absorbing_organisation.id).and_return(absorbing_organisation)
+ allow(absorbing_organisation).to receive(:save!).and_raise(ActiveRecord::RecordInvalid)
+ expect(Rails.logger).to receive(:error).with("Organisation merge failed with: Record invalid")
+ merge_organisations_service.call
+
+ absorbing_organisation.reload
+ expect(absorbing_organisation.sales_logs.count).to eq(0)
+ expect(sales_log.owning_organisation).to eq(merging_organisation)
+ end
+ end
+
+ context "and merging lettings logs" do
+ let(:owning_organisation) { create(:organisation, holds_own_stock: true) }
+ let!(:owned_lettings_log) { create(:lettings_log, startdate: Time.zone.today, owning_organisation: merging_organisation, created_by: merging_organisation_user) }
+ let!(:managed_lettings_log) { create(:lettings_log, startdate: Time.zone.today) }
+
+ before do
+ create(:organisation_relationship) { create(:organisation_relationship, parent_organisation: owning_organisation, child_organisation: merging_organisation) }
+ managed_lettings_log.update!(owning_organisation:, managing_organisation: merging_organisation, created_by: merging_organisation_user)
+ create(:lettings_log, startdate: Time.zone.today - 2.days, owning_organisation: merging_organisation, created_by: merging_organisation_user)
+ create(:lettings_log, startdate: Time.zone.today - 2.days, owning_organisation:, managing_organisation: merging_organisation, created_by: merging_organisation_user)
+ end
+
+ it "moves relevant logs" do
+ merge_organisations_service.call
+
+ absorbing_organisation.reload
+ expect(LettingsLog.filter_by_owning_organisation(absorbing_organisation).count).to eq(1)
+ expect(LettingsLog.filter_by_owning_organisation(absorbing_organisation).first).to eq(owned_lettings_log)
+ expect(LettingsLog.filter_by_managing_organisation(absorbing_organisation).count).to eq(2)
+ expect(LettingsLog.filter_by_managing_organisation(absorbing_organisation)).to include(managed_lettings_log)
+ expect(LettingsLog.filter_by_managing_organisation(absorbing_organisation)).to include(owned_lettings_log)
+ end
+
+ it "rolls back if there's an error" do
+ allow(Organisation).to receive(:find).with([merging_organisation_ids]).and_return(Organisation.find(merging_organisation_ids))
+ allow(Organisation).to receive(:find).with(absorbing_organisation.id).and_return(absorbing_organisation)
+ allow(absorbing_organisation).to receive(:save!).and_raise(ActiveRecord::RecordInvalid)
+ expect(Rails.logger).to receive(:error).with("Organisation merge failed with: Record invalid")
+ merge_organisations_service.call
+
+ absorbing_organisation.reload
+ expect(absorbing_organisation.lettings_logs.count).to eq(0)
+ expect(owned_lettings_log.owning_organisation).to eq(merging_organisation)
+ expect(managed_lettings_log.managing_organisation).to eq(merging_organisation)
+ end
+ end
+
+ context "and merging organisation schemes and locations" do
+ let!(:scheme) { create(:scheme, owning_organisation: merging_organisation) }
+ let!(:location) { create(:location, scheme:) }
+ let!(:deactivated_location) { create(:location, scheme:) }
+ let!(:deactivated_scheme) { create(:scheme, owning_organisation: merging_organisation) }
+ let!(:owned_lettings_log) { create(:lettings_log, :sh, scheme:, location:, startdate: Time.zone.tomorrow, owning_organisation: merging_organisation) }
+ let!(:owned_lettings_log_no_location) { create(:lettings_log, :sh, scheme:, startdate: Time.zone.tomorrow, owning_organisation: merging_organisation) }
+
+ before do
+ create(:location, scheme: deactivated_scheme)
+ create(:scheme_deactivation_period, scheme: deactivated_scheme, deactivation_date: Time.zone.today - 1.month)
+ create(:location_deactivation_period, location: deactivated_location, deactivation_date: Time.zone.today - 1.month)
+ create(:lettings_log, scheme:, location:, startdate: Time.zone.yesterday)
+ create(:lettings_log, startdate: Time.zone.tomorrow, managing_organisation: merging_organisation)
+ end
+
+ it "combines organisation schemes and locations" do
+ expect(Rails.logger).to receive(:info).with("Merged users from fake org:")
+ expect(Rails.logger).to receive(:info).with("\tDanny Rojas (#{merging_organisation.data_protection_officers.first.email})")
+ expect(Rails.logger).to receive(:info).with("\tfake name (fake@email.com)")
+ expect(Rails.logger).to receive(:info).with("New schemes from fake org:")
+ expect(Rails.logger).to receive(:info).with(/\t#{scheme.service_name} \(S/)
+ merge_organisations_service.call
+
+ absorbing_organisation.reload
+ expect(absorbing_organisation.owned_schemes.count).to eq(1)
+ expect(absorbing_organisation.owned_schemes.first.service_name).to eq(scheme.service_name)
+ expect(absorbing_organisation.owned_schemes.first.locations.count).to eq(1)
+ expect(absorbing_organisation.owned_schemes.first.locations.first.postcode).to eq(location.postcode)
+ expect(scheme.scheme_deactivation_periods.count).to eq(1)
+ expect(scheme.scheme_deactivation_periods.first.deactivation_date.to_date).to eq(Time.zone.yesterday)
+ end
+
+ it "moves relevant logs and assigns the new scheme" do
+ merge_organisations_service.call
+
+ absorbing_organisation.reload
+ merging_organisation.reload
+ expect(absorbing_organisation.owned_lettings_logs.count).to eq(2)
+ 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)
+ expect(absorbing_organisation.owned_lettings_logs.find(owned_lettings_log_no_location.id).scheme).to eq(absorbing_organisation.owned_schemes.first)
+ expect(absorbing_organisation.owned_lettings_logs.find(owned_lettings_log_no_location.id).location).to eq(nil)
+ end
+
+ it "rolls back if there's an error" do
+ allow(Organisation).to receive(:find).with([merging_organisation_ids]).and_return(Organisation.find(merging_organisation_ids))
+ allow(Organisation).to receive(:find).with(absorbing_organisation.id).and_return(absorbing_organisation)
+ allow(absorbing_organisation).to receive(:save!).and_raise(ActiveRecord::RecordInvalid)
+ expect(Rails.logger).to receive(:error).with("Organisation merge failed with: Record invalid")
+ merge_organisations_service.call
+
+ absorbing_organisation.reload
+ merging_organisation.reload
+ expect(absorbing_organisation.owned_schemes.count).to eq(0)
+ expect(scheme.scheme_deactivation_periods.count).to eq(0)
+ expect(owned_lettings_log.owning_organisation).to eq(merging_organisation)
+ expect(owned_lettings_log_no_location.owning_organisation).to eq(merging_organisation)
+ end
+ end
+
+ context "and absorbing_organisation_active_from_merge_date is true" do
+ subject(:merge_organisations_service) { described_class.new(absorbing_organisation_id: absorbing_organisation.id, merging_organisation_ids: [merging_organisation_ids], merge_date: Time.zone.yesterday, absorbing_organisation_active_from_merge_date: true) }
+
+ it "sets available from to merge_date for absorbing organisation" do
+ merge_organisations_service.call
+
+ absorbing_organisation.reload
+ expect(absorbing_organisation.available_from.to_date).to eq(Time.zone.yesterday)
+ end
+ end
+ end
+
+ context "and absorbing_organisation_active_from_merge_date is true" do
+ subject(:merge_organisations_service) { described_class.new(absorbing_organisation_id: absorbing_organisation.id, merging_organisation_ids: [merging_organisation_ids], absorbing_organisation_active_from_merge_date: true) }
+
+ it "sets available from to merge_date (today) for absorbing organisation" do
+ merge_organisations_service.call
+
+ absorbing_organisation.reload
+ expect(absorbing_organisation.available_from.to_date).to eq(Time.zone.today)
+ end
+ end
end
context "when merging a multiple organisations into an existing organisation" do
+ subject(:merge_organisations_service) { described_class.new(absorbing_organisation_id: absorbing_organisation.id, merging_organisation_ids: [merging_organisation_ids], merge_date: nil) }
+
+ let(:absorbing_organisation) { create(:organisation, holds_own_stock: false) }
+ let(:absorbing_organisation_user) { create(:user, organisation: absorbing_organisation) }
+
let(:merging_organisation) { create(:organisation, holds_own_stock: true, name: "fake org") }
let(:merging_organisation_too) { create(:organisation, holds_own_stock: true, name: "second org") }
@@ -318,6 +494,530 @@ RSpec.describe Merge::MergeOrganisationsService do
expect(absorbing_organisation.child_organisations).to include(absorbing_organisation_relationship.child_organisation)
end
end
+
+ context "and merge date is provided" do
+ subject(:merge_organisations_service) { described_class.new(absorbing_organisation_id: absorbing_organisation.id, merging_organisation_ids: [merging_organisation_ids], merge_date: Time.zone.yesterday) }
+
+ it "sets merge date and absorbing organisation on merged organisations" do
+ merge_organisations_service.call
+
+ merging_organisation.reload
+ merging_organisation_too.reload
+ expect(merging_organisation.merge_date.to_date).to eq(Time.zone.yesterday)
+ expect(merging_organisation.absorbing_organisation_id).to eq(absorbing_organisation.id)
+ expect(merging_organisation_too.merge_date.to_date).to eq(Time.zone.yesterday)
+ expect(merging_organisation_too.absorbing_organisation_id).to eq(absorbing_organisation.id)
+ end
+ end
+ end
+
+ context "when merging a single organisation into a new organisation" do
+ subject(:merge_organisations_service) { described_class.new(absorbing_organisation_id: new_absorbing_organisation.id, merging_organisation_ids: [merging_organisation_ids], merge_date: nil) }
+
+ let(:new_absorbing_organisation) { create(:organisation, :without_dpc, holds_own_stock: false) }
+ let(:new_absorbing_organisation_user) { create(:user, organisation: new_absorbing_organisation) }
+
+ let(:merging_organisation) { create(:organisation, holds_own_stock: true, name: "fake org") }
+
+ let(:merging_organisation_ids) { [merging_organisation.id] }
+ let!(:merging_organisation_user) { create(:user, organisation: merging_organisation, name: "fake name", email: "fake@email.com") }
+
+ it "moves the users from merging organisation to absorbing organisation" do
+ expect(Rails.logger).to receive(:info).with("Merged users from fake org:")
+ expect(Rails.logger).to receive(:info).with("\tDanny Rojas (#{merging_organisation.data_protection_officers.first.email})")
+ expect(Rails.logger).to receive(:info).with("\tfake name (fake@email.com)")
+ expect(Rails.logger).to receive(:info).with("New schemes from fake org:")
+ merge_organisations_service.call
+
+ merging_organisation_user.reload
+ expect(merging_organisation_user.organisation).to eq(new_absorbing_organisation)
+ end
+
+ it "sets merge date on merged organisation" do
+ merge_organisations_service.call
+
+ merging_organisation.reload
+ expect(merging_organisation.merge_date.to_date).to eq(Time.zone.today)
+ expect(merging_organisation.absorbing_organisation_id).to eq(new_absorbing_organisation.id)
+ end
+
+ it "combines organisation data" do
+ merge_organisations_service.call
+
+ new_absorbing_organisation.reload
+ expect(new_absorbing_organisation.holds_own_stock).to eq(true)
+ end
+
+ it "rolls back if there's an error" do
+ allow(Organisation).to receive(:find).with([merging_organisation_ids]).and_return(Organisation.find(merging_organisation_ids))
+ allow(Organisation).to receive(:find).with(new_absorbing_organisation.id).and_return(new_absorbing_organisation)
+ allow(new_absorbing_organisation).to receive(:save!).and_raise(ActiveRecord::RecordInvalid)
+ expect(Rails.logger).to receive(:error).with("Organisation merge failed with: Record invalid")
+ merge_organisations_service.call
+
+ new_absorbing_organisation.reload
+ merging_organisation.reload
+ expect(new_absorbing_organisation.holds_own_stock).to eq(false)
+ expect(merging_organisation.merge_date).to eq(nil)
+ expect(merging_organisation.absorbing_organisation_id).to eq(nil)
+ expect(merging_organisation_user.organisation).to eq(merging_organisation)
+ end
+
+ it "does not set available_from for absorbing organisation" do
+ merge_organisations_service.call
+
+ new_absorbing_organisation.reload
+ expect(new_absorbing_organisation.available_from).to be_nil
+ end
+
+ context "and merging organisation rent periods" do
+ before do
+ OrganisationRentPeriod.create!(organisation: new_absorbing_organisation, rent_period: 1)
+ OrganisationRentPeriod.create!(organisation: new_absorbing_organisation, rent_period: 3)
+ OrganisationRentPeriod.create!(organisation: merging_organisation, rent_period: 1)
+ OrganisationRentPeriod.create!(organisation: merging_organisation, rent_period: 2)
+ end
+
+ it "combines organisation rent periods" do
+ expect(new_absorbing_organisation.rent_periods.count).to eq(2)
+ merge_organisations_service.call
+
+ new_absorbing_organisation.reload
+ expect(new_absorbing_organisation.rent_periods.count).to eq(3)
+ expect(new_absorbing_organisation.rent_periods).to include(1)
+ expect(new_absorbing_organisation.rent_periods).to include(2)
+ expect(new_absorbing_organisation.rent_periods).to include(3)
+ end
+
+ it "rolls back if there's an error" do
+ allow(Organisation).to receive(:find).with([merging_organisation_ids]).and_return(Organisation.find(merging_organisation_ids))
+ allow(Organisation).to receive(:find).with(new_absorbing_organisation.id).and_return(new_absorbing_organisation)
+ allow(new_absorbing_organisation).to receive(:save!).and_raise(ActiveRecord::RecordInvalid)
+ expect(Rails.logger).to receive(:error).with("Organisation merge failed with: Record invalid")
+ merge_organisations_service.call
+
+ new_absorbing_organisation.reload
+ merging_organisation.reload
+ expect(new_absorbing_organisation.rent_periods.count).to eq(2)
+ expect(merging_organisation.rent_periods.count).to eq(2)
+ end
+ end
+
+ context "and merging organisation relationships" do
+ let(:other_organisation) { create(:organisation) }
+ let!(:merging_organisation_relationship) { create(:organisation_relationship, parent_organisation: merging_organisation) }
+ let!(:new_absorbing_organisation_relationship) { create(:organisation_relationship, parent_organisation: new_absorbing_organisation) }
+
+ before do
+ create(:organisation_relationship, parent_organisation: new_absorbing_organisation, child_organisation: merging_organisation)
+ create(:organisation_relationship, parent_organisation: merging_organisation, child_organisation: other_organisation)
+ create(:organisation_relationship, parent_organisation: new_absorbing_organisation, child_organisation: other_organisation)
+ end
+
+ it "combines organisation relationships" do
+ merge_organisations_service.call
+
+ new_absorbing_organisation.reload
+ expect(new_absorbing_organisation.child_organisations).to include(other_organisation)
+ expect(new_absorbing_organisation.child_organisations).to include(new_absorbing_organisation_relationship.child_organisation)
+ expect(new_absorbing_organisation.child_organisations).to include(merging_organisation_relationship.child_organisation)
+ expect(new_absorbing_organisation.child_organisations).not_to include(merging_organisation)
+ expect(new_absorbing_organisation.parent_organisations.count).to eq(0)
+ expect(new_absorbing_organisation.child_organisations.count).to eq(3)
+ end
+
+ it "rolls back if there's an error" do
+ allow(Organisation).to receive(:find).with([merging_organisation_ids]).and_return(Organisation.find(merging_organisation_ids))
+ allow(Organisation).to receive(:find).with(new_absorbing_organisation.id).and_return(new_absorbing_organisation)
+ allow(new_absorbing_organisation).to receive(:save!).and_raise(ActiveRecord::RecordInvalid)
+ expect(Rails.logger).to receive(:error).with("Organisation merge failed with: Record invalid")
+ merge_organisations_service.call
+
+ new_absorbing_organisation.reload
+ expect(new_absorbing_organisation.child_organisations.count).to eq(3)
+ expect(new_absorbing_organisation.child_organisations).to include(other_organisation)
+ expect(new_absorbing_organisation.child_organisations).to include(merging_organisation)
+ expect(new_absorbing_organisation.child_organisations).to include(new_absorbing_organisation_relationship.child_organisation)
+ end
+ end
+
+ context "and merging organisation schemes and locations" do
+ let!(:scheme) { create(:scheme, owning_organisation: merging_organisation, old_id: "scheme_old_id", old_visible_id: "scheme_old_visible_id") }
+ let!(:location) { create(:location, scheme:, old_id: "location_old_id", old_visible_id: "location_old_visible_id") }
+ let!(:deactivated_location) { create(:location, scheme:) }
+ let!(:deactivated_scheme) { create(:scheme, owning_organisation: merging_organisation) }
+ let!(:owned_lettings_log) { create(:lettings_log, :sh, scheme:, location:, startdate: Time.zone.tomorrow, owning_organisation: merging_organisation) }
+ let!(:owned_lettings_log_no_location) { create(:lettings_log, :sh, scheme:, startdate: Time.zone.tomorrow, owning_organisation: merging_organisation) }
+
+ before do
+ create(:location, scheme: deactivated_scheme)
+ create(:scheme_deactivation_period, scheme: deactivated_scheme, deactivation_date: Time.zone.today - 1.month)
+ create(:location_deactivation_period, location: deactivated_location, deactivation_date: Time.zone.today - 1.month)
+ create(:lettings_log, scheme:, location:, startdate: Time.zone.yesterday)
+ create(:lettings_log, startdate: Time.zone.tomorrow, managing_organisation: merging_organisation)
+ end
+
+ it "combines organisation schemes and locations" do
+ expect(Rails.logger).to receive(:info).with("Merged users from fake org:")
+ expect(Rails.logger).to receive(:info).with("\tDanny Rojas (#{merging_organisation.data_protection_officers.first.email})")
+ expect(Rails.logger).to receive(:info).with("\tfake name (fake@email.com)")
+ expect(Rails.logger).to receive(:info).with("New schemes from fake org:")
+ expect(Rails.logger).to receive(:info).with(/\t#{scheme.service_name} \(S/)
+ merge_organisations_service.call
+
+ new_absorbing_organisation.reload
+ expect(new_absorbing_organisation.owned_schemes.count).to eq(1)
+ expect(new_absorbing_organisation.owned_schemes.first.service_name).to eq(scheme.service_name)
+ expect(new_absorbing_organisation.owned_schemes.first.old_id).to be_nil
+ expect(new_absorbing_organisation.owned_schemes.first.old_visible_id).to be_nil
+ expect(new_absorbing_organisation.owned_schemes.first.locations.count).to eq(1)
+ expect(new_absorbing_organisation.owned_schemes.first.locations.first.postcode).to eq(location.postcode)
+ expect(new_absorbing_organisation.owned_schemes.first.locations.first.old_id).to be_nil
+ expect(new_absorbing_organisation.owned_schemes.first.locations.first.old_visible_id).to be_nil
+ expect(scheme.scheme_deactivation_periods.count).to eq(1)
+ expect(scheme.scheme_deactivation_periods.first.deactivation_date.to_date).to eq(Time.zone.today)
+ end
+
+ it "moves relevant logs and assigns the new scheme" do
+ merge_organisations_service.call
+
+ new_absorbing_organisation.reload
+ merging_organisation.reload
+ expect(new_absorbing_organisation.owned_lettings_logs.count).to eq(2)
+ expect(new_absorbing_organisation.managed_lettings_logs.count).to eq(1)
+ expect(new_absorbing_organisation.owned_lettings_logs.find(owned_lettings_log.id).scheme).to eq(new_absorbing_organisation.owned_schemes.first)
+ expect(new_absorbing_organisation.owned_lettings_logs.find(owned_lettings_log.id).location).to eq(new_absorbing_organisation.owned_schemes.first.locations.first)
+ expect(new_absorbing_organisation.owned_lettings_logs.find(owned_lettings_log_no_location.id).scheme).to eq(new_absorbing_organisation.owned_schemes.first)
+ expect(new_absorbing_organisation.owned_lettings_logs.find(owned_lettings_log_no_location.id).location).to eq(nil)
+ end
+
+ it "rolls back if there's an error" do
+ allow(Organisation).to receive(:find).with([merging_organisation_ids]).and_return(Organisation.find(merging_organisation_ids))
+ allow(Organisation).to receive(:find).with(new_absorbing_organisation.id).and_return(new_absorbing_organisation)
+ allow(new_absorbing_organisation).to receive(:save!).and_raise(ActiveRecord::RecordInvalid)
+ expect(Rails.logger).to receive(:error).with("Organisation merge failed with: Record invalid")
+ merge_organisations_service.call
+
+ new_absorbing_organisation.reload
+ merging_organisation.reload
+ expect(new_absorbing_organisation.owned_schemes.count).to eq(0)
+ expect(scheme.scheme_deactivation_periods.count).to eq(0)
+ expect(owned_lettings_log.owning_organisation).to eq(merging_organisation)
+ expect(owned_lettings_log_no_location.owning_organisation).to eq(merging_organisation)
+ end
+ end
+
+ context "and merging sales logs" do
+ let!(:sales_log) { create(:sales_log, saledate: Time.zone.tomorrow, owning_organisation: merging_organisation) }
+
+ before do
+ create(:sales_log, saledate: Time.zone.yesterday, owning_organisation: merging_organisation)
+ end
+
+ it "moves relevant logs" do
+ merge_organisations_service.call
+
+ new_absorbing_organisation.reload
+ expect(SalesLog.filter_by_owning_organisation(new_absorbing_organisation).count).to eq(1)
+ expect(SalesLog.filter_by_owning_organisation(new_absorbing_organisation).first).to eq(sales_log)
+ end
+
+ it "rolls back if there's an error" do
+ allow(Organisation).to receive(:find).with([merging_organisation_ids]).and_return(Organisation.find(merging_organisation_ids))
+ allow(Organisation).to receive(:find).with(new_absorbing_organisation.id).and_return(new_absorbing_organisation)
+ allow(new_absorbing_organisation).to receive(:save!).and_raise(ActiveRecord::RecordInvalid)
+ expect(Rails.logger).to receive(:error).with("Organisation merge failed with: Record invalid")
+ merge_organisations_service.call
+
+ new_absorbing_organisation.reload
+ expect(new_absorbing_organisation.sales_logs.count).to eq(0)
+ expect(sales_log.owning_organisation).to eq(merging_organisation)
+ end
+ end
+
+ context "and merge date is provided" do
+ subject(:merge_organisations_service) { described_class.new(absorbing_organisation_id: new_absorbing_organisation.id, merging_organisation_ids: [merging_organisation_ids], merge_date: Time.zone.yesterday) }
+
+ it "sets merge date on merged organisation" do
+ merge_organisations_service.call
+
+ merging_organisation.reload
+ expect(merging_organisation.merge_date.to_date).to eq(Time.zone.yesterday)
+ expect(merging_organisation.absorbing_organisation_id).to eq(new_absorbing_organisation.id)
+ end
+
+ context "and merging sales logs" do
+ let!(:sales_log) { create(:sales_log, saledate: Time.zone.today, owning_organisation: merging_organisation) }
+
+ before do
+ create(:sales_log, saledate: Time.zone.today - 2.days, owning_organisation: merging_organisation)
+ end
+
+ it "moves relevant logs" do
+ merge_organisations_service.call
+
+ new_absorbing_organisation.reload
+ expect(SalesLog.filter_by_owning_organisation(new_absorbing_organisation).count).to eq(1)
+ expect(SalesLog.filter_by_owning_organisation(new_absorbing_organisation).first).to eq(sales_log)
+ end
+
+ it "rolls back if there's an error" do
+ allow(Organisation).to receive(:find).with([merging_organisation_ids]).and_return(Organisation.find(merging_organisation_ids))
+ allow(Organisation).to receive(:find).with(new_absorbing_organisation.id).and_return(new_absorbing_organisation)
+ allow(new_absorbing_organisation).to receive(:save!).and_raise(ActiveRecord::RecordInvalid)
+ expect(Rails.logger).to receive(:error).with("Organisation merge failed with: Record invalid")
+ merge_organisations_service.call
+
+ new_absorbing_organisation.reload
+ expect(new_absorbing_organisation.sales_logs.count).to eq(0)
+ expect(sales_log.owning_organisation).to eq(merging_organisation)
+ end
+ end
+
+ context "and merging lettings logs" do
+ let(:owning_organisation) { create(:organisation, holds_own_stock: true) }
+ let!(:owned_lettings_log) { create(:lettings_log, startdate: Time.zone.today, owning_organisation: merging_organisation, created_by: merging_organisation_user) }
+ let!(:managed_lettings_log) { create(:lettings_log, startdate: Time.zone.today) }
+
+ before do
+ create(:organisation_relationship) { create(:organisation_relationship, parent_organisation: owning_organisation, child_organisation: merging_organisation) }
+ managed_lettings_log.update!(owning_organisation:, managing_organisation: merging_organisation, created_by: merging_organisation_user)
+ create(:lettings_log, startdate: Time.zone.today - 2.days, owning_organisation: merging_organisation, created_by: merging_organisation_user)
+ create(:lettings_log, startdate: Time.zone.today - 2.days, owning_organisation:, managing_organisation: merging_organisation, created_by: merging_organisation_user)
+ end
+
+ it "moves relevant logs" do
+ merge_organisations_service.call
+
+ new_absorbing_organisation.reload
+ expect(LettingsLog.filter_by_owning_organisation(new_absorbing_organisation).count).to eq(1)
+ expect(LettingsLog.filter_by_owning_organisation(new_absorbing_organisation).first).to eq(owned_lettings_log)
+ expect(LettingsLog.filter_by_managing_organisation(new_absorbing_organisation).count).to eq(2)
+ expect(LettingsLog.filter_by_managing_organisation(new_absorbing_organisation)).to include(managed_lettings_log)
+ expect(LettingsLog.filter_by_managing_organisation(new_absorbing_organisation)).to include(owned_lettings_log)
+ end
+
+ it "rolls back if there's an error" do
+ allow(Organisation).to receive(:find).with([merging_organisation_ids]).and_return(Organisation.find(merging_organisation_ids))
+ allow(Organisation).to receive(:find).with(new_absorbing_organisation.id).and_return(new_absorbing_organisation)
+ allow(new_absorbing_organisation).to receive(:save!).and_raise(ActiveRecord::RecordInvalid)
+ expect(Rails.logger).to receive(:error).with("Organisation merge failed with: Record invalid")
+ merge_organisations_service.call
+
+ new_absorbing_organisation.reload
+ expect(new_absorbing_organisation.lettings_logs.count).to eq(0)
+ expect(owned_lettings_log.owning_organisation).to eq(merging_organisation)
+ expect(managed_lettings_log.managing_organisation).to eq(merging_organisation)
+ end
+ end
+
+ context "and merging organisation schemes and locations" do
+ let!(:scheme) { create(:scheme, owning_organisation: merging_organisation) }
+ let!(:location) { create(:location, scheme:) }
+ let!(:deactivated_location) { create(:location, scheme:) }
+ let!(:deactivated_scheme) { create(:scheme, owning_organisation: merging_organisation) }
+ let!(:owned_lettings_log) { create(:lettings_log, :sh, scheme:, location:, startdate: Time.zone.tomorrow, owning_organisation: merging_organisation) }
+ let!(:owned_lettings_log_no_location) { create(:lettings_log, :sh, scheme:, startdate: Time.zone.tomorrow, owning_organisation: merging_organisation) }
+
+ before do
+ create(:location, scheme: deactivated_scheme)
+ create(:scheme_deactivation_period, scheme: deactivated_scheme, deactivation_date: Time.zone.today - 1.month)
+ create(:location_deactivation_period, location: deactivated_location, deactivation_date: Time.zone.today - 1.month)
+ create(:lettings_log, scheme:, location:, startdate: Time.zone.yesterday)
+ create(:lettings_log, startdate: Time.zone.tomorrow, managing_organisation: merging_organisation)
+ end
+
+ it "combines organisation schemes and locations" do
+ expect(Rails.logger).to receive(:info).with("Merged users from fake org:")
+ expect(Rails.logger).to receive(:info).with("\tDanny Rojas (#{merging_organisation.data_protection_officers.first.email})")
+ expect(Rails.logger).to receive(:info).with("\tfake name (fake@email.com)")
+ expect(Rails.logger).to receive(:info).with("New schemes from fake org:")
+ expect(Rails.logger).to receive(:info).with(/\t#{scheme.service_name} \(S/)
+ merge_organisations_service.call
+
+ new_absorbing_organisation.reload
+ expect(new_absorbing_organisation.owned_schemes.count).to eq(1)
+ expect(new_absorbing_organisation.owned_schemes.first.service_name).to eq(scheme.service_name)
+ expect(new_absorbing_organisation.owned_schemes.first.locations.count).to eq(1)
+ expect(new_absorbing_organisation.owned_schemes.first.locations.first.postcode).to eq(location.postcode)
+ expect(scheme.scheme_deactivation_periods.count).to eq(1)
+ expect(scheme.scheme_deactivation_periods.first.deactivation_date.to_date).to eq(Time.zone.yesterday)
+ end
+
+ it "moves relevant logs and assigns the new scheme" do
+ merge_organisations_service.call
+
+ new_absorbing_organisation.reload
+ merging_organisation.reload
+ expect(new_absorbing_organisation.owned_lettings_logs.count).to eq(2)
+ expect(new_absorbing_organisation.managed_lettings_logs.count).to eq(1)
+ expect(new_absorbing_organisation.owned_lettings_logs.find(owned_lettings_log.id).scheme).to eq(new_absorbing_organisation.owned_schemes.first)
+ expect(new_absorbing_organisation.owned_lettings_logs.find(owned_lettings_log.id).location).to eq(new_absorbing_organisation.owned_schemes.first.locations.first)
+ expect(new_absorbing_organisation.owned_lettings_logs.find(owned_lettings_log_no_location.id).scheme).to eq(new_absorbing_organisation.owned_schemes.first)
+ expect(new_absorbing_organisation.owned_lettings_logs.find(owned_lettings_log_no_location.id).location).to eq(nil)
+ end
+
+ it "rolls back if there's an error" do
+ allow(Organisation).to receive(:find).with([merging_organisation_ids]).and_return(Organisation.find(merging_organisation_ids))
+ allow(Organisation).to receive(:find).with(new_absorbing_organisation.id).and_return(new_absorbing_organisation)
+ allow(new_absorbing_organisation).to receive(:save!).and_raise(ActiveRecord::RecordInvalid)
+ expect(Rails.logger).to receive(:error).with("Organisation merge failed with: Record invalid")
+ merge_organisations_service.call
+
+ new_absorbing_organisation.reload
+ merging_organisation.reload
+ expect(new_absorbing_organisation.owned_schemes.count).to eq(0)
+ expect(scheme.scheme_deactivation_periods.count).to eq(0)
+ expect(owned_lettings_log.owning_organisation).to eq(merging_organisation)
+ expect(owned_lettings_log_no_location.owning_organisation).to eq(merging_organisation)
+ end
+ end
+
+ context "and absorbing_organisation_active_from_merge_date is true" do
+ subject(:merge_organisations_service) { described_class.new(absorbing_organisation_id: new_absorbing_organisation.id, merging_organisation_ids: [merging_organisation_ids], merge_date: Time.zone.yesterday, absorbing_organisation_active_from_merge_date: true) }
+
+ it "sets available from to merge_date for absorbing organisation" do
+ merge_organisations_service.call
+
+ new_absorbing_organisation.reload
+ expect(new_absorbing_organisation.available_from.to_date).to eq(Time.zone.yesterday)
+ end
+ end
+ end
+
+ context "and absorbing_organisation_active_from_merge_date is true" do
+ subject(:merge_organisations_service) { described_class.new(absorbing_organisation_id: new_absorbing_organisation.id, merging_organisation_ids: [merging_organisation_ids], absorbing_organisation_active_from_merge_date: true) }
+
+ it "sets available from to merge_date (today) for absorbing organisation" do
+ merge_organisations_service.call
+
+ new_absorbing_organisation.reload
+ expect(new_absorbing_organisation.available_from.to_date).to eq(Time.zone.today)
+ end
+ end
+ end
+
+ context "when merging multiple organisations into a new organisation" do
+ subject(:merge_organisations_service) { described_class.new(absorbing_organisation_id: new_absorbing_organisation.id, merging_organisation_ids: [merging_organisation_ids], merge_date: nil) }
+
+ let(:new_absorbing_organisation) { create(:organisation, :without_dpc, holds_own_stock: false) }
+ let(:new_absorbing_organisation_user) { create(:user, organisation: new_absorbing_organisation) }
+
+ let(:merging_organisation) { create(:organisation, holds_own_stock: true, name: "fake org") }
+ let(:merging_organisation_too) { create(:organisation, holds_own_stock: true, name: "second org") }
+
+ let(:merging_organisation_ids) { [merging_organisation.id, merging_organisation_too.id] }
+ let!(:merging_organisation_user) { create(:user, organisation: merging_organisation, name: "fake name", email: "fake@email.com") }
+
+ before do
+ create_list(:user, 5, organisation: merging_organisation_too)
+ end
+
+ it "moves the users from merging organisations to absorbing organisation" do
+ expect(Rails.logger).to receive(:info).with("Merged users from fake org:")
+ expect(Rails.logger).to receive(:info).with("\tDanny Rojas (#{merging_organisation.data_protection_officers.first.email})")
+ expect(Rails.logger).to receive(:info).with("\tfake name (fake@email.com)")
+ expect(Rails.logger).to receive(:info).with("Merged users from second org:")
+ expect(Rails.logger).to receive(:info).with(/\tDanny Rojas/).exactly(6).times
+ expect(Rails.logger).to receive(:info).with("New schemes from fake org:")
+ expect(Rails.logger).to receive(:info).with("New schemes from second org:")
+ merge_organisations_service.call
+
+ merging_organisation_user.reload
+ expect(merging_organisation_user.organisation).to eq(new_absorbing_organisation)
+ end
+
+ it "sets merge date and absorbing organisation on merged organisations" do
+ merge_organisations_service.call
+
+ merging_organisation.reload
+ merging_organisation_too.reload
+ expect(merging_organisation.merge_date.to_date).to eq(Time.zone.today)
+ expect(merging_organisation.absorbing_organisation_id).to eq(new_absorbing_organisation.id)
+ expect(merging_organisation_too.merge_date.to_date).to eq(Time.zone.today)
+ expect(merging_organisation_too.absorbing_organisation_id).to eq(new_absorbing_organisation.id)
+ end
+
+ it "combines organisation data" do
+ merge_organisations_service.call
+
+ new_absorbing_organisation.reload
+ expect(new_absorbing_organisation.holds_own_stock).to eq(true)
+ end
+
+ it "rolls back if there's an error" do
+ allow(Organisation).to receive(:find).with([merging_organisation_ids]).and_return(Organisation.find(merging_organisation_ids))
+ allow(Organisation).to receive(:find).with(new_absorbing_organisation.id).and_return(new_absorbing_organisation)
+ allow(new_absorbing_organisation).to receive(:save!).and_raise(ActiveRecord::RecordInvalid)
+ expect(Rails.logger).to receive(:error).with("Organisation merge failed with: Record invalid")
+ merge_organisations_service.call
+
+ new_absorbing_organisation.reload
+ merging_organisation.reload
+ expect(new_absorbing_organisation.holds_own_stock).to eq(false)
+ expect(merging_organisation.merge_date).to eq(nil)
+ expect(merging_organisation.absorbing_organisation_id).to eq(nil)
+ expect(merging_organisation_user.organisation).to eq(merging_organisation)
+ end
+
+ context "and merging organisation relationships" do
+ let(:other_organisation) { create(:organisation) }
+ let!(:merging_organisation_relationship) { create(:organisation_relationship, parent_organisation: merging_organisation) }
+ let!(:new_absorbing_organisation_relationship) { create(:organisation_relationship, parent_organisation: new_absorbing_organisation) }
+
+ before do
+ create(:organisation_relationship, parent_organisation: merging_organisation, child_organisation: new_absorbing_organisation)
+ create(:organisation_relationship, parent_organisation: merging_organisation, child_organisation: other_organisation)
+ create(:organisation_relationship, parent_organisation: new_absorbing_organisation, child_organisation: other_organisation)
+ create(:organisation_relationship, parent_organisation: merging_organisation, child_organisation: merging_organisation_too)
+ end
+
+ it "combines organisation relationships" do
+ merge_organisations_service.call
+
+ new_absorbing_organisation.reload
+ expect(new_absorbing_organisation.child_organisations).to include(other_organisation)
+ expect(new_absorbing_organisation.child_organisations).to include(new_absorbing_organisation_relationship.child_organisation)
+ expect(new_absorbing_organisation.child_organisations).to include(merging_organisation_relationship.child_organisation)
+ expect(new_absorbing_organisation.child_organisations).not_to include(merging_organisation)
+ expect(new_absorbing_organisation.parent_organisations).not_to include(merging_organisation)
+ expect(new_absorbing_organisation.child_organisations).not_to include(merging_organisation_too)
+ expect(new_absorbing_organisation.parent_organisations).not_to include(merging_organisation_too)
+ expect(new_absorbing_organisation.parent_organisations.count).to eq(0)
+ expect(new_absorbing_organisation.child_organisations.count).to eq(3)
+ end
+
+ it "rolls back if there's an error" do
+ allow(Organisation).to receive(:find).with([merging_organisation_ids]).and_return(Organisation.find(merging_organisation_ids))
+ allow(Organisation).to receive(:find).with(new_absorbing_organisation.id).and_return(new_absorbing_organisation)
+ allow(new_absorbing_organisation).to receive(:save!).and_raise(ActiveRecord::RecordInvalid)
+ expect(Rails.logger).to receive(:error).with("Organisation merge failed with: Record invalid")
+ merge_organisations_service.call
+
+ new_absorbing_organisation.reload
+ merging_organisation.reload
+ expect(new_absorbing_organisation.child_organisations.count).to eq(2)
+ expect(new_absorbing_organisation.parent_organisations.count).to eq(1)
+ expect(new_absorbing_organisation.child_organisations).to include(other_organisation)
+ expect(new_absorbing_organisation.parent_organisations).to include(merging_organisation)
+ expect(new_absorbing_organisation.child_organisations).to include(new_absorbing_organisation_relationship.child_organisation)
+ end
+ end
+
+ context "and merge date is provided" do
+ subject(:merge_organisations_service) { described_class.new(absorbing_organisation_id: new_absorbing_organisation.id, merging_organisation_ids: [merging_organisation_ids], merge_date: Time.zone.yesterday) }
+
+ it "sets merge date and absorbing organisation on merged organisations" do
+ merge_organisations_service.call
+
+ merging_organisation.reload
+ merging_organisation_too.reload
+ expect(merging_organisation.merge_date.to_date).to eq(Time.zone.yesterday)
+ expect(merging_organisation.absorbing_organisation_id).to eq(new_absorbing_organisation.id)
+ expect(merging_organisation_too.merge_date.to_date).to eq(Time.zone.yesterday)
+ expect(merging_organisation_too.absorbing_organisation_id).to eq(new_absorbing_organisation.id)
+ end
+ end
end
end
end