mirror of
https://github.com/snipe/snipe-it.git
synced 2025-01-25 20:51:30 -08:00
Add simple test for LogListener
This commit is contained in:
parent
6f53f2ac64
commit
e65252725a
|
@ -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)
|
||||
|
|
37
tests/Unit/Listeners/LogListenerTest.php
Normal file
37
tests/Unit/Listeners/LogListenerTest.php
Normal 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...',
|
||||
]);
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue