Initial commit
This commit is contained in:
82
tests/Feature/Logs/LogControllerTest.php
Normal file
82
tests/Feature/Logs/LogControllerTest.php
Normal file
@@ -0,0 +1,82 @@
|
||||
<?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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user