update tests

This commit is contained in:
root
2026-06-08 22:06:30 -04:00
parent 79024235ef
commit 60ecacb7f8
54 changed files with 13243 additions and 5561 deletions
@@ -13,6 +13,54 @@ class ApiAuthenticationAndAuthorizationTest extends TestCase
use CreatesApiTestUsers;
use RefreshDatabase;
public function test_api_login_returns_token_and_user_object(): void
{
$user = $this->createApiUserWithRole('teacher', [
'firstname' => 'Login',
'lastname' => 'Tester',
'email' => 'api.login@example.test',
]);
$this->postJson('/api/v1/auth/login', [
'email' => strtoupper($user->email),
'password' => 'password',
])
->assertOk()
->assertJsonPath('status', true)
->assertJsonStructure([
'token',
'access_token',
'token_type',
'expires_in',
'user' => ['id', 'name', 'firstname', 'lastname', 'email', 'roles'],
])
->assertJsonPath('user.email', 'api.login@example.test');
}
public function test_session_login_also_returns_token_and_user_object_for_spa_clients(): void
{
$user = $this->createApiUserWithRole('teacher', [
'firstname' => 'Session',
'lastname' => 'Tester',
'email' => 'session.login@example.test',
]);
$this->postJson('/user/login', [
'email' => $user->email,
'password' => 'password',
])
->assertOk()
->assertJsonPath('status', true)
->assertJsonStructure([
'token',
'access_token',
'user' => ['id', 'name', 'firstname', 'lastname', 'email', 'roles'],
'next_url',
])
->assertJsonPath('user.email', 'session.login@example.test');
}
public function test_auth_me_requires_authentication(): void
{
$this->getJson('/api/v1/auth/me')->assertUnauthorized();