Skip to content

Commit 7ce3bf1

Browse files
committed
test(clients): run unit tests using ts-mocha
1 parent 7bf9e45 commit 7ce3bf1

File tree

11 files changed

+434
-9
lines changed

11 files changed

+434
-9
lines changed

clients/client-cognito-identity/package.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,8 @@
1212
"clean:dist": "rimraf ./dist",
1313
"clean:docs": "rimraf ./docs",
1414
"downlevel-dts": "downlevel-dts dist-types dist-types/ts3.4",
15-
"test": "yarn test:unit",
16-
"test:e2e": "mocha **/cjs/**/*.ispec.js && karma start karma.conf.js",
17-
"test:unit": "mocha **/cjs/**/*.spec.js"
15+
"test": "exit 0",
16+
"test:e2e": "mocha **/cjs/**/*.ispec.js && karma start karma.conf.js"
1817
},
1918
"main": "./dist-cjs/index.js",
2019
"types": "./dist-types/index.d.ts",

clients/client-lex-runtime-service/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"clean:docs": "rimraf ./docs",
1414
"downlevel-dts": "downlevel-dts dist-types dist-types/ts3.4",
1515
"test": "yarn test:unit",
16-
"test:unit": "mocha **/cjs/**/*.spec.js"
16+
"test:unit": "ts-mocha test/**/*.spec.ts"
1717
},
1818
"main": "./dist-cjs/index.js",
1919
"types": "./dist-types/index.d.ts",
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/// <reference types="mocha" />
2+
import { HttpRequest } from "@aws-sdk/protocol-http";
3+
import { SerializeMiddleware } from "@aws-sdk/types";
4+
import { expect } from "chai";
5+
6+
import { LexRuntimeService } from "../src/LexRuntimeService";
7+
8+
describe("@aws-sdk/client-lex-runtime-service", () => {
9+
describe("PostContent", () => {
10+
it("should contain correct x-amz-content-sha256 header", async () => {
11+
const validator: SerializeMiddleware<any, any> = (next) => (args) => {
12+
// middleware intercept the request and return it early
13+
const request = args.request as HttpRequest;
14+
expect(request.headers).to.have.property("x-amz-content-sha256", "UNSIGNED-PAYLOAD");
15+
return Promise.resolve({ output: {} as any, response: {} as any });
16+
};
17+
const client = new LexRuntimeService({
18+
region: "us-west-2",
19+
});
20+
client.middlewareStack.add(validator, {
21+
step: "serialize",
22+
name: "endpointValidator",
23+
priority: "low",
24+
});
25+
return await client.postContent({
26+
botAlias: "alias",
27+
botName: "bot",
28+
userId: "user",
29+
contentType: "text/plain; charset=utf-8",
30+
inputStream: "hello world!",
31+
});
32+
});
33+
});
34+
});

clients/client-mediastore-data/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"clean:docs": "rimraf ./docs",
1414
"downlevel-dts": "downlevel-dts dist-types dist-types/ts3.4",
1515
"test": "yarn test:unit",
16-
"test:unit": "mocha **/cjs/**/*.spec.js"
16+
"test:unit": "ts-mocha test/**/*.spec.ts"
1717
},
1818
"main": "./dist-cjs/index.js",
1919
"types": "./dist-types/index.d.ts",
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/// <reference types="mocha" />
2+
import { HttpRequest } from "@aws-sdk/protocol-http";
3+
import { SerializeMiddleware } from "@aws-sdk/types";
4+
import { expect } from "chai";
5+
6+
import { MediaStoreData } from "../src/MediaStoreData";
7+
8+
describe("@aws-sdk/client-mediastore-data", () => {
9+
describe("PutObject", () => {
10+
it("should contain correct x-amz-content-sha256 header", async () => {
11+
const validator: SerializeMiddleware<any, any> = (next) => (args) => {
12+
// middleware intercept the request and return it early
13+
const request = args.request as HttpRequest;
14+
expect(request.headers).to.have.property("x-amz-content-sha256", "UNSIGNED-PAYLOAD");
15+
return Promise.resolve({ output: {} as any, response: {} as any });
16+
};
17+
const client = new MediaStoreData({
18+
region: "us-west-2",
19+
});
20+
client.middlewareStack.add(validator, {
21+
step: "serialize",
22+
name: "endpointValidator",
23+
priority: "low",
24+
});
25+
return await client.putObject({
26+
Path: "foo.avi",
27+
Body: "binary body",
28+
});
29+
});
30+
});
31+
});

clients/client-s3-control/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"clean:docs": "rimraf ./docs",
1414
"downlevel-dts": "downlevel-dts dist-types dist-types/ts3.4",
1515
"test": "yarn test:unit",
16-
"test:unit": "mocha **/cjs/**/*.spec.js"
16+
"test:unit": "ts-mocha test/**/*.spec.ts"
1717
},
1818
"main": "./dist-cjs/index.js",
1919
"types": "./dist-types/index.d.ts",
Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
/// <reference types="mocha" />
2+
import { FinalizeRequestMiddleware } from "@aws-sdk/types";
3+
import { expect } from "chai";
4+
5+
import { S3Control } from "../src/S3Control";
6+
7+
describe("S3Control Client", () => {
8+
// Middleware intercept request and return it before reaching the HTTP client. It records the request and context
9+
// and return them in the Metadata.
10+
const interceptionMiddleware: FinalizeRequestMiddleware<any, any> = (next, context) => (args) => {
11+
return Promise.resolve({ output: { $metadata: { request: args.request } }, response: "" as any });
12+
};
13+
const region = "us-east-1";
14+
const credentials = { accessKeyId: "AKID", secretAccessKey: "SECRET" };
15+
const s3Control = new S3Control({ region, credentials });
16+
s3Control.middlewareStack.add(interceptionMiddleware, { step: "finalizeRequest", name: "interceptionMiddleware" });
17+
const HEADER_OUTPOST_ID = "x-amz-outpost-id";
18+
const HEADER_ACCOUNT_ID = "x-amz-account-id";
19+
const dateStr = new Date().toISOString().substr(0, 10).replace(/[\-:]/g, "");
20+
21+
describe("CreateBucket", () => {
22+
it("should populate correct endpoint and signing region", async () => {
23+
const {
24+
// @ts-ignore request is set in $metadata by interception middleware.
25+
$metadata: { request },
26+
} = await s3Control.createBucket({ Bucket: "Bucket" });
27+
expect(request.hostname).eql(`s3-control.${region}.amazonaws.com`);
28+
expect(request.headers["authorization"]).contains(
29+
`Credential=${credentials.accessKeyId}/${dateStr}/${region}/s3/aws4_request`
30+
);
31+
});
32+
33+
it("should populate correct endpoint and signing region if OutpostId is supplied", async () => {
34+
const OutpostId = "123456789012";
35+
const {
36+
// @ts-ignore request is set in $metadata by interception middleware.
37+
$metadata: { request },
38+
} = await s3Control.createBucket({ Bucket: "Bucket", OutpostId });
39+
expect(request.hostname).eql(`s3-outposts.${region}.amazonaws.com`);
40+
expect(request.headers[HEADER_OUTPOST_ID]).eql(OutpostId);
41+
expect(request.headers["authorization"]).contains(
42+
`Credential=${credentials.accessKeyId}/${dateStr}/${region}/s3-outposts/aws4_request`
43+
);
44+
});
45+
});
46+
47+
describe("ListRegionalBuckets", () => {
48+
const AccountId = "123456789012";
49+
it("should populate correct endpoint and signing region", async () => {
50+
const {
51+
// @ts-ignore request is set in $metadata by interception middleware.
52+
$metadata: { request },
53+
} = await s3Control.listRegionalBuckets({ AccountId });
54+
expect(request.hostname).eql(`${AccountId}.s3-control.${region}.amazonaws.com`);
55+
expect(request.headers["authorization"]).contains(
56+
`Credential=${credentials.accessKeyId}/${dateStr}/${region}/s3/aws4_request`
57+
);
58+
});
59+
60+
it("should populate correct endpoint and signing region if OutpostId is supplied", async () => {
61+
const OutpostId = "123456789012";
62+
const {
63+
// @ts-ignore request is set in $metadata by interception middleware.
64+
$metadata: { request },
65+
} = await s3Control.listRegionalBuckets({ AccountId, OutpostId });
66+
expect(request.hostname).eql(`s3-outposts.${region}.amazonaws.com`);
67+
expect(request.headers[HEADER_OUTPOST_ID]).eql(OutpostId);
68+
expect(request.headers[HEADER_ACCOUNT_ID]).eql(AccountId);
69+
expect(request.headers["authorization"]).contains(
70+
`Credential=${credentials.accessKeyId}/${dateStr}/${region}/s3-outposts/aws4_request`
71+
);
72+
});
73+
});
74+
75+
// Use GetAccessPointCommand to validate the customizations for Access Point ARN customizations
76+
describe("Outposts Access Point ARN", () => {
77+
const AccountId = "123456789012";
78+
const OutpostId = "op-01234567890123456";
79+
const accesspointArn = `arn:aws:s3-outposts:${region}:${AccountId}:outpost:${OutpostId}:accesspoint:myaccesspoint`;
80+
it("should populate correct endpoint if Access Point name is non-ARN", async () => {
81+
const {
82+
// @ts-ignore request is set in $metadata by interception middleware.
83+
$metadata: { request },
84+
} = await s3Control.getAccessPoint({ Name: "FakeAccessPoint", AccountId });
85+
expect(request.hostname).eql(`${AccountId}.s3-control.${region}.amazonaws.com`);
86+
expect(request.headers["authorization"]).contains(
87+
`Credential=${credentials.accessKeyId}/${dateStr}/${region}/s3/aws4_request`
88+
);
89+
});
90+
91+
it("should populate correct endpoint and signing region if Access Point name is ARN", async () => {
92+
const {
93+
// @ts-ignore request is set in $metadata by interception middleware.
94+
$metadata: { request },
95+
} = await s3Control.getAccessPoint({ Name: accesspointArn });
96+
expect(request.hostname).eql(`s3-outposts.${region}.amazonaws.com`);
97+
expect(request.headers[HEADER_OUTPOST_ID]).eql(OutpostId);
98+
expect(request.headers[HEADER_ACCOUNT_ID]).eql(AccountId);
99+
expect(request.headers["authorization"]).contains(
100+
`Credential=${credentials.accessKeyId}/${dateStr}/${region}/s3-outposts/aws4_request`
101+
);
102+
});
103+
});
104+
105+
// Use GetBucketCommand to validate the customizations for Bucket ARN customizations
106+
describe("Outposts Bucket ARN", () => {
107+
const AccountId = "123456789012";
108+
const OutpostId = "op-01234567890123456";
109+
const bucketArn = `arn:aws:s3-outposts:${region}:${AccountId}:outpost/${OutpostId}/bucket/bucket-id"`;
110+
it("should populate correct endpoint if Bucket name is non-ARN", async () => {
111+
const {
112+
// @ts-ignore request is set in $metadata by interception middleware.
113+
$metadata: { request },
114+
} = await s3Control.getBucket({ Bucket: "BucketName", AccountId });
115+
expect(request.hostname).eql(`${AccountId}.s3-control.${region}.amazonaws.com`);
116+
expect(request.headers["authorization"]).contains(
117+
`Credential=${credentials.accessKeyId}/${dateStr}/${region}/s3/aws4_request`
118+
);
119+
});
120+
121+
it("should populate correct endpoint and signing region if Bucket name is ARN", async () => {
122+
const {
123+
// @ts-ignore request is set in $metadata by interception middleware.
124+
$metadata: { request },
125+
} = await s3Control.getBucket({ Bucket: bucketArn });
126+
expect(request.hostname).eql(`s3-outposts.${region}.amazonaws.com`);
127+
expect(request.headers[HEADER_OUTPOST_ID]).eql(OutpostId);
128+
expect(request.headers[HEADER_ACCOUNT_ID]).eql(AccountId);
129+
expect(request.headers["authorization"]).contains(
130+
`Credential=${credentials.accessKeyId}/${dateStr}/${region}/s3-outposts/aws4_request`
131+
);
132+
});
133+
});
134+
});

clients/client-s3/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"downlevel-dts": "downlevel-dts dist-types dist-types/ts3.4",
1515
"test": "yarn test:unit",
1616
"test:e2e": "mocha **/cjs/**/*.ispec.js && karma start karma.conf.js",
17-
"test:unit": "mocha **/cjs/**/*.spec.js"
17+
"test:unit": "ts-mocha test/**/*.spec.ts"
1818
},
1919
"main": "./dist-cjs/index.js",
2020
"types": "./dist-types/index.d.ts",

0 commit comments

Comments
 (0)