From 15dca4a3b84a2132c3f0f6465b8a4ad41959a804 Mon Sep 17 00:00:00 2001 From: Damian Fortuna Date: Thu, 10 Aug 2017 16:45:39 -0300 Subject: [PATCH] Fix enrollment:complete event in polling mode --- CHANGELOG.md | 6 ++++++ lib/utils/polling_client.js | 3 ++- package.json | 2 +- test/utils/polling_client.test.js | 34 +++++++++++++++++++++---------- 4 files changed, 32 insertions(+), 13 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 305f69f..68a7ff9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -45,3 +45,9 @@ **Fix** - Bump dependencies versions (no breaking changes) [\#37](https://github.com/auth0/auth0-guardian.js/pull/37) ([dafortune](https://github.com/dafortune)). + +# [v1.2.1](https://github.com/auth0/auth0-guardian.js/tree/v1.1.1) (2017-06-13) +[Full Changelog](https://github.com/auth0/auth0-guardian.js/compare/v1.2.1...v1.2.0) + +**Fix** +- Fix enrollment:complete event in polling mode [\#37](https://github.com/auth0/auth0-guardian.js/pull/38) ([dafortune](https://github.com/dafortune)). diff --git a/lib/utils/polling_client.js b/lib/utils/polling_client.js index bcca0b5..8338f09 100644 --- a/lib/utils/polling_client.js +++ b/lib/utils/polling_client.js @@ -184,7 +184,8 @@ pollingClient.prototype.emitEvents = function emitEvents(err, oldState, newState } if (oldState && oldState.state === 'pending' && - !oldState.enrollment && newState.enrollment) { + (!oldState.enrollment || oldState.enrollment.available_methods.length === 0) && + (newState.enrollment && newState.enrollment.available_methods.length > 0)) { self.hub.emit('enrollment:confirmed', object.toCamelKeys({ device_account: newState.enrollment, tx_id: newState.id diff --git a/package.json b/package.json index 0da3ba1..f3f47c5 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "auth0-guardian-js", - "version": "1.2.0", + "version": "1.2.1", "description": "Interface", "main": "index.js", "directories": { diff --git a/test/utils/polling_client.test.js b/test/utils/polling_client.test.js index 3900967..e3d1457 100644 --- a/test/utils/polling_client.test.js +++ b/test/utils/polling_client.test.js @@ -227,7 +227,8 @@ describe('utils/polling_client', function () { state: 'pending', enrollment: { id: 'dev_123', - test: 'test' + test: 'test', + available_methods: ['sms'] } }, events: [ @@ -235,6 +236,7 @@ describe('utils/polling_client', function () { name: 'enrollment:confirmed', payload: { deviceAccount: { + availableMethods: ['sms'], id: 'dev_123', test: 'test' }, @@ -257,7 +259,8 @@ describe('utils/polling_client', function () { state: 'accepted', enrollment: { id: 'dev_123', - test: 'test' + test: 'test', + available_methods: ['push'] }, token: '123.123.1234' }, @@ -267,7 +270,8 @@ describe('utils/polling_client', function () { payload: { deviceAccount: { id: 'dev_123', - test: 'test' + test: 'test', + availableMethods: ['push'] }, txId: 'tx_1234' } @@ -296,7 +300,8 @@ describe('utils/polling_client', function () { state: 'rejected', enrollment: { id: 'dev_123', - test: 'test' + test: 'test', + available_methods: ['totp'] } }, events: [ @@ -305,7 +310,8 @@ describe('utils/polling_client', function () { payload: { deviceAccount: { id: 'dev_123', - test: 'test' + test: 'test', + availableMethods: ['totp'] }, txId: 'tx_1234' } @@ -328,7 +334,8 @@ describe('utils/polling_client', function () { state: 'pending', enrollment: { id: 'dev_123', - test: 'test' + test: 'test', + available_methods: [] } }, transitionState: { @@ -336,7 +343,8 @@ describe('utils/polling_client', function () { state: 'rejected', enrollment: { id: 'dev_123', - test: 'test' + test: 'test', + available_methods: [] } }, events: [ @@ -358,7 +366,8 @@ describe('utils/polling_client', function () { state: 'pending', enrollment: { id: 'dev_123', - test: 'test' + test: 'test', + available_methods: [] } }, transitionState: { @@ -366,7 +375,8 @@ describe('utils/polling_client', function () { state: 'accepted', enrollment: { id: 'dev_123', - test: 'test' + test: 'test', + available_methods: [] }, token: '123.123.1234' }, @@ -395,7 +405,8 @@ describe('utils/polling_client', function () { state: 'accepted', enrollment: { id: 'dev_123', - test: 'test' + test: 'test', + available_methods: ['totp'] }, token: '123.123.1234' }, @@ -405,7 +416,8 @@ describe('utils/polling_client', function () { payload: { deviceAccount: { id: 'dev_123', - test: 'test' + test: 'test', + availableMethods: ['totp'] }, txId: 'tx_1234' }