Skip to content

Commit f41c896

Browse files
committed
fix: Sonar style issues
1 parent 04fd85f commit f41c896

4 files changed

Lines changed: 25 additions & 25 deletions

File tree

packages/cdk/resources/Apis.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ export class Apis extends Construct {
7979
})
8080

8181
// POST /notification-delivery-status-callback — Lambda proxy integration
82-
const notificationDeliveryStatusCallbackEndpoint = new LambdaEndpoint(this, "NotificationDeliveryStatusCallbackEndpoint", {
82+
const notifyCallbackEndpoint = new LambdaEndpoint(this, "NotificationDeliveryStatusCallbackEndpoint", {
8383
parentResource: rootResource,
8484
resourceName: "notification-delivery-status-callback",
8585
method: HttpMethod.POST,
@@ -110,7 +110,7 @@ export class Apis extends Construct {
110110
format1UpdatePrescriptionStatusEndpoint: format1PsuEndpoint,
111111
status: statusEndpoint,
112112
capabilityStatement: capabilityStatementEndpoint,
113-
notificationDeliveryStatusCallback: notificationDeliveryStatusCallbackEndpoint,
113+
notificationDeliveryStatusCallback: notifyCallbackEndpoint,
114114
}
115115

116116
// GET /checkprescriptionstatusupdates — conditional Lambda proxy integration

packages/updatePrescriptionStatus/tests/testDatabaseClient.test.ts

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ describe("Unit test persistDataItems", () => {
144144
ApplicationID: "550e8400-e29b-41d4-a716-446655440000",
145145
ExpiryTime: 10
146146
}
147-
const dataItems = Array(150).fill(dataItem)
147+
const dataItems = new Array(150).fill(dataItem)
148148

149149
const loggerSpy = vi.spyOn(logger, "error")
150150

@@ -367,7 +367,7 @@ describe("Unit test rollbackDataItems", () => {
367367
const items = [makeItem(), makeItem({PrescriptionID: "PrescriptionID_2", TaskID: "TaskID_2"})]
368368

369369
// success for each conditioned delete
370-
mockSend.mockImplementation(async () => Promise.resolve())
370+
mockSend.mockImplementation(async () => {})
371371

372372
const loggerWarn = vi.spyOn(logger, "warn")
373373
const loggerError = vi.spyOn(logger, "error")
@@ -384,14 +384,14 @@ describe("Unit test rollbackDataItems", () => {
384384

385385
// First delete succeeds, second hits conditional check failure (skip it)
386386
mockSend
387-
.mockImplementationOnce(async () => Promise.resolve())
388-
.mockImplementationOnce(async () => Promise.reject(
389-
new TransactionCanceledException({
387+
.mockImplementationOnce(async () => {})
388+
.mockImplementationOnce(async () => {
389+
throw new TransactionCanceledException({
390390
$metadata: {},
391391
message: "Conditional check failed",
392392
CancellationReasons: [{Code: "ConditionalCheckFailedException"}]
393393
})
394-
))
394+
})
395395

396396
const loggerWarn = vi.spyOn(logger, "warn")
397397
const loggerError = vi.spyOn(logger, "error")
@@ -406,7 +406,9 @@ describe("Unit test rollbackDataItems", () => {
406406
it("returns false when an unexpected error occurs", async () => {
407407
const items = [makeItem()]
408408

409-
mockSend.mockImplementationOnce(async () => Promise.reject(new Error("error")))
409+
mockSend.mockImplementationOnce(async () => {
410+
throw new Error("error")
411+
})
410412

411413
const loggerError = vi.spyOn(logger, "error")
412414

@@ -420,15 +422,15 @@ describe("Unit test rollbackDataItems", () => {
420422
const items = [makeItem({TaskID: "A"}), makeItem({TaskID: "B"}), makeItem({TaskID: "C"})]
421423

422424
mockSend
423-
.mockImplementationOnce(async () => Promise.resolve()) // A: delete ok
424-
.mockImplementationOnce(async () => Promise.reject( // B: condition failure -> skip
425-
new TransactionCanceledException({
425+
.mockImplementationOnce(async () => {}) // A: delete ok
426+
.mockImplementationOnce(async () => { // B: condition failure -> skip
427+
throw new TransactionCanceledException({
426428
$metadata: {},
427429
message: "Conditional check failed",
428430
CancellationReasons: [{Code: "ConditionalCheckFailedException"}]
429431
})
430-
))
431-
.mockImplementationOnce(async () => Promise.resolve()) // C: delete ok
432+
})
433+
.mockImplementationOnce(async () => {}) // C: delete ok
432434

433435
const loggerWarn = vi.spyOn(logger, "warn")
434436
const loggerError = vi.spyOn(logger, "error")

packages/updatePrescriptionStatus/tests/testHandler.test.ts

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,10 @@ import {QueryCommand, TransactionCanceledException, TransactWriteItemsCommand} f
3939

4040
const {dynamoDBMockSend, mockPushPrescriptionToNotificationSQS, mockGetParametersByName, mockInitiatedSSMProvider} =
4141
vi.hoisted(() => {
42-
const mockGetParametersByName = vi.fn(async () => Promise.resolve(
43-
{[process.env.ENABLE_NOTIFICATIONS_PARAM!]: "false"}
44-
))
42+
const mockGetParametersByName = vi.fn(async () => ({[process.env.ENABLE_NOTIFICATIONS_PARAM!]: "false"}))
4543
return {
4644
dynamoDBMockSend: vi.fn(),
47-
mockPushPrescriptionToNotificationSQS: vi.fn().mockImplementation(async () => Promise.resolve()),
45+
mockPushPrescriptionToNotificationSQS: vi.fn().mockImplementation(async () => {}),
4846
mockGetParametersByName,
4947
mockInitiatedSSMProvider: {getParametersByName: mockGetParametersByName}
5048
}
@@ -97,12 +95,10 @@ describe("Integration tests for updatePrescriptionStatus handler", () => {
9795
})
9896

9997
mockPushPrescriptionToNotificationSQS.mockReset()
100-
mockPushPrescriptionToNotificationSQS.mockImplementation(async () => Promise.resolve())
98+
mockPushPrescriptionToNotificationSQS.mockImplementation(async () => {})
10199

102100
mockGetParametersByName.mockReset()
103-
mockGetParametersByName.mockImplementation(async () => Promise.resolve(
104-
{[process.env.ENABLE_NOTIFICATIONS_PARAM!]: "false"}
105-
))
101+
mockGetParametersByName.mockImplementation(async () => ({[process.env.ENABLE_NOTIFICATIONS_PARAM!]: "false"}))
106102
})
107103

108104
it("when request doesn't have correct resourceType and type, expect 400 status code and appropriate message", async () => {
@@ -277,7 +273,7 @@ describe("Integration tests for updatePrescriptionStatus handler", () => {
277273

278274
it("when dynamo call fails, expect 500 status code and internal server error message", async () => {
279275
const event = generateMockEvent(requestDispatched)
280-
dynamoDBMockSend.mockRejectedValue(new Error() as never)
276+
dynamoDBMockSend.mockRejectedValue(new Error() as never) // NOSONAR
281277

282278
const response: APIGatewayProxyResult = await handler(event, {})
283279

@@ -532,7 +528,9 @@ describe("Integration tests for updatePrescriptionStatus handler", () => {
532528
})
533529

534530
it("When the get parameter call throws an error, the request succeeds and the sqs queue is untouched", async () => {
535-
mockGetParametersByName.mockImplementation(async () => Promise.reject(new Error("Failed")))
531+
mockGetParametersByName.mockImplementation(async () => {
532+
throw new Error("Failed")
533+
})
536534
const {handler: tmpfn} = await import("../src/updatePrescriptionStatus")
537535

538536
const rejected_event: APIGatewayProxyEvent = generateMockEvent(requestDispatched)

packages/updatePrescriptionStatus/tests/utils/testUtils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ export const TASK_VALUES = [
7777
]
7878

7979
export function deepCopy(toCopy: object) {
80-
return JSON.parse(JSON.stringify(toCopy))
80+
return structuredClone(toCopy)
8181
}
8282

8383
export function validTask(): Task {

0 commit comments

Comments
 (0)