Adding more tests.
This commit is contained in:
parent
e8a3d8c62e
commit
a04fcab25d
|
@ -0,0 +1,67 @@
|
|||
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
||||
import { initDb } from '.';
|
||||
|
||||
import { putNewRte } from './rte';
|
||||
|
||||
const test = it;
|
||||
const jest = vi;
|
||||
|
||||
declare global {
|
||||
var db: any;
|
||||
var dbReady: boolean;
|
||||
}
|
||||
|
||||
const originalDb = globalThis.db;
|
||||
const originalDateNow = globalThis.Date.now;
|
||||
|
||||
describe('The rte module', () => {
|
||||
beforeEach(() => {
|
||||
globalThis.db = { put: jest.fn() };
|
||||
globalThis.Date.now = () => 0;
|
||||
});
|
||||
afterEach(() => {
|
||||
globalThis.db = originalDb;
|
||||
globalThis.Date.now = originalDateNow;
|
||||
});
|
||||
test('db.put() a new rte when required', async () => {
|
||||
putNewRte({ gpx: 4320000000000000, rte: 25 });
|
||||
await expect(globalThis.db.put).toBeCalledWith({
|
||||
_id: 'gpx/4320000000000000/2rte/000025',
|
||||
_rev: undefined,
|
||||
doc: {
|
||||
cmt: undefined,
|
||||
desc: undefined,
|
||||
extensions: undefined,
|
||||
link: undefined,
|
||||
name: undefined,
|
||||
number: 0,
|
||||
rtept: undefined,
|
||||
src: undefined,
|
||||
type: undefined,
|
||||
},
|
||||
type: 'rte',
|
||||
});
|
||||
});
|
||||
test('db.put() generates an id for the trk if needed', async () => {
|
||||
const id = await putNewRte({ gpx: 0 });
|
||||
expect(id).toEqual({ gpx: 0, rte: 0 });
|
||||
});
|
||||
test('db.put() generates ids for both gpx and trk if needed', async () => {
|
||||
const id = await putNewRte();
|
||||
expect(id).toEqual({ gpx: 4320000000000000, rte: 0 });
|
||||
});
|
||||
});
|
||||
|
||||
describe('The rte module with a real db', () => {
|
||||
beforeEach(async () => {
|
||||
await initDb({});
|
||||
globalThis.Date.now = () => 0;
|
||||
});
|
||||
afterEach(async () => {
|
||||
await db.destroy();
|
||||
db = undefined;
|
||||
globalThis.Date.now = originalDateNow;
|
||||
});
|
||||
it('', () => {});
|
||||
});
|
||||
|
|
@ -0,0 +1,28 @@
|
|||
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
||||
import { initDb } from '.';
|
||||
|
||||
import { putRtept } from './rtept';
|
||||
|
||||
const test = it;
|
||||
const jest = vi;
|
||||
|
||||
declare global {
|
||||
var db: any;
|
||||
var dbReady: boolean;
|
||||
}
|
||||
|
||||
const originalDb = globalThis.db;
|
||||
const originalDateNow = globalThis.Date.now;
|
||||
|
||||
describe('The rtept module with a real db', () => {
|
||||
beforeEach(async () => {
|
||||
await initDb({});
|
||||
globalThis.Date.now = () => 0;
|
||||
});
|
||||
afterEach(async () => {
|
||||
await db.destroy();
|
||||
db = undefined;
|
||||
globalThis.Date.now = originalDateNow;
|
||||
});
|
||||
it('', () => {});
|
||||
});
|
Loading…
Reference in New Issue