Skip to content

Commit 59c44bb

Browse files
committed
chore: placate SQ
1 parent 58ebd8b commit 59c44bb

File tree

6 files changed

+45
-47
lines changed

6 files changed

+45
-47
lines changed

packages/getMyPrescriptions/src/getMyPrescriptions.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import {
2424
ResponseFunc
2525
} from "./responses"
2626
import {extractNHSNumber, NHSNumberValidationError, validateNHSNumber} from "./extractNHSNumber"
27-
import {deepCopy, hasTimedOut, jobWithTimeout} from "./utils"
27+
import {hasTimedOut, jobWithTimeout} from "./utils"
2828
import {buildStatusUpdateData, shouldGetStatusUpdates} from "./statusUpdate"
2929
import {extractOdsCodes, isolateOperationOutcome} from "./fhirUtils"
3030
import {pfpConfig, PfPConfig} from "@pfp-common/utilities"
@@ -130,7 +130,7 @@ async function eventHandler(
130130
const statusUpdateData = includeStatusUpdateData ? buildStatusUpdateData(logger, searchsetBundle) : undefined
131131

132132
const distanceSelling = new DistanceSelling(servicesCache, logger)
133-
const distanceSellingBundle = deepCopy(searchsetBundle)
133+
const distanceSellingBundle = structuredClone(searchsetBundle)
134134
const distanceSellingCallout = distanceSelling.search(distanceSellingBundle)
135135

136136
const distanceSellingResponse = await jobWithTimeout(params.serviceSearchTimeoutMs, distanceSellingCallout)

packages/getMyPrescriptions/src/utils.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
export function deepCopy<T>(obj: T): T {
2-
return JSON.parse(JSON.stringify(obj))
3-
}
4-
51
export interface Timeout {
62
isTimeout: true
73
}

packages/getMyPrescriptions/tests/statusUpdate.test.ts

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,29 @@ import {
77
jest
88
} from "@jest/globals"
99
import axios from "axios"
10+
import MockAdapter from "axios-mock-adapter"
1011
import {Bundle, MedicationRequest} from "fhir/r4"
1112
import {APIGatewayProxyResult as LambdaResult, Context} from "aws-lambda"
12-
import MockAdapter from "axios-mock-adapter"
13+
import {LogLevel} from "@aws-lambda-powertools/logger/types"
14+
import {Logger} from "@aws-lambda-powertools/logger"
15+
import {createSpineClient} from "@NHSDigital/eps-spine-client"
16+
import {MiddyfiedHandler} from "@middy/core"
1317

1418
import {
19+
createMockedPfPConfig,
1520
helloworldContext,
1621
mockAPIResponseBody as mockResponseBody,
1722
mockInteractionResponseBody,
1823
mockPharmacy2uResponse,
1924
mockPharmicaResponse,
20-
mockStateMachineInputEvent
25+
mockStateMachineInputEvent,
26+
MockedPfPConfig,
27+
setupTestEnvironment
2128
} from "@pfp-common/testing"
29+
import {
30+
SERVICE_SEARCH_BASE_QUERY_PARAMS,
31+
getServiceSearchEndpoint
32+
} from "@prescriptionsforpatients/serviceSearchClient"
2233

2334
import {buildStatusUpdateData} from "../src/statusUpdate"
2435
import {StateMachineFunctionResponseBody} from "../src/responses"
@@ -29,12 +40,7 @@ import {
2940
newHandler,
3041
stateMachineEventHandler
3142
} from "../src/getMyPrescriptions"
32-
import {EXPECTED_TRACE_IDS, SERVICE_SEARCH_PARAMS, getServiceSearchEndpoint} from "./utils"
33-
import {createMockedPfPConfig, MockedPfPConfig, setupTestEnvironment} from "@pfp-common/testing"
34-
import {LogLevel} from "@aws-lambda-powertools/logger/types"
35-
import {Logger} from "@aws-lambda-powertools/logger"
36-
import {createSpineClient} from "@NHSDigital/eps-spine-client"
37-
import {MiddyfiedHandler} from "@middy/core"
43+
import {EXPECTED_TRACE_IDS} from "./utils"
3844

3945
const exampleEvent = JSON.stringify(mockStateMachineInputEvent)
4046
const exampleInteractionResponse = JSON.stringify(mockInteractionResponseBody)
@@ -143,10 +149,10 @@ describe("Unit tests for statusUpdate, via handler", function () {
143149
const event: GetMyPrescriptionsEvent = JSON.parse(exampleEvent)
144150

145151
mock
146-
.onGet(getServiceSearchEndpoint(), {params: {...SERVICE_SEARCH_PARAMS, search: "flm49"}})
152+
.onGet(getServiceSearchEndpoint(), {params: {...SERVICE_SEARCH_BASE_QUERY_PARAMS, search: "flm49"}})
147153
.reply(200, JSON.parse(pharmacy2uResponse))
148154
mock
149-
.onGet(getServiceSearchEndpoint(), {params: {...SERVICE_SEARCH_PARAMS, search: "few08"}})
155+
.onGet(getServiceSearchEndpoint(), {params: {...SERVICE_SEARCH_BASE_QUERY_PARAMS, search: "few08"}})
150156
.reply(200, JSON.parse(pharmicaResponse))
151157

152158
mock.onGet("https://spine/mm/patientfacingprescriptions").reply(200, JSON.parse(exampleInteractionResponse))

packages/getMyPrescriptions/tests/test-handler.test.ts

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
11
import {APIGatewayProxyResult as LambdaResult, Context} from "aws-lambda"
2-
import {
3-
DEFAULT_HANDLER_PARAMS,
4-
newHandler,
5-
GetMyPrescriptionsEvent,
6-
stateMachineEventHandler,
7-
STATE_MACHINE_MIDDLEWARE
8-
} from "../src/getMyPrescriptions"
92
import {Logger} from "@aws-lambda-powertools/logger"
3+
import {LogLevel} from "@aws-lambda-powertools/logger/types"
104
import axios from "axios"
115
import MockAdapter from "axios-mock-adapter"
126
import {
@@ -15,23 +9,35 @@ import {
159
it,
1610
jest
1711
} from "@jest/globals"
12+
import {createSpineClient} from "@NHSDigital/eps-spine-client"
13+
import {MiddyfiedHandler} from "@middy/core"
1814

1915
import {
16+
createMockedPfPConfig,
2017
mockAPIResponseBody as mockResponseBody,
2118
mockInteractionResponseBody,
2219
mockPharmacy2uResponse,
2320
mockPharmicaResponse,
2421
helloworldContext,
25-
mockStateMachineInputEvent
22+
mockStateMachineInputEvent,
23+
MockedPfPConfig,
24+
setupTestEnvironment
2625
} from "@pfp-common/testing"
26+
import {
27+
SERVICE_SEARCH_BASE_QUERY_PARAMS,
28+
getServiceSearchEndpoint
29+
} from "@prescriptionsforpatients/serviceSearchClient"
2730

31+
import {
32+
DEFAULT_HANDLER_PARAMS,
33+
newHandler,
34+
GetMyPrescriptionsEvent,
35+
stateMachineEventHandler,
36+
STATE_MACHINE_MIDDLEWARE
37+
} from "../src/getMyPrescriptions"
2838
import {HEADERS, StateMachineFunctionResponseBody, TIMEOUT_RESPONSE} from "../src/responses"
2939
import "./toMatchJsonLogMessage"
30-
import {EXPECTED_TRACE_IDS, getServiceSearchEndpoint, SERVICE_SEARCH_PARAMS} from "./utils"
31-
import {LogLevel} from "@aws-lambda-powertools/logger/types"
32-
import {createSpineClient} from "@NHSDigital/eps-spine-client"
33-
import {MiddyfiedHandler} from "@middy/core"
34-
import {createMockedPfPConfig, MockedPfPConfig, setupTestEnvironment} from "@pfp-common/testing"
40+
import {EXPECTED_TRACE_IDS} from "./utils"
3541

3642
const TC008_NHS_NUMBER = "9992387920"
3743

@@ -386,11 +392,11 @@ describe("Unit tests for app handler including service search", function () {
386392
const event: GetMyPrescriptionsEvent = JSON.parse(exampleStateMachineEvent)
387393

388394
mock
389-
.onGet(getServiceSearchEndpoint(), {params: {...SERVICE_SEARCH_PARAMS, search: "flm49"}})
395+
.onGet(getServiceSearchEndpoint(), {params: {...SERVICE_SEARCH_BASE_QUERY_PARAMS, search: "flm49"}})
390396
.reply(200, JSON.parse(pharmacy2uResponse))
391397

392398
mock
393-
.onGet(getServiceSearchEndpoint(), {params: {...SERVICE_SEARCH_PARAMS, search: "few08"}})
399+
.onGet(getServiceSearchEndpoint(), {params: {...SERVICE_SEARCH_BASE_QUERY_PARAMS, search: "few08"}})
394400
.reply(200, JSON.parse(pharmicaResponse))
395401

396402
mock.onGet("https://spine/mm/patientfacingprescriptions").reply(200, JSON.parse(exampleInteractionResponse))
@@ -426,11 +432,11 @@ describe("Unit tests for app handler including service search", function () {
426432
mock.onGet("https://spine/mm/patientfacingprescriptions").reply(200, interactionResponse)
427433

428434
mock
429-
.onGet(getServiceSearchEndpoint(), {params: {...SERVICE_SEARCH_PARAMS, search: "flm49"}})
435+
.onGet(getServiceSearchEndpoint(), {params: {...SERVICE_SEARCH_BASE_QUERY_PARAMS, search: "flm49"}})
430436
.reply(200, JSON.parse(pharmacy2uResponse))
431437

432438
mock
433-
.onGet(getServiceSearchEndpoint(), {params: {...SERVICE_SEARCH_PARAMS, search: "few08"}})
439+
.onGet(getServiceSearchEndpoint(), {params: {...SERVICE_SEARCH_BASE_QUERY_PARAMS, search: "few08"}})
434440
.reply(200, JSON.parse(pharmicaResponse))
435441

436442
const event: GetMyPrescriptionsEvent = JSON.parse(exampleStateMachineEvent)
@@ -574,11 +580,11 @@ describe("Unit tests for logging functionality", function () {
574580
mock.onGet("https://spine/mm/patientfacingprescriptions").reply(200, interactionResponse)
575581

576582
mock
577-
.onGet(getServiceSearchEndpoint(), {params: {...SERVICE_SEARCH_PARAMS, search: "flm49"}})
583+
.onGet(getServiceSearchEndpoint(), {params: {...SERVICE_SEARCH_BASE_QUERY_PARAMS, search: "flm49"}})
578584
.reply(200, JSON.parse(pharmacy2uResponse))
579585

580586
mock
581-
.onGet(getServiceSearchEndpoint(), {params: {...SERVICE_SEARCH_PARAMS, search: "few08"}})
587+
.onGet(getServiceSearchEndpoint(), {params: {...SERVICE_SEARCH_BASE_QUERY_PARAMS, search: "few08"}})
582588
.reply(200, JSON.parse(pharmicaResponse))
583589

584590
const event: GetMyPrescriptionsEvent = JSON.parse(exampleStateMachineEvent)

packages/getMyPrescriptions/tests/utils.ts

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
import {jest} from "@jest/globals"
22
import {Organization} from "fhir/r4"
33
import {TraceIDs} from "../src/responses"
4-
import {
5-
SERVICE_SEARCH_BASE_QUERY_PARAMS,
6-
getServiceSearchEndpoint
7-
} from "@prescriptionsforpatients/serviceSearchClient"
84

95
// Uses unstable jest method to enable mocking while using ESM. To be replaced in future.
106
export function mockInternalDependency(modulePath: string, module: object, dependency: string) {
@@ -16,10 +12,6 @@ export function mockInternalDependency(modulePath: string, module: object, depen
1612
return mockDependency
1713
}
1814

19-
// Re-export for convenience in tests
20-
export const SERVICE_SEARCH_PARAMS = SERVICE_SEARCH_BASE_QUERY_PARAMS
21-
export {getServiceSearchEndpoint}
22-
2315
export const EXPECTED_TRACE_IDS: TraceIDs = {
2416
"apigw-request-id": "c6af9ac6-7b61-11e6-9a41-93e8deadbeef",
2517
"nhsd-correlation-id": "test-request-id.test-correlation-id.rrt-5789322914740101037-b-aet2-20145-482635-2",
Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,2 @@
1-
import {createServiceSearchClient, ServiceSearchClient} from "./serviceSearch-client"
2-
import {SERVICE_SEARCH_BASE_QUERY_PARAMS, getServiceSearchEndpoint} from "./live-serviceSearch-client"
3-
4-
export {createServiceSearchClient, ServiceSearchClient, SERVICE_SEARCH_BASE_QUERY_PARAMS, getServiceSearchEndpoint}
1+
export {createServiceSearchClient, ServiceSearchClient} from "./serviceSearch-client"
2+
export {SERVICE_SEARCH_BASE_QUERY_PARAMS, getServiceSearchEndpoint} from "./live-serviceSearch-client"

0 commit comments

Comments
 (0)