create(['registration_enabled' => true, 'capacity' => 2, 'waitlist' => true, 'starts_at' => now()->addWeek(), ...$attributes]); } public function test_capacity_waitlist_and_moving_up(): void { Notification::fake(); $event = $this->event(); [$a, $b, $c, $d] = User::factory()->count(4)->create()->all(); $this->actingAs($a)->post("/termine/{$event->id}/anmeldung", ['note' => 'vegetarisch'])->assertRedirect()->assertSessionHas('status', 'Sie sind angemeldet.'); $this->actingAs($b)->post("/termine/{$event->id}/anmeldung"); $this->actingAs($c)->post("/termine/{$event->id}/anmeldung")->assertSessionHas('status', 'Der Termin ist ausgebucht – Sie stehen auf der Warteliste.'); $this->actingAs($d)->post("/termine/{$event->id}/anmeldung"); $this->actingAs($d)->get("/termine/{$event->id}")->assertInertia(fn (Assert $page) => $page ->where('registration.status', 'waitlist')->where('registration.position', 2) ->where('registration.free', 0)->where('registration.waiting', 2)->where('participants', null)); $this->actingAs($a)->delete("/termine/{$event->id}/anmeldung")->assertRedirect(); $this->assertSame(EventRegistration::CONFIRMED, EventRegistration::query()->where('user_id', $c->id)->value('status')); Notification::assertSentTo($c, PortalNotification::class, fn ($n) => str_contains($n->title, 'nachgerückt')); Notification::assertNotSentTo($d, PortalNotification::class); } public function test_without_waitlist_a_full_event_rejects(): void { $event = $this->event(['capacity' => 1, 'waitlist' => false]); [$a, $b] = User::factory()->count(2)->create()->all(); $this->actingAs($a)->post("/termine/{$event->id}/anmeldung"); $this->actingAs($b)->post("/termine/{$event->id}/anmeldung")->assertSessionHasErrors(['registration' => 'Der Termin ist leider ausgebucht.']); } public function test_deadline_and_disabled_registration(): void { $user = User::factory()->create(); $closed = $this->event(['registration_deadline' => now()->subHour()]); $none = $this->event(['registration_enabled' => false]); $this->actingAs($user)->post("/termine/{$closed->id}/anmeldung")->assertSessionHasErrors('registration'); $this->actingAs($user)->post("/termine/{$none->id}/anmeldung")->assertSessionHasErrors('registration'); $this->assertSame(0, EventRegistration::query()->count()); } public function test_managers_see_the_list_export_and_raising_capacity_moves_people_up(): void { Notification::fake(); $admin = User::factory()->admin()->create(); $event = $this->event(['capacity' => 1]); [$a, $b] = User::factory()->count(2)->create()->all(); $this->actingAs($a)->post("/termine/{$event->id}/anmeldung", ['note' => '=HYPERLINK("x")']); $this->actingAs($b)->post("/termine/{$event->id}/anmeldung"); $this->actingAs($admin)->get("/termine/{$event->id}")->assertInertia(fn (Assert $page) => $page->has('participants', 2)->where('participants.1.status', 'waitlist')); $csv = $this->actingAs($admin)->get("/termine/{$event->id}/teilnehmende.csv")->assertOk()->streamedContent(); $this->assertStringContainsString("'=HYPERLINK", $csv); $this->actingAs($a)->get("/termine/{$event->id}/teilnehmende.csv")->assertForbidden(); $this->actingAs($admin)->put("/redaktion/termine/{$event->id}", [ 'title' => $event->title, 'starts_at' => $event->starts_at->format('Y-m-d\TH:i'), 'registration_enabled' => true, 'capacity' => 2, 'waitlist' => true, ])->assertSessionHasNoErrors(); $this->assertSame(2, EventRegistration::query()->where('status', EventRegistration::CONFIRMED)->count()); Notification::assertSentTo($b, PortalNotification::class); } public function test_public_participant_list_only_for_registered_people(): void { $event = $this->event(['participants_public' => true]); [$a, $b] = User::factory()->count(2)->create()->all(); $this->actingAs($a)->post("/termine/{$event->id}/anmeldung", ['note' => 'geheim']); $this->actingAs($b)->get("/termine/{$event->id}")->assertInertia(fn (Assert $page) => $page->where('participants', null)); $this->actingAs($a)->get("/termine/{$event->id}")->assertInertia(fn (Assert $page) => $page ->has('participants', 1)->where('participants.0.name', $a->name)->missing('participants.0.note')); } public function test_registration_via_api(): void { $user = User::factory()->create(); $event = $this->event(); $headers = ['Authorization' => 'Bearer '.$user->createToken('App')->plainTextToken]; $this->postJson("/api/v1/events/{$event->id}/registration", [], $headers)->assertOk()->assertJsonPath('data.status', 'confirmed'); $this->getJson("/api/v1/events/{$event->id}", $headers)->assertJsonPath('data.registration.status', 'confirmed'); $this->getJson('/api/v1/events', $headers)->assertJsonPath('data.0.registration.status', 'confirmed')->assertJsonPath('data.0.registration.enabled', true); $this->deleteJson("/api/v1/events/{$event->id}/registration", [], $headers)->assertOk()->assertJsonPath('data.status', null); } }