Skip to content

Commit

Permalink
Merge branch 'main' into patch-1
Browse files Browse the repository at this point in the history
  • Loading branch information
joesilveira authored Feb 21, 2023
2 parents a40ec8f + 4a9a71d commit c9787a6
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 13 deletions.
5 changes: 1 addition & 4 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1571,10 +1571,7 @@ releasable_branches: &releasable_branches
only:
- release
- main
- ui-components/main
- 1.0-stable
- geo/main
- in-app-messaging/main
- next

# List of test browsers that are always used in every E2E test. Tests that aren't expected to interact with browser APIs
# should use `minimal_browser_list` to keep test execution time low.
Expand Down
3 changes: 3 additions & 0 deletions lerna.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
"command": {
"run": {
"private": false
},
"bootstrap": {
"ignore": "@aws-amplify/xr"
}
}
}
2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@
"publish:next": "lerna publish --canary --force-publish \"*\" --yes --dist-tag=next --preid=next --exact --no-verify-access",
"publish:release": "lerna publish --conventional-commits --yes --message 'chore(release): Publish [ci skip]' --no-verify-access",
"publish:verdaccio": "lerna publish --no-push --canary minor --dist-tag=unstable --preid=unstable --exact --force-publish --yes --no-verify-access",
"publish:geo/main": "lerna publish --canary --force-publish \"*\" --yes --dist-tag=geo --preid=geo --exact --no-verify-access",
"publish:in-app-messaging/main": "lerna publish --canary --force-publish \"*\" --yes --dist-tag=in-app-messaging --preid=in-app-messaging --exact --no-verify-access",
"ts-coverage": "lerna run ts-coverage"
},
"husky": {
Expand Down
66 changes: 64 additions & 2 deletions packages/auth/__tests__/auth-unit-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ jest.mock('amazon-cognito-identity-js/lib/CognitoUserPool', () => {
CognitoUserPool.prototype.getCurrentUser = () => {
return {
username: 'username',
attributes: { email: '[email protected]' },
getSession: callback => {
// throw 3;
callback(null, {
Expand Down Expand Up @@ -1332,6 +1333,34 @@ describe('auth unit test', () => {
spyon.mockClear();
});

test('happy case attributes are appended', async () => {
const spyon = jest
.spyOn(CognitoUser.prototype, 'sendMFACode')
.mockImplementationOnce((code, callback) => {
callback.onSuccess(session);
});
const hubSpy = jest.spyOn(Hub, 'dispatch');
const auth = new Auth(authOptions);
const user = new CognitoUser({
Username: 'username',
Pool: userPool,
});
const expectedUser = Object.assign(user, { email: '[email protected]' });
const result = await auth.confirmSignIn(user, 'code', null);
expect(result.attributes.email).toEqual('[email protected]');
expect(hubSpy).toHaveBeenCalledWith(
'auth',
{
data: expectedUser,
event: 'signIn',
message: 'A user username has been signed in',
},
'Auth',
Symbol.for('amplify_default')
);
spyon.mockClear();
});

test('happy case clientMetadata default', async () => {
const spyon = jest.spyOn(CognitoUser.prototype, 'sendMFACode');
const auth = new Auth(authOptionsWithClientMetadata);
Expand Down Expand Up @@ -1378,6 +1407,39 @@ describe('auth unit test', () => {
spyon.mockClear();
});

test('currentUserPoolUser fails but hub event still dispatches', async () => {
const auth = new Auth(authOptions);
const spyon = jest
.spyOn(CognitoUser.prototype, 'sendMFACode')
.mockImplementationOnce((code, callback) => {
callback.onSuccess(session);
});

const spyon2 = jest
.spyOn(auth, 'currentUserPoolUser')
.mockImplementationOnce(() => {
return Promise.reject('Could not get current user.');
});
const hubSpy = jest.spyOn(Hub, 'dispatch');
const user = new CognitoUser({
Username: 'username',
Pool: userPool,
});
const result = await auth.confirmSignIn(user, 'code', null);
expect(result).toEqual(user);
expect(hubSpy).toHaveBeenCalledWith(
'auth',
{
data: user,
event: 'signIn',
message: 'A user username has been signed in',
},
'Auth',
Symbol.for('amplify_default')
);
spyon.mockClear();
});

test('onFailure', async () => {
const spyon = jest
.spyOn(CognitoUser.prototype, 'sendMFACode')
Expand Down Expand Up @@ -3031,7 +3093,7 @@ describe('auth unit test', () => {
} catch (e) {
expect(e).toEqual(new Error('Error'));
}

spyon.mockClear();
});

Expand All @@ -3050,7 +3112,7 @@ describe('auth unit test', () => {
const spyon = jest.spyOn(CognitoUser.prototype, 'updateAttributes')
.mockImplementationOnce((attrs, callback: any) => {
callback(null, 'SUCCESS', codeDeliverDetailsResult);
});
});
const auth = new Auth(authOptions);

const user = new CognitoUser({
Expand Down
12 changes: 8 additions & 4 deletions packages/auth/src/Auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1183,7 +1183,12 @@ export class AuthClass {
logger.debug('cannot get cognito credentials', e);
} finally {
that.user = user;

try {
const currentUser = await this.currentUserPoolUser();
user.attributes = currentUser.attributes;
} catch (e) {
logger.debug('cannot get updated Cognito User', e);
}
dispatchAuthEvent(
'signIn',
user,
Expand Down Expand Up @@ -1428,7 +1433,6 @@ export class AuthClass {
user.updateAttributes(
attributeList,
(err, result, details) => {

if (err) {
dispatchAuthEvent('updateUserAttributes_failure', err, 'Failed to update attributes');
return reject(err);
Expand All @@ -1447,8 +1451,8 @@ export class AuthClass {
}

private createUpdateAttributesResultList(
attributes: Record<string, string>,
codeDeliveryDetailsList?: CodeDeliveryDetails []
attributes: Record<string, string>,
codeDeliveryDetailsList?: CodeDeliveryDetails[]
): Record<string, string> {
const attrs = {};
Object.keys(attributes).forEach(key => {
Expand Down
2 changes: 1 addition & 1 deletion packages/aws-amplify/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
"@aws-amplify/predictions": "5.0.15",
"@aws-amplify/pubsub": "5.0.15",
"@aws-amplify/storage": "5.1.5",
"@aws-amplify/xr": "4.0.15",
"@aws-amplify/xr": "latest",
"tslib": "^2.0.0"
},
"jest": {
Expand Down
1 change: 1 addition & 0 deletions packages/xr/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"name": "@aws-amplify/xr",
"version": "4.0.15",
"private": true,
"description": "XR category of aws-amplify",
"main": "./lib/index.js",
"module": "./lib-esm/index.js",
Expand Down

0 comments on commit c9787a6

Please sign in to comment.