95 lines
2.5 KiB
PHP
95 lines
2.5 KiB
PHP
<?php
|
|
|
|
namespace Tests\Feature\Catalog;
|
|
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Tests\TestCase;
|
|
|
|
class CtyControllerTest extends TestCase
|
|
{
|
|
use RefreshDatabase;
|
|
|
|
public function test_index_returns_cty_records(): void
|
|
{
|
|
$item = $this->createCty();
|
|
|
|
$response = $this->getJson('/api/cty');
|
|
|
|
$response->assertStatus(200)
|
|
->assertJsonFragment(['id' => $item->id]);
|
|
}
|
|
|
|
public function test_show_returns_cty_record(): void
|
|
{
|
|
$item = $this->createCty();
|
|
|
|
$response = $this->getJson("/api/cty/{$item->id}");
|
|
|
|
$response->assertStatus(200)
|
|
->assertJsonFragment(['id' => $item->id]);
|
|
}
|
|
|
|
public function test_admin_can_create_update_and_delete_cty_record(): void
|
|
{
|
|
$this->actingAsAdmin();
|
|
|
|
$createResponse = $this->postJson('/api/cty', [
|
|
'country_name' => 'Test Country',
|
|
'dxcc' => 999,
|
|
'cq_zone' => 10,
|
|
'itu_zone' => 20,
|
|
'continent' => 'EU',
|
|
'latitude' => 10.0,
|
|
'longitude' => 20.0,
|
|
'time_offset' => 1.0,
|
|
'prefix' => 'TST',
|
|
'prefix_norm' => 'TST',
|
|
'precise' => true,
|
|
'source' => 'test',
|
|
]);
|
|
|
|
$createResponse->assertStatus(201);
|
|
$itemId = $createResponse->json('id');
|
|
|
|
$updateResponse = $this->putJson("/api/cty/{$itemId}", [
|
|
'country_name' => 'Test Country 2',
|
|
'dxcc' => 999,
|
|
'cq_zone' => 10,
|
|
'itu_zone' => 20,
|
|
'continent' => 'EU',
|
|
'latitude' => 10.0,
|
|
'longitude' => 20.0,
|
|
'time_offset' => 1.0,
|
|
'prefix' => 'TST2',
|
|
'prefix_norm' => 'TST2',
|
|
'precise' => false,
|
|
'source' => 'test',
|
|
]);
|
|
|
|
$updateResponse->assertStatus(200)
|
|
->assertJsonFragment(['id' => $itemId]);
|
|
|
|
$this->deleteJson("/api/cty/{$itemId}")
|
|
->assertStatus(204);
|
|
}
|
|
|
|
public function test_non_admin_cannot_create_cty_record(): void
|
|
{
|
|
$this->actingAsUser();
|
|
|
|
$this->postJson('/api/cty', [
|
|
'country_name' => 'Test Country',
|
|
'dxcc' => 999,
|
|
'cq_zone' => 10,
|
|
'itu_zone' => 20,
|
|
'continent' => 'EU',
|
|
'latitude' => 10.0,
|
|
'longitude' => 20.0,
|
|
'time_offset' => 1.0,
|
|
'prefix' => 'TST',
|
|
'precise' => true,
|
|
'source' => 'test',
|
|
])->assertStatus(403);
|
|
}
|
|
}
|