Skip to content

A free open source IT asset/license management system

Add simple tests around asset check in

Marcus Moore6fc06f2ee171
diff --git a/tests/Feature/Api/Assets/AssetCheckinTest.php b/tests/Feature/Api/Assets/AssetCheckinTest.php
new file mode 100644
index 0000000000..f71191d80c
--- /dev/null
+++ b/tests/Feature/Api/Assets/AssetCheckinTest.php
@@ -0,0 +1,30 @@
+<?php
+
+namespace Tests\Feature\Api\Assets;
+
+use App\Models\Asset;
+use App\Models\User;
+use Tests\Support\InteractsWithSettings;
+use Tests\TestCase;
+
+class AssetCheckinTest extends TestCase
+{
+ use InteractsWithSettings;
+
+ public function testLastCheckInFieldIsSetOnCheckin()
+ {
+ $admin = User::factory()->superuser()->create();
+ $asset = Asset::factory()->create(['last_checkin' => null]);
+
+ $asset->checkOut(User::factory()->create(), $admin, now());
+
+ $this->actingAsForApi($admin)
+ ->postJson(route('api.asset.checkin', $asset))
+ ->assertOk();
+
+ $this->assertNotNull(
+ $asset->fresh()->last_checkin,
+ 'last_checkin field should be set on checkin'
+ );
+ }
+}
diff --git a/tests/Feature/Assets/AssetCheckinTest.php b/tests/Feature/Assets/AssetCheckinTest.php
new file mode 100644
index 0000000000..059fb1294f
--- /dev/null
+++ b/tests/Feature/Assets/AssetCheckinTest.php
@@ -0,0 +1,32 @@
+<?php
+
+namespace Tests\Feature\Assets;
+
+use App\Models\Asset;
+use App\Models\User;
+use Tests\Support\InteractsWithSettings;
+use Tests\TestCase;
+
+class AssetCheckinTest extends TestCase
+{
+ use InteractsWithSettings;
+
+ public function testLastCheckInFieldIsSetOnCheckin()
+ {
+ $admin = User::factory()->superuser()->create();
+ $asset = Asset::factory()->create(['last_checkin' => null]);
+
+ $asset->checkOut(User::factory()->create(), $admin, now());
+
+ $this->actingAs($admin)
+ ->post(route('hardware.checkin.store', [
+ 'assetId' => $asset->id,
+ ]))
+ ->assertRedirect();
+
+ $this->assertNotNull(
+ $asset->fresh()->last_checkin,
+ 'last_checkin field should be set on checkin'
+ );
+ }
+}