Browse Source

CLDC-3732: Update review apps seeds (#2834)

* Update seeds

* Fix linting

* Update dsa bits

* Fix duplicate user/org variable names

* Fix create_list

* Set faker locale for development and review

* Update tests that relied on user factory default name

* Update more tests

* Add additional randomness to log factories

* Also create older logs

* Update tests and log randomness

* Ensure sufficient gap between child and parent ages

* More test fixes

* Specify names for users

* Fix more tests

* Fix lint

* More fixes

* More randomness in organisation generation

* Add some extra organisations

* Create future logs if future form use is enabled

* Update tests that expect fixed default org name

* Update more tests

* Fix typo

* Another tweak

* More test fixes

* More test fixes

* Another fix

* Update more tests

* More fixes

* Only create outright sale logs for relevant years

* Reduce max random age to avoid soft validations

* Don't allow sales logs to use no longer valid relat value

* Include fixed locations
pull/2837/head
Rachael Booth 4 months ago committed by GitHub
parent
commit
4157a7bb8f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 2
      config/environments/development.rb
  2. 2
      config/environments/review.rb
  3. 526
      db/seeds.rb
  4. 2
      spec/components/check_answers_summary_list_card_component_spec.rb
  5. 4
      spec/components/lettings_log_summary_component_spec.rb
  6. 2
      spec/components/sales_log_summary_component_spec.rb
  7. 10
      spec/factories/lettings_log.rb
  8. 20
      spec/factories/organisation.rb
  9. 44
      spec/factories/sales_log.rb
  10. 3
      spec/factories/scheme.rb
  11. 6
      spec/factories/user.rb
  12. 4
      spec/features/lettings_log_spec.rb
  13. 4
      spec/features/sales_log_spec.rb
  14. 9
      spec/features/schemes_spec.rb
  15. 2
      spec/helpers/organisations_helper_spec.rb
  16. 2
      spec/helpers/tab_nav_helper_spec.rb
  17. 2
      spec/models/form_spec.rb
  18. 2
      spec/models/organisation_spec.rb
  19. 2
      spec/models/user_spec.rb
  20. 12
      spec/requests/merge_requests_controller_spec.rb
  21. 11
      spec/requests/organisations_controller_spec.rb
  22. 22
      spec/requests/users_controller_spec.rb
  23. 4
      spec/services/csv/lettings_log_csv_service_spec.rb
  24. 10
      spec/services/csv/sales_log_csv_service_spec.rb
  25. 2
      spec/services/csv/scheme_csv_service_spec.rb
  26. 17
      spec/services/exports/lettings_log_export_service_spec.rb
  27. 2
      spec/services/exports/organisation_export_service_spec.rb
  28. 4
      spec/services/exports/user_export_service_spec.rb
  29. 28
      spec/services/merge/merge_organisations_service_spec.rb

2
config/environments/development.rb

@ -81,6 +81,8 @@ Rails.application.configure do
# Uncomment if you wish to allow Action Cable access from any origin. # Uncomment if you wish to allow Action Cable access from any origin.
# config.action_cable.disable_request_forgery_protection = true # config.action_cable.disable_request_forgery_protection = true
Faker::Config.locale = "en-GB"
# see https://discuss.rubyonrails.org/t/cve-2022-32224-possible-rce-escalation-bug-with-serialized-columns-in-active-record/81017 # see https://discuss.rubyonrails.org/t/cve-2022-32224-possible-rce-escalation-bug-with-serialized-columns-in-active-record/81017
config.active_record.yaml_column_permitted_classes = [Time, BigDecimal] config.active_record.yaml_column_permitted_classes = [Time, BigDecimal]

2
config/environments/review.rb

@ -125,6 +125,8 @@ Rails.application.configure do
# config.active_record.database_resolver = ActiveRecord::Middleware::DatabaseSelector::Resolver # config.active_record.database_resolver = ActiveRecord::Middleware::DatabaseSelector::Resolver
# config.active_record.database_resolver_context = ActiveRecord::Middleware::DatabaseSelector::Resolver::Session # config.active_record.database_resolver_context = ActiveRecord::Middleware::DatabaseSelector::Resolver::Session
Faker::Config.locale = "en-GB"
# see https://discuss.rubyonrails.org/t/cve-2022-32224-possible-rce-escalation-bug-with-serialized-columns-in-active-record/81017 # see https://discuss.rubyonrails.org/t/cve-2022-32224-possible-rce-escalation-bug-with-serialized-columns-in-active-record/81017
config.active_record.yaml_column_permitted_classes = [Time, BigDecimal] config.active_record.yaml_column_permitted_classes = [Time, BigDecimal]
end end

526
db/seeds.rb

@ -1,436 +1,175 @@
# This file should contain all the record creation needed to seed the database with its default values. # This file should contain all the record creation needed to seed the database with its default values.
# The data can then be loaded with the bin/rails db:seed command (or created alongside the database with db:setup). # The data can then be loaded with the bin/rails db:seed command (or created alongside the database with db:setup).
#
# Examples:
#
# movies = Movie.create([{ name: 'Star Wars' }, { name: 'Lord of the Rings' }])
# Character.create(name: 'Luke', movie: movies.first)
# rubocop:disable Rails/Output def find_or_create_user(organisation, email, name, role)
def create_data_protection_confirmation(user) case role
DataProtectionConfirmation.find_or_create_by!( when :data_provider
organisation: user.organisation, FactoryBot.create(:user, :if_unique, :data_provider, organisation:, email:, name:, password: ENV["REVIEW_APP_USER_PASSWORD"])
confirmed: true, when :data_coordinator
data_protection_officer: user, FactoryBot.create(:user, :if_unique, :data_coordinator, organisation:, email:, name:, password: ENV["REVIEW_APP_USER_PASSWORD"])
signed_at: Time.zone.local(2019, 1, 1), when :support
data_protection_officer_email: user.email, FactoryBot.create(:user, :if_unique, :support, organisation:, email:, name:, password: ENV["REVIEW_APP_USER_PASSWORD"])
data_protection_officer_name: user.name, end
organisation_name: user.organisation.name,
organisation_address: user.organisation.address_row,
)
end end
unless Rails.env.test? unless Rails.env.test?
stock_owner1 = Organisation.find_or_create_by!( if LocalAuthority.count.zero?
name: "Stock Owner 1", la_path = "config/local_authorities_data/initial_local_authorities.csv"
address_line1: "2 Marsham Street", service = Imports::LocalAuthoritiesService.new(path: la_path)
address_line2: "London", service.call
postcode: "SW1P 4DF", end
holds_own_stock: true,
other_stock_owners: "None",
managing_agents_label: "None",
provider_type: "LA",
)
stock_owner2 = Organisation.find_or_create_by!(
name: "Stock Owner 2",
address_line1: "2 Marsham Street",
address_line2: "London",
postcode: "SW1P 4DF",
holds_own_stock: true,
other_stock_owners: "None",
managing_agents_label: "None",
provider_type: "LA",
)
managing_agent1 = Organisation.find_or_create_by!(
name: "Managing Agent 1 (PRP)",
address_line1: "2 Marsham Street",
address_line2: "London",
postcode: "SW1P 4DF",
holds_own_stock: true,
other_stock_owners: "None",
managing_agents_label: "None",
provider_type: "PRP",
)
managing_agent2 = Organisation.find_or_create_by!(
name: "Managing Agent 2",
address_line1: "2 Marsham Street",
address_line2: "London",
postcode: "SW1P 4DF",
holds_own_stock: true,
other_stock_owners: "None",
managing_agents_label: "None",
provider_type: "LA",
)
org = Organisation.find_or_create_by!( if LaRentRange.count.zero?
name: "MHCLG", Dir.glob("config/rent_range_data/*.csv").each do |path|
address_line1: "2 Marsham Street", start_year = File.basename(path, ".csv")
address_line2: "London", service = Imports::RentRangesService.new(start_year:, path:)
postcode: "SW1P 4DF", service.call
holds_own_stock: true,
other_stock_owners: "None",
managing_agents_label: "None",
provider_type: "LA",
) do
info = "Seeded MHCLG Organisation"
if Rails.env.development?
pp info
else
Rails.logger.info info
end end
end end
standalone_owns_stock = Organisation.find_or_create_by!( if LaSaleRange.count.zero?
name: "Standalone Owns Stock 1 Ltd", Dir.glob("config/sale_range_data/*.csv").each do |path|
address_line1: "2 Marsham Street", start_year = File.basename(path, ".csv")
address_line2: "London", service = Imports::SaleRangesService.new(start_year:, path:)
postcode: "SW1P 4DF", service.call
holds_own_stock: true, end
other_stock_owners: "None", end
managing_agents_label: "None",
provider_type: "LA", first_run = Organisation.count.zero?
)
all_rent_periods = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]
standalone_no_stock = Organisation.find_or_create_by!( mhclg = FactoryBot.create(
name: "Standalone No Stock 1 Ltd", :organisation,
:if_unique,
name: "MHCLG",
address_line1: "2 Marsham Street", address_line1: "2 Marsham Street",
address_line2: "London", address_line2: "London",
postcode: "SW1P 4DF", postcode: "SW1P 4DF",
holds_own_stock: false, holds_own_stock: true,
other_stock_owners: "None", other_stock_owners: "None",
managing_agents_label: "None", managing_agents_label: "None",
provider_type: "LA", provider_type: "LA",
) housing_registration_no: nil,
rent_periods: all_rent_periods,
User.find_or_create_by!(
name: "Provider Owns Stock",
email: "provider.owner1@example.com",
organisation: standalone_owns_stock,
role: "data_provider",
is_dpo: true,
) do |user|
user.password = ENV["REVIEW_APP_USER_PASSWORD"]
user.confirmed_at = Time.zone.now
create_data_protection_confirmation(user)
end
User.find_or_create_by!(
name: "Coordinator Owns Stock",
email: "coordinator.owner1@example.com",
organisation: standalone_owns_stock,
role: "data_coordinator",
is_dpo: true,
) do |user|
user.password = ENV["REVIEW_APP_USER_PASSWORD"]
user.confirmed_at = Time.zone.now
create_data_protection_confirmation(user)
end
User.find_or_create_by!(
name: "Provider No Stock",
email: "provider.nostock@example.com",
organisation: standalone_no_stock,
role: "data_provider",
is_dpo: true,
) do |user|
user.password = ENV["REVIEW_APP_USER_PASSWORD"]
user.confirmed_at = Time.zone.now
create_data_protection_confirmation(user)
end
User.find_or_create_by!(
name: "Coordinator No Stock",
email: "coordinator.nostock@example.com",
organisation: standalone_no_stock,
role: "data_coordinator",
) do |user|
user.password = ENV["REVIEW_APP_USER_PASSWORD"]
user.confirmed_at = Time.zone.now
end
User.find_or_create_by!(
name: "Stock owner 1",
email: "stock_owner1_dpo@example.com",
organisation: stock_owner1,
role: "data_coordinator",
is_dpo: true,
) do |user|
user.password = ENV["REVIEW_APP_USER_PASSWORD"]
user.confirmed_at = Time.zone.now
create_data_protection_confirmation(user)
end
User.find_or_create_by!(
name: "Stock owner 2",
email: "stock_owner2_dpo@example.com",
organisation: stock_owner2,
role: "data_coordinator",
is_dpo: true,
) do |user|
user.password = ENV["REVIEW_APP_USER_PASSWORD"]
user.confirmed_at = Time.zone.now
create_data_protection_confirmation(user)
end
User.find_or_create_by!(
name: "Managing agent 1",
email: "managing_agent1_dpo@example.com",
organisation: managing_agent1,
role: "data_coordinator",
is_dpo: true,
) do |user|
user.password = ENV["REVIEW_APP_USER_PASSWORD"]
user.confirmed_at = Time.zone.now
create_data_protection_confirmation(user)
end
User.find_or_create_by!(
name: "Managing agent 2",
email: "managing_agent2_dpo@example.com",
organisation: managing_agent2,
role: "data_coordinator",
is_dpo: true,
) do |user|
user.password = ENV["REVIEW_APP_USER_PASSWORD"]
user.confirmed_at = Time.zone.now
create_data_protection_confirmation(user)
end
OrganisationRelationship.find_or_create_by!(
parent_organisation: stock_owner1,
child_organisation: org,
)
OrganisationRelationship.find_or_create_by!(
parent_organisation: stock_owner2,
child_organisation: org,
)
OrganisationRelationship.find_or_create_by!(
parent_organisation: org,
child_organisation: managing_agent1,
)
OrganisationRelationship.find_or_create_by!(
parent_organisation: org,
child_organisation: managing_agent2,
) )
if Rails.env.development? || Rails.env.review? if Rails.env.development? || Rails.env.review?
User.find_or_create_by!( stock_owner1 = FactoryBot.create(:organisation, :if_unique, :la, :holds_own_stock, name: "Stock Owner 1", rent_periods: all_rent_periods)
name: "Provider", stock_owner2 = FactoryBot.create(:organisation, :if_unique, :la, :holds_own_stock, name: "Stock Owner 2", rent_periods: all_rent_periods.sample(5))
email: "provider@example.com", managing_agent1 = FactoryBot.create(:organisation, :if_unique, :prp, :holds_own_stock, name: "Managing Agent 1 (PRP)", rent_periods: all_rent_periods)
organisation: org, managing_agent2 = FactoryBot.create(:organisation, :if_unique, :la, :holds_own_stock, name: "Managing Agent 2", rent_periods: all_rent_periods.sample(5))
role: "data_provider", standalone_owns_stock = FactoryBot.create(:organisation, :if_unique, :la, :holds_own_stock, name: "Standalone Owns Stock 1 Ltd", rent_periods: all_rent_periods)
) do |user| standalone_no_stock = FactoryBot.create(:organisation, :if_unique, :la, :does_not_own_stock, name: "Standalone No Stock 1 Ltd", rent_periods: all_rent_periods)
user.password = ENV["REVIEW_APP_USER_PASSWORD"]
user.confirmed_at = Time.zone.now other_orgs = FactoryBot.create_list(:organisation, 5, :prp, rent_periods: all_rent_periods.sample(3)) if first_run
end
OrganisationRelationship.find_or_create_by!(
parent_organisation: stock_owner1,
child_organisation: mhclg,
)
OrganisationRelationship.find_or_create_by!(
parent_organisation: stock_owner2,
child_organisation: mhclg,
)
OrganisationRelationship.find_or_create_by!(
parent_organisation: mhclg,
child_organisation: managing_agent1,
)
OrganisationRelationship.find_or_create_by!(
parent_organisation: mhclg,
child_organisation: managing_agent2,
)
User.find_or_create_by!( provider = find_or_create_user(mhclg, "provider@example.com", "Provider", :data_provider)
name: "Coordinator", coordinator = find_or_create_user(mhclg, "coordinator@example.com", "Coordinator", :data_coordinator)
email: "coordinator@example.com", support = find_or_create_user(mhclg, "support@example.com", "Support", :support)
organisation: org,
role: "data_coordinator",
is_dpo: true,
) do |user|
user.password = ENV["REVIEW_APP_USER_PASSWORD"]
user.confirmed_at = Time.zone.now
user.is_dpo = true
create_data_protection_confirmation(user)
end
support_user = User.find_or_create_by!( stock_owner1_user = find_or_create_user(stock_owner1, "stock_owner1_dpo@example.com", "Stock owner 1", :data_coordinator)
name: "Support", stock_owner2_user = find_or_create_user(stock_owner2, "stock_owner2_dpo@example.com", "Stock owner 2", :data_coordinator)
email: "support@example.com",
organisation: org,
role: "support",
is_dpo: true,
) do |user|
user.password = ENV["REVIEW_APP_USER_PASSWORD"]
user.confirmed_at = Time.zone.now
create_data_protection_confirmation(user)
end
pp "Seeded dummy users" managing_agent1_user = find_or_create_user(managing_agent1, "managing_agent1_dpo@example.com", "Managing agent 1", :data_coordinator)
end managing_agent2_user = find_or_create_user(managing_agent2, "managing_agent2_dpo@example.com", "Managing agent 2", :data_coordinator)
if (Rails.env.development? || Rails.env.review?) && SalesLog.count.zero? provider_owner1 = find_or_create_user(standalone_owns_stock, "provider.owner1@example.com", "Provider Owns Stock", :data_provider)
SalesLog.find_or_create_by!( coordinator_owner1 = find_or_create_user(standalone_owns_stock, "coordinator.owner1@example.com", "Coordinator Owns Stock", :data_coordinator)
assigned_to: support_user,
owning_organisation: org,
managing_organisation: org,
saledate: Time.zone.today,
purchid: "1",
ownershipsch: 1,
type: 2,
jointpur: 1,
jointmore: 1,
)
SalesLog.find_or_create_by!( find_or_create_user(standalone_no_stock, "provider.nostock@example.com", "Provider No Stock", :data_provider)
assigned_to: support_user, find_or_create_user(standalone_no_stock, "coordinator.nostock@example.com", "Coordinator No Stock", :data_coordinator)
owning_organisation: org,
managing_organisation: org,
saledate: Time.zone.today,
purchid: "1",
ownershipsch: 2,
type: 9,
jointpur: 1,
jointmore: 1,
)
SalesLog.find_or_create_by!( if Scheme.count.zero?
assigned_to: support_user, beulahside = FactoryBot.create(:scheme, service_name: "Beulahside Care", owning_organisation: mhclg)
owning_organisation: org, abdullah = FactoryBot.create(:scheme, service_name: "Abdullahview Point", owning_organisation: mhclg)
managing_organisation: org,
saledate: Time.zone.today,
purchid: "1",
ownershipsch: 3,
type: 10,
companybuy: 1,
)
pp "Seeded a sales log of each type" FactoryBot.create(:location, scheme: beulahside, name: "Rectory Road", postcode: "CU193AA", location_code: "E09000033", location_admin_district: "Westminster", type_of_unit: 4, mobility_type: "N")
end FactoryBot.create(:location, scheme: beulahside, name: "Smithy Lane", postcode: "DM25ODC", location_code: "E09000033", location_admin_district: "Westminster", type_of_unit: 1, mobility_type: "W")
FactoryBot.create(:location, scheme: abdullah, name: "Smithy Lane", postcode: "YX130WP", location_code: "E09000033", location_admin_district: "Westminster", type_of_unit: 2, mobility_type: "W")
if Rails.env.development? || Rails.env.review? mhclg_scheme = FactoryBot.create(:scheme, :created_now, owning_organisation: mhclg)
dummy_org = Organisation.find_or_create_by!( stock_owner_scheme = FactoryBot.create(:scheme, owning_organisation: stock_owner1)
name: "FooBar LTD",
address_line1: "Higher Kingston",
address_line2: "Yeovil",
postcode: "BA21 4AT",
holds_own_stock: true,
other_stock_owners: "None",
managing_agents_label: "None",
provider_type: "LA",
)
pp "Seeded dummy FooBar LTD organisation" other_schemes = first_run ? other_orgs.sample(3).map { |org| FactoryBot.create(:scheme, owning_organisation: org) } : []
User.find_or_create_by!( [mhclg_scheme, stock_owner_scheme, *other_schemes].each do |scheme|
name: "Dummy user", FactoryBot.create(:location, scheme:)
email: "dummy_org@example.com", end
organisation: dummy_org, [beulahside, mhclg_scheme, *other_schemes].each do |scheme|
role: "data_provider", FactoryBot.create_list(:location, 3, scheme:)
is_dpo: true, end
) do |user|
user.password = ENV["REVIEW_APP_USER_PASSWORD"]
user.confirmed_at = Time.zone.now
create_data_protection_confirmation(user)
end end
end
if (Rails.env.development? || Rails.env.review?) && Scheme.count.zero? other_org_users = first_run ? other_orgs.map { |org| org.users.first } : []
scheme1 = Scheme.create!( users_with_logs = [provider, coordinator, support, stock_owner1_user, stock_owner2_user, managing_agent1_user, managing_agent2_user, provider_owner1, coordinator_owner1, *other_org_users]
service_name: "Beulahside Care",
sensitive: 0,
registered_under_care_act: 1,
support_type: 2,
scheme_type: 4,
intended_stay: "M",
primary_client_group: "O",
has_other_client_group: 1,
secondary_client_group: "H",
owning_organisation: org,
arrangement_type: "D",
confirmed: true,
created_at: Time.zone.now,
)
scheme2 = Scheme.create!( if SalesLog.count.zero?
service_name: "Abdullahview Point", users_with_logs.each do |user|
sensitive: 0, FactoryBot.create(:sales_log, :shared_ownership_setup_complete, assigned_to: user)
registered_under_care_act: 1, FactoryBot.create(:sales_log, :discounted_ownership_setup_complete, assigned_to: user)
support_type: 2, FactoryBot.create(:sales_log, :outright_sale_setup_complete, assigned_to: user) if Time.zone.today < Time.zone.local(2025, 4, 1)
scheme_type: 5, FactoryBot.create(:sales_log, :completed, assigned_to: user)
intended_stay: "S", FactoryBot.create_list(:sales_log, 2, :completed, :ignore_validation_errors, saledate: Time.zone.today - 1.year, assigned_to: user)
primary_client_group: "D",
secondary_client_group: "E",
has_other_client_group: 1,
owning_organisation: org,
arrangement_type: "D",
confirmed: true,
created_at: Time.zone.now,
)
Scheme.create!( next unless FeatureToggle.allow_future_form_use?
service_name: "Caspermouth Center",
sensitive: 1,
registered_under_care_act: 1,
support_type: 4,
scheme_type: 7,
intended_stay: "X",
primary_client_group: "G",
has_other_client_group: 1,
secondary_client_group: "R",
owning_organisation: dummy_org,
arrangement_type: "D",
confirmed: true,
created_at: Time.zone.now,
)
Location.create!( FactoryBot.create(:sales_log, :shared_ownership_setup_complete, saledate: Time.zone.today + 1.year, assigned_to: user)
scheme: scheme1, FactoryBot.create(:sales_log, :discounted_ownership_setup_complete, saledate: Time.zone.today + 1.year, assigned_to: user)
location_code: "E09000033", FactoryBot.create(:sales_log, :completed, saledate: Time.zone.today + 1.year, assigned_to: user)
location_admin_district: "Westminster", end
postcode: "CU193AA",
name: "Rectory Road",
type_of_unit: 4,
units: 1,
mobility_type: "N",
)
Location.create!( FactoryBot.create(:sales_log, :completed, assigned_to: managing_agent1_user, owning_organisation: mhclg)
scheme: scheme1, FactoryBot.create(:sales_log, :completed, assigned_to: provider, owning_organisation: stock_owner1)
location_code: "E09000033",
location_admin_district: "Westminster",
postcode: "DM250DC",
name: "Smithy Lane",
type_of_unit: 1,
units: 1,
mobility_type: "W",
)
Location.create!(
scheme: scheme2,
location_code: "E09000033",
location_admin_district: "Westminster",
postcode: "YX130WP",
name: "Smithy Lane",
type_of_unit: 2,
units: 1,
mobility_type: "W",
)
pp "Seeded dummy schemes"
end
if LocalAuthority.count.zero?
la_path = "config/local_authorities_data/initial_local_authorities.csv"
service = Imports::LocalAuthoritiesService.new(path: la_path)
service.call
end
if (Rails.env.development? || Rails.env.review?) && LocalAuthorityLink.count.zero?
links_data_paths = ["config/local_authorities_data/local_authority_links_2023.csv", "config/local_authorities_data/local_authority_links_2022.csv"]
links_data_paths.each do |path|
service = Imports::LocalAuthorityLinksService.new(path:)
service.call
end end
pp "Seeded local authority links" if LettingsLog.count.zero?
end users_with_logs.each do |user|
FactoryBot.create(:lettings_log, :setup_completed, assigned_to: user)
if LaRentRange.count.zero? FactoryBot.create(:lettings_log, :completed, assigned_to: user)
Dir.glob("config/rent_range_data/*.csv").each do |path| if user.organisation.owned_schemes.any?
start_year = File.basename(path, ".csv") scheme = user.organisation.owned_schemes.first
service = Imports::RentRangesService.new(start_year:, path:) FactoryBot.create(:lettings_log, :setup_completed, :sh, scheme:, location: scheme.locations.first, assigned_to: user)
service.call end
FactoryBot.create_list(:lettings_log, 2, :completed, :ignore_validation_errors, startdate: Time.zone.today - 1.year, assigned_to: user)
next unless FeatureToggle.allow_future_form_use?
FactoryBot.create(:lettings_log, :setup_completed, startdate: Time.zone.today + 1.year, assigned_to: user)
FactoryBot.create(:lettings_log, :completed, startdate: Time.zone.today + 1.year, assigned_to: user)
if user.organisation.owned_schemes.any?
scheme = user.organisation.owned_schemes.first
FactoryBot.create(:lettings_log, :setup_completed, :sh, scheme:, location: scheme.locations.first, startdate: Time.zone.today + 1.year, assigned_to: user)
end
end
FactoryBot.create(:lettings_log, :completed, assigned_to: managing_agent1_user, owning_organisation: mhclg)
FactoryBot.create(:lettings_log, :completed, assigned_to: provider, owning_organisation: stock_owner1)
end end
end
if LaSaleRange.count.zero? if LocalAuthorityLink.count.zero?
Dir.glob("config/sale_range_data/*.csv").each do |path| links_data_paths = ["config/local_authorities_data/local_authority_links_2023.csv", "config/local_authorities_data/local_authority_links_2022.csv"]
start_year = File.basename(path, ".csv") links_data_paths.each do |path|
service = Imports::SaleRangesService.new(start_year:, path:) service = Imports::LocalAuthorityLinksService.new(path:)
service.call service.call
end
end end
end end
end end
@ -440,4 +179,3 @@ if LocalAuthority.count.zero?
service = Imports::LocalAuthoritiesService.new(path:) service = Imports::LocalAuthoritiesService.new(path:)
service.call service.call
end end
# rubocop:enable Rails/Output

2
spec/components/check_answers_summary_list_card_component_spec.rb

@ -6,7 +6,7 @@ RSpec.describe CheckAnswersSummaryListCardComponent, type: :component do
let(:rendered) { render_inline(component) } let(:rendered) { render_inline(component) }
let(:user) { create(:user) } let(:user) { create(:user) }
let(:log) { create(:lettings_log, :completed, age2: 99, retirement_value_check: 1) } let(:log) { create(:lettings_log, :completed, sex1: "F", age2: 99, retirement_value_check: 1) }
let(:subsection_id) { "household_characteristics" } let(:subsection_id) { "household_characteristics" }
let(:subsection) { log.form.get_subsection(subsection_id) } let(:subsection) { log.form.get_subsection(subsection_id) }
let(:questions) { subsection.applicable_questions(log) } let(:questions) { subsection.applicable_questions(log) }

4
spec/components/lettings_log_summary_component_spec.rb

@ -3,9 +3,11 @@ require "rails_helper"
RSpec.describe LettingsLogSummaryComponent, type: :component do RSpec.describe LettingsLogSummaryComponent, type: :component do
let(:support_user) { FactoryBot.create(:user, :support) } let(:support_user) { FactoryBot.create(:user, :support) }
let(:coordinator_user) { FactoryBot.create(:user) } let(:coordinator_user) { FactoryBot.create(:user) }
let(:organisation) { create(:organisation, name: "MHCLG") }
let(:log_user) { create(:user, name: "Danny Rojas", organisation:) }
let(:propcode) { "P3647" } let(:propcode) { "P3647" }
let(:tenancycode) { "T62863" } let(:tenancycode) { "T62863" }
let(:lettings_log) { FactoryBot.create(:lettings_log, needstype: 1, tenancycode:, propcode:, startdate: Time.zone.today) } let(:lettings_log) { FactoryBot.create(:lettings_log, assigned_to: log_user, needstype: 1, tenancycode:, propcode:, startdate: Time.zone.today) }
context "when rendering lettings log for a support user" do context "when rendering lettings log for a support user" do
it "shows the log summary with organisational relationships" do it "shows the log summary with organisational relationships" do

2
spec/components/sales_log_summary_component_spec.rb

@ -16,7 +16,7 @@ RSpec.describe SalesLogSummaryComponent, type: :component do
it "shows the log summary with organisational relationships" do it "shows the log summary with organisational relationships" do
result = render_inline(described_class.new(current_user: support_user, log: sales_log)) result = render_inline(described_class.new(current_user: support_user, log: sales_log))
expect(result).to have_content("Owned by\n MHCLG") expect(result).to have_content("Owned by\n #{sales_log.owning_organisation.name}")
expect(result).not_to have_content("Managed by") expect(result).not_to have_content("Managed by")
end end
end end

10
spec/factories/lettings_log.rb

@ -56,8 +56,8 @@ FactoryBot.define do
status { 2 } status { 2 }
tenancycode { Faker::Name.initials(number: 10) } tenancycode { Faker::Name.initials(number: 10) }
age1_known { 0 } age1_known { 0 }
age1 { 35 } age1 { Faker::Number.within(range: 25..45) }
sex1 { "F" } sex1 { %w[F M X R].sample }
ethnic_group { 0 } ethnic_group { 0 }
ethnic { 2 } ethnic { 2 }
national { 13 } national { 13 }
@ -67,8 +67,8 @@ FactoryBot.define do
relat2 { "P" } relat2 { "P" }
age2_known { 0 } age2_known { 0 }
details_known_2 { 0 } details_known_2 { 0 }
age2 { 32 } age2 { Faker::Number.within(range: 25..45) }
sex2 { "M" } sex2 { %w[F M X R].sample }
ecstat2 { 6 } ecstat2 { 6 }
homeless { 1 } homeless { 1 }
underoccupation_benefitcap { 0 } underoccupation_benefitcap { 0 }
@ -163,7 +163,7 @@ FactoryBot.define do
uprn_known { 0 } uprn_known { 0 }
joint { 3 } joint { 3 }
address_line1 { "Address line 1" } address_line1 { "Address line 1" }
town_or_city { "London" } town_or_city { Faker::Address.city }
ppcodenk { 1 } ppcodenk { 1 }
tshortfall_known { 1 } tshortfall_known { 1 }
after(:build) do |log, _evaluator| after(:build) do |log, _evaluator|

20
spec/factories/organisation.rb

@ -1,11 +1,11 @@
FactoryBot.define do FactoryBot.define do
factory :organisation do factory :organisation do
name { "MHCLG" } name { Faker::Company.name }
address_line1 { "2 Marsham Street" } address_line1 { Faker::Address.street_address }
address_line2 { "London" } address_line2 { Faker::Address.city }
provider_type { "LA" } provider_type { "LA" }
housing_registration_no { "1234" } housing_registration_no { rand(99_999).to_s }
postcode { "SW1P 4DF" } postcode { Faker::Address.postcode }
created_at { Time.zone.now } created_at { Time.zone.now }
updated_at { Time.zone.now } updated_at { Time.zone.now }
holds_own_stock { true } holds_own_stock { true }
@ -41,7 +41,13 @@ FactoryBot.define do
trait :prp do trait :prp do
provider_type { "PRP" } provider_type { "PRP" }
end end
trait :la do
provider_type { "LA" }
end
trait :holds_own_stock do
holds_own_stock { true }
end
trait :does_not_own_stock do trait :does_not_own_stock do
holds_own_stock { false } holds_own_stock { false }
end end
@ -53,6 +59,10 @@ FactoryBot.define do
data_protection_confirmation { nil } data_protection_confirmation { nil }
end end
trait :if_unique do
initialize_with { Organisation.find_or_create_by(name:) }
end
end end
factory :organisation_rent_period do factory :organisation_rent_period do

44
spec/factories/sales_log.rb

@ -5,7 +5,7 @@ FactoryBot.define do
created_by { assigned_to } created_by { assigned_to }
owning_organisation { assigned_to.organisation } owning_organisation { assigned_to.organisation }
managing_organisation { owning_organisation } managing_organisation { assigned_to.organisation }
created_at { Time.zone.now } created_at { Time.zone.now }
updated_at { Time.zone.now } updated_at { Time.zone.now }
trait :in_progress do trait :in_progress do
@ -32,6 +32,17 @@ FactoryBot.define do
jointpur { 2 } jointpur { 2 }
noint { 2 } noint { 2 }
privacynotice { 1 } privacynotice { 1 }
purchid { rand(999_999_999).to_s }
end
trait :discounted_ownership_setup_complete do
saledate_today
ownershipsch { 2 }
type { 9 }
jointpur { 1 }
jointmore { 1 }
noint { 2 }
privacynotice { 1 }
purchid { rand(999_999_999).to_s }
end end
trait :outright_sale_setup_complete do trait :outright_sale_setup_complete do
saledate_today saledate_today
@ -67,14 +78,14 @@ FactoryBot.define do
noint { 2 } noint { 2 }
privacynotice { 1 } privacynotice { 1 }
age1_known { 0 } age1_known { 0 }
age1 { 30 } age1 { Faker::Number.within(range: 27..45) }
sex1 { "X" } sex1 { %w[F M X R].sample }
national { 18 } national { 18 }
buy1livein { 1 } buy1livein { 1 }
relat2 { "P" } relat2 { "P" }
proptype { 1 } proptype { 1 }
age2_known { 0 } age2_known { 0 }
age2 { 35 } age2 { Faker::Number.within(range: 25..45) }
builtype { 1 } builtype { 1 }
ethnic { 3 } ethnic { 3 }
ethnic_group { 17 } ethnic_group { 17 }
@ -104,16 +115,16 @@ FactoryBot.define do
inc2mort { 1 } inc2mort { 1 }
uprn_known { 0 } uprn_known { 0 }
address_line1 { "Address line 1" } address_line1 { "Address line 1" }
town_or_city { "Town or city" } town_or_city { Faker::Address.city }
la_known { 1 } la_known { 1 }
la { "E09000003" } la { "E09000003" }
savingsnk { 1 } savingsnk { 1 }
prevown { 1 } prevown { 1 }
prevshared { 2 } prevshared { 2 }
sex3 { "X" } sex3 { %w[F M X R].sample }
sex4 { "X" } sex4 { %w[F M X R].sample }
sex5 { "X" } sex5 { %w[F M X R].sample }
sex6 { "X" } sex6 { %w[F M X R].sample }
mortgage { 20_000 } mortgage { 20_000 }
ecstat3 { 9 } ecstat3 { 9 }
ecstat4 { 3 } ecstat4 { 3 }
@ -122,6 +133,7 @@ FactoryBot.define do
disabled { 1 } disabled { 1 }
deposit { 80_000 } deposit { 80_000 }
value { 110_000 } value { 110_000 }
value_value_check { 0 }
grant { 10_000 } grant { 10_000 }
proplen { 10 } proplen { 10 }
pregyrha { 1 } pregyrha { 1 }
@ -161,6 +173,13 @@ FactoryBot.define do
log.uprn = "10033558653" log.uprn = "10033558653"
log.uprn_selection = 1 log.uprn_selection = 1
end end
if log.saledate >= Time.zone.local(2025, 4, 1)
log.relat2 = "X" if log.relat2 == "C"
log.relat3 = "X" if log.relat3 == "C"
log.relat4 = "X" if log.relat4 == "C"
log.relat5 = "X" if log.relat5 == "C"
log.relat6 = "X" if log.relat6 == "C"
end
end end
end end
trait :with_uprn do trait :with_uprn do
@ -174,5 +193,12 @@ FactoryBot.define do
trait :imported do trait :imported do
old_id { Random.hex } old_id { Random.hex }
end end
trait :ignore_validation_errors do
to_create do |instance|
instance.valid?
instance.errors.clear
instance.save!(validate: false)
end
end
end end
end end

3
spec/factories/scheme.rb

@ -41,5 +41,8 @@ FactoryBot.define do
support_type { 2 } support_type { 2 }
intended_stay { "M" } intended_stay { "M" }
end end
trait :created_now do
created_at { Time.zone.now }
end
end end
end end

6
spec/factories/user.rb

@ -1,7 +1,7 @@
FactoryBot.define do FactoryBot.define do
factory :user do factory :user do
sequence(:email) { "test#{SecureRandom.hex}@example.com" } sequence(:email) { "test#{SecureRandom.hex}@example.com" }
name { "Danny Rojas" } name { Faker::Name.name }
password { "pAssword1" } password { "pAssword1" }
organisation { association :organisation, with_dsa: is_dpo ? false : true } organisation { association :organisation, with_dsa: is_dpo ? false : true }
role { "data_provider" } role { "data_provider" }
@ -40,5 +40,9 @@ FactoryBot.define do
) )
end end
end end
trait :if_unique do
initialize_with { User.find_or_create_by(email:) }
end
end end
end end

4
spec/features/lettings_log_spec.rb

@ -276,7 +276,7 @@ RSpec.describe "Lettings Log Features" do
expect(breadcrumbs.length).to eq 3 expect(breadcrumbs.length).to eq 3
expect(breadcrumbs[0].text).to eq "Home" expect(breadcrumbs[0].text).to eq "Home"
expect(breadcrumbs[0][:href]).to eq root_path expect(breadcrumbs[0][:href]).to eq root_path
expect(breadcrumbs[1].text).to eq "Lettings logs (MHCLG)" expect(breadcrumbs[1].text).to eq "Lettings logs (#{lettings_log.owning_organisation.name})"
expect(breadcrumbs[1][:href]).to eq lettings_logs_organisation_path(lettings_log.owning_organisation) expect(breadcrumbs[1][:href]).to eq lettings_logs_organisation_path(lettings_log.owning_organisation)
expect(breadcrumbs[2].text).to eq "Log #{lettings_log.id}" expect(breadcrumbs[2].text).to eq "Log #{lettings_log.id}"
expect(breadcrumbs[2][:href]).to eq lettings_log_path(lettings_log) expect(breadcrumbs[2][:href]).to eq lettings_log_path(lettings_log)
@ -292,7 +292,7 @@ RSpec.describe "Lettings Log Features" do
expect(breadcrumbs.length).to eq 3 expect(breadcrumbs.length).to eq 3
expect(breadcrumbs[0].text).to eq "Home" expect(breadcrumbs[0].text).to eq "Home"
expect(breadcrumbs[0][:href]).to eq root_path expect(breadcrumbs[0][:href]).to eq root_path
expect(breadcrumbs[1].text).to eq "Lettings logs (MHCLG)" expect(breadcrumbs[1].text).to eq "Lettings logs (#{lettings_log.owning_organisation.name})"
expect(breadcrumbs[1][:href]).to eq lettings_logs_organisation_path(lettings_log.owning_organisation) expect(breadcrumbs[1][:href]).to eq lettings_logs_organisation_path(lettings_log.owning_organisation)
expect(breadcrumbs[2].text).to eq "Log #{lettings_log.id}" expect(breadcrumbs[2].text).to eq "Log #{lettings_log.id}"
expect(breadcrumbs[2][:href]).to eq lettings_log_path(lettings_log) expect(breadcrumbs[2][:href]).to eq lettings_log_path(lettings_log)

4
spec/features/sales_log_spec.rb

@ -259,7 +259,7 @@ RSpec.describe "Sales Log Features" do
expect(breadcrumbs.length).to eq 3 expect(breadcrumbs.length).to eq 3
expect(breadcrumbs[0].text).to eq "Home" expect(breadcrumbs[0].text).to eq "Home"
expect(breadcrumbs[0][:href]).to eq root_path expect(breadcrumbs[0][:href]).to eq root_path
expect(breadcrumbs[1].text).to eq "Sales logs (MHCLG)" expect(breadcrumbs[1].text).to eq "Sales logs (#{sales_log.owning_organisation.name})"
expect(breadcrumbs[1][:href]).to eq sales_logs_organisation_path(sales_log.owning_organisation) expect(breadcrumbs[1][:href]).to eq sales_logs_organisation_path(sales_log.owning_organisation)
expect(breadcrumbs[2].text).to eq "Log #{sales_log.id}" expect(breadcrumbs[2].text).to eq "Log #{sales_log.id}"
expect(breadcrumbs[2][:href]).to eq sales_log_path(sales_log.id) expect(breadcrumbs[2][:href]).to eq sales_log_path(sales_log.id)
@ -273,7 +273,7 @@ RSpec.describe "Sales Log Features" do
expect(breadcrumbs.length).to eq 3 expect(breadcrumbs.length).to eq 3
expect(breadcrumbs[0].text).to eq "Home" expect(breadcrumbs[0].text).to eq "Home"
expect(breadcrumbs[0][:href]).to eq root_path expect(breadcrumbs[0][:href]).to eq root_path
expect(breadcrumbs[1].text).to eq "Sales logs (MHCLG)" expect(breadcrumbs[1].text).to eq "Sales logs (#{sales_log.owning_organisation.name})"
expect(breadcrumbs[1][:href]).to eq sales_logs_organisation_path(sales_log.owning_organisation) expect(breadcrumbs[1][:href]).to eq sales_logs_organisation_path(sales_log.owning_organisation)
expect(breadcrumbs[2].text).to eq "Log #{sales_log.id}" expect(breadcrumbs[2].text).to eq "Log #{sales_log.id}"
expect(breadcrumbs[2][:href]).to eq sales_log_path(sales_log.id) expect(breadcrumbs[2][:href]).to eq sales_log_path(sales_log.id)

9
spec/features/schemes_spec.rb

@ -5,9 +5,10 @@ RSpec.describe "Schemes scheme Features" do
include SchemesHelpers include SchemesHelpers
context "when viewing list of schemes" do context "when viewing list of schemes" do
context "when I am signed as a coordinator user and there are schemes in the database" do context "when I am signed as a coordinator user and there are schemes in the database" do
let!(:user) { FactoryBot.create(:user, :data_coordinator, last_sign_in_at: Time.zone.now) } let(:organisation) { FactoryBot.create(:organisation, name: "MHCLG") }
let!(:schemes) { FactoryBot.create_list(:scheme, 5, owning_organisation: user.organisation) } let!(:user) { FactoryBot.create(:user, :data_coordinator, organisation:, last_sign_in_at: Time.zone.now) }
let!(:scheme_to_search) { FactoryBot.create(:scheme, owning_organisation: user.organisation) } let!(:schemes) { FactoryBot.create_list(:scheme, 5, owning_organisation: organisation) }
let!(:scheme_to_search) { FactoryBot.create(:scheme, owning_organisation: organisation) }
before do before do
Timecop.freeze(Time.zone.local(2024, 3, 1)) Timecop.freeze(Time.zone.local(2024, 3, 1))
@ -225,7 +226,7 @@ RSpec.describe "Schemes scheme Features" do
end end
it "shows list of links to the organisation's schemes" do it "shows list of links to the organisation's schemes" do
click_on("Schemes (MHCLG)") click_on("Schemes (#{user.organisation.name})")
same_organisation_schemes.each do |scheme| same_organisation_schemes.each do |scheme|
expect(page).to have_link(scheme.service_name) expect(page).to have_link(scheme.service_name)
expect(page).to have_content(scheme.id_to_display) expect(page).to have_content(scheme.id_to_display)

2
spec/helpers/organisations_helper_spec.rb

@ -3,7 +3,7 @@ require "rails_helper"
RSpec.describe OrganisationsHelper do RSpec.describe OrganisationsHelper do
include TagHelper include TagHelper
describe "display_organisation_attributes" do describe "display_organisation_attributes" do
let(:organisation) { create(:organisation) } let(:organisation) { create(:organisation, :la, :holds_own_stock, address_line1: "2 Marsham Street", address_line2: "London", postcode: "SW1P 4DF", housing_registration_no: 1234, organisation_rent_periods: []) }
it "has the correct values" do it "has the correct values" do
expect(display_organisation_attributes(organisation)).to eq( expect(display_organisation_attributes(organisation)).to eq(

2
spec/helpers/tab_nav_helper_spec.rb

@ -15,7 +15,7 @@ RSpec.describe TabNavHelper do
describe "#org_cell" do describe "#org_cell" do
it "returns the users org name and role separated by a newline character" do it "returns the users org name and role separated by a newline character" do
expected_html = "MHCLG\n<span class=\"app-!-colour-muted\">Data provider</span>" expected_html = "#{organisation.name}\n<span class=\"app-!-colour-muted\">Data provider</span>"
expect(org_cell(current_user)).to match(expected_html) expect(org_cell(current_user)).to match(expected_html)
end end
end end

2
spec/models/form_spec.rb

@ -329,7 +329,7 @@ RSpec.describe Form, type: :model do
end end
context "when a value is changed such that a radio and free input questions are no longer routed to" do context "when a value is changed such that a radio and free input questions are no longer routed to" do
let(:log) { FactoryBot.create(:lettings_log, :completed, startdate: now) } let(:log) { FactoryBot.create(:lettings_log, :completed, startdate: now, hhmemb: 2, details_known_2: 0, sex2: "M", relat2: "P", age2_known: 0, age2: 32, ecstat2: 6) }
it "all attributes relating to that checkbox question are cleared" do it "all attributes relating to that checkbox question are cleared" do
expect(log.hhmemb).to be 2 expect(log.hhmemb).to be 2

2
spec/models/organisation_spec.rb

@ -207,7 +207,7 @@ RSpec.describe Organisation, type: :model do
end end
describe "paper trail" do describe "paper trail" do
let(:organisation) { create(:organisation) } let(:organisation) { create(:organisation, name: "MHCLG") }
it "creates a record of changes to a log" do it "creates a record of changes to a log" do
expect { organisation.update!(name: "new test name") }.to change(organisation.versions, :count).by(1) expect { organisation.update!(name: "new test name") }.to change(organisation.versions, :count).by(1)

2
spec/models/user_spec.rb

@ -380,7 +380,7 @@ RSpec.describe User, type: :model do
end end
describe "paper trail" do describe "paper trail" do
let(:user) { create(:user) } let(:user) { create(:user, name: "Danny Rojas") }
it "creates a record of changes to a log" do it "creates a record of changes to a log" do
expect { user.update!(name: "new test name") }.to change(user.versions, :count).by(1) expect { user.update!(name: "new test name") }.to change(user.versions, :count).by(1)

12
spec/requests/merge_requests_controller_spec.rb

@ -49,7 +49,7 @@ RSpec.describe MergeRequestsController, type: :request do
end end
it "shows the correct content" do it "shows the correct content" do
expect(page).to have_content("Which organisations are merging into MHCLG?") expect(page).to have_content("Which organisations are merging into #{organisation.name}?")
end end
end end
end end
@ -64,7 +64,7 @@ RSpec.describe MergeRequestsController, type: :request do
it "adds merging organisation to the page" do it "adds merging organisation to the page" do
merge_request.reload merge_request.reload
expect(page).to have_content("MHCLG") expect(page).to have_content(organisation.name)
expect(page).to have_content("Other Test Org") expect(page).to have_content("Other Test Org")
expect(page).to have_link("Remove") expect(page).to have_link("Remove")
end end
@ -657,7 +657,7 @@ RSpec.describe MergeRequestsController, type: :request do
it "shows user outcomes after merge" do it "shows user outcomes after merge" do
expect(page).to have_link("View all 4 Organisation with some users users (opens in a new tab)", href: users_organisation_path(organisation_with_some_users)) expect(page).to have_link("View all 4 Organisation with some users users (opens in a new tab)", href: users_organisation_path(organisation_with_some_users))
expect(page).to have_link("View all 12 Organisation with many users users (opens in a new tab)", href: users_organisation_path(organisation_with_some_more_users)) expect(page).to have_link("View all 12 Organisation with many users users (opens in a new tab)", href: users_organisation_path(organisation_with_some_more_users))
expect(page).to have_link("View all 3 MHCLG users (opens in a new tab)", href: users_organisation_path(organisation)) expect(page).to have_link("View all 3 #{organisation.name} users (opens in a new tab)", href: users_organisation_path(organisation))
expect(page).to have_content("Organisation with no users and Organisation with no users too have no users.") expect(page).to have_content("Organisation with no users and Organisation with no users too have no users.")
expect(page).to have_content("19 users after merge") expect(page).to have_content("19 users after merge")
end end
@ -684,7 +684,7 @@ RSpec.describe MergeRequestsController, type: :request do
it "shows scheme outcomes after merge" do it "shows scheme outcomes after merge" do
expect(page).to have_link("View all 4 Organisation with some schemes schemes (opens in a new tab)", href: schemes_organisation_path(organisation_with_some_schemes)) expect(page).to have_link("View all 4 Organisation with some schemes schemes (opens in a new tab)", href: schemes_organisation_path(organisation_with_some_schemes))
expect(page).to have_link("View all 6 Organisation with many schemes schemes (opens in a new tab)", href: schemes_organisation_path(organisation_with_some_more_schemes)) expect(page).to have_link("View all 6 Organisation with many schemes schemes (opens in a new tab)", href: schemes_organisation_path(organisation_with_some_more_schemes))
expect(page).to have_link("View all 3 MHCLG schemes (opens in a new tab)", href: schemes_organisation_path(organisation)) expect(page).to have_link("View all 3 #{organisation.name} schemes (opens in a new tab)", href: schemes_organisation_path(organisation))
expect(page).to have_content("Organisation with no schemes and Organisation with no schemes too have no schemes.") expect(page).to have_content("Organisation with no schemes and Organisation with no schemes too have no schemes.")
expect(page).to have_content("13 schemes after merge") expect(page).to have_content("13 schemes after merge")
end end
@ -710,8 +710,8 @@ RSpec.describe MergeRequestsController, type: :request do
it "shows logs outcomes after merge" do it "shows logs outcomes after merge" do
expect(page).to have_link("View all 4 Organisation with some logs lettings logs (opens in a new tab)", href: lettings_logs_organisation_path(organisation_with_some_logs)) expect(page).to have_link("View all 4 Organisation with some logs lettings logs (opens in a new tab)", href: lettings_logs_organisation_path(organisation_with_some_logs))
expect(page).to have_link("View all 2 Organisation with some logs sales logs (opens in a new tab)", href: sales_logs_organisation_path(organisation_with_some_logs)) expect(page).to have_link("View all 2 Organisation with some logs sales logs (opens in a new tab)", href: sales_logs_organisation_path(organisation_with_some_logs))
expect(page).to have_link("View all 2 MHCLG lettings logs (opens in a new tab)", href: lettings_logs_organisation_path(organisation)) expect(page).to have_link("View all 2 #{organisation.name} lettings logs (opens in a new tab)", href: lettings_logs_organisation_path(organisation))
expect(page).to have_link("View all 3 MHCLG sales logs (opens in a new tab)", href: sales_logs_organisation_path(organisation)) expect(page).to have_link("View all 3 #{organisation.name} sales logs (opens in a new tab)", href: sales_logs_organisation_path(organisation))
expect(page).to have_content("Organisation with no logs and Organisation with no logs too have no lettings logs.") expect(page).to have_content("Organisation with no logs and Organisation with no logs too have no lettings logs.")
expect(page).to have_content("Organisation with no logs and Organisation with no logs too have no sales logs.") expect(page).to have_content("Organisation with no logs and Organisation with no logs too have no sales logs.")
expect(page).to have_content("6 lettings logs after merge") expect(page).to have_content("6 lettings logs after merge")

11
spec/requests/organisations_controller_spec.rb

@ -1431,7 +1431,7 @@ RSpec.describe OrganisationsController, type: :request do
end end
context "when a search parameter is passed" do context "when a search parameter is passed" do
let!(:matching_user) { create(:user, organisation:, name: "joe", email: "matching@example.com") } let!(:matching_user) { create(:user, organisation:, name: "abcdefghijklmnopqrstuvwxyz", email: "matching@example.com") }
let(:org_user_count) { User.where(organisation:).count } let(:org_user_count) { User.where(organisation:).count }
before do before do
@ -1439,7 +1439,7 @@ RSpec.describe OrganisationsController, type: :request do
end end
context "when our search string matches case" do context "when our search string matches case" do
let(:search_param) { "joe" } let(:search_param) { "abcdefghijklmnopqrstuvwxyz" }
it "returns only matching results" do it "returns only matching results" do
expect(page).to have_content(matching_user.name) expect(page).to have_content(matching_user.name)
@ -1459,7 +1459,7 @@ RSpec.describe OrganisationsController, type: :request do
end end
context "when we need case insensitive search" do context "when we need case insensitive search" do
let(:search_param) { "Joe" } let(:search_param) { "Abcdefghijklmnopqrstuvwxyz" }
it "returns only matching results" do it "returns only matching results" do
expect(page).to have_content(matching_user.name) expect(page).to have_content(matching_user.name)
@ -1643,6 +1643,11 @@ RSpec.describe OrganisationsController, type: :request do
context "when search results require pagination" do context "when search results require pagination" do
let(:search_param) { "MHCLG" } let(:search_param) { "MHCLG" }
before do
create_list(:organisation, 27, name: "MHCLG")
get "/organisations?search=#{search_param}"
end
it "has search and pagination in the title" do it "has search and pagination in the title" do
expect(page).to have_title("Organisations (27 organisations matching ‘#{search_param}’) (page 1 of 2) - Submit social housing lettings and sales data (CORE) - GOV.UK") expect(page).to have_title("Organisations (27 organisations matching ‘#{search_param}’) (page 1 of 2) - Submit social housing lettings and sales data (CORE) - GOV.UK")
end end

22
spec/requests/users_controller_spec.rb

@ -1264,8 +1264,8 @@ RSpec.describe UsersController, type: :request do
end end
context "when user is signed in as a support user" do context "when user is signed in as a support user" do
let(:user) { create(:user, :support, organisation: create(:organisation, :without_dpc)) } let(:user) { create(:user, :support, name: "Danny Rojas", organisation: create(:organisation, :without_dpc)) }
let(:other_user) { create(:user, organisation: user.organisation, last_sign_in_at: Time.zone.now) } let(:other_user) { create(:user, name: "Danny Rojas", organisation: user.organisation, last_sign_in_at: Time.zone.now) }
before do before do
allow(user).to receive(:need_two_factor_authentication?).and_return(false) allow(user).to receive(:need_two_factor_authentication?).and_return(false)
@ -2002,7 +2002,7 @@ RSpec.describe UsersController, type: :request do
end end
context "when the user is not part of the same organisation as the current user" do context "when the user is not part of the same organisation as the current user" do
let(:other_user) { create(:user) } let(:other_user) { create(:user, organisation: create(:organisation, name: "Another org")) }
let(:params) { { id: other_user.id, user: { name: new_name } } } let(:params) { { id: other_user.id, user: { name: new_name } } }
it "updates the user" do it "updates the user" do
@ -2191,9 +2191,9 @@ RSpec.describe UsersController, type: :request do
context "when different organisations manage the logs" do context "when different organisations manage the logs" do
before do before do
create(:lettings_log, managing_organisation: other_user.organisation, assigned_to: other_user) create(:lettings_log, owning_organisation: other_user.organisation, managing_organisation: other_user.organisation, assigned_to: other_user)
create(:lettings_log, managing_organisation: new_organisation_2, assigned_to: other_user) create(:lettings_log, owning_organisation: other_user.organisation, managing_organisation: new_organisation_2, assigned_to: other_user)
create(:sales_log, managing_organisation: new_organisation_3, assigned_to: other_user) create(:sales_log, owning_organisation: other_user.organisation, managing_organisation: new_organisation_3, assigned_to: other_user)
patch "/users/#{other_user.id}/log-reassignment", headers:, params: patch "/users/#{other_user.id}/log-reassignment", headers:, params:
end end
@ -2209,8 +2209,8 @@ RSpec.describe UsersController, type: :request do
context "when users organisation manages the logs" do context "when users organisation manages the logs" do
before do before do
create(:lettings_log, owning_organisation: other_user.organisation, assigned_to: other_user) create(:lettings_log, owning_organisation: other_user.organisation, managing_organisation: other_user.organisation, assigned_to: other_user)
create(:sales_log, owning_organisation: other_user.organisation, assigned_to: other_user) create(:sales_log, owning_organisation: other_user.organisation, managing_organisation: other_user.organisation, assigned_to: other_user)
patch "/users/#{other_user.id}/log-reassignment", headers:, params: patch "/users/#{other_user.id}/log-reassignment", headers:, params:
end end
@ -2222,15 +2222,15 @@ RSpec.describe UsersController, type: :request do
context "when different organisations manage the logs" do context "when different organisations manage the logs" do
before do before do
create(:lettings_log, owning_organisation: other_user.organisation, assigned_to: other_user) create(:lettings_log, owning_organisation: other_user.organisation, managing_organisation: other_user.organisation, assigned_to: other_user)
create(:lettings_log, owning_organisation: new_organisation_2, assigned_to: other_user) create(:lettings_log, owning_organisation: new_organisation_2, managing_organisation: other_user.organisation, assigned_to: other_user)
create(:sales_log, owning_organisation: new_organisation_3, managing_organisation: other_user.organisation, assigned_to: other_user) create(:sales_log, owning_organisation: new_organisation_3, managing_organisation: other_user.organisation, assigned_to: other_user)
patch "/users/#{other_user.id}/log-reassignment", headers:, params: patch "/users/#{other_user.id}/log-reassignment", headers:, params:
end end
it "required the new org to have managing agent relationship with owning organisations" do it "required the new org to have managing agent relationship with owning organisations" do
expect(response).to have_http_status(:unprocessable_entity) expect(response).to have_http_status(:unprocessable_entity)
expect(page).to have_content("New org must be a managing agent of #{other_user.organisation_name}, #{new_organisation_2.name}, and #{new_organisation_3.name} to make this change.") expect(page).to have_content("New org must be a managing agent of #{other_user.organisation.name}, #{new_organisation_2.name}, and #{new_organisation_3.name} to make this change.")
end end
end end
end end

4
spec/services/csv/lettings_log_csv_service_spec.rb

@ -196,7 +196,7 @@ RSpec.describe Csv::LettingsLogCsvService do
describe "the full CSV output" do describe "the full CSV output" do
context "when the requested log year is 2024" do context "when the requested log year is 2024" do
let(:year) { 2024 } let(:year) { 2024 }
let(:organisation) { create(:organisation, provider_type: "LA") } let(:organisation) { create(:organisation, provider_type: "LA", name: "MHCLG") }
let(:log) do let(:log) do
create( create(
:lettings_log, :lettings_log,
@ -389,7 +389,7 @@ RSpec.describe Csv::LettingsLogCsvService do
context "when the requested log year is 2023" do context "when the requested log year is 2023" do
let(:year) { 2023 } let(:year) { 2023 }
let(:organisation) { create(:organisation, provider_type: "LA") } let(:organisation) { create(:organisation, provider_type: "LA", name: "MHCLG") }
let(:log) do let(:log) do
create( create(
:lettings_log, :lettings_log,

10
spec/services/csv/sales_log_csv_service_spec.rb

@ -4,7 +4,7 @@ RSpec.describe Csv::SalesLogCsvService do
subject(:task) { Rake::Task["data_import:add_variable_definitions"] } subject(:task) { Rake::Task["data_import:add_variable_definitions"] }
let(:form_handler_mock) { instance_double(FormHandler) } let(:form_handler_mock) { instance_double(FormHandler) }
let(:organisation) { create(:organisation) } let(:organisation) { create(:organisation, name: "MHCLG") }
let(:fixed_time) { now } let(:fixed_time) { now }
let(:now) { Time.zone.now } let(:now) { Time.zone.now }
let(:user) { create(:user, :support, email: "billyboy@eyeKLAUD.com") } let(:user) { create(:user, :support, email: "billyboy@eyeKLAUD.com") }
@ -17,15 +17,23 @@ RSpec.describe Csv::SalesLogCsvService do
created_at: fixed_time, created_at: fixed_time,
updated_at: now, updated_at: now,
owning_organisation: organisation, owning_organisation: organisation,
managing_organisation: organisation,
purchid: nil, purchid: nil,
hholdcount: 3, hholdcount: 3,
age1: 30,
sex1: "X",
age2: 35,
sex2: "X",
sex3: "X",
age4_known: 1, age4_known: 1,
sex4: "X",
details_known_5: 2, details_known_5: 2,
age6_known: nil, age6_known: nil,
age6: nil, age6: nil,
ecstat6: nil, ecstat6: nil,
relat6: nil, relat6: nil,
sex6: nil, sex6: nil,
town_or_city: "Town or city",
address_line1_as_entered: "address line 1 as entered", address_line1_as_entered: "address line 1 as entered",
address_line2_as_entered: "address line 2 as entered", address_line2_as_entered: "address line 2 as entered",
town_or_city_as_entered: "town or city as entered", town_or_city_as_entered: "town or city as entered",

2
spec/services/csv/scheme_csv_service_spec.rb

@ -1,7 +1,7 @@
require "rails_helper" require "rails_helper"
RSpec.describe Csv::SchemeCsvService do RSpec.describe Csv::SchemeCsvService do
let(:organisation) { create(:organisation) } let(:organisation) { create(:organisation, name: "MHCLG") }
let(:fixed_time) { Time.zone.local(2023, 6, 26) } let(:fixed_time) { Time.zone.local(2023, 6, 26) }
let(:scheme) { create(:scheme, :export, owning_organisation: organisation, service_name: "Test name") } let(:scheme) { create(:scheme, :export, owning_organisation: organisation, service_name: "Test name") }
let(:location) { create(:location, :export, scheme:) } let(:location) { create(:location, :export, scheme:) }

17
spec/services/exports/lettings_log_export_service_spec.rb

@ -15,7 +15,8 @@ RSpec.describe Exports::LettingsLogExportService do
let(:expected_data_filename) { "core_2021_2022_apr_mar_f0001_inc0001_pt001.xml" } let(:expected_data_filename) { "core_2021_2022_apr_mar_f0001_inc0001_pt001.xml" }
let(:expected_manifest_filename) { "manifest.xml" } let(:expected_manifest_filename) { "manifest.xml" }
let(:start_time) { Time.zone.local(2022, 5, 1) } let(:start_time) { Time.zone.local(2022, 5, 1) }
let(:user) { FactoryBot.create(:user, email: "test1@example.com") } let(:organisation) { create(:organisation, name: "MHCLG", housing_registration_no: 1234) }
let(:user) { FactoryBot.create(:user, email: "test1@example.com", organisation:) }
def replace_entity_ids(lettings_log, export_template) def replace_entity_ids(lettings_log, export_template)
export_template.sub!(/\{id\}/, (lettings_log["id"] + Exports::LettingsLogExportService::LOG_ID_OFFSET).to_s) export_template.sub!(/\{id\}/, (lettings_log["id"] + Exports::LettingsLogExportService::LOG_ID_OFFSET).to_s)
@ -79,7 +80,7 @@ RSpec.describe Exports::LettingsLogExportService do
end end
context "and one lettings log is available for export" do context "and one lettings log is available for export" do
let!(:lettings_log) { FactoryBot.create(:lettings_log, :completed, assigned_to: user, propcode: "123", ppostcode_full: "SE2 6RT", postcode_full: "NW1 5TY", tenancycode: "BZ737", startdate: Time.zone.local(2022, 2, 2, 10, 36, 49), voiddate: Time.zone.local(2019, 11, 3), mrcdate: Time.zone.local(2020, 5, 5, 10, 36, 49), tenancylength: 5, underoccupation_benefitcap: 4) } let!(:lettings_log) { FactoryBot.create(:lettings_log, :completed, assigned_to: user, age1: 35, sex1: "F", age2: 32, sex2: "M", propcode: "123", ppostcode_full: "SE2 6RT", postcode_full: "NW1 5TY", town_or_city: "London", tenancycode: "BZ737", startdate: Time.zone.local(2022, 2, 2, 10, 36, 49), voiddate: Time.zone.local(2019, 11, 3), mrcdate: Time.zone.local(2020, 5, 5, 10, 36, 49), tenancylength: 5, underoccupation_benefitcap: 4) }
it "generates a ZIP export file with the expected filename" do it "generates a ZIP export file with the expected filename" do
expect(storage_service).to receive(:write_file).with(expected_zip_filename, any_args) expect(storage_service).to receive(:write_file).with(expected_zip_filename, any_args)
@ -123,7 +124,7 @@ RSpec.describe Exports::LettingsLogExportService do
end end
context "and one lettings log with unknown user details is available for export" do context "and one lettings log with unknown user details is available for export" do
let!(:lettings_log) { FactoryBot.create(:lettings_log, :completed, details_known_2: 1, assigned_to: user, propcode: "123", ppostcode_full: "SE2 6RT", postcode_full: "NW1 5TY", tenancycode: "BZ737", startdate: Time.zone.local(2022, 2, 2, 10, 36, 49), voiddate: Time.zone.local(2019, 11, 3), mrcdate: Time.zone.local(2020, 5, 5, 10, 36, 49), tenancylength: 5, underoccupation_benefitcap: 4) } let!(:lettings_log) { FactoryBot.create(:lettings_log, :completed, details_known_2: 1, assigned_to: user, age1: 35, sex1: "F", propcode: "123", ppostcode_full: "SE2 6RT", postcode_full: "NW1 5TY", town_or_city: "London", tenancycode: "BZ737", startdate: Time.zone.local(2022, 2, 2, 10, 36, 49), voiddate: Time.zone.local(2019, 11, 3), mrcdate: Time.zone.local(2020, 5, 5, 10, 36, 49), tenancylength: 5, underoccupation_benefitcap: 4) }
def replace_person_details(export_file) def replace_person_details(export_file)
export_file.sub!("<age2>32</age2>", "<age2>-9</age2>") export_file.sub!("<age2>32</age2>", "<age2>-9</age2>")
@ -176,7 +177,7 @@ RSpec.describe Exports::LettingsLogExportService do
end end
context "and one lettings log is available for export" do context "and one lettings log is available for export" do
let!(:lettings_log) { FactoryBot.create(:lettings_log, :completed, assigned_to: user, uprn_known: 1, uprn: "100023336956", propcode: "123", postcode_full: "SE2 6RT", ppostcode_full: "SE2 6RT", tenancycode: "BZ737", startdate: Time.zone.local(2023, 4, 2, 10, 36, 49), voiddate: Time.zone.local(2021, 11, 3), mrcdate: Time.zone.local(2022, 5, 5, 10, 36, 49), tenancylength: 5, underoccupation_benefitcap: 4) } let!(:lettings_log) { FactoryBot.create(:lettings_log, :completed, assigned_to: user, age1: 35, sex1: "F", age2: 32, sex2: "M", uprn_known: 1, uprn: "100023336956", propcode: "123", postcode_full: "SE2 6RT", ppostcode_full: "SE2 6RT", tenancycode: "BZ737", startdate: Time.zone.local(2023, 4, 2, 10, 36, 49), voiddate: Time.zone.local(2021, 11, 3), mrcdate: Time.zone.local(2022, 5, 5, 10, 36, 49), tenancylength: 5, underoccupation_benefitcap: 4) }
let(:expected_zip_filename) { "core_2023_2024_apr_mar_f0001_inc0001.zip" } let(:expected_zip_filename) { "core_2023_2024_apr_mar_f0001_inc0001.zip" }
let(:expected_data_filename) { "core_2023_2024_apr_mar_f0001_inc0001_pt001.xml" } let(:expected_data_filename) { "core_2023_2024_apr_mar_f0001_inc0001_pt001.xml" }
let(:xml_export_file) { File.open("spec/fixtures/exports/general_needs_log_23_24.xml", "r:UTF-8") } let(:xml_export_file) { File.open("spec/fixtures/exports/general_needs_log_23_24.xml", "r:UTF-8") }
@ -396,7 +397,7 @@ RSpec.describe Exports::LettingsLogExportService do
end end
context "and one lettings log with duplicate reference is available for export" do context "and one lettings log with duplicate reference is available for export" do
let!(:lettings_log) { FactoryBot.create(:lettings_log, :completed, assigned_to: user, propcode: "123", ppostcode_full: "SE2 6RT", postcode_full: "NW1 5TY", tenancycode: "BZ737", startdate: Time.zone.local(2022, 2, 2, 10, 36, 49), voiddate: Time.zone.local(2019, 11, 3), mrcdate: Time.zone.local(2020, 5, 5, 10, 36, 49), tenancylength: 5, underoccupation_benefitcap: 4, duplicate_set_id: 123) } let!(:lettings_log) { FactoryBot.create(:lettings_log, :completed, assigned_to: user, age1: 35, sex1: "F", age2: 32, sex2: "M", propcode: "123", ppostcode_full: "SE2 6RT", postcode_full: "NW1 5TY", town_or_city: "London", tenancycode: "BZ737", startdate: Time.zone.local(2022, 2, 2, 10, 36, 49), voiddate: Time.zone.local(2019, 11, 3), mrcdate: Time.zone.local(2020, 5, 5, 10, 36, 49), tenancylength: 5, underoccupation_benefitcap: 4, duplicate_set_id: 123) }
def replace_duplicate_set_id(export_file) def replace_duplicate_set_id(export_file)
export_file.sub!("<duplicate_set_id/>", "<duplicate_set_id>123</duplicate_set_id>") export_file.sub!("<duplicate_set_id/>", "<duplicate_set_id>123</duplicate_set_id>")
@ -429,7 +430,7 @@ RSpec.describe Exports::LettingsLogExportService do
end end
context "and one lettings log is available for export" do context "and one lettings log is available for export" do
let!(:lettings_log) { FactoryBot.create(:lettings_log, :completed, assigned_to: user, ppostcode_full: "A1 1AA", nationality_all_group: 13, propcode: "123", postcode_full: "SE2 6RT", tenancycode: "BZ737", startdate: Time.zone.local(2024, 4, 2, 10, 36, 49), voiddate: Time.zone.local(2021, 11, 3), mrcdate: Time.zone.local(2022, 5, 5, 10, 36, 49), tenancylength: 5, underoccupation_benefitcap: 4, creation_method: 2, bulk_upload_id: 1, address_line1_as_entered: "address line 1 as entered", address_line2_as_entered: "address line 2 as entered", town_or_city_as_entered: "town or city as entered", county_as_entered: "county as entered", postcode_full_as_entered: "AB1 2CD", la_as_entered: "la as entered") } let!(:lettings_log) { FactoryBot.create(:lettings_log, :completed, assigned_to: user, age1: 35, sex1: "F", age2: 32, sex2: "M", ppostcode_full: "A1 1AA", nationality_all_group: 13, propcode: "123", postcode_full: "SE2 6RT", tenancycode: "BZ737", startdate: Time.zone.local(2024, 4, 2, 10, 36, 49), voiddate: Time.zone.local(2021, 11, 3), mrcdate: Time.zone.local(2022, 5, 5, 10, 36, 49), tenancylength: 5, underoccupation_benefitcap: 4, creation_method: 2, bulk_upload_id: 1, address_line1_as_entered: "address line 1 as entered", address_line2_as_entered: "address line 2 as entered", town_or_city_as_entered: "town or city as entered", county_as_entered: "county as entered", postcode_full_as_entered: "AB1 2CD", la_as_entered: "la as entered") }
let(:expected_zip_filename) { "core_2024_2025_apr_mar_f0001_inc0001.zip" } let(:expected_zip_filename) { "core_2024_2025_apr_mar_f0001_inc0001.zip" }
let(:expected_data_filename) { "core_2024_2025_apr_mar_f0001_inc0001_pt001.xml" } let(:expected_data_filename) { "core_2024_2025_apr_mar_f0001_inc0001_pt001.xml" }
let(:xml_export_file) { File.open("spec/fixtures/exports/general_needs_log_24_25.xml", "r:UTF-8") } let(:xml_export_file) { File.open("spec/fixtures/exports/general_needs_log_24_25.xml", "r:UTF-8") }
@ -450,13 +451,13 @@ RSpec.describe Exports::LettingsLogExportService do
context "when exporting a supported housing lettings logs in XML" do context "when exporting a supported housing lettings logs in XML" do
let(:export_file) { File.open("spec/fixtures/exports/supported_housing_logs.xml", "r:UTF-8") } let(:export_file) { File.open("spec/fixtures/exports/supported_housing_logs.xml", "r:UTF-8") }
let(:organisation) { FactoryBot.create(:organisation, provider_type: "LA") } let(:organisation) { FactoryBot.create(:organisation, name: "MHCLG", provider_type: "LA", housing_registration_no: 1234) }
let(:user) { FactoryBot.create(:user, organisation:, email: "fake@email.com") } let(:user) { FactoryBot.create(:user, organisation:, email: "fake@email.com") }
let(:other_user) { FactoryBot.create(:user, organisation:, email: "other@email.com") } let(:other_user) { FactoryBot.create(:user, organisation:, email: "other@email.com") }
let(:scheme) { FactoryBot.create(:scheme, :export, owning_organisation: organisation) } let(:scheme) { FactoryBot.create(:scheme, :export, owning_organisation: organisation) }
let(:location) { FactoryBot.create(:location, :export, scheme:, startdate: Time.zone.local(2021, 4, 1), old_id: "1a") } let(:location) { FactoryBot.create(:location, :export, scheme:, startdate: Time.zone.local(2021, 4, 1), old_id: "1a") }
let(:lettings_log) { FactoryBot.create(:lettings_log, :completed, :export, :sh, scheme:, location:, assigned_to: user, updated_by: other_user, owning_organisation: organisation, startdate: Time.zone.local(2022, 2, 2, 10, 36, 49), voiddate: Time.zone.local(2019, 11, 3), mrcdate: Time.zone.local(2020, 5, 5, 10, 36, 49), underoccupation_benefitcap: 4, sheltered: 1) } let(:lettings_log) { FactoryBot.create(:lettings_log, :completed, :export, :sh, scheme:, location:, assigned_to: user, updated_by: other_user, owning_organisation: organisation, age1: 35, sex1: "F", age2: 32, sex2: "M", startdate: Time.zone.local(2022, 2, 2, 10, 36, 49), voiddate: Time.zone.local(2019, 11, 3), mrcdate: Time.zone.local(2020, 5, 5, 10, 36, 49), underoccupation_benefitcap: 4, sheltered: 1) }
before do before do
lettings_log.postcode_full = nil lettings_log.postcode_full = nil

2
spec/services/exports/organisation_export_service_spec.rb

@ -42,7 +42,7 @@ RSpec.describe Exports::OrganisationExportService do
end end
context "and one organisation is available for export" do context "and one organisation is available for export" do
let!(:organisation) { create(:organisation) } let!(:organisation) { create(:organisation, name: "MHCLG", address_line1: "2 Marsham Street", address_line2: "London", postcode: "SW1P 4DF", housing_registration_no: "1234") }
it "generates a ZIP export file with the expected filename" do it "generates a ZIP export file with the expected filename" do
expect(storage_service).to receive(:write_file).with(expected_zip_filename, any_args) expect(storage_service).to receive(:write_file).with(expected_zip_filename, any_args)

4
spec/services/exports/user_export_service_spec.rb

@ -12,7 +12,7 @@ RSpec.describe Exports::UserExportService do
let(:expected_data_filename) { "users_2024_2025_apr_mar_f0001_inc0001_pt001.xml" } let(:expected_data_filename) { "users_2024_2025_apr_mar_f0001_inc0001_pt001.xml" }
let(:expected_manifest_filename) { "manifest.xml" } let(:expected_manifest_filename) { "manifest.xml" }
let(:start_time) { Time.zone.local(2022, 5, 1) } let(:start_time) { Time.zone.local(2022, 5, 1) }
let(:organisation) { create(:organisation, with_dsa: false) } let(:organisation) { create(:organisation, name: "MHCLG", with_dsa: false) }
def replace_entity_ids(user, export_template) def replace_entity_ids(user, export_template)
export_template.sub!(/\{id\}/, user["id"].to_s) export_template.sub!(/\{id\}/, user["id"].to_s)
@ -42,7 +42,7 @@ RSpec.describe Exports::UserExportService do
end end
context "and one user is available for export" do context "and one user is available for export" do
let!(:user) { create(:user, organisation:, phone_extension: "123") } let!(:user) { create(:user, organisation:, name: "Danny Rojas", phone_extension: "123") }
it "generates a ZIP export file with the expected filename" do it "generates a ZIP export file with the expected filename" do
expect(storage_service).to receive(:write_file).with(expected_zip_filename, any_args) expect(storage_service).to receive(:write_file).with(expected_zip_filename, any_args)

28
spec/services/merge/merge_organisations_service_spec.rb

@ -28,7 +28,7 @@ RSpec.describe Merge::MergeOrganisationsService do
it "moves the users from merging organisation to absorbing organisation" do 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("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("\t#{merging_organisation.data_protection_officers.first.name} (#{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("\tfake name (fake@email.com)")
expect(Rails.logger).to receive(:info).with("New schemes from fake org:") expect(Rails.logger).to receive(:info).with("New schemes from fake org:")
merge_organisations_service.call merge_organisations_service.call
@ -477,7 +477,7 @@ RSpec.describe Merge::MergeOrganisationsService do
it "logs the merged schemes and locations" do it "logs the merged schemes and locations" do
expect(Rails.logger).to receive(:info).with("Merged users from fake org:") 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("\t#{merging_organisation.data_protection_officers.first.name} (#{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("\tfake name (fake@email.com)")
expect(Rails.logger).to receive(:info).with("New schemes from fake org:") expect(Rails.logger).to receive(:info).with("New schemes from fake org:")
expect(Rails.logger).to receive(:info).with(/\t#{scheme.service_name} \(S/) expect(Rails.logger).to receive(:info).with(/\t#{scheme.service_name} \(S/)
@ -623,7 +623,7 @@ RSpec.describe Merge::MergeOrganisationsService do
context "and merging sales logs" do context "and merging sales logs" do
let(:owning_organisation) { create(:organisation, holds_own_stock: true) } let(:owning_organisation) { create(:organisation, holds_own_stock: true) }
let!(:sales_log) { create(:sales_log, saledate: Time.zone.today, owning_organisation: merging_organisation, purchid: "owned") } let!(:sales_log) { create(:sales_log, saledate: Time.zone.today, owning_organisation: merging_organisation, managing_organisation: merging_organisation, purchid: "owned") }
let!(:managed_sales_log) { create(:sales_log, saledate: Time.zone.today, purchid: "managed") } let!(:managed_sales_log) { create(:sales_log, saledate: Time.zone.today, purchid: "managed") }
before do before do
@ -744,7 +744,7 @@ RSpec.describe Merge::MergeOrganisationsService do
it "logs the merged schemes" do it "logs the merged schemes" do
expect(Rails.logger).to receive(:info).with("Merged users from fake org:") 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("\t#{merging_organisation.data_protection_officers.first.name} (#{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("\tfake name (fake@email.com)")
expect(Rails.logger).to receive(:info).with("New schemes from fake org:") expect(Rails.logger).to receive(:info).with("New schemes from fake org:")
expect(Rails.logger).to receive(:info).with(/\t#{scheme.service_name} \(S/) expect(Rails.logger).to receive(:info).with(/\t#{scheme.service_name} \(S/)
@ -922,7 +922,7 @@ RSpec.describe Merge::MergeOrganisationsService do
let!(:merging_organisation_user) { create(:user, organisation: merging_organisation, name: "fake name", email: "fake@email.com") } let!(:merging_organisation_user) { create(:user, organisation: merging_organisation, name: "fake name", email: "fake@email.com") }
before do before do
create_list(:user, 5, organisation: merging_organisation_too) create_list(:user, 5, organisation: merging_organisation_too, name: "Danny Rojas")
end end
it "sets merge date and absorbing organisation on merged organisations" do it "sets merge date and absorbing organisation on merged organisations" do
@ -961,10 +961,11 @@ RSpec.describe Merge::MergeOrganisationsService do
context "and merging users" do context "and merging users" do
it "moves the users from merging organisations to absorbing organisation" do 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("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("\t#{merging_organisation.data_protection_officers.first.name} (#{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("\tfake name (fake@email.com)")
expect(Rails.logger).to receive(:info).with("Merged users from second org:") 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(/\tDanny Rojas/).exactly(5).times
expect(Rails.logger).to receive(:info).with(/\t#{merging_organisation_too.data_protection_officers.first.name}/)
expect(Rails.logger).to receive(:info).with("New schemes from fake org:") expect(Rails.logger).to receive(:info).with("New schemes from fake org:")
expect(Rails.logger).to receive(:info).with("New schemes from second org:") expect(Rails.logger).to receive(:info).with("New schemes from second org:")
merge_organisations_service.call merge_organisations_service.call
@ -1113,7 +1114,7 @@ RSpec.describe Merge::MergeOrganisationsService do
it "moves the users from merging organisation to absorbing organisation" do 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("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("\t#{merging_organisation.data_protection_officers.first.name} (#{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("\tfake name (fake@email.com)")
expect(Rails.logger).to receive(:info).with("New schemes from fake org:") expect(Rails.logger).to receive(:info).with("New schemes from fake org:")
merge_organisations_service.call merge_organisations_service.call
@ -1251,7 +1252,7 @@ RSpec.describe Merge::MergeOrganisationsService do
it "logs the merged schemes" do it "logs the merged schemes" do
expect(Rails.logger).to receive(:info).with("Merged users from fake org:") 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("\t#{merging_organisation.data_protection_officers.first.name} (#{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("\tfake name (fake@email.com)")
expect(Rails.logger).to receive(:info).with("New schemes from fake org:") expect(Rails.logger).to receive(:info).with("New schemes from fake org:")
expect(Rails.logger).to receive(:info).with(/\t#{scheme.service_name} \(S/) expect(Rails.logger).to receive(:info).with(/\t#{scheme.service_name} \(S/)
@ -1462,7 +1463,7 @@ RSpec.describe Merge::MergeOrganisationsService do
it "logs the merged schemes" do it "logs the merged schemes" do
expect(Rails.logger).to receive(:info).with("Merged users from fake org:") 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("\t#{merging_organisation.data_protection_officers.first.name} (#{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("\tfake name (fake@email.com)")
expect(Rails.logger).to receive(:info).with("New schemes from fake org:") expect(Rails.logger).to receive(:info).with("New schemes from fake org:")
expect(Rails.logger).to receive(:info).with(/\t#{scheme.service_name} \(S/) expect(Rails.logger).to receive(:info).with(/\t#{scheme.service_name} \(S/)
@ -1590,15 +1591,16 @@ RSpec.describe Merge::MergeOrganisationsService do
let!(:merging_organisation_user) { create(:user, organisation: merging_organisation, name: "fake name", email: "fake@email.com") } let!(:merging_organisation_user) { create(:user, organisation: merging_organisation, name: "fake name", email: "fake@email.com") }
before do before do
create_list(:user, 5, organisation: merging_organisation_too) create_list(:user, 5, organisation: merging_organisation_too, name: "Danny Rojas")
end end
it "moves the users from merging organisations to absorbing organisation" do 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("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("\t#{merging_organisation.data_protection_officers.first.name} (#{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("\tfake name (fake@email.com)")
expect(Rails.logger).to receive(:info).with("Merged users from second org:") 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(/\tDanny Rojas/).exactly(5).times
expect(Rails.logger).to receive(:info).with(/\t#{merging_organisation_too.data_protection_officers.first.name}/)
expect(Rails.logger).to receive(:info).with("New schemes from fake org:") expect(Rails.logger).to receive(:info).with("New schemes from fake org:")
expect(Rails.logger).to receive(:info).with("New schemes from second org:") expect(Rails.logger).to receive(:info).with("New schemes from second org:")
merge_organisations_service.call merge_organisations_service.call

Loading…
Cancel
Save