Browse Source

CLDC-1228 Scheme and Location imports (#727)

pull/732/head
Stéphane Meny 2 years ago committed by GitHub
parent
commit
da2c8dd50a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      app/controllers/locations_controller.rb
  2. 4
      app/models/location.rb
  3. 8
      app/models/scheme.rb
  4. 60
      app/services/imports/scheme_import_service.rb
  5. 173
      app/services/imports/scheme_location_import_service.rb
  6. 2
      app/views/locations/edit.html.erb
  7. 2
      app/views/locations/index.html.erb
  8. 2
      app/views/locations/new.html.erb
  9. 2
      app/views/schemes/check_answers.html.erb
  10. 9
      db/migrate/20220708112603_add_missing_fields_to_scheme.rb
  11. 8
      db/migrate/20220708133052_add_missing_fields_to_location.rb
  12. 6
      db/migrate/20220711081400_rename_units_from_locations.rb
  13. 5
      db/migrate/20220711152629_add_unique_index_for_old_ids.rb
  14. 15
      db/schema.rb
  15. 6
      lib/tasks/data_import.rake
  16. 2
      spec/factories/location.rb
  17. 2
      spec/factories/scheme.rb
  18. 0
      spec/fixtures/imports/case_logs/00d2343e-d5fa-4c89-8400-ec3854b0f2b4.xml
  19. 0
      spec/fixtures/imports/case_logs/0ead17cb-1668-442d-898c-0d52879ff592.xml
  20. 0
      spec/fixtures/imports/case_logs/166fc004-392e-47a8-acb8-1c018734882b.xml
  21. 0
      spec/fixtures/imports/case_logs/5ybz29dj-l33t-k1l0-hj86-n4k4ma77xkcd.xml
  22. 0
      spec/fixtures/imports/case_logs/893ufj2s-lq77-42m4-rty6-ej09gh585uy1.xml
  23. 0
      spec/fixtures/imports/data_protection_confirmations/7c5bd5fb549c09a2c55d7cb90d7ba84927e64618.xml
  24. 0
      spec/fixtures/imports/organisation_rent_periods/ebd22326d33e389e9f1bfd546979d2c05f9e68d6.xml
  25. 0
      spec/fixtures/imports/organisations/7c5bd5fb549c09a2c55d7cb90d7ba84927e64618.xml
  26. 25
      spec/fixtures/imports/scheme_locations/0ae7ad6dc0f1cf7ef33c18cc8c108bebc1b4923e.xml
  27. 23
      spec/fixtures/imports/scheme_locations/0bb3836b70b4dd9903263d5a764a5c45b964a89d.xml
  28. 9
      spec/fixtures/imports/schemes/6d6d7618b58affe2a150a5ef2e9f4765fa6cd05d.xml
  29. 0
      spec/fixtures/imports/users/10c887710550844e2551b3e0fb88dc9b4a8a642b.xml
  30. 0
      spec/fixtures/imports/users/9ed81a262215a1634f0809effa683e38924d8bcb.xml
  31. 0
      spec/fixtures/imports/users/b7829b1a5dfb68bb1e01c08445830c0add40907c.xml
  32. 0
      spec/fixtures/imports/users/d4729b1a5dfb68bb1e01c08445830c0add40907c.xml
  33. 0
      spec/fixtures/imports/users/d6717836154cd9a58f9e2f1d3077e3ab81e07613.xml
  34. 0
      spec/fixtures/imports/users/fc7625a02b24ae16162aa63ae7cb33feeec0c373.xml
  35. 46
      spec/lib/tasks/data_import_spec.rb
  36. 2
      spec/lib/tasks/date_import_field_spec.rb
  37. 84
      spec/requests/locations_controller_spec.rb
  38. 2
      spec/services/imports/case_logs_field_import_service_spec.rb
  39. 2
      spec/services/imports/case_logs_import_service_spec.rb
  40. 2
      spec/services/imports/data_protection_confirmation_import_service_spec.rb
  41. 2
      spec/services/imports/organisation_import_service_spec.rb
  42. 2
      spec/services/imports/organisation_rent_period_import_service_spec.rb
  43. 64
      spec/services/imports/scheme_import_service_spec.rb
  44. 180
      spec/services/imports/scheme_location_import_service_spec.rb
  45. 2
      spec/services/imports/user_import_service_spec.rb

2
app/controllers/locations_controller.rb

@ -69,7 +69,7 @@ private
end end
def location_params def location_params
required_params = params.require(:location).permit(:postcode, :name, :total_units, :type_of_unit, :wheelchair_adaptation, :add_another_location).merge(scheme_id: @scheme.id) required_params = params.require(:location).permit(:postcode, :name, :units, :type_of_unit, :wheelchair_adaptation, :add_another_location).merge(scheme_id: @scheme.id)
required_params[:postcode] = PostcodeService.clean(required_params[:postcode]) if required_params[:postcode] required_params[:postcode] = PostcodeService.clean(required_params[:postcode]) if required_params[:postcode]
required_params required_params
end end

4
app/models/location.rb

@ -16,8 +16,8 @@ class Location < ApplicationRecord
"Self-contained flat or bedsit with common facilities": 2, "Self-contained flat or bedsit with common facilities": 2,
"Shared flat": 3, "Shared flat": 3,
"Shared house or hostel": 4, "Shared house or hostel": 4,
"Bungalow": 5, "Bungalow": 6,
"Self-contained house": 6, "Self-contained house": 7,
}.freeze }.freeze
enum type_of_unit: TYPE_OF_UNIT enum type_of_unit: TYPE_OF_UNIT

8
app/models/scheme.rb

@ -17,10 +17,10 @@ class Scheme < ApplicationRecord
enum sensitive: SENSITIVE, _suffix: true enum sensitive: SENSITIVE, _suffix: true
REGISTERED_UNDER_CARE_ACT = { REGISTERED_UNDER_CARE_ACT = {
"No": 0, "No": 1,
"Yes – registered care home providing nursing care": 1, "Yes – registered care home providing nursing care": 4,
"Yes – registered care home providing personal care": 2, "Yes – registered care home providing personal care": 3,
"Yes – part registered as a care home": 3, "Yes – part registered as a care home": 2,
}.freeze }.freeze
enum registered_under_care_act: REGISTERED_UNDER_CARE_ACT enum registered_under_care_act: REGISTERED_UNDER_CARE_ACT

60
app/services/imports/scheme_import_service.rb

@ -0,0 +1,60 @@
module Imports
class SchemeImportService < ImportService
def create_schemes(folder)
import_from(folder, :create_scheme)
end
def create_scheme(xml_document)
old_id = string_or_nil(xml_document, "id")
status = string_or_nil(xml_document, "status")
if status == "Approved"
Scheme.create!(
owning_organisation_id: find_owning_organisation_id(xml_document),
managing_organisation_id: find_managing_organisation_id(xml_document),
service_name: string_or_nil(xml_document, "name"),
arrangement_type: string_or_nil(xml_document, "arrangement_type"),
old_id:,
old_visible_id: safe_string_as_integer(xml_document, "visible-id"),
)
else
@logger.warn("Scheme with legacy ID #{old_id} is not approved (#{status}), skipping")
end
end
private
def scheme_field_value(xml_document, field)
field_value(xml_document, "mgmtgroup", field)
end
def string_or_nil(xml_doc, attribute)
str = scheme_field_value(xml_doc, attribute)
str.presence
end
# Safe: A string that represents only an integer (or empty/nil)
def safe_string_as_integer(xml_doc, attribute)
str = scheme_field_value(xml_doc, attribute)
Integer(str, exception: false)
end
def find_owning_organisation_id(xml_doc)
old_org_id = string_or_nil(xml_doc, "institution")
organisation = Organisation.find_by(old_org_id:)
raise "Organisation not found with legacy ID #{old_org_id}" if organisation.nil?
organisation.id
end
def find_managing_organisation_id(xml_doc)
old_visible_id = safe_string_as_integer(xml_doc, "agent")
return unless old_visible_id
organisation = Organisation.find_by(old_visible_id:)
raise "Organisation not found with legacy visible ID #{old_visible_id}" if organisation.nil?
organisation.id
end
end
end

173
app/services/imports/scheme_location_import_service.rb

@ -0,0 +1,173 @@
module Imports
class SchemeLocationImportService < ImportService
def create_scheme_locations(folder)
import_from(folder, :create_scheme_location)
end
def create_scheme_location(xml_document)
management_group = location_field_value(xml_document, "mgmtgroup")
schemes = Scheme.where(old_id: management_group)
raise "Scheme not found with legacy ID #{management_group}" if schemes.empty?
if schemes.size == 1 && schemes.first.locations&.empty?
scheme = update_scheme(schemes.first, xml_document)
else
scheme = find_scheme_to_merge(xml_document)
scheme ||= duplicate_scheme(schemes, xml_document)
end
add_location(scheme, xml_document)
end
private
REGISTERED_UNDER_CARE_ACT = {
2 => "(Part-registered care home)",
3 => "(Registered personal care home)",
4 => "(Registered nursing care home)",
}.freeze
def create_scheme(source_scheme, xml_doc)
attributes = scheme_attributes(xml_doc)
attributes["owning_organisation_id"] = source_scheme.owning_organisation_id
attributes["managing_organisation_id"] = source_scheme.managing_organisation_id
attributes["service_name"] = source_scheme.service_name
attributes["arrangement_type"] = source_scheme.arrangement_type
attributes["old_id"] = source_scheme.old_id
attributes["old_visible_id"] = source_scheme.old_visible_id
Scheme.create!(attributes)
end
def update_scheme(scheme, xml_doc)
attributes = scheme_attributes(xml_doc)
scheme.update!(attributes)
scheme
end
def scheme_attributes(xml_doc)
attributes = {}
attributes["scheme_type"] = safe_string_as_integer(xml_doc, "scheme-type")
registered_under_care_act = safe_string_as_integer(xml_doc, "reg-home-type")
attributes["registered_under_care_act"] = registered_under_care_act.zero? ? nil : registered_under_care_act
attributes["support_type"] = safe_string_as_integer(xml_doc, "support-type")
attributes["intended_stay"] = string_or_nil(xml_doc, "intended-stay")
attributes["primary_client_group"] = string_or_nil(xml_doc, "client-group-1")
attributes["secondary_client_group"] = string_or_nil(xml_doc, "client-group-2")
attributes["secondary_client_group"] = nil if attributes["primary_client_group"] == attributes["secondary_client_group"]
attributes["sensitive"] = sensitive(xml_doc)
attributes["end_date"] = parse_end_date(xml_doc)
attributes
end
def add_location(scheme, xml_doc)
end_date = parse_end_date(xml_doc)
old_id = string_or_nil(xml_doc, "id")
if end_date.nil? || end_date >= Time.zone.now
# wheelchair_adaptation: string_or_nil(xml_doc, "mobility-type"),
begin
Location.create!(
name: string_or_nil(xml_doc, "name"),
postcode: string_or_nil(xml_doc, "postcode"),
units: safe_string_as_integer(xml_doc, "total-units"),
type_of_unit: safe_string_as_integer(xml_doc, "unit-type"),
old_visible_id: safe_string_as_integer(xml_doc, "visible-id"),
old_id:,
scheme:,
)
rescue ActiveRecord::RecordNotUnique
@logger.warn("Location is already present with legacy ID #{old_id}, skipping")
end
else
@logger.warn("Location with legacy ID #{old_id} is expired (#{end_date}), skipping")
end
end
def find_scheme_to_merge(xml_doc)
attributes = scheme_attributes(xml_doc)
Scheme.find_by(
scheme_type: attributes["scheme_type"],
registered_under_care_act: attributes["registered_under_care_act"],
support_type: attributes["support_type"],
intended_stay: attributes["intended_stay"],
primary_client_group: attributes["primary_client_group"],
secondary_client_group: attributes["secondary_client_group"],
)
end
def duplicate_scheme(schemes, xml_doc)
# Since all schemes in the array are different, pick the first one
# In the future, consider a better selection method if needed
old_scheme = schemes.first
new_scheme = create_scheme(old_scheme, xml_doc)
if old_scheme.scheme_type != new_scheme.scheme_type
rename_schemes(old_scheme, new_scheme, :scheme_type)
elsif old_scheme.registered_under_care_act != new_scheme.registered_under_care_act
rename_registered_care(old_scheme, new_scheme)
elsif old_scheme.support_type != new_scheme.support_type
rename_schemes(old_scheme, new_scheme, :support_type)
elsif old_scheme.intended_stay != new_scheme.intended_stay
rename_schemes(old_scheme, new_scheme, :intended_stay)
elsif old_scheme.primary_client_group != new_scheme.primary_client_group
rename_schemes(old_scheme, new_scheme, :primary_client_group)
elsif old_scheme.secondary_client_group != new_scheme.secondary_client_group
rename_schemes(old_scheme, new_scheme, :secondary_client_group)
end
new_scheme
end
def rename_registered_care(*schemes)
schemes.each do |scheme|
if REGISTERED_UNDER_CARE_ACT.key?(scheme.registered_under_care_act_before_type_cast)
suffix = REGISTERED_UNDER_CARE_ACT[scheme.registered_under_care_act_before_type_cast]
scheme.update!(service_name: "#{scheme.service_name} - #{suffix}")
end
end
end
def rename_schemes(old_scheme, new_scheme, attribute)
old_scheme_attribute = old_scheme.send(attribute)
new_scheme_attribute = new_scheme.send(attribute)
if old_scheme_attribute
old_scheme_name = "#{old_scheme.service_name} - #{old_scheme_attribute}"
old_scheme.update!(service_name: old_scheme_name)
end
if new_scheme_attribute
new_scheme_name = "#{new_scheme.service_name} - #{new_scheme_attribute}"
new_scheme.update!(service_name: new_scheme_name)
end
end
def location_field_value(xml_doc, field)
field_value(xml_doc, "scheme", field)
end
def string_or_nil(xml_doc, attribute)
str = location_field_value(xml_doc, attribute)
str.presence
end
# Safe: A string that represents only an integer (or empty/nil)
def safe_string_as_integer(xml_doc, attribute)
str = location_field_value(xml_doc, attribute)
Integer(str, exception: false)
end
def sensitive(xml_doc)
value = string_or_nil(xml_doc, "sensitive")
if value == "true"
1
else
0
end
end
def parse_end_date(xml_doc)
end_date = string_or_nil(xml_doc, "end-date")
Time.zone.parse(end_date) if end_date
end
end
end

2
app/views/locations/edit.html.erb

@ -23,7 +23,7 @@
label: { text: "Name (optional)", size: "m" }, label: { text: "Name (optional)", size: "m" },
hint: { text: "This is how you refer to this location within your organisation" } %> hint: { text: "This is how you refer to this location within your organisation" } %>
<%= f.govuk_number_field :total_units, <%= f.govuk_number_field :units,
label: { text: "Total number of units at this location", size: "m" }, label: { text: "Total number of units at this location", size: "m" },
width: 2, width: 2,
hint: { text: "A unit can be a bedroom in a shared house or flat, or a house with 4 bedrooms. Do not include bedrooms used for wardens, managers, volunteers or sleep-in staff.s" }, hint: { text: "A unit can be a bedroom in a shared house or flat, or a house with 4 bedrooms. Do not include bedrooms used for wardens, managers, volunteers or sleep-in staff.s" },

2
app/views/locations/index.html.erb

@ -37,7 +37,7 @@
<%= body.row do |row| %> <%= body.row do |row| %>
<% row.cell(text: location.id) %> <% row.cell(text: location.id) %>
<% row.cell(text: simple_format(location_cell(location, "/schemes/#{@scheme.id}/locations/#{location.id}/edit-name"), { class: "govuk-!-font-weight-bold" }, wrapper_tag: "div")) %> <% row.cell(text: simple_format(location_cell(location, "/schemes/#{@scheme.id}/locations/#{location.id}/edit-name"), { class: "govuk-!-font-weight-bold" }, wrapper_tag: "div")) %>
<% row.cell(text: location.total_units) %> <% row.cell(text: location.units) %>
<% row.cell(text: simple_format("<span>#{location.type_of_unit}</span>#{location.wheelchair_adaptation == 'Yes' ? "\n<span class=\"govuk-!-font-weight-regular app-!-colour-muted\">With wheelchair adaptations</span>" : ''}")) %> <% row.cell(text: simple_format("<span>#{location.type_of_unit}</span>#{location.wheelchair_adaptation == 'Yes' ? "\n<span class=\"govuk-!-font-weight-regular app-!-colour-muted\">With wheelchair adaptations</span>" : ''}")) %>
<% end %> <% end %>
<% end %> <% end %>

2
app/views/locations/new.html.erb

@ -23,7 +23,7 @@
label: { text: "Name (optional)", size: "m" }, label: { text: "Name (optional)", size: "m" },
hint: { text: "This is how you refer to this location within your organisation" } %> hint: { text: "This is how you refer to this location within your organisation" } %>
<%= f.govuk_number_field :total_units, <%= f.govuk_number_field :units,
label: { text: "Total number of units at this location", size: "m" }, label: { text: "Total number of units at this location", size: "m" },
width: 2, width: 2,
hint: { text: "A unit can be a bedroom in a shared house or flat, or a house with 4 bedrooms. Do not include bedrooms used for wardens, managers, volunteers or sleep-in staff.s" }, hint: { text: "A unit can be a bedroom in a shared house or flat, or a house with 4 bedrooms. Do not include bedrooms used for wardens, managers, volunteers or sleep-in staff.s" },

2
app/views/schemes/check_answers.html.erb

@ -88,7 +88,7 @@
<%= body.row do |row| %> <%= body.row do |row| %>
<% row.cell(text: location.id) %> <% row.cell(text: location.id) %>
<% row.cell(text: simple_format(location_cell(location, "/schemes/#{@scheme.id}/locations/#{location.id}/edit"), { class: "govuk-!-font-weight-bold" }, wrapper_tag: "div")) %> <% row.cell(text: simple_format(location_cell(location, "/schemes/#{@scheme.id}/locations/#{location.id}/edit"), { class: "govuk-!-font-weight-bold" }, wrapper_tag: "div")) %>
<% row.cell(text: location.total_units) %> <% row.cell(text: location.units) %>
<% row.cell(text: simple_format("<span>#{location.type_of_unit}</span>#{location.wheelchair_adaptation == 'Yes' ? "\n<span class=\"govuk-!-font-weight-regular app-!-colour-muted\">With wheelchair adaptations</span>" : ''}")) %> <% row.cell(text: simple_format("<span>#{location.type_of_unit}</span>#{location.wheelchair_adaptation == 'Yes' ? "\n<span class=\"govuk-!-font-weight-regular app-!-colour-muted\">With wheelchair adaptations</span>" : ''}")) %>
<% end %> <% end %>
<% end %> <% end %>

9
db/migrate/20220708112603_add_missing_fields_to_scheme.rb

@ -0,0 +1,9 @@
class AddMissingFieldsToScheme < ActiveRecord::Migration[7.0]
def change
change_table :schemes, bulk: true do |t|
t.column :arrangement_type, :string
t.column :old_id, :string
t.column :old_visible_id, :integer
end
end
end

8
db/migrate/20220708133052_add_missing_fields_to_location.rb

@ -0,0 +1,8 @@
class AddMissingFieldsToLocation < ActiveRecord::Migration[7.0]
def change
change_table :locations, bulk: true do |t|
t.column :old_id, :string
t.column :old_visible_id, :integer
end
end
end

6
db/migrate/20220711081400_rename_units_from_locations.rb

@ -0,0 +1,6 @@
class RenameUnitsFromLocations < ActiveRecord::Migration[7.0]
def change
rename_column :locations, :total_units, :units
add_column :schemes, :total_units, :integer
end
end

5
db/migrate/20220711152629_add_unique_index_for_old_ids.rb

@ -0,0 +1,5 @@
class AddUniqueIndexForOldIds < ActiveRecord::Migration[7.0]
def change
add_index :locations, :old_id, unique: true
end
end

15
db/schema.rb

@ -10,7 +10,7 @@
# #
# It's strongly recommended that you check this file into your version control system. # It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema[7.0].define(version: 2022_07_06_104313) do ActiveRecord::Schema[7.0].define(version: 2022_07_11_152629) do
# These are extensions that must be enabled in order to support this database # These are extensions that must be enabled in order to support this database
enable_extension "plpgsql" enable_extension "plpgsql"
@ -191,9 +191,9 @@ ActiveRecord::Schema[7.0].define(version: 2022_07_06_104313) do
t.integer "joint" t.integer "joint"
t.bigint "created_by_id" t.bigint "created_by_id"
t.integer "illness_type_0" t.integer "illness_type_0"
t.integer "retirement_value_check"
t.integer "tshortfall_known" t.integer "tshortfall_known"
t.integer "sheltered" t.integer "sheltered"
t.integer "retirement_value_check"
t.integer "pregnancy_value_check" t.integer "pregnancy_value_check"
t.integer "hhtype" t.integer "hhtype"
t.integer "new_old" t.integer "new_old"
@ -247,14 +247,17 @@ ActiveRecord::Schema[7.0].define(version: 2022_07_06_104313) do
t.string "county" t.string "county"
t.datetime "created_at", null: false t.datetime "created_at", null: false
t.datetime "updated_at", null: false t.datetime "updated_at", null: false
t.integer "total_units" t.integer "units"
t.integer "type_of_unit" t.integer "type_of_unit"
t.string "old_id"
t.integer "old_visible_id"
t.index ["old_id"], name: "index_locations_on_old_id", unique: true
t.index ["scheme_id"], name: "index_locations_on_scheme_id" t.index ["scheme_id"], name: "index_locations_on_scheme_id"
end end
create_table "logs_exports", force: :cascade do |t| create_table "logs_exports", force: :cascade do |t|
t.datetime "created_at", default: -> { "CURRENT_TIMESTAMP" } t.datetime "created_at", default: -> { "CURRENT_TIMESTAMP" }
t.datetime "started_at", null: false t.datetime "started_at", precision: nil, null: false
t.integer "base_number", default: 1, null: false t.integer "base_number", default: 1, null: false
t.integer "increment_number", default: 1, null: false t.integer "increment_number", default: 1, null: false
t.boolean "empty_export", default: false, null: false t.boolean "empty_export", default: false, null: false
@ -314,6 +317,10 @@ ActiveRecord::Schema[7.0].define(version: 2022_07_06_104313) do
t.datetime "end_date" t.datetime "end_date"
t.integer "has_other_client_group" t.integer "has_other_client_group"
t.bigint "managing_organisation_id" t.bigint "managing_organisation_id"
t.string "arrangement_type"
t.string "old_id"
t.integer "old_visible_id"
t.integer "total_units"
t.index ["managing_organisation_id"], name: "index_schemes_on_managing_organisation_id" t.index ["managing_organisation_id"], name: "index_schemes_on_managing_organisation_id"
t.index ["owning_organisation_id"], name: "index_schemes_on_owning_organisation_id" t.index ["owning_organisation_id"], name: "index_schemes_on_owning_organisation_id"
end end

6
lib/tasks/data_import.rake

@ -10,12 +10,14 @@ namespace :core do
case type case type
when "organisation" when "organisation"
Imports::OrganisationImportService.new(storage_service).create_organisations(path) Imports::OrganisationImportService.new(storage_service).create_organisations(path)
when "scheme"
Imports::SchemeImportService.new(storage_service).create_schemes(path)
when "scheme-location"
Imports::SchemeLocationImportService.new(storage_service).create_scheme_locations(path)
when "user" when "user"
Imports::UserImportService.new(storage_service).create_users(path) Imports::UserImportService.new(storage_service).create_users(path)
when "data-protection-confirmation" when "data-protection-confirmation"
Imports::DataProtectionConfirmationImportService.new(storage_service).create_data_protection_confirmations(path) Imports::DataProtectionConfirmationImportService.new(storage_service).create_data_protection_confirmations(path)
when "organisation-las"
Imports::OrganisationLaImportService.new(storage_service).create_organisation_las(path)
when "organisation-rent-periods" when "organisation-rent-periods"
Imports::OrganisationRentPeriodImportService.new(storage_service).create_organisation_rent_periods(path) Imports::OrganisationRentPeriodImportService.new(storage_service).create_organisation_rent_periods(path)
when "case-logs" when "case-logs"

2
spec/factories/location.rb

@ -3,7 +3,7 @@ FactoryBot.define do
location_code { Faker::Name.initials(number: 10) } location_code { Faker::Name.initials(number: 10) }
postcode { Faker::Address.postcode.delete(" ") } postcode { Faker::Address.postcode.delete(" ") }
name { Faker::Address.street_name } name { Faker::Address.street_name }
type_of_unit { Faker::Number.within(range: 1..6) } type_of_unit { [1, 2, 3, 4, 6, 7].sample }
type_of_building { "Purpose built" } type_of_building { "Purpose built" }
wheelchair_adaptation { 0 } wheelchair_adaptation { 0 }
county { Faker::Address.state } county { Faker::Address.state }

2
spec/factories/scheme.rb

@ -2,7 +2,7 @@ FactoryBot.define do
factory :scheme do factory :scheme do
service_name { Faker::Name.name } service_name { Faker::Name.name }
sensitive { Faker::Number.within(range: 0..1) } sensitive { Faker::Number.within(range: 0..1) }
registered_under_care_act { Faker::Number.within(range: 0..1) } registered_under_care_act { 1 }
support_type { Faker::Number.within(range: 0..6) } support_type { Faker::Number.within(range: 0..6) }
scheme_type { 0 } scheme_type { 0 }
intended_stay { %w[M P S V X].sample } intended_stay { %w[M P S V X].sample }

0
spec/fixtures/softwire_imports/case_logs/00d2343e-d5fa-4c89-8400-ec3854b0f2b4.xml → spec/fixtures/imports/case_logs/00d2343e-d5fa-4c89-8400-ec3854b0f2b4.xml vendored

0
spec/fixtures/softwire_imports/case_logs/0ead17cb-1668-442d-898c-0d52879ff592.xml → spec/fixtures/imports/case_logs/0ead17cb-1668-442d-898c-0d52879ff592.xml vendored

0
spec/fixtures/softwire_imports/case_logs/166fc004-392e-47a8-acb8-1c018734882b.xml → spec/fixtures/imports/case_logs/166fc004-392e-47a8-acb8-1c018734882b.xml vendored

0
spec/fixtures/softwire_imports/case_logs/5ybz29dj-l33t-k1l0-hj86-n4k4ma77xkcd.xml → spec/fixtures/imports/case_logs/5ybz29dj-l33t-k1l0-hj86-n4k4ma77xkcd.xml vendored

0
spec/fixtures/softwire_imports/case_logs/893ufj2s-lq77-42m4-rty6-ej09gh585uy1.xml → spec/fixtures/imports/case_logs/893ufj2s-lq77-42m4-rty6-ej09gh585uy1.xml vendored

0
spec/fixtures/softwire_imports/data_protection_confirmations/7c5bd5fb549c09a2c55d7cb90d7ba84927e64618.xml → spec/fixtures/imports/data_protection_confirmations/7c5bd5fb549c09a2c55d7cb90d7ba84927e64618.xml vendored

0
spec/fixtures/softwire_imports/organisation_rent_periods/ebd22326d33e389e9f1bfd546979d2c05f9e68d6.xml → spec/fixtures/imports/organisation_rent_periods/ebd22326d33e389e9f1bfd546979d2c05f9e68d6.xml vendored

0
spec/fixtures/softwire_imports/organisations/7c5bd5fb549c09a2c55d7cb90d7ba84927e64618.xml → spec/fixtures/imports/organisations/7c5bd5fb549c09a2c55d7cb90d7ba84927e64618.xml vendored

25
spec/fixtures/imports/scheme_locations/0ae7ad6dc0f1cf7ef33c18cc8c108bebc1b4923e.xml vendored

@ -0,0 +1,25 @@
<scheme:scheme xmlns:scheme="dclg:scheme">
<scheme:id>0ae7ad6dc0f1cf7ef33c18cc8c108bebc1b4923e</scheme:id>
<scheme:name id-field="Y">Location 1</scheme:name>
<scheme:local-authority-name>134</scheme:local-authority-name>
<scheme:postcode>S44 6EJ</scheme:postcode>
<scheme:required>true</scheme:required>
<scheme:sensitive>false</scheme:sensitive>
<scheme:total-units>5</scheme:total-units>
<scheme:sp-grant>True</scheme:sp-grant>
<scheme:scheme-type>7</scheme:scheme-type>
<scheme:unit-type>6</scheme:unit-type>
<scheme:reg-home-type>1</scheme:reg-home-type>
<scheme:support-type>2</scheme:support-type>
<scheme:mobility-type>A</scheme:mobility-type>
<scheme:intended-stay>P</scheme:intended-stay>
<scheme:client-group-1>M</scheme:client-group-1>
<scheme:client-group-2/>
<scheme:start-date>1900-01-01</scheme:start-date>
<scheme:end-date>2050-12-31</scheme:end-date>
<scheme:mgmtgroup>6d6d7618b58affe2a150a5ef2e9f4765fa6cd05d</scheme:mgmtgroup>
<scheme:status>Approved</scheme:status>
<scheme:visible-id>10</scheme:visible-id>
<scheme:user-stamp>1</scheme:user-stamp>
<scheme:date-stamp>08:12.0</scheme:date-stamp>
</scheme:scheme>

23
spec/fixtures/imports/scheme_locations/0bb3836b70b4dd9903263d5a764a5c45b964a89d.xml vendored

@ -0,0 +1,23 @@
<scheme:scheme xmlns:scheme="dclg:scheme">
<scheme:id>0bb3836b70b4dd9903263d5a764a5c45b964a89d</scheme:id>
<scheme:name id-field="Y">Location 2</scheme:name>
<scheme:local-authority-name>134</scheme:local-authority-name>
<scheme:postcode>NG19 8SW</scheme:postcode>
<scheme:required>false</scheme:required>
<scheme:sensitive>false</scheme:sensitive>
<scheme:total-units>11</scheme:total-units>
<scheme:scheme-type>7</scheme:scheme-type>
<scheme:unit-type>6</scheme:unit-type>
<scheme:reg-home-type>1</scheme:reg-home-type>
<scheme:support-type>2</scheme:support-type>
<scheme:mobility-type>W</scheme:mobility-type>
<scheme:sp-grant>False</scheme:sp-grant>
<scheme:intended-stay>P</scheme:intended-stay>
<scheme:client-group-1>M</scheme:client-group-1>
<scheme:client-group-2/>
<scheme:start-date>2014-04-07</scheme:start-date>
<scheme:end-date/>
<scheme:mgmtgroup>6d6d7618b58affe2a150a5ef2e9f4765fa6cd05d</scheme:mgmtgroup>
<scheme:status>Approved</scheme:status>
<scheme:visible-id>001</scheme:visible-id>
</scheme:scheme>

9
spec/fixtures/imports/schemes/6d6d7618b58affe2a150a5ef2e9f4765fa6cd05d.xml vendored

@ -0,0 +1,9 @@
<mgmtgroup:mgmtgroup xmlns:mgmtgroup="dclg:mgmtgroup">
<mgmtgroup:id>6d6d7618b58affe2a150a5ef2e9f4765fa6cd05d</mgmtgroup:id>
<mgmtgroup:name id-field="Y">Management Group</mgmtgroup:name>
<mgmtgroup:arrangement_type>O</mgmtgroup:arrangement_type>
<mgmtgroup:agent>456</mgmtgroup:agent>
<mgmtgroup:institution>7c5bd5fb549c09z2c55d9cb90d7ba84927e64618</mgmtgroup:institution>
<mgmtgroup:status>Approved</mgmtgroup:status>
<mgmtgroup:visible-id>123</mgmtgroup:visible-id>
</mgmtgroup:mgmtgroup>

0
spec/fixtures/softwire_imports/users/10c887710550844e2551b3e0fb88dc9b4a8a642b.xml → spec/fixtures/imports/users/10c887710550844e2551b3e0fb88dc9b4a8a642b.xml vendored

0
spec/fixtures/softwire_imports/users/9ed81a262215a1634f0809effa683e38924d8bcb.xml → spec/fixtures/imports/users/9ed81a262215a1634f0809effa683e38924d8bcb.xml vendored

0
spec/fixtures/softwire_imports/users/b7829b1a5dfb68bb1e01c08445830c0add40907c.xml → spec/fixtures/imports/users/b7829b1a5dfb68bb1e01c08445830c0add40907c.xml vendored

0
spec/fixtures/softwire_imports/users/d4729b1a5dfb68bb1e01c08445830c0add40907c.xml → spec/fixtures/imports/users/d4729b1a5dfb68bb1e01c08445830c0add40907c.xml vendored

0
spec/fixtures/softwire_imports/users/d6717836154cd9a58f9e2f1d3077e3ab81e07613.xml → spec/fixtures/imports/users/d6717836154cd9a58f9e2f1d3077e3ab81e07613.xml vendored

0
spec/fixtures/softwire_imports/users/fc7625a02b24ae16162aa63ae7cb33feeec0c373.xml → spec/fixtures/imports/users/fc7625a02b24ae16162aa63ae7cb33feeec0c373.xml vendored

46
spec/lib/tasks/data_import_spec.rb

@ -22,7 +22,7 @@ describe "rake core:data_import", type: :task do
context "when importing organisation data" do context "when importing organisation data" do
let(:type) { "organisation" } let(:type) { "organisation" }
let(:import_service) { instance_double(Imports::OrganisationImportService) } let(:import_service) { instance_double(Imports::OrganisationImportService) }
let(:fixture_path) { "spec/fixtures/softwire_imports/organisations" } let(:fixture_path) { "spec/fixtures/imports/organisations" }
before do before do
allow(Imports::OrganisationImportService).to receive(:new).and_return(import_service) allow(Imports::OrganisationImportService).to receive(:new).and_return(import_service)
@ -40,7 +40,7 @@ describe "rake core:data_import", type: :task do
context "when importing user data" do context "when importing user data" do
let(:type) { "user" } let(:type) { "user" }
let(:import_service) { instance_double(Imports::UserImportService) } let(:import_service) { instance_double(Imports::UserImportService) }
let(:fixture_path) { "spec/fixtures/softwire_imports/users" } let(:fixture_path) { "spec/fixtures/imports/users" }
before do before do
allow(Imports::UserImportService).to receive(:new).and_return(import_service) allow(Imports::UserImportService).to receive(:new).and_return(import_service)
@ -58,7 +58,7 @@ describe "rake core:data_import", type: :task do
context "when importing data protection confirmation data" do context "when importing data protection confirmation data" do
let(:type) { "data-protection-confirmation" } let(:type) { "data-protection-confirmation" }
let(:import_service) { instance_double(Imports::DataProtectionConfirmationImportService) } let(:import_service) { instance_double(Imports::DataProtectionConfirmationImportService) }
let(:fixture_path) { "spec/fixtures/softwire_imports/data_protection_confirmations" } let(:fixture_path) { "spec/fixtures/imports/data_protection_confirmations" }
before do before do
allow(Imports::DataProtectionConfirmationImportService).to receive(:new).and_return(import_service) allow(Imports::DataProtectionConfirmationImportService).to receive(:new).and_return(import_service)
@ -76,7 +76,7 @@ describe "rake core:data_import", type: :task do
context "when importing organisation rent period data" do context "when importing organisation rent period data" do
let(:type) { "organisation-rent-periods" } let(:type) { "organisation-rent-periods" }
let(:import_service) { instance_double(Imports::OrganisationRentPeriodImportService) } let(:import_service) { instance_double(Imports::OrganisationRentPeriodImportService) }
let(:fixture_path) { "spec/fixtures/softwire_imports/organisation_rent_periods" } let(:fixture_path) { "spec/fixtures/imports/organisation_rent_periods" }
before do before do
allow(Imports::OrganisationRentPeriodImportService).to receive(:new).and_return(import_service) allow(Imports::OrganisationRentPeriodImportService).to receive(:new).and_return(import_service)
@ -94,7 +94,7 @@ describe "rake core:data_import", type: :task do
context "when importing case logs" do context "when importing case logs" do
let(:type) { "case-logs" } let(:type) { "case-logs" }
let(:import_service) { instance_double(Imports::CaseLogsImportService) } let(:import_service) { instance_double(Imports::CaseLogsImportService) }
let(:fixture_path) { "spec/fixtures/softwire_imports/case_logs" } let(:fixture_path) { "spec/fixtures/imports/case_logs" }
before do before do
allow(Imports::CaseLogsImportService).to receive(:new).and_return(import_service) allow(Imports::CaseLogsImportService).to receive(:new).and_return(import_service)
@ -109,6 +109,42 @@ describe "rake core:data_import", type: :task do
end end
end end
context "when importing scheme data" do
let(:type) { "scheme" }
let(:import_service) { instance_double(Imports::SchemeImportService) }
let(:fixture_path) { "spec/fixtures/imports/schemes" }
before do
allow(Imports::SchemeImportService).to receive(:new).and_return(import_service)
end
it "creates a scheme from the given XML file" do
expect(StorageService).to receive(:new).with(paas_config_service, instance_name)
expect(Imports::SchemeImportService).to receive(:new).with(storage_service)
expect(import_service).to receive(:create_schemes).with(fixture_path)
task.invoke(type, fixture_path)
end
end
context "when importing scheme location data" do
let(:type) { "scheme-location" }
let(:import_service) { instance_double(Imports::SchemeLocationImportService) }
let(:fixture_path) { "spec/fixtures/imports/organisations" }
before do
allow(Imports::SchemeLocationImportService).to receive(:new).and_return(import_service)
end
it "creates a scheme location from the given XML file" do
expect(StorageService).to receive(:new).with(paas_config_service, instance_name)
expect(Imports::SchemeLocationImportService).to receive(:new).with(storage_service)
expect(import_service).to receive(:create_scheme_locations).with(fixture_path)
task.invoke(type, fixture_path)
end
end
it "raises an exception if no parameters are provided" do it "raises an exception if no parameters are provided" do
expect { task.invoke }.to raise_error(/Usage/) expect { task.invoke }.to raise_error(/Usage/)
end end

2
spec/lib/tasks/date_import_field_spec.rb

@ -21,7 +21,7 @@ describe "rake core:data_import_field", type: :task do
context "when importing a case log field" do context "when importing a case log field" do
let(:import_service) { instance_double(Imports::CaseLogsFieldImportService) } let(:import_service) { instance_double(Imports::CaseLogsFieldImportService) }
let(:fixture_path) { "spec/fixtures/softwire_imports/case_logs" } let(:fixture_path) { "spec/fixtures/imports/case_logs" }
before do before do
allow(Imports::CaseLogsFieldImportService).to receive(:new).and_return(import_service) allow(Imports::CaseLogsFieldImportService).to receive(:new).and_return(import_service)

84
spec/requests/locations_controller_spec.rb

@ -90,7 +90,7 @@ RSpec.describe LocationsController, type: :request do
context "when signed in as a data coordinator" do context "when signed in as a data coordinator" do
let(:user) { FactoryBot.create(:user, :data_coordinator) } let(:user) { FactoryBot.create(:user, :data_coordinator) }
let!(:scheme) { FactoryBot.create(:scheme, owning_organisation: user.organisation) } let!(:scheme) { FactoryBot.create(:scheme, owning_organisation: user.organisation) }
let(:params) { { location: { name: "Test", total_units: "5", type_of_unit: "Bungalow", wheelchair_adaptation: "No", add_another_location: "No", postcode: "ZZ1 1ZZ" } } } let(:params) { { location: { name: "Test", units: "5", type_of_unit: "Bungalow", wheelchair_adaptation: "No", add_another_location: "No", postcode: "ZZ1 1ZZ" } } }
before do before do
sign_in user sign_in user
@ -108,13 +108,13 @@ RSpec.describe LocationsController, type: :request do
expect(Location.last.scheme.owning_organisation_id).to eq(user.organisation_id) expect(Location.last.scheme.owning_organisation_id).to eq(user.organisation_id)
expect(Location.last.name).to eq("Test") expect(Location.last.name).to eq("Test")
expect(Location.last.postcode).to eq("ZZ11ZZ") expect(Location.last.postcode).to eq("ZZ11ZZ")
expect(Location.last.total_units).to eq(5) expect(Location.last.units).to eq(5)
expect(Location.last.type_of_unit).to eq("Bungalow") expect(Location.last.type_of_unit).to eq("Bungalow")
expect(Location.last.wheelchair_adaptation).to eq("No") expect(Location.last.wheelchair_adaptation).to eq("No")
end end
context "when postcode is submitted with lower case" do context "when postcode is submitted with lower case" do
let(:params) { { location: { name: "Test", total_units: "5", type_of_unit: "Bungalow", wheelchair_adaptation: "No", add_another_location: "No", postcode: "zz1 1zz" } } } let(:params) { { location: { name: "Test", units: "5", type_of_unit: "Bungalow", wheelchair_adaptation: "No", add_another_location: "No", postcode: "zz1 1zz" } } }
it "creates a new location for scheme with postcode " do it "creates a new location for scheme with postcode " do
expect(Location.last.postcode).to eq("ZZ11ZZ") expect(Location.last.postcode).to eq("ZZ11ZZ")
@ -123,7 +123,7 @@ RSpec.describe LocationsController, type: :request do
context "when trying to add location to a scheme that belongs to another organisation" do context "when trying to add location to a scheme that belongs to another organisation" do
let(:another_scheme) { FactoryBot.create(:scheme) } let(:another_scheme) { FactoryBot.create(:scheme) }
let(:params) { { location: { name: "Test", total_units: "5", type_of_unit: "Bungalow", wheelchair_adaptation: "No", add_another_location: "No", postcode: "ZZ1 1ZZ" } } } let(:params) { { location: { name: "Test", units: "5", type_of_unit: "Bungalow", wheelchair_adaptation: "No", add_another_location: "No", postcode: "ZZ1 1ZZ" } } }
it "displays the new page with an error message" do it "displays the new page with an error message" do
post "/schemes/#{another_scheme.id}/locations", params: params post "/schemes/#{another_scheme.id}/locations", params: params
@ -132,7 +132,7 @@ RSpec.describe LocationsController, type: :request do
end end
context "when required postcode param is missing" do context "when required postcode param is missing" do
let(:params) { { location: { name: "Test", total_units: "5", type_of_unit: "Bungalow", wheelchair_adaptation: "No", add_another_location: "No" } } } let(:params) { { location: { name: "Test", units: "5", type_of_unit: "Bungalow", wheelchair_adaptation: "No", add_another_location: "No" } } }
it "displays the new page with an error message" do it "displays the new page with an error message" do
expect(response).to have_http_status(:unprocessable_entity) expect(response).to have_http_status(:unprocessable_entity)
@ -141,7 +141,7 @@ RSpec.describe LocationsController, type: :request do
end end
context "when do you want to add another location is selected as yes" do context "when do you want to add another location is selected as yes" do
let(:params) { { location: { name: "Test", total_units: "5", type_of_unit: "Bungalow", wheelchair_adaptation: "No", add_another_location: "Yes", postcode: "ZZ1 1ZZ" } } } let(:params) { { location: { name: "Test", units: "5", type_of_unit: "Bungalow", wheelchair_adaptation: "No", add_another_location: "Yes", postcode: "ZZ1 1ZZ" } } }
it "creates a new location for scheme with valid params and redirects to correct page" do it "creates a new location for scheme with valid params and redirects to correct page" do
expect { post "/schemes/#{scheme.id}/locations", params: }.to change(Location, :count).by(1) expect { post "/schemes/#{scheme.id}/locations", params: }.to change(Location, :count).by(1)
@ -153,14 +153,14 @@ RSpec.describe LocationsController, type: :request do
it "creates a new location for scheme with valid params" do it "creates a new location for scheme with valid params" do
expect(Location.last.scheme.owning_organisation_id).to eq(user.organisation_id) expect(Location.last.scheme.owning_organisation_id).to eq(user.organisation_id)
expect(Location.last.name).to eq("Test") expect(Location.last.name).to eq("Test")
expect(Location.last.total_units).to eq(5) expect(Location.last.units).to eq(5)
expect(Location.last.type_of_unit).to eq("Bungalow") expect(Location.last.type_of_unit).to eq("Bungalow")
expect(Location.last.wheelchair_adaptation).to eq("No") expect(Location.last.wheelchair_adaptation).to eq("No")
end end
end end
context "when do you want to add another location is selected as no" do context "when do you want to add another location is selected as no" do
let(:params) { { location: { name: "Test", total_units: "5", type_of_unit: "Bungalow", wheelchair_adaptation: "No", add_another_location: "No", postcode: "ZZ1 1ZZ" } } } let(:params) { { location: { name: "Test", units: "5", type_of_unit: "Bungalow", wheelchair_adaptation: "No", add_another_location: "No", postcode: "ZZ1 1ZZ" } } }
it "creates a new location for scheme with valid params and redirects to correct page" do it "creates a new location for scheme with valid params and redirects to correct page" do
expect { post "/schemes/#{scheme.id}/locations", params: }.to change(Location, :count).by(1) expect { post "/schemes/#{scheme.id}/locations", params: }.to change(Location, :count).by(1)
@ -172,14 +172,14 @@ RSpec.describe LocationsController, type: :request do
it "creates a new location for scheme with valid params" do it "creates a new location for scheme with valid params" do
expect(Location.last.scheme.owning_organisation_id).to eq(user.organisation_id) expect(Location.last.scheme.owning_organisation_id).to eq(user.organisation_id)
expect(Location.last.name).to eq("Test") expect(Location.last.name).to eq("Test")
expect(Location.last.total_units).to eq(5) expect(Location.last.units).to eq(5)
expect(Location.last.type_of_unit).to eq("Bungalow") expect(Location.last.type_of_unit).to eq("Bungalow")
expect(Location.last.wheelchair_adaptation).to eq("No") expect(Location.last.wheelchair_adaptation).to eq("No")
end end
end end
context "when do you want to add another location is not selected" do context "when do you want to add another location is not selected" do
let(:params) { { location: { name: "Test", total_units: "5", type_of_unit: "Bungalow", wheelchair_adaptation: "No", postcode: "ZZ1 1ZZ" } } } let(:params) { { location: { name: "Test", units: "5", type_of_unit: "Bungalow", wheelchair_adaptation: "No", postcode: "ZZ1 1ZZ" } } }
it "creates a new location for scheme with valid params and redirects to correct page" do it "creates a new location for scheme with valid params and redirects to correct page" do
expect { post "/schemes/#{scheme.id}/locations", params: }.to change(Location, :count).by(1) expect { post "/schemes/#{scheme.id}/locations", params: }.to change(Location, :count).by(1)
@ -191,7 +191,7 @@ RSpec.describe LocationsController, type: :request do
it "creates a new location for scheme with valid params" do it "creates a new location for scheme with valid params" do
expect(Location.last.scheme.owning_organisation_id).to eq(user.organisation_id) expect(Location.last.scheme.owning_organisation_id).to eq(user.organisation_id)
expect(Location.last.name).to eq("Test") expect(Location.last.name).to eq("Test")
expect(Location.last.total_units).to eq(5) expect(Location.last.units).to eq(5)
expect(Location.last.type_of_unit).to eq("Bungalow") expect(Location.last.type_of_unit).to eq("Bungalow")
expect(Location.last.wheelchair_adaptation).to eq("No") expect(Location.last.wheelchair_adaptation).to eq("No")
end end
@ -201,7 +201,7 @@ RSpec.describe LocationsController, type: :request do
context "when signed in as a support user" do context "when signed in as a support user" do
let(:user) { FactoryBot.create(:user, :support) } let(:user) { FactoryBot.create(:user, :support) }
let!(:scheme) { FactoryBot.create(:scheme) } let!(:scheme) { FactoryBot.create(:scheme) }
let(:params) { { location: { name: "Test", total_units: "5", type_of_unit: "Bungalow", wheelchair_adaptation: "No", add_another_location: "No", postcode: "ZZ1 1ZZ" } } } let(:params) { { location: { name: "Test", units: "5", type_of_unit: "Bungalow", wheelchair_adaptation: "No", add_another_location: "No", postcode: "ZZ1 1ZZ" } } }
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)
@ -219,13 +219,13 @@ RSpec.describe LocationsController, type: :request do
it "creates a new location for scheme with valid params" do it "creates a new location for scheme with valid params" do
expect(Location.last.name).to eq("Test") expect(Location.last.name).to eq("Test")
expect(Location.last.postcode).to eq("ZZ11ZZ") expect(Location.last.postcode).to eq("ZZ11ZZ")
expect(Location.last.total_units).to eq(5) expect(Location.last.units).to eq(5)
expect(Location.last.type_of_unit).to eq("Bungalow") expect(Location.last.type_of_unit).to eq("Bungalow")
expect(Location.last.wheelchair_adaptation).to eq("No") expect(Location.last.wheelchair_adaptation).to eq("No")
end end
context "when postcode is submitted with lower case" do context "when postcode is submitted with lower case" do
let(:params) { { location: { name: "Test", total_units: "5", type_of_unit: "Bungalow", wheelchair_adaptation: "No", add_another_location: "No", postcode: "zz1 1zz" } } } let(:params) { { location: { name: "Test", units: "5", type_of_unit: "Bungalow", wheelchair_adaptation: "No", add_another_location: "No", postcode: "zz1 1zz" } } }
it "creates a new location for scheme with postcode " do it "creates a new location for scheme with postcode " do
expect(Location.last.postcode).to eq("ZZ11ZZ") expect(Location.last.postcode).to eq("ZZ11ZZ")
@ -233,7 +233,7 @@ RSpec.describe LocationsController, type: :request do
end end
context "when required postcode param is missing" do context "when required postcode param is missing" do
let(:params) { { location: { name: "Test", total_units: "5", type_of_unit: "Bungalow", wheelchair_adaptation: "No", add_another_location: "No" } } } let(:params) { { location: { name: "Test", units: "5", type_of_unit: "Bungalow", wheelchair_adaptation: "No", add_another_location: "No" } } }
it "displays the new page with an error message" do it "displays the new page with an error message" do
post "/schemes/#{scheme.id}/locations", params: params post "/schemes/#{scheme.id}/locations", params: params
@ -243,7 +243,7 @@ RSpec.describe LocationsController, type: :request do
end end
context "when do you want to add another location is selected as yes" do context "when do you want to add another location is selected as yes" do
let(:params) { { location: { name: "Test", total_units: "5", type_of_unit: "Bungalow", wheelchair_adaptation: "No", add_another_location: "Yes", postcode: "ZZ1 1ZZ" } } } let(:params) { { location: { name: "Test", units: "5", type_of_unit: "Bungalow", wheelchair_adaptation: "No", add_another_location: "Yes", postcode: "ZZ1 1ZZ" } } }
it "creates a new location for scheme with valid params and redirects to correct page" do it "creates a new location for scheme with valid params and redirects to correct page" do
expect { post "/schemes/#{scheme.id}/locations", params: }.to change(Location, :count).by(1) expect { post "/schemes/#{scheme.id}/locations", params: }.to change(Location, :count).by(1)
@ -254,14 +254,14 @@ RSpec.describe LocationsController, type: :request do
it "creates a new location for scheme with valid params" do it "creates a new location for scheme with valid params" do
expect(Location.last.name).to eq("Test") expect(Location.last.name).to eq("Test")
expect(Location.last.total_units).to eq(5) expect(Location.last.units).to eq(5)
expect(Location.last.type_of_unit).to eq("Bungalow") expect(Location.last.type_of_unit).to eq("Bungalow")
expect(Location.last.wheelchair_adaptation).to eq("No") expect(Location.last.wheelchair_adaptation).to eq("No")
end end
end end
context "when do you want to add another location is selected as no" do context "when do you want to add another location is selected as no" do
let(:params) { { location: { name: "Test", total_units: "5", type_of_unit: "Bungalow", wheelchair_adaptation: "No", add_another_location: "No", postcode: "ZZ1 1ZZ" } } } let(:params) { { location: { name: "Test", units: "5", type_of_unit: "Bungalow", wheelchair_adaptation: "No", add_another_location: "No", postcode: "ZZ1 1ZZ" } } }
it "creates a new location for scheme with valid params and redirects to correct page" do it "creates a new location for scheme with valid params and redirects to correct page" do
expect { post "/schemes/#{scheme.id}/locations", params: }.to change(Location, :count).by(1) expect { post "/schemes/#{scheme.id}/locations", params: }.to change(Location, :count).by(1)
@ -272,14 +272,14 @@ RSpec.describe LocationsController, type: :request do
it "creates a new location for scheme with valid params" do it "creates a new location for scheme with valid params" do
expect(Location.last.name).to eq("Test") expect(Location.last.name).to eq("Test")
expect(Location.last.total_units).to eq(5) expect(Location.last.units).to eq(5)
expect(Location.last.type_of_unit).to eq("Bungalow") expect(Location.last.type_of_unit).to eq("Bungalow")
expect(Location.last.wheelchair_adaptation).to eq("No") expect(Location.last.wheelchair_adaptation).to eq("No")
end end
end end
context "when do you want to add another location is not selected" do context "when do you want to add another location is not selected" do
let(:params) { { location: { name: "Test", total_units: "5", type_of_unit: "Bungalow", wheelchair_adaptation: "No", postcode: "ZZ1 1ZZ" } } } let(:params) { { location: { name: "Test", units: "5", type_of_unit: "Bungalow", wheelchair_adaptation: "No", postcode: "ZZ1 1ZZ" } } }
it "creates a new location for scheme with valid params and redirects to correct page" do it "creates a new location for scheme with valid params and redirects to correct page" do
expect { post "/schemes/#{scheme.id}/locations", params: }.to change(Location, :count).by(1) expect { post "/schemes/#{scheme.id}/locations", params: }.to change(Location, :count).by(1)
@ -290,7 +290,7 @@ RSpec.describe LocationsController, type: :request do
it "creates a new location for scheme with valid params" do it "creates a new location for scheme with valid params" do
expect(Location.last.name).to eq("Test") expect(Location.last.name).to eq("Test")
expect(Location.last.total_units).to eq(5) expect(Location.last.units).to eq(5)
expect(Location.last.type_of_unit).to eq("Bungalow") expect(Location.last.type_of_unit).to eq("Bungalow")
expect(Location.last.wheelchair_adaptation).to eq("No") expect(Location.last.wheelchair_adaptation).to eq("No")
end end
@ -390,7 +390,7 @@ RSpec.describe LocationsController, type: :request do
let(:user) { FactoryBot.create(:user, :data_coordinator) } let(:user) { FactoryBot.create(:user, :data_coordinator) }
let!(:scheme) { FactoryBot.create(:scheme, owning_organisation: user.organisation) } let!(:scheme) { FactoryBot.create(:scheme, owning_organisation: user.organisation) }
let!(:location) { FactoryBot.create(:location, scheme:) } let!(:location) { FactoryBot.create(:location, scheme:) }
let(:params) { { location: { name: "Test", total_units: "5", type_of_unit: "Bungalow", wheelchair_adaptation: "No", add_another_location: "No", postcode: "ZZ1 1ZZ", page: "edit" } } } let(:params) { { location: { name: "Test", units: "5", type_of_unit: "Bungalow", wheelchair_adaptation: "No", add_another_location: "No", postcode: "ZZ1 1ZZ", page: "edit" } } }
before do before do
sign_in user sign_in user
@ -407,7 +407,7 @@ RSpec.describe LocationsController, type: :request do
expect(Location.last.scheme.owning_organisation_id).to eq(user.organisation_id) expect(Location.last.scheme.owning_organisation_id).to eq(user.organisation_id)
expect(Location.last.name).to eq("Test") expect(Location.last.name).to eq("Test")
expect(Location.last.postcode).to eq("ZZ11ZZ") expect(Location.last.postcode).to eq("ZZ11ZZ")
expect(Location.last.total_units).to eq(5) expect(Location.last.units).to eq(5)
expect(Location.last.type_of_unit).to eq("Bungalow") expect(Location.last.type_of_unit).to eq("Bungalow")
expect(Location.last.wheelchair_adaptation).to eq("No") expect(Location.last.wheelchair_adaptation).to eq("No")
end end
@ -427,7 +427,7 @@ RSpec.describe LocationsController, type: :request do
end end
context "when postcode is submitted with lower case" do context "when postcode is submitted with lower case" do
let(:params) { { location: { name: "Test", total_units: "5", type_of_unit: "Bungalow", wheelchair_adaptation: "No", add_another_location: "No", postcode: "zz1 1zz", page: "edit" } } } let(:params) { { location: { name: "Test", units: "5", type_of_unit: "Bungalow", wheelchair_adaptation: "No", add_another_location: "No", postcode: "zz1 1zz", page: "edit" } } }
it "updates existing location for scheme with postcode " do it "updates existing location for scheme with postcode " do
expect(Location.last.postcode).to eq("ZZ11ZZ") expect(Location.last.postcode).to eq("ZZ11ZZ")
@ -437,7 +437,7 @@ RSpec.describe LocationsController, type: :request do
context "when trying to update location for a scheme that belongs to another organisation" do context "when trying to update location for a scheme that belongs to another organisation" do
let(:another_scheme) { FactoryBot.create(:scheme) } let(:another_scheme) { FactoryBot.create(:scheme) }
let(:another_location) { FactoryBot.create(:location) } let(:another_location) { FactoryBot.create(:location) }
let(:params) { { location: { name: "Test", total_units: "5", type_of_unit: "Bungalow", wheelchair_adaptation: "No", add_another_location: "No", postcode: "ZZ1 1ZZ", page: "edit" } } } let(:params) { { location: { name: "Test", units: "5", type_of_unit: "Bungalow", wheelchair_adaptation: "No", add_another_location: "No", postcode: "ZZ1 1ZZ", page: "edit" } } }
it "displays the new page with an error message" do it "displays the new page with an error message" do
patch "/schemes/#{another_scheme.id}/locations/#{another_location.id}", params: params patch "/schemes/#{another_scheme.id}/locations/#{another_location.id}", params: params
@ -446,7 +446,7 @@ RSpec.describe LocationsController, type: :request do
end end
context "when required postcode param is invalid" do context "when required postcode param is invalid" do
let(:params) { { location: { name: "Test", total_units: "5", type_of_unit: "Bungalow", wheelchair_adaptation: "No", add_another_location: "No", postcode: "invalid", page: "edit" } } } let(:params) { { location: { name: "Test", units: "5", type_of_unit: "Bungalow", wheelchair_adaptation: "No", add_another_location: "No", postcode: "invalid", page: "edit" } } }
it "displays the new page with an error message" do it "displays the new page with an error message" do
expect(response).to have_http_status(:unprocessable_entity) expect(response).to have_http_status(:unprocessable_entity)
@ -455,7 +455,7 @@ RSpec.describe LocationsController, type: :request do
end end
context "when do you want to add another location is selected as yes" do context "when do you want to add another location is selected as yes" do
let(:params) { { location: { name: "Test", total_units: "5", type_of_unit: "Bungalow", wheelchair_adaptation: "No", add_another_location: "Yes", postcode: "ZZ1 1ZZ", page: "edit" } } } let(:params) { { location: { name: "Test", units: "5", type_of_unit: "Bungalow", wheelchair_adaptation: "No", add_another_location: "Yes", postcode: "ZZ1 1ZZ", page: "edit" } } }
it "updates existing location for scheme with valid params and redirects to correct page" do it "updates existing location for scheme with valid params and redirects to correct page" do
follow_redirect! follow_redirect!
@ -466,14 +466,14 @@ RSpec.describe LocationsController, type: :request do
it "updates existing location for scheme with valid params" do it "updates existing location for scheme with valid params" do
expect(Location.last.scheme.owning_organisation_id).to eq(user.organisation_id) expect(Location.last.scheme.owning_organisation_id).to eq(user.organisation_id)
expect(Location.last.name).to eq("Test") expect(Location.last.name).to eq("Test")
expect(Location.last.total_units).to eq(5) expect(Location.last.units).to eq(5)
expect(Location.last.type_of_unit).to eq("Bungalow") expect(Location.last.type_of_unit).to eq("Bungalow")
expect(Location.last.wheelchair_adaptation).to eq("No") expect(Location.last.wheelchair_adaptation).to eq("No")
end end
end end
context "when do you want to add another location is selected as no" do context "when do you want to add another location is selected as no" do
let(:params) { { location: { name: "Test", total_units: "5", type_of_unit: "Bungalow", wheelchair_adaptation: "No", add_another_location: "No", postcode: "ZZ1 1ZZ", page: "edit" } } } let(:params) { { location: { name: "Test", units: "5", type_of_unit: "Bungalow", wheelchair_adaptation: "No", add_another_location: "No", postcode: "ZZ1 1ZZ", page: "edit" } } }
it "updates existing location for scheme with valid params and redirects to correct page" do it "updates existing location for scheme with valid params and redirects to correct page" do
follow_redirect! follow_redirect!
@ -484,14 +484,14 @@ RSpec.describe LocationsController, type: :request do
it "updates existing location for scheme with valid params" do it "updates existing location for scheme with valid params" do
expect(Location.last.scheme.owning_organisation_id).to eq(user.organisation_id) expect(Location.last.scheme.owning_organisation_id).to eq(user.organisation_id)
expect(Location.last.name).to eq("Test") expect(Location.last.name).to eq("Test")
expect(Location.last.total_units).to eq(5) expect(Location.last.units).to eq(5)
expect(Location.last.type_of_unit).to eq("Bungalow") expect(Location.last.type_of_unit).to eq("Bungalow")
expect(Location.last.wheelchair_adaptation).to eq("No") expect(Location.last.wheelchair_adaptation).to eq("No")
end end
end end
context "when do you want to add another location is not selected" do context "when do you want to add another location is not selected" do
let(:params) { { location: { name: "Test", total_units: "5", type_of_unit: "Bungalow", wheelchair_adaptation: "No", postcode: "ZZ1 1ZZ", page: "edit" } } } let(:params) { { location: { name: "Test", units: "5", type_of_unit: "Bungalow", wheelchair_adaptation: "No", postcode: "ZZ1 1ZZ", page: "edit" } } }
it "updates existing location for scheme with valid params and redirects to correct page" do it "updates existing location for scheme with valid params and redirects to correct page" do
follow_redirect! follow_redirect!
@ -502,7 +502,7 @@ RSpec.describe LocationsController, type: :request do
it "updates existing location for scheme with valid params" do it "updates existing location for scheme with valid params" do
expect(Location.last.scheme.owning_organisation_id).to eq(user.organisation_id) expect(Location.last.scheme.owning_organisation_id).to eq(user.organisation_id)
expect(Location.last.name).to eq("Test") expect(Location.last.name).to eq("Test")
expect(Location.last.total_units).to eq(5) expect(Location.last.units).to eq(5)
expect(Location.last.type_of_unit).to eq("Bungalow") expect(Location.last.type_of_unit).to eq("Bungalow")
expect(Location.last.wheelchair_adaptation).to eq("No") expect(Location.last.wheelchair_adaptation).to eq("No")
end end
@ -513,7 +513,7 @@ RSpec.describe LocationsController, type: :request do
let(:user) { FactoryBot.create(:user, :data_coordinator) } let(:user) { FactoryBot.create(:user, :data_coordinator) }
let!(:scheme) { FactoryBot.create(:scheme, owning_organisation: user.organisation) } let!(:scheme) { FactoryBot.create(:scheme, owning_organisation: user.organisation) }
let!(:location) { FactoryBot.create(:location, scheme:) } let!(:location) { FactoryBot.create(:location, scheme:) }
let(:params) { { location: { name: "Test", total_units: "5", type_of_unit: "Bungalow", wheelchair_adaptation: "No", add_another_location: "No", postcode: "ZZ1 1ZZ", page: "edit" } } } let(:params) { { location: { name: "Test", units: "5", type_of_unit: "Bungalow", wheelchair_adaptation: "No", add_another_location: "No", postcode: "ZZ1 1ZZ", page: "edit" } } }
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)
@ -530,7 +530,7 @@ RSpec.describe LocationsController, type: :request do
it "updates existing location for scheme with valid params" do it "updates existing location for scheme with valid params" do
expect(Location.last.name).to eq("Test") expect(Location.last.name).to eq("Test")
expect(Location.last.postcode).to eq("ZZ11ZZ") expect(Location.last.postcode).to eq("ZZ11ZZ")
expect(Location.last.total_units).to eq(5) expect(Location.last.units).to eq(5)
expect(Location.last.type_of_unit).to eq("Bungalow") expect(Location.last.type_of_unit).to eq("Bungalow")
expect(Location.last.wheelchair_adaptation).to eq("No") expect(Location.last.wheelchair_adaptation).to eq("No")
end end
@ -550,7 +550,7 @@ RSpec.describe LocationsController, type: :request do
end end
context "when postcode is submitted with lower case" do context "when postcode is submitted with lower case" do
let(:params) { { location: { name: "Test", total_units: "5", type_of_unit: "Bungalow", wheelchair_adaptation: "No", add_another_location: "No", postcode: "zz1 1zz", page: "edit" } } } let(:params) { { location: { name: "Test", units: "5", type_of_unit: "Bungalow", wheelchair_adaptation: "No", add_another_location: "No", postcode: "zz1 1zz", page: "edit" } } }
it "updates a location for scheme with postcode " do it "updates a location for scheme with postcode " do
expect(Location.last.postcode).to eq("ZZ11ZZ") expect(Location.last.postcode).to eq("ZZ11ZZ")
@ -558,7 +558,7 @@ RSpec.describe LocationsController, type: :request do
end end
context "when required postcode param is missing" do context "when required postcode param is missing" do
let(:params) { { location: { name: "Test", total_units: "5", type_of_unit: "Bungalow", wheelchair_adaptation: "No", add_another_location: "No", postcode: "invalid", page: "edit" } } } let(:params) { { location: { name: "Test", units: "5", type_of_unit: "Bungalow", wheelchair_adaptation: "No", add_another_location: "No", postcode: "invalid", page: "edit" } } }
it "displays the new page with an error message" do it "displays the new page with an error message" do
expect(response).to have_http_status(:unprocessable_entity) expect(response).to have_http_status(:unprocessable_entity)
@ -567,7 +567,7 @@ RSpec.describe LocationsController, type: :request do
end end
context "when do you want to add another location is selected as yes" do context "when do you want to add another location is selected as yes" do
let(:params) { { location: { name: "Test", total_units: "5", type_of_unit: "Bungalow", wheelchair_adaptation: "No", add_another_location: "Yes", postcode: "ZZ1 1ZZ", page: "edit" } } } let(:params) { { location: { name: "Test", units: "5", type_of_unit: "Bungalow", wheelchair_adaptation: "No", add_another_location: "Yes", postcode: "ZZ1 1ZZ", page: "edit" } } }
it "updates location for scheme with valid params and redirects to correct page" do it "updates location for scheme with valid params and redirects to correct page" do
follow_redirect! follow_redirect!
@ -577,14 +577,14 @@ RSpec.describe LocationsController, type: :request do
it "updates existing location for scheme with valid params" do it "updates existing location for scheme with valid params" do
expect(Location.last.name).to eq("Test") expect(Location.last.name).to eq("Test")
expect(Location.last.total_units).to eq(5) expect(Location.last.units).to eq(5)
expect(Location.last.type_of_unit).to eq("Bungalow") expect(Location.last.type_of_unit).to eq("Bungalow")
expect(Location.last.wheelchair_adaptation).to eq("No") expect(Location.last.wheelchair_adaptation).to eq("No")
end end
end end
context "when do you want to add another location is selected as no" do context "when do you want to add another location is selected as no" do
let(:params) { { location: { name: "Test", total_units: "5", type_of_unit: "Bungalow", wheelchair_adaptation: "No", add_another_location: "No", postcode: "ZZ1 1ZZ", page: "edit" } } } let(:params) { { location: { name: "Test", units: "5", type_of_unit: "Bungalow", wheelchair_adaptation: "No", add_another_location: "No", postcode: "ZZ1 1ZZ", page: "edit" } } }
it "updates a location for scheme with valid params and redirects to correct page" do it "updates a location for scheme with valid params and redirects to correct page" do
follow_redirect! follow_redirect!
@ -594,14 +594,14 @@ RSpec.describe LocationsController, type: :request do
it "updates existing location for scheme with valid params" do it "updates existing location for scheme with valid params" do
expect(Location.last.name).to eq("Test") expect(Location.last.name).to eq("Test")
expect(Location.last.total_units).to eq(5) expect(Location.last.units).to eq(5)
expect(Location.last.type_of_unit).to eq("Bungalow") expect(Location.last.type_of_unit).to eq("Bungalow")
expect(Location.last.wheelchair_adaptation).to eq("No") expect(Location.last.wheelchair_adaptation).to eq("No")
end end
end end
context "when do you want to add another location is not selected" do context "when do you want to add another location is not selected" do
let(:params) { { location: { name: "Test", total_units: "5", type_of_unit: "Bungalow", wheelchair_adaptation: "No", postcode: "ZZ1 1ZZ", page: "edit" } } } let(:params) { { location: { name: "Test", units: "5", type_of_unit: "Bungalow", wheelchair_adaptation: "No", postcode: "ZZ1 1ZZ", page: "edit" } } }
it "updates a location for scheme with valid params and redirects to correct page" do it "updates a location for scheme with valid params and redirects to correct page" do
follow_redirect! follow_redirect!
@ -611,7 +611,7 @@ RSpec.describe LocationsController, type: :request do
it "updates a location for scheme with valid params" do it "updates a location for scheme with valid params" do
expect(Location.last.name).to eq("Test") expect(Location.last.name).to eq("Test")
expect(Location.last.total_units).to eq(5) expect(Location.last.units).to eq(5)
expect(Location.last.type_of_unit).to eq("Bungalow") expect(Location.last.type_of_unit).to eq("Bungalow")
expect(Location.last.wheelchair_adaptation).to eq("No") expect(Location.last.wheelchair_adaptation).to eq("No")
end end

2
spec/services/imports/case_logs_field_import_service_spec.rb

@ -7,7 +7,7 @@ RSpec.describe Imports::CaseLogsFieldImportService do
let(:logger) { instance_double(ActiveSupport::Logger) } let(:logger) { instance_double(ActiveSupport::Logger) }
let(:real_2021_2022_form) { Form.new("config/forms/2021_2022.json", "2021_2022") } let(:real_2021_2022_form) { Form.new("config/forms/2021_2022.json", "2021_2022") }
let(:fixture_directory) { "spec/fixtures/softwire_imports/case_logs" } let(:fixture_directory) { "spec/fixtures/imports/case_logs" }
let(:case_log_id) { "0ead17cb-1668-442d-898c-0d52879ff592" } let(:case_log_id) { "0ead17cb-1668-442d-898c-0d52879ff592" }
let(:case_log_file) { open_file(fixture_directory, case_log_id) } let(:case_log_file) { open_file(fixture_directory, case_log_id) }

2
spec/services/imports/case_logs_import_service_spec.rb

@ -8,7 +8,7 @@ RSpec.describe Imports::CaseLogsImportService do
let(:real_2021_2022_form) { Form.new("config/forms/2021_2022.json", "2021_2022") } let(:real_2021_2022_form) { Form.new("config/forms/2021_2022.json", "2021_2022") }
let(:real_2022_2023_form) { Form.new("config/forms/2022_2023.json", "2022_2023") } let(:real_2022_2023_form) { Form.new("config/forms/2022_2023.json", "2022_2023") }
let(:fixture_directory) { "spec/fixtures/softwire_imports/case_logs" } let(:fixture_directory) { "spec/fixtures/imports/case_logs" }
let(:organisation) { FactoryBot.create(:organisation, old_visible_id: "1", provider_type: "PRP") } let(:organisation) { FactoryBot.create(:organisation, old_visible_id: "1", provider_type: "PRP") }
def open_file(directory, filename) def open_file(directory, filename)

2
spec/services/imports/data_protection_confirmation_import_service_spec.rb

@ -1,7 +1,7 @@
require "rails_helper" require "rails_helper"
RSpec.describe Imports::DataProtectionConfirmationImportService do RSpec.describe Imports::DataProtectionConfirmationImportService do
let(:fixture_directory) { "spec/fixtures/softwire_imports/data_protection_confirmations" } let(:fixture_directory) { "spec/fixtures/imports/data_protection_confirmations" }
let(:old_org_id) { "7c5bd5fb549c09a2c55d7cb90d7ba84927e64618" } let(:old_org_id) { "7c5bd5fb549c09a2c55d7cb90d7ba84927e64618" }
let(:old_id) { old_org_id } let(:old_id) { old_org_id }
let(:import_file) { File.open("#{fixture_directory}/#{old_id}.xml") } let(:import_file) { File.open("#{fixture_directory}/#{old_id}.xml") }

2
spec/services/imports/organisation_import_service_spec.rb

@ -5,7 +5,7 @@ RSpec.describe Imports::OrganisationImportService do
let(:logger) { instance_double(Rails::Rack::Logger) } let(:logger) { instance_double(Rails::Rack::Logger) }
let(:folder_name) { "organisations" } let(:folder_name) { "organisations" }
let(:filenames) { %w[my_folder/my_file1.xml my_folder/my_file2.xml] } let(:filenames) { %w[my_folder/my_file1.xml my_folder/my_file2.xml] }
let(:fixture_directory) { "spec/fixtures/softwire_imports/organisations" } let(:fixture_directory) { "spec/fixtures/imports/organisations" }
def create_organisation_file(fixture_directory, visible_id, name = nil) def create_organisation_file(fixture_directory, visible_id, name = nil)
file = File.open("#{fixture_directory}/7c5bd5fb549c09a2c55d7cb90d7ba84927e64618.xml") file = File.open("#{fixture_directory}/7c5bd5fb549c09a2c55d7cb90d7ba84927e64618.xml")

2
spec/services/imports/organisation_rent_period_import_service_spec.rb

@ -1,7 +1,7 @@
require "rails_helper" require "rails_helper"
RSpec.describe Imports::OrganisationRentPeriodImportService do RSpec.describe Imports::OrganisationRentPeriodImportService do
let(:fixture_directory) { "spec/fixtures/softwire_imports/organisation_rent_periods" } let(:fixture_directory) { "spec/fixtures/imports/organisation_rent_periods" }
let(:old_org_id) { "44026acc7ed5c29516b26f2a5deb639e5e37966d" } let(:old_org_id) { "44026acc7ed5c29516b26f2a5deb639e5e37966d" }
let(:old_id) { "ebd22326d33e389e9f1bfd546979d2c05f9e68d6" } let(:old_id) { "ebd22326d33e389e9f1bfd546979d2c05f9e68d6" }
let(:import_file) { File.open("#{fixture_directory}/#{old_id}.xml") } let(:import_file) { File.open("#{fixture_directory}/#{old_id}.xml") }

64
spec/services/imports/scheme_import_service_spec.rb

@ -0,0 +1,64 @@
require "rails_helper"
RSpec.describe Imports::SchemeImportService do
subject(:scheme_service) { described_class.new(storage_service, logger) }
let(:storage_service) { instance_double(StorageService) }
let(:logger) { instance_double(ActiveSupport::Logger) }
let(:fixture_directory) { "spec/fixtures/imports/schemes" }
let(:scheme_id) { "6d6d7618b58affe2a150a5ef2e9f4765fa6cd05d" }
let!(:owning_org) { FactoryBot.create(:organisation, old_org_id: "7c5bd5fb549c09z2c55d9cb90d7ba84927e64618") }
let!(:managing_org) { FactoryBot.create(:organisation, old_visible_id: 456) }
def open_file(directory, filename)
File.open("#{directory}/#{filename}.xml")
end
context "when importing schemes" do
let(:remote_folder) { "mgmtgroups" }
before do
# Stub the S3 file listing and download
allow(storage_service).to receive(:list_files)
.and_return(%W[#{remote_folder}/#{scheme_id}.xml])
allow(storage_service).to receive(:get_file_io)
.with("#{remote_folder}/#{scheme_id}.xml")
.and_return(open_file(fixture_directory, scheme_id))
end
it "successfully create all schemes" do
expect(logger).not_to receive(:error)
expect(logger).not_to receive(:warn)
expect(logger).not_to receive(:info)
expect { scheme_service.create_schemes(remote_folder) }
.to change(Scheme, :count).by(1)
end
end
context "when importing a specific scheme" do
let(:scheme_file) { open_file(fixture_directory, scheme_id) }
let(:scheme_xml) { Nokogiri::XML(scheme_file) }
it "matches expected values" do
scheme = scheme_service.create_scheme(scheme_xml)
expect(scheme.owning_organisation).to eq(owning_org)
expect(scheme.managing_organisation).to eq(managing_org)
expect(scheme.old_id).to eq("6d6d7618b58affe2a150a5ef2e9f4765fa6cd05d")
expect(scheme.old_visible_id).to eq(123)
expect(scheme.service_name).to eq("Management Group")
expect(scheme.arrangement_type).to eq("O")
end
context "and the scheme status is not approved" do
before { scheme_xml.at_xpath("//mgmtgroup:status").content = "Temporary" }
it "does not create the scheme" do
expect(logger).to receive(:warn).with("Scheme with legacy ID 6d6d7618b58affe2a150a5ef2e9f4765fa6cd05d is not approved (Temporary), skipping")
expect { scheme_service.create_scheme(scheme_xml) }
.not_to change(Scheme, :count)
end
end
end
end

180
spec/services/imports/scheme_location_import_service_spec.rb

@ -0,0 +1,180 @@
require "rails_helper"
RSpec.describe Imports::SchemeLocationImportService do
subject(:location_service) { described_class.new(storage_service, logger) }
let(:storage_service) { instance_double(StorageService) }
let(:logger) { instance_double(ActiveSupport::Logger) }
let(:fixture_directory) { "spec/fixtures/imports/scheme_locations" }
let(:first_location_id) { "0ae7ad6dc0f1cf7ef33c18cc8c108bebc1b4923e" }
let(:second_location_id) { "0bb3836b70b4dd9903263d5a764a5c45b964a89d" }
let!(:scheme) { FactoryBot.create(:scheme, service_name: "Management Group", old_id: "6d6d7618b58affe2a150a5ef2e9f4765fa6cd05d") }
def open_file(directory, filename)
File.open("#{directory}/#{filename}.xml")
end
context "when importing scheme locations" do
let(:remote_folder) { "schemes" }
before do
# Stub the S3 file listing and download
allow(storage_service).to receive(:list_files)
.and_return(%W[#{remote_folder}/#{first_location_id}.xml #{remote_folder}/#{second_location_id}.xml])
allow(storage_service).to receive(:get_file_io)
.with("#{remote_folder}/#{first_location_id}.xml")
.and_return(open_file(fixture_directory, first_location_id))
allow(storage_service).to receive(:get_file_io)
.with("#{remote_folder}/#{second_location_id}.xml")
.and_return(open_file(fixture_directory, second_location_id))
end
it "successfully create all scheme locations" do
expect(logger).not_to receive(:error)
expect(logger).not_to receive(:warn)
expect(logger).not_to receive(:info)
expect { location_service.create_scheme_locations(remote_folder) }
.to change(Location, :count).by(2)
.and(change(Scheme, :count).by(0))
end
end
context "when importing different scheme locations" do
let(:location_xml_1) { Nokogiri::XML(open_file(fixture_directory, first_location_id)) }
let(:location_xml_2) { Nokogiri::XML(open_file(fixture_directory, second_location_id)) }
before { location_service.create_scheme_location(location_xml_1) }
context "and the scheme type is different" do
before { location_xml_2.at_xpath("//scheme:scheme-type").content = "5" }
it "renames the location scheme name" do
location = location_service.create_scheme_location(location_xml_2)
old_scheme = Scheme.find(scheme.id)
new_scheme = location.scheme
expect(old_scheme.service_name).to eq("Management Group - Housing for older people")
expect(new_scheme.service_name).to eq("Management Group - Direct Access Hostel")
end
end
context "and the registered under care act is different" do
before { location_xml_2.at_xpath("//scheme:reg-home-type").content = "2" }
it "renames both scheme names" do
location = location_service.create_scheme_location(location_xml_2)
old_scheme = Scheme.find(scheme.id)
new_scheme = location.scheme
expect(old_scheme.service_name).to eq("Management Group")
expect(new_scheme.service_name).to eq("Management Group - (Part-registered care home)")
end
end
context "and the support type is different" do
before { location_xml_2.at_xpath("//scheme:support-type").content = "3" }
it "renames both scheme names" do
location = location_service.create_scheme_location(location_xml_2)
old_scheme = Scheme.find(scheme.id)
new_scheme = location.scheme
expect(old_scheme.service_name).to eq("Management Group - Low levels of support")
expect(new_scheme.service_name).to eq("Management Group - Medium levels of support")
end
end
context "and the intended stay is different" do
before { location_xml_2.at_xpath("//scheme:intended-stay").content = "S" }
it "renames both scheme names" do
location = location_service.create_scheme_location(location_xml_2)
old_scheme = Scheme.find(scheme.id)
new_scheme = location.scheme
expect(old_scheme.service_name).to eq("Management Group - Permanent")
expect(new_scheme.service_name).to eq("Management Group - Short stay")
end
end
context "and the primary client group is different" do
before { location_xml_2.at_xpath("//scheme:client-group-1").content = "F" }
it "renames both scheme names" do
location = location_service.create_scheme_location(location_xml_2)
old_scheme = Scheme.find(scheme.id)
new_scheme = location.scheme
expect(old_scheme.service_name).to eq("Management Group - Older people with support needs")
expect(new_scheme.service_name).to eq("Management Group - People with drug problems")
end
end
context "and the secondary client group is different" do
before { location_xml_2.at_xpath("//scheme:client-group-2").content = "S" }
it "renames both scheme names" do
location = location_service.create_scheme_location(location_xml_2)
old_scheme = Scheme.find(scheme.id)
new_scheme = location.scheme
expect(old_scheme.service_name).to eq("Management Group")
expect(new_scheme.service_name).to eq("Management Group - Rough sleepers")
end
end
end
context "when importing a specific scheme location" do
let(:location_xml) { Nokogiri::XML(open_file(fixture_directory, first_location_id)) }
it "matches expected location values" do
location = location_service.create_scheme_location(location_xml)
expect(location.name).to eq("Location 1")
expect(location.postcode).to eq("S44 6EJ")
expect(location.units).to eq(5)
expect(location.type_of_unit).to eq("Bungalow")
expect(location.old_id).to eq(first_location_id)
expect(location.old_visible_id).to eq(10)
expect(location.scheme).to eq(scheme)
end
it "matches expected schemes values" do
location = location_service.create_scheme_location(location_xml)
expect(location.scheme.scheme_type).to eq("Housing for older people")
expect(location.scheme.registered_under_care_act).to eq("No")
expect(location.scheme.support_type).to eq("Low levels of support")
expect(location.scheme.intended_stay).to eq("Permanent")
expect(location.scheme.primary_client_group).to eq("Older people with support needs")
expect(location.scheme.secondary_client_group).to be_nil
expect(location.scheme.sensitive).to eq("No")
expect(location.scheme.end_date).to eq("2050-12-31")
end
context "and the end date is before the current date" do
before do
Timecop.freeze(2022, 6, 1)
location_xml.at_xpath("//scheme:end-date").content = "2022-05-01"
end
after { Timecop.unfreeze }
it "does not create the location" do
expect(logger).to receive(:warn).with("Location with legacy ID 0ae7ad6dc0f1cf7ef33c18cc8c108bebc1b4923e is expired (2022-05-01 00:00:00 +0100), skipping")
expect { location_service.create_scheme_location(location_xml) }
.not_to change(Location, :count)
end
end
context "and we import the same location twice" do
before { location_service.create_scheme_location(location_xml) }
it "does not create the location" do
expect(logger).to receive(:warn).with("Location is already present with legacy ID 0ae7ad6dc0f1cf7ef33c18cc8c108bebc1b4923e, skipping")
expect { location_service.create_scheme_location(location_xml) }
.not_to change(Location, :count)
end
end
end
end

2
spec/services/imports/user_import_service_spec.rb

@ -1,7 +1,7 @@
require "rails_helper" require "rails_helper"
RSpec.describe Imports::UserImportService do RSpec.describe Imports::UserImportService do
let(:fixture_directory) { "spec/fixtures/softwire_imports/users" } let(:fixture_directory) { "spec/fixtures/imports/users" }
let(:old_user_id) { "fc7625a02b24ae16162aa63ae7cb33feeec0c373" } let(:old_user_id) { "fc7625a02b24ae16162aa63ae7cb33feeec0c373" }
let(:old_org_id) { "7c5bd5fb549c09a2c55d7cb90d7ba84927e64618" } let(:old_org_id) { "7c5bd5fb549c09a2c55d7cb90d7ba84927e64618" }
let(:user_file) { File.open("#{fixture_directory}/#{old_user_id}.xml") } let(:user_file) { File.open("#{fixture_directory}/#{old_user_id}.xml") }

Loading…
Cancel
Save