63 lines
1.5 KiB
PHP
63 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace Tests\Feature\Catalog;
|
|
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Tests\TestCase;
|
|
|
|
class EdiBandControllerTest extends TestCase
|
|
{
|
|
use RefreshDatabase;
|
|
|
|
public function test_index_returns_edi_bands(): void
|
|
{
|
|
$item = $this->createEdiBand();
|
|
|
|
$response = $this->getJson('/api/edi-bands');
|
|
|
|
$response->assertStatus(200)
|
|
->assertJsonFragment(['id' => $item->id]);
|
|
}
|
|
|
|
public function test_show_returns_edi_band(): void
|
|
{
|
|
$item = $this->createEdiBand();
|
|
|
|
$response = $this->getJson("/api/edi-bands/{$item->id}");
|
|
|
|
$response->assertStatus(200)
|
|
->assertJsonFragment(['id' => $item->id]);
|
|
}
|
|
|
|
public function test_admin_can_create_update_and_delete_edi_band(): void
|
|
{
|
|
$this->actingAsAdmin();
|
|
|
|
$createResponse = $this->postJson('/api/edi-bands', [
|
|
'value' => 'EDI-144',
|
|
]);
|
|
|
|
$createResponse->assertStatus(201);
|
|
$itemId = $createResponse->json('id');
|
|
|
|
$updateResponse = $this->putJson("/api/edi-bands/{$itemId}", [
|
|
'value' => 'EDI-432',
|
|
]);
|
|
|
|
$updateResponse->assertStatus(200)
|
|
->assertJsonFragment(['id' => $itemId]);
|
|
|
|
$this->deleteJson("/api/edi-bands/{$itemId}")
|
|
->assertStatus(204);
|
|
}
|
|
|
|
public function test_non_admin_cannot_create_edi_band(): void
|
|
{
|
|
$this->actingAsUser();
|
|
|
|
$this->postJson('/api/edi-bands', [
|
|
'value' => 'EDI-144',
|
|
])->assertStatus(403);
|
|
}
|
|
}
|