This package has been deprecated

Author message:

Unmaintained

mongoose-fixture-factory

1.2.2 • Public • Published

Mongoose Fixture Factory

Automate filling, flushing and replacing of database documents for testing purposes

Version npmSupport via GratipayNPM DownloadsBuild StatusDependencies

Install

NPM

Documentation

register(model, fixtures)

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

fill(cb)

Flush all registered collections, then insert the respective fixtures

flush(cb)

Flush all registered collections

Example

// .
// ├── 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();
    });
  });
});

Package Sidebar

Install

npm i mongoose-fixture-factory

Weekly Downloads

9

Version

1.2.2

License

ISC

Last publish

Collaborators

  • bajix