Skip to content

Commit a7034a0

Browse files
committed
Add test case to cover wiki noti threshold boundary
1 parent 42d210a commit a7034a0

1 file changed

Lines changed: 19 additions & 1 deletion

File tree

tests/Jobs/SendEmptyWikiNotificationsJobTest.php

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public function testEmptyWikiNotificationsSendNotification() {
3838
Notification::fake();
3939
$user = User::factory()->create(['verified' => true]);
4040
$wiki = Wiki::factory()->create(['created_at' => $thresholdDaysAgo]);
41-
$manager = WikiManager::factory()->create(['wiki_id' => $wiki->id, 'user_id' => $user->id]);
41+
WikiManager::factory()->create(['wiki_id' => $wiki->id, 'user_id' => $user->id]);
4242
$wiki->wikiLifecycleEvents()->updateOrCreate(['first_edited' => null]);
4343

4444
$job = new SendEmptyWikiNotificationsJob;
@@ -50,6 +50,24 @@ public function testEmptyWikiNotificationsSendNotification() {
5050
);
5151
}
5252

53+
// empty wikis, that are almost old enough (29 days and 23 hrs)
54+
public function testEmptyWikiNotificationsNotSendNotification() {
55+
$thresholdDaysAgo = Carbon::now()
56+
->subDays((config('wbstack.wiki_empty_notification_threshold') - 1))
57+
->subHours(23)
58+
->toDateTimeString();
59+
60+
Notification::fake();
61+
$user = User::factory()->create(['verified' => true]);
62+
$wiki = Wiki::factory()->create(['created_at' => $thresholdDaysAgo]);
63+
WikiManager::factory()->create(['wiki_id' => $wiki->id, 'user_id' => $user->id]);
64+
$wiki->wikiLifecycleEvents()->updateOrCreate(['first_edited' => null]);
65+
66+
$job = new SendEmptyWikiNotificationsJob;
67+
$this->assertFalse($job->checkIfWikiIsOldAndEmpty($wiki));
68+
$job->handle();
69+
}
70+
5371
// fresh wiki that does not have lifecycle event records yet
5472
public function testEmptyWikiNotificationsFreshWiki() {
5573
$now = Carbon::now()->toDateTimeString();

0 commit comments

Comments
 (0)