Initial commit

This commit is contained in:
Zdeněk Burda
2026-01-09 21:26:40 +01:00
parent e83aec6dca
commit 41e3ce6f25
404 changed files with 61250 additions and 28 deletions

View File

@@ -0,0 +1,65 @@
<?php
namespace Tests\Feature\Catalog;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
class CategoryControllerTest extends TestCase
{
use RefreshDatabase;
public function test_index_returns_categories(): void
{
$category = $this->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);
}
}