Quota test: use today's YouTube day instead of a fixed date

The fixed 21 Oct timestamps got pruned as stale once that day passed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
metatroncubeswdev 2026-10-25 12:29:55 -04:00
parent 15bc0b9bf2
commit 2b667c655a

View File

@ -46,12 +46,13 @@ test("YouTube's day runs midnight to midnight Pacific time, including the DST ch
test("YouTube allows 6 uploads (6 x 1,600 of 10,000 units), then waits until midnight Pacific", () => {
reset();
const at = Date.parse("2026-10-21T19:00:00Z");
const at = Date.now(); // relative to now: stored entries older than the window are pruned on every write
const day = quota.windowAt(quota.limitFor("youtube"), at);
for (let i = 0; i < 6; i++) { quota.ensure("youtube", null, "publish", at); quota.record("youtube", null, "publish", at); }
const u = quota.usage("youtube", null, at);
assert.deepEqual([u.used, u.remaining], [9600, 400]);
assert.throws(() => quota.ensure("youtube", null, "publish", at), (e) => e.quota && e.resetAt === "2026-10-22T07:00:00.000Z");
assert.doesNotThrow(() => quota.ensure("youtube", null, "publish", Date.parse("2026-10-22T07:00:01Z")), "new day, new budget");
assert.throws(() => quota.ensure("youtube", null, "publish", at), (e) => e.quota && e.resetAt === new Date(day.end).toISOString());
assert.doesNotThrow(() => quota.ensure("youtube", null, "publish", day.end + 1000), "new day, new budget");
assert.doesNotThrow(() => quota.ensure("youtube", "someone-else", "read", at), "reads (1 unit) still fit");
});