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({ gpx: 'gpxId', trk: 'trkid', trkseg: 'trksegid', trkpt: 'trkptid', }); await expect(globalThis.db.put).toBeCalledWith({ _id: 'gpx/gpxId/2trk/trkid/trksegid/trkptid', _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 () => { const id = await putNewTrkpt({ gpx: 'gpxId' }); expect(id).toEqual({ gpx: 'gpxId', trk: '00000', trkseg: '00000', trkpt: '00000', }); }); test('db.put() generates ids for both gpx and trk if needed', async () => { const id = await putNewTrkpt(); expect(id).toEqual({ gpx: '0', trk: '00000', trkseg: '00000', trkpt: '00000', }); }); });