Add simple test for LogListener

This commit is contained in:
Marcus Moore 2024-04-10 11:52:59 -07:00
parent 6f53f2ac64
commit e65252725a
No known key found for this signature in database
2 changed files with 38 additions and 0 deletions

View file

@ -103,6 +103,7 @@ class AssetCheckoutTest extends TestCase
$this->assertEquals('2024-03-18 00:00:00', $asset->last_checkout);
$this->assertEquals('2024-03-28 00:00:00', (string)$asset->expected_checkin);
Event::assertDispatched(CheckoutableCheckedOut::class, 1);
Event::assertDispatched(function (CheckoutableCheckedOut $event) use ($admin, $asset, $user) {
return $event->checkoutable->is($asset)
&& $event->checkedOutTo->is($user)

View file

@ -0,0 +1,37 @@
<?php
namespace Tests\Unit\Listeners;
use App\Events\CheckoutableCheckedOut;
use App\Listeners\LogListener;
use App\Models\Asset;
use App\Models\User;
use Tests\TestCase;
class LogListenerTest extends TestCase
{
public function testLogsEntryOnCheckoutableCheckedOut()
{
$asset = Asset::factory()->create();
$checkedOutTo = User::factory()->create();
$checkedOutBy = User::factory()->create();
$this->actingAs($checkedOutBy);
(new LogListener())->onCheckoutableCheckedOut(new CheckoutableCheckedOut(
$asset,
$checkedOutTo,
$checkedOutBy,
'A simple note...',
));
$this->assertDatabaseHas('action_logs', [
'action_type' => 'checkout',
'user_id' => $checkedOutBy->id,
'target_id' => $checkedOutTo->id,
'target_type' => User::class,
'item_id' => $asset->id,
'item_type' => Asset::class,
'note' => 'A simple note...',
]);
}
}