mirror of
https://github.com/snipe/snipe-it.git
synced 2026-05-04 05:35:47 +00:00
Scaffold new listener
This commit is contained in:
22
app/Listeners/CheckoutablesCheckedOutInBulkListener.php
Normal file
22
app/Listeners/CheckoutablesCheckedOutInBulkListener.php
Normal file
@ -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
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
@ -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,
|
||||
];
|
||||
}
|
||||
|
||||
@ -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('someone@example.com');
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
41
tests/Feature/Notifications/Email/BulkCheckoutEmailTest.php
Normal file
41
tests/Feature/Notifications/Email/BulkCheckoutEmailTest.php
Normal file
@ -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' => 'someone@example.com']);
|
||||
$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('someone@example.com');
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user