-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
46 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 3 additions & 34 deletions
37
src/utils/offenceMatcher/getOffenceMatchingException.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
src/utils/offenceMatcher/getOffenceMatchingExceptions.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import ExceptionCode from "@moj-bichard7-developers/bichard7-next-data/dist/types/ExceptionCode" | ||
import type { Exception } from "types/exceptions" | ||
import getOffenceMatchingExceptions from "./getOffenceMatchingExceptions" | ||
|
||
describe("getOffenceMatchingExceptions", () => { | ||
it("returns an empty array when given no exceptions", () => { | ||
const result = getOffenceMatchingExceptions([]) | ||
expect(result).toEqual([]) | ||
}) | ||
|
||
it("returns an empty array when given exception that is not in array of valid values", () => { | ||
const exception: Exception = { code: ExceptionCode.HO100312, path: ["test"] } | ||
const result = getOffenceMatchingExceptions([exception]) | ||
expect(result).toEqual([]) | ||
}) | ||
|
||
it("returns exception when given exception that is in array of valid values", () => { | ||
const exception: Exception = { code: ExceptionCode.HO100310, path: ["test"] } | ||
const result = getOffenceMatchingExceptions([exception]) | ||
expect(result).toEqual([exception]) | ||
}) | ||
|
||
it("returns exception when given multiple exceptions and exception is in array of valid values", () => { | ||
const exceptions: Exception[] = [ | ||
{ code: ExceptionCode.HO100310, path: ["test"] }, | ||
{ code: ExceptionCode.HO100312, path: ["test"] } | ||
] | ||
const result = getOffenceMatchingExceptions(exceptions) | ||
expect(result).toEqual([exceptions[0]]) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import type { Exception } from "types/exceptions" | ||
import offenceMatchingExceptions from "./offenceMatchingExceptions" | ||
|
||
const getOffenceMatchingExceptions = (exceptions: Exception[]): Exception[] => | ||
exceptions.filter((exception) => offenceMatchingExceptions.offenceNotMatched.includes(exception.code)) | ||
|
||
export default getOffenceMatchingExceptions |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,6 @@ | ||
import { Exception } from "types/exceptions" | ||
import offenceMatchingExceptions from "./offenceMatchingExceptions" | ||
import getOffenceMatchingExceptions from "./getOffenceMatchingExceptions" | ||
|
||
const filterOffenceMatchingException = (exceptions: Exception[]): Exception[] => | ||
exceptions.filter((exception) => offenceMatchingExceptions.offenceNotMatched.includes(exception.code)) | ||
const hasOffenceMatchingExceptions = (exceptions: Exception[]) => getOffenceMatchingExceptions(exceptions).length > 0 | ||
|
||
const hasOffenceMatchingExceptions = (exceptions: Exception[]) => filterOffenceMatchingException(exceptions).length > 0 | ||
|
||
export { filterOffenceMatchingException } | ||
export default hasOffenceMatchingExceptions |