How to use the mongo-mock.max_delay function in mongo-mock

To help you get started, we’ve selected a few mongo-mock 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 swimlane / mongtype / tests / Repository.spec.ts View on Github external
import 'reflect-metadata';
import { MongoRepository } from '../src/Repository';
import { Collection, Before, After } from '../src/Decorators';
import { DatabaseClient } from '../src/DatabaseClient';
import * as mongoMock from 'mongo-mock';
mongoMock.max_delay = 0; // turn of fake async
import { expect } from 'chai';
import * as faker from 'faker';

describe('MongoRepository', () => {
  const dbs = [];

  // Make sure you close all DBs
  // Added this in case of error, CI tests are not hung open
  after(async () => {
    await Promise.all(dbs.map(db => db.close()));
  });

  function getDb(): Promise {
    return new Promise((resolve, reject) => {
      const dbc = new DatabaseClient();
      const MongoClient = mongoMock.MongoClient;
github devetry / mongo-schemer / index.js View on Github external
const Ajv = require('ajv');
const AjvBsonType = require('ajv-bsontype');
const MongoMock = require('mongo-mock');

const ajv = new Ajv({ allErrors: true });
AjvBsonType(ajv);

const MongoMockUrl = 'mongodb://localhost:27017/mongo-schemer';

MongoMock.max_delay = 0;

const validationErrors = async (db, collectionName, { doc, err }) => {
  const collectionInfo = await db.command({ listCollections: 1, filter: { name: collectionName } });
  const schema = collectionInfo.cursor.firstBatch[0].options.validator.$jsonSchema;
  if (!doc && err) {
    doc = ('op' in err) ? err.op : err.getOperation(); // eslint-disable-line no-param-reassign
  }
  const valid = ajv.validate(schema, doc);
  return { valid, errors: ajv.errors };
};

const explainSchemaErrors = (incomingDb, options = {}) => {
  const db = incomingDb;
  const { onError, includeValidationInError } = options;
  if (onError) {
    db.onValidationError = onError;
github DataFire / DataFire / test / integrations.js View on Github external
let expect = require('chai').expect;
let mongomock = require('mongo-mock');
mongomock.max_delay = 0;

let datafire = require('../index');
let locations = require('../lib/locations');
locations.integrations.push(__dirname + '/integrations');
locations.credentials = [__dirname + '/credentials'];

let mongo = datafire.Integration.new('mongodb').as('test');
mongo.client = mongomock.MongoClient;

describe('MongoDB Integration', () => {
  let executeSuccess = (flow, done) => {
    flow.execute(err => {
      if (err) throw err;
      done();
    });
  }

mongo-mock

Let's pretend we have a real MongoDB

MIT
Latest version published 2 years ago

Package Health Score

48 / 100
Full package analysis

Popular mongo-mock functions