2017-06-18 17:52:54 +00:00
|
|
|
import { tap, expect } from 'tapbundle'
|
|
|
|
import * as smartq from 'smartq'
|
2016-09-11 14:22:53 +00:00
|
|
|
|
2016-09-12 12:45:08 +00:00
|
|
|
// the tested module
|
|
|
|
import * as smartdata from '../dist/index'
|
2016-09-11 14:22:53 +00:00
|
|
|
|
|
|
|
let mongoChildProcess
|
2016-09-12 21:50:25 +00:00
|
|
|
let testDb: smartdata.Db
|
2016-09-12 20:11:17 +00:00
|
|
|
|
|
|
|
interface ITestObject1 {
|
2017-02-25 10:37:05 +00:00
|
|
|
value1: string
|
|
|
|
value2?: number
|
|
|
|
value3?: string
|
2016-09-12 20:11:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
let testDbCollection: smartdata.DbCollection<ITestObject1>
|
|
|
|
|
2017-06-18 17:52:54 +00:00
|
|
|
tap.test('should establish a connection to mongodb', async () => {
|
|
|
|
testDb = new smartdata.Db('mongodb://localhost:27017/smartdata')
|
|
|
|
await testDb.connect()
|
2016-09-11 14:22:53 +00:00
|
|
|
})
|
2016-09-12 20:11:17 +00:00
|
|
|
|
2017-06-18 17:52:54 +00:00
|
|
|
tap.test('should insert a doc into the collection', async () => {
|
|
|
|
await testDbCollection.insertOne({ value1: 'test' })
|
|
|
|
})
|
|
|
|
|
|
|
|
tap.test('should find all docs of testDbCollection', async () => {
|
|
|
|
await testDbCollection.find({}).then(async (resultArray) => {
|
|
|
|
console.log(resultArray)
|
|
|
|
expect(resultArray[ 0 ].value1).equal('test')
|
2017-02-25 10:37:05 +00:00
|
|
|
})
|
2017-06-18 17:52:54 +00:00
|
|
|
})
|
2016-11-17 23:42:25 +00:00
|
|
|
|
2017-06-18 17:52:54 +00:00
|
|
|
tap.test('should insert many docs into the collection', async () => {
|
|
|
|
await testDbCollection.insertMany([
|
|
|
|
{ value1: 'test2' },
|
|
|
|
{ value1: 'test', value2: 3, value3: 'hi' }
|
|
|
|
])
|
|
|
|
})
|
2016-09-13 23:02:11 +00:00
|
|
|
|
2017-06-18 17:52:54 +00:00
|
|
|
tap.test('should find a specified doc', async () => {
|
|
|
|
await testDbCollection.find({ 'value3': { '$exists': true } }).then((resultArray) => {
|
|
|
|
console.log(resultArray)
|
|
|
|
expect(resultArray[ 0 ].value3).equal('hi')
|
2017-02-25 10:37:05 +00:00
|
|
|
})
|
2016-09-11 14:22:53 +00:00
|
|
|
})
|
|
|
|
|
2017-06-18 17:52:54 +00:00
|
|
|
tap.test('should close the db Connection', async () => {
|
|
|
|
testDb.close()
|
2016-09-11 14:22:53 +00:00
|
|
|
})
|
2016-11-17 21:36:12 +00:00
|
|
|
|
2017-06-18 17:52:54 +00:00
|
|
|
tap.test('should create an extended class', async () => {
|
|
|
|
@smartdata.Collection(testDb)
|
|
|
|
class TestCar extends smartdata.DbDoc<TestCar> {
|
|
|
|
@smartdata.svDb()
|
|
|
|
color: string
|
|
|
|
constructor (optionsArg: {
|
|
|
|
color: string,
|
|
|
|
property2: number
|
|
|
|
}) {
|
|
|
|
super('TestCar')
|
|
|
|
this.color = optionsArg.color
|
|
|
|
}
|
|
|
|
}
|
|
|
|
let testCarInstance = new TestCar({
|
|
|
|
color: 'red',
|
|
|
|
property2: 2
|
2017-02-25 10:37:05 +00:00
|
|
|
})
|
2016-11-17 21:36:12 +00:00
|
|
|
|
2017-06-18 17:52:54 +00:00
|
|
|
expect(testCarInstance.saveableProperties[ 0 ]).equal('color')
|
|
|
|
console.log(TestCar)
|
|
|
|
expect(testCarInstance.collection).be.instanceof(smartdata.DbCollection)
|
|
|
|
expect(testCarInstance).be.instanceof(smartdata.DbDoc)
|
|
|
|
testCarInstance.save()
|
|
|
|
})
|
2016-11-17 21:36:12 +00:00
|
|
|
|
2017-06-18 17:52:54 +00:00
|
|
|
tap.test('should get a collection for testCar', async () => {
|
|
|
|
//
|
2016-11-17 21:36:12 +00:00
|
|
|
})
|
2017-06-18 17:52:54 +00:00
|
|
|
|
|
|
|
tap.start()
|