diff --git a/.vscode/launch.json b/.vscode/launch.json index 388786e2..2c7343b1 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -87,7 +87,7 @@ "--inspect-brk", "${workspaceRoot}/node_modules/.bin/jest", "--runInBand", - "MediaData" + "history" ], "console": "integratedTerminal", "internalConsoleOptions": "neverOpen", diff --git a/jest.config.cjs b/jest.config.cjs index 18bb8139..29335854 100644 --- a/jest.config.cjs +++ b/jest.config.cjs @@ -1,4 +1,5 @@ module.exports = { + testTimeout: 2 * 60 * 1000, moduleNameMapper: { '^(\\.{1,2}/.*)\\.js$': '$1' }, diff --git a/src/__tests__/history.ts b/src/__tests__/history.ts index 202747b2..d33e218e 100644 --- a/src/__tests__/history.ts +++ b/src/__tests__/history.ts @@ -119,9 +119,15 @@ describe('history API', () => { expect(climbChange.operation).toBe('updateClimb') expect(climbChange.editedBy).toBe(userUuid) - // Two changes: Insert the climb, update the parent area - // Ordering is non-deterministic. - expect(climbChange.changes.length).toBe(2) + + /** + * Four changes (Ordering is non-deterministic) + * 1. Insert the climb + * 2. Update the parent area + * 3. Update aggregate object on crag + * 4. Update the parent area + */ + expect(climbChange.changes.length).toBe(4) const insertChange = climbChange.changes.filter(c => c.dbOp === 'insert')[0] const updateChange = climbChange.changes.filter(c => c.dbOp === 'update')[0] expect(insertChange.fullDocument.uuid).toBe(climbIds[0]) diff --git a/src/db/utils/jobs/TreeUpdaters/updateAllAreas.ts b/src/db/utils/jobs/TreeUpdaters/updateAllAreas.ts index 6fa83edb..e7ff4201 100644 --- a/src/db/utils/jobs/TreeUpdaters/updateAllAreas.ts +++ b/src/db/utils/jobs/TreeUpdaters/updateAllAreas.ts @@ -118,7 +118,7 @@ export const leafReducer = (node: AreaType): StatsSummary => { */ const calculatePolygonFromChildren = (nodes: StatsSummary[]): Feature | null => { const childAsPolygons = nodes.reduce>>((acc, curr) => { - if (curr.bbox != null) { + if (Array.isArray(curr.bbox) && curr?.bbox.length === 4) { acc.push(bbox2Polygon(curr.bbox)) } return acc @@ -179,7 +179,7 @@ export const nodesReducer = async (childResults: StatsSummary[], parent: AreaMon const polygon = calculatePolygonFromChildren(childResults) nodeSummary.polygon = polygon?.geometry - nodeSummary.bbox = bboxFromGeojson(polygon) + nodeSummary.bbox = polygon == null ? undefined : bboxFromGeojson(polygon) nodeSummary.density = areaDensity(nodeSummary.bbox, nodeSummary.totalClimbs) const { totalClimbs, bbox, density, aggregate } = nodeSummary diff --git a/src/geo-utils.ts b/src/geo-utils.ts index 62a2fd64..f46c332d 100644 --- a/src/geo-utils.ts +++ b/src/geo-utils.ts @@ -35,7 +35,7 @@ export const bboxFromList = (bboxList: BBoxType[]): any => { * @returns total climbs per km sq */ export const areaDensity = (bbox: BBoxType | undefined, totalClimbs: number): number => { - if (bbox == null) return 0 + if (!Array.isArray(bbox) || bbox?.length !== 4) return 0 const areaInKm = area(bboxPolygon(bbox)) / 1000000 const minArea = areaInKm < 5 ? 5 : areaInKm return totalClimbs / minArea diff --git a/src/model/MutableAreaDataSource.ts b/src/model/MutableAreaDataSource.ts index 4cfea14d..fbbd7428 100644 --- a/src/model/MutableAreaDataSource.ts +++ b/src/model/MutableAreaDataSource.ts @@ -570,7 +570,9 @@ export const newAreaHelper = (areaName: string, parentAncestors: string, parentP leaf: false, area_id: uuid, leftRightIndex: -1, - ext_id: '' + ext_id: '', + bbox: undefined, + polygon: undefined }, ancestors, climbs: [],