Something went wrong. Try again.
[READ-ONLY] Mirror of https://github.com/openstatusHQ/openstatus. ๐ซ Status page with uptime monitoring & API monitoring as code ๐ซ openstatus.dev
bun drizzle-orm monitoring monitoring-as-code nextjs observability on-call open-source shadcn-ui status-page statuspage synthetic-monitoring tinybird turso uptime uptime-checker uptime-monitor
Something went wrong. Try again.
TypeScript
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849import { Code, ConnectError } from "@connectrpc/connect";import { describe, expect, test } from "vitest";
import { parseDate, parseId } from "./parse";
const invalid = () => new ConnectError("invalid", Code.InvalidArgument);
describe("parseDate", () => { test("accepts RFC 3339 with Z, offsets and fractions", () => { expect(parseDate("2024-02-29T10:30:00Z", invalid).toISOString()).toBe( "2024-02-29T10:30:00.000Z", ); expect( parseDate("2024-03-15T10:30:00.123+02:00", invalid).toISOString(), ).toBe("2024-03-15T08:30:00.123Z"); });
test("rejects impossible calendar values instead of rolling over", () => { for (const value of [ "2024-02-31T10:30:00Z", "2023-02-29T10:30:00Z", "2024-13-01T10:30:00Z", "2024-03-15T24:00:00Z", "2024-03-15T10:60:00Z", "2024-03-15T10:30:00+24:00", ]) { expect(() => parseDate(value, invalid)).toThrow(ConnectError); } });
test("rejects non RFC 3339 strings", () => { for (const value of ["2024-03-15", "March 15, 2024", ""]) { expect(() => parseDate(value, invalid)).toThrow(ConnectError); } });});
describe("parseId", () => { test("accepts decimal digits", () => { expect(parseId(" 42 ", invalid)).toBe(42); });
test("rejects anything else", () => { for (const value of ["", "1e3", "0x10", "1.5", "9007199254740993"]) { expect(() => parseId(value, invalid)).toThrow(ConnectError); } });});