Skip to content

Commit 53ff367

Browse files
committed
Add failing tests
1 parent 33a7de9 commit 53ff367

File tree

1 file changed

+46
-1
lines changed

1 file changed

+46
-1
lines changed

tests/Feature/Notifications/Email/BulkCheckoutEmailTest.php

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use App\Mail\BulkAssetCheckoutMail;
66
use App\Mail\CheckoutAssetMail;
77
use App\Models\Asset;
8+
use App\Models\Location;
89
use App\Models\User;
910
use Illuminate\Support\Facades\Mail;
1011
use PHPUnit\Framework\Attributes\Group;
@@ -44,6 +45,44 @@ public function test_email_is_sent_to_user()
4445
});
4546
}
4647

48+
public function test_email_is_sent_to_location_manager()
49+
{
50+
// todo: migrate this into a data provider?
51+
52+
$manager = User::factory()->create();
53+
54+
$this->target = Location::factory()->for($manager, 'manager')->create();
55+
56+
$this->sendRequest();
57+
58+
Mail::assertNotSent(CheckoutAssetMail::class);
59+
60+
Mail::assertSent(BulkAssetCheckoutMail::class, 1);
61+
62+
Mail::assertSent(BulkAssetCheckoutMail::class, function (BulkAssetCheckoutMail $mail) use ($manager) {
63+
return $mail->hasTo($manager->email);
64+
});
65+
}
66+
67+
public function test_email_is_sent_to_user_asset_is_checked_out_to()
68+
{
69+
// todo: migrate this into a data provider?
70+
71+
$user = User::factory()->create();
72+
73+
$this->target = Asset::factory()->assignedToUser($user)->create();
74+
75+
$this->sendRequest();
76+
77+
Mail::assertNotSent(CheckoutAssetMail::class);
78+
79+
Mail::assertSent(BulkAssetCheckoutMail::class, 1);
80+
81+
Mail::assertSent(BulkAssetCheckoutMail::class, function (BulkAssetCheckoutMail $mail) use ($user) {
82+
return $mail->hasTo($user->email);
83+
});
84+
}
85+
4786
public function test_email_is_not_sent_to_user_when_user_does_not_have_email_address()
4887
{
4988
$this->target = User::factory()->create(['email' => null]);
@@ -116,11 +155,17 @@ public function test_email_is_sent_to_cc_address_when_assets_do_not_require_acce
116155

117156
private function sendRequest()
118157
{
158+
$types = [
159+
User::class => 'user',
160+
Location::class => 'location',
161+
Asset::class => 'asset',
162+
];
163+
119164
$this->actingAs($this->admin)
120165
->followingRedirects()
121166
->post(route('hardware.bulkcheckout.store'), [
122167
'selected_assets' => $this->assets->pluck('id')->toArray(),
123-
'checkout_to_type' => 'user',
168+
'checkout_to_type' => $types[get_class($this->target)],
124169
'assigned_user' => $this->target->id,
125170
'assigned_asset' => null,
126171
'checkout_at' => now()->subWeek()->format('Y-m-d'),

0 commit comments

Comments
 (0)