From c00f05c346ad3bf7cbc428a5f3e37a2998e77ca3 Mon Sep 17 00:00:00 2001 From: Waleed Date: Wed, 28 Jan 2026 13:50:22 -0800 Subject: [PATCH] fix(tests): use UTC methods for timezone-independent schedule assertions (#3052) --- apps/sim/app/api/schedules/[id]/route.test.ts | 8 ++++---- apps/sim/lib/workflows/schedules/utils.test.ts | 10 +++++----- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/apps/sim/app/api/schedules/[id]/route.test.ts b/apps/sim/app/api/schedules/[id]/route.test.ts index b7ce032a4..448860680 100644 --- a/apps/sim/app/api/schedules/[id]/route.test.ts +++ b/apps/sim/app/api/schedules/[id]/route.test.ts @@ -344,7 +344,7 @@ describe('Schedule PUT API (Reactivate)', () => { expect(nextRunAt).toBeGreaterThan(beforeCall) expect(nextRunAt).toBeLessThanOrEqual(afterCall + 5 * 60 * 1000 + 1000) // Should align with 5-minute intervals (minute divisible by 5) - expect(new Date(nextRunAt).getMinutes() % 5).toBe(0) + expect(new Date(nextRunAt).getUTCMinutes() % 5).toBe(0) }) it('calculates nextRunAt from daily cron expression', async () => { @@ -572,7 +572,7 @@ describe('Schedule PUT API (Reactivate)', () => { expect(nextRunAt.getTime()).toBeGreaterThan(beforeCall) expect(nextRunAt.getTime()).toBeLessThanOrEqual(beforeCall + 10 * 60 * 1000 + 1000) // Should align with 10-minute intervals - expect(nextRunAt.getMinutes() % 10).toBe(0) + expect(nextRunAt.getUTCMinutes() % 10).toBe(0) }) it('handles hourly schedules with timezone correctly', async () => { @@ -598,8 +598,8 @@ describe('Schedule PUT API (Reactivate)', () => { // Should be a future date at minute 15 expect(nextRunAt.getTime()).toBeGreaterThan(beforeCall) - expect(nextRunAt.getMinutes()).toBe(15) - expect(nextRunAt.getSeconds()).toBe(0) + expect(nextRunAt.getUTCMinutes()).toBe(15) + expect(nextRunAt.getUTCSeconds()).toBe(0) }) it('handles custom cron expressions with complex patterns and timezone', async () => { diff --git a/apps/sim/lib/workflows/schedules/utils.test.ts b/apps/sim/lib/workflows/schedules/utils.test.ts index e8bc13fda..409816b87 100644 --- a/apps/sim/lib/workflows/schedules/utils.test.ts +++ b/apps/sim/lib/workflows/schedules/utils.test.ts @@ -266,9 +266,9 @@ describe('Schedule Utilities', () => { const nextRun = calculateNextRunTime('minutes', scheduleValues) // Should return the future start date with time - expect(nextRun.getFullYear()).toBe(2025) - expect(nextRun.getMonth()).toBe(3) // April - expect(nextRun.getDate()).toBe(15) + expect(nextRun.getUTCFullYear()).toBe(2025) + expect(nextRun.getUTCMonth()).toBe(3) // April + expect(nextRun.getUTCDate()).toBe(15) }) it.concurrent('should calculate next run for hourly schedule using Croner', () => { @@ -292,7 +292,7 @@ describe('Schedule Utilities', () => { expect(nextRun instanceof Date).toBe(true) expect(nextRun > new Date()).toBe(true) // Croner calculates based on cron "30 * * * *" - expect(nextRun.getMinutes()).toBe(30) + expect(nextRun.getUTCMinutes()).toBe(30) }) it.concurrent('should calculate next run for daily schedule using Croner with timezone', () => { @@ -439,7 +439,7 @@ describe('Schedule Utilities', () => { // Should not use the past date but calculate normally expect(nextRun > new Date()).toBe(true) - expect(nextRun.getMinutes() % 10).toBe(0) // Should align with the interval + expect(nextRun.getUTCMinutes() % 10).toBe(0) // Should align with the interval }) })