I have written the following method that searches for a user in the database by their email.
/**
* Find a user by providing their email address
*/
DataProvider.prototype.findUserByEmail = function(callback, email) {
console.log("in findUserByEmail");
User.findOne({
emailAddress : email
}, function(error, user) {
if(error) {
console.log(error);
callback(error);
}
else {
console.log(user);
callback(user);
}
});
};
I'm trying to test it with the following:
function testFindUserByEmail() {
var expectedEmail = "[email protected]";
data.findUserByEmail(function(user) {
if (user.emailAddress === expectedEmail) {
console.log("User found");
} else {
console.log("User not found");
}
console.log(user);
}, "[email protected]");
console.log("test");
}
I get an outout of: in findUserByEmail test
It's like User.findOne() isn't getting called and I don't know why. Other info:
var UserSchema = new Schema({
emailAddress : {
type : String
},
occupation : {
type : String
},
token : {
type : String
},
password : {
type : String
},
registrationDate : {
type : Date
},
activated : {
type : Boolean
}
});
/**
* Define Model
*/
var User = mongoose.model('User', UserSchema);
DataProvider = function() {
};