Open-source status page, incident response and uptime monitoring
TypeScript alertingincident-managementmcpmcp-servermonitoringmonitoring-as-codeobservabilityon-callopen-sourcesrestatus-pagestatuspagesynthetic-monitoringterraformtinybirdtursouptimeuptime-checkeruptime-monitor
test(notifications): cover the formatTimestamp helper (#2499)
Maria Zuheros2f05e0ca42a0
diff --git a/packages/notifications/base/src/utils/timestamp.test.ts b/packages/notifications/base/src/utils/timestamp.test.tsnew file mode 100644index 000000000..08a0793f1--- /dev/null+++ b/packages/notifications/base/src/utils/timestamp.test.ts@@ -0,0 +1,32 @@+import { expect } from "@std/expect";+import { describe, it } from "@std/testing/bdd";++import { formatTimestamp } from "./timestamp";++describe("formatTimestamp", () => {+ it("formats a valid epoch timestamp as an ISO string", () => {+ expect(formatTimestamp(1700000000000)).toBe("2023-11-14T22:13:20.000Z");+ });++ it("formats timestamps before the unix epoch", () => {+ expect(formatTimestamp(-1000)).toBe("1969-12-31T23:59:59.000Z");+ });++ it("returns Unknown for 0, since it is falsy", () => {+ expect(formatTimestamp(0)).toBe("Unknown");+ });++ it("returns Unknown for NaN", () => {+ expect(formatTimestamp(Number.NaN)).toBe("Unknown");+ });++ it("returns Unknown for non finite values", () => {+ expect(formatTimestamp(Number.POSITIVE_INFINITY)).toBe("Unknown");+ expect(formatTimestamp(Number.NEGATIVE_INFINITY)).toBe("Unknown");+ });++ it("returns Unknown when the timestamp is beyond the maximum valid date", () => {+ // The largest date JS can represent is 8.64e15 ms; one past it is invalid.+ expect(formatTimestamp(8.64e15 + 1)).toBe("Unknown");+ });+});