Implement test case

This commit is contained in:
Marcus Moore 2024-03-20 17:46:09 -07:00
parent 530291f81c
commit b368acf941
No known key found for this signature in database
2 changed files with 26 additions and 3 deletions

View file

@ -2,6 +2,7 @@
namespace Database\Factories;
use App\Models\Asset;
use App\Models\License;
use App\Models\User;
use Illuminate\Database\Eloquent\Factories\Factory;
@ -15,6 +16,15 @@ class LicenseSeatFactory extends Factory
];
}
public function assignedToAsset(Asset $asset = null)
{
return $this->state(function () use ($asset) {
return [
'asset_id' => $asset->id,
];
});
}
public function assignedToUser(User $user = null)
{
return $this->state(function () use ($user) {

View file

@ -4,6 +4,7 @@ namespace Tests\Feature\Checkouts;
use App\Events\CheckoutableCheckedOut;
use App\Models\Asset;
use App\Models\LicenseSeat;
use App\Models\Location;
use App\Models\Statuslabel;
use App\Models\User;
@ -102,9 +103,9 @@ class AssetCheckoutTest extends TestCase
// @todo: ensure asset updated
$asset->refresh();
$this->assertTrue($asset->location->is($userLocation));
$this->assertEquals('2024-03-28 00:00:00', (string) $asset->expected_checkin);
$this->assertEquals('2024-03-28 00:00:00', (string)$asset->expected_checkin);
$this->assertTrue($asset->assetstatus->is($updatedStatus));
Event::assertDispatched(function (CheckoutableCheckedOut $event) use ($admin, $asset, $user) {
return $event->checkoutable->is($asset)
&& $event->checkedOutTo->is($user)
@ -117,7 +118,19 @@ class AssetCheckoutTest extends TestCase
public function testLicenseSeatsAreAssignedToUserUponCheckout()
{
$this->markTestIncomplete();
$asset = Asset::factory()->create();
$seat = LicenseSeat::factory()->assignedToAsset($asset)->create();
$user = User::factory()->create();
$this->assertFalse($user->licenses->contains($seat->license));
$this->actingAs(User::factory()->checkoutAssets()->create())
->post(route('hardware.checkout.store', $asset), [
'checkout_to_type' => 'user',
'assigned_user' => $user->id,
]);
$this->assertTrue($user->fresh()->licenses->contains($seat->license));
}
public function testAnAssetCanBeCheckedOutToAnAsset()