59 lines
1.6 KiB
TypeScript
59 lines
1.6 KiB
TypeScript
import { putNewRtept } from './rtept';
|
|
|
|
declare global {
|
|
var db: any;
|
|
var dbReady: boolean;
|
|
}
|
|
|
|
const originalDb = globalThis.db;
|
|
const originalDateNow = globalThis.Date.now;
|
|
|
|
describe('The rtept module', () => {
|
|
beforeEach(() => {
|
|
globalThis.db = { put: jest.fn() };
|
|
globalThis.Date.now = () => 0;
|
|
});
|
|
afterEach(() => {
|
|
globalThis.db = originalDb;
|
|
globalThis.Date.now = originalDateNow;
|
|
});
|
|
test('db.put() a new rtept when required', async () => {
|
|
putNewRtept({ gpx: 0, rte: 0, rtept: 0 });
|
|
await expect(globalThis.db.put).toBeCalledWith({
|
|
_id: 'gpx/0000000000000000/2rte/000000/000000',
|
|
_rev: undefined,
|
|
doc: {
|
|
$: { lat: 0, lon: 0 },
|
|
ageofdgpsdata: undefined,
|
|
cmt: undefined,
|
|
desc: undefined,
|
|
dgpsid: undefined,
|
|
ele: undefined,
|
|
extensions: undefined,
|
|
fix: undefined,
|
|
geoidheight: undefined,
|
|
hdop: undefined,
|
|
link: undefined,
|
|
magvar: undefined,
|
|
name: undefined,
|
|
pdop: undefined,
|
|
sat: undefined,
|
|
src: undefined,
|
|
sym: undefined,
|
|
time: undefined,
|
|
type: undefined,
|
|
vdop: undefined,
|
|
},
|
|
type: 'rtept',
|
|
});
|
|
});
|
|
test('db.put() generates an id for the rtept if needed', async () => {
|
|
const id = await putNewRtept({ gpx: 0 });
|
|
expect(id).toEqual({ gpx: 0, rte: 0, rtept: 0 });
|
|
});
|
|
test('db.put() generates ids for both gpx and rte if needed', async () => {
|
|
const id = await putNewRtept();
|
|
expect(id).toEqual({ gpx: 4320000000000000, rte: 0, rtept: 0 });
|
|
});
|
|
});
|