More tests
This commit is contained in:
1 parent
a04fcab25d
commit
3f5bb1633c
7 files changed
+158
-8
No files matched your search
+7
-1
@@ -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;
|
||||
});
|
||||
|
||||
+37
-4
@@ -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);
|
||||
});
|
||||
});
|
||||
|
||||
+43
-2
@@ -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);
|
||||
});
|
||||
});
|
||||
@@ -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;
|
||||
|
||||
Reference in new issue
Block a user