Skip to content

Commit 97398f1

Browse files
committed
adds testing to unaccepted reminder command
1 parent 281ff6a commit 97398f1

File tree

2 files changed

+59
-8
lines changed

2 files changed

+59
-8
lines changed

app/Console/Commands/SendAcceptanceReminder.php

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -65,14 +65,15 @@ public function handle()
6565
return $item['acceptance']->assignedTo ? $item['acceptance']->assignedTo->id : '';
6666
});
6767

68-
$no_mail_address = [];
69-
7068
foreach($unacceptedAssetGroups as $unacceptedAssetGroup) {
7169
// The [0] is weird, but it allows for the item_count to work and grabs the appropriate info for each user.
7270
// Collapsing and flattening the collection doesn't work above.
7371
$acceptance = $unacceptedAssetGroup[0]['acceptance'];
7472
$locale = $acceptance->assignedTo?->locale;
7573
$email = $acceptance->assignedTo?->email;
74+
if(!$email){
75+
$this->info($acceptance->assignedTo->present()->fullName().' has no email address.');
76+
}
7677
$item_count = $unacceptedAssetGroup->count();
7778

7879
if ($locale && $email) {
@@ -84,12 +85,9 @@ public function handle()
8485
$count++;
8586
}
8687

87-
if (!empty($no_mail_address)) {
88-
foreach($no_mail_address as $user) {
89-
return $user.' has no email.';
90-
}
91-
}
92-
9388
$this->info($count.' users notified.');
89+
90+
return 0;
9491
}
92+
9593
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<?php
2+
3+
namespace Tests\Feature\Console;
4+
5+
use App\Mail\UnacceptedAssetReminderMail;
6+
use App\Models\CheckoutAcceptance;
7+
use App\Models\User;
8+
use Illuminate\Support\Facades\Mail;
9+
use Tests\TestCase;
10+
class SendAcceptanceReminderTest extends TestCase
11+
{
12+
public function testAcceptanceReminderCommand()
13+
{
14+
Mail::fake();
15+
$userA = User::factory()->create(['email' => '[email protected]']);
16+
$userB = User::factory()->create(['email' => '[email protected]']);
17+
18+
CheckoutAcceptance::factory()->pending()->count(2)->create([
19+
'assigned_to_id' => $userA->id,
20+
]);
21+
CheckoutAcceptance::factory()->pending()->create([
22+
'assigned_to_id' => $userB->id,
23+
]);
24+
25+
$this->artisan('snipeit:acceptance-reminder')->assertExitCode(0);
26+
27+
Mail::assertSent(UnacceptedAssetReminderMail::class, function ($mail) {
28+
return $mail->hasTo('[email protected]');
29+
});
30+
31+
Mail::assertSent(UnacceptedAssetReminderMail::class, function ($mail) {
32+
return $mail->hasTo('[email protected]');
33+
});
34+
35+
Mail::assertSent(UnacceptedAssetReminderMail::class,2);
36+
}
37+
38+
public function testAcceptanceReminderCommandHandlesUserWithoutEmail()
39+
{
40+
Mail::fake();
41+
$userA = User::factory()->create(['email' => '']);
42+
43+
CheckoutAcceptance::factory()->pending()->create([
44+
'assigned_to_id' => $userA->id,
45+
]);
46+
47+
$this->artisan('snipeit:acceptance-reminder')
48+
->expectsOutput($userA->present()->fullName().' has no email address.')
49+
->assertExitCode(0);
50+
51+
Mail::assertNotSent(UnacceptedAssetReminderMail::class);
52+
}
53+
}

0 commit comments

Comments
 (0)