More tests

This commit is contained in:
Eric van der Vlist 2023-02-09 16:37:46 +01:00
parent a04fcab25d
commit 3f5bb1633c
7 changed files with 158 additions and 8 deletions

View File

@ -354,7 +354,7 @@ Requires esrun (`sudo npm i -g @digitak/esrun`)
### Patches ### Patches
```
* suid: https://github.com/swordev/suid/issues/89 * suid: https://github.com/swordev/suid/issues/89

66
package-lock.json generated
View File

@ -48,10 +48,12 @@
"@types/memoizee": "^0.4.8", "@types/memoizee": "^0.4.8",
"@types/pouchdb": "^6.4.0", "@types/pouchdb": "^6.4.0",
"@types/proj4": "^2.5.2", "@types/proj4": "^2.5.2",
"@types/shelljs": "^0.8.11",
"jsdom": "^21.1.0", "jsdom": "^21.1.0",
"license-checker": "^25.0.1", "license-checker": "^25.0.1",
"license-compatibility-checker": "^0.3.5", "license-compatibility-checker": "^0.3.5",
"license-report": "^6.3.0", "license-report": "^6.3.0",
"shelljs": "^0.8.5",
"typescript": "^4.9.5", "typescript": "^4.9.5",
"vite": ">=4.1.1", "vite": ">=4.1.1",
"vite-plugin-solid": "^2.5.0", "vite-plugin-solid": "^2.5.0",
@ -1882,6 +1884,16 @@
"integrity": "sha512-Nmh0K3iWQJzniTuPRcJn5hxXkfB1T1pgB89SBig5PlJQU5yocazeu4jATJlaA0GYFKWMqDdvYemoSnF2pXgLVA==", "integrity": "sha512-Nmh0K3iWQJzniTuPRcJn5hxXkfB1T1pgB89SBig5PlJQU5yocazeu4jATJlaA0GYFKWMqDdvYemoSnF2pXgLVA==",
"optional": true "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": { "node_modules/@types/http-cache-semantics": {
"version": "4.0.1", "version": "4.0.1",
"resolved": "https://registry.npmjs.org/@types/http-cache-semantics/-/http-cache-semantics-4.0.1.tgz", "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==", "integrity": "sha512-qDpXKGgwKywnQt/64fH1O0LiPA++QGIYeykEUiZ51HymKVRLnUSGcRuF60IfpPeeXiuRwiR/W4y7S5VzbrgLCA==",
"dev": true "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": { "node_modules/@types/ms": {
"version": "0.7.31", "version": "0.7.31",
"resolved": "https://registry.npmjs.org/@types/ms/-/ms-0.7.31.tgz", "resolved": "https://registry.npmjs.org/@types/ms/-/ms-0.7.31.tgz",
@ -2131,6 +2149,16 @@
"integrity": "sha512-/Nmfn9p08yaYw6xo5f2b0L+2oHk2kZeOkp5v+4VCeNfq+ETlLQbmHmC97/pjDIEZy8jxwz7pdPpwNzDHM5cuJw==", "integrity": "sha512-/Nmfn9p08yaYw6xo5f2b0L+2oHk2kZeOkp5v+4VCeNfq+ETlLQbmHmC97/pjDIEZy8jxwz7pdPpwNzDHM5cuJw==",
"dev": true "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": { "node_modules/@types/slice-ansi": {
"version": "4.0.0", "version": "4.0.0",
"resolved": "https://registry.npmjs.org/@types/slice-ansi/-/slice-ansi-4.0.0.tgz", "resolved": "https://registry.npmjs.org/@types/slice-ansi/-/slice-ansi-4.0.0.tgz",
@ -4539,6 +4567,15 @@
"node": ">= 0.4" "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": { "node_modules/is-arguments": {
"version": "1.1.1", "version": "1.1.1",
"resolved": "https://registry.npmjs.org/is-arguments/-/is-arguments-1.1.1.tgz", "resolved": "https://registry.npmjs.org/is-arguments/-/is-arguments-1.1.1.tgz",
@ -7223,6 +7260,18 @@
"once": "^1.3.0" "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": { "node_modules/redent": {
"version": "3.0.0", "version": "3.0.0",
"resolved": "https://registry.npmjs.org/redent/-/redent-3.0.0.tgz", "resolved": "https://registry.npmjs.org/redent/-/redent-3.0.0.tgz",
@ -7508,6 +7557,23 @@
"node": ">=8" "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": { "node_modules/side-channel": {
"version": "1.0.4", "version": "1.0.4",
"resolved": "https://registry.npmjs.org/side-channel/-/side-channel-1.0.4.tgz", "resolved": "https://registry.npmjs.org/side-channel/-/side-channel-1.0.4.tgz",

View File

@ -20,10 +20,12 @@
"@types/memoizee": "^0.4.8", "@types/memoizee": "^0.4.8",
"@types/pouchdb": "^6.4.0", "@types/pouchdb": "^6.4.0",
"@types/proj4": "^2.5.2", "@types/proj4": "^2.5.2",
"@types/shelljs": "^0.8.11",
"jsdom": "^21.1.0", "jsdom": "^21.1.0",
"license-checker": "^25.0.1", "license-checker": "^25.0.1",
"license-compatibility-checker": "^0.3.5", "license-compatibility-checker": "^0.3.5",
"license-report": "^6.3.0", "license-report": "^6.3.0",
"shelljs": "^0.8.5",
"typescript": "^4.9.5", "typescript": "^4.9.5",
"vite": ">=4.1.1", "vite": ">=4.1.1",
"vite-plugin-solid": "^2.5.0", "vite-plugin-solid": "^2.5.0",

View File

@ -1,4 +1,5 @@
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'; import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
import shell from 'shelljs';
import { initDb } from '.'; import { initDb } from '.';
import { existsGpx, putNewGpx } from './gpx'; import { existsGpx, putNewGpx } from './gpx';
@ -70,7 +71,12 @@ describe('The gpx module with a real db', () => {
globalThis.Date.now = () => 0; globalThis.Date.now = () => 0;
}); });
afterEach(async () => { afterEach(async () => {
try {
await db.destroy(); await db.destroy();
} catch (err) {
// console.error(err);
shell.exec('rm -rf $*$');
}
db = undefined; db = undefined;
globalThis.Date.now = originalDateNow; globalThis.Date.now = originalDateNow;
}); });

View File

@ -1,7 +1,9 @@
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'; import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
import shell from 'shelljs';
import { initDb } from '.'; import { initDb } from '.';
import { putNewRte } from './rte'; import { emptyRte, getRte, putNewRte, putRte } from './rte';
const test = it; const test = it;
const jest = vi; const jest = vi;
@ -58,10 +60,41 @@ describe('The rte module with a real db', () => {
globalThis.Date.now = () => 0; globalThis.Date.now = () => 0;
}); });
afterEach(async () => { afterEach(async () => {
try {
await db.destroy(); await db.destroy();
} catch (err) {
// console.error(err);
shell.exec('rm -rf \$*\$');
}
db = undefined; db = undefined;
globalThis.Date.now = originalDateNow; 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);
});
}); });

View File

@ -1,5 +1,7 @@
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'; import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
import shell from 'shelljs';
import { initDb } from '.'; import { initDb } from '.';
import { getRte, putRte } from './rte';
import { putRtept } from './rtept'; import { putRtept } from './rtept';
@ -20,9 +22,48 @@ describe('The rtept module with a real db', () => {
globalThis.Date.now = () => 0; globalThis.Date.now = () => 0;
}); });
afterEach(async () => { afterEach(async () => {
try {
await db.destroy(); await db.destroy();
} catch (err) {
// console.error(err);
shell.exec('rm -rf \$*\$');
}
db = undefined; db = undefined;
globalThis.Date.now = originalDateNow; 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);
});
}); });

View File

@ -26,9 +26,11 @@ export const emptyRtept: Wpt = {
}; };
export const putRtept = async (params: any) => { export const putRtept = async (params: any) => {
console.log({ caller: 'putRtept', params });
const { idRte, index, rtept } = params; const { idRte, index, rtept } = params;
const { docs, rte } = await getRteDocs({ id: idRte }); const { docs, rte } = await getRteDocs({ id: idRte });
const nbRteptInRte = rte && rte.rtept ? rte.rtept.length : 0; const nbRteptInRte = rte && rte.rtept ? rte.rtept.length : 0;
console.log({ caller: 'putRtept', nbRteptInRte });
const nbRteptOutRte = docs.rows.length - 1; const nbRteptOutRte = docs.rows.length - 1;
const nbRtept = nbRteptInRte + nbRteptOutRte; const nbRtept = nbRteptInRte + nbRteptOutRte;
const positiveIndex = index >= 0 ? index : nbRtept - index; const positiveIndex = index >= 0 ? index : nbRtept - index;