From cdd4fef7df6d49951aaa09ca597995b90a26f2ad Mon Sep 17 00:00:00 2001 From: Godfrey M Date: Thu, 17 Oct 2024 13:34:55 -0700 Subject: [PATCH] attempt to fix tests p2 --- .../Feature/Checkins/Ui/AccessoryCheckinTest.php | 2 +- .../Checkouts/Api/AccessoryCheckoutTest.php | 8 ++++++-- .../Checkouts/Api/ConsumableCheckoutTest.php | 6 ++++-- .../Checkouts/Ui/AccessoryCheckoutTest.php | 2 +- .../Checkouts/Ui/ConsumableCheckoutTest.php | 2 +- tests/Feature/Importing/Api/ImportAssetsTest.php | 4 +++- .../Email/EmailNotificationsUponCheckinTest.php | 2 +- tests/Unit/NotificationTest.php | 16 +++++++++------- 8 files changed, 26 insertions(+), 16 deletions(-) diff --git a/tests/Feature/Checkins/Ui/AccessoryCheckinTest.php b/tests/Feature/Checkins/Ui/AccessoryCheckinTest.php index 56d429ac56..419bead5a0 100644 --- a/tests/Feature/Checkins/Ui/AccessoryCheckinTest.php +++ b/tests/Feature/Checkins/Ui/AccessoryCheckinTest.php @@ -77,7 +77,7 @@ class AccessoryCheckinTest extends TestCase '', )); - Mail::assertSent(CheckoutAccessoryMail::class, function ($mail) use ($accessory, $user) { + Mail::assertNotSent(CheckoutAccessoryMail::class, function ($mail) use ($accessory, $user) { return $mail->hasTo($user) && $mail->contains($accessory); }); } diff --git a/tests/Feature/Checkouts/Api/AccessoryCheckoutTest.php b/tests/Feature/Checkouts/Api/AccessoryCheckoutTest.php index 765b8436a0..62a7b68733 100644 --- a/tests/Feature/Checkouts/Api/AccessoryCheckoutTest.php +++ b/tests/Feature/Checkouts/Api/AccessoryCheckoutTest.php @@ -2,10 +2,12 @@ namespace Tests\Feature\Checkouts\Api; +use App\Mail\CheckoutAccessoryMail; use App\Models\Accessory; use App\Models\Actionlog; use App\Models\User; use App\Notifications\CheckoutAccessoryNotification; +use Illuminate\Support\Facades\Mail; use Illuminate\Support\Facades\Notification; use Tests\Concerns\TestsPermissionsRequirement; use Tests\TestCase; @@ -146,7 +148,7 @@ class AccessoryCheckoutTest extends TestCase implements TestsPermissionsRequirem public function testUserSentNotificationUponCheckout() { - Notification::fake(); + Mail::fake(); $accessory = Accessory::factory()->requiringAcceptance()->create(); $user = User::factory()->create(); @@ -157,7 +159,9 @@ class AccessoryCheckoutTest extends TestCase implements TestsPermissionsRequirem 'checkout_to_type' => 'user', ]); - Notification::assertSentTo($user, CheckoutAccessoryNotification::class); + Mail::assertSent(CheckoutAccessoryMail::class, function ($mail) use ($accessory, $user) { + return $mail->hasTo($user) && $mail->contains($accessory); + }); } public function testActionLogCreatedUponCheckout() diff --git a/tests/Feature/Checkouts/Api/ConsumableCheckoutTest.php b/tests/Feature/Checkouts/Api/ConsumableCheckoutTest.php index 94fa63cba3..eaeeb9fb83 100644 --- a/tests/Feature/Checkouts/Api/ConsumableCheckoutTest.php +++ b/tests/Feature/Checkouts/Api/ConsumableCheckoutTest.php @@ -2,10 +2,12 @@ namespace Tests\Feature\Checkouts\Api; +use App\Mail\CheckoutConsumableMail; use App\Models\Actionlog; use App\Models\Consumable; use App\Models\User; use App\Notifications\CheckoutConsumableNotification; +use Illuminate\Support\Facades\Mail; use Illuminate\Support\Facades\Notification; use Tests\TestCase; @@ -51,7 +53,7 @@ class ConsumableCheckoutTest extends TestCase public function testUserSentNotificationUponCheckout() { - Notification::fake(); + Mail::fake(); $consumable = Consumable::factory()->requiringAcceptance()->create(); @@ -62,7 +64,7 @@ class ConsumableCheckoutTest extends TestCase 'assigned_to' => $user->id, ]); - Notification::assertSentTo($user, CheckoutConsumableNotification::class); + Mail::assertSentTo($user, CheckoutConsumableMail::class); } public function testActionLogCreatedUponCheckout() diff --git a/tests/Feature/Checkouts/Ui/AccessoryCheckoutTest.php b/tests/Feature/Checkouts/Ui/AccessoryCheckoutTest.php index fedc1a2584..9b79b02da2 100644 --- a/tests/Feature/Checkouts/Ui/AccessoryCheckoutTest.php +++ b/tests/Feature/Checkouts/Ui/AccessoryCheckoutTest.php @@ -171,7 +171,7 @@ class AccessoryCheckoutTest extends TestCase ]); Mail::assertSent(CheckoutAccessoryMail::class, function ($mail) use ($accessory, $user) { - return $mail->hasTo($user) && $mail->contains($accessory); + return $mail->hasTo($user->email) && $mail->accessory->is($accessory); }); } diff --git a/tests/Feature/Checkouts/Ui/ConsumableCheckoutTest.php b/tests/Feature/Checkouts/Ui/ConsumableCheckoutTest.php index 2ce4a04533..4a8f6d7323 100644 --- a/tests/Feature/Checkouts/Ui/ConsumableCheckoutTest.php +++ b/tests/Feature/Checkouts/Ui/ConsumableCheckoutTest.php @@ -66,7 +66,7 @@ class ConsumableCheckoutTest extends TestCase ]); Mail::assertSent(CheckoutConsumableMail::class, function ($mail) use ($consumable, $user) { - return $mail->hasTo($user) && $mail->consumables->contains($consumable); + return $mail->hasTo($user->email) && $mail->consumable->is($consumable); }); } diff --git a/tests/Feature/Importing/Api/ImportAssetsTest.php b/tests/Feature/Importing/Api/ImportAssetsTest.php index 66cc5174c4..58d3a83ecb 100644 --- a/tests/Feature/Importing/Api/ImportAssetsTest.php +++ b/tests/Feature/Importing/Api/ImportAssetsTest.php @@ -140,7 +140,9 @@ class ImportAssetsTest extends ImportDataTestCase implements TestsPermissionsReq //Notes is never read. // $this->assertEquals($row['notes'], $newAsset->notes); - Mail::assertSent($assignee, CheckoutAssetMail::class); + Mail::assertSent(CheckoutAssetMail::class, function ($mail) use ($assignee) { + return $mail->hasTo($assignee->email); + }); } #[Test] diff --git a/tests/Feature/Notifications/Email/EmailNotificationsUponCheckinTest.php b/tests/Feature/Notifications/Email/EmailNotificationsUponCheckinTest.php index c7c239b7ab..0b1a1fddc5 100644 --- a/tests/Feature/Notifications/Email/EmailNotificationsUponCheckinTest.php +++ b/tests/Feature/Notifications/Email/EmailNotificationsUponCheckinTest.php @@ -19,7 +19,7 @@ class EmailNotificationsUponCheckinTest extends TestCase { parent::setUp(); - Notification::fake(); + Mail::fake(); } public function testCheckInEmailSentToUserIfSettingEnabled() diff --git a/tests/Unit/NotificationTest.php b/tests/Unit/NotificationTest.php index 86177c3030..16350e117e 100644 --- a/tests/Unit/NotificationTest.php +++ b/tests/Unit/NotificationTest.php @@ -1,12 +1,14 @@ Carbon::createFromDate(2017, 1, 1)->hour(0)->minute(0)->second(0)->format('Y-m-d') ]); - Notification::fake(); + Mail::fake(); $asset->checkOut($user, $admin->id); - Notification::assertSentTo($user, CheckoutAssetNotification::class); + Mail::assertSent($user, CheckoutAssetMail::class); } public function testDefaultEulaIsSentWhenSetInCategory() { - Notification::fake(); + Mail::fake(); $this->settings->setEula('My Custom EULA Text'); @@ -51,10 +53,10 @@ class NotificationTest extends TestCase $asset->checkOut($user, User::factory()->superuser()->create()->id); - Notification::assertSentTo($user, CheckoutAssetNotification::class, function ($notification) { - $content = $notification->toMail()->render(); - - return str_contains($content, 'My Custom EULA Text') && !str_contains($content, 'EULA Text that should not be used'); + Mail::assertSent(CheckoutAssetMail::class, function ($mail) use ($user) { + return $mail->hasTo($user->email) && + str_contains($mail->render(), 'My Custom EULA Text') && + !str_contains($mail->render(), 'EULA Text that should not be used'); }); } }