create(['name' => 'Personal']); $role->grants()->create(['ability' => 'jobs.manage']); $this->hr = User::factory()->withRoles([$role])->create(); } private function posting(array $data = []): JobPosting { return JobPosting::query()->create([ 'title' => 'Pflegefachkraft (m/w/d)', 'department' => 'Pflege', 'location' => 'Haus am See', 'employment' => 'part', 'hours' => '30 Std./Woche', 'contract' => 'permanent', 'apply_mode' => 'online', 'published_at' => now()->subHour(), 'deadline' => today()->addWeeks(2), 'created_by' => $this->hr->id, ...$data, ]); } public function test_hr_publishes_a_posting_and_everyone_is_notified_once(): void { Notification::fake(); $employees = User::factory()->count(3)->create(); $this->actingAs($this->hr)->get('/redaktion/stellen/neu')->assertOk(); $this->assertFalse($this->hr->canAccessAdmin(), 'Stellen pflegen braucht kein Backend'); $this->post('/redaktion/stellen', [ 'title' => 'Leitung Hauswirtschaft', 'department' => 'Hauswirtschaft', 'location' => 'Zentrale', 'employment' => 'full', 'contract' => 'fixed', 'contract_note' => 'bis 31.12.2027', 'description' => '
Organisation
', 'apply_mode' => 'online', 'publish' => 'now', 'deadline' => today()->addMonth()->toDateString(), 'pdf' => UploadedFile::fake()->create('ausschreibung.pdf', 50, 'application/pdf'), ])->assertRedirect()->assertSessionHasNoErrors(); $posting = JobPosting::query()->sole(); $this->assertTrue($posting->isOpen()); $this->assertNotNull($posting->announced_at); $this->assertStringNotContainsString('script', $posting->description); Storage::disk('local')->assertExists($posting->pdf_path); Notification::assertSentTo($employees, PortalNotification::class, fn ($n) => str_contains($n->title, 'Leitung Hauswirtschaft')); Notification::assertNotSentTo($this->hr, PortalNotification::class); // Erneutes Speichern kündigt nicht noch einmal an Notification::fake(); $this->post("/redaktion/stellen/{$posting->id}", ['title' => 'Leitung Hauswirtschaft (m/w/d)', 'employment' => 'full', 'contract' => 'fixed', 'apply_mode' => 'online', 'publish' => 'now'])->assertSessionHasNoErrors(); Notification::assertNothingSent(); $this->assertTrue($posting->fresh()->published_at->equalTo($posting->published_at)); } public function test_only_open_postings_are_listed_and_scheduled_ones_announced_later(): void { Notification::fake(); $this->posting(['title' => 'Offen']); $this->posting(['title' => 'Abgelaufen', 'deadline' => today()->subDay()]); $this->posting(['title' => 'Entwurf', 'published_at' => null]); $scheduled = $this->posting(['title' => 'Geplant', 'published_at' => now()->addHour()]); $this->actingAs(User::factory()->create())->get('/stellen')->assertInertia(fn (Assert $page) => $page ->where('postings', fn ($postings) => collect($postings)->pluck('title')->all() === ['Offen'])); $this->get("/stellen/{$scheduled->id}")->assertNotFound(); $this->travel(2)->hours(); $this->assertSame(2, app(Announcer::class)->announceDue()); // „Offen“ und „Geplant“ (per Modell angelegt) $this->assertSame(0, app(Announcer::class)->announceDue()); } public function test_online_application_is_confidential(): void { Notification::fake(); Mail::fake(); $contact = User::factory()->create(); $posting = $this->posting(['contact_id' => $contact->id, 'notify_email' => 'personal@firma.de']); $anna = User::factory()->create(); $colleague = User::factory()->create(); $this->actingAs($anna)->post("/stellen/{$posting->id}/bewerben", [])->assertSessionHasErrors('message'); $this->post("/stellen/{$posting->id}/bewerben", ['message' => 'Ich habe Interesse.', 'file' => UploadedFile::fake()->create('lebenslauf.pdf', 100, 'application/pdf')])->assertSessionHasNoErrors(); $this->post("/stellen/{$posting->id}/bewerben", ['message' => 'Nochmal'])->assertStatus(422); $application = JobApplication::query()->sole(); Notification::assertSentTo($contact, PortalNotification::class); Mail::assertQueued(ApplicationReceived::class, fn ($m) => $m->hasTo('personal@firma.de')); $this->get("/stellen/{$posting->id}")->assertInertia(fn (Assert $page) => $page->where('application.status', 'received')->where('canApply', false)->where('applicationsUrl', null)); $this->get('/stellen/meine-bewerbungen')->assertInertia(fn (Assert $page) => $page->where('applications.0.id', $application->id)); $this->get("/stellen/bewerbungen/{$application->id}/unterlagen")->assertOk(); // Kolleg:innen sehen nichts, die Ansprechperson schon $this->actingAs($colleague)->get("/redaktion/stellen/{$posting->id}/bewerbungen")->assertForbidden(); $this->actingAs($colleague)->get("/stellen/bewerbungen/{$application->id}/unterlagen")->assertNotFound(); $this->actingAs($contact)->get("/redaktion/stellen/{$posting->id}/bewerbungen")->assertOk()->assertInertia(fn (Assert $page) => $page->where('applications.0.person.id', $anna->id)); // Stand ändern → Bewerberin wird benachrichtigt, Notiz bleibt intern $this->put("/redaktion/stellen/bewerbungen/{$application->id}", ['status' => 'interview', 'note' => 'Termin 12.10.'])->assertRedirect(); Notification::assertSentTo($anna, PortalNotification::class, fn ($n) => str_contains($n->body, 'Gespräch vereinbart')); $this->actingAs($anna)->get('/stellen/meine-bewerbungen')->assertInertia(fn (Assert $page) => $page->where('applications.0.note', null)->where('applications.0.status', 'interview')); } public function test_applicants_can_withdraw_and_other_apply_modes(): void { $posting = $this->posting(); $anna = User::factory()->create(); $this->actingAs($anna)->post("/stellen/{$posting->id}/bewerben", ['message' => 'Hallo', 'file' => UploadedFile::fake()->create('cv.docx', 20)])->assertSessionHasNoErrors(); $application = JobApplication::query()->sole(); $path = $application->file_path; $this->actingAs(User::factory()->create())->delete("/stellen/bewerbungen/{$application->id}")->assertForbidden(); $this->actingAs($anna)->delete("/stellen/bewerbungen/{$application->id}")->assertRedirect(); $this->assertSame(0, JobApplication::query()->count()); Storage::disk('local')->assertMissing($path); $link = $this->posting(['apply_mode' => 'link', 'apply_url' => 'https://karriere.example.org/123']); $this->get("/stellen/{$link->id}")->assertInertia(fn (Assert $page) => $page->where('canApply', false)->where('posting.apply_url', 'https://karriere.example.org/123')); $this->post("/stellen/{$link->id}/bewerben", ['message' => 'x'])->assertNotFound(); } public function test_others_cannot_manage_postings(): void { $posting = $this->posting(); $user = User::factory()->create(); $this->actingAs($user)->get('/redaktion/stellen/neu')->assertForbidden(); $this->actingAs($user)->post('/redaktion/stellen', ['title' => 'x'])->assertForbidden(); $this->actingAs($user)->delete("/redaktion/stellen/{$posting->id}")->assertForbidden(); } public function test_images_can_be_used_in_the_description(): void { Storage::fake('uploads'); $url = $this->actingAs($this->hr)->postJson('/redaktion/stellen/bilder', ['image' => UploadedFile::fake()->image('team.jpg', 1200, 800)])->assertOk()->json('url'); $this->assertStringContainsString('stellen/', $url); $this->post('/redaktion/stellen', [ 'title' => 'Mit Bild', 'employment' => 'full', 'contract' => 'permanent', 'apply_mode' => 'online', 'publish' => 'draft', 'description' => 'Unser Team
id}")->assertInertia(fn (Assert $page) => $page
->where('posting.apply_mode', 'email')->where('posting.apply_email', 'bewerbung@firma.de')->where('canApply', false));
$this->post("/stellen/{$posting->id}/bewerben", ['message' => 'x'])->assertNotFound();
}
public function test_posting_editors_cannot_make_themselves_contact_to_read_applications(): void
{
$this->actingAs($this->hr)->post('/redaktion/stellen', [
'title' => 'Selbst', 'employment' => 'full', 'contract' => 'permanent', 'apply_mode' => 'online', 'publish' => 'draft', 'contact_id' => $this->hr->id,
])->assertSessionHasErrors('contact_id');
}
public function test_excluded_roles_are_not_notified_about_new_postings(): void
{
Notification::fake();
$external = Role::query()->create(['name' => 'Extern']);
app(PluginAccess::class)->exclude('stellen', [$external->id]);
$guest = User::factory()->withRoles([$external])->create();
$staff = User::factory()->create();
app(Announcer::class)->announceIfDue($this->posting());
Notification::assertSentTo($staff, PortalNotification::class);
Notification::assertNotSentTo($guest, PortalNotification::class);
}
}