Skip to content

Commit 5362e4e

Browse files
committed
chore: update for vitest 4 mocking
1 parent cdf1488 commit 5362e4e

10 files changed

Lines changed: 60 additions & 46 deletions

File tree

packages/nhsNotifyLambda/tests/testAuth.test.ts

Lines changed: 31 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,9 @@ describe("tokenExchange", () => {
6868
},
6969
sign: vi.fn().mockImplementation(() => Promise.resolve("signed.jwt.token"))
7070
}
71-
mockSignJWTConstructor.mockImplementation(() => fakeJwtInstance)
71+
mockSignJWTConstructor.mockImplementation(function() {
72+
return fakeJwtInstance
73+
})
7274

7375
// Mock the HTTP call
7476
nock(`${host}`)
@@ -101,18 +103,20 @@ describe("tokenExchange", () => {
101103
}
102104

103105
mockImportPKCS8.mockImplementation(() => Promise.resolve("imported"))
104-
mockSignJWTConstructor.mockImplementation(() => ({
105-
setProtectedHeader() {
106-
return this
107-
},
108-
setIssuedAt() {
109-
return this
110-
},
111-
setExpirationTime() {
112-
return this
113-
},
114-
sign: vi.fn().mockImplementation(() => Promise.resolve("jwt-tkn"))
115-
}))
106+
mockSignJWTConstructor.mockImplementation(function() {
107+
return ({
108+
setProtectedHeader() {
109+
return this
110+
},
111+
setIssuedAt() {
112+
return this
113+
},
114+
setExpirationTime() {
115+
return this
116+
},
117+
sign: vi.fn().mockImplementation(() => Promise.resolve("jwt-tkn"))
118+
})
119+
})
116120

117121
nock(`${host}`)
118122
.post("/oauth2/token")
@@ -131,18 +135,20 @@ describe("tokenExchange", () => {
131135
}
132136

133137
mockImportPKCS8.mockImplementation(() => Promise.resolve("imported"))
134-
mockSignJWTConstructor.mockImplementation(() => ({
135-
setProtectedHeader() {
136-
return this
137-
},
138-
setIssuedAt() {
139-
return this
140-
},
141-
setExpirationTime() {
142-
return this
143-
},
144-
sign: vi.fn().mockImplementation(() => Promise.resolve("jwt-tkn"))
145-
}))
138+
mockSignJWTConstructor.mockImplementation(function() {
139+
return ({
140+
setProtectedHeader() {
141+
return this
142+
},
143+
setIssuedAt() {
144+
return this
145+
},
146+
setExpirationTime() {
147+
return this
148+
},
149+
sign: vi.fn().mockImplementation(() => Promise.resolve("jwt-tkn"))
150+
})
151+
})
146152

147153
nock(`${host}`)
148154
.post("/oauth2/token")

packages/nhsNotifyLambda/tests/testHelpers.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ vi.mock("@aws-sdk/client-sqs", async (importOriginal) => {
1010
const sqs = await importOriginal<typeof import("@aws-sdk/client-sqs")>()
1111
return {
1212
...sqs,
13-
SQSClient: vi.fn().mockImplementation(() => ({
14-
send: mockSend
15-
}))
13+
SQSClient: vi.fn(class {
14+
send = mockSend
15+
})
1616
}
1717
})
1818

packages/nhsNotifyLambda/tests/testNhsNotifyLambda.test.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,11 @@ vi.mock(
5959
"@aws-lambda-powertools/logger",
6060
async () => ({
6161
__esModule: true,
62-
Logger: vi.fn().mockImplementation(() => ({
63-
info: mockInfo,
64-
error: mockError,
65-
warn: mockWarn
66-
}))
62+
Logger: vi.fn(class {
63+
info = mockInfo
64+
error = mockError
65+
warn = mockWarn
66+
})
6767
})
6868
)
6969

packages/nhsNotifyLambda/tests/testUtils.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@ vi.mock(
4242
"@aws-lambda-powertools/parameters/ssm",
4343
async () => ({
4444
__esModule: true,
45-
SSMProvider: vi.fn().mockImplementation(() => ({
46-
getParametersByName: mockGetParametersByName
47-
}))
45+
SSMProvider: vi.fn(class {
46+
getParametersByName = mockGetParametersByName
47+
})
4848
})
4949
)
5050

packages/postDatedLambda/tests/testDatabaseClient.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ vi.mock("@aws-sdk/client-dynamodb", async () => {
1818
const dynamo = await vi.importActual<typeof import("@aws-sdk/client-dynamodb")>("@aws-sdk/client-dynamodb")
1919
return {
2020
...dynamo,
21-
DynamoDBClient: vi.fn().mockImplementation(() => ({
22-
send: mockSend
23-
}))
21+
DynamoDBClient: vi.fn(class {
22+
send = mockSend
23+
})
2424
}
2525
})
2626
const {

packages/postDatedLambda/tests/testSqs.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ vi.mock("@aws-sdk/client-sqs", async () => {
2020
const sqs = await vi.importActual<typeof import("@aws-sdk/client-sqs")>("@aws-sdk/client-sqs")
2121
return {
2222
...sqs,
23-
SQSClient: vi.fn().mockImplementation(() => ({
24-
send: mockSend
25-
}))
23+
SQSClient: vi.fn(class {
24+
send = mockSend
25+
})
2626
}
2727
})
2828

packages/updatePrescriptionStatus/tests/testDatabaseClient.test.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ vi.mock(
1818
const mod = await importOriginal()
1919
return {
2020
...mod,
21-
DynamoDBClient: vi.fn().mockImplementation(() => ({send: mockSend}))
21+
DynamoDBClient: vi.fn(class {
22+
send = mockSend
23+
})
2224
}
2325
}
2426
)

packages/updatePrescriptionStatus/tests/testHandler.test.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,9 @@ vi.mock("@aws-sdk/client-dynamodb", async (importOriginal) => {
5454
const mod = await importOriginal<typeof import("@aws-sdk/client-dynamodb")>()
5555
return {
5656
...mod,
57-
DynamoDBClient: vi.fn().mockImplementation(() => ({send: dynamoDBMockSend}))
57+
DynamoDBClient: vi.fn(class {
58+
send = dynamoDBMockSend
59+
})
5860
}
5961
})
6062

packages/updatePrescriptionStatus/tests/testPrescriptionIntercept.test.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@ vi.mock("@aws-sdk/client-dynamodb", async (importOriginal) => {
3434
const mod = await importOriginal<typeof import("@aws-sdk/client-dynamodb")>()
3535
return {
3636
...mod,
37-
DynamoDBClient: vi.fn().mockImplementation(() => ({send: mockSend}))
37+
DynamoDBClient: vi.fn(class {
38+
send = mockSend
39+
})
3840
}
3941
})
4042

packages/updatePrescriptionStatus/tests/testSqsClient.test.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@ vi.mock("@aws-sdk/client-sqs", async (importOriginal: () => Promise<typeof impor
3030
const mod = await importOriginal()
3131
return {
3232
...mod,
33-
SQSClient: vi.fn().mockImplementation(() => ({send: mockSend}))
33+
SQSClient: vi.fn(class {
34+
send = mockSend
35+
})
3436
}
3537
})
3638

0 commit comments

Comments
 (0)