From f16c79bb9a74b44c4e5bca6de01923ee627fc81a Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Wed, 22 May 2024 15:38:23 -0700 Subject: [PATCH] Improve event assertions --- app/Http/Controllers/Api/AssetsController.php | 3 --- tests/Feature/Api/Assets/AssetCheckoutTest.php | 17 ++++++++++------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/app/Http/Controllers/Api/AssetsController.php b/app/Http/Controllers/Api/AssetsController.php index bfdc0255e..b5ef2e43c 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 471b67a00..82d572ef5 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; }); }