59 lines
1.4 KiB
JavaScript
59 lines
1.4 KiB
JavaScript
|
|
import assert from "node:assert/strict";
|
||
|
|
import test from "node:test";
|
||
|
|
import { isCollectionScheduleDue } from "../lib/collection-service.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,
|
||
|
|
);
|
||
|
|
assert.equal(
|
||
|
|
isCollectionScheduleDue(
|
||
|
|
scheduledDate,
|
||
|
|
Date.parse("2026-08-11T16:00:00Z"),
|
||
|
|
),
|
||
|
|
false,
|
||
|
|
);
|
||
|
|
});
|
||
|
|
|
||
|
|
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"],
|
||
|
|
);
|
||
|
|
});
|