Files
cv-roberto/tests/Feature/Controllers/FrontendControllerTest.php
Roberto fe47b79a25
All checks were successful
Tests / Laravel tests (pull_request) Successful in 3m24s
Fix controller cleanup issues
2026-06-03 21:57:10 +02:00

102 lines
3.1 KiB
PHP

<?php
use App\Jobs\NotifyTelegramAboutContactMessage;
use App\Jobs\NotifyTelegramAboutPersonaliaClick;
use App\Models\Education;
use App\Models\Personalia;
use App\Models\Skill;
use App\Models\WorkExperience;
use Illuminate\Support\Facades\Queue;
test('the homepage shows the public cv data', function () {
$skill = Skill::factory()->rating()->create([
'title' => 'Laravel',
'description' => 'Framework expertise',
'rating' => 8,
]);
$personalium = Personalia::factory()->hidden()->create([
'key' => 'Email',
'value' => 'roberto@example.com',
'icon' => 'fa-solid fa-envelope',
]);
$education = Education::factory()->create([
'opleiding' => 'HBO-ICT',
'instituut' => 'Hogeschool Utrecht',
'startdatum' => '2020-09-01',
'einddatum' => '2024-07-01',
]);
$experience = WorkExperience::factory()->current()->create([
'werkgever' => 'Acme',
'functie' => 'Developer',
'startdatum' => '2022-01-01',
]);
$this->get(route('home'))
->assertOk()
->assertViewIs('welcome')
->assertViewHas('skills', fn ($skills) => $skills->get('rating')->contains($skill))
->assertViewHas('personalia', fn ($personalia) => $personalia->contains($personalium))
->assertViewHas('education', fn ($educations) => $educations->contains($education))
->assertViewHas('experience', fn ($experiences) => $experiences->contains($experience));
});
test('a hidden personalia value can be requested and the click is queued for notification', function () {
Queue::fake();
$personalium = Personalia::factory()->hidden()->create([
'key' => 'Email',
'value' => 'roberto@example.com',
'icon' => 'fa-solid fa-envelope',
]);
$this->withHeader('User-Agent', 'Pest Browser')
->getJson(route('personalia', $personalium))
->assertOk()
->assertJson([
'value' => 'roberto@example.com',
]);
Queue::assertPushed(NotifyTelegramAboutPersonaliaClick::class);
});
test('requesting unknown personalia returns not found', function () {
Queue::fake();
$this->getJson(route('personalia', 999))->assertNotFound();
Queue::assertNotPushed(NotifyTelegramAboutPersonaliaClick::class);
});
test('a contact message can be submitted and is queued for notification', function () {
Queue::fake();
$this->withHeader('User-Agent', 'Pest Browser')
->postJson(route('contact'), [
'name' => 'Roberto',
'email' => 'roberto@example.com',
'phone' => '+31612345678',
'message' => 'Hoi, ik wil graag contact opnemen.',
])
->assertOk()
->assertJson([
'status' => 'success',
]);
Queue::assertPushed(NotifyTelegramAboutContactMessage::class);
});
test('a contact message requires a name and message', function () {
Queue::fake();
$this->postJson(route('contact'), [
'email' => 'not-an-email',
])
->assertUnprocessable()
->assertJsonValidationErrors(['name', 'message', 'email']);
Queue::assertNotPushed(NotifyTelegramAboutContactMessage::class);
});