ldc-cocotte/tests/Feature/App/Jobs/DeleteOldResetTokensTest.php

35 lines
989 B
PHP

<?php
declare(strict_types=1);
namespace Tests\Feature\App\Jobs;
use App\Jobs\DeleteOldResetTokens;
use App\Models\PasswordReset;
use Illuminate\Support\Facades\Date;
it('deletes old password reset tokens via Executor when dispatched', function (): void {
// GIVEN
Date::setTestNow('2026-11-14 12:00:00');
PasswordReset::query()->insert([
[
'email' => 'expired@example.com',
'token' => 'expired-token',
'created_at' => Date::now()->subDays(8),
],
[
'email' => 'fresh@example.com',
'token' => 'fresh-token',
'created_at' => Date::now()->subDay(),
],
]);
// WHEN
DeleteOldResetTokens::dispatchSync();
// THEN
expect(PasswordReset::query()->where('email', 'expired@example.com')->exists())->toBeFalse()
->and(PasswordReset::query()->where('email', 'fresh@example.com')->exists())->toBeTrue();
Date::setTestNow();
});