Implement test

This commit is contained in:
Marcus Moore 2024-02-14 10:48:49 -08:00
parent 7bfd02054b
commit af513946a2
No known key found for this signature in database
2 changed files with 33 additions and 3 deletions

View file

@ -2,8 +2,11 @@
namespace Tests\Feature\Api\Assets;
use App\Events\CheckoutableCheckedIn;
use App\Models\Asset;
use App\Models\Statuslabel;
use App\Models\User;
use Illuminate\Support\Facades\Event;
use Tests\Support\InteractsWithSettings;
use Tests\TestCase;
@ -34,7 +37,35 @@ class AssetCheckinTest extends TestCase
public function testAssetCanBeCheckedIn()
{
$this->markTestIncomplete();
Event::fake([CheckoutableCheckedIn::class]);
$user = User::factory()->create();
$status = Statuslabel::factory()->create();
$asset = Asset::factory()->assignedToUser($user)->create([
'expected_checkin' => now()->addDay(),
'last_checkin' => null,
'accepted' => 'accepted',
]);
$this->assertTrue($asset->assignedTo->is($user));
$this->actingAsForApi(User::factory()->checkinAssets()->create())
->postJson(route('api.asset.checkin', $asset->id), [
'name' => 'Changed Name',
'status_id' => $status->id,
])
->assertOk();
Event::assertDispatched(CheckoutableCheckedIn::class, 1);
$this->assertNull($asset->refresh()->assignedTo);
$this->assertNull($asset->expected_checkin);
$this->assertNull($asset->last_checkout);
$this->assertNotNull($asset->last_checkin);
$this->assertNull($asset->assignedTo);
$this->assertNull($asset->assigned_type);
$this->assertNull($asset->accepted);
$this->assertEquals('Changed Name', $asset->name);
$this->assertEquals($status->id, $asset->status_id);
}
public function testLastCheckInFieldIsSetOnCheckin()

View file

@ -40,7 +40,6 @@ class AssetCheckinTest extends TestCase
{
Event::fake([CheckoutableCheckedIn::class]);
$admin = User::factory()->checkinAssets()->create();
$user = User::factory()->create();
$status = Statuslabel::first() ?? Statuslabel::factory()->create();
$asset = Asset::factory()->assignedToUser($user)->create([
@ -51,7 +50,7 @@ class AssetCheckinTest extends TestCase
$this->assertTrue($asset->assignedTo->is($user));
$this->actingAs($admin)
$this->actingAs(User::factory()->checkinAssets()->create())
->post(
route('hardware.checkin.store', ['assetId' => $asset->id, 'backto' => 'user']),
[