@accounts/client
Advanced tools
Comparing version 0.0.10-alpha.18d76699 to 0.0.10-alpha.42950dcc
@@ -158,11 +158,6 @@ 'use strict'; | ||
}, { | ||
key: 'user', | ||
value: function user() { | ||
var user = this.getState().get('user'); | ||
return user ? user.toJS() : null; | ||
} | ||
}, { | ||
key: 'tokens', | ||
key: 'loadTokensFromStorage', | ||
value: function () { | ||
var _ref4 = _asyncToGenerator(regeneratorRuntime.mark(function _callee4() { | ||
var tokens; | ||
return regeneratorRuntime.wrap(function _callee4$(_context4) { | ||
@@ -182,8 +177,10 @@ while (1) { | ||
_context4.t1 = _context4.sent; | ||
return _context4.abrupt('return', { | ||
tokens = { | ||
accessToken: _context4.t0, | ||
refreshToken: _context4.t1 | ||
}); | ||
}; | ||
case 7: | ||
this.store.dispatch((0, _module.setTokens)(tokens)); | ||
case 8: | ||
case 'end': | ||
@@ -196,9 +193,26 @@ return _context4.stop(); | ||
function tokens() { | ||
function loadTokensFromStorage() { | ||
return _ref4.apply(this, arguments); | ||
} | ||
return tokens; | ||
return loadTokensFromStorage; | ||
}() | ||
}, { | ||
key: 'user', | ||
value: function user() { | ||
var user = this.getState().get('user'); | ||
return user ? user.toJS() : null; | ||
} | ||
}, { | ||
key: 'tokens', | ||
value: function tokens() { | ||
var tokens = this.getState().get('tokens'); | ||
return tokens ? tokens.toJS() : { | ||
accessToken: null, | ||
refreshToken: null | ||
}; | ||
} | ||
}, { | ||
key: 'clearTokens', | ||
@@ -773,3 +787,22 @@ value: function () { | ||
config: function config(options, transport) { | ||
this.instance = new AccountsClient(_extends({}, _config3.default, options), transport); | ||
var _this = this; | ||
return _asyncToGenerator(regeneratorRuntime.mark(function _callee15() { | ||
return regeneratorRuntime.wrap(function _callee15$(_context15) { | ||
while (1) { | ||
switch (_context15.prev = _context15.next) { | ||
case 0: | ||
_this.instance = new AccountsClient(_extends({}, _config3.default, options), transport); | ||
return _context15.abrupt('return', _this.instance.loadTokensFromStorage().then(function () { | ||
return _this.instance; | ||
})); | ||
case 2: | ||
case 'end': | ||
return _context15.stop(); | ||
} | ||
} | ||
}, _callee15, _this); | ||
}))(); | ||
}, | ||
@@ -776,0 +809,0 @@ user: function user() { |
@@ -50,14 +50,65 @@ 'use strict'; | ||
describe('config', function () { | ||
it('requires a transport', function () { | ||
try { | ||
_AccountsClient2.default.config({ | ||
history: history | ||
}); | ||
throw new Error(); | ||
} catch (err) { | ||
var message = err.message; | ||
it('requires a transport', _asyncToGenerator(regeneratorRuntime.mark(function _callee() { | ||
var message; | ||
return regeneratorRuntime.wrap(function _callee$(_context) { | ||
while (1) { | ||
switch (_context.prev = _context.next) { | ||
case 0: | ||
_context.prev = 0; | ||
_context.next = 3; | ||
return _AccountsClient2.default.config({ | ||
history: history | ||
}); | ||
expect(message).toEqual('A REST or GraphQL transport is required'); | ||
} | ||
}); | ||
case 3: | ||
throw new Error(); | ||
case 6: | ||
_context.prev = 6; | ||
_context.t0 = _context['catch'](0); | ||
message = _context.t0.message; | ||
expect(message).toEqual('A REST or GraphQL transport is required'); | ||
case 10: | ||
case 'end': | ||
return _context.stop(); | ||
} | ||
} | ||
}, _callee, undefined, [[0, 6]]); | ||
}))); | ||
it('should eagerly load tokens from storage after using config', _asyncToGenerator(regeneratorRuntime.mark(function _callee2() { | ||
var transport, tokens; | ||
return regeneratorRuntime.wrap(function _callee2$(_context2) { | ||
while (1) { | ||
switch (_context2.prev = _context2.next) { | ||
case 0: | ||
transport = { | ||
loginWithPassword: function loginWithPassword() { | ||
return Promise.resolve(loggedInUser); | ||
} | ||
}; | ||
_context2.next = 3; | ||
return _AccountsClient2.default.config({ | ||
history: history, | ||
tokenStorage: { | ||
getItem: function getItem() { | ||
return Promise.resolve('testValue'); | ||
} | ||
} | ||
}, transport); | ||
case 3: | ||
tokens = _AccountsClient2.default.tokens(); | ||
expect(tokens.accessToken).toBeDefined(); | ||
expect(tokens.refreshToken).toBeDefined(); | ||
case 6: | ||
case 'end': | ||
return _context2.stop(); | ||
} | ||
} | ||
}, _callee2, undefined); | ||
}))); | ||
it('sets the transport', function () { | ||
@@ -72,7 +123,7 @@ var transport = {}; | ||
describe('createUser', function () { | ||
it('requires user object', _asyncToGenerator(regeneratorRuntime.mark(function _callee() { | ||
it('requires user object', _asyncToGenerator(regeneratorRuntime.mark(function _callee3() { | ||
var message; | ||
return regeneratorRuntime.wrap(function _callee$(_context) { | ||
return regeneratorRuntime.wrap(function _callee3$(_context3) { | ||
while (1) { | ||
switch (_context.prev = _context.next) { | ||
switch (_context3.prev = _context3.next) { | ||
case 0: | ||
@@ -84,4 +135,4 @@ _AccountsClient2.default.config({ | ||
}); | ||
_context.prev = 1; | ||
_context.next = 4; | ||
_context3.prev = 1; | ||
_context3.next = 4; | ||
return _AccountsClient2.default.createUser(); | ||
@@ -93,5 +144,5 @@ | ||
case 7: | ||
_context.prev = 7; | ||
_context.t0 = _context['catch'](1); | ||
message = _context.t0.message; | ||
_context3.prev = 7; | ||
_context3.t0 = _context3['catch'](1); | ||
message = _context3.t0.message; | ||
@@ -102,12 +153,12 @@ expect(message).toEqual('Unrecognized options for create user request'); | ||
case 'end': | ||
return _context.stop(); | ||
return _context3.stop(); | ||
} | ||
} | ||
}, _callee, undefined, [[1, 7]]); | ||
}, _callee3, undefined, [[1, 7]]); | ||
}))); | ||
it('requires password', _asyncToGenerator(regeneratorRuntime.mark(function _callee2() { | ||
it('requires password', _asyncToGenerator(regeneratorRuntime.mark(function _callee4() { | ||
var message; | ||
return regeneratorRuntime.wrap(function _callee2$(_context2) { | ||
return regeneratorRuntime.wrap(function _callee4$(_context4) { | ||
while (1) { | ||
switch (_context2.prev = _context2.next) { | ||
switch (_context4.prev = _context4.next) { | ||
case 0: | ||
@@ -119,4 +170,4 @@ _AccountsClient2.default.config({ | ||
}); | ||
_context2.prev = 1; | ||
_context2.next = 4; | ||
_context4.prev = 1; | ||
_context4.next = 4; | ||
return _AccountsClient2.default.createUser({ | ||
@@ -130,5 +181,5 @@ password: null | ||
case 7: | ||
_context2.prev = 7; | ||
_context2.t0 = _context2['catch'](1); | ||
message = _context2.t0.message; | ||
_context4.prev = 7; | ||
_context4.t0 = _context4['catch'](1); | ||
message = _context4.t0.message; | ||
@@ -139,12 +190,12 @@ expect(message).toEqual('Password is required'); | ||
case 'end': | ||
return _context2.stop(); | ||
return _context4.stop(); | ||
} | ||
} | ||
}, _callee2, undefined, [[1, 7]]); | ||
}, _callee4, undefined, [[1, 7]]); | ||
}))); | ||
it('requires username or an email', _asyncToGenerator(regeneratorRuntime.mark(function _callee3() { | ||
it('requires username or an email', _asyncToGenerator(regeneratorRuntime.mark(function _callee5() { | ||
var message; | ||
return regeneratorRuntime.wrap(function _callee3$(_context3) { | ||
return regeneratorRuntime.wrap(function _callee5$(_context5) { | ||
while (1) { | ||
switch (_context3.prev = _context3.next) { | ||
switch (_context5.prev = _context5.next) { | ||
case 0: | ||
@@ -154,4 +205,4 @@ _AccountsClient2.default.config({ history: history }, { | ||
}); | ||
_context3.prev = 1; | ||
_context3.next = 4; | ||
_context5.prev = 1; | ||
_context5.next = 4; | ||
return _AccountsClient2.default.createUser({ | ||
@@ -167,5 +218,5 @@ password: '123456', | ||
case 7: | ||
_context3.prev = 7; | ||
_context3.t0 = _context3['catch'](1); | ||
message = _context3.t0.message; | ||
_context5.prev = 7; | ||
_context5.t0 = _context5['catch'](1); | ||
message = _context5.t0.message; | ||
@@ -176,12 +227,12 @@ expect(message).toEqual('Username or Email is required'); | ||
case 'end': | ||
return _context3.stop(); | ||
return _context5.stop(); | ||
} | ||
} | ||
}, _callee3, undefined, [[1, 7]]); | ||
}, _callee5, undefined, [[1, 7]]); | ||
}))); | ||
it('calls callback on succesfull user creation', _asyncToGenerator(regeneratorRuntime.mark(function _callee4() { | ||
it('calls callback on succesfull user creation', _asyncToGenerator(regeneratorRuntime.mark(function _callee6() { | ||
var callback, transport; | ||
return regeneratorRuntime.wrap(function _callee4$(_context4) { | ||
return regeneratorRuntime.wrap(function _callee6$(_context6) { | ||
while (1) { | ||
switch (_context4.prev = _context4.next) { | ||
switch (_context6.prev = _context6.next) { | ||
case 0: | ||
@@ -197,5 +248,7 @@ callback = jest.fn(); | ||
}; | ||
_context6.next = 4; | ||
return _AccountsClient2.default.config({ history: history }, transport); | ||
_AccountsClient2.default.config({ history: history }, transport); | ||
_context4.next = 5; | ||
case 4: | ||
_context6.next = 6; | ||
return _AccountsClient2.default.createUser({ | ||
@@ -206,18 +259,18 @@ password: '123456', | ||
case 5: | ||
case 6: | ||
expect(callback.mock.calls.length).toEqual(1); | ||
case 6: | ||
case 7: | ||
case 'end': | ||
return _context4.stop(); | ||
return _context6.stop(); | ||
} | ||
} | ||
}, _callee4, undefined); | ||
}, _callee6, undefined); | ||
}))); | ||
it('calls callback on failure with error message', _asyncToGenerator(regeneratorRuntime.mark(function _callee5() { | ||
it('calls callback on failure with error message', _asyncToGenerator(regeneratorRuntime.mark(function _callee7() { | ||
var transport, callback; | ||
return regeneratorRuntime.wrap(function _callee5$(_context5) { | ||
return regeneratorRuntime.wrap(function _callee7$(_context7) { | ||
while (1) { | ||
switch (_context5.prev = _context5.next) { | ||
switch (_context7.prev = _context7.next) { | ||
case 0: | ||
@@ -229,9 +282,9 @@ transport = { | ||
}; | ||
_context7.next = 3; | ||
return _AccountsClient2.default.config({ history: history }, transport); | ||
_AccountsClient2.default.config({ history: history }, transport); | ||
case 3: | ||
callback = jest.fn(); | ||
_context5.prev = 3; | ||
_context5.next = 6; | ||
_context7.prev = 4; | ||
_context7.next = 7; | ||
return _AccountsClient2.default.createUser({ | ||
@@ -242,8 +295,8 @@ password: '123456', | ||
case 6: | ||
case 7: | ||
throw new Error(); | ||
case 9: | ||
_context5.prev = 9; | ||
_context5.t0 = _context5['catch'](3); | ||
case 10: | ||
_context7.prev = 10; | ||
_context7.t0 = _context7['catch'](4); | ||
@@ -253,14 +306,14 @@ expect(callback.mock.calls.length).toEqual(1); | ||
case 13: | ||
case 14: | ||
case 'end': | ||
return _context5.stop(); | ||
return _context7.stop(); | ||
} | ||
} | ||
}, _callee5, undefined, [[3, 9]]); | ||
}, _callee7, undefined, [[4, 10]]); | ||
}))); | ||
it('calls login function with user id and password of created user', _asyncToGenerator(regeneratorRuntime.mark(function _callee6() { | ||
it('calls login function with user id and password of created user', _asyncToGenerator(regeneratorRuntime.mark(function _callee8() { | ||
var transport; | ||
return regeneratorRuntime.wrap(function _callee6$(_context6) { | ||
return regeneratorRuntime.wrap(function _callee8$(_context8) { | ||
while (1) { | ||
switch (_context6.prev = _context6.next) { | ||
switch (_context8.prev = _context8.next) { | ||
case 0: | ||
@@ -279,3 +332,3 @@ transport = { | ||
_context6.next = 5; | ||
_context8.next = 5; | ||
return _AccountsClient2.default.createUser({ | ||
@@ -293,14 +346,14 @@ password: '123456', | ||
case 'end': | ||
return _context6.stop(); | ||
return _context8.stop(); | ||
} | ||
} | ||
}, _callee6, undefined); | ||
}, _callee8, undefined); | ||
}))); | ||
}); | ||
describe('loginWithPassword', function () { | ||
it('throws error if password is undefined', _asyncToGenerator(regeneratorRuntime.mark(function _callee7() { | ||
it('throws error if password is undefined', _asyncToGenerator(regeneratorRuntime.mark(function _callee9() { | ||
var transport, message; | ||
return regeneratorRuntime.wrap(function _callee7$(_context7) { | ||
return regeneratorRuntime.wrap(function _callee9$(_context9) { | ||
while (1) { | ||
switch (_context7.prev = _context7.next) { | ||
switch (_context9.prev = _context9.next) { | ||
case 0: | ||
@@ -314,4 +367,4 @@ transport = { | ||
_AccountsClient2.default.config({ history: history }, transport); | ||
_context7.prev = 2; | ||
_context7.next = 5; | ||
_context9.prev = 2; | ||
_context9.next = 5; | ||
return _AccountsClient2.default.loginWithPassword(); | ||
@@ -323,5 +376,5 @@ | ||
case 8: | ||
_context7.prev = 8; | ||
_context7.t0 = _context7['catch'](2); | ||
message = _context7.t0.message; | ||
_context9.prev = 8; | ||
_context9.t0 = _context9['catch'](2); | ||
message = _context9.t0.message; | ||
@@ -332,12 +385,12 @@ expect(message).toEqual('Unrecognized options for login request'); | ||
case 'end': | ||
return _context7.stop(); | ||
return _context9.stop(); | ||
} | ||
} | ||
}, _callee7, undefined, [[2, 8]]); | ||
}, _callee9, undefined, [[2, 8]]); | ||
}))); | ||
it('throws error if user is undefined', _asyncToGenerator(regeneratorRuntime.mark(function _callee8() { | ||
it('throws error if user is undefined', _asyncToGenerator(regeneratorRuntime.mark(function _callee10() { | ||
var transport, message; | ||
return regeneratorRuntime.wrap(function _callee8$(_context8) { | ||
return regeneratorRuntime.wrap(function _callee10$(_context10) { | ||
while (1) { | ||
switch (_context8.prev = _context8.next) { | ||
switch (_context10.prev = _context10.next) { | ||
case 0: | ||
@@ -351,4 +404,4 @@ transport = { | ||
_AccountsClient2.default.config({ history: history }, transport); | ||
_context8.prev = 2; | ||
_context8.next = 5; | ||
_context10.prev = 2; | ||
_context10.next = 5; | ||
return _AccountsClient2.default.loginWithPassword(); | ||
@@ -360,5 +413,5 @@ | ||
case 8: | ||
_context8.prev = 8; | ||
_context8.t0 = _context8['catch'](2); | ||
message = _context8.t0.message; | ||
_context10.prev = 8; | ||
_context10.t0 = _context10['catch'](2); | ||
message = _context10.t0.message; | ||
@@ -369,12 +422,12 @@ expect(message).toEqual('Unrecognized options for login request'); | ||
case 'end': | ||
return _context8.stop(); | ||
return _context10.stop(); | ||
} | ||
} | ||
}, _callee8, undefined, [[2, 8]]); | ||
}, _callee10, undefined, [[2, 8]]); | ||
}))); | ||
it('throws error user is not a string or is an empty object', _asyncToGenerator(regeneratorRuntime.mark(function _callee9() { | ||
it('throws error user is not a string or is an empty object', _asyncToGenerator(regeneratorRuntime.mark(function _callee11() { | ||
var transport, message; | ||
return regeneratorRuntime.wrap(function _callee9$(_context9) { | ||
return regeneratorRuntime.wrap(function _callee11$(_context11) { | ||
while (1) { | ||
switch (_context9.prev = _context9.next) { | ||
switch (_context11.prev = _context11.next) { | ||
case 0: | ||
@@ -388,4 +441,4 @@ transport = { | ||
_AccountsClient2.default.config({ history: history }, transport); | ||
_context9.prev = 2; | ||
_context9.next = 5; | ||
_context11.prev = 2; | ||
_context11.next = 5; | ||
return _AccountsClient2.default.loginWithPassword({}, 'password'); | ||
@@ -397,5 +450,5 @@ | ||
case 8: | ||
_context9.prev = 8; | ||
_context9.t0 = _context9['catch'](2); | ||
message = _context9.t0.message; | ||
_context11.prev = 8; | ||
_context11.t0 = _context11['catch'](2); | ||
message = _context11.t0.message; | ||
@@ -406,12 +459,12 @@ expect(message).toEqual('Match failed'); | ||
case 'end': | ||
return _context9.stop(); | ||
return _context11.stop(); | ||
} | ||
} | ||
}, _callee9, undefined, [[2, 8]]); | ||
}, _callee11, undefined, [[2, 8]]); | ||
}))); | ||
it('throws error password is not a string', _asyncToGenerator(regeneratorRuntime.mark(function _callee10() { | ||
it('throws error password is not a string', _asyncToGenerator(regeneratorRuntime.mark(function _callee12() { | ||
var transport, message; | ||
return regeneratorRuntime.wrap(function _callee10$(_context10) { | ||
return regeneratorRuntime.wrap(function _callee12$(_context12) { | ||
while (1) { | ||
switch (_context10.prev = _context10.next) { | ||
switch (_context12.prev = _context12.next) { | ||
case 0: | ||
@@ -425,4 +478,4 @@ transport = { | ||
_AccountsClient2.default.config({ history: history }, transport); | ||
_context10.prev = 2; | ||
_context10.next = 5; | ||
_context12.prev = 2; | ||
_context12.next = 5; | ||
return _AccountsClient2.default.loginWithPassword({ user: 'username' }, {}); | ||
@@ -434,5 +487,5 @@ | ||
case 8: | ||
_context10.prev = 8; | ||
_context10.t0 = _context10['catch'](2); | ||
message = _context10.t0.message; | ||
_context12.prev = 8; | ||
_context12.t0 = _context12['catch'](2); | ||
message = _context12.t0.message; | ||
@@ -443,12 +496,12 @@ expect(message).toEqual('Match failed'); | ||
case 'end': | ||
return _context10.stop(); | ||
return _context12.stop(); | ||
} | ||
} | ||
}, _callee10, undefined, [[2, 8]]); | ||
}, _callee12, undefined, [[2, 8]]); | ||
}))); | ||
it('calls callback on successful login', _asyncToGenerator(regeneratorRuntime.mark(function _callee11() { | ||
it('calls callback on successful login', _asyncToGenerator(regeneratorRuntime.mark(function _callee13() { | ||
var transport, callback; | ||
return regeneratorRuntime.wrap(function _callee11$(_context11) { | ||
return regeneratorRuntime.wrap(function _callee13$(_context13) { | ||
while (1) { | ||
switch (_context11.prev = _context11.next) { | ||
switch (_context13.prev = _context13.next) { | ||
case 0: | ||
@@ -463,3 +516,3 @@ transport = { | ||
callback = jest.fn(); | ||
_context11.next = 5; | ||
_context13.next = 5; | ||
return _AccountsClient2.default.loginWithPassword('username', 'password', callback); | ||
@@ -473,12 +526,12 @@ | ||
case 'end': | ||
return _context11.stop(); | ||
return _context13.stop(); | ||
} | ||
} | ||
}, _callee11, undefined); | ||
}, _callee13, undefined); | ||
}))); | ||
it('calls transport', _asyncToGenerator(regeneratorRuntime.mark(function _callee12() { | ||
it('calls transport', _asyncToGenerator(regeneratorRuntime.mark(function _callee14() { | ||
var loginWithPassword, transport; | ||
return regeneratorRuntime.wrap(function _callee12$(_context12) { | ||
return regeneratorRuntime.wrap(function _callee14$(_context14) { | ||
while (1) { | ||
switch (_context12.prev = _context12.next) { | ||
switch (_context14.prev = _context14.next) { | ||
case 0: | ||
@@ -493,3 +546,3 @@ loginWithPassword = jest.fn(function () { | ||
_AccountsClient2.default.config({ history: history }, transport); | ||
_context12.next = 5; | ||
_context14.next = 5; | ||
return _AccountsClient2.default.loginWithPassword('username', 'password'); | ||
@@ -504,12 +557,12 @@ | ||
case 'end': | ||
return _context12.stop(); | ||
return _context14.stop(); | ||
} | ||
} | ||
}, _callee12, undefined); | ||
}, _callee14, undefined); | ||
}))); | ||
it('calls callback with error on failed login', _asyncToGenerator(regeneratorRuntime.mark(function _callee13() { | ||
it('calls callback with error on failed login', _asyncToGenerator(regeneratorRuntime.mark(function _callee15() { | ||
var transport, callback; | ||
return regeneratorRuntime.wrap(function _callee13$(_context13) { | ||
return regeneratorRuntime.wrap(function _callee15$(_context15) { | ||
while (1) { | ||
switch (_context13.prev = _context13.next) { | ||
switch (_context15.prev = _context15.next) { | ||
case 0: | ||
@@ -524,4 +577,4 @@ transport = { | ||
callback = jest.fn(); | ||
_context13.prev = 3; | ||
_context13.next = 6; | ||
_context15.prev = 3; | ||
_context15.next = 6; | ||
return _AccountsClient2.default.loginWithPassword('username', 'password', callback); | ||
@@ -533,4 +586,4 @@ | ||
case 9: | ||
_context13.prev = 9; | ||
_context13.t0 = _context13['catch'](3); | ||
_context15.prev = 9; | ||
_context15.t0 = _context15['catch'](3); | ||
@@ -542,12 +595,12 @@ expect(callback.mock.calls.length).toEqual(1); | ||
case 'end': | ||
return _context13.stop(); | ||
return _context15.stop(); | ||
} | ||
} | ||
}, _callee13, undefined, [[3, 9]]); | ||
}, _callee15, undefined, [[3, 9]]); | ||
}))); | ||
it('sets loggingIn flag to false on failed login', _asyncToGenerator(regeneratorRuntime.mark(function _callee14() { | ||
it('sets loggingIn flag to false on failed login', _asyncToGenerator(regeneratorRuntime.mark(function _callee16() { | ||
var transport; | ||
return regeneratorRuntime.wrap(function _callee14$(_context14) { | ||
return regeneratorRuntime.wrap(function _callee16$(_context16) { | ||
while (1) { | ||
switch (_context14.prev = _context14.next) { | ||
switch (_context16.prev = _context16.next) { | ||
case 0: | ||
@@ -561,4 +614,4 @@ transport = { | ||
_AccountsClient2.default.config({ history: history }, transport); | ||
_context14.prev = 2; | ||
_context14.next = 5; | ||
_context16.prev = 2; | ||
_context16.next = 5; | ||
return _AccountsClient2.default.loginWithPassword('username', 'password'); | ||
@@ -570,4 +623,4 @@ | ||
case 8: | ||
_context14.prev = 8; | ||
_context14.t0 = _context14['catch'](2); | ||
_context16.prev = 8; | ||
_context16.t0 = _context16['catch'](2); | ||
@@ -578,12 +631,12 @@ expect(_AccountsClient2.default.loggingIn()).toBe(false); | ||
case 'end': | ||
return _context14.stop(); | ||
return _context16.stop(); | ||
} | ||
} | ||
}, _callee14, undefined, [[2, 8]]); | ||
}, _callee16, undefined, [[2, 8]]); | ||
}))); | ||
it('stores tokens in local storage', _asyncToGenerator(regeneratorRuntime.mark(function _callee15() { | ||
it('stores tokens in local storage', _asyncToGenerator(regeneratorRuntime.mark(function _callee17() { | ||
var transport; | ||
return regeneratorRuntime.wrap(function _callee15$(_context15) { | ||
return regeneratorRuntime.wrap(function _callee17$(_context17) { | ||
while (1) { | ||
switch (_context15.prev = _context15.next) { | ||
switch (_context17.prev = _context17.next) { | ||
case 0: | ||
@@ -597,3 +650,3 @@ transport = { | ||
_AccountsClient2.default.config({ history: history }, transport); | ||
_context15.next = 4; | ||
_context17.next = 4; | ||
return _AccountsClient2.default.loginWithPassword('username', 'password'); | ||
@@ -607,13 +660,13 @@ | ||
case 'end': | ||
return _context15.stop(); | ||
return _context17.stop(); | ||
} | ||
} | ||
}, _callee15, undefined); | ||
}, _callee17, undefined); | ||
}))); | ||
it('fetch tokens from storage when storage is async', _asyncToGenerator(regeneratorRuntime.mark(function _callee16() { | ||
it('should return tokens in a sync return value', _asyncToGenerator(regeneratorRuntime.mark(function _callee18() { | ||
var transport, tokens; | ||
return regeneratorRuntime.wrap(function _callee16$(_context16) { | ||
return regeneratorRuntime.wrap(function _callee18$(_context18) { | ||
while (1) { | ||
switch (_context16.prev = _context16.next) { | ||
switch (_context18.prev = _context18.next) { | ||
case 0: | ||
@@ -625,5 +678,4 @@ transport = { | ||
}; | ||
_AccountsClient2.default.config({ | ||
_context18.next = 3; | ||
return _AccountsClient2.default.config({ | ||
history: history, | ||
@@ -637,63 +689,20 @@ tokenStorage: { | ||
_context16.next = 4; | ||
return _AccountsClient2.default.tokens(); | ||
case 3: | ||
tokens = _AccountsClient2.default.tokens(); | ||
case 4: | ||
tokens = _context16.sent; | ||
expect(tokens.accessToken).toBe('testValue'); | ||
expect(tokens.refreshToken).toBe('testValue'); | ||
case 7: | ||
case 6: | ||
case 'end': | ||
return _context16.stop(); | ||
return _context18.stop(); | ||
} | ||
} | ||
}, _callee16, undefined); | ||
}, _callee18, undefined); | ||
}))); | ||
it('fetch tokens from storage when storage is sync', _asyncToGenerator(regeneratorRuntime.mark(function _callee17() { | ||
var transport, tokens; | ||
return regeneratorRuntime.wrap(function _callee17$(_context17) { | ||
while (1) { | ||
switch (_context17.prev = _context17.next) { | ||
case 0: | ||
transport = { | ||
loginWithPassword: function loginWithPassword() { | ||
return Promise.resolve(loggedInUser); | ||
} | ||
}; | ||
_AccountsClient2.default.config({ | ||
history: history, | ||
tokenStorage: { | ||
getItem: function getItem() { | ||
return 'testValue'; | ||
} | ||
} | ||
}, transport); | ||
_context17.next = 4; | ||
return _AccountsClient2.default.tokens(); | ||
case 4: | ||
tokens = _context17.sent; | ||
expect(tokens.accessToken).toBe('testValue'); | ||
expect(tokens.refreshToken).toBe('testValue'); | ||
case 7: | ||
case 'end': | ||
return _context17.stop(); | ||
} | ||
} | ||
}, _callee17, undefined); | ||
}))); | ||
it('stores user in redux', _asyncToGenerator(regeneratorRuntime.mark(function _callee18() { | ||
it('stores user in redux', _asyncToGenerator(regeneratorRuntime.mark(function _callee19() { | ||
var transport; | ||
return regeneratorRuntime.wrap(function _callee18$(_context18) { | ||
return regeneratorRuntime.wrap(function _callee19$(_context19) { | ||
while (1) { | ||
switch (_context18.prev = _context18.next) { | ||
switch (_context19.prev = _context19.next) { | ||
case 0: | ||
@@ -707,3 +716,3 @@ transport = { | ||
_AccountsClient2.default.config({ history: history }, transport); | ||
_context18.next = 4; | ||
_context19.next = 4; | ||
return _AccountsClient2.default.loginWithPassword('username', 'password'); | ||
@@ -716,12 +725,12 @@ | ||
case 'end': | ||
return _context18.stop(); | ||
return _context19.stop(); | ||
} | ||
} | ||
}, _callee18, undefined); | ||
}, _callee19, undefined); | ||
}))); | ||
it('stores tokens in redux', _asyncToGenerator(regeneratorRuntime.mark(function _callee19() { | ||
it('stores tokens in redux', _asyncToGenerator(regeneratorRuntime.mark(function _callee20() { | ||
var transport; | ||
return regeneratorRuntime.wrap(function _callee19$(_context19) { | ||
return regeneratorRuntime.wrap(function _callee20$(_context20) { | ||
while (1) { | ||
switch (_context19.prev = _context19.next) { | ||
switch (_context20.prev = _context20.next) { | ||
case 0: | ||
@@ -735,3 +744,3 @@ transport = { | ||
_AccountsClient2.default.config({ history: history }, transport); | ||
_context19.next = 4; | ||
_context20.next = 4; | ||
return _AccountsClient2.default.loginWithPassword('username', 'password'); | ||
@@ -744,13 +753,13 @@ | ||
case 'end': | ||
return _context19.stop(); | ||
return _context20.stop(); | ||
} | ||
} | ||
}, _callee19, undefined); | ||
}, _callee20, undefined); | ||
}))); | ||
it('can hash password with specified algorithm', _asyncToGenerator(regeneratorRuntime.mark(function _callee20() { | ||
it('can hash password with specified algorithm', _asyncToGenerator(regeneratorRuntime.mark(function _callee21() { | ||
var loginWithPassword, transport, hashDigest; | ||
return regeneratorRuntime.wrap(function _callee20$(_context20) { | ||
return regeneratorRuntime.wrap(function _callee21$(_context21) { | ||
while (1) { | ||
switch (_context20.prev = _context20.next) { | ||
switch (_context21.prev = _context21.next) { | ||
case 0: | ||
@@ -769,3 +778,3 @@ loginWithPassword = jest.fn(function () { | ||
hashDigest = _crypto2.default.createHash('sha256').update('password').digest('hex'); | ||
_context20.next = 6; | ||
_context21.next = 6; | ||
return _AccountsClient2.default.loginWithPassword('username', 'password'); | ||
@@ -780,14 +789,14 @@ | ||
case 'end': | ||
return _context20.stop(); | ||
return _context21.stop(); | ||
} | ||
} | ||
}, _callee20, undefined); | ||
}, _callee21, undefined); | ||
}))); | ||
}); | ||
describe('logout', function () { | ||
it('calls callback on successful logout', _asyncToGenerator(regeneratorRuntime.mark(function _callee21() { | ||
it('calls callback on successful logout', _asyncToGenerator(regeneratorRuntime.mark(function _callee22() { | ||
var transport, callback; | ||
return regeneratorRuntime.wrap(function _callee21$(_context21) { | ||
return regeneratorRuntime.wrap(function _callee22$(_context22) { | ||
while (1) { | ||
switch (_context21.prev = _context21.next) { | ||
switch (_context22.prev = _context22.next) { | ||
case 0: | ||
@@ -802,3 +811,3 @@ transport = { | ||
callback = jest.fn(); | ||
_context21.next = 5; | ||
_context22.next = 5; | ||
return _AccountsClient2.default.logout(callback); | ||
@@ -811,12 +820,12 @@ | ||
case 'end': | ||
return _context21.stop(); | ||
return _context22.stop(); | ||
} | ||
} | ||
}, _callee21, undefined); | ||
}, _callee22, undefined); | ||
}))); | ||
it('calls onLogout on successful logout', _asyncToGenerator(regeneratorRuntime.mark(function _callee22() { | ||
it('calls onLogout on successful logout', _asyncToGenerator(regeneratorRuntime.mark(function _callee23() { | ||
var onSignedOutHook, transport; | ||
return regeneratorRuntime.wrap(function _callee22$(_context22) { | ||
return regeneratorRuntime.wrap(function _callee23$(_context23) { | ||
while (1) { | ||
switch (_context22.prev = _context22.next) { | ||
switch (_context23.prev = _context23.next) { | ||
case 0: | ||
@@ -831,3 +840,3 @@ onSignedOutHook = jest.fn(); | ||
_AccountsClient2.default.config({ history: history, onSignedOutHook: onSignedOutHook }, transport); | ||
_context22.next = 5; | ||
_context23.next = 5; | ||
return _AccountsClient2.default.logout(); | ||
@@ -840,13 +849,13 @@ | ||
case 'end': | ||
return _context22.stop(); | ||
return _context23.stop(); | ||
} | ||
} | ||
}, _callee22, undefined); | ||
}, _callee23, undefined); | ||
}))); | ||
it('calls callback on failure with error message', _asyncToGenerator(regeneratorRuntime.mark(function _callee23() { | ||
it('calls callback on failure with error message', _asyncToGenerator(regeneratorRuntime.mark(function _callee24() { | ||
var transport, callback; | ||
return regeneratorRuntime.wrap(function _callee23$(_context23) { | ||
return regeneratorRuntime.wrap(function _callee24$(_context24) { | ||
while (1) { | ||
switch (_context23.prev = _context23.next) { | ||
switch (_context24.prev = _context24.next) { | ||
case 0: | ||
@@ -858,34 +867,39 @@ transport = { | ||
}; | ||
_context24.next = 3; | ||
return _AccountsClient2.default.instance.storeTokens({ tokens: { accessToken: '1' } }); | ||
_AccountsClient2.default.instance.storeTokens({ tokens: { accessToken: '1' } }); | ||
_AccountsClient2.default.config({ history: history }, transport); | ||
case 3: | ||
_context24.next = 5; | ||
return _AccountsClient2.default.config({ history: history }, transport); | ||
case 5: | ||
callback = jest.fn(); | ||
_context23.prev = 4; | ||
_context23.next = 7; | ||
_context24.prev = 6; | ||
_context24.next = 9; | ||
return _AccountsClient2.default.logout(callback); | ||
case 7: | ||
case 9: | ||
throw new Error(); | ||
case 10: | ||
_context23.prev = 10; | ||
_context23.t0 = _context23['catch'](4); | ||
case 12: | ||
_context24.prev = 12; | ||
_context24.t0 = _context24['catch'](6); | ||
expect(_context23.t0.message).toEqual('error message'); | ||
expect(_context24.t0.message).toEqual('error message'); | ||
expect(callback.mock.calls.length).toEqual(1); | ||
expect(callback.mock.calls[0][0]).toEqual({ message: 'error message' }); | ||
case 15: | ||
case 17: | ||
case 'end': | ||
return _context23.stop(); | ||
return _context24.stop(); | ||
} | ||
} | ||
}, _callee23, undefined, [[4, 10]]); | ||
}, _callee24, undefined, [[6, 12]]); | ||
}))); | ||
it('clear tokens in redux', _asyncToGenerator(regeneratorRuntime.mark(function _callee24() { | ||
it('clear tokens in redux', _asyncToGenerator(regeneratorRuntime.mark(function _callee25() { | ||
var transport, callback; | ||
return regeneratorRuntime.wrap(function _callee24$(_context24) { | ||
return regeneratorRuntime.wrap(function _callee25$(_context25) { | ||
while (1) { | ||
switch (_context24.prev = _context24.next) { | ||
switch (_context25.prev = _context25.next) { | ||
case 0: | ||
@@ -901,4 +915,4 @@ transport = { | ||
callback = jest.fn(); | ||
_context24.prev = 4; | ||
_context24.next = 7; | ||
_context25.prev = 4; | ||
_context25.next = 7; | ||
return _AccountsClient2.default.logout(callback); | ||
@@ -910,4 +924,4 @@ | ||
case 10: | ||
_context24.prev = 10; | ||
_context24.t0 = _context24['catch'](4); | ||
_context25.prev = 10; | ||
_context25.t0 = _context25['catch'](4); | ||
@@ -918,12 +932,12 @@ expect(_AccountsClient2.default.instance.getState().get('tokens')).toEqual(null); | ||
case 'end': | ||
return _context24.stop(); | ||
return _context25.stop(); | ||
} | ||
} | ||
}, _callee24, undefined, [[4, 10]]); | ||
}, _callee25, undefined, [[4, 10]]); | ||
}))); | ||
it('clear user in redux', _asyncToGenerator(regeneratorRuntime.mark(function _callee25() { | ||
it('clear user in redux', _asyncToGenerator(regeneratorRuntime.mark(function _callee26() { | ||
var transport, callback; | ||
return regeneratorRuntime.wrap(function _callee25$(_context25) { | ||
return regeneratorRuntime.wrap(function _callee26$(_context26) { | ||
while (1) { | ||
switch (_context25.prev = _context25.next) { | ||
switch (_context26.prev = _context26.next) { | ||
case 0: | ||
@@ -939,4 +953,4 @@ transport = { | ||
callback = jest.fn(); | ||
_context25.prev = 4; | ||
_context25.next = 7; | ||
_context26.prev = 4; | ||
_context26.next = 7; | ||
return _AccountsClient2.default.logout(callback); | ||
@@ -948,4 +962,4 @@ | ||
case 10: | ||
_context25.prev = 10; | ||
_context25.t0 = _context25['catch'](4); | ||
_context26.prev = 10; | ||
_context26.t0 = _context26['catch'](4); | ||
@@ -956,18 +970,18 @@ expect(_AccountsClient2.default.instance.getState().get('user')).toEqual(null); | ||
case 'end': | ||
return _context25.stop(); | ||
return _context26.stop(); | ||
} | ||
} | ||
}, _callee25, undefined, [[4, 10]]); | ||
}, _callee26, undefined, [[4, 10]]); | ||
}))); | ||
}); | ||
describe('refreshSession', _asyncToGenerator(regeneratorRuntime.mark(function _callee28() { | ||
return regeneratorRuntime.wrap(function _callee28$(_context28) { | ||
describe('refreshSession', _asyncToGenerator(regeneratorRuntime.mark(function _callee29() { | ||
return regeneratorRuntime.wrap(function _callee29$(_context29) { | ||
while (1) { | ||
switch (_context28.prev = _context28.next) { | ||
switch (_context29.prev = _context29.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 _callee26() { | ||
return regeneratorRuntime.wrap(function _callee26$(_context26) { | ||
it('clears tokens and user if tokens are not set', _asyncToGenerator(regeneratorRuntime.mark(function _callee27() { | ||
return regeneratorRuntime.wrap(function _callee27$(_context27) { | ||
while (1) { | ||
switch (_context26.prev = _context26.next) { | ||
switch (_context27.prev = _context27.next) { | ||
case 0: | ||
@@ -981,15 +995,15 @@ _AccountsClient2.default.config({}, {}); | ||
}); | ||
_context26.prev = 3; | ||
_context26.next = 6; | ||
_context27.prev = 3; | ||
_context27.next = 6; | ||
return _AccountsClient2.default.refreshSession(); | ||
case 6: | ||
_context26.next = 13; | ||
_context27.next = 13; | ||
break; | ||
case 8: | ||
_context26.prev = 8; | ||
_context26.t0 = _context26['catch'](3); | ||
_context27.prev = 8; | ||
_context27.t0 = _context27['catch'](3); | ||
expect(_context26.t0.message).toEqual('no tokens provided'); | ||
expect(_context27.t0.message).toEqual('no tokens provided'); | ||
expect(_AccountsClient2.default.instance.clearTokens.mock.calls.length).toEqual(1); | ||
@@ -1000,16 +1014,19 @@ expect(_AccountsClient2.default.instance.clearUser.mock.calls.length).toEqual(1); | ||
case 'end': | ||
return _context26.stop(); | ||
return _context27.stop(); | ||
} | ||
} | ||
}, _callee26, undefined, [[3, 8]]); | ||
}, _callee27, undefined, [[3, 8]]); | ||
}))); | ||
it('clears tokens, users and throws error if bad refresh token provided', _asyncToGenerator(regeneratorRuntime.mark(function _callee27() { | ||
it('clears tokens, users and throws error if bad refresh token provided', _asyncToGenerator(regeneratorRuntime.mark(function _callee28() { | ||
var message; | ||
return regeneratorRuntime.wrap(function _callee27$(_context27) { | ||
return regeneratorRuntime.wrap(function _callee28$(_context28) { | ||
while (1) { | ||
switch (_context27.prev = _context27.next) { | ||
switch (_context28.prev = _context28.next) { | ||
case 0: | ||
_AccountsClient2.default.config({}, {}); | ||
localStorage.setItem('accounts:refreshToken', 'bad token'); | ||
localStorage.setItem('accounts:accessToken', 'bad token'); | ||
_context28.next = 4; | ||
return _AccountsClient2.default.config({}, {}); | ||
case 4: | ||
_AccountsClient2.default.instance.clearTokens = jest.fn(function () { | ||
@@ -1021,22 +1038,22 @@ return _AccountsClient2.default.instance.clearTokens; | ||
}); | ||
_context27.prev = 5; | ||
_context27.next = 8; | ||
_context28.prev = 6; | ||
_context28.next = 9; | ||
return _AccountsClient2.default.refreshSession(); | ||
case 8: | ||
case 9: | ||
throw new Error(); | ||
case 11: | ||
_context27.prev = 11; | ||
_context27.t0 = _context27['catch'](5); | ||
message = _context27.t0.message; | ||
case 12: | ||
_context28.prev = 12; | ||
_context28.t0 = _context28['catch'](6); | ||
message = _context28.t0.message; | ||
expect(message).toEqual('falsy token provided'); | ||
case 15: | ||
case 16: | ||
case 'end': | ||
return _context27.stop(); | ||
return _context28.stop(); | ||
} | ||
} | ||
}, _callee27, undefined, [[5, 11]]); | ||
}, _callee28, undefined, [[6, 12]]); | ||
}))); | ||
@@ -1080,14 +1097,14 @@ // it('requests a new token pair, sets the tokens and the user', async () => { | ||
case 'end': | ||
return _context28.stop(); | ||
return _context29.stop(); | ||
} | ||
} | ||
}, _callee28, undefined); | ||
}, _callee29, undefined); | ||
}))); | ||
describe('verifyEmail', function () { | ||
it('should return an AccountsError', _asyncToGenerator(regeneratorRuntime.mark(function _callee29() { | ||
it('should return an AccountsError', _asyncToGenerator(regeneratorRuntime.mark(function _callee30() { | ||
var error; | ||
return regeneratorRuntime.wrap(function _callee29$(_context29) { | ||
return regeneratorRuntime.wrap(function _callee30$(_context30) { | ||
while (1) { | ||
switch (_context29.prev = _context29.next) { | ||
switch (_context30.prev = _context30.next) { | ||
case 0: | ||
@@ -1099,4 +1116,4 @@ error = 'something bad'; | ||
} }); | ||
_context29.prev = 2; | ||
_context29.next = 5; | ||
_context30.prev = 2; | ||
_context30.next = 5; | ||
return _AccountsClient2.default.verifyEmail(); | ||
@@ -1108,20 +1125,20 @@ | ||
case 8: | ||
_context29.prev = 8; | ||
_context29.t0 = _context29['catch'](2); | ||
_context30.prev = 8; | ||
_context30.t0 = _context30['catch'](2); | ||
expect(_context29.t0.message).toEqual(error); | ||
expect(_context30.t0.message).toEqual(error); | ||
case 11: | ||
case 'end': | ||
return _context29.stop(); | ||
return _context30.stop(); | ||
} | ||
} | ||
}, _callee29, undefined, [[2, 8]]); | ||
}, _callee30, undefined, [[2, 8]]); | ||
}))); | ||
it('should call transport.verifyEmail', _asyncToGenerator(regeneratorRuntime.mark(function _callee30() { | ||
it('should call transport.verifyEmail', _asyncToGenerator(regeneratorRuntime.mark(function _callee31() { | ||
var mock; | ||
return regeneratorRuntime.wrap(function _callee30$(_context30) { | ||
return regeneratorRuntime.wrap(function _callee31$(_context31) { | ||
while (1) { | ||
switch (_context30.prev = _context30.next) { | ||
switch (_context31.prev = _context31.next) { | ||
case 0: | ||
@@ -1133,3 +1150,3 @@ mock = jest.fn(function () { | ||
_AccountsClient2.default.config({}, { verifyEmail: mock }); | ||
_context30.next = 4; | ||
_context31.next = 4; | ||
return _AccountsClient2.default.verifyEmail('token'); | ||
@@ -1143,6 +1160,6 @@ | ||
case 'end': | ||
return _context30.stop(); | ||
return _context31.stop(); | ||
} | ||
} | ||
}, _callee30, undefined); | ||
}, _callee31, undefined); | ||
}))); | ||
@@ -1152,7 +1169,7 @@ }); | ||
describe('resetPassword', function () { | ||
it('should return an AccountsError', _asyncToGenerator(regeneratorRuntime.mark(function _callee31() { | ||
it('should return an AccountsError', _asyncToGenerator(regeneratorRuntime.mark(function _callee32() { | ||
var error; | ||
return regeneratorRuntime.wrap(function _callee31$(_context31) { | ||
return regeneratorRuntime.wrap(function _callee32$(_context32) { | ||
while (1) { | ||
switch (_context31.prev = _context31.next) { | ||
switch (_context32.prev = _context32.next) { | ||
case 0: | ||
@@ -1164,4 +1181,4 @@ error = 'something bad'; | ||
} }); | ||
_context31.prev = 2; | ||
_context31.next = 5; | ||
_context32.prev = 2; | ||
_context32.next = 5; | ||
return _AccountsClient2.default.resetPassword(); | ||
@@ -1173,20 +1190,20 @@ | ||
case 8: | ||
_context31.prev = 8; | ||
_context31.t0 = _context31['catch'](2); | ||
_context32.prev = 8; | ||
_context32.t0 = _context32['catch'](2); | ||
expect(_context31.t0.message).toEqual(error); | ||
expect(_context32.t0.message).toEqual(error); | ||
case 11: | ||
case 'end': | ||
return _context31.stop(); | ||
return _context32.stop(); | ||
} | ||
} | ||
}, _callee31, undefined, [[2, 8]]); | ||
}, _callee32, undefined, [[2, 8]]); | ||
}))); | ||
it('should call transport.resetPassword', _asyncToGenerator(regeneratorRuntime.mark(function _callee32() { | ||
it('should call transport.resetPassword', _asyncToGenerator(regeneratorRuntime.mark(function _callee33() { | ||
var mock; | ||
return regeneratorRuntime.wrap(function _callee32$(_context32) { | ||
return regeneratorRuntime.wrap(function _callee33$(_context33) { | ||
while (1) { | ||
switch (_context32.prev = _context32.next) { | ||
switch (_context33.prev = _context33.next) { | ||
case 0: | ||
@@ -1198,3 +1215,3 @@ mock = jest.fn(function () { | ||
_AccountsClient2.default.config({}, { resetPassword: mock }); | ||
_context32.next = 4; | ||
_context33.next = 4; | ||
return _AccountsClient2.default.resetPassword('token', 'newPassword'); | ||
@@ -1209,6 +1226,6 @@ | ||
case 'end': | ||
return _context32.stop(); | ||
return _context33.stop(); | ||
} | ||
} | ||
}, _callee32, undefined); | ||
}, _callee33, undefined); | ||
}))); | ||
@@ -1218,7 +1235,7 @@ }); | ||
describe('requestPasswordReset', function () { | ||
it('should return an AccountsError', _asyncToGenerator(regeneratorRuntime.mark(function _callee33() { | ||
it('should return an AccountsError', _asyncToGenerator(regeneratorRuntime.mark(function _callee34() { | ||
var error; | ||
return regeneratorRuntime.wrap(function _callee33$(_context33) { | ||
return regeneratorRuntime.wrap(function _callee34$(_context34) { | ||
while (1) { | ||
switch (_context33.prev = _context33.next) { | ||
switch (_context34.prev = _context34.next) { | ||
case 0: | ||
@@ -1230,4 +1247,4 @@ error = 'something bad'; | ||
} }); | ||
_context33.prev = 2; | ||
_context33.next = 5; | ||
_context34.prev = 2; | ||
_context34.next = 5; | ||
return _AccountsClient2.default.requestPasswordReset('email@g.co'); | ||
@@ -1239,20 +1256,20 @@ | ||
case 8: | ||
_context33.prev = 8; | ||
_context33.t0 = _context33['catch'](2); | ||
_context34.prev = 8; | ||
_context34.t0 = _context34['catch'](2); | ||
expect(_context33.t0.message).toEqual(error); | ||
expect(_context34.t0.message).toEqual(error); | ||
case 11: | ||
case 'end': | ||
return _context33.stop(); | ||
return _context34.stop(); | ||
} | ||
} | ||
}, _callee33, undefined, [[2, 8]]); | ||
}, _callee34, undefined, [[2, 8]]); | ||
}))); | ||
it('should call transport.sendResetPasswordEmail', _asyncToGenerator(regeneratorRuntime.mark(function _callee34() { | ||
it('should call transport.sendResetPasswordEmail', _asyncToGenerator(regeneratorRuntime.mark(function _callee35() { | ||
var mock; | ||
return regeneratorRuntime.wrap(function _callee34$(_context34) { | ||
return regeneratorRuntime.wrap(function _callee35$(_context35) { | ||
while (1) { | ||
switch (_context34.prev = _context34.next) { | ||
switch (_context35.prev = _context35.next) { | ||
case 0: | ||
@@ -1264,3 +1281,3 @@ mock = jest.fn(function () { | ||
_AccountsClient2.default.config({}, { sendResetPasswordEmail: mock }); | ||
_context34.next = 4; | ||
_context35.next = 4; | ||
return _AccountsClient2.default.requestPasswordReset('email@g.co'); | ||
@@ -1274,13 +1291,13 @@ | ||
case 'end': | ||
return _context34.stop(); | ||
return _context35.stop(); | ||
} | ||
} | ||
}, _callee34, undefined); | ||
}, _callee35, undefined); | ||
}))); | ||
it('should throw if an invalid email is provided', _asyncToGenerator(regeneratorRuntime.mark(function _callee35() { | ||
it('should throw if an invalid email is provided', _asyncToGenerator(regeneratorRuntime.mark(function _callee36() { | ||
var mock; | ||
return regeneratorRuntime.wrap(function _callee35$(_context35) { | ||
return regeneratorRuntime.wrap(function _callee36$(_context36) { | ||
while (1) { | ||
switch (_context35.prev = _context35.next) { | ||
switch (_context36.prev = _context36.next) { | ||
case 0: | ||
@@ -1290,4 +1307,4 @@ mock = jest.fn(); | ||
_AccountsClient2.default.config({}, { sendResetPasswordEmail: mock }); | ||
_context35.prev = 2; | ||
_context35.next = 5; | ||
_context36.prev = 2; | ||
_context36.next = 5; | ||
return _AccountsClient2.default.requestPasswordReset('email'); | ||
@@ -1299,6 +1316,6 @@ | ||
case 8: | ||
_context35.prev = 8; | ||
_context35.t0 = _context35['catch'](2); | ||
_context36.prev = 8; | ||
_context36.t0 = _context36['catch'](2); | ||
expect(_context35.t0.message).toEqual('Valid email must be provided'); | ||
expect(_context36.t0.message).toEqual('Valid email must be provided'); | ||
expect(mock.mock.calls.length).toEqual(0); | ||
@@ -1308,6 +1325,6 @@ | ||
case 'end': | ||
return _context35.stop(); | ||
return _context36.stop(); | ||
} | ||
} | ||
}, _callee35, undefined, [[2, 8]]); | ||
}, _callee36, undefined, [[2, 8]]); | ||
}))); | ||
@@ -1317,7 +1334,7 @@ }); | ||
describe('requestVerificationEmail', function () { | ||
it('should return an AccountsError', _asyncToGenerator(regeneratorRuntime.mark(function _callee36() { | ||
it('should return an AccountsError', _asyncToGenerator(regeneratorRuntime.mark(function _callee37() { | ||
var error; | ||
return regeneratorRuntime.wrap(function _callee36$(_context36) { | ||
return regeneratorRuntime.wrap(function _callee37$(_context37) { | ||
while (1) { | ||
switch (_context36.prev = _context36.next) { | ||
switch (_context37.prev = _context37.next) { | ||
case 0: | ||
@@ -1329,4 +1346,4 @@ error = 'something bad'; | ||
} }); | ||
_context36.prev = 2; | ||
_context36.next = 5; | ||
_context37.prev = 2; | ||
_context37.next = 5; | ||
return _AccountsClient2.default.requestVerificationEmail('email@g.co'); | ||
@@ -1338,20 +1355,20 @@ | ||
case 8: | ||
_context36.prev = 8; | ||
_context36.t0 = _context36['catch'](2); | ||
_context37.prev = 8; | ||
_context37.t0 = _context37['catch'](2); | ||
expect(_context36.t0.message).toEqual(error); | ||
expect(_context37.t0.message).toEqual(error); | ||
case 11: | ||
case 'end': | ||
return _context36.stop(); | ||
return _context37.stop(); | ||
} | ||
} | ||
}, _callee36, undefined, [[2, 8]]); | ||
}, _callee37, undefined, [[2, 8]]); | ||
}))); | ||
it('should call transport.sendVerificationEmail', _asyncToGenerator(regeneratorRuntime.mark(function _callee37() { | ||
it('should call transport.sendVerificationEmail', _asyncToGenerator(regeneratorRuntime.mark(function _callee38() { | ||
var mock; | ||
return regeneratorRuntime.wrap(function _callee37$(_context37) { | ||
return regeneratorRuntime.wrap(function _callee38$(_context38) { | ||
while (1) { | ||
switch (_context37.prev = _context37.next) { | ||
switch (_context38.prev = _context38.next) { | ||
case 0: | ||
@@ -1363,3 +1380,3 @@ mock = jest.fn(function () { | ||
_AccountsClient2.default.config({}, { sendVerificationEmail: mock }); | ||
_context37.next = 4; | ||
_context38.next = 4; | ||
return _AccountsClient2.default.requestVerificationEmail('email@g.co'); | ||
@@ -1373,13 +1390,13 @@ | ||
case 'end': | ||
return _context37.stop(); | ||
return _context38.stop(); | ||
} | ||
} | ||
}, _callee37, undefined); | ||
}, _callee38, undefined); | ||
}))); | ||
it('should throw if an invalid email is provided', _asyncToGenerator(regeneratorRuntime.mark(function _callee38() { | ||
it('should throw if an invalid email is provided', _asyncToGenerator(regeneratorRuntime.mark(function _callee39() { | ||
var mock; | ||
return regeneratorRuntime.wrap(function _callee38$(_context38) { | ||
return regeneratorRuntime.wrap(function _callee39$(_context39) { | ||
while (1) { | ||
switch (_context38.prev = _context38.next) { | ||
switch (_context39.prev = _context39.next) { | ||
case 0: | ||
@@ -1389,4 +1406,4 @@ mock = jest.fn(); | ||
_AccountsClient2.default.config({}, { sendVerificationEmail: mock }); | ||
_context38.prev = 2; | ||
_context38.next = 5; | ||
_context39.prev = 2; | ||
_context39.next = 5; | ||
return _AccountsClient2.default.requestVerificationEmail('email'); | ||
@@ -1398,6 +1415,6 @@ | ||
case 8: | ||
_context38.prev = 8; | ||
_context38.t0 = _context38['catch'](2); | ||
_context39.prev = 8; | ||
_context39.t0 = _context39['catch'](2); | ||
expect(_context38.t0.message).toEqual('Valid email must be provided'); | ||
expect(_context39.t0.message).toEqual('Valid email must be provided'); | ||
expect(mock.mock.calls.length).toEqual(0); | ||
@@ -1407,8 +1424,8 @@ | ||
case 'end': | ||
return _context38.stop(); | ||
return _context39.stop(); | ||
} | ||
} | ||
}, _callee38, undefined, [[2, 8]]); | ||
}, _callee39, undefined, [[2, 8]]); | ||
}))); | ||
}); | ||
}); |
@@ -262,11 +262,6 @@ (function webpackUniversalModuleDefinition(root, factory) { | ||
}, { | ||
key: 'user', | ||
value: function user() { | ||
var user = this.getState().get('user'); | ||
return user ? user.toJS() : null; | ||
} | ||
}, { | ||
key: 'tokens', | ||
key: 'loadTokensFromStorage', | ||
value: function () { | ||
var _ref4 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee4() { | ||
var tokens; | ||
return _regenerator2.default.wrap(function _callee4$(_context4) { | ||
@@ -286,8 +281,10 @@ while (1) { | ||
_context4.t1 = _context4.sent; | ||
return _context4.abrupt('return', { | ||
tokens = { | ||
accessToken: _context4.t0, | ||
refreshToken: _context4.t1 | ||
}); | ||
}; | ||
case 7: | ||
this.store.dispatch((0, _module.setTokens)(tokens)); | ||
case 8: | ||
case 'end': | ||
@@ -300,9 +297,26 @@ return _context4.stop(); | ||
function tokens() { | ||
function loadTokensFromStorage() { | ||
return _ref4.apply(this, arguments); | ||
} | ||
return tokens; | ||
return loadTokensFromStorage; | ||
}() | ||
}, { | ||
key: 'user', | ||
value: function user() { | ||
var user = this.getState().get('user'); | ||
return user ? user.toJS() : null; | ||
} | ||
}, { | ||
key: 'tokens', | ||
value: function tokens() { | ||
var tokens = this.getState().get('tokens'); | ||
return tokens ? tokens.toJS() : { | ||
accessToken: null, | ||
refreshToken: null | ||
}; | ||
} | ||
}, { | ||
key: 'clearTokens', | ||
@@ -876,3 +890,22 @@ value: function () { | ||
config: function config(options, transport) { | ||
this.instance = new AccountsClient((0, _extends3.default)({}, _config3.default, options), transport); | ||
var _this = this; | ||
return (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee15() { | ||
return _regenerator2.default.wrap(function _callee15$(_context15) { | ||
while (1) { | ||
switch (_context15.prev = _context15.next) { | ||
case 0: | ||
_this.instance = new AccountsClient((0, _extends3.default)({}, _config3.default, options), transport); | ||
return _context15.abrupt('return', _this.instance.loadTokensFromStorage().then(function () { | ||
return _this.instance; | ||
})); | ||
case 2: | ||
case 'end': | ||
return _context15.stop(); | ||
} | ||
} | ||
}, _callee15, _this); | ||
}))(); | ||
}, | ||
@@ -879,0 +912,0 @@ user: function user() { |
{ | ||
"name": "@accounts/client", | ||
"version": "0.0.10-alpha.18d76699", | ||
"version": "0.0.10-alpha.42950dcc", | ||
"description": "Fullstack authentication and accounts-management", | ||
@@ -74,3 +74,3 @@ "main": "lib/index.js", | ||
"dependencies": { | ||
"@accounts/common": "^0.0.10-alpha.18d76699", | ||
"@accounts/common": "^0.0.10-alpha.42950dcc", | ||
"crypto-js": "^3.1.9-1", | ||
@@ -77,0 +77,0 @@ "immutable": "^3.8.1", |
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
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
319472
6058