From cf0ce1c5ea2f1f61c723efb518f81a2790a15e20 Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Tue, 18 Feb 2025 16:24:52 -0800 Subject: [PATCH] Start to implement tests --- app/Http/Controllers/NotesController.php | 2 +- tests/Feature/Notes/CreateNotesTest.php | 22 +++++++++++++++++++++- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/app/Http/Controllers/NotesController.php b/app/Http/Controllers/NotesController.php index dd32b17ebc..e24436e5ad 100644 --- a/app/Http/Controllers/NotesController.php +++ b/app/Http/Controllers/NotesController.php @@ -25,7 +25,7 @@ class NotesController extends Controller $item = Asset::findOrFail($validated['id']); - // @todo: authorization + $this->authorize('update', $item); $logaction = new Actionlog(); $logaction->item_id = $item->id; diff --git a/tests/Feature/Notes/CreateNotesTest.php b/tests/Feature/Notes/CreateNotesTest.php index a993e7508f..a42d501bb9 100644 --- a/tests/Feature/Notes/CreateNotesTest.php +++ b/tests/Feature/Notes/CreateNotesTest.php @@ -2,6 +2,8 @@ namespace Tests\Feature\Notes; +use App\Models\Asset; +use App\Models\User; use Tests\TestCase; class CreateNotesTest extends TestCase @@ -9,6 +11,10 @@ class CreateNotesTest extends TestCase public function testRequiresPermission() { $this->markTestIncomplete(); + + $this->actingAs(User::factory()->create()) + ->post(route('notes.store')) + ->assertForbidden(); } public function testValidation() @@ -18,6 +24,20 @@ class CreateNotesTest extends TestCase public function testCanCreateNote() { - $this->markTestIncomplete(); + // @todo: make dynamic? + + $actor = User::factory()->editAssets()->create(); + + $asset = Asset::factory()->create(); + + $this->actingAs($actor) + ->post(route('notes.store'), [ + 'id' => $asset->id, + 'type' => 'asset', + 'note' => 'my special note', + ]) + ->assertRedirect(route('hardware.show', $asset->id) . '#history'); + + // @todo: assert action log created with expected data } }