Files
saqel/backend/tests/Feature/GuardianSummaryTest.php
T

47 lines
1.3 KiB
PHP

<?php
namespace Tests\Feature;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use PHPUnit\Framework\Attributes\Test;
use Tests\TestCase;
class GuardianSummaryTest extends TestCase
{
use RefreshDatabase;
#[Test]
public function guardian_can_view_linked_student_summary(): void
{
$guardian = User::factory()->guardian()->create();
$student = User::factory()->create();
$guardian->students()->attach($student->id);
$response = $this->getJson("/api/v1/guardian/students/{$student->id}/summary", [
'Authorization' => 'Bearer '.$guardian->api_token,
]);
$response->assertOk()
->assertJsonPath('student.id', $student->id)
->assertJsonStructure([
'student' => ['id', 'name'],
'lessons_progress',
'weakest_concepts',
'latest_ai_summary',
]);
}
#[Test]
public function guardian_cannot_view_unlinked_student(): void
{
$guardian = User::factory()->guardian()->create();
$otherStudent = User::factory()->create();
$this->getJson("/api/v1/guardian/students/{$otherStudent->id}/summary", [
'Authorization' => 'Bearer '.$guardian->api_token,
])->assertForbidden();
}
}