Storing track points independently from their tracks (#3). Also adding some basic tests for gpx database operations.

This commit is contained in:
vdv committed 2022-09-26 21:48:46 +02:00
1 parent e1da4a1e4a
commit 6e9fc21830
7 files changed
+130 -83

No files matched your search

+50
View File
@@ -0,0 +1,50 @@
import { initDb } from '.';
import PouchDB from 'pouchdb';
import { appendTrkpt } from './gpx';
import PouchDBFind from 'pouchdb-find';
import { mkdtempSync, rmdirSync } from 'fs';
import { join } from 'path';
import { tmpdir } from 'os';
PouchDB.plugin(PouchDBFind);
//PouchDB.plugin(require('pouchdb-find'));
// export class PouchService {
// constructor() {
// PouchDB.plugin(PouchDBFind);
// }
// }
// jest.useFakeTimers();
const tmpDir = mkdtempSync(join(tmpdir(), 'dyomedea-testDB'));
var db: PouchDB.Database;
beforeEach(async () => {
db = new PouchDB(tmpDir);
await initDb(db, () => {});
});
afterEach(async () => {
// await db.close();
await db.destroy();
});
describe('Checking that trkpts are beeing inserted', () => {
test('and that we have two documents after the first call', async () => {
await appendTrkpt(db, {});
const results = await db.find({ selector: {} });
const docs = results.docs;
// console.log(`docs: ${JSON.stringify(docs)}`);
expect(docs.length).toBe(2);
});
test('and that we have three documents after the second call', async () => {
await appendTrkpt(db, {});
await appendTrkpt(db, {});
const results = await db.find({ selector: {} });
const docs = results.docs;
console.log(`docs: ${JSON.stringify(docs)}`);
expect(docs.length).toBe(3);
});
});