From ae04cd6b04e0d402cb8ec53253cd32dbbc02324f Mon Sep 17 00:00:00 2001 From: AllanFly120 Date: Thu, 23 Jul 2020 01:25:15 +0000 Subject: [PATCH] test: update broken unit tests from mw stack update --- .../src/fromCognitoIdentity.spec.ts | 32 +++++++++---------- .../src/fromCognitoIdentityPool.spec.ts | 22 +++++++------ .../src/bucketEndpointMiddleware.spec.ts | 4 +-- .../util-create-request/src/index.spec.ts | 2 +- packages/util-create-request/src/index.ts | 3 +- 5 files changed, 32 insertions(+), 31 deletions(-) diff --git a/packages/credential-provider-cognito-identity/src/fromCognitoIdentity.spec.ts b/packages/credential-provider-cognito-identity/src/fromCognitoIdentity.spec.ts index 696c8afd6b84d..8c4414b06a366 100644 --- a/packages/credential-provider-cognito-identity/src/fromCognitoIdentity.spec.ts +++ b/packages/credential-provider-cognito-identity/src/fromCognitoIdentity.spec.ts @@ -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 () => { @@ -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 () => { diff --git a/packages/credential-provider-cognito-identity/src/fromCognitoIdentityPool.spec.ts b/packages/credential-provider-cognito-identity/src/fromCognitoIdentityPool.spec.ts index 0c27fb51b5f13..45f4953ba3754 100644 --- a/packages/credential-provider-cognito-identity/src/fromCognitoIdentityPool.spec.ts +++ b/packages/credential-provider-cognito-identity/src/fromCognitoIdentityPool.spec.ts @@ -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({ @@ -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 () => { diff --git a/packages/middleware-bucket-endpoint/src/bucketEndpointMiddleware.spec.ts b/packages/middleware-bucket-endpoint/src/bucketEndpointMiddleware.spec.ts index 918f22c00693c..b044ec8050712 100644 --- a/packages/middleware-bucket-endpoint/src/bucketEndpointMiddleware.spec.ts +++ b/packages/middleware-bucket-endpoint/src/bucketEndpointMiddleware.spec.ts @@ -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"; @@ -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); diff --git a/packages/util-create-request/src/index.spec.ts b/packages/util-create-request/src/index.spec.ts index 63f4323370ef2..c59fb5e743176 100644 --- a/packages/util-create-request/src/index.spec.ts +++ b/packages/util-create-request/src/index.spec.ts @@ -111,7 +111,7 @@ describe("create-request", () => { ); expect(request).toEqual({ ...httpRequest, - body: "A1B2C3", + body: "1A2B3C", }); }); }); diff --git a/packages/util-create-request/src/index.ts b/packages/util-create-request/src/index.ts index 1a1f64d641c71..11263c03e605d 100644 --- a/packages/util-create-request/src/index.ts +++ b/packages/util-create-request/src/index.ts @@ -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"; @@ -22,7 +21,7 @@ export async function createRequest< priority: "low", }); - const handler = command.resolveMiddleware(clientStack as MiddlewareStack, client.config, undefined); + const handler = command.resolveMiddleware(clientStack, client.config, undefined); //@ts-ignore return await handler(command).then((output) => output.output.request);