Automate filling, flushing and replacing of database documents for testing purposes
Register a model and it's respective fixtures to be included when calling flush or fill.
model
{Function}
Mongoose Model constructor.
fixtures
{Array}
Stub data
Flush all registered collections, then insert the respective fixtures
Flush all registered collections
// .
// ├── test
// │ ├── unit
// │ └── ...
// │ ├── mocha.opts
// │ └── suite.js
// Suite
process.env.NODE_ENV = 'test';
var fixtures = require('fixtures'),
Factory = require('factory'),
models = require('models');
Factory.register(models, fixtures); // Convience syntax.
/*
// Manually calling register on each model/fixture pair.
//
// Factory.register(models.Page, fixtures.Page);
// Factory.register(models.User, fixtures.User);
//
*/
// Auth test
describe('Passwords', function() {
before(Factory.flush);
it('hashes passwords', function( done ) {
var user = new User(fixture);
user.password = 'password';
user.save(function( err, user ) {
if (err) {
return done(err);
}
assert.lengthOf(user.password, 60);
assert.equal(user.password.indexOf('$2a$10$'), 0);
done();
});
});
});