From 2b667c655ada4b826237d9134e3119f562511f09 Mon Sep 17 00:00:00 2001 From: metatroncubeswdev Date: Sun, 25 Oct 2026 12:29:55 -0400 Subject: [PATCH] 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 --- connector/test/quota.test.mjs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/connector/test/quota.test.mjs b/connector/test/quota.test.mjs index 6f6b7c0..cab65b2 100644 --- a/connector/test/quota.test.mjs +++ b/connector/test/quota.test.mjs @@ -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"); });