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,82 @@
<?php
namespace Tests\Feature\Logs;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
class LogControllerTest extends TestCase
{
use RefreshDatabase;
public function test_index_returns_logs(): void
{
$log = $this->createLog();
$response = $this->getJson('/api/logs');
$response->assertStatus(200)
->assertJsonFragment(['id' => $log->id]);
}
public function test_index_can_filter_by_round(): void
{
$roundA = $this->createRound();
$roundB = $this->createRound();
$logA = $this->createLog(['round_id' => $roundA->id]);
$this->createLog(['round_id' => $roundB->id]);
$response = $this->getJson("/api/logs?round_id={$roundA->id}");
$response->assertStatus(200)
->assertJsonFragment(['id' => $logA->id]);
$ids = collect($response->json('data'))->pluck('id')->all();
$this->assertCount(1, $ids);
}
public function test_show_returns_log(): void
{
$log = $this->createLog();
$response = $this->getJson("/api/logs/{$log->id}");
$response->assertStatus(200)
->assertJsonFragment(['id' => $log->id]);
}
public function test_admin_can_create_update_and_delete_log(): void
{
$this->actingAsAdmin();
$round = $this->createRound();
$createResponse = $this->postJson('/api/logs', [
'round_id' => $round->id,
'pcall' => 'OK1ABC',
]);
$createResponse->assertStatus(201);
$logId = $createResponse->json('id');
$updateResponse = $this->putJson("/api/logs/{$logId}", [
'pcall' => 'OK1DEF',
]);
$updateResponse->assertStatus(200)
->assertJsonFragment(['id' => $logId]);
$this->deleteJson("/api/logs/{$logId}")
->assertStatus(204);
}
public function test_non_admin_cannot_create_log(): void
{
$this->actingAsUser();
$round = $this->createRound();
$this->postJson('/api/logs', [
'round_id' => $round->id,
'pcall' => 'OK1ABC',
])->assertStatus(403);
}
}