Skip to content

Commit

Permalink
Minor cleanups
Browse files Browse the repository at this point in the history
1. Clean up getSession()
2. Allow defaults for the pool/client in case they aren't somehow
in the Cognito service.
  • Loading branch information
paulcwatts committed Jun 10, 2019
1 parent b15ee11 commit 1b59acc
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
6 changes: 4 additions & 2 deletions addon-test-support/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import { CognitoUser as AWSUser, CognitoUserPool } from 'amazon-cognito-identity
export function newUser(username) {
const { owner } = getContext();
const cognito = owner.lookup('service:cognito');
const { poolId, clientId } = getProperties(cognito, "poolId", "clientId");
const { poolId = 'us-east-1_TEST', clientId = 'TEST' } =
getProperties(cognito, "poolId", "clientId");
const pool = new CognitoUserPool({ UserPoolId: poolId, ClientId: clientId });
return new AWSUser({ Username: username, Pool: pool });
}
Expand All @@ -18,7 +19,8 @@ export function mockCognitoUser(userAttributes) {

const { username } = userAttributes;
const cognito = owner.lookup('service:cognito');
const { poolId, clientId } = getProperties(cognito, "poolId", "clientId");
const { poolId = 'us-east-1_TEST', clientId = 'TEST' } =
getProperties(cognito, "poolId", "clientId");
const pool = new CognitoUserPool({ UserPoolId: poolId, ClientId: clientId });
const user = new AWSUser({ Username: username, Pool: pool });
const auth = MockAuth.create({ _authenticatedUser: user });
Expand Down
6 changes: 1 addition & 5 deletions addon-test-support/utils/ember-cognito.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,7 @@ const MockUser = EmberObject.extend({
},

getSession() {
const session = this.get('session');
if (session) {
return resolve(session);
}
return resolve(newSession());
return resolve(this.get('session') || newSession());
},

getUserAttributes() {
Expand Down

0 comments on commit 1b59acc

Please sign in to comment.