Skip to content

Commit

Permalink
ACD-433: Add application summary to SearchProsecutionCase
Browse files Browse the repository at this point in the history
- Updated `ApplicationSummary` and `ProsecutionCaseSummary` models to include the application summary data.
- Modified `apiCourtsDefinitions.json` to reflect the new schema changes.
- Added fixture file `application_summary/all_fields.json` for testing.
- Created a new spec for `ApplicationSummary` model.
- Updated `ProsecutionCaseSummary` spec to test integration with application summary data.
- Enhanced `json_schema_rspec` to support validation of new schema changes.

This commit introduces support for application summary in the prosecution case search functionality.
  • Loading branch information
alexdesi committed Jan 22, 2025
1 parent e86f87d commit 8483547
Show file tree
Hide file tree
Showing 7 changed files with 103 additions and 0 deletions.
51 changes: 51 additions & 0 deletions app/models/hmcts_common_platform/application_summary.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,56 @@ class ApplicationSummary
def initialize(data)
@data = HashWithIndifferentAccess.new(data || {})
end

def id
data[:applicationId]
end

def reference
data[:applicationReference]
end

def type
data[:applicationType]
end

def application_status
data[:applicationStatus]
end

def application_external_creator_type
data[:applicationExternalCreatorType]
end

def received_date
data[:receivedDate]
end

def decision_date
data[:decisionDate]
end

def due_date
data[:dueDate]
end

def to_json(*_args)
to_builder.attributes!
end

private

def to_builder
Jbuilder.new do |application_summary|
application_summary.id id
application_summary.reference reference
application_summary.type type
application_summary.applicationStatus application_status
application_summary.applicationExternalCreatorType application_external_creator_type
application_summary.receivedDate received_date
application_summary.decisionDate decision_date
application_summary.dueDate due_date
end
end
end
end
7 changes: 7 additions & 0 deletions app/models/hmcts_common_platform/prosecution_case_summary.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ def hearing_summaries
end
end

def application_summaries
Array(data[:applicationSummary]).map do |application_summary_data|
HmctsCommonPlatform::ApplicationSummary.new(application_summary_data)
end
end

def to_json(*_args)
to_builder.attributes!
end
Expand All @@ -38,6 +44,7 @@ def to_builder
case_summary.case_status case_status
case_summary.defendant_summaries defendant_summaries.map(&:to_json)
case_summary.hearing_summaries hearing_summaries.map(&:to_json)
case_summary.application_summaries application_summaries.map(&:to_json)
end
end
end
Expand Down
1 change: 1 addition & 0 deletions lib/schemas/global/apiCourtsDefinitions.json
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@
"applicationJurisdictionType": {
"description": "Indicates the jurisdiction that is required to consider the application",
"type": "string",

"enum": [
"MAGISTRATES",
"CROWN",
Expand Down
10 changes: 10 additions & 0 deletions spec/fixtures/files/application_summary/all_fields.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"applicationId": "62158b87-56fc-43cc-bbdc-d957d372420f",
"applicationReference": "CJ03512",
"applicationType": "Application to amend a community order on change of residence",
"applicationStatus": "EJECTED",
"applicationExternalCreatorType": "PROSECUTOR",
"receivedDate": "2024-12-21",
"decisionDate": "2025-02-11",
"dueDate": "2025-01-27"
}
31 changes: 31 additions & 0 deletions spec/models/hmcts_common_platform/application_summary_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# {
# "applicationId": "62158b87-56fc-43cc-bbdc-d957d372420f",
# "applicationReference": "CJ03512",
# "applicationType": "Application to amend a community order on change of residence",
# "applicationStatus": "EJECTED",
# "applicationExternalCreatorType": "PROSECUTOR",
# "receivedDate": "2024-12-21",
# "decisionDate": "2025-02-11",
# "dueDate": "2025-01-27"
# }

RSpec.describe HmctsCommonPlatform::ApplicationSummary, type: :model do
let(:hearing_summary) { described_class.new(data) }

context "with all fields" do
let(:data) { JSON.parse(file_fixture("application_summary/all_fields.json").read) }

it "matches the HMCTS Common Platform schema" do
expect(data).to match_json_schema(:application_summary)
end

it { expect(hearing_summary.id).to eql("62158b87-56fc-43cc-bbdc-d957d372420f") }
it { expect(hearing_summary.reference).to eql("CJ03512") }
it { expect(hearing_summary.type).to eql("Application to amend a community order on change of residence") }
it { expect(hearing_summary.application_status).to eql("EJECTED") }
it { expect(hearing_summary.application_external_creator_type).to eql("PROSECUTOR") }
it { expect(hearing_summary.received_date).to eql("2024-12-21") }
it { expect(hearing_summary.decision_date).to eql("2025-02-11") }
it { expect(hearing_summary.due_date).to eql("2025-01-27") }
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
it { expect(prosecution_case_summary.case_status).to eq("ACTIVE") }
it { expect(prosecution_case_summary.defendant_summaries).to all be_an(HmctsCommonPlatform::DefendantSummary) }
it { expect(prosecution_case_summary.hearing_summaries).to all be_an(HmctsCommonPlatform::HearingSummary) }
it { expect(prosecution_case_summary.application_summaries).to all be_an(HmctsCommonPlatform::ApplicationSummary) }
end

context "with required fields only" do
Expand All @@ -37,6 +38,7 @@
expect(json["case_status"]).to eql("ACTIVE")
expect(json["defendant_summaries"].count).to be(2)
expect(json["hearing_summaries"].count).to be(2)
expect(json["application_summaries"].count).to be(1)
end
end
end
1 change: 1 addition & 0 deletions spec/support/json_schema_rspec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

config.json_schemas[:address] = "#{schema_path}/global/apiAddress.json"
config.json_schemas[:allocation_decision] = "#{schema_path}/global/apiAllocationDecision.json"
config.json_schemas[:application_summary] = "#{schema_path}/global/search/apiApplicationSummary.json"
config.json_schemas[:attendance_day] = "#{schema_path}/global/apiAttendanceDay.json"
config.json_schemas[:bail_status] = "#{schema_path}/global/apiBailStatus.json"
config.json_schemas[:contact_details] = "#{schema_path}/global/apiContactNumber.json"
Expand Down

0 comments on commit 8483547

Please sign in to comment.