From b79599a350b4856202a7e50233ad2f0ffac9ec90 Mon Sep 17 00:00:00 2001 From: evlist Date: Tue, 8 Nov 2022 20:04:21 +0100 Subject: [PATCH] More tests --- src/db/lib.test.ts | 58 ++++++++++++++++++++++++++++++++++++++++++++++ src/db/lib.ts | 8 +++++-- 2 files changed, 64 insertions(+), 2 deletions(-) diff --git a/src/db/lib.test.ts b/src/db/lib.test.ts index 89392f6..cdb24c9 100644 --- a/src/db/lib.test.ts +++ b/src/db/lib.test.ts @@ -16,6 +16,7 @@ describe('getFamily', () => { }); afterEach(async () => { await db.destroy(); + db = undefined; globalThis.Date.now = originalDateNow; }); test('returns two rows after a gpx and a track have been inserted.', async () => { @@ -42,6 +43,63 @@ Object { ], "total_rows": 5, } +`); + }); + test('also returns the docs if required.', async () => { + await putNewTrk(); + const allDocs: any = await getFamily(uri('gpx', { gpx: '0' }), { + include_docs: true, + }); + expect(allDocs).toMatchInlineSnapshot(` +Object { + "offset": 0, + "rows": Array [ + Object { + "doc": Object { + "_id": "gpx/0", + "_rev": "1-98d42c99fcf471a500b0506a60e77559", + "doc": Object { + "$": Object { + "creator": "dyomedea version 0.000002", + "version": "1.1", + "xmlns": "http://www.topografix.com/GPX/1/1", + "xmlns:dyo": "http://xmlns.dyomedea.com/", + "xmlns:gpxtpx": "http://www.garmin.com/xmlschemas/TrackPointExtension/v1", + "xmlns:gpxx": "http://www.garmin.com/xmlschemas/GpxExtensions/v3", + "xmlns:wptx1": "http://www.garmin.com/xmlschemas/WaypointExtension/v1", + "xmlns:xsi": "http://www.w3.org/2001/XMLSchema-instance", + "xsi:schemaLocation": "http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd http://www.garmin.com/xmlschemas/GpxExtensions/v3 http://www8.garmin.com/xmlschemas/GpxExtensionsv3.xsd http://www.garmin.com/xmlschemas/WaypointExtension/v1 http://www8.garmin.com/xmlschemas/WaypointExtensionv1.xsd http://www.garmin.com/xmlschemas/TrackPointExtension/v1 http://www.garmin.com/xmlschemas/TrackPointExtensionv1.xsd", + }, + "metadata": Object { + "time": "1970-01-01T00:00:00.000Z", + }, + }, + "type": "gpx", + }, + "id": "gpx/0", + "key": "gpx/0", + "value": Object { + "rev": "1-98d42c99fcf471a500b0506a60e77559", + }, + }, + Object { + "doc": Object { + "_id": "gpx/0/2trk/00000", + "_rev": "1-1e197ef8965a436730f80cabaaaa6f70", + "doc": Object { + "number": 0, + }, + "type": "trk", + }, + "id": "gpx/0/2trk/00000", + "key": "gpx/0/2trk/00000", + "value": Object { + "rev": "1-1e197ef8965a436730f80cabaaaa6f70", + }, + }, + ], + "total_rows": 5, +} `); }); }); diff --git a/src/db/lib.ts b/src/db/lib.ts index e7f2279..3594940 100644 --- a/src/db/lib.ts +++ b/src/db/lib.ts @@ -31,6 +31,10 @@ export const put = async ( } }; -export const getFamily = async (key: string) => { - return await db.allDocs({ startkey: key, endkey: key + '\ufff0' }); +export const getFamily = async (key: string, options: any = {}) => { + return await db.allDocs({ + startkey: key, + endkey: key + '\ufff0', + ...options, + }); };