Skip to content

Commit e9e3b87

Browse files
committed
test(client-s3): validate response structure
1 parent a218adb commit e9e3b87

File tree

3 files changed

+31
-19
lines changed

3 files changed

+31
-19
lines changed

clients/client-s3/test/e2e/S3.browser.e2e.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { S3, SelectObjectContentEventStream, waitUntilObjectExists } from "@aws-sdk/client-s3";
1+
import type { S3, waitUntilObjectExists } from "@aws-sdk/client-s3";
22
import { fromNodeProviderChain } from "@aws-sdk/credential-providers";
33
import { FetchHttpHandler } from "@smithy/fetch-http-handler";
44
import { Browser } from "happy-dom";

clients/client-s3/test/e2e/S3.e2e.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import "@aws-sdk/signature-v4-crt";
22

3-
import { ChecksumAlgorithm, S3, SelectObjectContentEventStream } from "@aws-sdk/client-s3";
3+
import { ChecksumAlgorithm, S3 } from "@aws-sdk/client-s3";
44
import { afterAll, afterEach, beforeAll, describe, expect, test as it } from "vitest";
55

66
import { getIntegTestResources } from "../../../../tests/e2e/get-integ-test-resources";
Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { S3 } from "@aws-sdk/client-s3";
2+
import { HttpResponse } from "@smithy/protocol-http";
23
import { describe, expect, test as it } from "vitest";
34

45
import { requireRequestsFrom } from "../../../../private/aws-util-test/src";
@@ -12,24 +13,31 @@ describe("selectObjectContent", () => {
1213
it("should make correct request", async () => {
1314
const client = new S3({ region: "us-west-2", credentials });
1415

15-
requireRequestsFrom(client).toMatch({
16-
hostname: /aws-sdk-js-integ-test-bucket\.s3\.us-west-2\.amazonaws\.com/,
17-
method: "POST",
18-
path: "/test-key",
19-
headers: {
20-
authorization: /AWS4-HMAC-SHA256 Credential/,
21-
"content-type": "application/xml",
22-
"x-amz-content-sha256": /./,
23-
},
24-
body(xmlBody) {
25-
expect(xmlBody).toContain(
26-
"<Expression>SELECT user_name FROM S3Object WHERE cast(age as int) &gt; 20</Expression>"
27-
);
28-
expect(xmlBody).toContain("<ExpressionType>SQL</ExpressionType>");
29-
},
30-
});
16+
requireRequestsFrom(client)
17+
.toMatch({
18+
hostname: /aws-sdk-js-integ-test-bucket\.s3\.us-west-2\.amazonaws\.com/,
19+
method: "POST",
20+
path: "/test-key",
21+
headers: {
22+
authorization: /AWS4-HMAC-SHA256 Credential/,
23+
"content-type": "application/xml",
24+
"x-amz-content-sha256": /./,
25+
},
26+
body(xmlBody) {
27+
expect(xmlBody).toContain(
28+
"<Expression>SELECT user_name FROM S3Object WHERE cast(age as int) &gt; 20</Expression>"
29+
);
30+
expect(xmlBody).toContain("<ExpressionType>SQL</ExpressionType>");
31+
},
32+
})
33+
.respondWith(
34+
new HttpResponse({
35+
statusCode: 200,
36+
body: " ",
37+
})
38+
);
3139

32-
await client.selectObjectContent({
40+
const response = await client.selectObjectContent({
3341
Bucket: "aws-sdk-js-integ-test-bucket",
3442
Key: "test-key",
3543
ExpressionType: "SQL",
@@ -47,5 +55,9 @@ describe("selectObjectContent", () => {
4755
});
4856

4957
expect.hasAssertions();
58+
expect(response).toHaveProperty("$metadata");
59+
expect(response.$metadata.httpStatusCode).toBe(200);
60+
expect(response).toHaveProperty("Payload");
61+
expect(response.Payload).toBeDefined();
5062
});
5163
});

0 commit comments

Comments
 (0)