smartdata/test/test.ts

70 lines
1.6 KiB
TypeScript
Raw Normal View History

2017-06-18 17:52:54 +00:00
import { tap, expect } from 'tapbundle'
import * as smartq from 'smartq'
import { Qenv } from 'qenv'
let testQenv = new Qenv(process.cwd(), process.cwd() + '/.nogit/')
2016-09-11 14:22:53 +00:00
// the tested module
2017-09-13 11:47:38 +00:00
import * as smartdata from '../ts/index'
import { smartstring } from '../ts/smartdata.plugins';
2016-09-11 14:22:53 +00:00
// =======================================
// Connecting to the database server
// =======================================
2016-09-12 20:11:17 +00:00
let testDb = new smartdata.Db({
db: process.env.RDB_DB,
host: process.env.RDB_HOST,
user: process.env.RDB_USER,
password: process.env.RDB_PASS,
port: parseInt(process.env.RDB_PORT)
})
testDb.setSsl(process.env.RDB_CERT, 'base64')
2016-09-12 20:11:17 +00:00
tap.test('should establish a connection to the rethink Db cluster', async () => {
2017-06-18 17:52:54 +00:00
await testDb.connect()
2016-09-11 14:22:53 +00:00
})
2016-09-12 20:11:17 +00:00
// =======================================
// The actual tests
// =======================================
2017-11-16 13:23:06 +00:00
// ------
// Collections
// ------
2017-06-18 17:52:54 +00:00
@smartdata.Table(testDb)
class Car extends smartdata.DbDoc<Car> {
@smartdata.svDb() color: string
@smartdata.svDb() brand: string
constructor (colorArg: string, brandArg: string) {
super()
this.color = colorArg
this.brand = brandArg
}
}
tap.test('should save the car to the db', async () => {
const myCar = new Car('red','Volvo')
await myCar.save()
2016-09-11 14:22:53 +00:00
})
tap.test('expect to get instance of Car', async () => {
let myCar = await Car.getInstances<Car>({
brand: 'Volvo'
})
expect(myCar[0].color).to.equal('red')
})
2016-11-17 21:36:12 +00:00
// =======================================
// close the database connection
// =======================================
tap.test('should close the database connection', async (tools) => {
await testDb.close()
2016-11-17 21:36:12 +00:00
})
2017-06-18 17:52:54 +00:00
tap.start()