UNPKG

apollo-passport-local-strategy

Version:

Local strategy using email address and hashed, bcrypted password

141 lines (112 loc) 4.25 kB
'use strict'; var _chai = require('chai'); var _chai2 = _interopRequireDefault(_chai); var _sinon = require('sinon'); var _sinon2 = _interopRequireDefault(_sinon); var _sinonChai = require('sinon-chai'); var _sinonChai2 = _interopRequireDefault(_sinonChai); require('regenerator-runtime/runtime'); var _index = require('./index'); var _index2 = _interopRequireDefault(_index); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } var should = _chai2.default.should(); _chai2.default.use(_sinonChai2.default); describe('apollo-passport-local - client', function () { var ap = { apolloClient: {}, extendWith: function extendWith(obj) { for (var key in obj) { this[key] = obj[key]; } } }; it('createUserEmailPassword()', function _callee() { return regeneratorRuntime.async(function _callee$(_context) { while (1) { switch (_context.prev = _context.next) { case 0: ap.loginStart = _sinon2.default.spy(); ap.loginComplete = _sinon2.default.spy(); ap.apolloClient.mutate = _sinon2.default.spy(function () { return "result"; }); new _index2.default(ap); _context.next = 6; return regeneratorRuntime.awrap(ap.createUserEmailPassword('email', 'password')); case 6: ap.loginStart.should.have.been.calledBefore(ap.apolloClient); ap.apolloClient.mutate.should.have.been.calledWithMatch({ variables: { email: 'email', password: (0, _index.hashPassword)('password') } }); ap.loginComplete.should.have.been.calledAfter(ap.apolloClient.mutate); ap.loginComplete.should.have.been.calledWith("result", "apCreateUserEmailPassword"); case 10: case 'end': return _context.stop(); } } }, null, undefined); }); it('loginWithEmailPassword()', function _callee2() { return regeneratorRuntime.async(function _callee2$(_context2) { while (1) { switch (_context2.prev = _context2.next) { case 0: ap.loginStart = _sinon2.default.spy(); ap.loginComplete = _sinon2.default.spy(); ap.apolloClient.mutate = _sinon2.default.spy(function () { return "result"; }); new _index2.default(ap); _context2.next = 6; return regeneratorRuntime.awrap(ap.loginWithEmailPassword('email', 'password')); case 6: ap.loginStart.should.have.been.calledBefore(ap.apolloClient); ap.apolloClient.mutate.should.have.been.calledWithMatch({ variables: { email: 'email', password: (0, _index.hashPassword)('password') } }); ap.loginComplete.should.have.been.calledAfter(ap.apolloClient.mutate); ap.loginComplete.should.have.been.calledWith("result", "apLoginEmailPassword"); case 10: case 'end': return _context2.stop(); } } }, null, undefined); }); it('updateUserPassword()', function _callee3() { var result; return regeneratorRuntime.async(function _callee3$(_context3) { while (1) { switch (_context3.prev = _context3.next) { case 0: ap.apolloClient.mutate = _sinon2.default.spy(function () { return "result"; }); new _index2.default(ap); _context3.next = 4; return regeneratorRuntime.awrap(ap.updateUserPassword('userId', 'oldPass', 'newPass')); case 4: result = _context3.sent; ap.apolloClient.mutate.should.have.been.calledWithMatch({ variables: { userId: 'userId', oldPassword: (0, _index.hashPassword)('oldPass'), newPassword: (0, _index.hashPassword)('newPass') } }); result.should.equal("result"); case 7: case 'end': return _context3.stop(); } } }, null, undefined); }); });