Initial commit
This commit is contained in:
84
tests/Feature/Logs/LogQsoControllerTest.php
Normal file
84
tests/Feature/Logs/LogQsoControllerTest.php
Normal file
@@ -0,0 +1,84 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Logs;
|
||||
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Tests\TestCase;
|
||||
|
||||
class LogQsoControllerTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_index_returns_log_qsos(): void
|
||||
{
|
||||
$qso = $this->createLogQso();
|
||||
|
||||
$response = $this->getJson('/api/log-qsos');
|
||||
|
||||
$response->assertStatus(200)
|
||||
->assertJsonFragment(['id' => $qso->id]);
|
||||
}
|
||||
|
||||
public function test_index_can_filter_by_log_id(): void
|
||||
{
|
||||
$logA = $this->createLog();
|
||||
$logB = $this->createLog();
|
||||
$qsoA = $this->createLogQso(['log_id' => $logA->id]);
|
||||
$this->createLogQso(['log_id' => $logB->id]);
|
||||
|
||||
$response = $this->getJson("/api/log-qsos?log_id={$logA->id}");
|
||||
|
||||
$response->assertStatus(200)
|
||||
->assertJsonFragment(['id' => $qsoA->id]);
|
||||
|
||||
$ids = collect($response->json('data'))->pluck('id')->all();
|
||||
$this->assertCount(1, $ids);
|
||||
}
|
||||
|
||||
public function test_show_returns_log_qso(): void
|
||||
{
|
||||
$qso = $this->createLogQso();
|
||||
|
||||
$response = $this->getJson("/api/log-qsos/{$qso->id}");
|
||||
|
||||
$response->assertStatus(200)
|
||||
->assertJsonFragment(['id' => $qso->id]);
|
||||
}
|
||||
|
||||
public function test_admin_can_create_update_and_delete_log_qso(): void
|
||||
{
|
||||
$this->actingAsAdmin();
|
||||
$log = $this->createLog();
|
||||
|
||||
$createResponse = $this->postJson('/api/log-qsos', [
|
||||
'log_id' => $log->id,
|
||||
'my_call' => 'OK1ABC',
|
||||
'dx_call' => 'OK2ABC',
|
||||
]);
|
||||
|
||||
$createResponse->assertStatus(201);
|
||||
$qsoId = $createResponse->json('id');
|
||||
|
||||
$updateResponse = $this->putJson("/api/log-qsos/{$qsoId}", [
|
||||
'dx_call' => 'OK9XYZ',
|
||||
]);
|
||||
|
||||
$updateResponse->assertStatus(200)
|
||||
->assertJsonFragment(['id' => $qsoId]);
|
||||
|
||||
$this->deleteJson("/api/log-qsos/{$qsoId}")
|
||||
->assertStatus(204);
|
||||
}
|
||||
|
||||
public function test_non_admin_cannot_create_log_qso(): void
|
||||
{
|
||||
$this->actingAsUser();
|
||||
$log = $this->createLog();
|
||||
|
||||
$this->postJson('/api/log-qsos', [
|
||||
'log_id' => $log->id,
|
||||
'my_call' => 'OK1ABC',
|
||||
'dx_call' => 'OK2ABC',
|
||||
])->assertStatus(403);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user