Test: pin the Earlier alerts clock so it stops failing just after midnight

Merged
BI
1mo ago
+5-0

User description

Summary

Before: the Earlier alerts test file used the real clock. In the first minutes after Perth midnight, alerts made "a few minutes ago" fell under Yesterday, and two tests failed on any PR that ran then.

After: the file pins the clock to midday in Perth, so the tests give the same result at any hour.

How: vi.useFakeTimers({ toFake: ["Date"] }) with vi.setSystemTime in beforeEach, and vi.useRealTimers() in afterEach. Only Date is faked, so timers stay real for waitFor.

Areas touched: Delivery and assurance (test only)

Verification

  • Checks run:
    • Pinned at 12:01 am Perth (before this fix's value): Tests 2 failed | 26 passed (28), reproducing the failure seen on #3556.
    • Pinned at midday Perth: Tests 28 passed (28).
    • Prettier and eslint clean on the changed file.

Risk and rollout

  • Risk: none. Test file only.
  • Rollback: revert the commit.
  • Provider or production effects: None.

🤖 Generated with Claude Code

https://claude.ai/code/session_01KhogQUCHgdtFBHFtpjnd1n


Generated by Claude Code


Summary by cubic

Pins the Earlier alerts test clock to midday in Perth so the tests no longer fail just after midnight.

The file previously used the real clock, so alerts made "a few minutes ago" fell under Yesterday in the first minutes after Perth midnight and two tests failed. vi.useFakeTimers now fakes only Date in beforeEach, keeping timers real for waitFor, and vi.useRealTimers() restores them in afterEach.


CodeAnt-AI Description

Prevent Earlier alerts tests from failing after Perth midnight

What Changed

  • Earlier alerts tests now use a fixed Perth midday date, so “minutes ago” alerts remain under Today.
  • The tests restore the real clock afterward and keep timers real for asynchronous waits.

Impact

✅ Stable Earlier alerts tests after Perth midnight
✅ Real timers remain available for test waits

💡 Usage Guide

Checking Your Pull Request

Every time you make a pull request, our system automatically looks through it. We check for security issues, mistakes in how you're setting up your infrastructure, and common code problems. We do this to make sure your changes are solid and won't cause any trouble later.

Talking to CodeAnt AI

Got a question or need a hand with something in your pull request? You can easily get in touch with CodeAnt AI right here. Just type the following in a comment on your pull request, and replace "Your question here" with whatever you want to ask:

@codeant-ai ask: Your question here

This lets you have a chat with CodeAnt AI about your pull request, making it easier to understand and improve your code.

Example

@codeant-ai ask: Can you suggest a safer alternative to storing this secret?

Preserve Org Learnings with CodeAnt

You can record team preferences so CodeAnt AI applies them in future reviews. Reply directly to the specific CodeAnt AI suggestion (in the same thread) and replace "Your feedback here" with your input:

@codeant-ai: Your feedback here

This helps CodeAnt AI learn and adapt to your team's coding style and standards.

Example

@codeant-ai: Do not flag unused imports.

Retrigger review

Ask CodeAnt AI to review the PR again, by typing:

@codeant-ai: review

Check Your Repository Health

To analyze the health of your code repository, visit our dashboard at https://app.codeant.ai. This tool helps you identify potential issues and areas for improvement in your codebase, ensuring your repository maintains high standards of code health.