Files
event-uploader/api/tests/Feature/AuthTest.php
2026-02-03 10:38:46 +01:00

35 lines
872 B
PHP

<?php
use App\Models\User;
use Illuminate\Support\Facades\Hash;
test('login fails with invalid credentials', function () {
$response = test()->postJson('/api/auth/login', [
'email' => 'wrong@example.com',
'password' => 'wrong',
]);
$response->assertStatus(422);
});
test('login succeeds with valid credentials', function () {
User::factory()->create([
'email' => 'admin@test.com',
'password' => Hash::make('secret'),
]);
$response = test()->postJson('/api/auth/login', [
'email' => 'admin@test.com',
'password' => 'secret',
]);
$response->assertOk();
$response->assertJsonPath('user.email', 'admin@test.com');
});
test('auth user returns 401 when unauthenticated', function () {
$response = test()->getJson('/api/auth/user');
$response->assertStatus(401);
});