940afe9319
API CI/CD / Validate (composer + pint) (push) Successful in 2m7s
API CI/CD / Test (PHPUnit) (push) Failing after 2m23s
API CI/CD / Build frontend assets (push) Successful in 2m18s
API CI/CD / Security audit (push) Successful in 31s
API CI/CD / Deploy to shared hosting (PHP) (push) Has been skipped
85 lines
2.3 KiB
PHP
85 lines
2.3 KiB
PHP
<?php
|
|
|
|
namespace Tests\Feature\Api\V1\Frontend;
|
|
|
|
use App\Models\User;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Laravel\Sanctum\Sanctum;
|
|
use Tests\TestCase;
|
|
|
|
class LandingPageControllerTest extends TestCase
|
|
{
|
|
use RefreshDatabase;
|
|
|
|
public function test_index_returns_admin_dashboard(): void
|
|
{
|
|
$user = $this->createUser('admin');
|
|
$this->actingAs($user, 'api');
|
|
Sanctum::actingAs($user);
|
|
|
|
$response = $this->getJson('/api/v1/landing');
|
|
|
|
$response->assertOk();
|
|
$response->assertJsonPath('data.landing.role', 'admin');
|
|
}
|
|
|
|
public function test_teacher_dashboard_returns_summary(): void
|
|
{
|
|
$user = $this->createUser('teacher');
|
|
$this->actingAs($user, 'api');
|
|
Sanctum::actingAs($user);
|
|
|
|
$response = $this->getJson('/api/v1/landing/teacher');
|
|
|
|
$response->assertOk();
|
|
$response->assertJsonPath('data.landing.dashboard', 'teacher');
|
|
$response->assertJsonStructure(['data' => ['landing' => ['summary']]]);
|
|
}
|
|
|
|
public function test_parent_dashboard_returns_summary(): void
|
|
{
|
|
$user = $this->createUser('parent');
|
|
$this->actingAs($user, 'api');
|
|
Sanctum::actingAs($user);
|
|
|
|
$response = $this->getJson('/api/v1/landing/parent');
|
|
|
|
$response->assertOk();
|
|
$response->assertJsonPath('data.landing.dashboard', 'parent');
|
|
}
|
|
|
|
private function createUser(string $roleName): User
|
|
{
|
|
$roleId = DB::table('roles')->insertGetId([
|
|
'name' => $roleName,
|
|
'priority' => 1,
|
|
'is_active' => 1,
|
|
]);
|
|
|
|
$user = User::query()->create([
|
|
'firstname' => 'Test',
|
|
'lastname' => 'User',
|
|
'email' => $roleName.'@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',
|
|
'user_type' => 'primary',
|
|
]);
|
|
|
|
DB::table('user_roles')->insert([
|
|
'user_id' => $user->id,
|
|
'role_id' => $roleId,
|
|
]);
|
|
|
|
return $user;
|
|
}
|
|
}
|