Files
cv-roberto/tests/Feature/TelegramNotificationServiceTest.php
Roberto bbfc64031f
Some checks failed
Tests / Laravel tests (pull_request) Failing after 6m57s
Add page visit Telegram notifications
2026-06-03 23:19:06 +02:00

79 lines
2.6 KiB
PHP

<?php
use App\Models\Personalia;
use App\Services\TelegramNotificationService;
use Illuminate\Support\Facades\Http;
test('telegram service sends a contact message notification', function () {
config([
'services.telegram.bot_token' => 'telegram-token',
'services.telegram.chat_id' => 'telegram-chat',
]);
Http::fake();
app(TelegramNotificationService::class)->notifyContactMessage(
name: 'Roberto',
message: 'Hoi, ik wil graag contact opnemen.',
ip: '127.0.0.1',
userAgent: 'Pest Browser',
email: 'roberto@example.com',
phone: '+31612345678'
);
Http::assertSent(fn ($request) => $request->url() === 'https://api.telegram.org/bottelegram-token/sendMessage'
&& $request['chat_id'] === 'telegram-chat'
&& str_contains($request['text'], 'Nieuw contactbericht ontvangen')
&& str_contains($request['text'], 'roberto@example.com'));
});
test('telegram service sends a personalia click notification', function () {
config([
'services.telegram.bot_token' => 'telegram-token',
'services.telegram.chat_id' => 'telegram-chat',
]);
Http::fake();
$personalia = Personalia::factory()->create([
'value' => 'roberto@example.com',
]);
app(TelegramNotificationService::class)->notifyPersonaliaClick($personalia, '127.0.0.1', 'Pest Browser');
Http::assertSent(fn ($request) => str_contains($request['text'], 'Persoonlijke gegevens bekeken')
&& str_contains($request['text'], 'roberto@example.com'));
});
test('telegram service sends a page visit notification', function () {
config([
'services.telegram.bot_token' => 'telegram-token',
'services.telegram.chat_id' => 'telegram-chat',
]);
Http::fake();
app(TelegramNotificationService::class)->notifyPageVisit([
'visitor_id' => 'visitor-123',
'url' => 'https://cv.robert.ooo/',
'path' => '/',
'title' => 'CV Roberto',
'referrer' => 'https://example.com',
'language' => 'nl-NL',
'timezone' => 'Europe/Amsterdam',
'screen' => [
'width' => 1920,
'height' => 1080,
],
'viewport' => [
'width' => 1440,
'height' => 900,
],
], '127.0.0.1', 'Pest Browser', 'nl-NL,nl;q=0.9');
Http::assertSent(fn ($request) => str_contains($request['text'], 'Pagina bezocht')
&& str_contains($request['text'], 'Visitor ID: visitor-123')
&& str_contains($request['text'], 'Scherm: 1920x1080')
&& str_contains($request['text'], 'Viewport: 1440x900'));
});