Skip to content

Commit 7db0784

Browse files
author
Siddharth Srivastava
committed
fix(middleware-sdk-s3): added tests for returning <200 and >=300 code
1 parent 6cd77cb commit 7db0784

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

packages/middleware-sdk-s3/src/throw-200-exceptions.spec.ts

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,54 @@ describe("throw200ExceptionsMiddlewareOptions", () => {
1515
jest.clearAllMocks();
1616
});
1717

18+
describe("exceptions for code < 200 and >= 300", () => {
19+
mockStreamCollector.mockResolvedValue(Buffer.from(""));
20+
mockUtf8Encoder.mockReturnValue("");
21+
it("throws an exception if code is less than 200", async () => {
22+
mockNextHandler.mockReturnValue({
23+
response: new HttpResponse({
24+
statusCode: 199,
25+
headers: {},
26+
body: "",
27+
}),
28+
});
29+
const handler = throw200ExceptionsMiddleware(mockConfig)(mockNextHandler, {} as any);
30+
try {
31+
await handler({
32+
input: {},
33+
request: new HttpRequest({
34+
hostname: "s3.us-east-1.amazonaws.com",
35+
}),
36+
});
37+
} catch (e) {
38+
expect(e).toBeDefined();
39+
expect(e.name).toEqual("InternalError");
40+
expect(e.message).toEqual("S3 aborted request");
41+
}
42+
});
43+
it("throws an exception if code is greater than or equal to 300", async () => {
44+
mockNextHandler.mockReturnValue({
45+
response: new HttpResponse({
46+
statusCode: 300,
47+
headers: {},
48+
body: "",
49+
}),
50+
});
51+
const handler = throw200ExceptionsMiddleware(mockConfig)(mockNextHandler, {} as any);
52+
try {
53+
await handler({
54+
input: {},
55+
request: new HttpRequest({
56+
hostname: "s3.us-east-1.amazonaws.com",
57+
}),
58+
});
59+
} catch (e) {
60+
expect(e).toBeDefined();
61+
expect(e.name).toEqual("InternalError");
62+
expect(e.message).toEqual("S3 aborted request");
63+
}
64+
});
65+
});
1866
it("should throw if response body is empty", async () => {
1967
expect.assertions(3);
2068
mockStreamCollector.mockResolvedValue(Buffer.from(""));

0 commit comments

Comments
 (0)