seed(RoleSeeder::class); $this->organisation = Organisation::factory()->create(); $this->orgAdmin = User::factory()->create(); $this->orgAdmin->assignRole('org_admin'); $this->organisation->users()->attach($this->orgAdmin, ['role' => 'org_admin']); $this->festival = Event::factory()->festival()->create([ 'organisation_id' => $this->organisation->id, 'status' => 'registration_open', ]); } public function test_get_returns_grouped_unique_section_names(): void { $sub1 = Event::factory()->subEvent($this->festival)->create(); $sub2 = Event::factory()->subEvent($this->festival)->create(); foreach ([$sub1, $sub2] as $sub) { FestivalSection::factory()->create([ 'event_id' => $sub->id, 'name' => 'Hoofdpodium Bar', 'category' => 'Bar', 'icon' => 'tabler-beer', 'show_in_registration' => true, 'registration_description' => 'Tap bier', ]); } FestivalSection::factory()->create([ 'event_id' => $sub1->id, 'name' => 'Backstage', 'category' => 'Hospitality', 'show_in_registration' => false, ]); Sanctum::actingAs($this->orgAdmin); $response = $this->getJson("/api/v1/events/{$this->festival->id}/sections/registration-settings"); $response->assertOk() ->assertJsonCount(2, 'data'); $bar = collect($response->json('data'))->firstWhere('name', 'Hoofdpodium Bar'); $this->assertEquals(2, $bar['section_count']); $this->assertCount(2, $bar['section_ids']); $this->assertTrue($bar['show_in_registration']); $this->assertEquals('Tap bier', $bar['registration_description']); } public function test_put_updates_all_instances_across_festival(): void { $sub1 = Event::factory()->subEvent($this->festival)->create(); $sub2 = Event::factory()->subEvent($this->festival)->create(); $sub3 = Event::factory()->subEvent($this->festival)->create(); $sections = []; foreach ([$sub1, $sub2, $sub3] as $sub) { $sections[] = FestivalSection::factory()->create([ 'event_id' => $sub->id, 'name' => 'Theatertent Bar', 'show_in_registration' => false, 'registration_description' => null, ]); } Sanctum::actingAs($this->orgAdmin); $response = $this->putJson("/api/v1/events/{$this->festival->id}/sections/registration-settings", [ 'name' => 'Theatertent Bar', 'show_in_registration' => true, 'registration_description' => 'Bediening in de overdekte theatertent', ]); $response->assertOk(); foreach ($sections as $section) { $this->assertDatabaseHas('festival_sections', [ 'id' => $section->id, 'show_in_registration' => true, 'registration_description' => 'Bediening in de overdekte theatertent', ]); } } public function test_put_creates_activity_log(): void { $sub = Event::factory()->subEvent($this->festival)->create(); FestivalSection::factory()->create([ 'event_id' => $sub->id, 'name' => 'EHBO', 'show_in_registration' => false, ]); Sanctum::actingAs($this->orgAdmin); $this->putJson("/api/v1/events/{$this->festival->id}/sections/registration-settings", [ 'name' => 'EHBO', 'show_in_registration' => true, 'registration_description' => null, ]); $this->assertDatabaseHas('activity_log', [ 'description' => 'section.registration_settings_updated', ]); } public function test_put_requires_authenticated_organizer(): void { $sub = Event::factory()->subEvent($this->festival)->create(); FestivalSection::factory()->create([ 'event_id' => $sub->id, 'name' => 'Bar', 'show_in_registration' => false, ]); // Unauthenticated $response = $this->putJson("/api/v1/events/{$this->festival->id}/sections/registration-settings", [ 'name' => 'Bar', 'show_in_registration' => true, 'registration_description' => null, ]); $response->assertUnauthorized(); } public function test_put_returns_404_for_nonexistent_section_name(): void { Sanctum::actingAs($this->orgAdmin); $response = $this->putJson("/api/v1/events/{$this->festival->id}/sections/registration-settings", [ 'name' => 'Nonexistent Section', 'show_in_registration' => true, 'registration_description' => null, ]); $response->assertNotFound(); } public function test_get_requires_authentication(): void { $response = $this->getJson("/api/v1/events/{$this->festival->id}/sections/registration-settings"); $response->assertUnauthorized(); } public function test_flat_event_works_with_own_sections(): void { $flatEvent = Event::factory()->create([ 'organisation_id' => $this->organisation->id, 'status' => 'published', ]); FestivalSection::factory()->create([ 'event_id' => $flatEvent->id, 'name' => 'Podium', 'show_in_registration' => true, ]); Sanctum::actingAs($this->orgAdmin); $response = $this->getJson("/api/v1/events/{$flatEvent->id}/sections/registration-settings"); $response->assertOk() ->assertJsonCount(1, 'data') ->assertJsonPath('data.0.name', 'Podium') ->assertJsonPath('data.0.section_count', 1); } public function test_section_preferences_stored_in_table(): void { \Illuminate\Support\Facades\Mail::fake(); // This is a regression check for the VolunteerRegistration flow $event = Event::factory()->create([ 'organisation_id' => $this->organisation->id, 'status' => 'registration_open', ]); \App\Models\CrowdType::factory()->systemType('VOLUNTEER')->create([ 'organisation_id' => $this->organisation->id, ]); $section = FestivalSection::factory()->create([ 'event_id' => $event->id, 'name' => 'Backstage', 'show_in_registration' => true, ]); $response = $this->postJson("/api/v1/events/{$event->id}/volunteer-register", [ 'first_name' => 'Test', 'last_name' => 'Vrijwilliger', 'email' => 'test-section-pref@example.nl', 'password' => 'wachtwoord123', 'section_preferences' => [ ['festival_section_id' => $section->id, 'priority' => 1], ], ]); $response->assertStatus(201); $person = \App\Models\Person::where('email', 'test-section-pref@example.nl')->first(); $this->assertDatabaseHas('person_section_preferences', [ 'person_id' => $person->id, 'festival_section_id' => $section->id, 'priority' => 1, ]); } }