2017-06-18 17:52:54 +00:00
|
|
|
import { tap, expect } from 'tapbundle'
|
|
|
|
import * as smartq from 'smartq'
|
2017-06-23 09:40:20 +00:00
|
|
|
import { Qenv } from 'qenv'
|
|
|
|
|
|
|
|
let testQenv = new Qenv(process.cwd(), process.cwd() + '/.nogit/')
|
2016-09-11 14:22:53 +00:00
|
|
|
|
2016-09-12 12:45:08 +00:00
|
|
|
// the tested module
|
2017-09-13 11:47:38 +00:00
|
|
|
import * as smartdata from '../ts/index'
|
2018-01-12 00:22:58 +00:00
|
|
|
import { smartstring } from '../ts/smartdata.plugins';
|
2016-09-11 14:22:53 +00:00
|
|
|
|
2018-01-12 00:22:58 +00:00
|
|
|
// =======================================
|
|
|
|
// Connecting to the database server
|
|
|
|
// =======================================
|
2016-09-12 20:11:17 +00:00
|
|
|
|
2018-01-12 00:22:58 +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
|
|
|
|
2018-01-12 00:22:58 +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
|
|
|
|
2017-06-23 09:40:20 +00:00
|
|
|
// =======================================
|
|
|
|
// The actual tests
|
|
|
|
// =======================================
|
|
|
|
|
2017-11-16 13:23:06 +00:00
|
|
|
// ------
|
|
|
|
// Collections
|
|
|
|
// ------
|
2017-06-18 17:52:54 +00:00
|
|
|
|
2018-01-14 16:32:04 +00:00
|
|
|
@smartdata.Table(testDb)
|
2018-01-12 00:22:58 +00:00
|
|
|
class Car extends smartdata.DbDoc<Car> {
|
2018-01-14 16:32:04 +00:00
|
|
|
|
2018-01-12 00:22:58 +00:00
|
|
|
@smartdata.svDb() color: string
|
|
|
|
@smartdata.svDb() brand: string
|
|
|
|
constructor (colorArg: string, brandArg: string) {
|
|
|
|
super()
|
|
|
|
this.color = colorArg
|
|
|
|
this.brand = brandArg
|
|
|
|
}
|
|
|
|
}
|
2016-09-13 23:02:11 +00:00
|
|
|
|
2018-01-12 00:22:58 +00:00
|
|
|
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
|
|
|
})
|
|
|
|
|
2018-01-14 16:32:04 +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
|
|
|
|
2018-01-12 00:22:58 +00:00
|
|
|
// =======================================
|
|
|
|
// close the database connection
|
|
|
|
// =======================================
|
|
|
|
tap.test('should close the database connection', async (tools) => {
|
2017-06-23 09:40:20 +00:00
|
|
|
await testDb.close()
|
2016-11-17 21:36:12 +00:00
|
|
|
})
|
2017-06-18 17:52:54 +00:00
|
|
|
|
|
|
|
tap.start()
|