Skip to content

A free open source IT asset/license management system

Improve readability

Marcus Moore364775dcfe8a
diff --git a/tests/Feature/Users/Ui/BulkDeleteUsersTest.php b/tests/Feature/Users/Ui/BulkDeleteUsersTest.php
index 36526318e8..2da5cd9078 100644
--- a/tests/Feature/Users/Ui/BulkDeleteUsersTest.php
+++ b/tests/Feature/Users/Ui/BulkDeleteUsersTest.php
@@ -6,6 +6,7 @@ use App\Models\Accessory;
use App\Models\Consumable;
use App\Models\Statuslabel;
use App\Models\User;
+use Illuminate\Database\Eloquent\Model;
use Tests\TestCase;
class BulkDeleteUsersTest extends TestCase
@@ -31,32 +32,9 @@ class BulkDeleteUsersTest extends TestCase
// These assertions check against a bug where the wrong value from
// accessories_users was being populated in action_logs.item_id.
- $this->assertDatabaseHas('action_logs', [
- 'action_type' => 'checkin from',
- 'target_id' => $userA->id,
- 'target_type' => User::class,
- 'note' => 'Bulk checkin items',
- 'item_type' => Accessory::class,
- 'item_id' => $accessoryA->id,
- ]);
-
- $this->assertDatabaseHas('action_logs', [
- 'action_type' => 'checkin from',
- 'target_id' => $userA->id,
- 'target_type' => User::class,
- 'note' => 'Bulk checkin items',
- 'item_type' => Accessory::class,
- 'item_id' => $accessoryB->id,
- ]);
-
- $this->assertDatabaseHas('action_logs', [
- 'action_type' => 'checkin from',
- 'target_id' => $userC->id,
- 'target_type' => User::class,
- 'note' => 'Bulk checkin items',
- 'item_type' => Accessory::class,
- 'item_id' => $accessoryA->id,
- ]);
+ $this->assertActionLogCheckInEntryFor($userA, $accessoryA);
+ $this->assertActionLogCheckInEntryFor($userA, $accessoryB);
+ $this->assertActionLogCheckInEntryFor($userC, $accessoryA);
}
public function testConsumableCheckinsAreProperlyLogged()
@@ -80,32 +58,9 @@ class BulkDeleteUsersTest extends TestCase
// These assertions check against a bug where the wrong value from
// consumables_users was being populated in action_logs.item_id.
- $this->assertDatabaseHas('action_logs', [
- 'action_type' => 'checkin from',
- 'target_id' => $userA->id,
- 'target_type' => User::class,
- 'note' => 'Bulk checkin items',
- 'item_type' => Consumable::class,
- 'item_id' => $consumableA->id,
- ]);
-
- $this->assertDatabaseHas('action_logs', [
- 'action_type' => 'checkin from',
- 'target_id' => $userA->id,
- 'target_type' => User::class,
- 'note' => 'Bulk checkin items',
- 'item_type' => Consumable::class,
- 'item_id' => $consumableB->id,
- ]);
-
- $this->assertDatabaseHas('action_logs', [
- 'action_type' => 'checkin from',
- 'target_id' => $userC->id,
- 'target_type' => User::class,
- 'note' => 'Bulk checkin items',
- 'item_type' => Consumable::class,
- 'item_id' => $consumableA->id,
- ]);
+ $this->assertActionLogCheckInEntryFor($userA, $consumableA);
+ $this->assertActionLogCheckInEntryFor($userA, $consumableB);
+ $this->assertActionLogCheckInEntryFor($userC, $consumableA);
}
private function attachAccessoryToUsers(Accessory $accessory, array $users): void
@@ -127,4 +82,16 @@ class BulkDeleteUsersTest extends TestCase
]);
}
}
+
+ private function assertActionLogCheckInEntryFor(User $user, Model $model): void
+ {
+ $this->assertDatabaseHas('action_logs', [
+ 'action_type' => 'checkin from',
+ 'target_id' => $user->id,
+ 'target_type' => User::class,
+ 'note' => 'Bulk checkin items',
+ 'item_type' => get_class($model),
+ 'item_id' => $model->id,
+ ]);
+ }
}