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): incorrect return type for Auth.resendSignUp #5112

Merged
merged 8 commits into from
Aug 19, 2020
2 changes: 1 addition & 1 deletion packages/amazon-cognito-identity-js/index.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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
4 changes: 2 additions & 2 deletions packages/auth/src/Auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string> {
): Promise<any> {
Copy link
Contributor

Choose a reason for hiding this comment

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

It possible to re-use CodeDeliveryDetails here?

export interface CodeDeliveryDetails {
AttributeName: string;
DeliveryMedium: string;
Destination: string;
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@ericclemmons are we sure it always resolves to CodeDeliveryDetails? I wasn't positive so I chose any. The code builds fine with CodeDelieryDetails in there and I can push that if you'd like.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The branch with CodeDeliveryDetails is here:
https://github.com/mousedownmike/amplify-js/tree/resendsignup_codedeliverydetails

Happy to close this PR and start a new one or merge the change into this one. Whichever solution works best and whenever it works.

Cheers,
Mike

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm going to get this merged in once tests pass.

We'll do some more tests to confirm the payload shape, but for now this is a great step forward 👍

Copy link
Contributor

Choose a reason for hiding this comment

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

(I went ahead & opened #6561 for comparison)

if (!this.userPool) {
return this.rejectNoUserPool();
}
Expand Down