Files
smartdata/test/test.ts

64 lines
1.6 KiB
TypeScript
Raw Normal View History

import { tap, expect } from 'tapbundle';
import * as smartpromise from '@pushrocks/smartpromise';
import { Qenv } from 'qenv';
let testQenv = new Qenv(process.cwd(), process.cwd() + '/.nogit/');
2016-09-11 16:22:53 +02:00
// the tested module
import * as smartdata from '../ts/index';
import { smartstring } from '../ts/smartdata.plugins';
2016-09-11 16:22:53 +02:00
// =======================================
// Connecting to the database server
// =======================================
2016-09-12 22:11:17 +02:00
let testDb = new smartdata.SmartdataDb({
mongoDbName: process.env.MONGO_DBNAME,
mongoDbUrl: process.env.MONGO_URL,
mongoPass: process.env.MONGO_PASS
});
2016-09-12 22:11:17 +02:00
tap.test('should establish a connection to the rethink Db cluster', async () => {
await testDb.connect();
});
2016-09-12 22:11:17 +02:00
// =======================================
// The actual tests
// =======================================
2017-11-16 14:23:06 +01:00
// ------
// Collections
// ------
2017-06-18 19:52:54 +02:00
@smartdata.Table(testDb)
class Car extends smartdata.smartDataDbDoc<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 16:22:53 +02: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 22:36:12 +01:00
// =======================================
// close the database connection
// =======================================
tap.test('should close the database connection', async tools => {
await testDb.close();
});
2017-06-18 19:52:54 +02:00
tap.start();