S2a: purge legacy Form Builder PHP code and routes
This commit is contained in:
@@ -137,41 +137,6 @@ class EventImageUploadTest extends TestCase
|
||||
$response->assertNotFound();
|
||||
}
|
||||
|
||||
public function test_registration_data_includes_branding_fields(): void
|
||||
{
|
||||
$event = Event::factory()->create([
|
||||
'organisation_id' => $this->organisation->id,
|
||||
'status' => 'registration_open',
|
||||
'slug' => 'branding-test-event',
|
||||
'registration_welcome_text' => 'Welcome to our event!',
|
||||
'registration_banner_url' => 'https://example.com/banner.jpg',
|
||||
'registration_logo_url' => 'https://example.com/logo.png',
|
||||
]);
|
||||
|
||||
$response = $this->getJson('/api/v1/public/events/branding-test-event/registration-data');
|
||||
|
||||
$response->assertOk()
|
||||
->assertJsonPath('data.event.registration_welcome_text', 'Welcome to our event!')
|
||||
->assertJsonPath('data.event.registration_banner_url', 'https://example.com/banner.jpg')
|
||||
->assertJsonPath('data.event.registration_logo_url', 'https://example.com/logo.png');
|
||||
}
|
||||
|
||||
public function test_registration_data_includes_null_branding_fields(): void
|
||||
{
|
||||
Event::factory()->create([
|
||||
'organisation_id' => $this->organisation->id,
|
||||
'status' => 'registration_open',
|
||||
'slug' => 'no-branding-event',
|
||||
]);
|
||||
|
||||
$response = $this->getJson('/api/v1/public/events/no-branding-event/registration-data');
|
||||
|
||||
$response->assertOk()
|
||||
->assertJsonPath('data.event.registration_welcome_text', null)
|
||||
->assertJsonPath('data.event.registration_banner_url', null)
|
||||
->assertJsonPath('data.event.registration_logo_url', null);
|
||||
}
|
||||
|
||||
public function test_event_update_saves_welcome_text(): void
|
||||
{
|
||||
Sanctum::actingAs($this->orgAdmin);
|
||||
|
||||
@@ -1,314 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Feature\Api\V1;
|
||||
|
||||
use App\Models\CrowdType;
|
||||
use App\Models\Event;
|
||||
use App\Models\Organisation;
|
||||
use App\Models\Person;
|
||||
use App\Models\User;
|
||||
use Database\Seeders\RoleSeeder;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
use Laravel\Sanctum\Sanctum;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
* End-to-end test: public registration → organizer approval → account creation → portal access
|
||||
*
|
||||
* New flow: registration creates Person without User. Approval creates/links User.
|
||||
*/
|
||||
class PortalRegistrationFlowTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
private Organisation $organisation;
|
||||
private Event $event;
|
||||
private CrowdType $volunteerCrowdType;
|
||||
private User $orgAdmin;
|
||||
|
||||
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->orgAdmin = User::factory()->create();
|
||||
$this->orgAdmin->assignRole('super_admin');
|
||||
$this->organisation->users()->attach($this->orgAdmin, ['role' => 'org_admin']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Golden path: register → person without user → approve → user created → portal works.
|
||||
*/
|
||||
public function test_full_flow_register_approve_creates_user_and_portal_works(): void
|
||||
{
|
||||
Mail::fake();
|
||||
|
||||
// ── Step 1: Volunteer registers (no password) ──
|
||||
$regResponse = $this->postJson("/api/v1/events/{$this->event->id}/volunteer-register", [
|
||||
'first_name' => 'Vrijwilliger',
|
||||
'last_name' => 'Test',
|
||||
'email' => 'vrijwilliger@test.nl',
|
||||
]);
|
||||
|
||||
$regResponse->assertStatus(201);
|
||||
|
||||
$person = Person::where('email', 'vrijwilliger@test.nl')->first();
|
||||
$this->assertNotNull($person);
|
||||
$this->assertNull($person->user_id, 'Person should NOT have user_id after registration');
|
||||
$this->assertEquals('pending', $person->status);
|
||||
$this->assertEquals('self', $person->registration_source);
|
||||
|
||||
// No user account should exist yet
|
||||
$this->assertDatabaseMissing('users', ['email' => 'vrijwilliger@test.nl']);
|
||||
|
||||
// ── Step 2: Organizer approves ──
|
||||
Sanctum::actingAs($this->orgAdmin);
|
||||
|
||||
$approveResponse = $this->postJson(
|
||||
"/api/v1/organisations/{$this->organisation->id}/events/{$this->event->id}/persons/{$person->id}/approve"
|
||||
);
|
||||
|
||||
$approveResponse->assertOk();
|
||||
|
||||
// Approval should have created user account and linked it
|
||||
$person->refresh();
|
||||
$this->assertEquals('approved', $person->status);
|
||||
$this->assertNotNull($person->user_id, 'user_id should be set after approval');
|
||||
|
||||
$user = User::where('email', 'vrijwilliger@test.nl')->first();
|
||||
$this->assertNotNull($user, 'User account should be created on approval');
|
||||
$this->assertEquals($person->user_id, $user->id);
|
||||
|
||||
// ── Step 3: Volunteer accesses portal ──
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
$meResponse = $this->getJson('/api/v1/auth/me');
|
||||
$meResponse->assertOk();
|
||||
$meResponse->assertJsonCount(1, 'data.portal_events');
|
||||
$meResponse->assertJsonPath('data.portal_events.0.event_id', $this->event->id);
|
||||
$meResponse->assertJsonPath('data.portal_events.0.person_status', 'approved');
|
||||
|
||||
$portalMeResponse = $this->getJson("/api/v1/portal/me?event_id={$this->event->id}");
|
||||
$portalMeResponse->assertOk();
|
||||
$portalMeResponse->assertJsonPath('data.email', 'vrijwilliger@test.nl');
|
||||
$portalMeResponse->assertJsonPath('data.status', 'approved');
|
||||
}
|
||||
|
||||
/**
|
||||
* Approval links existing user by person.email.
|
||||
*/
|
||||
public function test_approve_links_existing_user_by_person_email(): void
|
||||
{
|
||||
Mail::fake();
|
||||
|
||||
// Pre-existing user account
|
||||
$existingUser = User::factory()->create(['email' => 'bestaand@test.nl']);
|
||||
|
||||
// Register with same email
|
||||
$this->postJson("/api/v1/events/{$this->event->id}/volunteer-register", [
|
||||
'first_name' => 'Bestaand',
|
||||
'last_name' => 'Lid',
|
||||
'email' => 'bestaand@test.nl',
|
||||
])->assertStatus(201);
|
||||
|
||||
$person = Person::where('email', 'bestaand@test.nl')->first();
|
||||
$this->assertNull($person->user_id);
|
||||
|
||||
// Approve
|
||||
Sanctum::actingAs($this->orgAdmin);
|
||||
$this->postJson(
|
||||
"/api/v1/organisations/{$this->organisation->id}/events/{$this->event->id}/persons/{$person->id}/approve"
|
||||
)->assertOk();
|
||||
|
||||
// Should link to existing user, not create a new one
|
||||
$person->refresh();
|
||||
$this->assertEquals($existingUser->id, $person->user_id);
|
||||
$this->assertEquals(1, User::where('email', 'bestaand@test.nl')->count());
|
||||
}
|
||||
|
||||
/**
|
||||
* Festival hierarchy: register via sub-event, portal works with both IDs.
|
||||
*/
|
||||
public function test_full_flow_with_festival_sub_event(): void
|
||||
{
|
||||
Mail::fake();
|
||||
|
||||
$festival = Event::factory()->festival()->create([
|
||||
'organisation_id' => $this->organisation->id,
|
||||
'status' => 'registration_open',
|
||||
]);
|
||||
$subEvent = Event::factory()->subEvent($festival)->create([
|
||||
'status' => 'registration_open',
|
||||
]);
|
||||
|
||||
// Register via sub-event
|
||||
$this->postJson("/api/v1/events/{$subEvent->id}/volunteer-register", [
|
||||
'first_name' => 'Festival',
|
||||
'last_name' => 'Ganger',
|
||||
'email' => 'festival@test.nl',
|
||||
])->assertStatus(201);
|
||||
|
||||
$person = Person::where('email', 'festival@test.nl')->first();
|
||||
$this->assertEquals($festival->id, $person->event_id, 'Person should be linked to parent event');
|
||||
|
||||
// Approve
|
||||
Sanctum::actingAs($this->orgAdmin);
|
||||
$this->postJson(
|
||||
"/api/v1/organisations/{$this->organisation->id}/events/{$festival->id}/persons/{$person->id}/approve"
|
||||
)->assertOk();
|
||||
|
||||
$person->refresh();
|
||||
$user = User::find($person->user_id);
|
||||
|
||||
// Portal access
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
$this->getJson("/api/v1/portal/me?event_id={$festival->id}")
|
||||
->assertOk()
|
||||
->assertJsonPath('data.email', 'festival@test.nl');
|
||||
|
||||
$this->getJson("/api/v1/portal/me?event_id={$subEvent->id}")
|
||||
->assertOk()
|
||||
->assertJsonPath('data.email', 'festival@test.nl');
|
||||
}
|
||||
|
||||
/**
|
||||
* Authenticated registration still links user_id directly.
|
||||
*/
|
||||
public function test_authenticated_registration_links_user_directly(): void
|
||||
{
|
||||
Mail::fake();
|
||||
|
||||
$user = User::factory()->create([
|
||||
'first_name' => 'Ingelogd',
|
||||
'last_name' => 'Gebruiker',
|
||||
'email' => 'ingelogd@test.nl',
|
||||
]);
|
||||
$this->organisation->users()->attach($user, ['role' => 'org_member']);
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
$this->postJson("/api/v1/events/{$this->event->id}/volunteer-register", [])
|
||||
->assertStatus(201);
|
||||
|
||||
$person = Person::where('email', 'ingelogd@test.nl')->first();
|
||||
$this->assertEquals($user->id, $person->user_id, 'Authenticated registration should set user_id directly');
|
||||
}
|
||||
|
||||
/**
|
||||
* Approval skips account creation if person already has user_id (authenticated registration).
|
||||
*/
|
||||
public function test_approve_skips_account_creation_if_user_already_linked(): void
|
||||
{
|
||||
Mail::fake();
|
||||
|
||||
$user = User::factory()->create(['email' => 'al-gelinkt@test.nl']);
|
||||
$this->organisation->users()->attach($user, ['role' => 'org_member']);
|
||||
|
||||
// Authenticated registration sets user_id
|
||||
Sanctum::actingAs($user);
|
||||
$this->postJson("/api/v1/events/{$this->event->id}/volunteer-register", [])
|
||||
->assertStatus(201);
|
||||
|
||||
$person = Person::where('email', 'al-gelinkt@test.nl')->first();
|
||||
$this->assertEquals($user->id, $person->user_id);
|
||||
|
||||
// Approve — should not create another user
|
||||
Sanctum::actingAs($this->orgAdmin);
|
||||
$this->postJson(
|
||||
"/api/v1/organisations/{$this->organisation->id}/events/{$this->event->id}/persons/{$person->id}/approve"
|
||||
)->assertOk();
|
||||
|
||||
$person->refresh();
|
||||
$this->assertEquals($user->id, $person->user_id);
|
||||
$this->assertEquals(1, User::where('email', 'al-gelinkt@test.nl')->count());
|
||||
}
|
||||
|
||||
/**
|
||||
* Organizer-created person → identity match confirmed → portal/me works.
|
||||
*/
|
||||
public function test_organizer_created_person_then_identity_linked(): void
|
||||
{
|
||||
$user = User::factory()->create([
|
||||
'first_name' => 'Handmatig',
|
||||
'last_name' => 'Toegevoegd',
|
||||
'email' => 'handmatig@test.nl',
|
||||
]);
|
||||
$this->organisation->users()->attach($user, ['role' => 'org_member']);
|
||||
|
||||
Sanctum::actingAs($this->orgAdmin);
|
||||
|
||||
$this->postJson(
|
||||
"/api/v1/organisations/{$this->organisation->id}/events/{$this->event->id}/persons",
|
||||
[
|
||||
'crowd_type_id' => $this->volunteerCrowdType->id,
|
||||
'first_name' => 'Handmatig',
|
||||
'last_name' => 'Toegevoegd',
|
||||
'email' => 'handmatig@test.nl',
|
||||
'status' => 'approved',
|
||||
]
|
||||
)->assertStatus(201);
|
||||
|
||||
$person = Person::where('email', 'handmatig@test.nl')->first();
|
||||
$this->assertNull($person->user_id);
|
||||
|
||||
// Portal fails without user link
|
||||
Sanctum::actingAs($user);
|
||||
$this->getJson("/api/v1/portal/me?event_id={$this->event->id}")
|
||||
->assertStatus(404);
|
||||
|
||||
// Confirm identity match
|
||||
$match = $person->pendingIdentityMatch;
|
||||
$this->assertNotNull($match);
|
||||
|
||||
Sanctum::actingAs($this->orgAdmin);
|
||||
$this->postJson(
|
||||
"/api/v1/organisations/{$this->organisation->id}/identity-matches/{$match->id}/confirm"
|
||||
)->assertOk();
|
||||
|
||||
// Portal now works
|
||||
Sanctum::actingAs($user);
|
||||
$this->getJson("/api/v1/portal/me?event_id={$this->event->id}")
|
||||
->assertOk()
|
||||
->assertJsonPath('data.email', 'handmatig@test.nl');
|
||||
}
|
||||
|
||||
/**
|
||||
* Fuzzy name matching is skipped for self-registered persons.
|
||||
*/
|
||||
public function test_fuzzy_name_match_skipped_for_self_registered(): void
|
||||
{
|
||||
Mail::fake();
|
||||
|
||||
// Create a user with similar name but different email
|
||||
$existingUser = User::factory()->create([
|
||||
'first_name' => 'Jan',
|
||||
'last_name' => 'de Vries',
|
||||
'email' => 'jan.devries@other.nl',
|
||||
]);
|
||||
$this->organisation->users()->attach($existingUser, ['role' => 'org_member']);
|
||||
|
||||
// Self-register with same name but different email
|
||||
$this->postJson("/api/v1/events/{$this->event->id}/volunteer-register", [
|
||||
'first_name' => 'Jan',
|
||||
'last_name' => 'de Vries',
|
||||
'email' => 'jan@voorbeeld.nl',
|
||||
])->assertStatus(201);
|
||||
|
||||
$person = Person::where('email', 'jan@voorbeeld.nl')->first();
|
||||
|
||||
// Should NOT have a fuzzy name match (self-registered)
|
||||
$this->assertNull($person->pendingIdentityMatch);
|
||||
}
|
||||
}
|
||||
@@ -1,332 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Feature\Api\V1;
|
||||
|
||||
use App\Models\CrowdType;
|
||||
use App\Models\Event;
|
||||
use App\Models\FestivalSection;
|
||||
use App\Models\Organisation;
|
||||
use App\Models\PersonTag;
|
||||
use App\Models\RegistrationFormField;
|
||||
use App\Models\TimeSlot;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Tests\TestCase;
|
||||
|
||||
class PublicRegistrationDataTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
private Organisation $organisation;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
$this->organisation = Organisation::factory()->create();
|
||||
}
|
||||
|
||||
public function test_returns_registration_data_for_open_event(): void
|
||||
{
|
||||
$event = Event::factory()->create([
|
||||
'organisation_id' => $this->organisation->id,
|
||||
'status' => 'registration_open',
|
||||
'slug' => 'test-event-2026',
|
||||
]);
|
||||
|
||||
$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([
|
||||
'event_id' => $event->id,
|
||||
'person_type' => 'VOLUNTEER',
|
||||
]);
|
||||
|
||||
TimeSlot::factory()->create([
|
||||
'event_id' => $event->id,
|
||||
'person_type' => 'CREW',
|
||||
]);
|
||||
|
||||
$response = $this->getJson('/api/v1/public/events/test-event-2026/registration-data');
|
||||
|
||||
$response->assertOk()
|
||||
->assertJsonPath('data.event.id', $event->id)
|
||||
->assertJsonPath('data.event.name', $event->name)
|
||||
->assertJsonCount(1, 'data.sections')
|
||||
->assertJsonPath('data.sections.0.id', $section->id)
|
||||
->assertJsonCount(1, 'data.time_slots')
|
||||
->assertJsonPath('data.time_slots.0.id', $timeSlot->id);
|
||||
}
|
||||
|
||||
public function test_returns_404_for_non_registration_open_event(): void
|
||||
{
|
||||
Event::factory()->create([
|
||||
'organisation_id' => $this->organisation->id,
|
||||
'status' => 'draft',
|
||||
'slug' => 'draft-event',
|
||||
]);
|
||||
|
||||
$response = $this->getJson('/api/v1/public/events/draft-event/registration-data');
|
||||
|
||||
$response->assertNotFound();
|
||||
}
|
||||
|
||||
public function test_returns_404_for_nonexistent_slug(): void
|
||||
{
|
||||
$response = $this->getJson('/api/v1/public/events/does-not-exist/registration-data');
|
||||
|
||||
$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');
|
||||
}
|
||||
|
||||
// ─── Registration Fields ───────────────────────────────────────────
|
||||
|
||||
public function test_registration_data_includes_registration_fields(): void
|
||||
{
|
||||
$event = Event::factory()->create([
|
||||
'organisation_id' => $this->organisation->id,
|
||||
'status' => 'registration_open',
|
||||
'slug' => 'fields-event',
|
||||
]);
|
||||
|
||||
$field = RegistrationFormField::factory()->selectField()->create([
|
||||
'event_id' => $event->id,
|
||||
'is_portal_visible' => true,
|
||||
'is_admin_only' => false,
|
||||
'sort_order' => 0,
|
||||
]);
|
||||
|
||||
RegistrationFormField::factory()->textareaField()->create([
|
||||
'event_id' => $event->id,
|
||||
'is_portal_visible' => true,
|
||||
'is_admin_only' => false,
|
||||
'sort_order' => 1,
|
||||
]);
|
||||
|
||||
$response = $this->getJson('/api/v1/public/events/fields-event/registration-data');
|
||||
|
||||
$response->assertOk()
|
||||
->assertJsonCount(2, 'data.registration_fields')
|
||||
->assertJsonPath('data.registration_fields.0.slug', $field->slug)
|
||||
->assertJsonPath('data.registration_fields.0.field_type', 'select')
|
||||
->assertJsonPath('data.registration_fields.0.is_required', false);
|
||||
}
|
||||
|
||||
public function test_registration_data_excludes_admin_only_fields(): void
|
||||
{
|
||||
$event = Event::factory()->create([
|
||||
'organisation_id' => $this->organisation->id,
|
||||
'status' => 'registration_open',
|
||||
'slug' => 'admin-fields-event',
|
||||
]);
|
||||
|
||||
RegistrationFormField::factory()->create([
|
||||
'event_id' => $event->id,
|
||||
'label' => 'Public field',
|
||||
'slug' => 'public-field',
|
||||
'is_portal_visible' => true,
|
||||
'is_admin_only' => false,
|
||||
]);
|
||||
|
||||
// Admin-only field (should be excluded)
|
||||
RegistrationFormField::factory()->create([
|
||||
'event_id' => $event->id,
|
||||
'label' => 'Admin only field',
|
||||
'slug' => 'admin-only-field',
|
||||
'is_portal_visible' => true,
|
||||
'is_admin_only' => true,
|
||||
]);
|
||||
|
||||
// Not portal visible (should be excluded)
|
||||
RegistrationFormField::factory()->create([
|
||||
'event_id' => $event->id,
|
||||
'label' => 'Hidden field',
|
||||
'slug' => 'hidden-field',
|
||||
'is_portal_visible' => false,
|
||||
'is_admin_only' => false,
|
||||
]);
|
||||
|
||||
$response = $this->getJson('/api/v1/public/events/admin-fields-event/registration-data');
|
||||
|
||||
$response->assertOk()
|
||||
->assertJsonCount(1, 'data.registration_fields')
|
||||
->assertJsonPath('data.registration_fields.0.slug', 'public-field');
|
||||
}
|
||||
|
||||
public function test_registration_data_includes_form_toggles(): void
|
||||
{
|
||||
$event = Event::factory()->create([
|
||||
'organisation_id' => $this->organisation->id,
|
||||
'status' => 'registration_open',
|
||||
'slug' => 'toggles-event',
|
||||
'registration_show_section_preferences' => true,
|
||||
'registration_show_availability' => false,
|
||||
]);
|
||||
|
||||
$response = $this->getJson('/api/v1/public/events/toggles-event/registration-data');
|
||||
|
||||
$response->assertOk()
|
||||
->assertJsonPath('data.event.registration_show_section_preferences', true)
|
||||
->assertJsonPath('data.event.registration_show_availability', false);
|
||||
}
|
||||
|
||||
public function test_registration_data_includes_available_tags_for_tag_picker(): void
|
||||
{
|
||||
$event = Event::factory()->create([
|
||||
'organisation_id' => $this->organisation->id,
|
||||
'status' => 'registration_open',
|
||||
'slug' => 'tags-event',
|
||||
]);
|
||||
|
||||
$tag = PersonTag::factory()->create([
|
||||
'organisation_id' => $this->organisation->id,
|
||||
'name' => 'EHBO',
|
||||
'category' => 'Certificaat',
|
||||
'is_active' => true,
|
||||
]);
|
||||
|
||||
PersonTag::factory()->create([
|
||||
'organisation_id' => $this->organisation->id,
|
||||
'name' => 'Barervaring',
|
||||
'category' => 'Ervaring',
|
||||
'is_active' => true,
|
||||
]);
|
||||
|
||||
RegistrationFormField::factory()->tagPickerField()->create([
|
||||
'event_id' => $event->id,
|
||||
'tag_categories' => ['Certificaat'],
|
||||
'is_portal_visible' => true,
|
||||
'is_admin_only' => false,
|
||||
]);
|
||||
|
||||
$response = $this->getJson('/api/v1/public/events/tags-event/registration-data');
|
||||
|
||||
$response->assertOk()
|
||||
->assertJsonCount(1, 'data.registration_fields')
|
||||
->assertJsonCount(1, 'data.registration_fields.0.available_tags')
|
||||
->assertJsonPath('data.registration_fields.0.available_tags.0.name', 'EHBO');
|
||||
}
|
||||
}
|
||||
@@ -195,44 +195,4 @@ class RegistrationSettingsTest extends TestCase
|
||||
->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' => 'Wachtwoord1',
|
||||
'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,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,762 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Feature\Api\V1;
|
||||
|
||||
use App\Enums\PersonStatus;
|
||||
use App\Mail\RegistrationConfirmationMail;
|
||||
use App\Models\CrowdType;
|
||||
use App\Models\Event;
|
||||
use App\Models\FestivalSection;
|
||||
use App\Models\Organisation;
|
||||
use App\Models\Person;
|
||||
use App\Models\RegistrationFormField;
|
||||
use App\Models\TimeSlot;
|
||||
use App\Models\User;
|
||||
use Database\Seeders\RoleSeeder;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
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
|
||||
{
|
||||
Mail::fake();
|
||||
|
||||
$response = $this->postJson("/api/v1/events/{$this->event->id}/volunteer-register", [
|
||||
'first_name' => 'Jan',
|
||||
'last_name' => '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
|
||||
{
|
||||
Mail::fake();
|
||||
|
||||
$response = $this->postJson("/api/v1/events/{$this->event->id}/volunteer-register", [
|
||||
'first_name' => 'Sophie',
|
||||
'last_name' => 'Bakker',
|
||||
'email' => 'sophie@voorbeeld.nl',
|
||||
|
||||
]);
|
||||
|
||||
$response->assertStatus(201);
|
||||
|
||||
$this->assertDatabaseHas('persons', [
|
||||
'email' => 'sophie@voorbeeld.nl',
|
||||
'first_name' => 'Sophie',
|
||||
'last_name' => '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", [
|
||||
'first_name' => 'Pieter',
|
||||
'last_name' => '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
|
||||
{
|
||||
Mail::fake();
|
||||
$timeSlot2 = TimeSlot::factory()->create(['event_id' => $this->event->id]);
|
||||
|
||||
$response = $this->postJson("/api/v1/events/{$this->event->id}/volunteer-register", [
|
||||
'first_name' => 'Fleur',
|
||||
'last_name' => '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
|
||||
{
|
||||
Mail::fake();
|
||||
|
||||
$response = $this->postJson("/api/v1/events/{$this->event->id}/volunteer-register", [
|
||||
'first_name' => 'Daan',
|
||||
'last_name' => 'Mulder',
|
||||
'email' => 'daan@voorbeeld.nl',
|
||||
|
||||
'tshirt_size' => 'XL',
|
||||
'motivation' => 'Ik vind festivals geweldig.',
|
||||
'section_preferences' => [
|
||||
['festival_section_id' => $this->section->id, '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->assertDatabaseHas('person_section_preferences', [
|
||||
'person_id' => $person->id,
|
||||
'festival_section_id' => $this->section->id,
|
||||
'priority' => 1,
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_volunteer_can_register_with_date_of_birth(): void
|
||||
{
|
||||
Mail::fake();
|
||||
|
||||
$response = $this->postJson("/api/v1/events/{$this->event->id}/volunteer-register", [
|
||||
'first_name' => 'Mila',
|
||||
'last_name' => 'de Boer',
|
||||
'email' => 'mila@voorbeeld.nl',
|
||||
|
||||
'date_of_birth' => '1998-05-12',
|
||||
]);
|
||||
|
||||
$response->assertStatus(201);
|
||||
|
||||
$person = Person::where('email', 'mila@voorbeeld.nl')->first();
|
||||
$this->assertEquals('1998-05-12', $person->date_of_birth->format('Y-m-d'));
|
||||
}
|
||||
|
||||
public function test_volunteer_can_register_without_date_of_birth(): void
|
||||
{
|
||||
Mail::fake();
|
||||
|
||||
$response = $this->postJson("/api/v1/events/{$this->event->id}/volunteer-register", [
|
||||
'first_name' => 'Sem',
|
||||
'last_name' => 'van Beek',
|
||||
'email' => 'sem@voorbeeld.nl',
|
||||
|
||||
]);
|
||||
|
||||
$response->assertStatus(201);
|
||||
|
||||
$person = Person::where('email', 'sem@voorbeeld.nl')->first();
|
||||
$this->assertNull($person->date_of_birth);
|
||||
}
|
||||
|
||||
public function test_date_of_birth_must_be_before_today(): void
|
||||
{
|
||||
$response = $this->postJson("/api/v1/events/{$this->event->id}/volunteer-register", [
|
||||
'first_name' => 'Tijn',
|
||||
'last_name' => 'Kuiper',
|
||||
'email' => 'tijn@voorbeeld.nl',
|
||||
|
||||
'date_of_birth' => now()->addDay()->format('Y-m-d'),
|
||||
]);
|
||||
|
||||
$response->assertStatus(422);
|
||||
$response->assertJsonValidationErrors('date_of_birth');
|
||||
}
|
||||
|
||||
public function test_duplicate_email_rejected(): void
|
||||
{
|
||||
Mail::fake();
|
||||
|
||||
$this->postJson("/api/v1/events/{$this->event->id}/volunteer-register", [
|
||||
'first_name' => 'Anna',
|
||||
'last_name' => 'Smit',
|
||||
'email' => 'anna@voorbeeld.nl',
|
||||
|
||||
]);
|
||||
|
||||
$response = $this->postJson("/api/v1/events/{$this->event->id}/volunteer-register", [
|
||||
'first_name' => 'Anna',
|
||||
'last_name' => 'Smit',
|
||||
'email' => 'anna@voorbeeld.nl',
|
||||
|
||||
]);
|
||||
|
||||
$response->assertStatus(422);
|
||||
$response->assertJsonValidationErrors('email');
|
||||
}
|
||||
|
||||
public function test_rejected_person_can_reregister(): void
|
||||
{
|
||||
Mail::fake();
|
||||
|
||||
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", [
|
||||
'first_name' => 'Herkan',
|
||||
'last_name' => '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", [
|
||||
'first_name' => 'Test',
|
||||
'last_name' => '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", [
|
||||
'first_name' => 'Bas',
|
||||
'last_name' => '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([
|
||||
'first_name' => 'Lisa',
|
||||
'last_name' => '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([
|
||||
'first_name' => 'Mark',
|
||||
'last_name' => '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([
|
||||
'first_name' => 'Eva',
|
||||
'last_name' => '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_with_empty_token_returns_422(): void
|
||||
{
|
||||
$response = $this->postJson('/api/v1/portal/token-auth', [
|
||||
'token' => '',
|
||||
]);
|
||||
|
||||
$response->assertStatus(422);
|
||||
}
|
||||
|
||||
// ─── Portal Me ──────────────────────────────────────────────────────
|
||||
|
||||
public function test_authenticated_user_gets_person(): void
|
||||
{
|
||||
$user = User::factory()->create(['first_name' => 'Karin', 'last_name' => '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(['first_name' => 'Tom', 'last_name' => '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(['first_name' => 'Sanne', 'last_name' => '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);
|
||||
}
|
||||
|
||||
// ─── Dynamic Field Values ──────────────────────────────────────────
|
||||
|
||||
public function test_volunteer_can_register_with_field_values(): void
|
||||
{
|
||||
Mail::fake();
|
||||
|
||||
$selectField = RegistrationFormField::factory()->selectField()->create([
|
||||
'event_id' => $this->event->id,
|
||||
'sort_order' => 0,
|
||||
]);
|
||||
|
||||
$textField = RegistrationFormField::factory()->textareaField()->create([
|
||||
'event_id' => $this->event->id,
|
||||
'sort_order' => 1,
|
||||
]);
|
||||
|
||||
$response = $this->postJson("/api/v1/events/{$this->event->id}/volunteer-register", [
|
||||
'first_name' => 'Noor',
|
||||
'last_name' => 'Janssen',
|
||||
'email' => 'noor@voorbeeld.nl',
|
||||
|
||||
'field_values' => [
|
||||
$selectField->slug => 'L',
|
||||
$textField->slug => 'Ik ben een ervaren vrijwilliger',
|
||||
],
|
||||
]);
|
||||
|
||||
$response->assertStatus(201);
|
||||
|
||||
$person = Person::where('email', 'noor@voorbeeld.nl')->first();
|
||||
|
||||
$this->assertDatabaseHas('person_field_values', [
|
||||
'person_id' => $person->id,
|
||||
'registration_form_field_id' => $selectField->id,
|
||||
'value' => 'L',
|
||||
]);
|
||||
|
||||
$this->assertDatabaseHas('person_field_values', [
|
||||
'person_id' => $person->id,
|
||||
'registration_form_field_id' => $textField->id,
|
||||
'value' => 'Ik ben een ervaren vrijwilliger',
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_volunteer_can_register_with_section_preferences(): void
|
||||
{
|
||||
Mail::fake();
|
||||
|
||||
$section1 = FestivalSection::factory()->create([
|
||||
'event_id' => $this->event->id,
|
||||
'name' => 'Hoofdpodium Bar',
|
||||
]);
|
||||
|
||||
$section2 = FestivalSection::factory()->create([
|
||||
'event_id' => $this->event->id,
|
||||
'name' => 'EHBO Post',
|
||||
]);
|
||||
|
||||
$response = $this->postJson("/api/v1/events/{$this->event->id}/volunteer-register", [
|
||||
'first_name' => 'Rick',
|
||||
'last_name' => 'Peters',
|
||||
'email' => 'rick@voorbeeld.nl',
|
||||
|
||||
'section_preferences' => [
|
||||
['festival_section_id' => $section1->id, 'priority' => 1],
|
||||
['festival_section_id' => $section2->id, 'priority' => 2],
|
||||
],
|
||||
]);
|
||||
|
||||
$response->assertStatus(201);
|
||||
|
||||
$person = Person::where('email', 'rick@voorbeeld.nl')->first();
|
||||
|
||||
$this->assertDatabaseHas('person_section_preferences', [
|
||||
'person_id' => $person->id,
|
||||
'festival_section_id' => $section1->id,
|
||||
'priority' => 1,
|
||||
]);
|
||||
|
||||
$this->assertDatabaseHas('person_section_preferences', [
|
||||
'person_id' => $person->id,
|
||||
'festival_section_id' => $section2->id,
|
||||
'priority' => 2,
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_volunteer_can_register_with_multiselect_field_values(): void
|
||||
{
|
||||
Mail::fake();
|
||||
|
||||
$multiselectField = RegistrationFormField::factory()->multiselectField()->create([
|
||||
'event_id' => $this->event->id,
|
||||
]);
|
||||
|
||||
$response = $this->postJson("/api/v1/events/{$this->event->id}/volunteer-register", [
|
||||
'first_name' => 'Femke',
|
||||
'last_name' => 'de Jong',
|
||||
'email' => 'femke@voorbeeld.nl',
|
||||
|
||||
'field_values' => [
|
||||
$multiselectField->slug => ['Vegetarisch', 'Glutenvrij'],
|
||||
],
|
||||
]);
|
||||
|
||||
$response->assertStatus(201);
|
||||
|
||||
$person = Person::where('email', 'femke@voorbeeld.nl')->first();
|
||||
|
||||
$this->assertDatabaseHas('person_field_values', [
|
||||
'person_id' => $person->id,
|
||||
'registration_form_field_id' => $multiselectField->id,
|
||||
]);
|
||||
|
||||
$value = $person->fieldValues()
|
||||
->where('registration_form_field_id', $multiselectField->id)
|
||||
->first();
|
||||
|
||||
$this->assertEquals(['Vegetarisch', 'Glutenvrij'], $value->selected_options);
|
||||
}
|
||||
|
||||
// ─── Passwordless Registration (account deferred to approval) ─────────
|
||||
|
||||
public function test_registration_creates_person_without_user_account(): void
|
||||
{
|
||||
Mail::fake();
|
||||
|
||||
$response = $this->postJson("/api/v1/events/{$this->event->id}/volunteer-register", [
|
||||
'first_name' => 'Nieuwe',
|
||||
'last_name' => 'Vrijwilliger',
|
||||
'email' => 'nieuw@voorbeeld.nl',
|
||||
]);
|
||||
|
||||
$response->assertStatus(201);
|
||||
|
||||
$this->assertDatabaseHas('persons', [
|
||||
'email' => 'nieuw@voorbeeld.nl',
|
||||
'event_id' => $this->event->id,
|
||||
'user_id' => null,
|
||||
'registration_source' => 'self',
|
||||
]);
|
||||
|
||||
// No user account should be created at registration time
|
||||
$this->assertDatabaseMissing('users', [
|
||||
'email' => 'nieuw@voorbeeld.nl',
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_registration_without_password_succeeds(): void
|
||||
{
|
||||
Mail::fake();
|
||||
|
||||
$response = $this->postJson("/api/v1/events/{$this->event->id}/volunteer-register", [
|
||||
'first_name' => 'Zonder',
|
||||
'last_name' => 'Wachtwoord',
|
||||
'email' => 'geenww@voorbeeld.nl',
|
||||
]);
|
||||
|
||||
$response->assertStatus(201);
|
||||
|
||||
$this->assertDatabaseHas('persons', [
|
||||
'email' => 'geenww@voorbeeld.nl',
|
||||
'user_id' => null,
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_registration_sends_confirmation_email(): void
|
||||
{
|
||||
Mail::fake();
|
||||
|
||||
$this->postJson("/api/v1/events/{$this->event->id}/volunteer-register", [
|
||||
'first_name' => 'Mail',
|
||||
'last_name' => 'Test',
|
||||
'email' => 'mailtest@voorbeeld.nl',
|
||||
]);
|
||||
|
||||
Mail::assertQueued(RegistrationConfirmationMail::class, function ($mail) {
|
||||
return $mail->hasTo('mailtest@voorbeeld.nl');
|
||||
});
|
||||
}
|
||||
|
||||
public function test_email_is_always_stored_lowercase(): void
|
||||
{
|
||||
Mail::fake();
|
||||
|
||||
$response = $this->postJson("/api/v1/events/{$this->event->id}/volunteer-register", [
|
||||
'first_name' => 'Hoofdletter',
|
||||
'last_name' => 'Email',
|
||||
'email' => 'HOOFDLETTER@VOORBEELD.NL',
|
||||
]);
|
||||
|
||||
$response->assertStatus(201);
|
||||
|
||||
$this->assertDatabaseHas('persons', [
|
||||
'email' => 'hoofdletter@voorbeeld.nl',
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_password_not_required_for_authenticated_registration(): void
|
||||
{
|
||||
Mail::fake();
|
||||
|
||||
$user = User::factory()->create([
|
||||
'first_name' => 'Auth',
|
||||
'last_name' => 'User',
|
||||
'email' => 'authuser@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);
|
||||
}
|
||||
|
||||
// ─── Registration Data Endpoint ─────────────────────────────────────
|
||||
|
||||
public function test_registration_data_includes_registration_fields(): void
|
||||
{
|
||||
$field = RegistrationFormField::factory()->selectField()->create([
|
||||
'event_id' => $this->event->id,
|
||||
'is_portal_visible' => true,
|
||||
'is_admin_only' => false,
|
||||
]);
|
||||
|
||||
$response = $this->getJson("/api/v1/public/events/{$this->event->slug}/registration-data");
|
||||
|
||||
$response->assertOk();
|
||||
$response->assertJsonPath('data.registration_fields.0.slug', $field->slug);
|
||||
}
|
||||
|
||||
public function test_registration_data_excludes_admin_only_fields(): void
|
||||
{
|
||||
RegistrationFormField::factory()->selectField()->create([
|
||||
'event_id' => $this->event->id,
|
||||
'is_portal_visible' => true,
|
||||
'is_admin_only' => true,
|
||||
]);
|
||||
|
||||
$response = $this->getJson("/api/v1/public/events/{$this->event->slug}/registration-data");
|
||||
|
||||
$response->assertOk();
|
||||
$response->assertJsonCount(0, 'data.registration_fields');
|
||||
}
|
||||
|
||||
public function test_registration_data_includes_form_toggles(): void
|
||||
{
|
||||
$response = $this->getJson("/api/v1/public/events/{$this->event->slug}/registration-data");
|
||||
|
||||
$response->assertOk();
|
||||
$response->assertJsonStructure([
|
||||
'data' => [
|
||||
'event' => [
|
||||
'registration_show_section_preferences',
|
||||
'registration_show_availability',
|
||||
],
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_portal_me_includes_field_values_and_section_preferences(): void
|
||||
{
|
||||
$user = User::factory()->create(['first_name' => 'Lotte', 'last_name' => 'Vos']);
|
||||
$this->organisation->users()->attach($user, ['role' => 'org_member']);
|
||||
|
||||
$person = Person::factory()->create([
|
||||
'event_id' => $this->event->id,
|
||||
'crowd_type_id' => $this->volunteerCrowdType->id,
|
||||
'user_id' => $user->id,
|
||||
'email' => $user->email,
|
||||
]);
|
||||
|
||||
$field = RegistrationFormField::factory()->selectField()->create([
|
||||
'event_id' => $this->event->id,
|
||||
]);
|
||||
|
||||
\App\Models\PersonFieldValue::create([
|
||||
'person_id' => $person->id,
|
||||
'registration_form_field_id' => $field->id,
|
||||
'value' => 'M',
|
||||
]);
|
||||
|
||||
\App\Models\PersonSectionPreference::create([
|
||||
'person_id' => $person->id,
|
||||
'festival_section_id' => $this->section->id,
|
||||
'priority' => 1,
|
||||
]);
|
||||
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
$response = $this->getJson("/api/v1/portal/me?event_id={$this->event->id}");
|
||||
|
||||
$response->assertStatus(200)
|
||||
->assertJsonCount(1, 'data.field_values')
|
||||
->assertJsonPath('data.field_values.0.field_slug', $field->slug)
|
||||
->assertJsonPath('data.field_values.0.value', 'M')
|
||||
->assertJsonCount(1, 'data.section_preferences')
|
||||
->assertJsonPath('data.section_preferences.0.festival_section_id', $this->section->id)
|
||||
->assertJsonPath('data.section_preferences.0.priority', 1);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user