From 6d13c0c9ac8695888fff2230bc62a6a09cd43c52 Mon Sep 17 00:00:00 2001 From: Yash Singh <123385188+yashs33244@users.noreply.github.com> Date: Thu, 18 Jun 2026 12:40:24 +0530 Subject: [PATCH] fix(notifications): show region location name in recovery and degraded emails (#2287) The recovery and degraded email notifications passed the raw region code (e.g. "fra") to the template, while the alert email looked it up in regionDict to show the human-readable location (e.g. "Frankfurt, Germany"). This made the three email types inconsistent for the same monitor. Mirror the alert lookup in sendRecovery and sendDegraded so all three show the location name. The region value is a validated Region (z.enum over ALL_REGIONS) and regionDict is keyed on Region, so the lookup always resolves. Updated the email tests to drive the real `regions` array path (the existing cases passed a singular `region` the code never reads) and assert the resolved location for alert, recovery, and degraded. --- packages/notifications/email/src/index.test.ts | 9 ++++++--- packages/notifications/email/src/index.ts | 4 ++-- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/packages/notifications/email/src/index.test.ts b/packages/notifications/email/src/index.test.ts index ec91cd79..16b88c71 100644 --- a/packages/notifications/email/src/index.test.ts +++ b/packages/notifications/email/src/index.test.ts @@ -58,7 +58,7 @@ describe("Email Notifications", () => { statusCode: 500, message: "Something went wrong", latency: 1500, - region: "iad", + regions: ["iad"], cronTimestamp: Date.now(), }); @@ -70,6 +70,7 @@ describe("Email Notifications", () => { expect(callArgs.url).toBe("https://api.example.com/health"); expect(callArgs.status).toBe("500"); expect(callArgs.latency).toBe("1500ms"); + expect(callArgs.region).toBe("Ashburn, Virginia, USA"); expect(callArgs.message).toBe("Something went wrong"); expect(callArgs.timestamp).toBeDefined(); }); @@ -106,7 +107,7 @@ describe("Email Notifications", () => { notification, statusCode: 200, latency: 100, - region: "ams", + regions: ["ams"], cronTimestamp: Date.now(), }); @@ -117,6 +118,7 @@ describe("Email Notifications", () => { expect(callArgs.to).toBe("ping@openstatus.dev"); expect(callArgs.status).toBe("200"); expect(callArgs.latency).toBe("100ms"); + expect(callArgs.region).toBe("Amsterdam, Netherlands"); }); test("Send Degraded", async () => { @@ -131,7 +133,7 @@ describe("Email Notifications", () => { notification, statusCode: 503, latency: 2000, - region: "lax", + regions: ["lax"], cronTimestamp: Date.now(), }); @@ -141,6 +143,7 @@ describe("Email Notifications", () => { expect(callArgs.name).toBe("API Health Check"); expect(callArgs.status).toBe("503"); expect(callArgs.latency).toBe("2000ms"); + expect(callArgs.region).toBe("Los Angeles, California, USA"); }); test("Handles invalid notification data gracefully", async () => { diff --git a/packages/notifications/email/src/index.ts b/packages/notifications/email/src/index.ts index 59f7aae1..8e6a78fa 100644 --- a/packages/notifications/email/src/index.ts +++ b/packages/notifications/email/src/index.ts @@ -59,7 +59,7 @@ export const sendRecovery = async ({ url: monitor.url, status: statusCode?.toString(), latency: latency ? `${latency}ms` : "N/A", - region: region ?? "N/A", + region: region ? regionDict[region].location : "N/A", timestamp: new Date(cronTimestamp).toISOString(), }); }; @@ -87,7 +87,7 @@ export const sendDegraded = async ({ url: monitor.url, status: statusCode?.toString(), latency: latency ? `${latency}ms` : "N/A", - region: region ?? "N/A", + region: region ? regionDict[region].location : "N/A", timestamp: new Date(cronTimestamp).toISOString(), }); }; -- 2.51.2