-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.test.js
More file actions
44 lines (38 loc) · 1.1 KB
/
index.test.js
File metadata and controls
44 lines (38 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import { mockClient } from "aws-sdk-client-mock";
import { DynamoDBClient, GetItemCommand } from "@aws-sdk/client-dynamodb";
import { handler } from "./index.mjs";
const ddbMock = mockClient(DynamoDBClient);
beforeEach(() => {
ddbMock.reset();
ddbMock.on(GetItemCommand, { TableName: "jokes" }).resolves({
Item: {
ID: {
N: "1",
},
Text: {
S: "funny joke from shared table",
},
},
});
ddbMock.on(GetItemCommand, { TableName: "jokes-test-user" }).resolves({
Item: {
ID: {
N: "1",
},
Text: {
S: "funny joke from user-specific table",
},
},
});
});
test("A joke is returned from the shared table", async () => {
const result = await handler({ jokeID: "1" });
expect(result).toBeDefined();
expect(result.Text.S).toBe("funny joke from shared table");
});
test("Table suffix env variable is honored", async () => {
process.env.JOKE_TABLE_SUFFIX = "-test-user";
const result = await handler({ jokeID: "1" });
expect(result).toBeDefined();
expect(result.Text.S).toBe("funny joke from user-specific table");
});