YouAndWeb_TwoToc
a98e8d4c8be3c9266abcdd007f47a6b1c3ed9599
YouAndWeb_TwoToc / .fr-KzWVa7 / twotoc / server / api / user / user.model.spec.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
'use strict'; var app = require('../..'); var User = require('./user.model'); var user; var genUser = function() { user = new User({ provider: 'local', name: 'Fake User', email: 'test@example.com', password: 'password' }); return user; }; describe('User Model', function() { before(function() { // Clear users before testing return User.removeAsync(); }); beforeEach(function() { genUser(); }); afterEach(function() { return User.removeAsync(); }); it('should begin with no users', function() { return User.findAsync({}).should .eventually.have.length(0); }); it('should fail when saving a duplicate user', function() { return user.saveAsync() .then(function() { var userDup = genUser(); return userDup.saveAsync(); }).should.be.rejected; }); describe('#email', function() { it('should fail when saving without an email', function() { user.email = ''; return user.saveAsync().should.be.rejected; }); }); describe('#password', function() { beforeEach(function() { return user.saveAsync(); }); it('should authenticate user if valid', function() { user.authenticate('password').should.be.true; }); it('should not authenticate user if invalid', function() { user.authenticate('blah').should.not.be.true; }); it('should remain the same hash unless the password is updated', function() { user.name = 'Test User'; return user.saveAsync() .spread(function(u) { return u.authenticate('password'); }).should.eventually.be.true; }); }); }); |
Commits for YouAndWeb_TwoToc.fr-KzWVa7/twotoc/server/api/user/user.model.spec.js
Revision | Author | Commited | Message |
---|---|---|---|
a98e8d ... | FSinnona | Thu 26 Nov, 2015 13:26:45 +0000 | Creazione organizza |