From b44e379adf9402dca4c14b6590780430bbb3a4b5 Mon Sep 17 00:00:00 2001 From: Alex Worrad-Andrews Date: Wed, 11 Feb 2026 17:39:36 +0000 Subject: [PATCH 1/2] Add test proving duplicate admin email bug when no branch assigned --- tests/EmailTest.php | 19 ++----------------- 1 file changed, 2 insertions(+), 17 deletions(-) diff --git a/tests/EmailTest.php b/tests/EmailTest.php index 04c0526..4d8f39a 100644 --- a/tests/EmailTest.php +++ b/tests/EmailTest.php @@ -191,22 +191,7 @@ public function test_branch_notification_sends_to_branch_email() $this->assertSame('moss-side@tenantsunion.org.uk', $sentTo); } - public function test_branch_notification_notifies_admin_when_no_branch() - { - $sentSubject = null; - Functions\when('wp_mail')->alias(function ($to, $subject) use (&$sentSubject) { - $sentSubject = $subject; - return true; - }); - - send_branch_notification( - $this->makeSampleMemberDetails(['branch' => null]), - $this->makeSampleNotificationConfig() - ); - $this->assertSame('GMTU Member Registration - No Branch Assigned', $sentSubject); - } - - public function test_branch_notification_does_nothing_when_no_branch_and_no_admin() + public function test_branch_notification_does_not_send_when_no_branch() { $mailCalled = false; Functions\when('wp_mail')->alias(function () use (&$mailCalled) { @@ -216,7 +201,7 @@ public function test_branch_notification_does_nothing_when_no_branch_and_no_admi send_branch_notification( $this->makeSampleMemberDetails(['branch' => null]), - $this->makeSampleNotificationConfig(['successNotificationEmails' => []]) + $this->makeSampleNotificationConfig() ); $this->assertFalse($mailCalled); } From d41fbe84c102de1f1d023bcbb13524ae302aa77a Mon Sep 17 00:00:00 2001 From: Alex Worrad-Andrews Date: Wed, 11 Feb 2026 17:39:41 +0000 Subject: [PATCH 2/2] Fix duplicate admin email when no branch assigned send_branch_notification was sending a second email to admin when branch was null, duplicating the admin notification already sent at priority 10. Now returns early since admin is already notified. --- src/Email.php | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/Email.php b/src/Email.php index cc76b3a..5a79d69 100644 --- a/src/Email.php +++ b/src/Email.php @@ -78,13 +78,9 @@ function send_branch_notification($memberDetails, $config) { $branchEmailMap = get_branch_email_map(); $memberBranch = $memberDetails['branch']; - // If no branch assigned, notify admin + // If no branch assigned, nothing to do — admin already notified at priority 10 if (empty($memberBranch)) { - if (!empty($config['successNotificationEmails'])) { - $intro = "A new member has joined but no branch was assigned.\n\nPlease review and assign a branch manually."; - $emailBody = build_email_body($intro, $memberDetails); - send_notification_emails($config['successNotificationEmails'], 'GMTU Member Registration - No Branch Assigned', $emailBody); - } + log_info("No branch assigned, skipping branch notification (admin already notified)"); return; }