Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(@aws-amplify/auth): CodeDeliveryDetails return type for Auth.resendSignUp #6561

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/amazon-cognito-identity-js/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ declare module 'amazon-cognito-identity-js' {
callback: IAuthenticationCallback
): void;
public resendConfirmationCode(
callback: NodeCallback<Error, 'SUCCESS'>,
callback: NodeCallback<Error, any>,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we be more specific with this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not without inspecting the payload:
https://github.com/aws-amplify/amplify-js/pull/5112/files#r396791471

Also, this PR can't successfully be updated to the latest branch via GitHub's GUI for some reason. We may be better off closing this in favor of: #5112.

(I was attempting to pull in the author's latest code, but unsuccessfully)

clientMetaData?: ClientMetadata
): void;
public changePassword(
Expand Down
68 changes: 46 additions & 22 deletions packages/auth/__tests__/auth-unit-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = (
Expand Down Expand Up @@ -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();
});

Expand All @@ -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();
});

Expand Down Expand Up @@ -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();
});
Expand Down Expand Up @@ -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();
});

Expand All @@ -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();
});
});
Expand Down
5 changes: 3 additions & 2 deletions packages/auth/src/Auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ import {
CognitoIdToken,
CognitoRefreshToken,
CognitoAccessToken,
CodeDeliveryDetails,
} from 'amazon-cognito-identity-js';

import { parse } from 'url';
Expand Down Expand Up @@ -388,12 +389,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 the CodeDeliveryDetails if successful
*/
public resendSignUp(
username: string,
clientMetadata: ClientMetaData = this._config.clientMetadata
): Promise<string> {
): Promise<CodeDeliveryDetails> {
if (!this.userPool) {
return this.rejectNoUserPool();
}
Expand Down