83 lines
2.1 KiB
PHP
83 lines
2.1 KiB
PHP
<?php
|
|
|
|
namespace Tests\Feature\Logs;
|
|
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Tests\TestCase;
|
|
|
|
class LogControllerTest extends TestCase
|
|
{
|
|
use RefreshDatabase;
|
|
|
|
public function test_index_returns_logs(): void
|
|
{
|
|
$log = $this->createLog();
|
|
|
|
$response = $this->getJson('/api/logs');
|
|
|
|
$response->assertStatus(200)
|
|
->assertJsonFragment(['id' => $log->id]);
|
|
}
|
|
|
|
public function test_index_can_filter_by_round(): void
|
|
{
|
|
$roundA = $this->createRound();
|
|
$roundB = $this->createRound();
|
|
$logA = $this->createLog(['round_id' => $roundA->id]);
|
|
$this->createLog(['round_id' => $roundB->id]);
|
|
|
|
$response = $this->getJson("/api/logs?round_id={$roundA->id}");
|
|
|
|
$response->assertStatus(200)
|
|
->assertJsonFragment(['id' => $logA->id]);
|
|
|
|
$ids = collect($response->json('data'))->pluck('id')->all();
|
|
$this->assertCount(1, $ids);
|
|
}
|
|
|
|
public function test_show_returns_log(): void
|
|
{
|
|
$log = $this->createLog();
|
|
|
|
$response = $this->getJson("/api/logs/{$log->id}");
|
|
|
|
$response->assertStatus(200)
|
|
->assertJsonFragment(['id' => $log->id]);
|
|
}
|
|
|
|
public function test_admin_can_create_update_and_delete_log(): void
|
|
{
|
|
$this->actingAsAdmin();
|
|
$round = $this->createRound();
|
|
|
|
$createResponse = $this->postJson('/api/logs', [
|
|
'round_id' => $round->id,
|
|
'pcall' => 'OK1ABC',
|
|
]);
|
|
|
|
$createResponse->assertStatus(201);
|
|
$logId = $createResponse->json('id');
|
|
|
|
$updateResponse = $this->putJson("/api/logs/{$logId}", [
|
|
'pcall' => 'OK1DEF',
|
|
]);
|
|
|
|
$updateResponse->assertStatus(200)
|
|
->assertJsonFragment(['id' => $logId]);
|
|
|
|
$this->deleteJson("/api/logs/{$logId}")
|
|
->assertStatus(204);
|
|
}
|
|
|
|
public function test_non_admin_cannot_create_log(): void
|
|
{
|
|
$this->actingAsUser();
|
|
$round = $this->createRound();
|
|
|
|
$this->postJson('/api/logs', [
|
|
'round_id' => $round->id,
|
|
'pcall' => 'OK1ABC',
|
|
])->assertStatus(403);
|
|
}
|
|
}
|