A free open source IT asset/license management system
Implement test
Marcus Mooreaf513946a2c5
diff --git a/tests/Feature/Api/Assets/AssetCheckinTest.php b/tests/Feature/Api/Assets/AssetCheckinTest.phpindex 77b64a3f8c..b068d49491 100644--- a/tests/Feature/Api/Assets/AssetCheckinTest.php+++ b/tests/Feature/Api/Assets/AssetCheckinTest.php@@ -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 TestCasepublic 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()diff --git a/tests/Feature/Checkins/AssetCheckinTest.php b/tests/Feature/Checkins/AssetCheckinTest.phpindex f951ede70a..ce4cb6f22e 100644--- a/tests/Feature/Checkins/AssetCheckinTest.php+++ b/tests/Feature/Checkins/AssetCheckinTest.php@@ -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']),[