I have a MEAN stack application using Passport for authentication.
I am trying to write a unit test that logs into the system and checks if you are redirected to the root ( / ). However, whenever I start Mocha, I get the following error message:
1) POST /home Login test should redirect to / after login: Error: the string "Not a valid BCrypt hash." was thrown, throw an Error :)
Here is my unit test LoginSpec.js :
var should = require("should"); var app = require("../app"); var mongoose = require("mongoose"); var User = mongoose.model("User"); var request = require("supertest"); var agent = request.agent(app); ... describe('POST /home', function() { before(function(done) { user = new User({ email: " john@email.com ", firstName: "John", lastName: "Doe", password: "strongPassword", username: "johndoe" }); user.save(done); }) describe('Login test', function() { it ('should redirect to / after login', function(done) { agent.post('/login') .send({ username: 'johndoe', password: 'strongPassword' }) .end(function(err, res) { done(); }) }) after(function(done) { User.remove().exec(); return done(); }) }) })
Do I need a BCrype password? If so, how to do it?
Also, why are some of the online examples that I see for login not doing this? For example, NodeJS / Passport - checking user login with wet and superagent and How to authenticate Supertest requests with Passport?
source share