actingAsForApi(User::factory()->create()) ->postJson(route('api.asset.checkin', Asset::factory()->assignedToUser()->create())) ->assertForbidden(); } public function testCannotCheckInNonExistentAsset() { $this->actingAsForApi(User::factory()->checkinAssets()->create()) ->postJson(route('api.asset.checkin', ['id' => 'does-not-exist'])) ->assertStatusMessageIs('error'); } public function testCannotCheckInAssetThatIsNotCheckedOut() { $this->actingAsForApi(User::factory()->checkinAssets()->create()) ->postJson(route('api.asset.checkin', Asset::factory()->create()->id)) ->assertStatusMessageIs('error'); } public function testAssetCanBeCheckedIn() { 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), [ '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 testLocationIsSetToRTDLocationByDefaultUponCheckin() { $rtdLocation = Location::factory()->create(); $asset = Asset::factory()->assignedToUser()->create([ 'location_id' => Location::factory()->create()->id, 'rtd_location_id' => $rtdLocation->id, ]); $this->actingAsForApi(User::factory()->checkinAssets()->create()) ->postJson(route('api.asset.checkin', $asset->id)); $this->assertTrue($asset->refresh()->location()->is($rtdLocation)); } public function testLocationCanBeSetUponCheckin() { $location = Location::factory()->create(); $asset = Asset::factory()->assignedToUser()->create(); $this->actingAsForApi(User::factory()->checkinAssets()->create()) ->postJson(route('api.asset.checkin', $asset->id), [ 'location_id' => $location->id, ]); $this->assertTrue($asset->refresh()->location()->is($location)); } public function testDefaultLocationCanBeUpdatedUponCheckin() { $this->markTestIncomplete(); } public function testAssetsLicenseSeatsAreClearedUponCheckin() { $this->markTestIncomplete(); } public function testLegacyLocationValuesSetToZeroAreUpdated() { $this->markTestIncomplete(); } public function testPendingCheckoutAcceptancesAreClearedUponCheckin() { $this->markTestIncomplete('Not currently in controller'); } public function testCheckinTimeAndActionLogNoteCanBeSet() { $this->markTestIncomplete(); } }