smartdata/test/test.easystore.ts

56 lines
1.6 KiB
TypeScript
Raw Normal View History

2023-07-21 20:08:18 +02:00
import { tap, expect } from '@push.rocks/tapbundle';
import { Qenv } from '@push.rocks/qenv';
import * as smartmongo from '@push.rocks/smartmongo';
2022-05-17 00:33:44 +02:00
import { smartunique } from '../ts/smartdata.plugins.js';
2021-10-16 19:54:05 +02:00
const testQenv = new Qenv(process.cwd(), process.cwd() + '/.nogit/');
console.log(process.memoryUsage());
// the tested module
2022-05-17 00:33:44 +02:00
import * as smartdata from '../ts/index.js';
2021-10-16 19:54:05 +02:00
// =======================================
// Connecting to the database server
// =======================================
2022-05-17 00:33:44 +02:00
let smartmongoInstance: smartmongo.SmartMongo;
2021-10-16 19:54:05 +02:00
let testDb: smartdata.SmartdataDb;
2021-11-12 19:03:06 +01:00
tap.test('should create a testinstance as database', async () => {
2022-05-17 00:33:44 +02:00
smartmongoInstance = await smartmongo.SmartMongo.createAndStart();
testDb = new smartdata.SmartdataDb(await smartmongoInstance.getMongoDescriptor());
2021-10-16 19:54:05 +02:00
await testDb.init();
});
2021-11-12 19:03:06 +01:00
tap.skip.test('should connect to atlas', async (tools) => {
2021-11-12 17:32:43 +01:00
const databaseName = `test-smartdata-${smartunique.shortId()}`;
testDb = new smartdata.SmartdataDb({
2023-08-15 01:01:16 +02:00
mongoDbUrl: await testQenv.getEnvVarOnDemand('MONGO_URL'),
2021-11-12 17:32:43 +01:00
mongoDbName: databaseName,
});
2021-11-12 18:04:08 +01:00
await testDb.init();
2021-11-12 17:32:43 +01:00
});
2021-10-16 19:54:05 +02:00
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');
2022-05-17 00:33:44 +02:00
expect(retrievedKey).toEqual('hello');
2021-10-16 21:17:02 +02:00
});
2021-10-16 19:54:05 +02:00
tap.test('close', async () => {
2022-05-17 21:26:17 +02:00
await testDb.mongoDb.dropDatabase();
await testDb.close();
2022-05-17 00:33:44 +02:00
if (smartmongoInstance) {
await smartmongoInstance.stop();
2021-11-12 18:12:59 +01:00
}
2021-10-16 21:17:02 +02:00
});
2021-10-16 19:54:05 +02:00
2021-10-16 21:17:02 +02:00
tap.start();