Initial commit
This commit is contained in:
90
tests/Feature/Results/LogOverrideControllerTest.php
Normal file
90
tests/Feature/Results/LogOverrideControllerTest.php
Normal file
@@ -0,0 +1,90 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Results;
|
||||
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Tests\TestCase;
|
||||
|
||||
class LogOverrideControllerTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_index_returns_log_overrides(): void
|
||||
{
|
||||
$override = $this->createLogOverride();
|
||||
|
||||
$response = $this->getJson('/api/log-overrides');
|
||||
|
||||
$response->assertStatus(200)
|
||||
->assertJsonFragment(['id' => $override->id]);
|
||||
}
|
||||
|
||||
public function test_index_can_filter_by_evaluation_run(): void
|
||||
{
|
||||
$runA = $this->createEvaluationRun();
|
||||
$runB = $this->createEvaluationRun();
|
||||
$overrideA = $this->createLogOverride(['evaluation_run_id' => $runA->id]);
|
||||
$this->createLogOverride(['evaluation_run_id' => $runB->id]);
|
||||
|
||||
$response = $this->getJson("/api/log-overrides?evaluation_run_id={$runA->id}");
|
||||
|
||||
$response->assertStatus(200)
|
||||
->assertJsonFragment(['id' => $overrideA->id]);
|
||||
|
||||
$ids = collect($response->json('data'))->pluck('id')->all();
|
||||
$this->assertCount(1, $ids);
|
||||
}
|
||||
|
||||
public function test_show_returns_log_override(): void
|
||||
{
|
||||
$override = $this->createLogOverride();
|
||||
|
||||
$response = $this->getJson("/api/log-overrides/{$override->id}");
|
||||
|
||||
$response->assertStatus(200)
|
||||
->assertJsonFragment(['id' => $override->id]);
|
||||
}
|
||||
|
||||
public function test_admin_can_create_update_and_delete_override(): void
|
||||
{
|
||||
$this->actingAsAdmin();
|
||||
$run = $this->createEvaluationRun();
|
||||
$log = $this->createLog(['round_id' => $run->round_id]);
|
||||
|
||||
$createResponse = $this->postJson('/api/log-overrides', [
|
||||
'evaluation_run_id' => $run->id,
|
||||
'log_id' => $log->id,
|
||||
'forced_log_status' => 'CHECK',
|
||||
'reason' => 'Test důvod',
|
||||
]);
|
||||
|
||||
$createResponse->assertStatus(201);
|
||||
$overrideId = $createResponse->json('id');
|
||||
|
||||
$updateResponse = $this->putJson("/api/log-overrides/{$overrideId}", [
|
||||
'evaluation_run_id' => $run->id,
|
||||
'log_id' => $log->id,
|
||||
'forced_log_status' => 'OK',
|
||||
'reason' => 'Aktualizace',
|
||||
]);
|
||||
|
||||
$updateResponse->assertStatus(200)
|
||||
->assertJsonFragment(['id' => $overrideId]);
|
||||
|
||||
$this->deleteJson("/api/log-overrides/{$overrideId}")
|
||||
->assertStatus(204);
|
||||
}
|
||||
|
||||
public function test_non_admin_cannot_create_override(): void
|
||||
{
|
||||
$this->actingAsUser();
|
||||
$run = $this->createEvaluationRun();
|
||||
$log = $this->createLog(['round_id' => $run->round_id]);
|
||||
|
||||
$this->postJson('/api/log-overrides', [
|
||||
'evaluation_run_id' => $run->id,
|
||||
'log_id' => $log->id,
|
||||
'forced_log_status' => 'CHECK',
|
||||
])->assertStatus(403);
|
||||
}
|
||||
}
|
||||
141
tests/Feature/Results/LogResultControllerTest.php
Normal file
141
tests/Feature/Results/LogResultControllerTest.php
Normal file
@@ -0,0 +1,141 @@
|
||||
<?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);
|
||||
}
|
||||
}
|
||||
90
tests/Feature/Results/QsoOverrideControllerTest.php
Normal file
90
tests/Feature/Results/QsoOverrideControllerTest.php
Normal file
@@ -0,0 +1,90 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Results;
|
||||
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Tests\TestCase;
|
||||
|
||||
class QsoOverrideControllerTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_index_returns_qso_overrides(): void
|
||||
{
|
||||
$override = $this->createQsoOverride();
|
||||
|
||||
$response = $this->getJson('/api/qso-overrides');
|
||||
|
||||
$response->assertStatus(200)
|
||||
->assertJsonFragment(['id' => $override->id]);
|
||||
}
|
||||
|
||||
public function test_index_can_filter_by_evaluation_run(): void
|
||||
{
|
||||
$runA = $this->createEvaluationRun();
|
||||
$runB = $this->createEvaluationRun();
|
||||
$overrideA = $this->createQsoOverride(['evaluation_run_id' => $runA->id]);
|
||||
$this->createQsoOverride(['evaluation_run_id' => $runB->id]);
|
||||
|
||||
$response = $this->getJson("/api/qso-overrides?evaluation_run_id={$runA->id}");
|
||||
|
||||
$response->assertStatus(200)
|
||||
->assertJsonFragment(['id' => $overrideA->id]);
|
||||
|
||||
$ids = collect($response->json('data'))->pluck('id')->all();
|
||||
$this->assertCount(1, $ids);
|
||||
}
|
||||
|
||||
public function test_show_returns_qso_override(): void
|
||||
{
|
||||
$override = $this->createQsoOverride();
|
||||
|
||||
$response = $this->getJson("/api/qso-overrides/{$override->id}");
|
||||
|
||||
$response->assertStatus(200)
|
||||
->assertJsonFragment(['id' => $override->id]);
|
||||
}
|
||||
|
||||
public function test_admin_can_create_update_and_delete_override(): void
|
||||
{
|
||||
$this->actingAsAdmin();
|
||||
$run = $this->createEvaluationRun();
|
||||
$logQso = $this->createLogQso();
|
||||
|
||||
$createResponse = $this->postJson('/api/qso-overrides', [
|
||||
'evaluation_run_id' => $run->id,
|
||||
'log_qso_id' => $logQso->id,
|
||||
'forced_status' => 'VALID',
|
||||
'reason' => 'Test důvod',
|
||||
]);
|
||||
|
||||
$createResponse->assertStatus(201);
|
||||
$overrideId = $createResponse->json('id');
|
||||
|
||||
$updateResponse = $this->putJson("/api/qso-overrides/{$overrideId}", [
|
||||
'evaluation_run_id' => $run->id,
|
||||
'log_qso_id' => $logQso->id,
|
||||
'forced_status' => 'INVALID',
|
||||
'reason' => 'Aktualizace',
|
||||
]);
|
||||
|
||||
$updateResponse->assertStatus(200)
|
||||
->assertJsonFragment(['id' => $overrideId]);
|
||||
|
||||
$this->deleteJson("/api/qso-overrides/{$overrideId}")
|
||||
->assertStatus(204);
|
||||
}
|
||||
|
||||
public function test_non_admin_cannot_create_override(): void
|
||||
{
|
||||
$this->actingAsUser();
|
||||
$run = $this->createEvaluationRun();
|
||||
$logQso = $this->createLogQso();
|
||||
|
||||
$this->postJson('/api/qso-overrides', [
|
||||
'evaluation_run_id' => $run->id,
|
||||
'log_qso_id' => $logQso->id,
|
||||
'forced_status' => 'VALID',
|
||||
])->assertStatus(403);
|
||||
}
|
||||
}
|
||||
85
tests/Feature/Results/QsoResultControllerTest.php
Normal file
85
tests/Feature/Results/QsoResultControllerTest.php
Normal file
@@ -0,0 +1,85 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Results;
|
||||
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Tests\TestCase;
|
||||
|
||||
class QsoResultControllerTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_index_returns_qso_results(): void
|
||||
{
|
||||
$result = $this->createQsoResult();
|
||||
|
||||
$response = $this->getJson('/api/qso-results');
|
||||
|
||||
$response->assertStatus(200)
|
||||
->assertJsonFragment(['id' => $result->id]);
|
||||
}
|
||||
|
||||
public function test_index_can_filter_by_evaluation_run(): void
|
||||
{
|
||||
$runA = $this->createEvaluationRun();
|
||||
$runB = $this->createEvaluationRun();
|
||||
$resultA = $this->createQsoResult(['evaluation_run_id' => $runA->id]);
|
||||
$this->createQsoResult(['evaluation_run_id' => $runB->id]);
|
||||
|
||||
$response = $this->getJson("/api/qso-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_show_returns_qso_result(): void
|
||||
{
|
||||
$result = $this->createQsoResult();
|
||||
|
||||
$response = $this->getJson("/api/qso-results/{$result->id}");
|
||||
|
||||
$response->assertStatus(200)
|
||||
->assertJsonFragment(['id' => $result->id]);
|
||||
}
|
||||
|
||||
public function test_admin_can_create_update_and_delete_qso_result(): void
|
||||
{
|
||||
$this->actingAsAdmin();
|
||||
$run = $this->createEvaluationRun();
|
||||
$logQso = $this->createLogQso();
|
||||
|
||||
$createResponse = $this->postJson('/api/qso-results', [
|
||||
'evaluation_run_id' => $run->id,
|
||||
'log_qso_id' => $logQso->id,
|
||||
'points' => 50,
|
||||
]);
|
||||
|
||||
$createResponse->assertStatus(201);
|
||||
$resultId = $createResponse->json('id');
|
||||
|
||||
$updateResponse = $this->putJson("/api/qso-results/{$resultId}", [
|
||||
'points' => 75,
|
||||
]);
|
||||
|
||||
$updateResponse->assertStatus(200)
|
||||
->assertJsonFragment(['id' => $resultId]);
|
||||
|
||||
$this->deleteJson("/api/qso-results/{$resultId}")
|
||||
->assertStatus(204);
|
||||
}
|
||||
|
||||
public function test_non_admin_cannot_create_qso_result(): void
|
||||
{
|
||||
$this->actingAsUser();
|
||||
$run = $this->createEvaluationRun();
|
||||
$logQso = $this->createLogQso();
|
||||
|
||||
$this->postJson('/api/qso-results', [
|
||||
'evaluation_run_id' => $run->id,
|
||||
'log_qso_id' => $logQso->id,
|
||||
])->assertStatus(403);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user