Initial commit
This commit is contained in:
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