Fixed bug selecting eating habits

This commit is contained in:
2026-10-04 14:36:15 +02:00
parent bcebe2ebed
commit 9e9ea0cfd5
7 changed files with 142 additions and 12 deletions
@@ -37,11 +37,7 @@ class SignUpCommand {
return $response; return $response;
} }
$eatingHabit = match ($this->request->eating_habit) { $eatingHabit = $this->resolveEatingHabit();
'vegan' => EatingHabit::EATING_HABIT_VEGAN,
'vegetarian' => EatingHabit::EATING_HABIT_VEGETARIAN,
default => EatingHabit::EATING_HABIT_OMNIVOR,
};
$participantAge = new Age($this->request->birthday); $participantAge = new Age($this->request->birthday);
@@ -111,6 +107,21 @@ class SignUpCommand {
return $response; return $response;
} }
/**
* Ernährungsweise auflösen. Übernommen wird nur ein Slug, den die Veranstaltung anbietet; ohne Angabe (z. B. bei
* der Kurzanmeldung) oder bei einem nicht angebotenen Wert gilt "Omnivor".
*/
private function resolveEatingHabit(): string
{
$slug = $this->request->eating_habit;
if ($slug !== '' && $this->request->event->eatingHabits()->where('slug', $slug)->exists()) {
return $slug;
}
return EatingHabit::EATING_HABIT_OMNIVOR;
}
/** /**
* Badeerlaubnis auflösen. Volljährige brauchen keine Erlaubnis. Für Minderjährige gilt die getroffene Auswahl; * Badeerlaubnis auflösen. Volljährige brauchen keine Erlaubnis. Für Minderjährige gilt die getroffene Auswahl;
* fehlt sie -- weil die Veranstaltung die Badeerlaubnis gar nicht abfragt oder keine Wahl getroffen wurde --, * fehlt sie -- weil die Veranstaltung die Badeerlaubnis gar nicht abfragt oder keine Wahl getroffen wurde --,
@@ -143,7 +143,7 @@ class SignupController extends CommonController {
$registrationData['intolerances'], $registrationData['intolerances'],
$registrationData['medikamente'], $registrationData['medikamente'],
$tetanusVaccination, $tetanusVaccination,
$registrationData['essgewohnheit'], $registrationData['eatingHabit'] ?? '',
$registrationData['badeerlaubnis'], $registrationData['badeerlaubnis'],
$registrationData['first_aid'], $registrationData['first_aid'],
$registrationData['foto']['socialmedia'], $registrationData['foto']['socialmedia'],
@@ -13,8 +13,13 @@ export function useSignupForm(event, participantData) {
// Für die Aktion freigeschaltete Zahlungsmethoden; ist genau eine aktiv, wird sie vorausgewählt. // Für die Aktion freigeschaltete Zahlungsmethoden; ist genau eine aktiv, wird sie vorausgewählt.
const activeMethods = (event.paymentMethods ?? []).filter(m => m.active) const activeMethods = (event.paymentMethods ?? []).filter(m => m.active)
// Vorbelegung mit der Ernährungsweise aus dem Profil, sofern die Veranstaltung sie anbietet, sonst die erste Option.
const eatingHabitSlugs = (event.eatingHabits ?? []).map(h => h.data.slug)
const formData = reactive({ const formData = reactive({
eatingHabit: 'EATING_HABIT_VEGAN', eatingHabit: eatingHabitSlugs.includes(participantData.eating_habit)
? participantData.eating_habit
: (eatingHabitSlugs[0] ?? ''),
paymentMethod: activeMethods.length === 1 ? activeMethods[0].slug : null, paymentMethod: activeMethods.length === 1 ? activeMethods[0].slug : null,
paymentOptions: {}, paymentOptions: {},
// Antworten auf die event-spezifischen Teilnahmeoptionen: { [question.key]: option.value } // Antworten auf die event-spezifischen Teilnahmeoptionen: { [question.key]: option.value }
@@ -53,7 +58,6 @@ export function useSignupForm(event, participantData) {
intolerances: participantData.intolerances ?? '', intolerances: participantData.intolerances ?? '',
medikamente: participantData.medications ?? '', medikamente: participantData.medications ?? '',
tetanusVaccination: participantData.tetanusVaccination ?? '', tetanusVaccination: participantData.tetanusVaccination ?? '',
essgewohnheit: 'vegetarian',
anmerkungen: '', anmerkungen: '',
summary_information_correct: false, summary_information_correct: false,
summary_accept_terms: false, summary_accept_terms: false,
+2 -1
View File
@@ -40,6 +40,7 @@ class InvoiceNumberingTest extends TestCase
DB::table('participation_fee_types')->insert(['slug' => 'fixed', 'name' => 'Fix']); DB::table('participation_fee_types')->insert(['slug' => 'fixed', 'name' => 'Fix']);
EatingHabit::create(['slug' => EatingHabit::EATING_HABIT_VEGAN, 'name' => 'Vegan']); EatingHabit::create(['slug' => EatingHabit::EATING_HABIT_VEGAN, 'name' => 'Vegan']);
EatingHabit::create(['slug' => EatingHabit::EATING_HABIT_VEGETARIAN, 'name' => 'Vegetarisch']); EatingHabit::create(['slug' => EatingHabit::EATING_HABIT_VEGETARIAN, 'name' => 'Vegetarisch']);
EatingHabit::create(['slug' => EatingHabit::EATING_HABIT_OMNIVOR, 'name' => 'Omnivor']);
ParticipationType::create(['slug' => ParticipationType::PARTICIPATION_TYPE_PARTICIPANT, 'name' => 'Teilnehmende']); ParticipationType::create(['slug' => ParticipationType::PARTICIPATION_TYPE_PARTICIPANT, 'name' => 'Teilnehmende']);
PaymentMethod::create(['slug' => PaymentMethod::PAYMENT_ACCOUNT_TRANSACTION]); PaymentMethod::create(['slug' => PaymentMethod::PAYMENT_ACCOUNT_TRANSACTION]);
EfzStatus::create(['slug' => EfzStatus::EFZ_STATUS_NOT_CHECKED, 'name' => 'Nicht geprüft']); EfzStatus::create(['slug' => EfzStatus::EFZ_STATUS_NOT_CHECKED, 'name' => 'Nicht geprüft']);
@@ -167,7 +168,7 @@ class InvoiceNumberingTest extends TestCase
$event, null, $firstname, 'Muster', null, ParticipationType::PARTICIPATION_TYPE_PARTICIPANT, $event, null, $firstname, 'Muster', null, ParticipationType::PARTICIPATION_TYPE_PARTICIPANT,
$this->wildeMoehre, new DateTime('2000-01-01'), 'Weg 1', null, '00000', 'Stadt', $this->wildeMoehre, new DateTime('2000-01-01'), 'Weg 1', null, '00000', 'Stadt',
strtolower($firstname) . '@example.com', '123', null, null, null, null, null, null, null, strtolower($firstname) . '@example.com', '123', null, null, null, null, null, null, null,
'vegan', null, null, false, false, false, false, false, '', null, null, false, false, false, false, false,
new DateTime('2026-07-16'), new DateTime('2026-07-16'), 0, 0, null, new DateTime('2026-07-16'), new DateTime('2026-07-16'), 0, 0, null,
new Amount(50.0, 'Euro'), PaymentMethod::PAYMENT_ACCOUNT_TRANSACTION, new Amount(50.0, 'Euro'), PaymentMethod::PAYMENT_ACCOUNT_TRANSACTION,
))->execute(); ))->execute();
+111
View File
@@ -0,0 +1,111 @@
<?php
namespace Tests\Feature;
use App\Domains\Event\Actions\SignUp\SignUpCommand;
use App\Domains\Event\Actions\SignUp\SignUpRequest;
use App\Enumerations\EatingHabit;
use App\Enumerations\EfzStatus;
use App\Enumerations\FirstAidPermission;
use App\Enumerations\ParticipationType;
use App\Enumerations\SwimmingPermission;
use App\Models\Event;
use App\Models\PaymentMethod;
use App\Models\Tenant;
use App\ValueObjects\Amount;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\DB;
use Tests\TestCase;
/**
* Die bei der Anmeldung gewählte Ernährungsweise muss gespeichert werden -- früher landete immer "Vegetarisch",
* weil der Controller ein verwaistes Formularfeld las.
*/
class SignUpEatingHabitTest extends TestCase
{
use RefreshDatabase;
private Tenant $tenant;
protected function setUp(): void
{
parent::setUp();
$this->tenant = Tenant::create([
'slug' => 'tv', 'name' => 'Test', 'email' => 't@example.com', 'email_finance' => 'f@example.com',
'url' => 'test.local', 'account_name' => 'Test e.V.', 'account_iban' => 'DE00', 'account_bic' => 'XY',
'city' => 'Stadt', 'postcode' => '00000', 'is_active_local_group' => true, 'has_active_instance' => true,
]);
app()->instance('tenant', $this->tenant);
PaymentMethod::create(['slug' => PaymentMethod::PAYMENT_ACCOUNT_TRANSACTION]);
DB::table('participation_fee_types')->insert(['slug' => 'FIXED', 'name' => 'Fixed', 'created_at' => now(), 'updated_at' => now()]);
ParticipationType::create(['slug' => ParticipationType::PARTICIPATION_TYPE_PARTICIPANT, 'name' => 'Teilnehmende']);
EfzStatus::create(['slug' => EfzStatus::EFZ_STATUS_NOT_CHECKED, 'name' => 'Nicht geprüft']);
EfzStatus::create(['slug' => EfzStatus::EFZ_STATUS_NOT_REQUIRED, 'name' => 'Nicht erforderlich']);
SwimmingPermission::create(['slug' => SwimmingPermission::SWIMMING_PERMISSION_ALLOWED, 'name' => 'Darf baden', 'short' => 'Erteilt']);
FirstAidPermission::create(['slug' => FirstAidPermission::FIRST_AID_PERMISSION_ALLOWED, 'name' => 'Zugestimmt', 'description' => '']);
EatingHabit::create(['slug' => EatingHabit::EATING_HABIT_VEGAN, 'name' => 'Vegan']);
EatingHabit::create(['slug' => EatingHabit::EATING_HABIT_VEGETARIAN, 'name' => 'Vegetarisch']);
EatingHabit::create(['slug' => EatingHabit::EATING_HABIT_OMNIVOR, 'name' => 'Omnivor']);
}
private function createEvent(array $eatingHabitSlugs): Event
{
$event = Event::create([
'tenant' => $this->tenant->slug, 'name' => 'Event', 'identifier' => 'evt-1', 'location' => 'Ort',
'postal_code' => '00000', 'email' => 'e@example.com', 'start_date' => '2026-08-01', 'end_date' => '2026-08-05',
'early_bird_end' => '2026-07-01', 'registration_final_end' => '2026-07-20', 'early_bird_end_amount_increase' => 0,
'account_owner' => 'Owner', 'account_iban' => 'DE00', 'participation_fee_type' => 'FIXED',
'pay_per_day' => false, 'pay_direct' => false,
]);
$event->eatingHabits()->attach(EatingHabit::whereIn('slug', $eatingHabitSlugs)->pluck('id')->all());
return $event;
}
private function signUp(Event $event, string $eatingHabit): string
{
$request = new SignUpRequest(
$event, null, 'Hans', 'Muster', null, ParticipationType::PARTICIPATION_TYPE_PARTICIPANT,
$this->tenant, new \DateTime('2000-01-01'), 'Weg 1', null, '00000', 'Stadt',
'h@example.com', '123', null, null, null, null, null, null, null,
$eatingHabit, null, null, false, false, false, false, false,
new \DateTime('2026-08-01'), new \DateTime('2026-08-05'), 0, 0, null,
new Amount(50.0, ' Euro'), PaymentMethod::PAYMENT_ACCOUNT_TRANSACTION, [],
);
$response = new SignUpCommand($request)->execute();
$this->assertTrue($response->success);
return $response->participant->fresh()->eating_habit;
}
public function test_chosen_vegan_is_stored(): void
{
$event = $this->createEvent([EatingHabit::EATING_HABIT_VEGAN, EatingHabit::EATING_HABIT_VEGETARIAN]);
$this->assertSame(EatingHabit::EATING_HABIT_VEGAN, $this->signUp($event, EatingHabit::EATING_HABIT_VEGAN));
}
public function test_chosen_vegetarian_is_stored(): void
{
$event = $this->createEvent([EatingHabit::EATING_HABIT_VEGAN, EatingHabit::EATING_HABIT_VEGETARIAN]);
$this->assertSame(EatingHabit::EATING_HABIT_VEGETARIAN, $this->signUp($event, EatingHabit::EATING_HABIT_VEGETARIAN));
}
public function test_habit_not_offered_by_event_falls_back_to_omnivor(): void
{
$event = $this->createEvent([EatingHabit::EATING_HABIT_VEGETARIAN]);
$this->assertSame(EatingHabit::EATING_HABIT_OMNIVOR, $this->signUp($event, EatingHabit::EATING_HABIT_VEGAN));
}
public function test_empty_habit_falls_back_to_omnivor(): void
{
$event = $this->createEvent([EatingHabit::EATING_HABIT_VEGAN]);
$this->assertSame(EatingHabit::EATING_HABIT_OMNIVOR, $this->signUp($event, ''));
}
}
+5 -2
View File
@@ -48,13 +48,16 @@ class SignUpPaymentOptionsTest extends TestCase
private function createEvent(): Event private function createEvent(): Event
{ {
return Event::create([ $event = Event::create([
'tenant' => $this->tenant->slug, 'name' => 'Event', 'identifier' => 'evt-1', 'location' => 'Ort', 'tenant' => $this->tenant->slug, 'name' => 'Event', 'identifier' => 'evt-1', 'location' => 'Ort',
'postal_code' => '00000', 'email' => 'e@example.com', 'start_date' => '2026-08-01', 'end_date' => '2026-08-05', 'postal_code' => '00000', 'email' => 'e@example.com', 'start_date' => '2026-08-01', 'end_date' => '2026-08-05',
'early_bird_end' => '2026-07-01', 'registration_final_end' => '2026-07-20', 'early_bird_end_amount_increase' => 0, 'early_bird_end' => '2026-07-01', 'registration_final_end' => '2026-07-20', 'early_bird_end_amount_increase' => 0,
'account_owner' => 'Owner', 'account_iban' => 'DE00', 'participation_fee_type' => 'FIXED', 'account_owner' => 'Owner', 'account_iban' => 'DE00', 'participation_fee_type' => 'FIXED',
'pay_per_day' => false, 'pay_direct' => false, 'pay_per_day' => false, 'pay_direct' => false,
]); ]);
$event->eatingHabits()->attach(EatingHabit::where('slug', EatingHabit::EATING_HABIT_VEGAN)->first()->id);
return $event;
} }
private function signUpRequest(Event $event, array $paymentOptions): SignUpRequest private function signUpRequest(Event $event, array $paymentOptions): SignUpRequest
@@ -63,7 +66,7 @@ class SignUpPaymentOptionsTest extends TestCase
$event, null, 'Hans', 'Muster', null, ParticipationType::PARTICIPATION_TYPE_PARTICIPANT, $event, null, 'Hans', 'Muster', null, ParticipationType::PARTICIPATION_TYPE_PARTICIPANT,
$this->tenant, new \DateTime('2000-01-01'), 'Weg 1', null, '00000', 'Stadt', $this->tenant, new \DateTime('2000-01-01'), 'Weg 1', null, '00000', 'Stadt',
'h@example.com', '123', null, null, null, null, null, null, null, 'h@example.com', '123', null, null, null, null, null, null, null,
'vegan', null, null, false, false, false, false, false, EatingHabit::EATING_HABIT_VEGAN, null, null, false, false, false, false, false,
new \DateTime('2026-08-01'), new \DateTime('2026-08-05'), 0, 0, null, new \DateTime('2026-08-01'), new \DateTime('2026-08-05'), 0, 0, null,
new Amount(50.0, ' Euro'), PaymentMethod::PAYMENT_ACCOUNT_TRANSACTION, $paymentOptions, new Amount(50.0, ' Euro'), PaymentMethod::PAYMENT_ACCOUNT_TRANSACTION, $paymentOptions,
); );
+1 -1
View File
@@ -1 +1 @@
4.10.2 4.10.3