forked from puncoz-bookmarks/laravel-mailcoach-tests
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SendScheduledCampaignsCommandTest.php
77 lines (60 loc) · 2.19 KB
/
SendScheduledCampaignsCommandTest.php
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<?php
namespace Tests\Feature\Commands;
use Illuminate\Support\Facades\Bus;
use Spatie\Mailcoach\Commands\SendScheduledCampaignsCommand;
use Spatie\Mailcoach\Enums\CampaignStatus;
use Spatie\Mailcoach\Jobs\SendCampaignJob;
use Spatie\Mailcoach\Models\Campaign;
use Spatie\Mailcoach\Tests\TestCase;
use Spatie\TestTime\TestTime;
class SendScheduledCampaignsCommandTest extends TestCase
{
public function setUp(): void
{
parent::setUp();
TestTime::freeze();
Bus::fake();
}
/** @test */
public function it_will_not_send_campaigns_that_are_not_scheduled()
{
factory(Campaign::class)->create([
'scheduled_at' => null,
'status' => CampaignStatus::DRAFT,
]);
$this->artisan(SendScheduledCampaignsCommand::class)->assertExitCode(0);
Bus::assertNotDispatched(SendCampaignJob::class);
}
/** @test */
public function it_will_not_send_a_campaign_that_has_a_scheduled_at_in_the_future()
{
factory(Campaign::class)->create([
'scheduled_at' => now()->addSecond(),
'status' => CampaignStatus::DRAFT,
]);
$this->artisan(SendScheduledCampaignsCommand::class)->assertExitCode(0);
Bus::assertNotDispatched(SendCampaignJob::class);
}
/** @test */
public function it_will_send_a_campaign_that_has_a_scheduled_at_set_to_in_the_past()
{
factory(Campaign::class)->create([
'scheduled_at' => now()->subSecond(),
'status' => CampaignStatus::DRAFT,
]);
$this->artisan(SendScheduledCampaignsCommand::class)->assertExitCode(0);
Bus::assertDispatched(SendCampaignJob::class);
}
/** @test */
public function it_will_not_send_a_campaign_twice()
{
factory(Campaign::class)->create([
'scheduled_at' => now()->subSecond(),
'status' => CampaignStatus::DRAFT,
]);
$this->artisan(SendScheduledCampaignsCommand::class)->assertExitCode(0);
Bus::assertDispatchedTimes(SendCampaignJob::class, 1);
$this->artisan(SendScheduledCampaignsCommand::class)->assertExitCode(0);
Bus::assertDispatchedTimes(SendCampaignJob::class, 1);
}
}