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
+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, ''));
}
}