authelia/test/unit/server/connectors/mongo/MongoClient.test.ts
2017-07-31 00:29:00 +02:00

39 lines
1.1 KiB
TypeScript

import Assert = require("assert");
import Sinon = require("sinon");
import MongoDB = require("mongodb");
import { MongoClient } from "../../../../../src/server/lib/connectors/mongo/MongoClient";
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 ));
});
});
});