feat: add release controls and 09:00 collection

This commit is contained in:
巫凤萍
2026-08-12 11:43:26 +08:00
parent 1f1887c860
commit 1766a90cc1
14 changed files with 665 additions and 38 deletions

View File

@@ -0,0 +1,38 @@
import assert from "node:assert/strict";
import test from "node:test";
import { isCollectionScheduleDue } from "../lib/collection-schedule.ts";
import { sortWithNullsLast } from "../lib/sort-utils.ts";
test("runs the Beijing collection schedule from 09:00", () => {
const scheduledDate = "2026-08-12";
assert.equal(
isCollectionScheduleDue(scheduledDate, Date.parse("2026-08-12T00:59:59Z")),
false,
);
assert.equal(
isCollectionScheduleDue(scheduledDate, Date.parse("2026-08-12T01:00:00Z")),
true,
);
assert.equal(
isCollectionScheduleDue(scheduledDate, Date.parse("2026-08-13T00:00:00Z")),
true,
);
});
test("sorts both directions while keeping missing values last", () => {
const values = [
{ id: "missing-a", value: null },
{ id: "middle", value: 20 },
{ id: "high", value: 50 },
{ id: "missing-b", value: null },
{ id: "low", value: 10 },
];
assert.deepEqual(
sortWithNullsLast(values, (item) => item.value, "asc").map((item) => item.id),
["low", "middle", "high", "missing-a", "missing-b"],
);
assert.deepEqual(
sortWithNullsLast(values, (item) => item.value, "desc").map((item) => item.id),
["high", "middle", "low", "missing-a", "missing-b"],
);
});