feat: registration form fields, section preferences, tag sync & schema updates
Implement EAV system for dynamic event-specific registration fields with organisation-level templates, person section preferences with priority ranking, and TagSyncService for deferred tag_picker sync. New tables: registration_field_templates, registration_form_fields, person_field_values, person_section_preferences. New columns: persons.remarks, events.registration_show_section_preferences, events.registration_show_availability. 58 tests, 126 assertions — all 432 tests pass (zero regressions). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,202 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Feature\RegistrationFieldTemplate;
|
||||
|
||||
use App\Models\Event;
|
||||
use App\Models\Organisation;
|
||||
use App\Models\RegistrationFieldTemplate;
|
||||
use App\Models\RegistrationFormField;
|
||||
use App\Models\User;
|
||||
use App\Services\RegistrationFieldTemplateService;
|
||||
use Database\Seeders\RoleSeeder;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Laravel\Sanctum\Sanctum;
|
||||
use Tests\TestCase;
|
||||
|
||||
class RegistrationFieldTemplateTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
private User $orgAdmin;
|
||||
private User $outsider;
|
||||
private Organisation $organisation;
|
||||
private Organisation $otherOrganisation;
|
||||
|
||||
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']);
|
||||
}
|
||||
|
||||
public function test_index_returns_active_templates(): void
|
||||
{
|
||||
RegistrationFieldTemplate::factory()->count(3)->create([
|
||||
'organisation_id' => $this->organisation->id,
|
||||
]);
|
||||
RegistrationFieldTemplate::factory()->inactive()->create([
|
||||
'organisation_id' => $this->organisation->id,
|
||||
]);
|
||||
|
||||
Sanctum::actingAs($this->orgAdmin);
|
||||
|
||||
$response = $this->getJson("/api/v1/organisations/{$this->organisation->id}/registration-field-templates");
|
||||
|
||||
$response->assertOk();
|
||||
$this->assertCount(3, $response->json('data'));
|
||||
}
|
||||
|
||||
public function test_store_creates_template(): void
|
||||
{
|
||||
Sanctum::actingAs($this->orgAdmin);
|
||||
|
||||
$response = $this->postJson("/api/v1/organisations/{$this->organisation->id}/registration-field-templates", [
|
||||
'label' => 'Allergieën',
|
||||
'field_type' => 'text',
|
||||
]);
|
||||
|
||||
$response->assertCreated();
|
||||
|
||||
$this->assertDatabaseHas('registration_field_templates', [
|
||||
'organisation_id' => $this->organisation->id,
|
||||
'label' => 'Allergieën',
|
||||
'slug' => 'allergieen',
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_store_select_requires_options(): void
|
||||
{
|
||||
Sanctum::actingAs($this->orgAdmin);
|
||||
|
||||
$response = $this->postJson("/api/v1/organisations/{$this->organisation->id}/registration-field-templates", [
|
||||
'label' => 'Voorkeur',
|
||||
'field_type' => 'select',
|
||||
]);
|
||||
|
||||
$response->assertUnprocessable()
|
||||
->assertJsonValidationErrors('options');
|
||||
}
|
||||
|
||||
public function test_update_template(): void
|
||||
{
|
||||
$template = RegistrationFieldTemplate::factory()->create([
|
||||
'organisation_id' => $this->organisation->id,
|
||||
'label' => 'Oude label',
|
||||
'slug' => 'oude-label',
|
||||
]);
|
||||
|
||||
Sanctum::actingAs($this->orgAdmin);
|
||||
|
||||
$response = $this->putJson("/api/v1/organisations/{$this->organisation->id}/registration-field-templates/{$template->id}", [
|
||||
'label' => 'Nieuwe label',
|
||||
]);
|
||||
|
||||
$response->assertOk();
|
||||
|
||||
$this->assertDatabaseHas('registration_field_templates', [
|
||||
'id' => $template->id,
|
||||
'label' => 'Nieuwe label',
|
||||
'slug' => 'nieuwe-label',
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_destroy_org_template_deletes(): void
|
||||
{
|
||||
$template = RegistrationFieldTemplate::factory()->create([
|
||||
'organisation_id' => $this->organisation->id,
|
||||
'is_system' => false,
|
||||
]);
|
||||
|
||||
Sanctum::actingAs($this->orgAdmin);
|
||||
|
||||
$response = $this->deleteJson("/api/v1/organisations/{$this->organisation->id}/registration-field-templates/{$template->id}");
|
||||
|
||||
$response->assertNoContent();
|
||||
$this->assertDatabaseMissing('registration_field_templates', [
|
||||
'id' => $template->id,
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_destroy_system_template_deactivates(): void
|
||||
{
|
||||
$template = RegistrationFieldTemplate::factory()->system()->create([
|
||||
'organisation_id' => $this->organisation->id,
|
||||
]);
|
||||
|
||||
Sanctum::actingAs($this->orgAdmin);
|
||||
|
||||
$response = $this->deleteJson("/api/v1/organisations/{$this->organisation->id}/registration-field-templates/{$template->id}");
|
||||
|
||||
$response->assertNoContent();
|
||||
$this->assertDatabaseHas('registration_field_templates', [
|
||||
'id' => $template->id,
|
||||
'is_active' => false,
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_system_templates_seeded_on_org_creation(): void
|
||||
{
|
||||
RegistrationFieldTemplateService::seedSystemTemplates($this->organisation);
|
||||
|
||||
$count = RegistrationFieldTemplate::where('organisation_id', $this->organisation->id)
|
||||
->where('is_system', true)
|
||||
->count();
|
||||
|
||||
$this->assertEquals(11, $count);
|
||||
}
|
||||
|
||||
public function test_create_field_from_template(): void
|
||||
{
|
||||
$template = RegistrationFieldTemplate::factory()->create([
|
||||
'organisation_id' => $this->organisation->id,
|
||||
'label' => 'Shirtmaat',
|
||||
'slug' => 'shirtmaat',
|
||||
'field_type' => 'select',
|
||||
'options' => ['XS', 'S', 'M', 'L', 'XL'],
|
||||
]);
|
||||
|
||||
$event = Event::factory()->create([
|
||||
'organisation_id' => $this->organisation->id,
|
||||
]);
|
||||
|
||||
Sanctum::actingAs($this->orgAdmin);
|
||||
|
||||
$response = $this->postJson("/api/v1/events/{$event->id}/registration-fields/from-template", [
|
||||
'template_id' => $template->id,
|
||||
]);
|
||||
|
||||
$response->assertCreated();
|
||||
|
||||
$this->assertDatabaseHas('registration_form_fields', [
|
||||
'event_id' => $event->id,
|
||||
'label' => 'Shirtmaat',
|
||||
'field_type' => 'select',
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_cross_org_returns_403(): void
|
||||
{
|
||||
Sanctum::actingAs($this->outsider);
|
||||
|
||||
$response = $this->getJson("/api/v1/organisations/{$this->organisation->id}/registration-field-templates");
|
||||
|
||||
$response->assertForbidden();
|
||||
}
|
||||
|
||||
public function test_unauthenticated_returns_401(): void
|
||||
{
|
||||
$response = $this->getJson("/api/v1/organisations/{$this->organisation->id}/registration-field-templates");
|
||||
|
||||
$response->assertUnauthorized();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user