Skip to content

A free open source IT asset/license management system

Improve event assertions

Marcus Mooref16c79bb9a74
diff --git a/app/Http/Controllers/Api/AssetsController.php b/app/Http/Controllers/Api/AssetsController.php
index bfdc0255e1..b5ef2e43cc 100644
--- a/app/Http/Controllers/Api/AssetsController.php
+++ b/app/Http/Controllers/Api/AssetsController.php
@@ -852,12 +852,9 @@ class AssetsController extends Controller
}
$checkout_at = request('checkout_at', date('Y-m-d H:i:s'));
- // @todo: test this
$expected_checkin = request('expected_checkin', null);
- // @todo: test this
$note = request('note', null);
// Using `->has` preserves the asset name if the name parameter was not included in request.
- // @todo: test this
$asset_name = request()->has('name') ? request('name') : $asset->name;
// Set the location ID to the RTD location id if there is one
diff --git a/tests/Feature/Api/Assets/AssetCheckoutTest.php b/tests/Feature/Api/Assets/AssetCheckoutTest.php
index 471b67a004..82d572ef5d 100644
--- a/tests/Feature/Api/Assets/AssetCheckoutTest.php
+++ b/tests/Feature/Api/Assets/AssetCheckoutTest.php
@@ -160,20 +160,21 @@ class AssetCheckoutTest extends TestCase
$this->actingAsForApi($admin)
->postJson(route('api.asset.checkout', $asset), [
'checkout_to_type' => $type,
- 'assigned_' . $type => $target->id,
+ 'assigned_'.$type => $target->id,
'status_id' => $newStatus->id,
'checkout_at' => '2024-04-01',
'expected_checkin' => '2024-04-08',
'name' => 'Changed Name',
'note' => 'Here is a cool note!',
- ]);
+ ])
+ ->assertOk();
$asset->refresh();
$this->assertTrue($asset->assignedTo()->is($target));
$this->assertEquals('Changed Name', $asset->name);
$this->assertTrue($asset->assetstatus->is($newStatus));
$this->assertEquals('2024-04-01 00:00:00', $asset->last_checkout);
- $this->assertEquals('2024-04-08 00:00:00', (string)$asset->expected_checkin);
+ $this->assertEquals('2024-04-08 00:00:00', (string) $asset->expected_checkin);
$expectedLocation
? $this->assertTrue($asset->location->is($expectedLocation))
@@ -181,10 +182,12 @@ class AssetCheckoutTest extends TestCase
Event::assertDispatched(CheckoutableCheckedOut::class, 1);
Event::assertDispatched(function (CheckoutableCheckedOut $event) use ($admin, $asset, $target) {
- return $event->checkoutable->is($asset)
- && $event->checkedOutTo->is($target)
- && $event->checkedOutBy->is($admin)
- && $event->note === 'Here is a cool note!';
+ $this->assertTrue($event->checkoutable->is($asset));
+ $this->assertTrue($event->checkedOutTo->is($target));
+ $this->assertTrue($event->checkedOutBy->is($admin));
+ $this->assertEquals('Here is a cool note!', $event->note);
+
+ return true;
});
}