From 3f5bb1633c0d5417df2055a59a1c0102ba21135f Mon Sep 17 00:00:00 2001 From: evlist Date: Thu, 9 Feb 2023 16:37:46 +0100 Subject: [PATCH] More tests --- README.md | 2 +- package-lock.json | 66 ++++++++++++++++++++++++++++++++++++++++++++ package.json | 2 ++ src/db/gpx.test.ts | 8 +++++- src/db/rte.test.ts | 41 ++++++++++++++++++++++++--- src/db/rtept.test.ts | 45 ++++++++++++++++++++++++++++-- src/db/rtept.ts | 2 ++ 7 files changed, 158 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 952c78f..3427966 100644 --- a/README.md +++ b/README.md @@ -354,7 +354,7 @@ Requires esrun (`sudo npm i -g @digitak/esrun`) ### Patches -``` + * suid: https://github.com/swordev/suid/issues/89 diff --git a/package-lock.json b/package-lock.json index d0230c3..2da9b73 100644 --- a/package-lock.json +++ b/package-lock.json @@ -48,10 +48,12 @@ "@types/memoizee": "^0.4.8", "@types/pouchdb": "^6.4.0", "@types/proj4": "^2.5.2", + "@types/shelljs": "^0.8.11", "jsdom": "^21.1.0", "license-checker": "^25.0.1", "license-compatibility-checker": "^0.3.5", "license-report": "^6.3.0", + "shelljs": "^0.8.5", "typescript": "^4.9.5", "vite": ">=4.1.1", "vite-plugin-solid": "^2.5.0", @@ -1882,6 +1884,16 @@ "integrity": "sha512-Nmh0K3iWQJzniTuPRcJn5hxXkfB1T1pgB89SBig5PlJQU5yocazeu4jATJlaA0GYFKWMqDdvYemoSnF2pXgLVA==", "optional": true }, + "node_modules/@types/glob": { + "version": "8.0.1", + "resolved": "https://registry.npmjs.org/@types/glob/-/glob-8.0.1.tgz", + "integrity": "sha512-8bVUjXZvJacUFkJXHdyZ9iH1Eaj5V7I8c4NdH5sQJsdXkqT4CA5Dhb4yb4VE/3asyx4L9ayZr1NIhTsWHczmMw==", + "dev": true, + "dependencies": { + "@types/minimatch": "^5.1.2", + "@types/node": "*" + } + }, "node_modules/@types/http-cache-semantics": { "version": "4.0.1", "resolved": "https://registry.npmjs.org/@types/http-cache-semantics/-/http-cache-semantics-4.0.1.tgz", @@ -1934,6 +1946,12 @@ "integrity": "sha512-qDpXKGgwKywnQt/64fH1O0LiPA++QGIYeykEUiZ51HymKVRLnUSGcRuF60IfpPeeXiuRwiR/W4y7S5VzbrgLCA==", "dev": true }, + "node_modules/@types/minimatch": { + "version": "5.1.2", + "resolved": "https://registry.npmjs.org/@types/minimatch/-/minimatch-5.1.2.tgz", + "integrity": "sha512-K0VQKziLUWkVKiRVrx4a40iPaxTUefQmjtkQofBkYRcoaaL/8rhwDWww9qWbrgicNOgnpIsMxyNIUM4+n6dUIA==", + "dev": true + }, "node_modules/@types/ms": { "version": "0.7.31", "resolved": "https://registry.npmjs.org/@types/ms/-/ms-0.7.31.tgz", @@ -2131,6 +2149,16 @@ "integrity": "sha512-/Nmfn9p08yaYw6xo5f2b0L+2oHk2kZeOkp5v+4VCeNfq+ETlLQbmHmC97/pjDIEZy8jxwz7pdPpwNzDHM5cuJw==", "dev": true }, + "node_modules/@types/shelljs": { + "version": "0.8.11", + "resolved": "https://registry.npmjs.org/@types/shelljs/-/shelljs-0.8.11.tgz", + "integrity": "sha512-x9yaMvEh5BEaZKeVQC4vp3l+QoFj3BXcd4aYfuKSzIIyihjdVARAadYy3SMNIz0WCCdS2vB9JL/U6GQk5PaxQw==", + "dev": true, + "dependencies": { + "@types/glob": "*", + "@types/node": "*" + } + }, "node_modules/@types/slice-ansi": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/@types/slice-ansi/-/slice-ansi-4.0.0.tgz", @@ -4539,6 +4567,15 @@ "node": ">= 0.4" } }, + "node_modules/interpret": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/interpret/-/interpret-1.4.0.tgz", + "integrity": "sha512-agE4QfB2Lkp9uICn7BAqoscw4SZP9kTE2hxiFI3jBPmXJfdqiahTbUuKGsMoN2GtqL9AxhYioAcVvgsb1HvRbA==", + "dev": true, + "engines": { + "node": ">= 0.10" + } + }, "node_modules/is-arguments": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/is-arguments/-/is-arguments-1.1.1.tgz", @@ -7223,6 +7260,18 @@ "once": "^1.3.0" } }, + "node_modules/rechoir": { + "version": "0.6.2", + "resolved": "https://registry.npmjs.org/rechoir/-/rechoir-0.6.2.tgz", + "integrity": "sha512-HFM8rkZ+i3zrV+4LQjwQ0W+ez98pApMGM3HUrN04j3CqzPOzl9nmP15Y8YXNm8QHGv/eacOVEjqhmWpkRV0NAw==", + "dev": true, + "dependencies": { + "resolve": "^1.1.6" + }, + "engines": { + "node": ">= 0.10" + } + }, "node_modules/redent": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/redent/-/redent-3.0.0.tgz", @@ -7508,6 +7557,23 @@ "node": ">=8" } }, + "node_modules/shelljs": { + "version": "0.8.5", + "resolved": "https://registry.npmjs.org/shelljs/-/shelljs-0.8.5.tgz", + "integrity": "sha512-TiwcRcrkhHvbrZbnRcFYMLl30Dfov3HKqzp5tO5b4pt6G/SezKcYhmDg15zXVBswHmctSAQKznqNW2LO5tTDow==", + "dev": true, + "dependencies": { + "glob": "^7.0.0", + "interpret": "^1.0.0", + "rechoir": "^0.6.2" + }, + "bin": { + "shjs": "bin/shjs" + }, + "engines": { + "node": ">=4" + } + }, "node_modules/side-channel": { "version": "1.0.4", "resolved": "https://registry.npmjs.org/side-channel/-/side-channel-1.0.4.tgz", diff --git a/package.json b/package.json index 2cf5399..2f90c06 100644 --- a/package.json +++ b/package.json @@ -20,10 +20,12 @@ "@types/memoizee": "^0.4.8", "@types/pouchdb": "^6.4.0", "@types/proj4": "^2.5.2", + "@types/shelljs": "^0.8.11", "jsdom": "^21.1.0", "license-checker": "^25.0.1", "license-compatibility-checker": "^0.3.5", "license-report": "^6.3.0", + "shelljs": "^0.8.5", "typescript": "^4.9.5", "vite": ">=4.1.1", "vite-plugin-solid": "^2.5.0", diff --git a/src/db/gpx.test.ts b/src/db/gpx.test.ts index 3acdde5..10a434d 100644 --- a/src/db/gpx.test.ts +++ b/src/db/gpx.test.ts @@ -1,4 +1,5 @@ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'; +import shell from 'shelljs'; import { initDb } from '.'; import { existsGpx, putNewGpx } from './gpx'; @@ -70,7 +71,12 @@ describe('The gpx module with a real db', () => { globalThis.Date.now = () => 0; }); afterEach(async () => { - await db.destroy(); + try { + await db.destroy(); + } catch (err) { + // console.error(err); + shell.exec('rm -rf $*$'); + } db = undefined; globalThis.Date.now = originalDateNow; }); diff --git a/src/db/rte.test.ts b/src/db/rte.test.ts index 4bef486..c8d710b 100644 --- a/src/db/rte.test.ts +++ b/src/db/rte.test.ts @@ -1,7 +1,9 @@ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'; +import shell from 'shelljs'; + import { initDb } from '.'; -import { putNewRte } from './rte'; +import { emptyRte, getRte, putNewRte, putRte } from './rte'; const test = it; const jest = vi; @@ -58,10 +60,41 @@ describe('The rte module with a real db', () => { globalThis.Date.now = () => 0; }); afterEach(async () => { - await db.destroy(); + try { + await db.destroy(); + } catch (err) { +// console.error(err); + shell.exec('rm -rf \$*\$'); + } db = undefined; globalThis.Date.now = originalDateNow; }); - it('', () => {}); + it('can write and read a rte', async () => { + const id = 'whatever'; + const rte: Rte = { + name: 'A new route', + }; + const rtePut = await putRte({ id, rte }); + expect(rtePut).toEqual(rte); + const rteGet = await getRte({ id }); + expect(rteGet).toEqual(rte); + }); + it('can write and read a rte with rtepts', async () => { + const id = 'whatever'; + const rte: Rte = { + name: 'A new route', + rtept: [ + { + $: { lat: 0, lon: 0 }, + }, + { + $: { lat: 1, lon: 1 }, + }, + ], + }; + const rtePut = await putRte({ id, rte }); + expect(rtePut).toEqual(rte); + const rteGet = await getRte({ id }); + expect(rteGet).toEqual(rte); + }); }); - diff --git a/src/db/rtept.test.ts b/src/db/rtept.test.ts index 91455e7..9661906 100644 --- a/src/db/rtept.test.ts +++ b/src/db/rtept.test.ts @@ -1,5 +1,7 @@ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'; +import shell from 'shelljs'; import { initDb } from '.'; +import { getRte, putRte } from './rte'; import { putRtept } from './rtept'; @@ -20,9 +22,48 @@ describe('The rtept module with a real db', () => { globalThis.Date.now = () => 0; }); afterEach(async () => { - await db.destroy(); + try { + await db.destroy(); + } catch (err) { +// console.error(err); + shell.exec('rm -rf \$*\$'); + } db = undefined; globalThis.Date.now = originalDateNow; }); - it('', () => {}); + it('can write a rtept inside a rte', async () => { + const idRte = 'whatever'; + const rtept: Rtept = { + $: { lat: 2, lon: 2 }, + }; + const rte0: Rte = { + name: 'A new route', + rtept: [ + { + $: { lat: 0, lon: 0 }, + }, + { + $: { lat: 1, lon: 1 }, + }, + ], + }; + const rte1: Rte = { + name: 'A new route', + rtept: [ + { + $: { lat: 0, lon: 0 }, + }, + { + $: { lat: 2, lon: 2 }, + }, + ], + }; + + const rtePut = await putRte({ id: idRte, rte: rte0 }); + expect(rtePut).toEqual(rte0); + const rtePutRtept = await putRtept({ idRte, index: 1, rtept }); + expect(rtePutRtept).toEqual(rte1); + const rteGetRtept = await getRte({ id: idRte }); + expect(rteGetRtept).toEqual(rte1); + }); }); diff --git a/src/db/rtept.ts b/src/db/rtept.ts index 3fcfba7..0826c9b 100644 --- a/src/db/rtept.ts +++ b/src/db/rtept.ts @@ -26,9 +26,11 @@ export const emptyRtept: Wpt = { }; export const putRtept = async (params: any) => { + console.log({ caller: 'putRtept', params }); const { idRte, index, rtept } = params; const { docs, rte } = await getRteDocs({ id: idRte }); const nbRteptInRte = rte && rte.rtept ? rte.rtept.length : 0; + console.log({ caller: 'putRtept', nbRteptInRte }); const nbRteptOutRte = docs.rows.length - 1; const nbRtept = nbRteptInRte + nbRteptOutRte; const positiveIndex = index >= 0 ? index : nbRtept - index;