Skip to content

Commit fe65ffc

Browse files
authored
Merge pull request #16527 from Godmartinz/license_seat_notes_fix
add notes as fillable to license seat model
2 parents d44553c + 881cde4 commit fe65ffc

File tree

4 files changed

+89
-2
lines changed

4 files changed

+89
-2
lines changed

app/Http/Controllers/Api/LicenseSeatsController.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,13 +136,13 @@ public function update(Request $request, $licenseId, $seatId) : JsonResponse | a
136136
if ($licenseSeat->save()) {
137137

138138
if ($is_checkin) {
139-
$licenseSeat->logCheckin($target, $request->input('note'));
139+
$licenseSeat->logCheckin($target, $request->input('notes'));
140140

141141
return response()->json(Helper::formatStandardApiResponse('success', $licenseSeat, trans('admin/licenses/message.update.success')));
142142
}
143143

144144
// in this case, relevant fields are touched but it's not a checkin operation. so it must be a checkout operation.
145-
$licenseSeat->logCheckout($request->input('note'), $target);
145+
$licenseSeat->logCheckout($request->input('notes'), $target);
146146

147147
return response()->json(Helper::formatStandardApiResponse('success', $licenseSeat, trans('admin/licenses/message.update.success')));
148148
}

app/Models/LicenseSeat.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ class LicenseSeat extends SnipeModel implements ICompanyableChild
3030
protected $fillable = [
3131
'assigned_to',
3232
'asset_id',
33+
'notes',
3334
];
3435

3536
use Acceptable;
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php
2+
namespace Tests\Feature\Checkins\Api;
3+
4+
use App\Models\License;
5+
use App\Models\LicenseSeat;
6+
use App\Models\User;
7+
use Tests\TestCase;
8+
9+
class LicenseCheckInTest extends TestCase {
10+
public function testLicenseCheckin()
11+
{
12+
$authUser = User::factory()->superuser()->create();
13+
$this->actingAsForApi($authUser);
14+
15+
$license = License::factory()->create();
16+
$oldUser = User::factory()->create();
17+
18+
$licenseSeat = LicenseSeat::factory()->for($license)->create([
19+
'assigned_to' => $oldUser->id,
20+
'notes' => 'Previously checked out',
21+
]);
22+
23+
$payload = [
24+
'assigned_to' => null,
25+
'asset_id' => null,
26+
'notes' => 'Checking in the seat',
27+
];
28+
29+
$response = $this->patchJson(
30+
route('api.licenses.seats.update', [$license->id, $licenseSeat->id]),
31+
$payload);
32+
33+
$response->assertStatus(200)
34+
->assertJsonFragment([
35+
'status' => 'success',
36+
]);
37+
38+
$licenseSeat->refresh();
39+
40+
$this->assertNull($licenseSeat->assigned_to);
41+
$this->assertNull($licenseSeat->asset_id);
42+
43+
$this->assertEquals('Checking in the seat', $licenseSeat->notes);
44+
}
45+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
namespace Tests\Feature\Checkouts\Api;
3+
4+
use App\Models\License;
5+
use App\Models\LicenseSeat;
6+
use App\Models\User;
7+
use Tests\TestCase;
8+
9+
class LicenseCheckOutTest extends TestCase {
10+
public function testLicenseCheckout()
11+
{
12+
$authUser = User::factory()->superuser()->create();
13+
$this->actingAsForApi($authUser);
14+
15+
$license = License::factory()->create();
16+
$licenseSeat = LicenseSeat::factory()->for($license)->create([
17+
'assigned_to' => null,
18+
]);
19+
20+
$targetUser = User::factory()->create();
21+
22+
$payload = [
23+
'assigned_to' => $targetUser->id,
24+
'notes' => 'Checking out the seat to a user',
25+
];
26+
27+
$response = $this->patchJson(
28+
route('api.licenses.seats.update', [$license->id, $licenseSeat->id]),
29+
$payload);
30+
31+
$response->assertStatus(200)
32+
->assertJsonFragment([
33+
'status' => 'success',
34+
]);
35+
36+
$licenseSeat->refresh();
37+
38+
$this->assertEquals($targetUser->id, $licenseSeat->assigned_to);
39+
$this->assertEquals('Checking out the seat to a user', $licenseSeat->notes);
40+
}
41+
}

0 commit comments

Comments
 (0)