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, ]); } }