Initial commit

This commit is contained in:
Zdeněk Burda
2026-01-09 21:26:40 +01:00
parent e83aec6dca
commit 41e3ce6f25
404 changed files with 61250 additions and 28 deletions

View File

@@ -0,0 +1,104 @@
<?php
namespace Tests\Feature\Rounds;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
class RoundControllerTest extends TestCase
{
use RefreshDatabase;
public function test_index_returns_rounds(): void
{
$round = $this->createRound();
$response = $this->getJson('/api/rounds');
$response->assertStatus(200)
->assertJsonFragment(['id' => $round->id]);
}
public function test_index_can_filter_by_contest(): void
{
$contestA = $this->createContest();
$contestB = $this->createContest();
$roundA = $this->createRound(['contest_id' => $contestA->id]);
$this->createRound(['contest_id' => $contestB->id]);
$response = $this->getJson("/api/rounds?contest_id={$contestA->id}");
$response->assertStatus(200)
->assertJsonFragment(['id' => $roundA->id]);
$ids = collect($response->json('data'))->pluck('id')->all();
$this->assertCount(1, $ids);
}
public function test_show_returns_round(): void
{
$round = $this->createRound();
$response = $this->getJson("/api/rounds/{$round->id}");
$response->assertStatus(200)
->assertJsonFragment(['id' => $round->id]);
}
public function test_admin_can_create_update_and_delete_round(): void
{
$this->actingAsAdmin();
$contest = $this->createContest();
$ruleSet = $this->createRuleSet();
$start = now()->addDay();
$end = (clone $start)->addHours(2);
$deadline = (clone $end)->addDays(2);
$createResponse = $this->postJson('/api/rounds', [
'contest_id' => $contest->id,
'rule_set_id' => $ruleSet->id,
'name' => ['cs' => 'Kolo 1', 'en' => 'Round 1'],
'description' => ['cs' => 'Popis', 'en' => 'Description'],
'start_time' => $start->toDateTimeString(),
'end_time' => $end->toDateTimeString(),
'logs_deadline' => $deadline->toDateTimeString(),
'is_active' => true,
]);
$createResponse->assertStatus(201);
$roundId = $createResponse->json('id');
$updateResponse = $this->putJson("/api/rounds/{$roundId}", [
'contest_id' => $contest->id,
'name' => ['cs' => 'Kolo 1B', 'en' => 'Round 1B'],
'description' => ['cs' => 'Popis', 'en' => 'Description'],
'start_time' => $start->toDateTimeString(),
'end_time' => $end->toDateTimeString(),
'logs_deadline' => $deadline->toDateTimeString(),
'is_active' => false,
]);
$updateResponse->assertStatus(200)
->assertJsonFragment(['id' => $roundId]);
$this->deleteJson("/api/rounds/{$roundId}")
->assertStatus(204);
}
public function test_non_admin_cannot_create_round(): void
{
$this->actingAsUser();
$contest = $this->createContest();
$start = now()->addDay();
$end = (clone $start)->addHours(2);
$deadline = (clone $end)->addDays(2);
$this->postJson('/api/rounds', [
'contest_id' => $contest->id,
'name' => ['cs' => 'Kolo 1', 'en' => 'Round 1'],
'start_time' => $start->toDateTimeString(),
'end_time' => $end->toDateTimeString(),
'logs_deadline' => $deadline->toDateTimeString(),
])->assertStatus(403);
}
}