Skip to content

Commit c8549c9

Browse files
committed
feat: add test coverage for me controller
1 parent 29dc842 commit c8549c9

File tree

2 files changed

+53
-0
lines changed

2 files changed

+53
-0
lines changed

app/Http/Controllers/Api/V1/User/MeController.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace App\Http\Controllers\Api\V1\User;
46

57
use App\Http\Controllers\Controller;
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use App\Models\User;
6+
use Laravel\Sanctum\Sanctum;
7+
8+
describe('API/V1/User/MeController', function () {
9+
it('returns authenticated user profile with roles and permissions', function () {
10+
// Create a test user
11+
$user = User::factory()->create([
12+
'name' => 'John Doe',
13+
'email' => '[email protected]',
14+
]);
15+
16+
// Authenticate the user with Sanctum
17+
Sanctum::actingAs($user, ['access-api']);
18+
19+
// Make request to /me endpoint
20+
$response = $this->getJson('/api/v1/me');
21+
22+
// Assert response structure
23+
$response
24+
->assertStatus(200)
25+
->assertJsonStructure([
26+
'status',
27+
'message',
28+
'data' => [
29+
'id',
30+
'name',
31+
'email',
32+
'email_verified_at',
33+
'bio',
34+
'avatar_url',
35+
'twitter',
36+
'facebook',
37+
'linkedin',
38+
'github',
39+
'website',
40+
],
41+
])
42+
->assertJson([
43+
'status' => true,
44+
'data' => [
45+
'id' => $user->id,
46+
'name' => 'John Doe',
47+
'email' => '[email protected]',
48+
],
49+
]);
50+
});
51+
});

0 commit comments

Comments
 (0)