From 16aa47509b3f655f6a9e2497ed38278c4fd7a702 Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Mon, 5 Aug 2024 16:24:52 -0700 Subject: [PATCH] Implement test for assets --- .../Feature/Users/Ui/BulkDeleteUsersTest.php | 35 +++++++++++++++++-- 1 file changed, 32 insertions(+), 3 deletions(-) diff --git a/tests/Feature/Users/Ui/BulkDeleteUsersTest.php b/tests/Feature/Users/Ui/BulkDeleteUsersTest.php index 4048f50b4..8787e849e 100644 --- a/tests/Feature/Users/Ui/BulkDeleteUsersTest.php +++ b/tests/Feature/Users/Ui/BulkDeleteUsersTest.php @@ -101,10 +101,34 @@ class BulkDeleteUsersTest extends TestCase public function testAssetsCanBeBulkCheckedIn() { - $this->markTestIncomplete(); + // $this->markTestIncomplete(); - // @todo: - // $this->assertActionLogCheckInEntryFor(); ... + [$userA, $userB, $userC] = User::factory()->count(3)->create(); + + $assetA = $this->assignAssetToUser($userA); + $assetB = $this->assignAssetToUser($userB); + $assetC = $this->assignAssetToUser($userC); + + $this->assertTrue($userA->assets->isNotEmpty()); + $this->assertTrue($userB->assets->isNotEmpty()); + $this->assertTrue($userC->assets->isNotEmpty()); + + $this->actingAs(User::factory()->editUsers()->create()) + ->post(route('users/bulksave'), [ + 'ids' => [ + $userA->id, + $userC->id, + ], + 'status_id' => Statuslabel::factory()->create()->id, + ]) + ->assertRedirect(route('users.index')); + + $this->assertTrue($userA->fresh()->assets->isEmpty()); + $this->assertTrue($userB->fresh()->assets->isNotEmpty()); + $this->assertTrue($userC->fresh()->assets->isEmpty()); + + $this->assertActionLogCheckInEntryFor($userA, $assetA); + $this->assertActionLogCheckInEntryFor($userC, $assetC); } public function testConsumablesCanBeBulkCheckedIn() @@ -200,4 +224,9 @@ class BulkDeleteUsersTest extends TestCase 'item_id' => $model->id, ]); } + + private function assignAssetToUser(User $user): Asset + { + return Asset::factory()->assignedToUser($user)->create(); + } }