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.
This commit is contained in:
Scott Idem
2026-03-09 17:53:45 -04:00
parent 173dc3c84c
commit 37e7a93617

View File

@@ -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