createCategory(); $response = $this->getJson('/api/categories'); $response->assertStatus(200) ->assertJsonFragment(['id' => $category->id]); } public function test_show_returns_category(): void { $category = $this->createCategory(); $response = $this->getJson("/api/categories/{$category->id}"); $response->assertStatus(200) ->assertJsonFragment(['id' => $category->id]); } public function test_admin_can_create_update_and_delete_category(): void { $this->actingAsAdmin(); $createResponse = $this->postJson('/api/categories', [ 'name' => 'CAT-A', 'order' => 1, ]); $createResponse->assertStatus(201); $categoryId = $createResponse->json('id'); $updateResponse = $this->putJson("/api/categories/{$categoryId}", [ 'name' => 'CAT-B', 'order' => 2, ]); $updateResponse->assertStatus(200) ->assertJsonFragment(['id' => $categoryId]); $this->deleteJson("/api/categories/{$categoryId}") ->assertStatus(204); } public function test_non_admin_cannot_create_category(): void { $this->actingAsUser(); $this->postJson('/api/categories', [ 'name' => 'CAT-A', 'order' => 1, ])->assertStatus(403); } }