61 lines
1.7 KiB
TypeScript
61 lines
1.7 KiB
TypeScript
import { tap, expect } from '@pushrocks/tapbundle';
|
|
import { Qenv } from '@pushrocks/qenv';
|
|
|
|
const testQenv = new Qenv(process.cwd(), process.cwd() + '/.nogit/');
|
|
|
|
console.log(process.memoryUsage());
|
|
|
|
// the tested module
|
|
import * as smartdata from '../ts/index';
|
|
|
|
import * as mongoPlugin from 'mongodb-memory-server';
|
|
import { smartunique } from '../ts/smartdata.plugins';
|
|
|
|
// =======================================
|
|
// Connecting to the database server
|
|
// =======================================
|
|
|
|
let testDb: smartdata.SmartdataDb;
|
|
let smartdataOptions: smartdata.IMongoDescriptor;
|
|
let mongod: mongoPlugin.MongoMemoryServer;
|
|
|
|
tap.test('should create a testinstance as database', async () => {
|
|
mongod = await mongoPlugin.MongoMemoryServer.create();
|
|
console.log('created mongod instance');
|
|
console.log('mongod started');
|
|
smartdataOptions = {
|
|
mongoDbUrl: mongod.getUri(),
|
|
};
|
|
console.log(smartdataOptions);
|
|
testDb = new smartdata.SmartdataDb(smartdataOptions);
|
|
await testDb.init();
|
|
});
|
|
|
|
tap.skip.test('should connect to atlas', async (tools) => {
|
|
const databaseName = `test-smartdata-${smartunique.shortId()}`;
|
|
testDb = new smartdata.SmartdataDb({
|
|
mongoDbUrl: testQenv.getEnvVarOnDemand('MONGO_URL'),
|
|
mongoDbName: databaseName,
|
|
});
|
|
await testDb.init();
|
|
});
|
|
|
|
let easyStore: smartdata.EasyStore<{
|
|
key1: string;
|
|
key2: string;
|
|
}>;
|
|
|
|
tap.test('should create an easystore', async () => {
|
|
easyStore = await testDb.createEasyStore('hellothere');
|
|
await easyStore.writeKey('key1', 'hello');
|
|
const retrievedKey = await easyStore.readKey('key1');
|
|
expect(retrievedKey).to.equal('hello');
|
|
});
|
|
|
|
tap.test('close', async () => {
|
|
await mongod.stop();
|
|
await testDb.close();
|
|
});
|
|
|
|
tap.start();
|