-
-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adds testing to unaccepted reminder command
- Loading branch information
1 parent
281ff6a
commit 97398f1
Showing
2 changed files
with
59 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<?php | ||
|
||
namespace Tests\Feature\Console; | ||
|
||
use App\Mail\UnacceptedAssetReminderMail; | ||
use App\Models\CheckoutAcceptance; | ||
use App\Models\User; | ||
use Illuminate\Support\Facades\Mail; | ||
use Tests\TestCase; | ||
class SendAcceptanceReminderTest extends TestCase | ||
{ | ||
public function testAcceptanceReminderCommand() | ||
{ | ||
Mail::fake(); | ||
$userA = User::factory()->create(['email' => 'userA@test.com']); | ||
$userB = User::factory()->create(['email' => 'userB@test.com']); | ||
|
||
CheckoutAcceptance::factory()->pending()->count(2)->create([ | ||
'assigned_to_id' => $userA->id, | ||
]); | ||
CheckoutAcceptance::factory()->pending()->create([ | ||
'assigned_to_id' => $userB->id, | ||
]); | ||
|
||
$this->artisan('snipeit:acceptance-reminder')->assertExitCode(0); | ||
|
||
Mail::assertSent(UnacceptedAssetReminderMail::class, function ($mail) { | ||
return $mail->hasTo('userA@test.com'); | ||
}); | ||
|
||
Mail::assertSent(UnacceptedAssetReminderMail::class, function ($mail) { | ||
return $mail->hasTo('userB@test.com'); | ||
}); | ||
|
||
Mail::assertSent(UnacceptedAssetReminderMail::class,2); | ||
} | ||
|
||
public function testAcceptanceReminderCommandHandlesUserWithoutEmail() | ||
{ | ||
Mail::fake(); | ||
$userA = User::factory()->create(['email' => '']); | ||
|
||
CheckoutAcceptance::factory()->pending()->create([ | ||
'assigned_to_id' => $userA->id, | ||
]); | ||
|
||
$this->artisan('snipeit:acceptance-reminder') | ||
->expectsOutput($userA->present()->fullName().' has no email address.') | ||
->assertExitCode(0); | ||
|
||
Mail::assertNotSent(UnacceptedAssetReminderMail::class); | ||
} | ||
} |