Files
vkv/tests/Feature/Logs/LogControllerTest.php
Zdeněk Burda 1e484aef47 Skrytí osobních údajů #1
Nezobrazovat detail logu anonymnímu uživateli #2
2026-01-10 12:50:45 +01:00

133 lines
3.6 KiB
PHP

<?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_requires_admin(): void
{
$log = $this->createLog();
$this->getJson("/api/logs/{$log->id}")
->assertStatus(403);
}
public function test_admin_can_view_log(): void
{
$this->actingAsAdmin();
$log = $this->createLog();
$response = $this->getJson("/api/logs/{$log->id}");
$response->assertStatus(200)
->assertJsonFragment(['id' => $log->id]);
}
public function test_public_show_requires_final_results(): void
{
$log = $this->createLog();
$this->getJson("/api/logs/{$log->id}/public")
->assertStatus(403);
}
public function test_public_show_returns_whitelisted_fields(): void
{
$round = $this->createRound();
$log = $this->createLog([
'round_id' => $round->id,
'pcall' => 'OK1PUBLIC',
'rcall' => 'OK1SECRET',
'padr1' => 'Secret Street',
'pband' => '144',
'claimed_qso_count' => 50,
]);
$run = $this->createEvaluationRun([
'round_id' => $round->id,
'status' => 'SUCCEEDED',
'result_type' => 'FINAL',
'rules_version' => 'OFFICIAL',
]);
$round->official_evaluation_run_id = $run->id;
$round->save();
$response = $this->getJson("/api/logs/{$log->id}/public");
$response->assertStatus(200)
->assertJsonFragment([
'id' => $log->id,
'pcall' => 'OK1PUBLIC',
'pband' => '144',
'claimed_qso_count' => 50,
])
->assertJsonMissing(['rcall' => 'OK1SECRET'])
->assertJsonMissing(['padr1' => 'Secret Street']);
}
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);
}
}