Skip to content

A free open source IT asset/license management system

Scaffold some testing changes

Marcus Mooref34056fe2e74
diff --git a/tests/Feature/Checkouts/Ui/BulkAssetCheckoutTest.php b/tests/Feature/Checkouts/Ui/BulkAssetCheckoutTest.php
index 12a4aa264e..07a9da7a6b 100644
--- a/tests/Feature/Checkouts/Ui/BulkAssetCheckoutTest.php
+++ b/tests/Feature/Checkouts/Ui/BulkAssetCheckoutTest.php
@@ -36,6 +36,8 @@ class BulkAssetCheckoutTest extends TestCase
{
Mail::fake();
+ Event::fake();
+
$assets = Asset::factory()->requiresAcceptance()->count(2)->create();
$user = User::factory()->create(['email' => '[email protected]']);
@@ -57,6 +59,9 @@ class BulkAssetCheckoutTest extends TestCase
$assets = $assets->fresh();
+ Event::assertDispatched(CheckoutablesCheckedOutInBulk::class);
+
+ // @todo: move to another test case
$assets->each(function ($asset) use ($expectedCheckin, $checkoutAt, $user) {
$asset->assignedTo()->is($user);
$asset->last_checkout = $checkoutAt;
@@ -64,6 +69,7 @@ class BulkAssetCheckoutTest extends TestCase
$this->assertHasTheseActionLogs($asset, ['create', 'checkout']); //Note: '$this' gets auto-bound in closures, so this does work.
});
+ // @todo: move to another test case
Mail::assertSent(CheckoutAssetMail::class, 2);
Mail::assertSent(CheckoutAssetMail::class, function (CheckoutAssetMail $mail) {
return $mail->hasTo('[email protected]');
diff --git a/tests/Unit/Events/CheckoutablesCheckedOutInBulkTest.php b/tests/Unit/Events/CheckoutablesCheckedOutInBulkTest.php
new file mode 100644
index 0000000000..6c2a89ff18
--- /dev/null
+++ b/tests/Unit/Events/CheckoutablesCheckedOutInBulkTest.php
@@ -0,0 +1,99 @@
+<?php
+
+namespace Tests\Unit\Events;
+
+use App\Events\CheckoutablesCheckedOutInBulk;
+use App\Mail\BulkAssetCheckoutMail;
+use App\Models\Asset;
+use App\Models\User;
+use App\Notifications\CheckoutAssetNotification;
+use Illuminate\Support\Facades\Mail;
+use Illuminate\Support\Facades\Notification;
+use PHPUnit\Framework\Attributes\Group;
+use Tests\TestCase;
+
+class CheckoutablesCheckedOutInBulkTest extends TestCase
+{
+ private $assets;
+ private $target;
+ private $admin;
+ private $checkout_at;
+ private $expected_checkin;
+
+ protected function setUp(): void
+ {
+ parent::setUp();
+
+ $this->assets = Asset::factory()->count(2)->create();
+ $this->target = User::factory()->create(['email' => '[email protected]']);
+ $this->admin = User::factory()->create();
+ $this->checkout_at = date('Y-m-d H:i:s');
+ $this->expected_checkin = '';
+ }
+
+ public function test_action_log_entries()
+ {
+ $this->markTestIncomplete();
+
+ $this->dispatchEvent();
+
+ $this->assets->each(function ($asset) {
+ $asset->assignedTo()->is($this->target);
+ $asset->last_checkout = $this->checkout_at;
+ $asset->expected_checkin = $this->expected_checkin;
+ $this->assertHasTheseActionLogs($asset, ['create', 'checkout']); //Note: '$this' gets auto-bound in closures, so this does work.
+ });
+ }
+
+ public function test_checkout_acceptance_creation()
+ {
+ $this->markTestIncomplete();
+ }
+
+ #[Group('notifications')]
+ public function test_emails()
+ {
+ $this->markTestIncomplete();
+
+ Mail::fake();
+
+ $this->settings->enableAdminCC('[email protected]');
+
+ $this->dispatchEvent();
+
+ // we shouldn't send the "single" checkout mailable
+ Mail::assertNotSent(CheckoutAssetNotification::class);
+
+ Mail::assertSent(BulkAssetCheckoutMail::class, 2);
+
+ Mail::assertSent(BulkAssetCheckoutMail::class, function (BulkAssetCheckoutMail $mail) {
+ // @todo: assert contents
+ return $mail->hasTo('[email protected]');
+ });
+
+ Mail::assertSent(BulkAssetCheckoutMail::class, function (BulkAssetCheckoutMail $mail) {
+ // @todo: assert contents
+ return $mail->hasTo('[email protected]');
+ });
+ }
+
+ #[Group('notifications')]
+ public function test_webhooks()
+ {
+ $this->markTestIncomplete();
+
+ Notification::fake();
+ }
+
+ private function dispatchEvent(): void
+ {
+ CheckoutablesCheckedOutInBulk::dispatch(
+ $this->assets,
+ $this->target,
+ $this->admin,
+ $this->checkout_at,
+ $this->expected_checkin,
+ 'A note here',
+ );
+ }
+}