Skip to content

Commit 9479cee

Browse files
krlmrrKarl Murray
andauthored
[ADVAPP-1728]: Bug Fix: Attempts to Send Alert to a Deleted User (#1742)
* [ADVAPP-1728]: Bug Fix: Deleted User Subscription * [ADVAPP-1728]: Bug Fix: Deleted User Subscription * [ADVAPP-1728]: Create a test for the issue. * [ADVAPP-1728]: Fix the issue. * [ADVAPP-1728]: Add a Todo --------- Co-authored-by: Karl Murray <karl.murray@canyongbs.com>
1 parent fd5620b commit 9479cee

2 files changed

Lines changed: 24 additions & 1 deletion

File tree

app-modules/alert/tests/Tenant/AlertCreateTest.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,3 +79,26 @@
7979
Notification::assertSentTo($users, AlertCreatedNotification::class);
8080
Notification::assertSentTimes(AlertCreatedNotification::class, $student->subscriptions()->count());
8181
});
82+
83+
it('only notifies active users of alerts', function () {
84+
// @Todo: This tests works but we should change it to use the Listener instead of the Notification
85+
Notification::fake();
86+
87+
$deletedUser = User::factory()->licensed(LicenseType::cases())->create();
88+
89+
/** @var Student $student */
90+
$student = Student::factory()->create();
91+
92+
$student->subscriptions()->create([
93+
'user_id' => $deletedUser->id,
94+
]);
95+
96+
$deletedUser->delete();
97+
98+
Alert::factory()->create([
99+
'concern_id' => $student->sisid,
100+
'concern_type' => Student::class,
101+
]);
102+
103+
Notification::assertNotSentTo($deletedUser, AlertCreatedNotification::class);
104+
});

app-modules/notification/src/Models/Concerns/HasSubscriptions.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,6 @@ trait HasSubscriptions
4646
*/
4747
public function subscriptions(): MorphMany
4848
{
49-
return $this->morphMany(Subscription::class, 'subscribable');
49+
return $this->morphMany(Subscription::class, 'subscribable')->whereHas('user');
5050
}
5151
}

0 commit comments

Comments
 (0)