Using full ISO dates as Gpx ids to support a wider range of dates.

This commit is contained in:
Eric van der Vlist 2022-11-09 10:32:06 +01:00
parent 441c623999
commit 12f0a8a10d
9 changed files with 75 additions and 73 deletions

View File

@ -57,6 +57,6 @@ describe('The gpx module', () => {
});
test('db.put() generates an id if needed', async () => {
const id = await putNewGpx();
expect(id).toEqual({ gpx: '0' });
expect(id).toEqual({ gpx: '1970-01-01T00:00:00.000Z' });
});
});

View File

@ -31,7 +31,9 @@ const emptyGpx: Gpx = {
extensions: undefined,
};
export const putNewGpx = async (id: IdGpx = { gpx: Date.now().toString() }) => {
export const putNewGpx = async (
id: IdGpx = { gpx: new Date(Date.now()).toISOString() }
) => {
const uri = getUri('gpx', id);
await put(
uri,

View File

@ -26,23 +26,23 @@ describe('getFamily', () => {
});
test('returns two rows after a gpx and a track have been inserted.', async () => {
await putNewTrk();
const allDocs: any = await getFamily(uri('gpx', { gpx: '0' }));
const allDocs: any = await getFamily(uri('gpx', { gpx: '' }));
expect(allDocs).toMatchInlineSnapshot(`
Object {
"offset": 0,
"rows": Array [
Object {
"id": "gpx/0",
"key": "gpx/0",
"id": "gpx/1970-01-01T00%3A00%3A00.000Z",
"key": "gpx/1970-01-01T00%3A00%3A00.000Z",
"value": Object {
"rev": "1-98d42c99fcf471a500b0506a60e77559",
"rev": "1-649694b1e46839ec63d2a93f483dd023",
},
},
Object {
"id": "gpx/0/2trk/00000",
"key": "gpx/0/2trk/00000",
"id": "gpx/1970-01-01T00%3A00%3A00.000Z/2trk/00000",
"key": "gpx/1970-01-01T00%3A00%3A00.000Z/2trk/00000",
"value": Object {
"rev": "1-1e197ef8965a436730f80cabaaaa6f70",
"rev": "1-e1e6888ad978a5fcc405a75296604bee",
},
},
],
@ -52,7 +52,7 @@ Object {
});
test('also returns the docs if required.', async () => {
await putNewTrk();
const allDocs: any = await getFamily(uri('gpx', { gpx: '0' }), {
const allDocs: any = await getFamily(uri('gpx', { gpx: '' }), {
include_docs: true,
});
expect(allDocs).toMatchInlineSnapshot(`
@ -61,8 +61,8 @@ Object {
"rows": Array [
Object {
"doc": Object {
"_id": "gpx/0",
"_rev": "1-98d42c99fcf471a500b0506a60e77559",
"_id": "gpx/1970-01-01T00%3A00%3A00.000Z",
"_rev": "1-649694b1e46839ec63d2a93f483dd023",
"doc": Object {
"$": Object {
"creator": "dyomedea version 0.000002",
@ -81,25 +81,25 @@ Object {
},
"type": "gpx",
},
"id": "gpx/0",
"key": "gpx/0",
"id": "gpx/1970-01-01T00%3A00%3A00.000Z",
"key": "gpx/1970-01-01T00%3A00%3A00.000Z",
"value": Object {
"rev": "1-98d42c99fcf471a500b0506a60e77559",
"rev": "1-649694b1e46839ec63d2a93f483dd023",
},
},
Object {
"doc": Object {
"_id": "gpx/0/2trk/00000",
"_rev": "1-1e197ef8965a436730f80cabaaaa6f70",
"_id": "gpx/1970-01-01T00%3A00%3A00.000Z/2trk/00000",
"_rev": "1-e1e6888ad978a5fcc405a75296604bee",
"doc": Object {
"number": 0,
},
"type": "trk",
},
"id": "gpx/0/2trk/00000",
"key": "gpx/0/2trk/00000",
"id": "gpx/1970-01-01T00%3A00%3A00.000Z/2trk/00000",
"key": "gpx/1970-01-01T00%3A00%3A00.000Z/2trk/00000",
"value": Object {
"rev": "1-1e197ef8965a436730f80cabaaaa6f70",
"rev": "1-e1e6888ad978a5fcc405a75296604bee",
},
},
],
@ -109,30 +109,30 @@ Object {
});
test('returns three rows after a gpx and a track segment have been inserted.', async () => {
await putNewTrkseg();
const allDocs: any = await getFamily(uri('gpx', { gpx: '0' }));
const allDocs: any = await getFamily(uri('gpx', { gpx: '' }));
expect(allDocs).toMatchInlineSnapshot(`
Object {
"offset": 0,
"rows": Array [
Object {
"id": "gpx/0",
"key": "gpx/0",
"id": "gpx/1970-01-01T00%3A00%3A00.000Z",
"key": "gpx/1970-01-01T00%3A00%3A00.000Z",
"value": Object {
"rev": "1-98d42c99fcf471a500b0506a60e77559",
"rev": "1-649694b1e46839ec63d2a93f483dd023",
},
},
Object {
"id": "gpx/0/2trk/00000",
"key": "gpx/0/2trk/00000",
"id": "gpx/1970-01-01T00%3A00%3A00.000Z/2trk/00000",
"key": "gpx/1970-01-01T00%3A00%3A00.000Z/2trk/00000",
"value": Object {
"rev": "1-1e197ef8965a436730f80cabaaaa6f70",
"rev": "1-e1e6888ad978a5fcc405a75296604bee",
},
},
Object {
"id": "gpx/0/2trk/00000/00000",
"key": "gpx/0/2trk/00000/00000",
"id": "gpx/1970-01-01T00%3A00%3A00.000Z/2trk/00000/00000",
"key": "gpx/1970-01-01T00%3A00%3A00.000Z/2trk/00000/00000",
"value": Object {
"rev": "1-33cb714b4d5553cc20fc7a753c63cf51",
"rev": "1-9d8fbcd9cb7d2a45d6caf57a2cbee7ca",
},
},
],
@ -142,37 +142,37 @@ Object {
});
test('returns four rows after a gpx and a track point have been inserted.', async () => {
await putNewTrkpt();
const allDocs: any = await getFamily(uri('gpx', { gpx: '0' }));
const allDocs: any = await getFamily(uri('gpx', { gpx: '' }));
expect(allDocs).toMatchInlineSnapshot(`
Object {
"offset": 0,
"rows": Array [
Object {
"id": "gpx/0",
"key": "gpx/0",
"id": "gpx/1970-01-01T00%3A00%3A00.000Z",
"key": "gpx/1970-01-01T00%3A00%3A00.000Z",
"value": Object {
"rev": "1-98d42c99fcf471a500b0506a60e77559",
"rev": "1-649694b1e46839ec63d2a93f483dd023",
},
},
Object {
"id": "gpx/0/2trk/00000",
"key": "gpx/0/2trk/00000",
"id": "gpx/1970-01-01T00%3A00%3A00.000Z/2trk/00000",
"key": "gpx/1970-01-01T00%3A00%3A00.000Z/2trk/00000",
"value": Object {
"rev": "1-1e197ef8965a436730f80cabaaaa6f70",
"rev": "1-e1e6888ad978a5fcc405a75296604bee",
},
},
Object {
"id": "gpx/0/2trk/00000/00000",
"key": "gpx/0/2trk/00000/00000",
"id": "gpx/1970-01-01T00%3A00%3A00.000Z/2trk/00000/00000",
"key": "gpx/1970-01-01T00%3A00%3A00.000Z/2trk/00000/00000",
"value": Object {
"rev": "1-33cb714b4d5553cc20fc7a753c63cf51",
"rev": "1-9d8fbcd9cb7d2a45d6caf57a2cbee7ca",
},
},
Object {
"id": "gpx/0/2trk/00000/00000/00000",
"key": "gpx/0/2trk/00000/00000/00000",
"id": "gpx/1970-01-01T00%3A00%3A00.000Z/2trk/00000/00000/00000",
"key": "gpx/1970-01-01T00%3A00%3A00.000Z/2trk/00000/00000/00000",
"value": Object {
"rev": "1-c88eea2fc5a5637322a3f3357b49618f",
"rev": "1-42b858110cde8bec09e5d34b9e480936",
},
},
],
@ -183,23 +183,23 @@ Object {
test('returns two rows after a gpx and a waypoint have been inserted.', async () => {
await putNewWpt();
const allDocs: any = await getFamily(uri('gpx', { gpx: '0' }));
const allDocs: any = await getFamily(uri('gpx', { gpx: '' }));
expect(allDocs).toMatchInlineSnapshot(`
Object {
"offset": 0,
"rows": Array [
Object {
"id": "gpx/0",
"key": "gpx/0",
"id": "gpx/1970-01-01T00%3A00%3A00.000Z",
"key": "gpx/1970-01-01T00%3A00%3A00.000Z",
"value": Object {
"rev": "1-98d42c99fcf471a500b0506a60e77559",
"rev": "1-649694b1e46839ec63d2a93f483dd023",
},
},
Object {
"id": "gpx/0/0wpt/00000",
"key": "gpx/0/0wpt/00000",
"id": "gpx/1970-01-01T00%3A00%3A00.000Z/0wpt/00000",
"key": "gpx/1970-01-01T00%3A00%3A00.000Z/0wpt/00000",
"value": Object {
"rev": "1-dcdc55abd413b401dba4278510d9c51b",
"rev": "1-f98b9048879fc7b97771bf2bafc77e42",
},
},
],
@ -210,23 +210,23 @@ Object {
test('returns two rows after a gpx and a route have been inserted.', async () => {
await putNewRte();
const allDocs: any = await getFamily(uri('gpx', { gpx: '0' }));
const allDocs: any = await getFamily(uri('gpx', { gpx: '' }));
expect(allDocs).toMatchInlineSnapshot(`
Object {
"offset": 0,
"rows": Array [
Object {
"id": "gpx/0",
"key": "gpx/0",
"id": "gpx/1970-01-01T00%3A00%3A00.000Z",
"key": "gpx/1970-01-01T00%3A00%3A00.000Z",
"value": Object {
"rev": "1-98d42c99fcf471a500b0506a60e77559",
"rev": "1-649694b1e46839ec63d2a93f483dd023",
},
},
Object {
"id": "gpx/0/1rte/00000",
"key": "gpx/0/1rte/00000",
"id": "gpx/1970-01-01T00%3A00%3A00.000Z/1rte/00000",
"key": "gpx/1970-01-01T00%3A00%3A00.000Z/1rte/00000",
"value": Object {
"rev": "1-bce69fd9ada837c19cf8c1c296f82f92",
"rev": "1-f17cd2939d1e63764478613f54835884",
},
},
],
@ -237,30 +237,30 @@ Object {
test('returns three rows after a gpx and a route point have been inserted.', async () => {
await putNewRtept();
const allDocs: any = await getFamily(uri('gpx', { gpx: '0' }));
const allDocs: any = await getFamily(uri('gpx', { gpx: '' }));
expect(allDocs).toMatchInlineSnapshot(`
Object {
"offset": 0,
"rows": Array [
Object {
"id": "gpx/0",
"key": "gpx/0",
"id": "gpx/1970-01-01T00%3A00%3A00.000Z",
"key": "gpx/1970-01-01T00%3A00%3A00.000Z",
"value": Object {
"rev": "1-98d42c99fcf471a500b0506a60e77559",
"rev": "1-649694b1e46839ec63d2a93f483dd023",
},
},
Object {
"id": "gpx/0/1rte/00000",
"key": "gpx/0/1rte/00000",
"id": "gpx/1970-01-01T00%3A00%3A00.000Z/1rte/00000",
"key": "gpx/1970-01-01T00%3A00%3A00.000Z/1rte/00000",
"value": Object {
"rev": "1-bce69fd9ada837c19cf8c1c296f82f92",
"rev": "1-f17cd2939d1e63764478613f54835884",
},
},
Object {
"id": "gpx/0/1rte/00000/00000",
"key": "gpx/0/1rte/00000/00000",
"id": "gpx/1970-01-01T00%3A00%3A00.000Z/1rte/00000/00000",
"key": "gpx/1970-01-01T00%3A00%3A00.000Z/1rte/00000/00000",
"value": Object {
"rev": "1-1045e2dc6d2f7927514b02f79d14daa8",
"rev": "1-ba3f25be70b620dd06b453ec29853bae",
},
},
],

View File

@ -43,6 +43,6 @@ describe('The rte module', () => {
});
test('db.put() generates ids for both gpx and trk if needed', async () => {
const id = await putNewRte();
expect(id).toEqual({ gpx: '0', rte: '00000' });
expect(id).toEqual({ gpx: '1970-01-01T00:00:00.000Z', rte: '00000' });
});
});

View File

@ -53,6 +53,6 @@ describe('The rtept module', () => {
});
test('db.put() generates ids for both gpx and rte if needed', async () => {
const id = await putNewRtept();
expect(id).toEqual({ gpx: '0', rte: '00000', rtept: '00000' });
expect(id).toEqual({ gpx: '1970-01-01T00:00:00.000Z', rte: '00000', rtept: '00000' });
});
});

View File

@ -42,6 +42,6 @@ describe('The trk module', () => {
});
test('db.put() generates ids for both gpx and trk if needed', async () => {
const id = await putNewTrk();
expect(id).toEqual({ gpx: '0', trk: '00000' });
expect(id).toEqual({ gpx: '1970-01-01T00:00:00.000Z', trk: '00000' });
});
});

View File

@ -70,7 +70,7 @@ describe('The trkpt module', () => {
test('db.put() generates ids for both gpx and trk if needed', async () => {
const id = await putNewTrkpt();
expect(id).toEqual({
gpx: '0',
gpx: '1970-01-01T00:00:00.000Z',
trk: '00000',
trkseg: '00000',
trkpt: '00000',

View File

@ -35,6 +35,6 @@ describe('The trkseg module', () => {
});
test('db.put() generates ids for both gpx and trk if needed', async () => {
const id = await putNewTrkseg();
expect(id).toEqual({ gpx: '0', trk: '00000', trkseg: '00000' });
expect(id).toEqual({ gpx: '1970-01-01T00:00:00.000Z', trk: '00000', trkseg: '00000' });
});
});

View File

@ -53,6 +53,6 @@ describe('The wpt module', () => {
});
test('db.put() generates ids for both gpx and trk if needed', async () => {
const id = await putNewWpt();
expect(id).toEqual({ gpx: '0', wpt: '00000' });
expect(id).toEqual({ gpx: '1970-01-01T00:00:00.000Z', wpt: '00000' });
});
});