Skip to content

A free open source IT asset/license management system

Add failing tests

Marcus Moore53ff367473c7
diff --git a/tests/Feature/Notifications/Email/BulkCheckoutEmailTest.php b/tests/Feature/Notifications/Email/BulkCheckoutEmailTest.php
index 1542787295..e208c9d541 100644
--- a/tests/Feature/Notifications/Email/BulkCheckoutEmailTest.php
+++ b/tests/Feature/Notifications/Email/BulkCheckoutEmailTest.php
@@ -5,6 +5,7 @@ namespace Tests\Feature\Notifications\Email;
use App\Mail\BulkAssetCheckoutMail;
use App\Mail\CheckoutAssetMail;
use App\Models\Asset;
+use App\Models\Location;
use App\Models\User;
use Illuminate\Support\Facades\Mail;
use PHPUnit\Framework\Attributes\Group;
@@ -44,6 +45,44 @@ class BulkCheckoutEmailTest extends TestCase
});
}
+ public function test_email_is_sent_to_location_manager()
+ {
+ // todo: migrate this into a data provider?
+
+ $manager = User::factory()->create();
+
+ $this->target = Location::factory()->for($manager, 'manager')->create();
+
+ $this->sendRequest();
+
+ Mail::assertNotSent(CheckoutAssetMail::class);
+
+ Mail::assertSent(BulkAssetCheckoutMail::class, 1);
+
+ Mail::assertSent(BulkAssetCheckoutMail::class, function (BulkAssetCheckoutMail $mail) use ($manager) {
+ return $mail->hasTo($manager->email);
+ });
+ }
+
+ public function test_email_is_sent_to_user_asset_is_checked_out_to()
+ {
+ // todo: migrate this into a data provider?
+
+ $user = User::factory()->create();
+
+ $this->target = Asset::factory()->assignedToUser($user)->create();
+
+ $this->sendRequest();
+
+ Mail::assertNotSent(CheckoutAssetMail::class);
+
+ Mail::assertSent(BulkAssetCheckoutMail::class, 1);
+
+ Mail::assertSent(BulkAssetCheckoutMail::class, function (BulkAssetCheckoutMail $mail) use ($user) {
+ return $mail->hasTo($user->email);
+ });
+ }
+
public function test_email_is_not_sent_to_user_when_user_does_not_have_email_address()
{
$this->target = User::factory()->create(['email' => null]);
@@ -116,11 +155,17 @@ class BulkCheckoutEmailTest extends TestCase
private function sendRequest()
{
+ $types = [
+ User::class => 'user',
+ Location::class => 'location',
+ Asset::class => 'asset',
+ ];
+
$this->actingAs($this->admin)
->followingRedirects()
->post(route('hardware.bulkcheckout.store'), [
'selected_assets' => $this->assets->pluck('id')->toArray(),
- 'checkout_to_type' => 'user',
+ 'checkout_to_type' => $types[get_class($this->target)],
'assigned_user' => $this->target->id,
'assigned_asset' => null,
'checkout_at' => now()->subWeek()->format('Y-m-d'),