daily pastebin goal
11%
SHARE
TWEET

Untitled

a guest Jul 21st, 2017 445 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. 1) POST /home Login test should redirect to / after login:
  2.    Error: the string "Not a valid BCrypt hash." was thrown, throw an Error :)
  3.    
  4. var should = require("should");
  5. var app = require("../app");
  6. var mongoose = require("mongoose");
  7. var User = mongoose.model("User");
  8. var request = require("supertest");
  9. var agent = request.agent(app);
  10. ...
  11. describe('POST /home', function() {
  12.     before(function(done) {
  13.         user = new User({
  14.             email: "john@email.com",
  15.             firstName: "John",
  16.             lastName: "Doe",
  17.             password: "strongPassword",
  18.             username: "johndoe"
  19.         });
  20.  
  21.         user.save(done);
  22.     })
  23.  
  24.     describe('Login test', function() {
  25.         it ('should redirect to / after login', function(done) {
  26.             agent.post('/login')
  27.                 .send({
  28.                     username: 'johndoe',
  29.                     password: 'strongPassword'
  30.                 })
  31.                 .end(function(err, res) {
  32.                     done();
  33.                 })
  34.         })
  35.  
  36.         after(function(done) {
  37.             User.remove().exec();
  38.             return done();
  39.         })
  40.     })
  41. })
  42.    
  43. UserSchema.methods.encryptPassword = function(password) {
  44.     return bcrypt.hashSync(password, bcrypt.genSaltSync(10));
  45. }
  46.  
  47. UserSchema.methods.validPassword = function(password) {
  48.     return bcrypt.compareSync(password, this.password);
  49. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top