Skip to content

Commit

Permalink
Merge pull request #7059 from ministryofjustice/ap-5235/sca-proceedin…
Browse files Browse the repository at this point in the history
…g-filter

AP-5235: SCA proceeding filter
  • Loading branch information
colinbruce authored Aug 22, 2024
2 parents cd2e68d + efa0fc3 commit 06490f6
Show file tree
Hide file tree
Showing 59 changed files with 7,686 additions and 18,072 deletions.
2 changes: 1 addition & 1 deletion app/controllers/providers/proceedings_types_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def form_params
end

def proceeding_types
@proceeding_types ||= LegalFramework::ProceedingTypes::All.call(provider: current_provider)
@proceeding_types ||= LegalFramework::ProceedingTypes::All.call(legal_aid_application)
end

def excluded_codes
Expand Down
43 changes: 33 additions & 10 deletions app/services/legal_framework/proceeding_types/all.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,32 +15,55 @@ def initialize(pt_hash)
@sca_related = pt_hash["sca_related"]
end

# TODO: remove the below when the SCA feature flag is removed
def not_sca?
[@sca_core, @sca_related].all?(false)
end
end

def initialize(params)
def self.call(legal_aid_application)
new(legal_aid_application).call
end

def initialize(legal_aid_application)
super()
@provider = params[:provider]
@legal_aid_application = legal_aid_application
end

def call
Setting.special_childrens_act? ? unfiltered_payload : filtered_payload
result = JSON.parse(request.body).map { |pt_hash| ProceedingTypeStruct.new(pt_hash) }
# TODO: remove the below when the SCA feature flag is removed
# filter out SCA applications
result.select!(&:not_sca?) unless Setting.special_childrens_act?
result
end

def path
"/proceeding_types/all"
private

def request_body
{
current_proceedings: @legal_aid_application.proceedings&.map(&:ccms_code)&.join(","),
allowed_categories: %w[MAT], # TODO: replace with details from new PDA, for now hardcoded to only current category type
search_term: "", # TODO: add optional parameter to the initializer, but for now leave always empty
}.to_json
end

private
def request
conn.post do |request|
request.url url
request.headers["Content-Type"] = "application/json"
request.body = request_body
end
end

def unfiltered_payload
JSON.parse(request.body).map { |pt_hash| ProceedingTypeStruct.new(pt_hash) }
def path
"/proceeding_types/filter"
end

def filtered_payload
unfiltered_payload.select(&:not_sca?)
def headers
{
"Content-Type" => "application/json",
}
end
end
end
Expand Down

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

This file was deleted.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

This file was deleted.

This file was deleted.

This file was deleted.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@
:with_proceedings,
set_lead_proceeding: :da001)
end
let(:proceeding) { legal_aid_application.proceedings.find_by(ccms_code: "DA001") }
let(:proceeding) { create(:proceeding, :da004) }
let(:params) do
{
id: proceeding.ccms_code,
Expand Down
21 changes: 13 additions & 8 deletions spec/services/legal_framework/proceeding_types/all_spec.rb
Original file line number Diff line number Diff line change
@@ -1,34 +1,33 @@
require "rails_helper"

RSpec.describe LegalFramework::ProceedingTypes::All do
subject(:all) { described_class }
subject(:all) { described_class.new(legal_aid_application) }

before do
allow(Setting).to receive(:special_childrens_act?).and_return(sca_enabled)
stub_request(:get, uri).to_return(body: all_proceeding_types_payload)
stub_request(:post, uri).to_return(body: all_proceeding_types_payload)
end

let(:uri) { "#{Rails.configuration.x.legal_framework_api_host}/proceeding_types/all" }
let(:legal_aid_application) { create :legal_aid_application }
let(:uri) { "#{Rails.configuration.x.legal_framework_api_host}/proceeding_types/filter" }

describe ".call" do
subject(:call) { all.call(provider:) }
subject(:call) { all.call }

before { call }

let(:provider) { create(:provider) }

context "when the special children act setting is on" do
let(:sca_enabled) { true }

it "returns all the proceedings" do
it "returns the expected proceedings" do
expect(call.map(&:ccms_code)).to match_array %w[DA001 SE097 DA003 SE016E DA006 PB003]
end
end

context "when the special children act setting is off" do
let(:sca_enabled) { false }

it "returns all the proceedings" do
it "returns the expected proceedings" do
expect(call.map(&:ccms_code)).to match_array %w[DA001 SE097 DA003 SE016E DA006]
end
end
Expand All @@ -44,6 +43,7 @@ def all_proceeding_types_payload
sca_core: false,
sca_related: false,
ccms_category_law: "Family",
ccms_category_law_code: "MAT",
ccms_matter_code: "MINJN",
ccms_matter: "Domestic abuse",
},
Expand All @@ -55,6 +55,7 @@ def all_proceeding_types_payload
sca_core: false,
sca_related: false,
ccms_category_law: "Family",
ccms_category_law_code: "MAT",
ccms_matter_code: "KSEC8",
ccms_matter: "Children - section 8",
},
Expand All @@ -66,6 +67,7 @@ def all_proceeding_types_payload
sca_core: false,
sca_related: false,
ccms_category_law: "Family",
ccms_category_law_code: "MAT",
ccms_matter_code: "MINJN",
ccms_matter: "Domestic abuse",
},
Expand All @@ -77,6 +79,7 @@ def all_proceeding_types_payload
sca_core: false,
sca_related: false,
ccms_category_law: "Family",
ccms_category_law_code: "MAT",
ccms_matter_code: "KSEC8",
ccms_matter: "Children - section 8",
},
Expand All @@ -88,6 +91,7 @@ def all_proceeding_types_payload
sca_core: false,
sca_related: false,
ccms_category_law: "Family",
ccms_category_law_code: "MAT",
ccms_matter_code: "MINJN",
ccms_matter: "Domestic abuse",
},
Expand All @@ -99,6 +103,7 @@ def all_proceeding_types_payload
sca_core: true,
sca_related: false,
ccms_category_law: "Family",
ccms_category_law_code: "MAT",
ccms_matter_code: "KPBLW",
ccms_matter: "Special Children Act",
},
Expand Down

0 comments on commit 06490f6

Please sign in to comment.