Skip to content
This repository has been archived by the owner on May 2, 2024. It is now read-only.

Bajix/mongoose-fixture-factory

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

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

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published