2017-07-20 02:06:12 +07:00
|
|
|
import Assert = require("assert");
|
|
|
|
import Sinon = require("sinon");
|
|
|
|
import MongoDB = require("mongodb");
|
2017-10-07 05:09:42 +07:00
|
|
|
import { MongoClient } from "../../../src/lib/connectors/mongo/MongoClient";
|
2017-07-20 02:06:12 +07:00
|
|
|
|
|
|
|
describe("MongoClient", function () {
|
|
|
|
let mongoClientConnectStub: Sinon.SinonStub;
|
|
|
|
let mongoDatabase: any;
|
|
|
|
let mongoDatabaseCollectionStub: Sinon.SinonStub;
|
|
|
|
|
|
|
|
describe("collection", function () {
|
|
|
|
before(function () {
|
|
|
|
mongoDatabaseCollectionStub = Sinon.stub();
|
|
|
|
mongoDatabase = {
|
|
|
|
collection: mongoDatabaseCollectionStub
|
|
|
|
};
|
|
|
|
|
|
|
|
mongoClientConnectStub = Sinon.stub(MongoDB.MongoClient, "connect");
|
|
|
|
mongoClientConnectStub.yields(undefined, mongoDatabase);
|
|
|
|
});
|
|
|
|
|
|
|
|
after(function () {
|
|
|
|
mongoClientConnectStub.restore();
|
|
|
|
});
|
|
|
|
|
|
|
|
it("should create a collection", function () {
|
|
|
|
const COLLECTION_NAME = "mycollection";
|
|
|
|
const client = new MongoClient(mongoDatabase);
|
|
|
|
|
|
|
|
mongoDatabaseCollectionStub.returns({});
|
|
|
|
|
|
|
|
const collection = client.collection(COLLECTION_NAME);
|
|
|
|
|
|
|
|
Assert(collection);
|
|
|
|
Assert(mongoDatabaseCollectionStub.calledWith(COLLECTION_NAME ));
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|