From f9b7a7714088b06e9cd2ce57fcc698a0da1c6a4d Mon Sep 17 00:00:00 2001 From: Sameh Khamis Date: Tue, 10 Nov 2026 13:42:08 -0800 Subject: [PATCH] test(shipwrecks): the page deadline subtracts the newest available source's reported age from the limit --- src/layers/shipwrecks/index.test.mjs | 35 +++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/src/layers/shipwrecks/index.test.mjs b/src/layers/shipwrecks/index.test.mjs index 56cf34fde..6362be2e7 100644 --- a/src/layers/shipwrecks/index.test.mjs +++ b/src/layers/shipwrecks/index.test.mjs @@ -2,7 +2,11 @@ import test from 'node:test'; import assert from 'node:assert/strict'; import * as Cesium from 'cesium'; import * as picking from '../../data/pickRegistry.js'; -import { createShipwrecksLayer, markerPixelSize } from './index.js'; +import { + createShipwrecksLayer, + markerPixelSize, + snapshotDeadline, +} from './index.js'; const wreck = (id, extra = {}) => ({ id, @@ -348,3 +352,32 @@ test('a snapshot with no timestamp or ages still expires seven days after it arr await h.layer.update(); assert.equal(h.layer.getStats().count, 0); }); + +test('the page deadline subtracts the newest available source age from the limit', () => { + const DAY = 24 * 60 * 60 * 1000; + const both = { emodnet: true, wikidata: true }; + assert.equal( + snapshotDeadline( + { + sources: both, + ages: { emodnet: 2 * DAY, wikidata: 6.5 * DAY }, + maxAgeMs: 5 * DAY, + }, + 100, + ), + 100 + 3 * DAY, + ); + assert.equal( + snapshotDeadline( + { + sources: { emodnet: false, wikidata: true }, + ages: { emodnet: null, wikidata: 4 * DAY }, + maxAgeMs: 5 * DAY, + }, + 0, + ), + 1 * DAY, + 'an unavailable source does not count', + ); + assert.equal(snapshotDeadline({ sources: both }, 0), 7 * DAY, 'defaults'); +});