Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions src/Email.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
19 changes: 2 additions & 17 deletions tests/EmailTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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);
}
Expand Down