More tests

This commit is contained in:
Eric van der Vlist 2022-11-08 20:04:21 +01:00
parent 9cc4c404b0
commit b79599a350
2 changed files with 64 additions and 2 deletions

View File

@ -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,
}
`);
});
});

View File

@ -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,
});
};