Cross-cutting migration affecting the entire stack: - Database: 3 migrations splitting name columns with data migration - Models: first_name/last_name on User, Person; contact_first_name/contact_last_name on Company; backward-compatible name accessors - API: all resources return first_name, last_name, full_name; assignablePersons endpoint updated - Requests: validation rules updated for all person/user/company forms - Services: VolunteerRegistrationService, ShiftAssignmentService, InvitationService updated - Frontend: TypeScript types, Zod schemas, all forms split into Voornaam/Achternaam fields - Display: all person/user name references use full_name; initials use first_name[0]+last_name[0] - Tests: all 371 tests passing - Docs: SCHEMA.md and API.md updated Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
67 lines
1.7 KiB
PHP
67 lines
1.7 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Tests\Feature\Auth;
|
|
|
|
use App\Models\Organisation;
|
|
use App\Models\User;
|
|
use Database\Seeders\RoleSeeder;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Laravel\Sanctum\Sanctum;
|
|
use Tests\TestCase;
|
|
|
|
class MeTest extends TestCase
|
|
{
|
|
use RefreshDatabase;
|
|
|
|
protected function setUp(): void
|
|
{
|
|
parent::setUp();
|
|
$this->seed(RoleSeeder::class);
|
|
}
|
|
|
|
public function test_authenticated_user_can_get_profile(): void
|
|
{
|
|
$user = User::factory()->create();
|
|
$organisation = Organisation::factory()->create();
|
|
$organisation->users()->attach($user, ['role' => 'org_admin']);
|
|
|
|
Sanctum::actingAs($user);
|
|
|
|
$response = $this->getJson('/api/v1/auth/me');
|
|
|
|
$response->assertOk()
|
|
->assertJsonStructure([
|
|
'success',
|
|
'data' => [
|
|
'id', 'first_name', 'last_name', 'full_name', 'email', 'timezone', 'locale',
|
|
'organisations', 'app_roles', 'permissions',
|
|
],
|
|
]);
|
|
|
|
$this->assertCount(1, $response->json('data.organisations'));
|
|
}
|
|
|
|
public function test_me_returns_app_roles_and_permissions(): void
|
|
{
|
|
$user = User::factory()->create();
|
|
$user->assignRole('super_admin');
|
|
|
|
Sanctum::actingAs($user);
|
|
|
|
$response = $this->getJson('/api/v1/auth/me');
|
|
|
|
$response->assertOk();
|
|
$this->assertContains('super_admin', $response->json('data.app_roles'));
|
|
$this->assertIsArray($response->json('data.permissions'));
|
|
}
|
|
|
|
public function test_unauthenticated_user_cannot_get_profile(): void
|
|
{
|
|
$response = $this->getJson('/api/v1/auth/me');
|
|
|
|
$response->assertUnauthorized();
|
|
}
|
|
}
|