91 lines
2.7 KiB
PHP
91 lines
2.7 KiB
PHP
<?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);
|
|
}
|
|
}
|