-
-
Notifications
You must be signed in to change notification settings - Fork 108
Expand file tree
/
Copy pathResendLeadNotificationsTest.php
More file actions
60 lines (48 loc) · 1.97 KB
/
ResendLeadNotificationsTest.php
File metadata and controls
60 lines (48 loc) · 1.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
<?php
namespace Tests\Feature;
use App\Models\Lead;
use App\Notifications\NewLeadSubmitted;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Notification;
use PHPUnit\Framework\Attributes\Test;
use Tests\TestCase;
class ResendLeadNotificationsTest extends TestCase
{
use RefreshDatabase;
#[Test]
public function it_resends_notifications_for_leads_from_the_given_date(): void
{
Notification::fake();
$oldLead = Lead::factory()->create(['created_at' => '2025-01-01 12:00:00']);
$matchingLead = Lead::factory()->create(['created_at' => '2025-03-15 09:00:00']);
$newerLead = Lead::factory()->create(['created_at' => '2025-03-16 14:00:00']);
$this->artisan('app:resend-lead-notifications', ['date' => '2025-03-15'])
->expectsOutputToContain('Found 2 lead(s)')
->expectsOutputToContain('Done.')
->assertExitCode(0);
Notification::assertSentOnDemand(
NewLeadSubmitted::class,
function ($notification, $channels, $notifiable) use ($matchingLead) {
return $notifiable->routes['mail'] === 'sales@nativephp.com'
&& $notification->lead->is($matchingLead);
}
);
Notification::assertSentOnDemand(
NewLeadSubmitted::class,
function ($notification, $channels, $notifiable) use ($newerLead) {
return $notifiable->routes['mail'] === 'sales@nativephp.com'
&& $notification->lead->is($newerLead);
}
);
Notification::assertNotSentTo($oldLead, NewLeadSubmitted::class);
}
#[Test]
public function it_shows_message_when_no_leads_are_found(): void
{
Notification::fake();
$this->artisan('app:resend-lead-notifications', ['date' => '2099-01-01'])
->expectsOutputToContain('No leads found')
->assertExitCode(0);
Notification::assertNothingSent();
}
}