ldc-boutique-cnc-sable/tests/Unit/Services/IcsGeneratorServiceTest.php

43 lines
1.6 KiB
PHP

<?php
declare(strict_types=1);
use App\Dto\IcsContentDto;
use App\Services\IcsGeneratorService;
use Carbon\CarbonImmutable;
it('generates a valid ICS string', function () {
// GIVEN
$service = new IcsGeneratorService('La Boutique de Cocotte');
// Fix time to ensure DTSTAMP doesn't fail assertion
CarbonImmutable::setTestNow(CarbonImmutable::create(2024, 1, 1, 10, 0, 0, 'UTC'));
$event = new IcsContentDto(
uid: 'test-uid@laboutiquedecocotte.fr',
summary: 'Test Event',
description: 'This is a test description with a comma, and a newline' . "\n",
startsAt: CarbonImmutable::create(2024, 1, 1, 12, 0, 0, 'Europe/Paris'),
endsAt: CarbonImmutable::create(2024, 1, 1, 12, 15, 0, 'Europe/Paris'),
url: 'https://laboutiquedecocotte.fr'
);
// WHEN
$ics = $service->generate($event);
// THEN
expect($ics)->toContain('BEGIN:VCALENDAR')
->toContain('VERSION:2.0')
->toContain('PRODID:-//La Boutique de Cocotte//NONSGML v1.0//EN')
->toContain('BEGIN:VEVENT')
->toContain('UID:test-uid@laboutiquedecocotte.fr')
->toContain('DTSTAMP:20240101T100000Z')
// 12:00 Europe/Paris in winter is 11:00 UTC
->toContain('DTSTART:20240101T110000Z')
->toContain('DTEND:20240101T111500Z')
->toContain('SUMMARY:Test Event')
->toContain('DESCRIPTION:This is a test description with a comma\, and a newline\n')
->toContain('URL:https://laboutiquedecocotte.fr')
->toContain('END:VEVENT')
->toContain('END:VCALENDAR');
});