How to use @lykmapipo/mongoose-test-helpers - 10 common examples

To help you get started, we’ve selected a few @lykmapipo/mongoose-test-helpers examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github lykmapipo / mongoose-gridfs / test / model.spec.js View on Github external
it('should create gridfs model with plugins', () => {
    const Image = createModel({ modelName: 'Image' }, (schema) => {
      schema.statics.stats = (optns, done) => done(null, optns);
    });

    expect(Image).to.exist;
    expect(Image.schema).to.exist;
    expect(Image.modelName).to.be.equal('Image');
    expect(Image.collection.name).to.be.equal('images.files');
    expect(Image.stats).to.exist.and.be.a('function');
  });
github lykmapipo / mongoose-rest-actions / test / unit / index.spec.js View on Github external
it('should be able to hide default properties', () => {
    let user = User.fake();
    user = user.toObject();

    expect(user).to.exist;
    expect(user.name).to.exist;
    expect(user.password).to.not.exist;
  });
github lykmapipo / mongoose-rest-actions / test / unit / get.spec.js View on Github external
it('should work using `get` static method', done => {

    const User = createTestModel({}, schema => {
      schema.statics.beforeGet = (options, done) => done();
      schema.statics.afterGet = (options, results, done) => done();
    }, searchable, get);

    const options = { page: 1, limit: 10 };
    const results = {
      data: [User.fake()],
      total: 100,
      size: 1,
      limit: 10,
      skip: 0,
      page: 1,
      pages: 10,
      lastModified: new Date()
    };
github lykmapipo / mongoose-rest-actions / test / unit / get.spec.js View on Github external
it('should work using `getById` static method', done => {

    const User = createTestModel({}, schema => {
      schema.statics.beforeGetById = (done) => done();
      schema.statics.afterGetById = (instance, done) => done();
    }, get);
    const user = User.fake();

    const Mock = mockModel(User);
    const findById = Mock.expects('findById');
    const exec = findById.chain('exec').yields(null, user);
    const beforeGetById = sinon.spy(User, 'beforeGetById');
    const afterGetById = sinon.spy(User, 'afterGetById');

    User.getById(user._id, (error, found) => {
      Mock.verify();
      Mock.restore();

      expect(findById).to.have.been.calledOnce;
github lykmapipo / mongoose-rest-actions / test / unit / index.spec.js View on Github external
describe('index', () => {

  const User = createTestModel({
    name: { type: String, fake: f => f.name.findName() },
    address: { type: String, hide: true, fake: f => f.address.streetAddress() },
    password: { type: String, fake: f => f.internet.password() }
  }, actions);

  it('should be able to generate fake instance', () => {
    expect(User.fake).to.exist;
    expect(User.fake).to.be.a('function');

    const user = User.fake();
    expect(user).to.exist;
    expect(user.name).to.exist;
    expect(user.password).to.exist;
  });

  it('should be able to hide default properties', () => {
github lykmapipo / mongoose-rest-actions / test / unit / patch.spec.js View on Github external
it('should work using `patch` instance method', done => {

    const User = createTestModel({}, schema => {
      schema.methods.beforePatch = (updates, done) => done();
      schema.methods.afterPatch = (updates, done) => done();
    }, patch);
    const user = User.fake();

    const mock = mockInstance(user);

    const save = mock.expects('save').yields(null, user);
    const beforePatch = sinon.spy(user, 'beforePatch');
    const afterPatch = sinon.spy(user, 'afterPatch');

    const updates = _.pick(User.fake(), 'name');
    user.patch(updates, (error, updated) => {
      mock.verify();
      mock.restore();
github lykmapipo / mongoose-rest-actions / test / unit / post.spec.js View on Github external
it('should work using `post` static method', done => {

    const User = createTestModel({}, schema => {
      schema.methods.beforePost = done => done();
      schema.methods.afterPost = done => done();
    }, post);
    const user = User.fake();

    const mock = mockInstance(user);

    const save = mock.expects('save').yields(null, user);
    const beforePost = sinon.spy(user, 'beforePost');
    const afterPost = sinon.spy(user, 'afterPost');

    User.post(user, (error, created) => {
      mock.verify();
      mock.restore();

      expect(save).to.have.been.calledOnce;
github lykmapipo / mongoose-rest-actions / test / integration / post.spec.js View on Github external
describe('post', () => {

  const Guardian = createTestModel({
    email: { type: String, unique: true, fake: f => f.internet.email() }
  }, actions);

  const Child = createTestModel({
    email: { type: String, unique: true, fake: f => f.internet.email() },
    father: { type: ObjectId, ref: Guardian.modelName }
  }, actions);

  let father = Guardian.fake();

  before(done => clear(Guardian, Child, done));

  before(done => create(father, done));

  it('should work using `post` static method', done => {
    const guardian = Guardian.fake();
    Guardian.post(guardian.toObject(), (error, created) => {
      expect(error).to.not.exist;
      expect(created).to.exist;
      expect(created._id).to.exist.and.be.eql(guardian._id);
github lykmapipo / mongoose-rest-actions / test / unit / post.spec.js View on Github external
it('should work using `post` instance method', done => {

    const User = createTestModel({}, schema => {
      schema.methods.beforePost = done => done();
      schema.methods.afterPost = done => done();
    }, post);
    const user = User.fake();

    const mock = mockInstance(user);

    const save = mock.expects('save').yields(null, user);
    const beforePost = sinon.spy(user, 'beforePost');
    const afterPost = sinon.spy(user, 'afterPost');

    user.post((error, created) => {
      mock.verify();
      mock.restore();

      expect(save).to.have.been.calledOnce;
github lykmapipo / mongoose-rest-actions / test / unit / put.spec.js View on Github external
it('should work using `put` static method with filter', done => {

    const User = createTestModel({}, schema => {
      schema.methods.beforePut = (updates, done) => done();
      schema.methods.afterPut = (updates, done) => done();
    }, put);
    const user = User.fake();

    const Mock = mockModel(User);
    const mock = mockInstance(user);

    const findById = Mock.expects('findById');
    const where = findById.chain('where');
    const exec = findById.chain('exec').yields(null, user);
    const save = mock.expects('save').yields(null, user);
    const beforePut = sinon.spy(user, 'beforePut');
    const afterPut = sinon.spy(user, 'afterPut');

    const updates = _.pick(User.fake(), 'name');