From b8fb79e704f9ba2fcd53b37fba2d0db6b06b08b0 Mon Sep 17 00:00:00 2001 From: Mike Dalrymple Date: Mon, 16 Mar 2020 11:01:05 -0700 Subject: [PATCH] fix(@aws-amplify/auth): incorrect return type for Auth.resendSignUp --- .../amazon-cognito-identity-js/index.d.ts | 2 +- packages/auth/__tests__/auth-unit-test.ts | 68 +++++++++++++------ packages/auth/src/Auth.ts | 4 +- 3 files changed, 49 insertions(+), 25 deletions(-) diff --git a/packages/amazon-cognito-identity-js/index.d.ts b/packages/amazon-cognito-identity-js/index.d.ts index 3455ddd929e..74dd1f834bd 100644 --- a/packages/amazon-cognito-identity-js/index.d.ts +++ b/packages/amazon-cognito-identity-js/index.d.ts @@ -98,7 +98,7 @@ declare module 'amazon-cognito-identity-js' { callback: IAuthenticationCallback ): void; public resendConfirmationCode( - callback: NodeCallback, + callback: NodeCallback, clientMetaData?: ClientMetadata ): void; public changePassword( diff --git a/packages/auth/__tests__/auth-unit-test.ts b/packages/auth/__tests__/auth-unit-test.ts index fede44e7d79..72ab43cf9b6 100644 --- a/packages/auth/__tests__/auth-unit-test.ts +++ b/packages/auth/__tests__/auth-unit-test.ts @@ -133,7 +133,13 @@ jest.mock('amazon-cognito-identity-js/lib/CognitoUser', () => { }; CognitoUser.prototype.resendConfirmationCode = callback => { - callback(null, 'result'); + callback(null, { + CodeDeliveryDetails: { + AttributeName: 'email', + DeliveryMedium: 'EMAIL', + Destination: 'amplify@*****.com', + }, + }); }; CognitoUser.prototype.changePassword = ( @@ -500,11 +506,14 @@ describe('auth unit test', () => { await auth.confirmSignUp('username', code); - expect( - await CognitoUser.prototype.confirmRegistration - ).toBeCalledWith(code, jasmine.any(Boolean), jasmine.any(Function), { - foo: 'bar', - }); + expect(await CognitoUser.prototype.confirmRegistration).toBeCalledWith( + code, + jasmine.any(Boolean), + jasmine.any(Function), + { + foo: 'bar', + } + ); spyon.mockClear(); }); @@ -517,11 +526,14 @@ describe('auth unit test', () => { clientMetadata: { custom: 'value' }, }); - expect( - await CognitoUser.prototype.confirmRegistration - ).toBeCalledWith(code, jasmine.any(Boolean), jasmine.any(Function), { - custom: 'value', - }); + expect(await CognitoUser.prototype.confirmRegistration).toBeCalledWith( + code, + jasmine.any(Boolean), + jasmine.any(Function), + { + custom: 'value', + } + ); spyon.mockClear(); }); @@ -594,7 +606,13 @@ describe('auth unit test', () => { const auth = new Auth(authOptions); expect.assertions(1); - expect(await auth.resendSignUp('username')).toBe('result'); + expect(await auth.resendSignUp('username')).toMatchObject({ + CodeDeliveryDetails: { + AttributeName: 'email', + DeliveryMedium: 'EMAIL', + Destination: 'amplify@*****.com', + }, + }); spyon.mockClear(); }); @@ -1996,11 +2014,14 @@ describe('auth unit test', () => { await auth.changePassword(user, oldPassword, newPassword); - expect( - await CognitoUser.prototype.changePassword - ).toBeCalledWith(oldPassword, newPassword, jasmine.any(Function), { - foo: 'bar', - }); + expect(await CognitoUser.prototype.changePassword).toBeCalledWith( + oldPassword, + newPassword, + jasmine.any(Function), + { + foo: 'bar', + } + ); spyon.mockClear(); }); @@ -2018,11 +2039,14 @@ describe('auth unit test', () => { custom: 'value', }); - expect( - await CognitoUser.prototype.changePassword - ).toBeCalledWith(oldPassword, newPassword, jasmine.any(Function), { - custom: 'value', - }); + expect(await CognitoUser.prototype.changePassword).toBeCalledWith( + oldPassword, + newPassword, + jasmine.any(Function), + { + custom: 'value', + } + ); spyon.mockClear(); }); }); diff --git a/packages/auth/src/Auth.ts b/packages/auth/src/Auth.ts index 9063daac808..86135e47854 100644 --- a/packages/auth/src/Auth.ts +++ b/packages/auth/src/Auth.ts @@ -388,12 +388,12 @@ export default class AuthClass { * Resend the verification code * @param {String} username - The username to be confirmed * @param {ClientMetadata} clientMetadata - Metadata to be passed to Cognito Lambda triggers - * @return - A promise resolves data if success + * @return - A promise resolves code delivery details if successful */ public resendSignUp( username: string, clientMetadata: ClientMetaData = this._config.clientMetadata - ): Promise { + ): Promise { if (!this.userPool) { return this.rejectNoUserPool(); }