33 lines
1.2 KiB
JavaScript
33 lines
1.2 KiB
JavaScript
import { expect, test } from "bun:test";
|
|
import { refreshEarthUpdateBatch } from "./earth-update-batch.js";
|
|
|
|
function batchFixture(layers) {
|
|
const calls = [];
|
|
return {
|
|
calls,
|
|
batch: () => refreshEarthUpdateBatch({
|
|
layers,
|
|
strategies: new Map(layers.map((layer) => [layer, "reload"])),
|
|
isDatabaseChange: true,
|
|
loadSummary: async () => { calls.push("summary"); },
|
|
refreshLayer: async (layer, options) => { calls.push({ layer, options }); },
|
|
}),
|
|
};
|
|
}
|
|
|
|
test("a news-only database update refreshes news without fetching Earth summary", async () => {
|
|
const fixture = batchFixture(["news"]);
|
|
expect(await fixture.batch()).toEqual([{ status: "fulfilled", value: undefined }]);
|
|
expect(fixture.calls).toEqual([{ layer: "news", options: { force: true, strategy: "reload" } }]);
|
|
});
|
|
|
|
test("a mixed news and vessel update refreshes summary before both layers", async () => {
|
|
const fixture = batchFixture(["news", "vessels"]);
|
|
expect(await fixture.batch()).toHaveLength(2);
|
|
expect(fixture.calls).toEqual([
|
|
"summary",
|
|
{ layer: "news", options: { force: true, strategy: "reload" } },
|
|
{ layer: "vessels", options: { force: true, strategy: "reload" } },
|
|
]);
|
|
});
|