2022-11-08 20:09:33 +00:00
|
|
|
import { putNewTrkpt } from './trkpt';
|
|
|
|
|
|
|
|
declare global {
|
|
|
|
var db: any;
|
|
|
|
var dbReady: boolean;
|
|
|
|
}
|
|
|
|
|
|
|
|
const originalDb = globalThis.db;
|
|
|
|
const originalDateNow = globalThis.Date.now;
|
|
|
|
|
|
|
|
describe('The trkpt module', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
globalThis.db = { put: jest.fn() };
|
|
|
|
globalThis.Date.now = () => 0;
|
|
|
|
});
|
|
|
|
afterEach(() => {
|
|
|
|
globalThis.db = originalDb;
|
|
|
|
globalThis.Date.now = originalDateNow;
|
|
|
|
});
|
|
|
|
test('db.put() a new trkpt when required', async () => {
|
|
|
|
putNewTrkpt({
|
2022-11-13 19:02:11 +00:00
|
|
|
gpx: 1n,
|
|
|
|
trk: 2,
|
|
|
|
trkseg: 3,
|
|
|
|
trkpt: 4,
|
2022-11-08 20:09:33 +00:00
|
|
|
});
|
|
|
|
await expect(globalThis.db.put).toBeCalledWith({
|
2022-11-13 19:02:11 +00:00
|
|
|
_id: 'gpx/00000000000000001/2trk/000002/000003/000004',
|
2022-11-08 20:09:33 +00:00
|
|
|
_rev: undefined,
|
|
|
|
doc: {
|
|
|
|
$: { lat: 0, lon: 0 },
|
|
|
|
ageofdgpsdata: undefined,
|
|
|
|
cmt: undefined,
|
|
|
|
desc: undefined,
|
|
|
|
dgpsid: undefined,
|
|
|
|
ele: undefined,
|
|
|
|
extensions: {
|
|
|
|
'dyo:accuracy': undefined,
|
|
|
|
'dyo:batterylevel': undefined,
|
|
|
|
'dyo:course': undefined,
|
|
|
|
'dyo:speed': undefined,
|
|
|
|
'dyo:useragent': 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: 'trkpt',
|
|
|
|
});
|
|
|
|
});
|
|
|
|
test('db.put() generates an id for the trk if needed', async () => {
|
2022-11-13 19:02:11 +00:00
|
|
|
const id = await putNewTrkpt({ gpx: 5n });
|
2022-11-08 20:09:33 +00:00
|
|
|
expect(id).toEqual({
|
2022-11-13 19:02:11 +00:00
|
|
|
gpx: 5n,
|
|
|
|
trk: 0,
|
|
|
|
trkseg: 0,
|
|
|
|
trkpt: 0,
|
2022-11-08 20:09:33 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
test('db.put() generates ids for both gpx and trk if needed', async () => {
|
|
|
|
const id = await putNewTrkpt();
|
|
|
|
expect(id).toEqual({
|
2022-11-13 19:02:11 +00:00
|
|
|
gpx: 8640000000000000n,
|
|
|
|
trk: 0,
|
|
|
|
trkseg: 0,
|
|
|
|
trkpt: 0,
|
2022-11-08 20:09:33 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|