2016-09-11 14:22:53 +00:00
|
|
|
"use strict";
|
2016-09-13 23:02:11 +00:00
|
|
|
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
|
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
|
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
|
|
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
|
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
|
|
};
|
2016-11-17 11:20:52 +00:00
|
|
|
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
|
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
|
|
};
|
2017-02-25 10:37:05 +00:00
|
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
2016-11-17 11:20:52 +00:00
|
|
|
require("typings-test");
|
|
|
|
const shelljs = require("shelljs");
|
|
|
|
const should = require("should");
|
|
|
|
const smartstring = require("smartstring");
|
2016-09-12 12:45:08 +00:00
|
|
|
// the tested module
|
2016-11-17 11:20:52 +00:00
|
|
|
const smartdata = require("../dist/index");
|
2016-09-11 14:22:53 +00:00
|
|
|
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 () {
|
2016-09-13 23:02:11 +00:00
|
|
|
let TestCar = class TestCar extends smartdata.DbDoc {
|
2016-09-13 20:53:21 +00:00
|
|
|
constructor(optionsArg) {
|
2016-09-13 23:02:11 +00:00
|
|
|
super();
|
|
|
|
this.color = optionsArg.color;
|
2016-09-13 20:53:21 +00:00
|
|
|
}
|
2016-09-13 23:02:11 +00:00
|
|
|
};
|
2016-11-17 23:42:25 +00:00
|
|
|
__decorate([
|
2016-11-18 12:56:15 +00:00
|
|
|
smartdata.svDb(),
|
2016-11-17 23:42:25 +00:00
|
|
|
__metadata("design:type", String)
|
|
|
|
], TestCar.prototype, "color", void 0);
|
2016-09-13 23:02:11 +00:00
|
|
|
TestCar = __decorate([
|
2016-11-17 11:20:52 +00:00
|
|
|
smartdata.Collection(testDb),
|
|
|
|
__metadata("design:paramtypes", [Object])
|
2016-09-13 23:02:11 +00:00
|
|
|
], TestCar);
|
2016-09-13 20:53:21 +00:00
|
|
|
;
|
|
|
|
let testCarInstance = new TestCar({
|
|
|
|
color: 'red',
|
|
|
|
property2: 2
|
|
|
|
});
|
2016-11-17 23:42:25 +00:00
|
|
|
should(testCarInstance.saveableProperties[0]).equal('color');
|
2016-11-17 11:20:52 +00:00
|
|
|
console.log(TestCar);
|
2016-09-13 23:02:11 +00:00
|
|
|
should(testCarInstance.collection).be.instanceof(smartdata.DbCollection);
|
2016-09-13 20:53:21 +00:00
|
|
|
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-11-17 21:36:12 +00:00
|
|
|
describe('smartdata with nedb', function () {
|
|
|
|
let testDb;
|
|
|
|
let testCollection;
|
|
|
|
it('should create a DB with nedb', function () {
|
|
|
|
testDb = new smartdata.Db('any', 'nedb');
|
|
|
|
testDb.connect();
|
|
|
|
testCollection = new smartdata.DbCollection('anyName', testDb);
|
|
|
|
});
|
|
|
|
it('should insert a doc', function (done) {
|
|
|
|
testCollection.insertOne({ value1: 'hi' }).then(() => { done(); });
|
|
|
|
});
|
|
|
|
it('should find the inserted document', function (done) {
|
|
|
|
testCollection.find({ value1: 'hi' }).then(x => {
|
|
|
|
console.log(x);
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2017-02-25 10:37:05 +00:00
|
|
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGVzdC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbInRlc3QudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7Ozs7Ozs7Ozs7QUFBQSx3Q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