-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget-output-format.spec.ts
112 lines (92 loc) · 3.25 KB
/
get-output-format.spec.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
import S3 from "aws-sdk/clients/s3";
import SecretsManager from "aws-sdk/clients/secretsmanager";
import { ImageRequest } from "../../image-request";
import { SecretProvider } from "../../secret-provider";
describe("getOutputFormat", () => {
const s3Client = new S3();
const secretsManager = new SecretsManager();
const secretProvider = new SecretProvider(secretsManager);
const OLD_ENV = process.env;
beforeEach(() => {
process.env = { ...OLD_ENV };
});
afterAll(() => {
process.env = OLD_ENV;
});
it('Should pass if it returns "webp" for a capitalized accepts header which includes webp', () => {
// Arrange
const event = {
headers: {
Accept:
"text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3",
},
};
process.env.AUTO_WEBP = "Yes";
// Act
const imageRequest = new ImageRequest(s3Client, secretProvider);
const result = imageRequest.getOutputFormat(event);
// Assert
expect(result).toEqual("webp");
});
it('Should pass if it returns "webp" for a lowercase accepts header which includes webp', () => {
// Arrange
const event = {
headers: {
accept:
"text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3",
},
};
process.env.AUTO_WEBP = "Yes";
// Act
const imageRequest = new ImageRequest(s3Client, secretProvider);
const result = imageRequest.getOutputFormat(event);
// Assert
expect(result).toEqual("webp");
});
it("Should pass if it returns null for an accepts header which does not include webp", () => {
// Arrange
const event = {
headers: {
Accept:
"text/html,application/xhtml+xml,application/xml;q=0.9,image/apng,*/*;q=0.8,application/signed-exchange;v=b3",
},
};
process.env.AUTO_WEBP = "Yes";
// Act
const imageRequest = new ImageRequest(s3Client, secretProvider);
const result = imageRequest.getOutputFormat(event);
// Assert
expect(result).toBeNull();
});
it("Should pass if it returns null when AUTO_WEBP is disabled with accepts header including webp", () => {
// Arrange
const event = {
headers: {
Accept:
"text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3",
},
};
process.env.AUTO_WEBP = "No";
// Act
const imageRequest = new ImageRequest(s3Client, secretProvider);
const result = imageRequest.getOutputFormat(event);
// Assert
expect(result).toBeNull();
});
it("Should pass if it returns null when AUTO_WEBP is not set with accepts header including webp", () => {
// Arrange
const event = {
headers: {
Accept:
"text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3",
},
};
// Act
const imageRequest = new ImageRequest(s3Client, secretProvider);
const result = imageRequest.getOutputFormat(event);
// Assert
expect(result).toBeNull();
});
});