freeze auth feature time

This commit is contained in:
Yisroel Baum 2026-07-31 10:20:37 +03:00
parent ad27a0f03c
commit b3c9b0630f
Signed by: yisroelbaum
GPG key ID: 0FA60884F75520A9

View file

@ -2,6 +2,7 @@
namespace Tests\Feature\Auth;
use App\Auth\Clock;
use App\Auth\CreateSessionDto;
use App\Auth\SessionRepository;
use App\Http\Middleware\AuthMiddleware;
@ -15,16 +16,22 @@ use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Route;
use Tests\Fakes\FakeClock;
use Tests\TestCase;
class AuthMiddlewareTest extends TestCase
{
use RefreshDatabase;
private DateTimeImmutable $now;
protected function setUp(): void
{
parent::setUp();
$this->now = $this->utc('2026-07-31T12:00:00');
$this->app->instance(Clock::class, new FakeClock($this->now));
Route::middleware(AuthMiddleware::class)->get(
'/test/authenticated-user',
function (Request $request): JsonResponse {
@ -45,7 +52,7 @@ class AuthMiddlewareTest extends TestCase
{
$user = $this->createUserAndSession(
token: 'valid-token',
expiresAt: $this->utc('2030-08-07T12:00:00'),
expiresAt: $this->now->modify('+7 days'),
);
$response = $this->withCredentials()
@ -73,7 +80,7 @@ class AuthMiddlewareTest extends TestCase
{
$this->createUserAndSession(
token: 'expired-token',
expiresAt: $this->utc('2020-08-07T12:00:00'),
expiresAt: $this->now->modify('-1 day'),
);
$response = $this->withCredentials()
@ -98,7 +105,7 @@ class AuthMiddlewareTest extends TestCase
app(SessionRepository::class)->create(new CreateSessionDto(
token: $token,
user: $user,
createdAt: $this->utc('2026-07-31T12:00:00'),
createdAt: $this->now,
expiresAt: $expiresAt,
));