feat: add release controls and 09:00 collection
This commit is contained in:
38
tests/collection-schedule.test.mjs
Normal file
38
tests/collection-schedule.test.mjs
Normal 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"],
|
||||
);
|
||||
});
|
||||
Reference in New Issue
Block a user