@accounts/client
Advanced tools
Comparing version 0.0.7 to 0.0.8-alpha.840bab8d
@@ -205,10 +205,11 @@ 'use strict'; | ||
case 0: | ||
_context5.next = 2; | ||
this.store.dispatch((0, _module.clearTokens)()); | ||
_context5.next = 3; | ||
return this.removeStorageData(getTokenKey(ACCESS_TOKEN, this.options)); | ||
case 2: | ||
_context5.next = 4; | ||
case 3: | ||
_context5.next = 5; | ||
return this.removeStorageData(getTokenKey(REFRESH_TOKEN, this.options)); | ||
case 4: | ||
case 5: | ||
case 'end': | ||
@@ -301,3 +302,3 @@ return _context5.stop(); | ||
if (!(accessToken && refreshToken)) { | ||
_context7.next = 29; | ||
_context7.next = 30; | ||
break; | ||
@@ -318,3 +319,3 @@ } | ||
this.clearUser(); | ||
_context7.next = 20; | ||
_context7.next = 21; | ||
break; | ||
@@ -332,10 +333,11 @@ | ||
case 19: | ||
this.store.dispatch((0, _module.setTokens)(refreshedSession.tokens)); | ||
this.store.dispatch((0, _module.setUser)(refreshedSession.user)); | ||
case 20: | ||
_context7.next = 27; | ||
case 21: | ||
_context7.next = 28; | ||
break; | ||
case 22: | ||
_context7.prev = 22; | ||
case 23: | ||
_context7.prev = 23; | ||
_context7.t0 = _context7['catch'](6); | ||
@@ -347,7 +349,7 @@ | ||
case 27: | ||
_context7.next = 32; | ||
case 28: | ||
_context7.next = 33; | ||
break; | ||
case 29: | ||
case 30: | ||
this.clearTokens(); | ||
@@ -357,3 +359,3 @@ this.clearUser(); | ||
case 32: | ||
case 33: | ||
case 'end': | ||
@@ -363,3 +365,3 @@ return _context7.stop(); | ||
} | ||
}, _callee7, this, [[6, 22]]); | ||
}, _callee7, this, [[6, 23]]); | ||
})); | ||
@@ -482,6 +484,9 @@ | ||
res = _context9.sent; | ||
_context9.next = 11; | ||
this.store.dispatch((0, _module.loggingIn)(false)); | ||
_context9.next = 12; | ||
return this.storeTokens(res); | ||
case 11: | ||
case 12: | ||
this.store.dispatch((0, _module.setTokens)(res.tokens)); | ||
this.store.dispatch((0, _module.setUser)(res.user)); | ||
@@ -492,9 +497,10 @@ this.options.onSignedInHook(); | ||
} | ||
_context9.next = 20; | ||
_context9.next = 23; | ||
break; | ||
case 16: | ||
_context9.prev = 16; | ||
case 18: | ||
_context9.prev = 18; | ||
_context9.t0 = _context9['catch'](5); | ||
this.store.dispatch((0, _module.loggingIn)(false)); | ||
if (callback && (0, _lodash.isFunction)(callback)) { | ||
@@ -505,6 +511,3 @@ callback(_context9.t0); | ||
case 20: | ||
this.store.dispatch((0, _module.loggingIn)(false), user); | ||
case 21: | ||
case 23: | ||
case 'end': | ||
@@ -514,3 +517,3 @@ return _context9.stop(); | ||
} | ||
}, _callee9, this, [[5, 16]]); | ||
}, _callee9, this, [[5, 18]]); | ||
})); | ||
@@ -594,2 +597,142 @@ | ||
}() | ||
}, { | ||
key: 'verifyEmail', | ||
value: function () { | ||
var _ref13 = _asyncToGenerator(regeneratorRuntime.mark(function _callee11(token) { | ||
return regeneratorRuntime.wrap(function _callee11$(_context11) { | ||
while (1) { | ||
switch (_context11.prev = _context11.next) { | ||
case 0: | ||
_context11.prev = 0; | ||
_context11.next = 3; | ||
return this.transport.verifyEmail(token); | ||
case 3: | ||
_context11.next = 8; | ||
break; | ||
case 5: | ||
_context11.prev = 5; | ||
_context11.t0 = _context11['catch'](0); | ||
throw new _common.AccountsError(_context11.t0.message); | ||
case 8: | ||
case 'end': | ||
return _context11.stop(); | ||
} | ||
} | ||
}, _callee11, this, [[0, 5]]); | ||
})); | ||
function verifyEmail(_x12) { | ||
return _ref13.apply(this, arguments); | ||
} | ||
return verifyEmail; | ||
}() | ||
}, { | ||
key: 'resetPassword', | ||
value: function () { | ||
var _ref14 = _asyncToGenerator(regeneratorRuntime.mark(function _callee12(token, newPassword) { | ||
return regeneratorRuntime.wrap(function _callee12$(_context12) { | ||
while (1) { | ||
switch (_context12.prev = _context12.next) { | ||
case 0: | ||
_context12.prev = 0; | ||
_context12.next = 3; | ||
return this.transport.resetPassword(token, newPassword); | ||
case 3: | ||
_context12.next = 8; | ||
break; | ||
case 5: | ||
_context12.prev = 5; | ||
_context12.t0 = _context12['catch'](0); | ||
throw new _common.AccountsError(_context12.t0.message); | ||
case 8: | ||
case 'end': | ||
return _context12.stop(); | ||
} | ||
} | ||
}, _callee12, this, [[0, 5]]); | ||
})); | ||
function resetPassword(_x13, _x14) { | ||
return _ref14.apply(this, arguments); | ||
} | ||
return resetPassword; | ||
}() | ||
}, { | ||
key: 'requestPasswordReset', | ||
value: function () { | ||
var _ref15 = _asyncToGenerator(regeneratorRuntime.mark(function _callee13(email) { | ||
return regeneratorRuntime.wrap(function _callee13$(_context13) { | ||
while (1) { | ||
switch (_context13.prev = _context13.next) { | ||
case 0: | ||
_context13.prev = 0; | ||
_context13.next = 3; | ||
return this.transport.sendResetPasswordEmail(email); | ||
case 3: | ||
_context13.next = 8; | ||
break; | ||
case 5: | ||
_context13.prev = 5; | ||
_context13.t0 = _context13['catch'](0); | ||
throw new _common.AccountsError(_context13.t0.message); | ||
case 8: | ||
case 'end': | ||
return _context13.stop(); | ||
} | ||
} | ||
}, _callee13, this, [[0, 5]]); | ||
})); | ||
function requestPasswordReset(_x15) { | ||
return _ref15.apply(this, arguments); | ||
} | ||
return requestPasswordReset; | ||
}() | ||
}, { | ||
key: 'requestVerificationEmail', | ||
value: function () { | ||
var _ref16 = _asyncToGenerator(regeneratorRuntime.mark(function _callee14(email) { | ||
return regeneratorRuntime.wrap(function _callee14$(_context14) { | ||
while (1) { | ||
switch (_context14.prev = _context14.next) { | ||
case 0: | ||
_context14.prev = 0; | ||
_context14.next = 3; | ||
return this.transport.sendVerificationEmail(email); | ||
case 3: | ||
_context14.next = 8; | ||
break; | ||
case 5: | ||
_context14.prev = 5; | ||
_context14.t0 = _context14['catch'](0); | ||
throw new _common.AccountsError(_context14.t0.message); | ||
case 8: | ||
case 'end': | ||
return _context14.stop(); | ||
} | ||
} | ||
}, _callee14, this, [[0, 5]]); | ||
})); | ||
function requestVerificationEmail(_x16) { | ||
return _ref16.apply(this, arguments); | ||
} | ||
return requestVerificationEmail; | ||
}() | ||
}]); | ||
@@ -635,2 +778,14 @@ | ||
return this.instance.refreshSession(); | ||
}, | ||
verifyEmail: function verifyEmail(token) { | ||
return this.instance.verifyEmail(token); | ||
}, | ||
resetPassword: function resetPassword(token, newPassword) { | ||
return this.instance.resetPassword(token, newPassword); | ||
}, | ||
requestPasswordReset: function requestPasswordReset(email) { | ||
return this.instance.requestPasswordReset(email); | ||
}, | ||
requestVerificationEmail: function requestVerificationEmail(email) { | ||
return this.instance.requestVerificationEmail(email); | ||
} | ||
@@ -637,0 +792,0 @@ }; |
@@ -434,4 +434,5 @@ 'use strict'; | ||
expect(callback.mock.calls.length).toEqual(1); | ||
expect(_AccountsClient2.default.loggingIn()).toBe(false); | ||
case 6: | ||
case 7: | ||
case 'end': | ||
@@ -507,3 +508,3 @@ return _context11.stop(); | ||
}))); | ||
it('stores tokens in local storage', _asyncToGenerator(regeneratorRuntime.mark(function _callee14() { | ||
it('sets loggingIn flag to false on failed login', _asyncToGenerator(regeneratorRuntime.mark(function _callee14() { | ||
var transport; | ||
@@ -516,2 +517,35 @@ return regeneratorRuntime.wrap(function _callee14$(_context14) { | ||
loginWithPassword: function loginWithPassword() { | ||
return Promise.reject('error'); | ||
} | ||
}; | ||
_AccountsClient2.default.config({ history: history }, transport); | ||
_context14.prev = 2; | ||
_context14.next = 5; | ||
return _AccountsClient2.default.loginWithPassword('username', 'password'); | ||
case 5: | ||
throw new Error(); | ||
case 8: | ||
_context14.prev = 8; | ||
_context14.t0 = _context14['catch'](2); | ||
expect(_AccountsClient2.default.loggingIn()).toBe(false); | ||
case 11: | ||
case 'end': | ||
return _context14.stop(); | ||
} | ||
} | ||
}, _callee14, undefined, [[2, 8]]); | ||
}))); | ||
it('stores tokens in local storage', _asyncToGenerator(regeneratorRuntime.mark(function _callee15() { | ||
var transport; | ||
return regeneratorRuntime.wrap(function _callee15$(_context15) { | ||
while (1) { | ||
switch (_context15.prev = _context15.next) { | ||
case 0: | ||
transport = { | ||
loginWithPassword: function loginWithPassword() { | ||
return Promise.resolve(loggedInUser); | ||
@@ -522,3 +556,3 @@ } | ||
_AccountsClient2.default.config({ history: history }, transport); | ||
_context14.next = 4; | ||
_context15.next = 4; | ||
return _AccountsClient2.default.loginWithPassword('username', 'password'); | ||
@@ -532,13 +566,13 @@ | ||
case 'end': | ||
return _context14.stop(); | ||
return _context15.stop(); | ||
} | ||
} | ||
}, _callee14, undefined); | ||
}, _callee15, undefined); | ||
}))); | ||
it('fetch tokens from storage when storage is async', _asyncToGenerator(regeneratorRuntime.mark(function _callee15() { | ||
it('fetch tokens from storage when storage is async', _asyncToGenerator(regeneratorRuntime.mark(function _callee16() { | ||
var transport, tokens; | ||
return regeneratorRuntime.wrap(function _callee15$(_context15) { | ||
return regeneratorRuntime.wrap(function _callee16$(_context16) { | ||
while (1) { | ||
switch (_context15.prev = _context15.next) { | ||
switch (_context16.prev = _context16.next) { | ||
case 0: | ||
@@ -561,7 +595,7 @@ transport = { | ||
_context15.next = 4; | ||
_context16.next = 4; | ||
return _AccountsClient2.default.tokens(); | ||
case 4: | ||
tokens = _context15.sent; | ||
tokens = _context16.sent; | ||
@@ -573,13 +607,13 @@ expect(tokens.accessToken).toBe('testValue'); | ||
case 'end': | ||
return _context15.stop(); | ||
return _context16.stop(); | ||
} | ||
} | ||
}, _callee15, undefined); | ||
}, _callee16, undefined); | ||
}))); | ||
it('fetch tokens from storage when storage is sync', _asyncToGenerator(regeneratorRuntime.mark(function _callee16() { | ||
it('fetch tokens from storage when storage is sync', _asyncToGenerator(regeneratorRuntime.mark(function _callee17() { | ||
var transport, tokens; | ||
return regeneratorRuntime.wrap(function _callee16$(_context16) { | ||
return regeneratorRuntime.wrap(function _callee17$(_context17) { | ||
while (1) { | ||
switch (_context16.prev = _context16.next) { | ||
switch (_context17.prev = _context17.next) { | ||
case 0: | ||
@@ -602,7 +636,7 @@ transport = { | ||
_context16.next = 4; | ||
_context17.next = 4; | ||
return _AccountsClient2.default.tokens(); | ||
case 4: | ||
tokens = _context16.sent; | ||
tokens = _context17.sent; | ||
@@ -614,13 +648,13 @@ expect(tokens.accessToken).toBe('testValue'); | ||
case 'end': | ||
return _context16.stop(); | ||
return _context17.stop(); | ||
} | ||
} | ||
}, _callee16, undefined); | ||
}, _callee17, undefined); | ||
}))); | ||
it('stores user in redux', _asyncToGenerator(regeneratorRuntime.mark(function _callee17() { | ||
it('stores user in redux', _asyncToGenerator(regeneratorRuntime.mark(function _callee18() { | ||
var transport; | ||
return regeneratorRuntime.wrap(function _callee17$(_context17) { | ||
return regeneratorRuntime.wrap(function _callee18$(_context18) { | ||
while (1) { | ||
switch (_context17.prev = _context17.next) { | ||
switch (_context18.prev = _context18.next) { | ||
case 0: | ||
@@ -634,3 +668,3 @@ transport = { | ||
_AccountsClient2.default.config({ history: history }, transport); | ||
_context17.next = 4; | ||
_context18.next = 4; | ||
return _AccountsClient2.default.loginWithPassword('username', 'password'); | ||
@@ -643,14 +677,40 @@ | ||
case 'end': | ||
return _context17.stop(); | ||
return _context18.stop(); | ||
} | ||
} | ||
}, _callee17, undefined); | ||
}, _callee18, undefined); | ||
}))); | ||
it('stores tokens in redux', _asyncToGenerator(regeneratorRuntime.mark(function _callee19() { | ||
var transport; | ||
return regeneratorRuntime.wrap(function _callee19$(_context19) { | ||
while (1) { | ||
switch (_context19.prev = _context19.next) { | ||
case 0: | ||
transport = { | ||
loginWithPassword: function loginWithPassword() { | ||
return Promise.resolve(loggedInUser); | ||
} | ||
}; | ||
_AccountsClient2.default.config({ history: history }, transport); | ||
_context19.next = 4; | ||
return _AccountsClient2.default.loginWithPassword('username', 'password'); | ||
case 4: | ||
expect(_AccountsClient2.default.instance.getState().get('tokens')).toEqual((0, _immutable.Map)(_extends({}, loggedInUser.tokens))); | ||
case 5: | ||
case 'end': | ||
return _context19.stop(); | ||
} | ||
} | ||
}, _callee19, undefined); | ||
}))); | ||
}); | ||
describe('logout', function () { | ||
it('calls callback on successful logout', _asyncToGenerator(regeneratorRuntime.mark(function _callee18() { | ||
it('calls callback on successful logout', _asyncToGenerator(regeneratorRuntime.mark(function _callee20() { | ||
var transport, callback; | ||
return regeneratorRuntime.wrap(function _callee18$(_context18) { | ||
return regeneratorRuntime.wrap(function _callee20$(_context20) { | ||
while (1) { | ||
switch (_context18.prev = _context18.next) { | ||
switch (_context20.prev = _context20.next) { | ||
case 0: | ||
@@ -665,3 +725,3 @@ transport = { | ||
callback = jest.fn(); | ||
_context18.next = 5; | ||
_context20.next = 5; | ||
return _AccountsClient2.default.logout(callback); | ||
@@ -674,12 +734,12 @@ | ||
case 'end': | ||
return _context18.stop(); | ||
return _context20.stop(); | ||
} | ||
} | ||
}, _callee18, undefined); | ||
}, _callee20, undefined); | ||
}))); | ||
it('calls onLogout on successful logout', _asyncToGenerator(regeneratorRuntime.mark(function _callee19() { | ||
it('calls onLogout on successful logout', _asyncToGenerator(regeneratorRuntime.mark(function _callee21() { | ||
var onSignedOutHook, transport; | ||
return regeneratorRuntime.wrap(function _callee19$(_context19) { | ||
return regeneratorRuntime.wrap(function _callee21$(_context21) { | ||
while (1) { | ||
switch (_context19.prev = _context19.next) { | ||
switch (_context21.prev = _context21.next) { | ||
case 0: | ||
@@ -694,3 +754,3 @@ onSignedOutHook = jest.fn(); | ||
_AccountsClient2.default.config({ history: history, onSignedOutHook: onSignedOutHook }, transport); | ||
_context19.next = 5; | ||
_context21.next = 5; | ||
return _AccountsClient2.default.logout(); | ||
@@ -703,13 +763,13 @@ | ||
case 'end': | ||
return _context19.stop(); | ||
return _context21.stop(); | ||
} | ||
} | ||
}, _callee19, undefined); | ||
}, _callee21, undefined); | ||
}))); | ||
it('calls callback on failure with error message', _asyncToGenerator(regeneratorRuntime.mark(function _callee20() { | ||
it('calls callback on failure with error message', _asyncToGenerator(regeneratorRuntime.mark(function _callee22() { | ||
var transport, callback; | ||
return regeneratorRuntime.wrap(function _callee20$(_context20) { | ||
return regeneratorRuntime.wrap(function _callee22$(_context22) { | ||
while (1) { | ||
switch (_context20.prev = _context20.next) { | ||
switch (_context22.prev = _context22.next) { | ||
case 0: | ||
@@ -725,4 +785,4 @@ transport = { | ||
callback = jest.fn(); | ||
_context20.prev = 4; | ||
_context20.next = 7; | ||
_context22.prev = 4; | ||
_context22.next = 7; | ||
return _AccountsClient2.default.logout(callback); | ||
@@ -734,6 +794,6 @@ | ||
case 10: | ||
_context20.prev = 10; | ||
_context20.t0 = _context20['catch'](4); | ||
_context22.prev = 10; | ||
_context22.t0 = _context22['catch'](4); | ||
expect(_context20.t0.message).toEqual('error message'); | ||
expect(_context22.t0.message).toEqual('error message'); | ||
expect(callback.mock.calls.length).toEqual(1); | ||
@@ -744,18 +804,89 @@ expect(callback.mock.calls[0][0]).toEqual({ message: 'error message' }); | ||
case 'end': | ||
return _context20.stop(); | ||
return _context22.stop(); | ||
} | ||
} | ||
}, _callee20, undefined, [[4, 10]]); | ||
}, _callee22, undefined, [[4, 10]]); | ||
}))); | ||
it('clear tokens in redux', _asyncToGenerator(regeneratorRuntime.mark(function _callee23() { | ||
var transport, callback; | ||
return regeneratorRuntime.wrap(function _callee23$(_context23) { | ||
while (1) { | ||
switch (_context23.prev = _context23.next) { | ||
case 0: | ||
transport = { | ||
logout: function logout() { | ||
return Promise.reject({ message: 'error message' }); | ||
} | ||
}; | ||
_AccountsClient2.default.instance.storeTokens({ tokens: { accessToken: '1' } }); | ||
_AccountsClient2.default.config({ history: history }, transport); | ||
callback = jest.fn(); | ||
_context23.prev = 4; | ||
_context23.next = 7; | ||
return _AccountsClient2.default.logout(callback); | ||
case 7: | ||
throw new Error(); | ||
case 10: | ||
_context23.prev = 10; | ||
_context23.t0 = _context23['catch'](4); | ||
expect(_AccountsClient2.default.instance.getState().get('tokens')).toEqual(null); | ||
case 13: | ||
case 'end': | ||
return _context23.stop(); | ||
} | ||
} | ||
}, _callee23, undefined, [[4, 10]]); | ||
}))); | ||
it('clear user in redux', _asyncToGenerator(regeneratorRuntime.mark(function _callee24() { | ||
var transport, callback; | ||
return regeneratorRuntime.wrap(function _callee24$(_context24) { | ||
while (1) { | ||
switch (_context24.prev = _context24.next) { | ||
case 0: | ||
transport = { | ||
logout: function logout() { | ||
return Promise.reject({ message: 'error message' }); | ||
} | ||
}; | ||
_AccountsClient2.default.instance.storeTokens({ tokens: { accessToken: '1' } }); | ||
_AccountsClient2.default.config({ history: history }, transport); | ||
callback = jest.fn(); | ||
_context24.prev = 4; | ||
_context24.next = 7; | ||
return _AccountsClient2.default.logout(callback); | ||
case 7: | ||
throw new Error(); | ||
case 10: | ||
_context24.prev = 10; | ||
_context24.t0 = _context24['catch'](4); | ||
expect(_AccountsClient2.default.instance.getState().get('user')).toEqual(null); | ||
case 13: | ||
case 'end': | ||
return _context24.stop(); | ||
} | ||
} | ||
}, _callee24, undefined, [[4, 10]]); | ||
}))); | ||
}); | ||
describe('refreshSession', _asyncToGenerator(regeneratorRuntime.mark(function _callee23() { | ||
return regeneratorRuntime.wrap(function _callee23$(_context23) { | ||
describe('refreshSession', _asyncToGenerator(regeneratorRuntime.mark(function _callee27() { | ||
return regeneratorRuntime.wrap(function _callee27$(_context27) { | ||
while (1) { | ||
switch (_context23.prev = _context23.next) { | ||
switch (_context27.prev = _context27.next) { | ||
case 0: | ||
// TODO test that user and tokens are cleared if refreshToken is expired | ||
it('clears tokens and user if tokens are not set', _asyncToGenerator(regeneratorRuntime.mark(function _callee21() { | ||
return regeneratorRuntime.wrap(function _callee21$(_context21) { | ||
it('clears tokens and user if tokens are not set', _asyncToGenerator(regeneratorRuntime.mark(function _callee25() { | ||
return regeneratorRuntime.wrap(function _callee25$(_context25) { | ||
while (1) { | ||
switch (_context21.prev = _context21.next) { | ||
switch (_context25.prev = _context25.next) { | ||
case 0: | ||
@@ -769,15 +900,15 @@ _AccountsClient2.default.config({}, {}); | ||
}); | ||
_context21.prev = 3; | ||
_context21.next = 6; | ||
_context25.prev = 3; | ||
_context25.next = 6; | ||
return _AccountsClient2.default.refreshSession(); | ||
case 6: | ||
_context21.next = 13; | ||
_context25.next = 13; | ||
break; | ||
case 8: | ||
_context21.prev = 8; | ||
_context21.t0 = _context21['catch'](3); | ||
_context25.prev = 8; | ||
_context25.t0 = _context25['catch'](3); | ||
expect(_context21.t0.message).toEqual('no tokens provided'); | ||
expect(_context25.t0.message).toEqual('no tokens provided'); | ||
expect(_AccountsClient2.default.instance.clearTokens.mock.calls.length).toEqual(1); | ||
@@ -788,12 +919,12 @@ expect(_AccountsClient2.default.instance.clearUser.mock.calls.length).toEqual(1); | ||
case 'end': | ||
return _context21.stop(); | ||
return _context25.stop(); | ||
} | ||
} | ||
}, _callee21, undefined, [[3, 8]]); | ||
}, _callee25, undefined, [[3, 8]]); | ||
}))); | ||
it('clears tokens, users and throws error if bad refresh token provided', _asyncToGenerator(regeneratorRuntime.mark(function _callee22() { | ||
it('clears tokens, users and throws error if bad refresh token provided', _asyncToGenerator(regeneratorRuntime.mark(function _callee26() { | ||
var message; | ||
return regeneratorRuntime.wrap(function _callee22$(_context22) { | ||
return regeneratorRuntime.wrap(function _callee26$(_context26) { | ||
while (1) { | ||
switch (_context22.prev = _context22.next) { | ||
switch (_context26.prev = _context26.next) { | ||
case 0: | ||
@@ -809,4 +940,4 @@ _AccountsClient2.default.config({}, {}); | ||
}); | ||
_context22.prev = 5; | ||
_context22.next = 8; | ||
_context26.prev = 5; | ||
_context26.next = 8; | ||
return _AccountsClient2.default.refreshSession(); | ||
@@ -818,5 +949,5 @@ | ||
case 11: | ||
_context22.prev = 11; | ||
_context22.t0 = _context22['catch'](5); | ||
message = _context22.t0.message; | ||
_context26.prev = 11; | ||
_context26.t0 = _context26['catch'](5); | ||
message = _context26.t0.message; | ||
@@ -827,6 +958,6 @@ expect(message).toEqual('falsy token provided'); | ||
case 'end': | ||
return _context22.stop(); | ||
return _context26.stop(); | ||
} | ||
} | ||
}, _callee22, undefined, [[5, 11]]); | ||
}, _callee26, undefined, [[5, 11]]); | ||
}))); | ||
@@ -870,7 +1001,248 @@ // it('requests a new token pair, sets the tokens and the user', async () => { | ||
case 'end': | ||
return _context23.stop(); | ||
return _context27.stop(); | ||
} | ||
} | ||
}, _callee23, undefined); | ||
}, _callee27, undefined); | ||
}))); | ||
describe('verifyEmail', function () { | ||
it('should return an AccountsError', _asyncToGenerator(regeneratorRuntime.mark(function _callee28() { | ||
var error; | ||
return regeneratorRuntime.wrap(function _callee28$(_context28) { | ||
while (1) { | ||
switch (_context28.prev = _context28.next) { | ||
case 0: | ||
error = 'something bad'; | ||
_AccountsClient2.default.config({}, { verifyEmail: function verifyEmail() { | ||
return Promise.reject({ message: error }); | ||
} }); | ||
_context28.prev = 2; | ||
_context28.next = 5; | ||
return _AccountsClient2.default.verifyEmail(); | ||
case 5: | ||
throw new Error(); | ||
case 8: | ||
_context28.prev = 8; | ||
_context28.t0 = _context28['catch'](2); | ||
expect(_context28.t0.message).toEqual(error); | ||
case 11: | ||
case 'end': | ||
return _context28.stop(); | ||
} | ||
} | ||
}, _callee28, undefined, [[2, 8]]); | ||
}))); | ||
it('should call transport.verifyEmail', _asyncToGenerator(regeneratorRuntime.mark(function _callee29() { | ||
var mock; | ||
return regeneratorRuntime.wrap(function _callee29$(_context29) { | ||
while (1) { | ||
switch (_context29.prev = _context29.next) { | ||
case 0: | ||
mock = jest.fn(function () { | ||
return Promise.resolve(); | ||
}); | ||
_AccountsClient2.default.config({}, { verifyEmail: mock }); | ||
_context29.next = 4; | ||
return _AccountsClient2.default.verifyEmail('token'); | ||
case 4: | ||
expect(mock.mock.calls.length).toEqual(1); | ||
expect(mock.mock.calls[0][0]).toEqual('token'); | ||
case 6: | ||
case 'end': | ||
return _context29.stop(); | ||
} | ||
} | ||
}, _callee29, undefined); | ||
}))); | ||
}); | ||
describe('resetPassword', function () { | ||
it('should return an AccountsError', _asyncToGenerator(regeneratorRuntime.mark(function _callee30() { | ||
var error; | ||
return regeneratorRuntime.wrap(function _callee30$(_context30) { | ||
while (1) { | ||
switch (_context30.prev = _context30.next) { | ||
case 0: | ||
error = 'something bad'; | ||
_AccountsClient2.default.config({}, { resetPassword: function resetPassword() { | ||
return Promise.reject({ message: error }); | ||
} }); | ||
_context30.prev = 2; | ||
_context30.next = 5; | ||
return _AccountsClient2.default.resetPassword(); | ||
case 5: | ||
throw new Error(); | ||
case 8: | ||
_context30.prev = 8; | ||
_context30.t0 = _context30['catch'](2); | ||
expect(_context30.t0.message).toEqual(error); | ||
case 11: | ||
case 'end': | ||
return _context30.stop(); | ||
} | ||
} | ||
}, _callee30, undefined, [[2, 8]]); | ||
}))); | ||
it('should call transport.resetPassword', _asyncToGenerator(regeneratorRuntime.mark(function _callee31() { | ||
var mock; | ||
return regeneratorRuntime.wrap(function _callee31$(_context31) { | ||
while (1) { | ||
switch (_context31.prev = _context31.next) { | ||
case 0: | ||
mock = jest.fn(function () { | ||
return Promise.resolve(); | ||
}); | ||
_AccountsClient2.default.config({}, { resetPassword: mock }); | ||
_context31.next = 4; | ||
return _AccountsClient2.default.resetPassword('token', 'newPassword'); | ||
case 4: | ||
expect(mock.mock.calls.length).toEqual(1); | ||
expect(mock.mock.calls[0][0]).toEqual('token'); | ||
expect(mock.mock.calls[0][1]).toEqual('newPassword'); | ||
case 7: | ||
case 'end': | ||
return _context31.stop(); | ||
} | ||
} | ||
}, _callee31, undefined); | ||
}))); | ||
}); | ||
describe('requestPasswordReset', function () { | ||
it('should return an AccountsError', _asyncToGenerator(regeneratorRuntime.mark(function _callee32() { | ||
var error; | ||
return regeneratorRuntime.wrap(function _callee32$(_context32) { | ||
while (1) { | ||
switch (_context32.prev = _context32.next) { | ||
case 0: | ||
error = 'something bad'; | ||
_AccountsClient2.default.config({}, { sendResetPasswordEmail: function sendResetPasswordEmail() { | ||
return Promise.reject({ message: error }); | ||
} }); | ||
_context32.prev = 2; | ||
_context32.next = 5; | ||
return _AccountsClient2.default.requestPasswordReset(); | ||
case 5: | ||
throw new Error(); | ||
case 8: | ||
_context32.prev = 8; | ||
_context32.t0 = _context32['catch'](2); | ||
expect(_context32.t0.message).toEqual(error); | ||
case 11: | ||
case 'end': | ||
return _context32.stop(); | ||
} | ||
} | ||
}, _callee32, undefined, [[2, 8]]); | ||
}))); | ||
it('should call transport.sendResetPasswordEmail', _asyncToGenerator(regeneratorRuntime.mark(function _callee33() { | ||
var mock; | ||
return regeneratorRuntime.wrap(function _callee33$(_context33) { | ||
while (1) { | ||
switch (_context33.prev = _context33.next) { | ||
case 0: | ||
mock = jest.fn(function () { | ||
return Promise.resolve(); | ||
}); | ||
_AccountsClient2.default.config({}, { sendResetPasswordEmail: mock }); | ||
_context33.next = 4; | ||
return _AccountsClient2.default.requestPasswordReset('email'); | ||
case 4: | ||
expect(mock.mock.calls.length).toEqual(1); | ||
expect(mock.mock.calls[0][0]).toEqual('email'); | ||
case 6: | ||
case 'end': | ||
return _context33.stop(); | ||
} | ||
} | ||
}, _callee33, undefined); | ||
}))); | ||
}); | ||
describe('requestVerificationEmail', function () { | ||
it('should return an AccountsError', _asyncToGenerator(regeneratorRuntime.mark(function _callee34() { | ||
var error; | ||
return regeneratorRuntime.wrap(function _callee34$(_context34) { | ||
while (1) { | ||
switch (_context34.prev = _context34.next) { | ||
case 0: | ||
error = 'something bad'; | ||
_AccountsClient2.default.config({}, { sendVerificationEmail: function sendVerificationEmail() { | ||
return Promise.reject({ message: error }); | ||
} }); | ||
_context34.prev = 2; | ||
_context34.next = 5; | ||
return _AccountsClient2.default.requestVerificationEmail(); | ||
case 5: | ||
throw new Error(); | ||
case 8: | ||
_context34.prev = 8; | ||
_context34.t0 = _context34['catch'](2); | ||
expect(_context34.t0.message).toEqual(error); | ||
case 11: | ||
case 'end': | ||
return _context34.stop(); | ||
} | ||
} | ||
}, _callee34, undefined, [[2, 8]]); | ||
}))); | ||
it('should call transport.sendVerificationEmail', _asyncToGenerator(regeneratorRuntime.mark(function _callee35() { | ||
var mock; | ||
return regeneratorRuntime.wrap(function _callee35$(_context35) { | ||
while (1) { | ||
switch (_context35.prev = _context35.next) { | ||
case 0: | ||
mock = jest.fn(function () { | ||
return Promise.resolve(); | ||
}); | ||
_AccountsClient2.default.config({}, { sendVerificationEmail: mock }); | ||
_context35.next = 4; | ||
return _AccountsClient2.default.requestVerificationEmail('email'); | ||
case 4: | ||
expect(mock.mock.calls.length).toEqual(1); | ||
expect(mock.mock.calls[0][0]).toEqual('email'); | ||
case 6: | ||
case 'end': | ||
return _context35.stop(); | ||
} | ||
} | ||
}, _callee35, undefined); | ||
}))); | ||
}); | ||
}); |
@@ -6,3 +6,3 @@ 'use strict'; | ||
}); | ||
exports.clearUser = exports.setUser = exports.loggingIn = undefined; | ||
exports.clearUser = exports.clearTokens = exports.setTokens = exports.setUser = exports.loggingIn = undefined; | ||
@@ -14,2 +14,4 @@ var _immutable = require('immutable'); | ||
var SET_USER = PATH + 'SET_USER'; | ||
var SET_TOKENS = PATH + 'SET_TOKENS'; | ||
var CLEAR_TOKENS = PATH + 'CLEAR_TOKENS'; | ||
var CLEAR_USER = PATH + 'CLEAR_USER'; | ||
@@ -21,2 +23,3 @@ var LOGGING_IN = PATH + 'LOGGING_IN'; | ||
user: null, | ||
tokens: null, | ||
loggingIn: false | ||
@@ -41,2 +44,12 @@ }); | ||
} | ||
case SET_TOKENS: | ||
{ | ||
var tokens = action.payload.tokens; | ||
return state.set('tokens', (0, _immutable.Map)(tokens)); | ||
} | ||
case CLEAR_TOKENS: | ||
{ | ||
return state.set('tokens', null); | ||
} | ||
case CLEAR_USER: | ||
@@ -77,2 +90,17 @@ { | ||
var setTokens = exports.setTokens = function setTokens(tokens) { | ||
return { | ||
type: SET_TOKENS, | ||
payload: { | ||
tokens: tokens | ||
} | ||
}; | ||
}; | ||
var clearTokens = exports.clearTokens = function clearTokens() { | ||
return { | ||
type: CLEAR_TOKENS | ||
}; | ||
}; | ||
var clearUser = exports.clearUser = function clearUser() { | ||
@@ -79,0 +107,0 @@ return { |
{ | ||
"name": "@accounts/client", | ||
"version": "0.0.7", | ||
"version": "0.0.8-alpha.840bab8d", | ||
"description": "Fullstack authentication and accounts-management", | ||
@@ -67,3 +67,3 @@ "main": "lib/index.js", | ||
"dependencies": { | ||
"@accounts/common": "next", | ||
"@accounts/common": "^0.0.8-alpha.840bab8d", | ||
"immutable": "^3.8.1", | ||
@@ -70,0 +70,0 @@ "jwt-decode": "^2.1.0", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
161602
3040
+ Added@accounts/common@0.0.8-alpha.f59b6667(transitive)
- Removed@accounts/common@0.0.7(transitive)