Files
alrahma_sunday_school_api/tests/Feature/Api/V1/System/DashboardControllerTest.php
T
2026-03-11 17:53:15 -04:00

60 lines
1.6 KiB
PHP

<?php
namespace Tests\Feature\Api\V1\System;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\DB;
use Laravel\Sanctum\Sanctum;
use Tests\TestCase;
class DashboardControllerTest extends TestCase
{
use RefreshDatabase;
public function test_route_requires_authentication(): void
{
$response = $this->getJson('/api/v1/dashboard/route');
$response->assertStatus(401);
}
public function test_route_returns_dashboard_for_role(): void
{
$roleId = DB::table('roles')->insertGetId([
'name' => 'administrator',
'dashboard_route' => '/administrator/dashboard',
'priority' => 1,
'is_active' => 1,
]);
$user = User::query()->create([
'firstname' => 'Admin',
'lastname' => 'User',
'email' => 'admin@example.com',
'cellphone' => '5555555555',
'address_street' => '123 Main',
'city' => 'City',
'state' => 'ST',
'zip' => '12345',
'accept_school_policy' => 1,
'status' => 'Active',
'password' => bcrypt('secret'),
'semester' => 'Fall',
'school_year' => '2025-2026',
]);
DB::table('user_roles')->insert([
'user_id' => $user->id,
'role_id' => $roleId,
]);
Sanctum::actingAs($user);
$response = $this->getJson('/api/v1/dashboard/route');
$response->assertOk();
$response->assertJsonPath('data.dashboard.route', '/administrator/dashboard');
}
}