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;
|
2016-09-12 21:50:25 +00:00
|
|
|
let testDb;
|
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-13 20:53:21 +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) {
|
2016-09-12 21:50:25 +00:00
|
|
|
testDb = new smartdata.Db('mongodb://localhost:27017/smartdata');
|
|
|
|
testDb.connect().then(() => { done(); });
|
2016-09-11 14:22:53 +00:00
|
|
|
});
|
|
|
|
it('should create a collection', function () {
|
2016-09-12 21:50:25 +00:00
|
|
|
testDbCollection = new smartdata.DbCollection('something', testDb);
|
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 20:11:17 +00:00
|
|
|
testDbCollection.insertOne({ value1: 'test' }).then(() => { done(); });
|
2016-09-12 16:14:01 +00:00
|
|
|
});
|
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);
|
2016-09-12 20:11:17 +00:00
|
|
|
should(resultArray[0].value1).equal('test');
|
2016-09-12 16:14:01 +00:00
|
|
|
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([
|
2016-09-12 20:11:17 +00:00
|
|
|
{ value1: 'test2' },
|
|
|
|
{ value1: 'test', value2: 3, value3: 'hi' }
|
2016-09-12 19:36:26 +00:00
|
|
|
]).then(() => { done(); });
|
|
|
|
});
|
|
|
|
it('should find a specified doc', function (done) {
|
2016-09-12 20:11:17 +00:00
|
|
|
testDbCollection.find({ 'value3': { '$exists': true } }).then((resultArray) => {
|
2016-09-12 19:36:26 +00:00
|
|
|
console.log(resultArray);
|
2016-09-12 20:11:17 +00:00
|
|
|
should(resultArray[0].value3).equal('hi');
|
2016-09-12 19:36:26 +00:00
|
|
|
done();
|
|
|
|
}).catch(console.log);
|
|
|
|
});
|
2016-09-11 14:22:53 +00:00
|
|
|
it('should close the db Connection', function () {
|
2016-09-12 21:50:25 +00:00
|
|
|
testDb.close();
|
2016-09-11 14:22:53 +00:00
|
|
|
});
|
2016-09-13 20:53:21 +00:00
|
|
|
it('should create an extended class', function () {
|
|
|
|
class TestCar extends smartdata.DbDoc {
|
|
|
|
constructor(optionsArg) {
|
|
|
|
super('testCar', testDb);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
;
|
|
|
|
let testCarInstance = new TestCar({
|
|
|
|
color: 'red',
|
|
|
|
property2: 2
|
|
|
|
});
|
|
|
|
should(testCarInstance).be.instanceof(smartdata.DbDoc);
|
|
|
|
testCarInstance.save();
|
|
|
|
it('should get a collection for testCar', function () {
|
|
|
|
});
|
|
|
|
});
|
2016-09-11 14:22:53 +00:00
|
|
|
});
|
|
|
|
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-13 20:53:21 +00:00
|
|
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGVzdC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbInRlc3QudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLFFBQU8sY0FFUCxDQUFDLENBRm9CO0FBRXJCLE1BQVksT0FBTyxXQUFNLFNBQ3pCLENBQUMsQ0FEaUM7QUFDbEMsTUFBWSxNQUFNLFdBQU0sUUFDeEIsQ0FBQyxDQUQrQjtBQUNoQyxNQUFZLFdBQVcsV0FBTSxhQUc3QixDQUFDLENBSHlDO0FBRTFDLG9CQUFvQjtBQUNwQixNQUFZLFNBQVMsV0FBTSxlQUUzQixDQUFDLENBRnlDO0FBRTFDLElBQUksaUJBQWlCLENBQUE7QUFDckIsSUFBSSxNQUFvQixDQUFBO0FBUXhCLElBQUksZ0JBQXNELENBQUE7QUFJMUQsUUFBUSxDQUFDLFNBQVMsRUFBRTtJQUNoQixFQUFFLENBQUMsc0JBQXNCLEVBQUUsVUF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