2016-09-11 14:22:53 +00:00
|
|
|
"use strict";
|
|
|
|
require('typings-test');
|
|
|
|
const shelljs = require('shelljs');
|
2016-09-12 16:14:01 +00:00
|
|
|
const should = require('should');
|
2016-09-12 15:31:23 +00:00
|
|
|
const smartstring = require('smartstring');
|
2016-09-12 12:45:08 +00:00
|
|
|
// the tested module
|
2016-09-11 14:22:53 +00:00
|
|
|
const smartdata = require('../dist/index');
|
|
|
|
let mongoChildProcess;
|
|
|
|
let testDbConnection;
|
2016-09-11 16:01:46 +00:00
|
|
|
let testDbCollection;
|
2016-09-11 14:22:53 +00:00
|
|
|
describe('mongodb', function () {
|
|
|
|
it('should start mongodb', function (done) {
|
2016-09-12 16:14:01 +00:00
|
|
|
this.timeout(30000);
|
2016-09-12 12:45:08 +00:00
|
|
|
mongoChildProcess = shelljs.exec('mongod --dbpath=./test/data --port 27017', { async: true, silent: true });
|
|
|
|
let doneCalled = false;
|
|
|
|
mongoChildProcess.stdout.on('data', function (data) {
|
2016-09-12 15:31:23 +00:00
|
|
|
console.log(smartstring.indent.indentWithPrefix(data, "*** MongoDB Process *** : "));
|
2016-09-12 12:45:08 +00:00
|
|
|
if (!doneCalled) {
|
|
|
|
if (/waiting for connections on port 27017/.test(data)) {
|
|
|
|
doneCalled = true;
|
|
|
|
done();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2016-09-11 14:22:53 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
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 () {
|
2016-09-11 16:01:46 +00:00
|
|
|
testDbCollection = new smartdata.DbCollection('something', testDbConnection);
|
2016-09-11 14:22:53 +00:00
|
|
|
});
|
2016-09-12 19:36:26 +00:00
|
|
|
it('should insert a doc into the collection', function (done) {
|
2016-09-12 16:14:01 +00:00
|
|
|
testDbCollection.insertOne({ hello: 'test' }).then(() => { done(); });
|
|
|
|
});
|
2016-09-12 19:36:26 +00:00
|
|
|
it('should find all docs of testDbCollection', function (done) {
|
2016-09-12 16:14:01 +00:00
|
|
|
testDbCollection.find({}).then((resultArray) => {
|
|
|
|
console.log(resultArray);
|
|
|
|
should(resultArray[0].hello).equal('test');
|
|
|
|
done();
|
|
|
|
});
|
2016-09-12 15:31:23 +00:00
|
|
|
});
|
2016-09-12 19:36:26 +00:00
|
|
|
it('should insert many docs into the collection', function (done) {
|
|
|
|
testDbCollection.insertMany([
|
|
|
|
{ hello: 'test' },
|
|
|
|
{ wow: 'what is this', wow2: 3 }
|
|
|
|
]).then(() => { done(); });
|
|
|
|
});
|
|
|
|
it('should find a specified doc', function (done) {
|
|
|
|
testDbCollection.find({ 'wow2': { '$exists': true } }).then((resultArray) => {
|
|
|
|
console.log(resultArray);
|
|
|
|
should(resultArray[0].wow2).equal(3);
|
|
|
|
done();
|
|
|
|
}).catch(console.log);
|
|
|
|
});
|
2016-09-11 14:22:53 +00:00
|
|
|
it('should close the db Connection', function () {
|
|
|
|
testDbConnection.close();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
describe('mongodb', function () {
|
2016-09-12 16:14:01 +00:00
|
|
|
it('should kill mongodb', function (done) {
|
|
|
|
this.timeout(30000);
|
|
|
|
mongoChildProcess.stdout.on('data', function (data) {
|
|
|
|
if (/dbexit: rc: 0/.test(data)) {
|
|
|
|
done();
|
|
|
|
}
|
|
|
|
});
|
2016-09-11 14:48:08 +00:00
|
|
|
shelljs.exec('mongod --dbpath=./test/data --shutdown');
|
2016-09-11 14:44:36 +00:00
|
|
|
mongoChildProcess.kill('SIGTERM');
|
2016-09-11 14:22:53 +00:00
|
|
|
});
|
|
|
|
});
|
2016-09-12 19:36:26 +00:00
|
|
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGVzdC5qcyIsInNvdXJjZVJv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