add more controller
This commit is contained in:
@@ -0,0 +1,128 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Api\V1\Students;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Laravel\Sanctum\Sanctum;
|
||||
use Tests\TestCase;
|
||||
|
||||
class StudentControllerTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_assign_and_remove_class(): void
|
||||
{
|
||||
$this->seedConfig();
|
||||
$user = $this->seedUser();
|
||||
$studentId = $this->seedStudent();
|
||||
$classSectionId = $this->seedClassSection();
|
||||
|
||||
Sanctum::actingAs($user);
|
||||
$assignResponse = $this->postJson('/api/v1/students/assign-class', [
|
||||
'student_id' => $studentId,
|
||||
'class_section_id' => [$classSectionId],
|
||||
]);
|
||||
|
||||
$assignResponse->assertOk();
|
||||
$this->assertDatabaseHas('student_class', [
|
||||
'student_id' => $studentId,
|
||||
'class_section_id' => $classSectionId,
|
||||
]);
|
||||
|
||||
$removeResponse = $this->postJson('/api/v1/students/remove-class', [
|
||||
'student_id' => $studentId,
|
||||
'class_section_id' => $classSectionId,
|
||||
]);
|
||||
|
||||
$removeResponse->assertOk();
|
||||
$this->assertDatabaseMissing('student_class', [
|
||||
'student_id' => $studentId,
|
||||
'class_section_id' => $classSectionId,
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_score_card_returns_rows(): void
|
||||
{
|
||||
$this->seedConfig();
|
||||
$user = $this->seedUser();
|
||||
$studentId = $this->seedStudent();
|
||||
$this->seedClassSection();
|
||||
|
||||
DB::table('semester_scores')->insert([
|
||||
'student_id' => $studentId,
|
||||
'class_section_id' => 701,
|
||||
'school_year' => '2025-2026',
|
||||
'semester' => 'Fall',
|
||||
'semester_score' => 90,
|
||||
]);
|
||||
|
||||
Sanctum::actingAs($user);
|
||||
$response = $this->getJson('/api/v1/students/' . $studentId . '/score-card');
|
||||
|
||||
$response->assertOk();
|
||||
$response->assertJson(['ok' => true]);
|
||||
$this->assertNotEmpty($response->json('rows'));
|
||||
}
|
||||
|
||||
private function seedConfig(): void
|
||||
{
|
||||
DB::table('configuration')->insert([
|
||||
['config_key' => 'school_year', 'config_value' => '2025-2026'],
|
||||
['config_key' => 'semester', 'config_value' => 'Fall'],
|
||||
]);
|
||||
}
|
||||
|
||||
private function seedUser(): User
|
||||
{
|
||||
$userId = DB::table('users')->insertGetId([
|
||||
'firstname' => 'Admin',
|
||||
'lastname' => 'User',
|
||||
'cellphone' => '7777777777',
|
||||
'email' => 'student.controller@example.com',
|
||||
'address_street' => '123 Street',
|
||||
'city' => 'City',
|
||||
'state' => 'ST',
|
||||
'zip' => '12345',
|
||||
'accept_school_policy' => 1,
|
||||
'password' => bcrypt('password'),
|
||||
'user_type' => 'primary',
|
||||
'semester' => 'Fall',
|
||||
'school_year' => '2025-2026',
|
||||
'status' => 'Active',
|
||||
]);
|
||||
|
||||
return User::query()->findOrFail($userId);
|
||||
}
|
||||
|
||||
private function seedStudent(): int
|
||||
{
|
||||
return DB::table('students')->insertGetId([
|
||||
'school_id' => 'S-900',
|
||||
'firstname' => 'Omar',
|
||||
'lastname' => 'Student',
|
||||
'dob' => '2014-09-01',
|
||||
'age' => 11,
|
||||
'gender' => 'Male',
|
||||
'photo_consent' => 1,
|
||||
'parent_id' => 1,
|
||||
'year_of_registration' => '2025',
|
||||
'school_year' => '2025-2026',
|
||||
'semester' => 'Fall',
|
||||
]);
|
||||
}
|
||||
|
||||
private function seedClassSection(): int
|
||||
{
|
||||
DB::table('classSection')->insert([
|
||||
'class_id' => 1,
|
||||
'class_section_id' => 701,
|
||||
'class_section_name' => '7A',
|
||||
'semester' => 'Fall',
|
||||
'school_year' => '2025-2026',
|
||||
]);
|
||||
|
||||
return 701;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user