Skip to content

Commit

Permalink
test: update broken unit tests from mw stack update
Browse files Browse the repository at this point in the history
  • Loading branch information
AllanZhengYP committed Jul 23, 2020
1 parent e7a02f1 commit ae04cd6
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ describe("fromCognitoIdentity", () => {
expiration,
});

expect(send.mock.calls[0][0]).toEqual(
new GetCredentialsForIdentityCommand({
IdentityId: identityId,
CustomRoleArn: "myArn",
})
);
const sendParam = send.mock.calls[0][0];
expect(sendParam).toEqual(expect.any(GetCredentialsForIdentityCommand));
expect(sendParam.input).toEqual({
IdentityId: identityId,
CustomRoleArn: "myArn",
});
});

it("should resolve logins to string tokens and pass them to the service", async () => {
Expand All @@ -54,16 +54,16 @@ describe("fromCognitoIdentity", () => {
},
})();

expect(send.mock.calls[0][0]).toEqual(
new GetCredentialsForIdentityCommand({
IdentityId: identityId,
CustomRoleArn: "myArn",
Logins: {
myDomain: "token",
"www.amazon.com": "expiring nonce",
},
})
);
const sendParam = send.mock.calls[0][0];
expect(sendParam).toEqual(expect.any(GetCredentialsForIdentityCommand));
expect(sendParam.input).toMatchObject({
IdentityId: identityId,
CustomRoleArn: "myArn",
Logins: {
myDomain: "token",
"www.amazon.com": "expiring nonce",
},
});
});

it("should convert a GetCredentialsForIdentity response without credentials to a provider error", async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,10 @@ describe("fromCognitoIdentityPool", () => {
});

expect(send.mock.calls.length).toBe(1);
expect(send.mock.calls[0][0]).toEqual(new GetIdCommand({ IdentityPoolId: identityPoolId }));
expect(send.mock.calls[0][0]).toEqual(expect.any(GetIdCommand));
expect(send.mock.calls[0][0].input).toEqual({
IdentityPoolId: identityPoolId,
});

expect((fromCognitoIdentity as any).mock.calls.length).toBe(1);
expect((fromCognitoIdentity as any).mock.calls[0][0]).toEqual({
Expand All @@ -76,15 +79,14 @@ describe("fromCognitoIdentityPool", () => {
},
})();

expect(send.mock.calls[0][0]).toEqual(
new GetIdCommand({
IdentityPoolId: identityPoolId,
Logins: {
myDomain: "token",
"www.amazon.com": "expiring nonce",
},
})
);
expect(send.mock.calls[0][0]).toEqual(expect.any(GetIdCommand));
expect(send.mock.calls[0][0].input).toEqual({
IdentityPoolId: identityPoolId,
Logins: {
myDomain: "token",
"www.amazon.com": "expiring nonce",
},
});
});

it("should not invoke GetId a second time once an identityID has been fetched", async () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { MiddlewareStack } from "@aws-sdk/middleware-stack";
import { constructStack } from "@aws-sdk/middleware-stack";
import { HttpRequest } from "@aws-sdk/protocol-http";

import { bucketEndpointMiddleware, bucketEndpointMiddlewareOptions } from "./bucketEndpointMiddleware";
Expand Down Expand Up @@ -130,7 +130,7 @@ describe("bucketEndpointMiddleware", () => {
});

it("should be inserted before 'hostheaderMiddleware' if exists", async () => {
const stack = new MiddlewareStack();
const stack = constructStack();
const mockHostheaderMiddleware = (next: any) => (args: any) => {
args.request.arr.push("two");
return next(args);
Expand Down
2 changes: 1 addition & 1 deletion packages/util-create-request/src/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ describe("create-request", () => {
);
expect(request).toEqual({
...httpRequest,
body: "A1B2C3",
body: "1A2B3C",
});
});
});
3 changes: 1 addition & 2 deletions packages/util-create-request/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { MiddlewareStack } from "@aws-sdk/middleware-stack";
import { Client, Command } from "@aws-sdk/smithy-client";
import { BuildMiddleware, HttpRequest, MetadataBearer } from "@aws-sdk/types";

Expand All @@ -22,7 +21,7 @@ export async function createRequest<
priority: "low",
});

const handler = command.resolveMiddleware(clientStack as MiddlewareStack<any, any>, client.config, undefined);
const handler = command.resolveMiddleware(clientStack, client.config, undefined);

//@ts-ignore
return await handler(command).then((output) => output.output.request);
Expand Down

0 comments on commit ae04cd6

Please sign in to comment.