2018-07-08 21:48:14 +00:00
|
|
|
import { tap, expect } from 'tapbundle';
|
|
|
|
import * as smartpromise from '@pushrocks/smartpromise';
|
|
|
|
import { Qenv } from 'qenv';
|
2017-06-23 09:40:20 +00:00
|
|
|
|
2018-07-08 21:48:14 +00:00
|
|
|
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
|
2018-07-09 22:02:04 +00:00
|
|
|
import * as smartdata from '../ts';
|
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-07-08 21:48:14 +00:00
|
|
|
let testDb = new smartdata.SmartdataDb({
|
|
|
|
mongoDbName: process.env.MONGO_DBNAME,
|
|
|
|
mongoDbUrl: process.env.MONGO_URL,
|
2018-07-09 22:02:04 +00:00
|
|
|
mongoDbPass: process.env.MONGO_PASS
|
2018-07-08 21:48:14 +00:00
|
|
|
});
|
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 () => {
|
2018-07-08 21:48:14 +00:00
|
|
|
await testDb.connect();
|
|
|
|
});
|
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-07-09 22:02:04 +00:00
|
|
|
@smartdata.Collection(testDb)
|
|
|
|
class Car extends smartdata.SmartDataDbDoc<Car> {
|
2018-07-08 21:48:14 +00:00
|
|
|
@smartdata.svDb() color: string;
|
|
|
|
@smartdata.svDb() brand: string;
|
|
|
|
constructor(colorArg: string, brandArg: string) {
|
|
|
|
super();
|
|
|
|
this.color = colorArg;
|
|
|
|
this.brand = brandArg;
|
2018-01-12 00:22:58 +00:00
|
|
|
}
|
|
|
|
}
|
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 () => {
|
2018-07-08 21:48:14 +00:00
|
|
|
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 () => {
|
2018-07-09 22:02:04 +00:00
|
|
|
let myCars = await Car.getInstances<Car>({
|
2018-01-14 16:32:04 +00:00
|
|
|
brand: 'Volvo'
|
2018-07-08 21:48:14 +00:00
|
|
|
});
|
2018-07-09 22:02:04 +00:00
|
|
|
expect(myCars[0].color).to.equal('red');
|
2018-07-08 21:48:14 +00:00
|
|
|
});
|
2016-11-17 21:36:12 +00:00
|
|
|
|
2018-01-12 00:22:58 +00:00
|
|
|
// =======================================
|
|
|
|
// close the database connection
|
|
|
|
// =======================================
|
2018-07-08 21:48:14 +00:00
|
|
|
tap.test('should close the database connection', async tools => {
|
|
|
|
await testDb.close();
|
|
|
|
});
|
2017-06-18 17:52:54 +00:00
|
|
|
|
2018-07-08 21:48:14 +00:00
|
|
|
tap.start();
|