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);
}
}

View File

@@ -0,0 +1,84 @@
<?php
namespace Tests\Feature\Logs;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
class LogQsoControllerTest extends TestCase
{
use RefreshDatabase;
public function test_index_returns_log_qsos(): void
{
$qso = $this->createLogQso();
$response = $this->getJson('/api/log-qsos');
$response->assertStatus(200)
->assertJsonFragment(['id' => $qso->id]);
}
public function test_index_can_filter_by_log_id(): void
{
$logA = $this->createLog();
$logB = $this->createLog();
$qsoA = $this->createLogQso(['log_id' => $logA->id]);
$this->createLogQso(['log_id' => $logB->id]);
$response = $this->getJson("/api/log-qsos?log_id={$logA->id}");
$response->assertStatus(200)
->assertJsonFragment(['id' => $qsoA->id]);
$ids = collect($response->json('data'))->pluck('id')->all();
$this->assertCount(1, $ids);
}
public function test_show_returns_log_qso(): void
{
$qso = $this->createLogQso();
$response = $this->getJson("/api/log-qsos/{$qso->id}");
$response->assertStatus(200)
->assertJsonFragment(['id' => $qso->id]);
}
public function test_admin_can_create_update_and_delete_log_qso(): void
{
$this->actingAsAdmin();
$log = $this->createLog();
$createResponse = $this->postJson('/api/log-qsos', [
'log_id' => $log->id,
'my_call' => 'OK1ABC',
'dx_call' => 'OK2ABC',
]);
$createResponse->assertStatus(201);
$qsoId = $createResponse->json('id');
$updateResponse = $this->putJson("/api/log-qsos/{$qsoId}", [
'dx_call' => 'OK9XYZ',
]);
$updateResponse->assertStatus(200)
->assertJsonFragment(['id' => $qsoId]);
$this->deleteJson("/api/log-qsos/{$qsoId}")
->assertStatus(204);
}
public function test_non_admin_cannot_create_log_qso(): void
{
$this->actingAsUser();
$log = $this->createLog();
$this->postJson('/api/log-qsos', [
'log_id' => $log->id,
'my_call' => 'OK1ABC',
'dx_call' => 'OK2ABC',
])->assertStatus(403);
}
}

View File

@@ -0,0 +1,119 @@
<?php
namespace Tests\Feature\Logs;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
class LogQsoTableTest extends TestCase
{
use RefreshDatabase;
public function test_qso_table_uses_latest_succeeded_non_claimed_run_by_default(): void
{
$round = $this->createRound();
$log = $this->createLog(['round_id' => $round->id]);
$qsoA = $this->createLogQso([
'log_id' => $log->id,
'qso_index' => 1,
'dx_call' => 'OK1AAA',
]);
$qsoB = $this->createLogQso([
'log_id' => $log->id,
'qso_index' => 2,
'dx_call' => 'OK1BBB',
]);
$claimedRun = $this->createEvaluationRun([
'round_id' => $round->id,
'rules_version' => 'CLAIMED',
'status' => 'SUCCEEDED',
]);
$this->createQsoResult([
'evaluation_run_id' => $claimedRun->id,
'log_qso_id' => $qsoA->id,
'error_code' => 'DUP',
]);
$officialRun = $this->createEvaluationRun([
'round_id' => $round->id,
'rules_version' => 'OFFICIAL',
'status' => 'SUCCEEDED',
]);
$this->createQsoResult([
'evaluation_run_id' => $officialRun->id,
'log_qso_id' => $qsoA->id,
'error_code' => 'OK',
'penalty_points' => 5,
]);
$this->createQsoOverride([
'evaluation_run_id' => $officialRun->id,
'log_qso_id' => $qsoB->id,
'forced_status' => 'AUTO',
'reason' => 'Manual override',
]);
$response = $this->getJson("/api/logs/{$log->id}/qso-table");
$response->assertStatus(200)
->assertJsonFragment(['evaluation_run_id' => $officialRun->id]);
$rows = collect($response->json('data'));
$this->assertCount(2, $rows);
$rowA = $rows->firstWhere('id', $qsoA->id);
$rowB = $rows->firstWhere('id', $qsoB->id);
$this->assertSame('OK1AAA', $rowA['dx_call']);
$this->assertSame('OK', $rowA['result']['error_code']);
$this->assertSame(5, $rowA['result']['penalty_points']);
$this->assertNull($rowA['override']);
$this->assertSame('OK1BBB', $rowB['dx_call']);
$this->assertNull($rowB['result']);
$this->assertSame('Manual override', $rowB['override']['reason']);
}
public function test_qso_table_respects_explicit_evaluation_run_id(): void
{
$round = $this->createRound();
$log = $this->createLog(['round_id' => $round->id]);
$qso = $this->createLogQso([
'log_id' => $log->id,
'qso_index' => 1,
]);
$claimedRun = $this->createEvaluationRun([
'round_id' => $round->id,
'rules_version' => 'CLAIMED',
'status' => 'SUCCEEDED',
]);
$this->createQsoResult([
'evaluation_run_id' => $claimedRun->id,
'log_qso_id' => $qso->id,
'error_code' => 'DUP',
]);
$officialRun = $this->createEvaluationRun([
'round_id' => $round->id,
'rules_version' => 'OFFICIAL',
'status' => 'SUCCEEDED',
]);
$this->createQsoResult([
'evaluation_run_id' => $officialRun->id,
'log_qso_id' => $qso->id,
'error_code' => 'OK',
]);
$response = $this->getJson("/api/logs/{$log->id}/qso-table?evaluation_run_id={$claimedRun->id}");
$response->assertStatus(200)
->assertJsonFragment(['evaluation_run_id' => $claimedRun->id]);
$rows = collect($response->json('data'));
$row = $rows->firstWhere('id', $qso->id);
$this->assertSame('DUP', $row['result']['error_code']);
}
}