From 1b59acc3502bf944a716e2f72608da441c38863f Mon Sep 17 00:00:00 2001 From: Paul Watts Date: Mon, 10 Jun 2019 10:52:46 -0700 Subject: [PATCH] Minor cleanups 1. Clean up getSession() 2. Allow defaults for the pool/client in case they aren't somehow in the Cognito service. --- addon-test-support/index.js | 6 ++++-- addon-test-support/utils/ember-cognito.js | 6 +----- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/addon-test-support/index.js b/addon-test-support/index.js index 8091c02..164a417 100644 --- a/addon-test-support/index.js +++ b/addon-test-support/index.js @@ -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 }); } @@ -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 }); diff --git a/addon-test-support/utils/ember-cognito.js b/addon-test-support/utils/ember-cognito.js index 5e562eb..51ad672 100644 --- a/addon-test-support/utils/ember-cognito.js +++ b/addon-test-support/utils/ember-cognito.js @@ -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() {