Created
April 17, 2013 13:41
-
-
Save warnero/5404395 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var dbURI = 'mongodb://xxx' | |
| , mongoose = require('mongoose') | |
| , clearDB = require('mocha-mongoose')(dbURI) | |
| ; | |
| var User = require("../models/user").User; | |
| var testUser = new User({ | |
| name: "Warner Onstine", | |
| email: "warner@test.com", | |
| phone: "520-555-5555", | |
| username: "warneronstine", | |
| password: 'password test' | |
| }); | |
| describe("Users", function(){ | |
| before(function(done) { | |
| options = {noClear: true}; | |
| if (mongoose.connection.db) return done(); | |
| mongoose.connect(dbURI, done); | |
| }); | |
| it("creates a new user", function(done){ | |
| testUser.save(function(err, doc){ | |
| if(err) return done(err); | |
| doc.name.should.equal("Warner Onstine"); | |
| done(); | |
| }); | |
| }); | |
| it("finds a user by email", function(done) { | |
| testUser.save(function(err, doc){ | |
| if(err) return done(err); | |
| doc.email.should.equal("warner@test.com"); | |
| var userQuery = User.findOne({'email': 'warner@test.com'}); | |
| userQuery.exec(function (err, user){ | |
| if(err) return done(err); | |
| user.name.should.equal("Warner Onstine"); | |
| done(); | |
| }); | |
| }); | |
| }); | |
| it("finds a user by username", function(done) { | |
| var userQuery = User.findOne({'username': 'warneronstine'}); | |
| userQuery.exec(function (err, user){ | |
| if(err) throw err; | |
| user.should.exist; | |
| user.name.should.equal("Warner Onstine"); | |
| done(); | |
| }); | |
| }); | |
| }); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment