This repository was archived by the owner on Jan 28, 2025. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 465
/
Copy paths3StorePage.test.ts
56 lines (49 loc) · 1.73 KB
/
s3StorePage.test.ts
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
45
46
47
48
49
50
51
52
53
54
55
56
import { s3StorePage } from "../../src/s3/s3StorePage";
import { jest } from "@jest/globals";
import {
mockSend,
mockPutObjectCommand
} from "../mocks/s3/aws-sdk-s3-client.mock2";
jest.mock("@aws-sdk/client-s3", () =>
require("../mocks/s3/aws-sdk-s3-client.mock2")
);
describe("S3StorePage Tests", () => {
it.each`
basePath | uri | expectedKeyName
${undefined} | ${"/custom"} | ${"custom"}
${undefined} | ${"/"} | ${"index"}
${"/basepath"} | ${"/custom"} | ${"custom"}
${"/basepath"} | ${"/"} | ${"index"}
`(
"should store the page with basePath $basePath at path $uri with expectedKeyName $expectedKeyName",
async ({ basePath, uri, expectedKeyName }) => {
await s3StorePage({
uri: uri,
basePath: basePath,
bucketName: "test",
html: "test",
buildId: "test-build-id",
region: "us-west-2",
pageData: {}
});
const s3BasePath = basePath ? `${basePath.replace(/^\//, "")}/` : "";
expect(mockPutObjectCommand).toHaveBeenNthCalledWith(1, {
Bucket: "test",
Key: `${s3BasePath}_next/data/test-build-id/${expectedKeyName}.json`,
Body: "{}",
ContentType: "application/json",
CacheControl: "public, max-age=0, s-maxage=2678400, must-revalidate",
Expires: undefined
});
expect(mockPutObjectCommand).toHaveBeenNthCalledWith(2, {
Bucket: "test",
Key: `${s3BasePath}static-pages/test-build-id/${expectedKeyName}.html`,
Body: "test",
ContentType: "text/html",
CacheControl: "public, max-age=0, s-maxage=2678400, must-revalidate",
Expires: undefined
});
expect(mockSend).toHaveBeenCalledTimes(2);
}
);
});