import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
import { getCurrentTimestamp } from "./time.js";
describe("getCurrentTimestamp", () => {
beforeEach(() => {
vi.useFakeTimers();
});
afterEach(() => {
vi.useRealTimers();
});
it("should return an ISO 8601 timestamp string", () => {
vi.setSystemTime(new Date("2026-02-14T12:00:00.000Z"));
expect(getCurrentTimestamp()).toBe("2026-02-14T12:00:00.000Z");
});
it("should return different values at different times", () => {
vi.setSystemTime(new Date("2026-01-01T00:00:00.000Z"));
const t1 = getCurrentTimestamp();
vi.setSystemTime(new Date("2026-06-15T18:30:00.000Z"));
const t2 = getCurrentTimestamp();
expect(t1).not.toBe(t2);
expect(t1).toBe("2026-01-01T00:00:00.000Z");
expect(t2).toBe("2026-06-15T18:30:00.000Z");
});
it("should match ISO 8601 format", () => {
vi.setSystemTime(new Date("2026-02-14T12:00:00.000Z"));
const timestamp = getCurrentTimestamp();
expect(timestamp).toMatch(/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z$/);
});
});