All checks were successful
Tests / Laravel tests (pull_request) Successful in 12m3s
93 lines
3.2 KiB
PHP
93 lines
3.2 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',
|
|
ipHeaders: [
|
|
'CF-Connecting-IP' => '203.0.113.10',
|
|
'X-Forwarded-For' => '203.0.113.10, 198.51.100.20',
|
|
],
|
|
);
|
|
|
|
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')
|
|
&& str_contains($request['text'], 'CF-Connecting-IP: 203.0.113.10')
|
|
&& str_contains($request['text'], 'X-Forwarded-For: 203.0.113.10, 198.51.100.20'));
|
|
});
|
|
|
|
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', [
|
|
'CF-Connecting-IP' => '203.0.113.10',
|
|
]);
|
|
|
|
Http::assertSent(fn ($request) => str_contains($request['text'], 'Persoonlijke gegevens bekeken')
|
|
&& str_contains($request['text'], 'roberto@example.com')
|
|
&& str_contains($request['text'], 'CF-Connecting-IP: 203.0.113.10'));
|
|
});
|
|
|
|
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', [
|
|
'CF-Connecting-IP' => '203.0.113.10',
|
|
'X-Real-IP' => '198.51.100.30',
|
|
]);
|
|
|
|
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')
|
|
&& str_contains($request['text'], 'CF-Connecting-IP: 203.0.113.10')
|
|
&& str_contains($request['text'], 'X-Real-IP: 198.51.100.30'));
|
|
});
|