Browse Source

CLDC-2642 Make other client group mandatory (#1871)

* Make has_other_client_group a mandatory question

* Add a rake task to update has_other_client_group

* test and lint

* Set has_other_client group on import
pull/1876/head
kosiakkatrina 1 year ago committed by GitHub
parent
commit
5ec33c7938
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      app/models/scheme.rb
  2. 3
      app/services/imports/scheme_location_import_service.rb
  3. 2
      app/views/schemes/confirm_secondary.html.erb
  4. 3
      db/seeds.rb
  5. 5
      lib/tasks/correct_has_other_client_group_values.rake
  6. 2
      spec/factories/scheme.rb
  7. 56
      spec/lib/tasks/correct_has_other_client_group_values_spec.rb
  8. 1
      spec/services/imports/scheme_location_import_service_spec.rb

2
app/models/scheme.rb

@ -238,7 +238,7 @@ class Scheme < ApplicationRecord
end
def validate_confirmed
required_attributes = attribute_names - %w[id created_at updated_at old_id old_visible_id confirmed end_date sensitive secondary_client_group total_units has_other_client_group deactivation_date deactivation_date_type]
required_attributes = attribute_names - %w[id created_at updated_at old_id old_visible_id confirmed end_date sensitive secondary_client_group total_units deactivation_date deactivation_date_type]
if confirmed == true
required_attributes.any? do |attribute|

3
app/services/imports/scheme_location_import_service.rb

@ -34,6 +34,7 @@ module Imports
intended_stay: attributes["intended_stay"],
primary_client_group: attributes["primary_client_group"],
secondary_client_group: attributes["secondary_client_group"],
has_other_client_group: attributes["has_other_client_group"],
sensitive: attributes["sensitive"],
# These values were set by the scheme import (management groups)
owning_organisation_id: source_scheme.owning_organisation_id,
@ -56,6 +57,7 @@ module Imports
support_type: attributes["support_type"],
intended_stay: attributes["intended_stay"],
primary_client_group: attributes["primary_client_group"],
has_other_client_group: attributes["has_other_client_group"],
secondary_client_group: attributes["secondary_client_group"],
sensitive: attributes["sensitive"],
}
@ -83,6 +85,7 @@ module Imports
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["has_other_client_group"] = attributes["secondary_client_group"].present? ? 1 : 0
attributes["sensitive"] = sensitive(xml_doc)
attributes["start_date"] = parse_date(xml_doc, "start-date")
attributes["end_date"] = parse_date(xml_doc, "end-date")

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

@ -11,6 +11,8 @@
<%= form_for(@scheme, method: :patch) do |f| %>
<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds">
<%= f.govuk_error_summary %>
<% selection = [OpenStruct.new(id: "Yes", name: "Yes"), OpenStruct.new(id: "No", name: "No")] %>
<%= f.govuk_collection_radio_buttons :has_other_client_group,
selection,

3
db/seeds.rb

@ -253,6 +253,7 @@ unless Rails.env.test?
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",
@ -269,6 +270,7 @@ unless Rails.env.test?
intended_stay: "S",
primary_client_group: "D",
secondary_client_group: "E",
has_other_client_group: 1,
owning_organisation: org,
arrangement_type: "D",
confirmed: true,
@ -283,6 +285,7 @@ unless Rails.env.test?
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",

5
lib/tasks/correct_has_other_client_group_values.rake

@ -0,0 +1,5 @@
desc "Update has_other_client_group values for schemes"
task correct_has_other_client_group_values: :environment do
Scheme.where(confirmed: true, secondary_client_group: nil).update_all(has_other_client_group: 0)
Scheme.where(confirmed: true).where.not(secondary_client_group: nil).update_all(has_other_client_group: 1)
end

2
spec/factories/scheme.rb

@ -9,6 +9,7 @@ FactoryBot.define do
intended_stay { %w[M P S V X].sample }
primary_client_group { %w[O H M L A G F B D E I S N R Q P X].sample }
secondary_client_group { %w[O H M L A G F B D E I S N R Q P X].sample }
has_other_client_group { 1 }
owning_organisation { FactoryBot.create(:organisation) }
confirmed { true }
created_at { Time.zone.local(2021, 4, 1) }
@ -20,6 +21,7 @@ FactoryBot.define do
intended_stay { "M" }
primary_client_group { "G" }
secondary_client_group { "M" }
has_other_client_group { 1 }
end
trait :with_old_visible_id do

56
spec/lib/tasks/correct_has_other_client_group_values_spec.rb

@ -0,0 +1,56 @@
require "rails_helper"
require "rake"
RSpec.describe "correct_has_other_client_group_values" do
describe ":correct_has_other_client_group_values", type: :task do
subject(:task) { Rake::Task["correct_has_other_client_group_values"] }
before do
Rake.application.rake_require("tasks/correct_has_other_client_group_values")
Rake::Task.define_task(:environment)
task.reenable
end
context "when the rake task is run" do
let!(:scheme) { create(:scheme, secondary_client_group: nil) }
before do
scheme.has_other_client_group = nil
scheme.save!(validate: false)
end
context "and the scheme is marked confirmed" do
it "updates schemes with secondary_client_group to have has_other_client_group 1 (yes)" do
scheme.secondary_client_group = "G"
scheme.save!(validate: false)
task.invoke
expect(scheme.reload.has_other_client_group).to eq("Yes")
end
it "updates schemes without secondary_client_group to have has_other_client_group 0 (no)" do
task.invoke
expect(scheme.reload.has_other_client_group).to eq("No")
end
end
context "and the scheme is not marked confirmed" do
before do
scheme.confirmed = false
scheme.save!(validate: false)
end
it "does not update schemes with secondary_client_group" do
scheme.secondary_client_group = "G"
scheme.save!(validate: false)
task.invoke
expect(scheme.reload.has_other_client_group).to eq(nil)
end
it "does not update schemes without secondary_client_group" do
task.invoke
expect(scheme.reload.has_other_client_group).to eq(nil)
end
end
end
end
end

1
spec/services/imports/scheme_location_import_service_spec.rb

@ -162,6 +162,7 @@ RSpec.describe Imports::SchemeLocationImportService do
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.has_other_client_group).to eq("No")
expect(location.scheme.sensitive).to eq("No")
expect(location.scheme.confirmed).to be_truthy
end

Loading…
Cancel
Save