create(['name' => 'Personalabteilung']); $role->grants()->create(['ability' => 'gemeinsam.manage']); $this->hr = User::factory()->withRoles([$role])->create(); } protected function tearDown(): void { Carbon::setTestNow(); parent::tearDown(); } public function test_hr_maintains_all_sections_and_everyone_sees_the_month(): void { $new = User::factory()->create(['first_name' => 'Nora', 'last_name' => 'Neu', 'department' => 'Pflege', 'location' => 'Hamburg']); $this->actingAs($this->hr); $this->post('/gemeinsam/eintraege', ['section' => 'welcome', 'user_id' => $new->id, 'date' => '2026-10-01'])->assertSessionHasNoErrors(); $this->post('/gemeinsam/eintraege', ['section' => 'transfer', 'name' => 'Tim Wechsel', 'from' => 'Werkstatt Nord', 'to' => 'Verwaltung', 'date' => '2026-10-15'])->assertSessionHasNoErrors(); $this->post('/gemeinsam/eintraege', ['section' => 'jubilee', 'name' => 'Jutta Jubel', 'label' => '25 Jahre', 'date' => '2026-10-20'])->assertSessionHasNoErrors(); $this->post('/gemeinsam/eintraege', ['section' => 'farewell', 'name' => 'Rolf Ruhestand', 'label' => 'Ruhestand', 'date' => '2026-10-31'])->assertSessionHasNoErrors(); $this->post('/gemeinsam/eintraege', ['section' => 'memoriam', 'name' => 'Gerda Gedenk', 'born_on' => '1958-03-12', 'date' => '2026-09-28', 'text' => 'Wir werden sie vermissen.'])->assertSessionHasNoErrors(); $this->post('/gemeinsam/eintraege', ['section' => 'welcome', 'date' => '2026-10-01'])->assertSessionHasErrors('name'); $this->actingAs(User::factory()->create())->get('/gemeinsam')->assertOk()->assertInertia(fn (Assert $p) => $p ->component('gemeinsam::Index') ->where('month', '2026-10') ->where('canManage', false) ->where('sections.0.key', 'welcome') ->where('sections.0.entries.0.name', 'Nora Neu') ->where('sections.0.entries.0.department', 'Pflege', 'aus dem Profil') ->where('sections.1.entries.0.to', 'Verwaltung') ->where('sections.3.entries.0.label', '25 Jahre') ->where('sections.5.entries', [])); // Gedenken im September $this->get('/gemeinsam?monat=2026-09')->assertInertia(fn (Assert $p) => $p ->where('sections.5.entries.0.name', 'Gerda Gedenk') ->where('sections.5.entries.0.born_on', '1958-03-12')); } public function test_birthdays_come_from_the_birthday_plugin(): void { $anna = User::factory()->create(['first_name' => 'Anna', 'last_name' => 'Oktober']); Birthday::query()->create(['user_id' => $anna->id, 'month' => 10, 'day' => 14]); Birthday::query()->create(['user_id' => User::factory()->inactive()->create()->id, 'month' => 10, 'day' => 2]); Birthday::query()->create(['user_id' => User::factory()->create()->id, 'month' => 11, 'day' => 2]); $this->actingAs(User::factory()->create())->get('/gemeinsam')->assertInertia(fn (Assert $p) => $p ->where('sections.2.key', 'birthdays') ->where('sections.2.automatic', true) ->has('sections.2.entries', 1) ->where('sections.2.entries.0.name', 'Anna Oktober') ->where('sections.2.entries.0.date', '2026-10-14')); } public function test_only_hr_can_change_entries(): void { $entry = Entry::query()->create(['section' => 'welcome', 'name' => 'X', 'date' => '2026-10-01']); $this->actingAs(User::factory()->create()); $this->post('/gemeinsam/eintraege', ['section' => 'welcome', 'name' => 'Y', 'date' => '2026-10-01'])->assertForbidden(); $this->delete("/gemeinsam/eintraege/{$entry->id}")->assertForbidden(); $this->actingAs($this->hr)->put("/gemeinsam/eintraege/{$entry->id}", ['section' => 'welcome', 'name' => 'X Neu', 'date' => '2026-11-01'])->assertRedirect('/gemeinsam?monat=2026-11'); $this->delete("/gemeinsam/eintraege/{$entry->id}"); $this->assertSame(0, Entry::query()->count()); } }