From 37e7a936175f824753f31c3c2965e6ab8d1298a3 Mon Sep 17 00:00:00 2001 From: Scott Idem Date: Mon, 9 Mar 2026 17:53:45 -0400 Subject: [PATCH] fix(api): suppress send_email() in test/Playwright environments Add a guard at the top of send_email() that checks globalThis.__ae_test_mode. If truthy, logs a suppression message and returns null immediately so no HTTP request is made. This prevents real emails being sent when Playwright tests exercise components that call send_staff_notification_email() after a successful save. Activate by setting window.__ae_test_mode = true in addInitScript. --- src/lib/api/api.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/lib/api/api.ts b/src/lib/api/api.ts index b88aaf70..4848e03e 100644 --- a/src/lib/api/api.ts +++ b/src/lib/api/api.ts @@ -605,6 +605,13 @@ export const send_email = async function send_email({ }) { console.log('*** send_email() ***'); + // Skip email sending entirely when running in a test/Playwright environment. + // Set window.__ae_test_mode = true via addInitScript to activate this guard. + if (typeof globalThis !== 'undefined' && (globalThis as any).__ae_test_mode) { + console.log(`[TEST MODE] send_email() suppressed — would have sent to: ${to_email}, subject: ${subject}`); + return null; + } + const endpoint = `/util/email/send`; data['from_email'] = from_email; // Required