61 lines
5.2 KiB
JavaScript
61 lines
5.2 KiB
JavaScript
"use strict";
|
|
require('typings-test');
|
|
const shelljs = require('shelljs');
|
|
const should = require('should');
|
|
const smartstring = require('smartstring');
|
|
// the tested module
|
|
const smartdata = require('../dist/index');
|
|
let mongoChildProcess;
|
|
let testDbConnection;
|
|
let testDbCollection;
|
|
describe('mongodb', function () {
|
|
it('should start mongodb', function (done) {
|
|
this.timeout(30000);
|
|
mongoChildProcess = shelljs.exec('mongod --dbpath=./test/data --port 27017', { async: true, silent: true });
|
|
let doneCalled = false;
|
|
mongoChildProcess.stdout.on('data', function (data) {
|
|
console.log(smartstring.indent.indentWithPrefix(data, "*** MongoDB Process *** : "));
|
|
if (!doneCalled) {
|
|
if (/waiting for connections on port 27017/.test(data)) {
|
|
doneCalled = true;
|
|
done();
|
|
}
|
|
}
|
|
});
|
|
});
|
|
});
|
|
describe('smartdata', function () {
|
|
it('should establish a connection to mongodb', function (done) {
|
|
testDbConnection = new smartdata.DbConnection('mongodb://localhost:27017/smartdata');
|
|
testDbConnection.connect().then(() => { done(); });
|
|
});
|
|
it('should create a collection', function () {
|
|
testDbCollection = new smartdata.DbCollection('something', testDbConnection);
|
|
});
|
|
it('should insert something into the collection', function (done) {
|
|
testDbCollection.insertOne({ hello: 'test' }).then(() => { done(); });
|
|
});
|
|
it('should find all instances of test', function (done) {
|
|
testDbCollection.find({}).then((resultArray) => {
|
|
console.log(resultArray);
|
|
should(resultArray[0].hello).equal('test');
|
|
done();
|
|
});
|
|
});
|
|
it('should close the db Connection', function () {
|
|
testDbConnection.close();
|
|
});
|
|
});
|
|
describe('mongodb', function () {
|
|
it('should kill mongodb', function (done) {
|
|
this.timeout(30000);
|
|
mongoChildProcess.stdout.on('data', function (data) {
|
|
if (/dbexit: rc: 0/.test(data)) {
|
|
done();
|
|
}
|
|
});
|
|
shelljs.exec('mongod --dbpath=./test/data --shutdown');
|
|
mongoChildProcess.kill('SIGTERM');
|
|
});
|
|
});
|
|
//# sourceMapp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