1.2.2 • Published 9 years ago

mongoose-fixture-factory v1.2.2

Weekly downloads
1
License
ISC
Repository
github
Last release
9 years ago

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();
    });
  });
});
1.2.2

9 years ago

1.2.1

9 years ago

1.2.0

10 years ago

1.1.0

10 years ago

1.0.5

10 years ago

1.0.4

10 years ago

1.0.3

10 years ago

1.0.2

10 years ago

1.0.1

10 years ago

1.0.0

10 years ago