feat: fase 2 backend — crowd types, persons, sections, shifts, invite flow
- Crowd Types + Persons CRUD (73 tests) - Festival Sections + Time Slots + Shifts CRUD met assign/claim flow (84 tests) - Invite Flow + Member Management met InvitationService (109 tests) - Schema v1.6 migraties volledig uitgevoerd - DevSeeder bijgewerkt met crowd types voor testorganisatie
This commit is contained in:
168
api/tests/Feature/FestivalSection/FestivalSectionTest.php
Normal file
168
api/tests/Feature/FestivalSection/FestivalSectionTest.php
Normal file
@@ -0,0 +1,168 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Feature\FestivalSection;
|
||||
|
||||
use App\Models\Event;
|
||||
use App\Models\FestivalSection;
|
||||
use App\Models\Organisation;
|
||||
use App\Models\User;
|
||||
use Database\Seeders\RoleSeeder;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Laravel\Sanctum\Sanctum;
|
||||
use Tests\TestCase;
|
||||
|
||||
class FestivalSectionTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
private User $orgAdmin;
|
||||
private User $outsider;
|
||||
private Organisation $organisation;
|
||||
private Organisation $otherOrganisation;
|
||||
private Event $event;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
$this->seed(RoleSeeder::class);
|
||||
|
||||
$this->organisation = Organisation::factory()->create();
|
||||
$this->otherOrganisation = Organisation::factory()->create();
|
||||
|
||||
$this->orgAdmin = User::factory()->create();
|
||||
$this->organisation->users()->attach($this->orgAdmin, ['role' => 'org_admin']);
|
||||
|
||||
$this->outsider = User::factory()->create();
|
||||
$this->otherOrganisation->users()->attach($this->outsider, ['role' => 'org_admin']);
|
||||
|
||||
$this->event = Event::factory()->create(['organisation_id' => $this->organisation->id]);
|
||||
}
|
||||
|
||||
public function test_index_returns_sections_for_event(): void
|
||||
{
|
||||
FestivalSection::factory()->count(3)->create(['event_id' => $this->event->id]);
|
||||
|
||||
// Section on another event should not appear
|
||||
$otherEvent = Event::factory()->create(['organisation_id' => $this->organisation->id]);
|
||||
FestivalSection::factory()->create(['event_id' => $otherEvent->id]);
|
||||
|
||||
Sanctum::actingAs($this->orgAdmin);
|
||||
|
||||
$response = $this->getJson("/api/v1/events/{$this->event->id}/sections");
|
||||
|
||||
$response->assertOk();
|
||||
$this->assertCount(3, $response->json('data'));
|
||||
}
|
||||
|
||||
public function test_index_cross_org_returns_403(): void
|
||||
{
|
||||
Sanctum::actingAs($this->outsider);
|
||||
|
||||
$response = $this->getJson("/api/v1/events/{$this->event->id}/sections");
|
||||
|
||||
$response->assertForbidden();
|
||||
}
|
||||
|
||||
public function test_store_creates_section(): void
|
||||
{
|
||||
Sanctum::actingAs($this->orgAdmin);
|
||||
|
||||
$response = $this->postJson("/api/v1/events/{$this->event->id}/sections", [
|
||||
'name' => 'Bar',
|
||||
'sort_order' => 1,
|
||||
]);
|
||||
|
||||
$response->assertCreated()
|
||||
->assertJson(['data' => ['name' => 'Bar', 'sort_order' => 1]]);
|
||||
|
||||
$this->assertDatabaseHas('festival_sections', [
|
||||
'event_id' => $this->event->id,
|
||||
'name' => 'Bar',
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_store_unauthenticated_returns_401(): void
|
||||
{
|
||||
$response = $this->postJson("/api/v1/events/{$this->event->id}/sections", [
|
||||
'name' => 'Bar',
|
||||
'sort_order' => 1,
|
||||
]);
|
||||
|
||||
$response->assertUnauthorized();
|
||||
}
|
||||
|
||||
public function test_store_missing_name_returns_422(): void
|
||||
{
|
||||
Sanctum::actingAs($this->orgAdmin);
|
||||
|
||||
$response = $this->postJson("/api/v1/events/{$this->event->id}/sections", [
|
||||
'sort_order' => 1,
|
||||
]);
|
||||
|
||||
$response->assertUnprocessable()
|
||||
->assertJsonValidationErrors('name');
|
||||
}
|
||||
|
||||
public function test_update_section(): void
|
||||
{
|
||||
$section = FestivalSection::factory()->create([
|
||||
'event_id' => $this->event->id,
|
||||
'name' => 'Bar',
|
||||
]);
|
||||
|
||||
Sanctum::actingAs($this->orgAdmin);
|
||||
|
||||
$response = $this->putJson("/api/v1/events/{$this->event->id}/sections/{$section->id}", [
|
||||
'name' => 'Bar Updated',
|
||||
]);
|
||||
|
||||
$response->assertOk()
|
||||
->assertJson(['data' => ['name' => 'Bar Updated']]);
|
||||
}
|
||||
|
||||
public function test_destroy_soft_deletes_section(): void
|
||||
{
|
||||
$section = FestivalSection::factory()->create(['event_id' => $this->event->id]);
|
||||
|
||||
Sanctum::actingAs($this->orgAdmin);
|
||||
|
||||
$response = $this->deleteJson("/api/v1/events/{$this->event->id}/sections/{$section->id}");
|
||||
|
||||
$response->assertNoContent();
|
||||
$this->assertSoftDeleted('festival_sections', ['id' => $section->id]);
|
||||
}
|
||||
|
||||
public function test_reorder_updates_sort_order(): void
|
||||
{
|
||||
$sectionA = FestivalSection::factory()->create([
|
||||
'event_id' => $this->event->id,
|
||||
'sort_order' => 1,
|
||||
]);
|
||||
$sectionB = FestivalSection::factory()->create([
|
||||
'event_id' => $this->event->id,
|
||||
'sort_order' => 2,
|
||||
]);
|
||||
|
||||
Sanctum::actingAs($this->orgAdmin);
|
||||
|
||||
$response = $this->postJson("/api/v1/events/{$this->event->id}/sections/reorder", [
|
||||
'sections' => [
|
||||
['id' => $sectionA->id, 'sort_order' => 2],
|
||||
['id' => $sectionB->id, 'sort_order' => 1],
|
||||
],
|
||||
]);
|
||||
|
||||
$response->assertOk();
|
||||
|
||||
$this->assertDatabaseHas('festival_sections', [
|
||||
'id' => $sectionA->id,
|
||||
'sort_order' => 2,
|
||||
]);
|
||||
$this->assertDatabaseHas('festival_sections', [
|
||||
'id' => $sectionB->id,
|
||||
'sort_order' => 1,
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user