Skip to content

A free open source IT asset/license management system

add checkin test for api

Godfrey Mbf3837c49d1c
diff --git a/tests/Feature/Checkins/Api/LicenseCheckInTest.php b/tests/Feature/Checkins/Api/LicenseCheckInTest.php
new file mode 100644
index 0000000000..a8aabafb5c
--- /dev/null
+++ b/tests/Feature/Checkins/Api/LicenseCheckInTest.php
@@ -0,0 +1,45 @@
+<?php
+namespace Feature\Checkins\Api;
+
+use App\Models\License;
+use App\Models\LicenseSeat;
+use App\Models\User;
+use Tests\TestCase;
+
+class LicenseCheckInTest extends TestCase {
+ public function testLicenseCheckin()
+ {
+ $authUser = User::factory()->superuser()->make();
+ $this->actingAsForApi($authUser);
+
+ $license = License::factory()->create();
+ $oldUser = User::factory()->create();
+
+ $licenseSeat = LicenseSeat::factory()->for($license)->create([
+ 'assigned_to' => $oldUser->id,
+ 'notes' => 'Previously checked out',
+ ]);
+
+ $payload = [
+ 'assigned_to' => null,
+ 'asset_id' => null,
+ 'notes' => 'Checking in the seat',
+ ];
+
+ $response = $this->patchJson(
+ route('api.licenses.seats.update', [$license->id, $licenseSeat->id]),
+ $payload);
+
+ $response->assertStatus(200)
+ ->assertJsonFragment([
+ 'status' => 'success',
+ ]);
+
+ $licenseSeat->refresh();
+
+ $this->assertNull($licenseSeat->assigned_to);
+ $this->assertNull($licenseSeat->asset_id);
+
+ $this->assertEquals('Checking in the seat', $licenseSeat->notes);
+ }
+}
\ No newline at end of file