Skip to content

Commit 462e46f

Browse files
authored
test(client-eventbridge): functional test for EndpointId (#3522)
1 parent 1866b21 commit 462e46f

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

clients/client-eventbridge/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@
99
"build:es": "tsc -p tsconfig.es.json",
1010
"build:types": "tsc -p tsconfig.types.json",
1111
"build:types:downlevel": "downlevel-dts dist-types dist-types/ts3.4",
12-
"clean": "rimraf ./dist-* && rimraf *.tsbuildinfo"
12+
"clean": "rimraf ./dist-* && rimraf *.tsbuildinfo",
13+
"test": "yarn test:unit",
14+
"test:unit": "ts-mocha test/**/*.spec.ts"
1315
},
1416
"main": "./dist-cjs/index.js",
1517
"types": "./dist-types/index.d.ts",
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/// <reference types="mocha" />
2+
import { FinalizeRequestMiddleware } from "@aws-sdk/types";
3+
import chai from "chai";
4+
import chaiAsPromised from "chai-as-promised";
5+
6+
import { EventBridge } from "../src/EventBridge";
7+
8+
chai.use(chaiAsPromised);
9+
const { expect } = chai;
10+
11+
describe("EventBridge", () => {
12+
const client = new EventBridge({});
13+
// Middleware intercept request and return it before reaching the HTTP client. It records the request and context
14+
// and return them in the Metadata.
15+
const interceptionMiddleware: FinalizeRequestMiddleware<any, any> = (next, context) => (args) => {
16+
return Promise.resolve({ output: { $metadata: { request: args.request } }, response: "" as any });
17+
};
18+
client.middlewareStack.add(interceptionMiddleware, { step: "finalizeRequest", name: "interceptionMiddleware" });
19+
describe("putEvents", () => {
20+
it("should use sign request with sigv4a with EventId presents", async () => {
21+
const {
22+
// @ts-ignore request is set in $metadata by interception middleware.
23+
$metadata: { request },
24+
} = await client.putEvents({
25+
Entries: [],
26+
EndpointId: "endpointId",
27+
});
28+
expect(request.hostname).eql("endpointId.endpoint.events.amazonaws.com");
29+
expect(request.headers["X-Amz-Region-Set"]).eql("*");
30+
expect(request.headers["Authorization"]).includes("AWS4-ECDSA-P256-SHA256");
31+
});
32+
});
33+
});

0 commit comments

Comments
 (0)