Skip to content

A free open source IT asset/license management system

Scaffold new listener

Marcus Moore3c42acebf021
diff --git a/app/Listeners/CheckoutablesCheckedOutInBulkListener.php b/app/Listeners/CheckoutablesCheckedOutInBulkListener.php
new file mode 100644
index 0000000000..6a1d7528cb
--- /dev/null
+++ b/app/Listeners/CheckoutablesCheckedOutInBulkListener.php
@@ -0,0 +1,22 @@
+<?php
+
+namespace App\Listeners;
+
+use App\Events\CheckoutablesCheckedOutInBulk;
+
+class CheckoutablesCheckedOutInBulkListener
+{
+
+ public function subscribe($events)
+ {
+ $events->listen(
+ CheckoutablesCheckedOutInBulk::class,
+ CheckoutablesCheckedOutInBulkListener::class
+ );
+ }
+
+ public function handle(CheckoutablesCheckedOutInBulk $event): void
+ {
+ //
+ }
+}
diff --git a/app/Providers/EventServiceProvider.php b/app/Providers/EventServiceProvider.php
index 1f08b445c9..9143cdc8f5 100644
--- a/app/Providers/EventServiceProvider.php
+++ b/app/Providers/EventServiceProvider.php
@@ -3,6 +3,7 @@
namespace App\Providers;
use App\Listeners\CheckoutableListener;
+use App\Listeners\CheckoutablesCheckedOutInBulkListener;
use App\Listeners\LogListener;
use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;
@@ -31,5 +32,6 @@ class EventServiceProvider extends ServiceProvider
protected $subscribe = [
LogListener::class,
CheckoutableListener::class,
+ CheckoutablesCheckedOutInBulkListener::class,
];
}
diff --git a/tests/Feature/Checkouts/Ui/BulkAssetCheckoutTest.php b/tests/Feature/Checkouts/Ui/BulkAssetCheckoutTest.php
index b422e09aa4..12a4aa264e 100644
--- a/tests/Feature/Checkouts/Ui/BulkAssetCheckoutTest.php
+++ b/tests/Feature/Checkouts/Ui/BulkAssetCheckoutTest.php
@@ -3,7 +3,6 @@
namespace Tests\Feature\Checkouts\Ui;
use App\Events\CheckoutablesCheckedOutInBulk;
-use App\Mail\BulkAssetCheckoutMail;
use App\Mail\CheckoutAssetMail;
use App\Models\Asset;
use App\Models\Company;
@@ -195,7 +194,6 @@ class BulkAssetCheckoutTest extends TestCase
#[Group('notifications')]
public function test_one_email_is_sent_instead_of_multiple_individual_ones()
{
- Event::fake();
Mail::fake();
$assets = Asset::factory()->requiresAcceptance()->count(2)->create();
@@ -220,6 +218,7 @@ class BulkAssetCheckoutTest extends TestCase
// $this->assertHasTheseActionLogs($asset, ['create', 'checkout']);
// });
+ // ensure individual emails are not sent.
Mail::assertSent(CheckoutAssetMail::class, 0);
Event::assertDispatchedTimes(CheckoutablesCheckedOutInBulk::class, 1);
@@ -240,12 +239,5 @@ class BulkAssetCheckoutTest extends TestCase
return true;
});
-
- // @todo: move to Notifications test directory?
- Mail::assertSent(BulkAssetCheckoutMail::class, 1);
- Mail::assertSent(BulkAssetCheckoutMail::class, function (BulkAssetCheckoutMail $mail) {
- // @todo: assert contents
- return $mail->hasTo('[email protected]');
- });
}
}
diff --git a/tests/Feature/Notifications/Email/BulkCheckoutEmailTest.php b/tests/Feature/Notifications/Email/BulkCheckoutEmailTest.php
new file mode 100644
index 0000000000..67ba01d28e
--- /dev/null
+++ b/tests/Feature/Notifications/Email/BulkCheckoutEmailTest.php
@@ -0,0 +1,41 @@
+<?php
+
+namespace Tests\Feature\Notifications\Email;
+
+use App\Events\CheckoutablesCheckedOutInBulk;
+use App\Mail\BulkAssetCheckoutMail;
+use App\Models\Asset;
+use App\Models\User;
+use Illuminate\Support\Facades\Mail;
+use Tests\TestCase;
+
+class BulkCheckoutEmailTest extends TestCase
+{
+ public function test_email_is_sent()
+ {
+ $this->markTestIncomplete();
+
+ Mail::fake();
+
+ $assets = Asset::factory()->count(2)->create();
+ $target = User::factory()->create(['email' => '[email protected]']);
+ $admin = User::factory()->create();
+ $checkout_at = date('Y-m-d H:i:s');
+ $expected_checkin = '';
+
+ CheckoutablesCheckedOutInBulk::dispatch(
+ $assets,
+ $target,
+ $admin,
+ $checkout_at,
+ $expected_checkin,
+ 'A note here',
+ );
+
+ Mail::assertSent(BulkAssetCheckoutMail::class, 1);
+ Mail::assertSent(BulkAssetCheckoutMail::class, function (BulkAssetCheckoutMail $mail) {
+ // @todo: assert contents
+ return $mail->hasTo('[email protected]');
+ });
+ }
+}