228 lines
7.4 KiB
PHP
228 lines
7.4 KiB
PHP
<?php
|
|
|
|
namespace Tests\Feature\Results;
|
|
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Tests\TestCase;
|
|
|
|
class LogResultControllerTest extends TestCase
|
|
{
|
|
use RefreshDatabase;
|
|
|
|
public function test_index_filters_by_evaluation_run(): void
|
|
{
|
|
$runA = $this->createEvaluationRun();
|
|
$runB = $this->createEvaluationRun();
|
|
$logA = $this->createLog(['round_id' => $runA->round_id]);
|
|
$logB = $this->createLog(['round_id' => $runB->round_id]);
|
|
$resultA = $this->createLogResult([
|
|
'evaluation_run_id' => $runA->id,
|
|
'log_id' => $logA->id,
|
|
]);
|
|
$this->createLogResult([
|
|
'evaluation_run_id' => $runB->id,
|
|
'log_id' => $logB->id,
|
|
]);
|
|
|
|
$response = $this->getJson("/api/log-results?evaluation_run_id={$runA->id}");
|
|
|
|
$response->assertStatus(200)
|
|
->assertJsonFragment(['id' => $resultA->id]);
|
|
|
|
$ids = collect($response->json('data'))->pluck('id')->all();
|
|
$this->assertCount(1, $ids);
|
|
}
|
|
|
|
public function test_index_resolves_claimed_run_for_round(): void
|
|
{
|
|
$round = $this->createRound();
|
|
$run = $this->createEvaluationRun([
|
|
'round_id' => $round->id,
|
|
'rules_version' => 'CLAIMED',
|
|
]);
|
|
$log = $this->createLog(['round_id' => $round->id]);
|
|
$result = $this->createLogResult([
|
|
'evaluation_run_id' => $run->id,
|
|
'log_id' => $log->id,
|
|
]);
|
|
|
|
$response = $this->getJson("/api/log-results?round_id={$round->id}&status=CLAIMED");
|
|
|
|
$response->assertStatus(200)
|
|
->assertJsonFragment(['id' => $result->id]);
|
|
}
|
|
|
|
public function test_index_resolves_auto_result_type_from_round(): void
|
|
{
|
|
$round = $this->createRound();
|
|
$run = $this->createEvaluationRun(['round_id' => $round->id]);
|
|
$round->update(['official_evaluation_run_id' => $run->id]);
|
|
$log = $this->createLog(['round_id' => $round->id]);
|
|
$result = $this->createLogResult([
|
|
'evaluation_run_id' => $run->id,
|
|
'log_id' => $log->id,
|
|
]);
|
|
|
|
$response = $this->getJson("/api/log-results?round_id={$round->id}&result_type=AUTO");
|
|
|
|
$response->assertStatus(200)
|
|
->assertJsonFragment(['id' => $result->id]);
|
|
}
|
|
|
|
public function test_index_only_ok_filters_by_callsign(): void
|
|
{
|
|
$round = $this->createRound();
|
|
$run = $this->createEvaluationRun(['round_id' => $round->id]);
|
|
|
|
$logOk = $this->createLog([
|
|
'round_id' => $round->id,
|
|
'pcall' => 'OK1ABC',
|
|
]);
|
|
$logOther = $this->createLog([
|
|
'round_id' => $round->id,
|
|
'pcall' => 'DL1ABC',
|
|
]);
|
|
$resultOk = $this->createLogResult([
|
|
'evaluation_run_id' => $run->id,
|
|
'log_id' => $logOk->id,
|
|
]);
|
|
$this->createLogResult([
|
|
'evaluation_run_id' => $run->id,
|
|
'log_id' => $logOther->id,
|
|
]);
|
|
|
|
$response = $this->getJson("/api/log-results?evaluation_run_id={$run->id}&round_id={$round->id}&only_ok=1");
|
|
|
|
$response->assertStatus(200)
|
|
->assertJsonFragment(['id' => $resultOk->id]);
|
|
|
|
$ids = collect($response->json('data'))->pluck('id')->all();
|
|
$this->assertCount(1, $ids);
|
|
}
|
|
|
|
public function test_admin_can_create_update_and_delete_log_result(): void
|
|
{
|
|
$this->actingAsAdmin();
|
|
$run = $this->createEvaluationRun();
|
|
$log = $this->createLog(['round_id' => $run->round_id]);
|
|
|
|
$createResponse = $this->postJson('/api/log-results', [
|
|
'evaluation_run_id' => $run->id,
|
|
'log_id' => $log->id,
|
|
'claimed_qso_count' => 10,
|
|
'claimed_score' => 100,
|
|
]);
|
|
|
|
$createResponse->assertStatus(201);
|
|
$resultId = $createResponse->json('id');
|
|
|
|
$updateResponse = $this->putJson("/api/log-results/{$resultId}", [
|
|
'claimed_score' => 200,
|
|
]);
|
|
|
|
$updateResponse->assertStatus(200)
|
|
->assertJsonFragment(['id' => $resultId]);
|
|
|
|
$this->deleteJson("/api/log-results/{$resultId}")
|
|
->assertStatus(204);
|
|
}
|
|
|
|
public function test_non_admin_cannot_create_log_result(): void
|
|
{
|
|
$this->actingAsUser();
|
|
$run = $this->createEvaluationRun();
|
|
$log = $this->createLog(['round_id' => $run->round_id]);
|
|
|
|
$this->postJson('/api/log-results', [
|
|
'evaluation_run_id' => $run->id,
|
|
'log_id' => $log->id,
|
|
])->assertStatus(403);
|
|
}
|
|
|
|
public function test_claimed_results_redact_locator_and_odx_for_anonymous(): void
|
|
{
|
|
$round = $this->createRound();
|
|
$claimedRun = $this->createEvaluationRun([
|
|
'round_id' => $round->id,
|
|
'rules_version' => 'CLAIMED',
|
|
]);
|
|
$log = $this->createLog([
|
|
'round_id' => $round->id,
|
|
'pwwlo' => 'JN79',
|
|
'codxc' => 'OK2XYZ',
|
|
]);
|
|
$result = $this->createLogResult([
|
|
'evaluation_run_id' => $claimedRun->id,
|
|
'log_id' => $log->id,
|
|
]);
|
|
|
|
$response = $this->getJson("/api/log-results?round_id={$round->id}&status=CLAIMED");
|
|
|
|
$response->assertStatus(200);
|
|
$row = collect($response->json('data'))->firstWhere('id', $result->id);
|
|
$this->assertNotNull($row);
|
|
$this->assertNull($row['log']['pwwlo']);
|
|
$this->assertNull($row['log']['codxc']);
|
|
}
|
|
|
|
public function test_admin_sees_locator_and_odx_for_claimed_results(): void
|
|
{
|
|
$this->actingAsAdmin();
|
|
$round = $this->createRound();
|
|
$claimedRun = $this->createEvaluationRun([
|
|
'round_id' => $round->id,
|
|
'rules_version' => 'CLAIMED',
|
|
]);
|
|
$log = $this->createLog([
|
|
'round_id' => $round->id,
|
|
'pwwlo' => 'JN79',
|
|
'codxc' => 'OK2XYZ',
|
|
]);
|
|
$result = $this->createLogResult([
|
|
'evaluation_run_id' => $claimedRun->id,
|
|
'log_id' => $log->id,
|
|
]);
|
|
|
|
$response = $this->getJson("/api/log-results?round_id={$round->id}&status=CLAIMED");
|
|
|
|
$response->assertStatus(200);
|
|
$row = collect($response->json('data'))->firstWhere('id', $result->id);
|
|
$this->assertNotNull($row);
|
|
$this->assertSame('JN79', $row['log']['pwwlo']);
|
|
$this->assertSame('OK2XYZ', $row['log']['codxc']);
|
|
}
|
|
|
|
public function test_claimed_result_show_reveals_locator_after_final_published(): void
|
|
{
|
|
$round = $this->createRound();
|
|
$claimedRun = $this->createEvaluationRun([
|
|
'round_id' => $round->id,
|
|
'rules_version' => 'CLAIMED',
|
|
]);
|
|
$officialRun = $this->createEvaluationRun([
|
|
'round_id' => $round->id,
|
|
'rules_version' => 'OFFICIAL',
|
|
'status' => 'SUCCEEDED',
|
|
'result_type' => 'FINAL',
|
|
]);
|
|
$round->official_evaluation_run_id = $officialRun->id;
|
|
$round->save();
|
|
|
|
$log = $this->createLog([
|
|
'round_id' => $round->id,
|
|
'pwwlo' => 'JN79',
|
|
'codxc' => 'OK2XYZ',
|
|
]);
|
|
$result = $this->createLogResult([
|
|
'evaluation_run_id' => $claimedRun->id,
|
|
'log_id' => $log->id,
|
|
]);
|
|
|
|
$response = $this->getJson("/api/log-results/{$result->id}");
|
|
|
|
$response->assertStatus(200);
|
|
$this->assertSame('JN79', $response->json('log.pwwlo'));
|
|
$this->assertSame('OK2XYZ', $response->json('log.codxc'));
|
|
}
|
|
}
|