Initial commit
This commit is contained in:
72
tests/Feature/Evaluation/EvaluationRunControllerTest.php
Normal file
72
tests/Feature/Evaluation/EvaluationRunControllerTest.php
Normal file
@@ -0,0 +1,72 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Evaluation;
|
||||
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Tests\TestCase;
|
||||
|
||||
class EvaluationRunControllerTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_cancel_requires_authentication(): void
|
||||
{
|
||||
$run = $this->createEvaluationRun();
|
||||
|
||||
$this->postJson("/api/evaluation-runs/{$run->id}/cancel")
|
||||
->assertStatus(401);
|
||||
}
|
||||
|
||||
public function test_non_admin_cannot_cancel(): void
|
||||
{
|
||||
$this->actingAsUser();
|
||||
$run = $this->createEvaluationRun(['status' => 'RUNNING']);
|
||||
|
||||
$this->postJson("/api/evaluation-runs/{$run->id}/cancel")
|
||||
->assertStatus(403);
|
||||
}
|
||||
|
||||
public function test_admin_can_cancel_running_run(): void
|
||||
{
|
||||
$this->actingAsAdmin();
|
||||
$run = $this->createEvaluationRun(['status' => 'RUNNING']);
|
||||
|
||||
$response = $this->postJson("/api/evaluation-runs/{$run->id}/cancel");
|
||||
|
||||
$response->assertStatus(200)
|
||||
->assertJsonFragment(['status' => 'canceled']);
|
||||
|
||||
$this->assertDatabaseHas('evaluation_runs', [
|
||||
'id' => $run->id,
|
||||
'status' => 'CANCELED',
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_cancel_rejects_finished_runs(): void
|
||||
{
|
||||
$this->actingAsAdmin();
|
||||
$run = $this->createEvaluationRun(['status' => 'SUCCEEDED']);
|
||||
|
||||
$this->postJson("/api/evaluation-runs/{$run->id}/cancel")
|
||||
->assertStatus(409);
|
||||
}
|
||||
|
||||
public function test_admin_can_set_result_type_and_update_round(): void
|
||||
{
|
||||
$this->actingAsAdmin();
|
||||
$run = $this->createEvaluationRun(['result_type' => null]);
|
||||
$round = $run->round;
|
||||
|
||||
$response = $this->postJson("/api/evaluation-runs/{$run->id}/result-type", [
|
||||
'result_type' => 'PRELIMINARY',
|
||||
]);
|
||||
|
||||
$response->assertStatus(200)
|
||||
->assertJsonFragment(['result_type' => 'PRELIMINARY']);
|
||||
|
||||
$round->refresh();
|
||||
$this->assertSame($run->id, $round->preliminary_evaluation_run_id);
|
||||
$this->assertNull($round->official_evaluation_run_id);
|
||||
$this->assertNull($round->test_evaluation_run_id);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user