feat: registration section preferences with show_in_registration filtering and deduplication
Add show_in_registration and registration_description columns to festival_sections. Registration form now shows deduplicated sections by name (across sub-events), filtered by show_in_registration=true, grouped by category with card-based UI. Section preferences use section_name instead of section_id. Add GET/PUT registration-settings endpoints for festival-level bulk management. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -35,11 +35,20 @@ class PublicRegistrationDataTest extends TestCase
|
||||
$section = FestivalSection::factory()->create([
|
||||
'event_id' => $event->id,
|
||||
'type' => 'standard',
|
||||
'show_in_registration' => true,
|
||||
'registration_description' => 'Test description',
|
||||
]);
|
||||
|
||||
FestivalSection::factory()->create([
|
||||
'event_id' => $event->id,
|
||||
'type' => 'cross_event',
|
||||
'show_in_registration' => true,
|
||||
]);
|
||||
|
||||
FestivalSection::factory()->create([
|
||||
'event_id' => $event->id,
|
||||
'type' => 'standard',
|
||||
'show_in_registration' => false,
|
||||
]);
|
||||
|
||||
$timeSlot = TimeSlot::factory()->create([
|
||||
@@ -82,4 +91,112 @@ class PublicRegistrationDataTest extends TestCase
|
||||
|
||||
$response->assertNotFound();
|
||||
}
|
||||
|
||||
public function test_includes_registration_description_in_sections(): void
|
||||
{
|
||||
$event = Event::factory()->create([
|
||||
'organisation_id' => $this->organisation->id,
|
||||
'status' => 'registration_open',
|
||||
'slug' => 'desc-event',
|
||||
]);
|
||||
|
||||
FestivalSection::factory()->create([
|
||||
'event_id' => $event->id,
|
||||
'type' => 'standard',
|
||||
'show_in_registration' => true,
|
||||
'registration_description' => 'Tap bier en drankjes',
|
||||
]);
|
||||
|
||||
$response = $this->getJson('/api/v1/public/events/desc-event/registration-data');
|
||||
|
||||
$response->assertOk()
|
||||
->assertJsonPath('data.sections.0.registration_description', 'Tap bier en drankjes');
|
||||
}
|
||||
|
||||
public function test_excludes_sections_with_show_in_registration_false(): void
|
||||
{
|
||||
$event = Event::factory()->create([
|
||||
'organisation_id' => $this->organisation->id,
|
||||
'status' => 'registration_open',
|
||||
'slug' => 'filter-event',
|
||||
]);
|
||||
|
||||
FestivalSection::factory()->create([
|
||||
'event_id' => $event->id,
|
||||
'type' => 'standard',
|
||||
'show_in_registration' => false,
|
||||
]);
|
||||
|
||||
$response = $this->getJson('/api/v1/public/events/filter-event/registration-data');
|
||||
|
||||
$response->assertOk()
|
||||
->assertJsonCount(0, 'data.sections');
|
||||
}
|
||||
|
||||
public function test_festival_deduplicates_sections_by_name(): void
|
||||
{
|
||||
$festival = Event::factory()->festival()->create([
|
||||
'organisation_id' => $this->organisation->id,
|
||||
'status' => 'registration_open',
|
||||
'slug' => 'dedup-festival',
|
||||
]);
|
||||
|
||||
$sub1 = Event::factory()->subEvent($festival)->create(['status' => 'registration_open']);
|
||||
$sub2 = Event::factory()->subEvent($festival)->create(['status' => 'registration_open']);
|
||||
$sub3 = Event::factory()->subEvent($festival)->create(['status' => 'published']);
|
||||
|
||||
// Same section name across 3 sub-events
|
||||
foreach ([$sub1, $sub2, $sub3] as $sub) {
|
||||
FestivalSection::factory()->create([
|
||||
'event_id' => $sub->id,
|
||||
'name' => 'Hoofdpodium Bar',
|
||||
'type' => 'standard',
|
||||
'show_in_registration' => true,
|
||||
'category' => 'Bar',
|
||||
]);
|
||||
}
|
||||
|
||||
TimeSlot::factory()->create(['event_id' => $sub1->id, 'person_type' => 'VOLUNTEER']);
|
||||
|
||||
$response = $this->getJson('/api/v1/public/events/dedup-festival/registration-data');
|
||||
|
||||
$response->assertOk()
|
||||
->assertJsonCount(1, 'data.sections')
|
||||
->assertJsonPath('data.sections.0.name', 'Hoofdpodium Bar');
|
||||
}
|
||||
|
||||
public function test_festival_excludes_parent_operational_sections(): void
|
||||
{
|
||||
$festival = Event::factory()->festival()->create([
|
||||
'organisation_id' => $this->organisation->id,
|
||||
'status' => 'registration_open',
|
||||
'slug' => 'parent-ops-festival',
|
||||
]);
|
||||
|
||||
$sub = Event::factory()->subEvent($festival)->create(['status' => 'registration_open']);
|
||||
|
||||
// Parent operational section (should be excluded)
|
||||
FestivalSection::factory()->create([
|
||||
'event_id' => $festival->id,
|
||||
'name' => 'Terreinploeg',
|
||||
'type' => 'standard',
|
||||
'show_in_registration' => true,
|
||||
]);
|
||||
|
||||
// Sub-event section (should be included)
|
||||
FestivalSection::factory()->create([
|
||||
'event_id' => $sub->id,
|
||||
'name' => 'Bar',
|
||||
'type' => 'standard',
|
||||
'show_in_registration' => true,
|
||||
]);
|
||||
|
||||
TimeSlot::factory()->create(['event_id' => $sub->id, 'person_type' => 'VOLUNTEER']);
|
||||
|
||||
$response = $this->getJson('/api/v1/public/events/parent-ops-festival/registration-data');
|
||||
|
||||
$response->assertOk()
|
||||
->assertJsonCount(1, 'data.sections')
|
||||
->assertJsonPath('data.sections.0.name', 'Bar');
|
||||
}
|
||||
}
|
||||
|
||||
233
api/tests/Feature/Api/V1/RegistrationSettingsTest.php
Normal file
233
api/tests/Feature/Api/V1/RegistrationSettingsTest.php
Normal file
@@ -0,0 +1,233 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Feature\Api\V1;
|
||||
|
||||
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 RegistrationSettingsTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
private Organisation $organisation;
|
||||
private User $orgAdmin;
|
||||
private Event $festival;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
$this->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_as_section_name(): void
|
||||
{
|
||||
// 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,
|
||||
]);
|
||||
|
||||
FestivalSection::factory()->create([
|
||||
'event_id' => $event->id,
|
||||
'name' => 'Backstage',
|
||||
'show_in_registration' => true,
|
||||
]);
|
||||
|
||||
$response = $this->postJson("/api/v1/events/{$event->id}/volunteer-register", [
|
||||
'name' => 'Test Vrijwilliger',
|
||||
'email' => 'test-section-pref@example.nl',
|
||||
'section_preferences' => [
|
||||
['section_name' => 'Backstage', 'priority' => 1],
|
||||
],
|
||||
]);
|
||||
|
||||
$response->assertStatus(201);
|
||||
|
||||
$person = \App\Models\Person::where('email', 'test-section-pref@example.nl')->first();
|
||||
$prefs = $person->custom_fields['section_preferences'];
|
||||
|
||||
$this->assertCount(1, $prefs);
|
||||
$this->assertEquals('Backstage', $prefs[0]['section_name']);
|
||||
$this->assertEquals(1, $prefs[0]['priority']);
|
||||
}
|
||||
}
|
||||
375
api/tests/Feature/Api/V1/VolunteerRegistrationTest.php
Normal file
375
api/tests/Feature/Api/V1/VolunteerRegistrationTest.php
Normal file
@@ -0,0 +1,375 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Feature\Api\V1;
|
||||
|
||||
use App\Enums\PersonStatus;
|
||||
use App\Models\CrowdType;
|
||||
use App\Models\Event;
|
||||
use App\Models\FestivalSection;
|
||||
use App\Models\Organisation;
|
||||
use App\Models\Person;
|
||||
use App\Models\TimeSlot;
|
||||
use App\Models\User;
|
||||
use Database\Seeders\RoleSeeder;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Laravel\Sanctum\Sanctum;
|
||||
use Tests\TestCase;
|
||||
|
||||
class VolunteerRegistrationTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
private Organisation $organisation;
|
||||
private Event $event;
|
||||
private CrowdType $volunteerCrowdType;
|
||||
private TimeSlot $timeSlot;
|
||||
private FestivalSection $section;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
$this->seed(RoleSeeder::class);
|
||||
|
||||
$this->organisation = Organisation::factory()->create();
|
||||
$this->volunteerCrowdType = CrowdType::factory()->systemType('VOLUNTEER')->create([
|
||||
'organisation_id' => $this->organisation->id,
|
||||
]);
|
||||
$this->event = Event::factory()->create([
|
||||
'organisation_id' => $this->organisation->id,
|
||||
'status' => 'registration_open',
|
||||
]);
|
||||
$this->section = FestivalSection::factory()->create([
|
||||
'event_id' => $this->event->id,
|
||||
]);
|
||||
$this->timeSlot = TimeSlot::factory()->create([
|
||||
'event_id' => $this->event->id,
|
||||
]);
|
||||
}
|
||||
|
||||
// ─── Anonymous Registration ─────────────────────────────────────────
|
||||
|
||||
public function test_volunteer_can_register_with_all_fields(): void
|
||||
{
|
||||
$response = $this->postJson("/api/v1/events/{$this->event->id}/volunteer-register", [
|
||||
'name' => 'Jan de Vries',
|
||||
'email' => 'jan@voorbeeld.nl',
|
||||
'phone' => '+31612345678',
|
||||
'tshirt_size' => 'L',
|
||||
'motivation' => 'Ik wil graag helpen bij dit festival!',
|
||||
'availabilities' => [
|
||||
['time_slot_id' => $this->timeSlot->id, 'preference_level' => 5],
|
||||
],
|
||||
]);
|
||||
|
||||
$response->assertStatus(201);
|
||||
|
||||
$this->assertDatabaseHas('persons', [
|
||||
'email' => 'jan@voorbeeld.nl',
|
||||
'event_id' => $this->event->id,
|
||||
'status' => PersonStatus::PENDING->value,
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_volunteer_can_register_with_minimal_fields(): void
|
||||
{
|
||||
$response = $this->postJson("/api/v1/events/{$this->event->id}/volunteer-register", [
|
||||
'name' => 'Sophie Bakker',
|
||||
'email' => 'sophie@voorbeeld.nl',
|
||||
]);
|
||||
|
||||
$response->assertStatus(201);
|
||||
|
||||
$this->assertDatabaseHas('persons', [
|
||||
'email' => 'sophie@voorbeeld.nl',
|
||||
'name' => 'Sophie Bakker',
|
||||
'event_id' => $this->event->id,
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_registration_resolves_to_parent_event(): void
|
||||
{
|
||||
$festival = Event::factory()->festival()->create([
|
||||
'organisation_id' => $this->organisation->id,
|
||||
'status' => 'registration_open',
|
||||
]);
|
||||
$subEvent = Event::factory()->subEvent($festival)->create([
|
||||
'status' => 'registration_open',
|
||||
]);
|
||||
TimeSlot::factory()->create(['event_id' => $festival->id]);
|
||||
|
||||
$response = $this->postJson("/api/v1/events/{$subEvent->id}/volunteer-register", [
|
||||
'name' => 'Pieter Jansen',
|
||||
'email' => 'pieter@voorbeeld.nl',
|
||||
]);
|
||||
|
||||
$response->assertStatus(201);
|
||||
|
||||
$this->assertDatabaseHas('persons', [
|
||||
'email' => 'pieter@voorbeeld.nl',
|
||||
'event_id' => $festival->id,
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_registration_syncs_availabilities(): void
|
||||
{
|
||||
$timeSlot2 = TimeSlot::factory()->create(['event_id' => $this->event->id]);
|
||||
|
||||
$response = $this->postJson("/api/v1/events/{$this->event->id}/volunteer-register", [
|
||||
'name' => 'Fleur Vermeer',
|
||||
'email' => 'fleur@voorbeeld.nl',
|
||||
'availabilities' => [
|
||||
['time_slot_id' => $this->timeSlot->id, 'preference_level' => 4],
|
||||
['time_slot_id' => $timeSlot2->id, 'preference_level' => 2],
|
||||
],
|
||||
]);
|
||||
|
||||
$response->assertStatus(201);
|
||||
|
||||
$person = Person::where('email', 'fleur@voorbeeld.nl')->first();
|
||||
|
||||
$this->assertDatabaseHas('volunteer_availabilities', [
|
||||
'person_id' => $person->id,
|
||||
'time_slot_id' => $this->timeSlot->id,
|
||||
'preference_level' => 4,
|
||||
]);
|
||||
$this->assertDatabaseHas('volunteer_availabilities', [
|
||||
'person_id' => $person->id,
|
||||
'time_slot_id' => $timeSlot2->id,
|
||||
'preference_level' => 2,
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_registration_stores_custom_fields(): void
|
||||
{
|
||||
$response = $this->postJson("/api/v1/events/{$this->event->id}/volunteer-register", [
|
||||
'name' => 'Daan Mulder',
|
||||
'email' => 'daan@voorbeeld.nl',
|
||||
'tshirt_size' => 'XL',
|
||||
'motivation' => 'Ik vind festivals geweldig.',
|
||||
'section_preferences' => [
|
||||
['section_name' => $this->section->name, 'priority' => 1],
|
||||
],
|
||||
]);
|
||||
|
||||
$response->assertStatus(201);
|
||||
|
||||
$person = Person::where('email', 'daan@voorbeeld.nl')->first();
|
||||
$customFields = $person->custom_fields;
|
||||
|
||||
$this->assertEquals('XL', $customFields['tshirt_size']);
|
||||
$this->assertEquals('Ik vind festivals geweldig.', $customFields['motivation']);
|
||||
$this->assertNotEmpty($customFields['section_preferences']);
|
||||
}
|
||||
|
||||
public function test_duplicate_email_rejected(): void
|
||||
{
|
||||
$this->postJson("/api/v1/events/{$this->event->id}/volunteer-register", [
|
||||
'name' => 'Anna Smit',
|
||||
'email' => 'anna@voorbeeld.nl',
|
||||
]);
|
||||
|
||||
$response = $this->postJson("/api/v1/events/{$this->event->id}/volunteer-register", [
|
||||
'name' => 'Anna Smit',
|
||||
'email' => 'anna@voorbeeld.nl',
|
||||
]);
|
||||
|
||||
$response->assertStatus(422);
|
||||
$response->assertJsonValidationErrors('email');
|
||||
}
|
||||
|
||||
public function test_rejected_person_can_reregister(): void
|
||||
{
|
||||
Person::factory()->rejected()->create([
|
||||
'event_id' => $this->event->id,
|
||||
'crowd_type_id' => $this->volunteerCrowdType->id,
|
||||
'email' => 'herkan@voorbeeld.nl',
|
||||
]);
|
||||
|
||||
$response = $this->postJson("/api/v1/events/{$this->event->id}/volunteer-register", [
|
||||
'name' => 'Herkan Poging',
|
||||
'email' => 'herkan@voorbeeld.nl',
|
||||
]);
|
||||
|
||||
$response->assertStatus(200);
|
||||
|
||||
$this->assertDatabaseHas('persons', [
|
||||
'email' => 'herkan@voorbeeld.nl',
|
||||
'status' => PersonStatus::PENDING->value,
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_event_not_registration_open(): void
|
||||
{
|
||||
$draftEvent = Event::factory()->create([
|
||||
'organisation_id' => $this->organisation->id,
|
||||
'status' => 'draft',
|
||||
]);
|
||||
|
||||
$response = $this->postJson("/api/v1/events/{$draftEvent->id}/volunteer-register", [
|
||||
'name' => 'Test Persoon',
|
||||
'email' => 'test@voorbeeld.nl',
|
||||
]);
|
||||
|
||||
$response->assertStatus(422);
|
||||
}
|
||||
|
||||
public function test_invalid_time_slot_rejected(): void
|
||||
{
|
||||
$response = $this->postJson("/api/v1/events/{$this->event->id}/volunteer-register", [
|
||||
'name' => 'Bas van Dijk',
|
||||
'email' => 'bas@voorbeeld.nl',
|
||||
'availabilities' => [
|
||||
['time_slot_id' => '01JNONEXISTENT00000000000', 'preference_level' => 3],
|
||||
],
|
||||
]);
|
||||
|
||||
$response->assertStatus(422);
|
||||
$response->assertJsonValidationErrors('availabilities.0.time_slot_id');
|
||||
}
|
||||
|
||||
// ─── Authenticated Registration ─────────────────────────────────────
|
||||
|
||||
public function test_authenticated_user_registration(): void
|
||||
{
|
||||
$user = User::factory()->create([
|
||||
'name' => 'Lisa de Groot',
|
||||
'email' => 'lisa@voorbeeld.nl',
|
||||
]);
|
||||
$this->organisation->users()->attach($user, ['role' => 'org_member']);
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
$response = $this->postJson("/api/v1/events/{$this->event->id}/volunteer-register", []);
|
||||
|
||||
$response->assertStatus(201);
|
||||
|
||||
$this->assertDatabaseHas('persons', [
|
||||
'email' => 'lisa@voorbeeld.nl',
|
||||
'user_id' => $user->id,
|
||||
'event_id' => $this->event->id,
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_authenticated_ignores_request_email(): void
|
||||
{
|
||||
$user = User::factory()->create([
|
||||
'name' => 'Mark Visser',
|
||||
'email' => 'mark@voorbeeld.nl',
|
||||
]);
|
||||
$this->organisation->users()->attach($user, ['role' => 'org_member']);
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
$response = $this->postJson("/api/v1/events/{$this->event->id}/volunteer-register", [
|
||||
'email' => 'nep@voorbeeld.nl',
|
||||
]);
|
||||
|
||||
$response->assertStatus(201);
|
||||
|
||||
$person = Person::where('user_id', $user->id)->first();
|
||||
$this->assertEquals('mark@voorbeeld.nl', $person->email);
|
||||
}
|
||||
|
||||
public function test_authenticated_duplicate_rejected(): void
|
||||
{
|
||||
$user = User::factory()->create([
|
||||
'name' => 'Eva Hendriks',
|
||||
'email' => 'eva@voorbeeld.nl',
|
||||
]);
|
||||
$this->organisation->users()->attach($user, ['role' => 'org_member']);
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
$this->postJson("/api/v1/events/{$this->event->id}/volunteer-register", []);
|
||||
|
||||
$response = $this->postJson("/api/v1/events/{$this->event->id}/volunteer-register", []);
|
||||
|
||||
$response->assertStatus(422);
|
||||
$response->assertJsonValidationErrors('email');
|
||||
}
|
||||
|
||||
// ─── Portal Token Auth ──────────────────────────────────────────────
|
||||
|
||||
public function test_missing_token_returns_error(): void
|
||||
{
|
||||
$response = $this->postJson('/api/v1/portal/token-auth', []);
|
||||
|
||||
$response->assertStatus(422);
|
||||
$response->assertJsonValidationErrors('token');
|
||||
}
|
||||
|
||||
public function test_invalid_token_returns_401(): void
|
||||
{
|
||||
// artists table exists via migration, so an invalid token returns 401
|
||||
$response = $this->postJson('/api/v1/portal/token-auth', [
|
||||
'token' => 'some-random-invalid-token',
|
||||
]);
|
||||
|
||||
$response->assertStatus(401);
|
||||
$response->assertJson(['message' => 'Invalid or expired portal token']);
|
||||
}
|
||||
|
||||
public function test_token_auth_returns_501_when_no_tables(): void
|
||||
{
|
||||
// Drop the artists table to simulate no token tables existing
|
||||
Schema::dropIfExists('artists');
|
||||
|
||||
$response = $this->postJson('/api/v1/portal/token-auth', [
|
||||
'token' => '01JTEST000000000000000000',
|
||||
]);
|
||||
|
||||
$response->assertStatus(501);
|
||||
$response->assertJson(['message' => 'Token-based portal access is not yet available']);
|
||||
}
|
||||
|
||||
// ─── Portal Me ──────────────────────────────────────────────────────
|
||||
|
||||
public function test_authenticated_user_gets_person(): void
|
||||
{
|
||||
$user = User::factory()->create(['name' => 'Karin Bos']);
|
||||
$this->organisation->users()->attach($user, ['role' => 'org_member']);
|
||||
|
||||
Person::factory()->create([
|
||||
'event_id' => $this->event->id,
|
||||
'crowd_type_id' => $this->volunteerCrowdType->id,
|
||||
'user_id' => $user->id,
|
||||
'email' => $user->email,
|
||||
]);
|
||||
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
$response = $this->getJson("/api/v1/portal/me?event_id={$this->event->id}");
|
||||
|
||||
$response->assertStatus(200);
|
||||
$response->assertJsonPath('data.email', $user->email);
|
||||
}
|
||||
|
||||
public function test_authenticated_user_no_person_returns_404(): void
|
||||
{
|
||||
$user = User::factory()->create(['name' => 'Tom Kuiper']);
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
$response = $this->getJson("/api/v1/portal/me?event_id={$this->event->id}");
|
||||
|
||||
$response->assertStatus(404);
|
||||
$response->assertJson(['message' => 'No registration found for this event']);
|
||||
}
|
||||
|
||||
public function test_missing_event_id_returns_422(): void
|
||||
{
|
||||
$user = User::factory()->create(['name' => 'Sanne Bruin']);
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
$response = $this->getJson('/api/v1/portal/me');
|
||||
|
||||
$response->assertStatus(422);
|
||||
$response->assertJsonValidationErrors('event_id');
|
||||
}
|
||||
|
||||
public function test_unauthenticated_returns_401(): void
|
||||
{
|
||||
$response = $this->getJson("/api/v1/portal/me?event_id={$this->event->id}");
|
||||
|
||||
$response->assertStatus(401);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user