Files
fotospiel-app/tests/Feature/Tenant/EventJoinTokenTtlPolicyTest.php
Codex Agent 7025418d9e
Some checks failed
linter / quality (push) Has been cancelled
tests / ci (push) Has been cancelled
tests / ui (push) Has been cancelled
Adjust join token expiry for event dates
2026-02-04 14:35:52 +01:00

101 lines
2.9 KiB
PHP

<?php
namespace Tests\Feature\Tenant;
use App\Models\Event;
use Carbon\Carbon;
class EventJoinTokenTtlPolicyTest extends TenantTestCase
{
public function test_join_token_defaults_to_policy_ttl_when_expiry_missing(): void
{
Carbon::setTestNow(Carbon::parse('2026-01-05 12:00:00'));
$eventDate = Carbon::parse('2026-06-15');
$event = Event::factory()
->for($this->tenant)
->create([
'name' => ['de' => 'Token TTL Test', 'en' => 'Token TTL Test'],
'slug' => 'token-ttl-test',
'date' => $eventDate,
]);
$response = $this->authenticatedRequest('POST', "/api/v1/tenant/events/{$event->slug}/join-tokens");
$response->assertCreated();
$expectedExpiry = $eventDate->copy()
->endOfDay()
->addDays(7)
->toIso8601String();
$this->assertSame($expectedExpiry, $response->json('data.expires_at'));
Carbon::setTestNow();
}
public function test_join_tokens_extend_when_event_date_moves_forward(): void
{
Carbon::setTestNow(Carbon::parse('2026-01-05 12:00:00'));
$event = Event::factory()
->for($this->tenant)
->create([
'name' => ['de' => 'Token Update Test', 'en' => 'Token Update Test'],
'slug' => 'token-update-test',
'date' => Carbon::parse('2026-01-10'),
]);
$token = $event->joinTokens()->firstOrFail();
$newDate = Carbon::parse('2026-04-20');
$response = $this->authenticatedRequest('PUT', "/api/v1/tenant/events/{$event->slug}", [
'event_date' => $newDate->toDateString(),
]);
$response->assertOk();
$token->refresh();
$expectedExpiry = $newDate->copy()
->endOfDay()
->addDays(7);
$this->assertSame(
$expectedExpiry->toIso8601String(),
$token->expires_at?->toIso8601String()
);
Carbon::setTestNow();
}
public function test_join_token_expiry_must_not_be_before_event_minimum(): void
{
Carbon::setTestNow(Carbon::parse('2026-01-05 12:00:00'));
$eventDate = Carbon::parse('2026-06-15');
$event = Event::factory()
->for($this->tenant)
->create([
'name' => ['de' => 'Token Expiry Guard', 'en' => 'Token Expiry Guard'],
'slug' => 'token-expiry-guard',
'date' => $eventDate,
]);
$invalidExpiry = $eventDate->copy()
->endOfDay()
->addDay();
$response = $this->authenticatedRequest('POST', "/api/v1/tenant/events/{$event->slug}/join-tokens", [
'expires_at' => $invalidExpiry->toDateTimeString(),
]);
$response->assertUnprocessable();
$response->assertInvalid(['expires_at']);
Carbon::setTestNow();
}
}