Initial commit
This commit is contained in:
74
tests/Feature/Catalog/BandControllerTest.php
Normal file
74
tests/Feature/Catalog/BandControllerTest.php
Normal file
@@ -0,0 +1,74 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Catalog;
|
||||
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Tests\TestCase;
|
||||
|
||||
class BandControllerTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_index_returns_bands(): void
|
||||
{
|
||||
$band = $this->createBand();
|
||||
|
||||
$response = $this->getJson('/api/bands');
|
||||
|
||||
$response->assertStatus(200)
|
||||
->assertJsonFragment(['id' => $band->id]);
|
||||
}
|
||||
|
||||
public function test_show_returns_band(): void
|
||||
{
|
||||
$band = $this->createBand();
|
||||
|
||||
$response = $this->getJson("/api/bands/{$band->id}");
|
||||
|
||||
$response->assertStatus(200)
|
||||
->assertJsonFragment(['id' => $band->id]);
|
||||
}
|
||||
|
||||
public function test_admin_can_create_update_and_delete_band(): void
|
||||
{
|
||||
$this->actingAsAdmin();
|
||||
|
||||
$createResponse = $this->postJson('/api/bands', [
|
||||
'name' => '144 MHz',
|
||||
'order' => 1,
|
||||
'edi_band_begin' => 144000000,
|
||||
'edi_band_end' => 146000000,
|
||||
'has_power_category' => true,
|
||||
]);
|
||||
|
||||
$createResponse->assertStatus(201);
|
||||
$bandId = $createResponse->json('id');
|
||||
|
||||
$updateResponse = $this->putJson("/api/bands/{$bandId}", [
|
||||
'name' => '144 MHz (upd)',
|
||||
'order' => 2,
|
||||
'edi_band_begin' => 144000000,
|
||||
'edi_band_end' => 146000000,
|
||||
'has_power_category' => false,
|
||||
]);
|
||||
|
||||
$updateResponse->assertStatus(200)
|
||||
->assertJsonFragment(['id' => $bandId]);
|
||||
|
||||
$this->deleteJson("/api/bands/{$bandId}")
|
||||
->assertStatus(204);
|
||||
}
|
||||
|
||||
public function test_non_admin_cannot_create_band(): void
|
||||
{
|
||||
$this->actingAsUser();
|
||||
|
||||
$this->postJson('/api/bands', [
|
||||
'name' => '144 MHz',
|
||||
'order' => 1,
|
||||
'edi_band_begin' => 144000000,
|
||||
'edi_band_end' => 146000000,
|
||||
'has_power_category' => true,
|
||||
])->assertStatus(403);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user