Skip to content

Commit

Permalink
Merge branch 'main' into BICAWS7-3076-add-resolved-date-range-to-case…
Browse files Browse the repository at this point in the history
…-list-query
  • Loading branch information
ian-antking authored Sep 3, 2024
2 parents 71a5c2c + e6d3dbb commit adb2261
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,14 @@ const extractSearchParamsFromQuery = (query: ParsedUrlQuery, currentUser: User):
caseState === "Resolved" && !currentUser.hasAccessTo[Permission.ListAllCases] ? currentUser.username : null
const courtDateRange = caseAges || dateRange
const resolvedDateRange = validateDateRange({ from: query.resolvedFrom, to: query.resolvedTo })

const asn = validateQueryParams(query.asn) ? sanitise(query.asn) : null

return {
...(defendantName && { defendantName: defendantName }),
...(courtName && { courtName: courtName }),
...(reasonCodes && { reasonCodes: reasonCodes }),
...(ptiurn && { ptiurn }),
...(asn && { asn }),
reason,
maxPageItems: validateQueryParams(query.maxPageItems) ? +Number(query.maxPageItems) : defaults.maxPageItems,
page: validateQueryParams(query.page) ? +Number(query.page) : 1,
Expand Down
5 changes: 5 additions & 0 deletions src/services/listCourtCases.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ const listCourtCases = async (
reasonCodes,
resolvedByUsername,
resolvedDateRange
asn
}: CaseListQueryParams,
user: User
): PromiseResult<ListCourtCaseResult> => {
Expand Down Expand Up @@ -104,6 +105,10 @@ const listCourtCases = async (
query.andWhere(ptiurnLike)
}

if (asn) {
query.andWhere({ asn: ILike(`%${asn}%`) })
}

if (reasonCodes?.length) {
query.andWhere(
new Brackets((qb) => {
Expand Down
1 change: 1 addition & 0 deletions src/types/CaseListQueryParams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,5 @@ export type CaseListQueryParams = {
reasonCodes?: string[]
resolvedByUsername?: string
resolvedDateRange?: DateRange
asn?: string
}
30 changes: 29 additions & 1 deletion test/services/listCourtCases/listCourtCases.integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,35 @@ describe("listCourtCases", () => {
})
})

describe("search by asn", () => {
it("Should list cases when there is a case insensitive match", async () => {
const asnToInclude = "1101ZD0100000448754K"
const asnToIncludeWithPartialMatch = "1101ZD0100000448754J"
const asnToNotInclude = "AAAAAAAAAAAAAAAAAAA"

await insertCourtCasesWithFields([
{ asn: asnToInclude },
{ asn: asnToIncludeWithPartialMatch },
{ asn: asnToNotInclude }
])

let result = await listCourtCases(dataSource, { maxPageItems: 100, asn: "1101ZD0100000448754K" }, testUser)
expect(isError(result)).toBe(false)
let { result: cases } = result as ListCourtCaseResult

expect(cases).toHaveLength(1)
expect(cases[0].asn).toStrictEqual(asnToInclude)

result = await listCourtCases(dataSource, { maxPageItems: 100, asn: "1101ZD0100000448754" }, testUser)
expect(isError(result)).toBe(false)
cases = (result as ListCourtCaseResult).result

expect(cases).toHaveLength(2)
expect(cases[0].asn).toStrictEqual(asnToInclude)
expect(cases[1].asn).toStrictEqual(asnToIncludeWithPartialMatch)
})
})

describe("search by ptiurn", () => {
it("Should list cases when there is a case insensitive match", async () => {
const ptiurnToInclude = "01ZD0303908"
Expand Down Expand Up @@ -510,7 +539,6 @@ describe("listCourtCases", () => {
expect(cases[1].ptiurn).toStrictEqual(ptiurnToIncludeWithPartialMatch)
})
})

describe("search by reason", () => {
it("Should list cases when there is a case insensitive match in triggers or exceptions", async () => {
await insertCourtCasesWithFields(Array.from({ length: 4 }, () => ({ orgForPoliceFilter: orgCode })))
Expand Down

0 comments on commit adb2261

Please sign in to comment.