add all controllers logic
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
<?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');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Api\V1\System;
|
||||
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Tests\TestCase;
|
||||
|
||||
class DatabaseHealthControllerTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_db_check_returns_ok(): void
|
||||
{
|
||||
$response = $this->getJson('/api/v1/system/db-check');
|
||||
|
||||
$response->assertOk();
|
||||
$response->assertJsonPath('data.ok', true);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Api\V1\System;
|
||||
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Tests\TestCase;
|
||||
|
||||
class HealthControllerTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_health_returns_payload(): void
|
||||
{
|
||||
$response = $this->getJson('/api/v1/health');
|
||||
|
||||
$this->assertContains($response->status(), [200, 503]);
|
||||
$response->assertJsonStructure([
|
||||
'status',
|
||||
'message',
|
||||
'data' => [
|
||||
'health' => [
|
||||
'ok',
|
||||
'paths',
|
||||
'database',
|
||||
'write_path',
|
||||
'timestamp',
|
||||
],
|
||||
],
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,150 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Api\V1\System;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Tests\TestCase;
|
||||
|
||||
class NavBuilderControllerTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
private function makeAdminUser(): User
|
||||
{
|
||||
$roleId = DB::table('roles')->insertGetId([
|
||||
'name' => 'admin',
|
||||
'priority' => 1,
|
||||
]);
|
||||
|
||||
$user = User::query()->create([
|
||||
'firstname' => 'Admin',
|
||||
'lastname' => 'User',
|
||||
'email' => 'admin@example.com',
|
||||
'cellphone' => '5555555555',
|
||||
'address_street' => '123 Main',
|
||||
'city' => 'City',
|
||||
'state' => 'CT',
|
||||
'zip' => '12345',
|
||||
'accept_school_policy' => 1,
|
||||
'status' => 'Active',
|
||||
'password' => 'hashed',
|
||||
'semester' => 'Fall',
|
||||
]);
|
||||
|
||||
DB::table('user_roles')->insert([
|
||||
'user_id' => $user->id,
|
||||
'role_id' => $roleId,
|
||||
]);
|
||||
|
||||
return $user;
|
||||
}
|
||||
|
||||
public function test_menu_returns_items_for_roles(): void
|
||||
{
|
||||
$roleId = DB::table('roles')->insertGetId([
|
||||
'name' => 'parent',
|
||||
'priority' => 1,
|
||||
]);
|
||||
|
||||
$user = User::query()->create([
|
||||
'firstname' => 'Parent',
|
||||
'lastname' => 'User',
|
||||
'email' => 'parent@example.com',
|
||||
'cellphone' => '5555555555',
|
||||
'address_street' => '123 Main',
|
||||
'city' => 'City',
|
||||
'state' => 'CT',
|
||||
'zip' => '12345',
|
||||
'accept_school_policy' => 1,
|
||||
'status' => 'Active',
|
||||
'password' => 'hashed',
|
||||
'semester' => 'Fall',
|
||||
]);
|
||||
|
||||
DB::table('user_roles')->insert([
|
||||
'user_id' => $user->id,
|
||||
'role_id' => $roleId,
|
||||
]);
|
||||
|
||||
$navId = DB::table('nav_items')->insertGetId([
|
||||
'label' => 'Home',
|
||||
'url' => 'home',
|
||||
'sort_order' => 1,
|
||||
'is_enabled' => 1,
|
||||
]);
|
||||
|
||||
DB::table('role_nav_items')->insert([
|
||||
'role_id' => $roleId,
|
||||
'nav_item_id' => $navId,
|
||||
]);
|
||||
|
||||
$response = $this->actingAs($user, 'sanctum')->getJson('/api/v1/nav-builder/menu');
|
||||
|
||||
$response->assertOk();
|
||||
$response->assertJsonPath('data.items.0.label', 'Home');
|
||||
}
|
||||
|
||||
public function test_data_requires_admin(): void
|
||||
{
|
||||
$user = $this->makeAdminUser();
|
||||
|
||||
$response = $this->actingAs($user, 'sanctum')->getJson('/api/v1/nav-builder/data');
|
||||
|
||||
$response->assertOk();
|
||||
$response->assertJsonStructure(['data' => ['data' => ['items', 'roles', 'parentOptions']]]);
|
||||
}
|
||||
|
||||
public function test_store_creates_nav_item(): void
|
||||
{
|
||||
$user = $this->makeAdminUser();
|
||||
|
||||
$response = $this->actingAs($user, 'sanctum')->postJson('/api/v1/nav-builder', [
|
||||
'label' => 'Dashboard',
|
||||
'url' => 'dashboard',
|
||||
'sort_order' => 1,
|
||||
'is_enabled' => true,
|
||||
'roles' => [],
|
||||
]);
|
||||
|
||||
$response->assertCreated();
|
||||
$this->assertDatabaseHas('nav_items', ['label' => 'Dashboard']);
|
||||
}
|
||||
|
||||
public function test_delete_removes_nav_item(): void
|
||||
{
|
||||
$user = $this->makeAdminUser();
|
||||
|
||||
$navId = DB::table('nav_items')->insertGetId([
|
||||
'label' => 'Delete',
|
||||
'url' => 'delete',
|
||||
'sort_order' => 1,
|
||||
'is_enabled' => 1,
|
||||
]);
|
||||
|
||||
$response = $this->actingAs($user, 'sanctum')->deleteJson("/api/v1/nav-builder/{$navId}");
|
||||
|
||||
$response->assertOk();
|
||||
$this->assertDatabaseMissing('nav_items', ['id' => $navId]);
|
||||
}
|
||||
|
||||
public function test_reorder_updates_items(): void
|
||||
{
|
||||
$user = $this->makeAdminUser();
|
||||
|
||||
$navId = DB::table('nav_items')->insertGetId([
|
||||
'label' => 'Sort',
|
||||
'url' => 'sort',
|
||||
'sort_order' => 1,
|
||||
'is_enabled' => 1,
|
||||
]);
|
||||
|
||||
$response = $this->actingAs($user, 'sanctum')->postJson('/api/v1/nav-builder/reorder', [
|
||||
'orders' => [$navId => 9],
|
||||
]);
|
||||
|
||||
$response->assertOk();
|
||||
$this->assertDatabaseHas('nav_items', ['id' => $navId, 'sort_order' => 9]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user