add controllers, servoices
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\Services\ClassPreparation;
|
||||
|
||||
use App\Services\ClassPreparation\ClassPreparationAdjustmentService;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Tests\TestCase;
|
||||
|
||||
class ClassPreparationAdjustmentServiceTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_apply_adjustments_updates_counts(): void
|
||||
{
|
||||
DB::table('class_prep_adjustments')->insert([
|
||||
'class_section_id' => 101,
|
||||
'item_name' => 'Small Table',
|
||||
'adjustment' => 2,
|
||||
'school_year' => '2025-2026',
|
||||
'adjustable' => 1,
|
||||
]);
|
||||
|
||||
$service = new ClassPreparationAdjustmentService();
|
||||
[$items, $adjMap] = $service->applyAdjustments(['Small Table' => 1], '101', '2025-2026');
|
||||
|
||||
$this->assertSame(3, $items['Small Table']);
|
||||
$this->assertSame(2, $adjMap['Small Table']);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\Services\ClassPreparation;
|
||||
|
||||
use App\Services\ClassPreparation\ClassPreparationCalculatorService;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Tests\TestCase;
|
||||
|
||||
class ClassPreparationCalculatorServiceTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_get_class_level_by_section(): void
|
||||
{
|
||||
DB::table('classSection')->insert([
|
||||
'id' => 1,
|
||||
'class_id' => 1,
|
||||
'class_section_id' => 101,
|
||||
'class_section_name' => '2-A',
|
||||
'semester' => 'Fall',
|
||||
'school_year' => '2025-2026',
|
||||
]);
|
||||
|
||||
$service = new ClassPreparationCalculatorService();
|
||||
|
||||
$this->assertSame(2, $service->getClassLevelBySection('101'));
|
||||
$this->assertSame(1, $service->getClassLevelBySection('KG'));
|
||||
}
|
||||
|
||||
public function test_calculate_prep_items_for_lower_grades(): void
|
||||
{
|
||||
DB::table('configuration')->insert([
|
||||
['id' => 1, 'config_key' => 'school_year', 'config_value' => '2025-2026'],
|
||||
]);
|
||||
|
||||
DB::table('inventory_categories')->insert([
|
||||
['name' => 'Small Table', 'grade_min' => null, 'grade_max' => null, 'type' => 'classroom'],
|
||||
['name' => 'Small Chair', 'grade_min' => null, 'grade_max' => null, 'type' => 'classroom'],
|
||||
['name' => 'Teacher Chair', 'grade_min' => null, 'grade_max' => null, 'type' => 'classroom'],
|
||||
['name' => 'Grade Box', 'grade_min' => null, 'grade_max' => null, 'type' => 'classroom'],
|
||||
]);
|
||||
|
||||
DB::table('teacher_class')->insert([
|
||||
'class_section_id' => 101,
|
||||
'teacher_id' => 1,
|
||||
'position' => 'main',
|
||||
'school_year' => '2025-2026',
|
||||
]);
|
||||
|
||||
$service = new ClassPreparationCalculatorService();
|
||||
$items = $service->calculatePrepItems(6, 1, '101');
|
||||
|
||||
$this->assertSame(2, $items['Small Table']);
|
||||
$this->assertSame(6, $items['Small Chair']);
|
||||
$this->assertSame(1, $items['Teacher Chair']);
|
||||
$this->assertSame(1, $items['Grade Box']);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\Services\ClassPreparation;
|
||||
|
||||
use App\Services\ClassPreparation\ClassPreparationContextService;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Tests\TestCase;
|
||||
|
||||
class ClassPreparationContextServiceTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_has_roster_for_semester(): void
|
||||
{
|
||||
DB::table('student_class')->insert([
|
||||
'student_id' => 1,
|
||||
'class_section_id' => 101,
|
||||
'semester' => 'Fall',
|
||||
'school_year' => '2025-2026',
|
||||
]);
|
||||
|
||||
$service = new ClassPreparationContextService();
|
||||
|
||||
$this->assertTrue($service->hasRosterForSemester('2025-2026', 'Fall'));
|
||||
$this->assertFalse($service->hasRosterForSemester('2025-2026', 'Spring'));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\Services\ClassPreparation;
|
||||
|
||||
use App\Services\ClassPreparation\ClassPreparationInventoryService;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Tests\TestCase;
|
||||
|
||||
class ClassPreparationInventoryServiceTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_build_availability_uses_max_value(): void
|
||||
{
|
||||
DB::table('inventory_categories')->insert([
|
||||
'id' => 1,
|
||||
'type' => 'classroom',
|
||||
'name' => 'Small Table',
|
||||
]);
|
||||
|
||||
DB::table('inventory_items')->insert([
|
||||
[
|
||||
'type' => 'classroom',
|
||||
'category_id' => 1,
|
||||
'name' => 'Small Table',
|
||||
'quantity' => 5,
|
||||
'good_qty' => 5,
|
||||
'school_year' => '2025-2026',
|
||||
'semester' => 'Fall',
|
||||
],
|
||||
[
|
||||
'type' => 'classroom',
|
||||
'category_id' => 1,
|
||||
'name' => 'Small Table',
|
||||
'quantity' => 3,
|
||||
'good_qty' => 3,
|
||||
'school_year' => '2025-2026',
|
||||
'semester' => 'Fall',
|
||||
],
|
||||
]);
|
||||
|
||||
$service = new ClassPreparationInventoryService();
|
||||
$map = $service->buildAvailability('2025-2026', 'Fall', true, ['Small Table']);
|
||||
|
||||
$this->assertSame(8, $map['Small Table']);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\Services\ClassPreparation;
|
||||
|
||||
use App\Services\ClassPreparation\ClassPreparationLogService;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Tests\TestCase;
|
||||
|
||||
class ClassPreparationLogServiceTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_has_prep_changed_detects_diff(): void
|
||||
{
|
||||
$service = new ClassPreparationLogService();
|
||||
|
||||
$this->assertTrue($service->hasPrepChanged(['a' => 1], ['a' => 2]));
|
||||
$this->assertFalse($service->hasPrepChanged(['a' => 1], ['a' => 1]));
|
||||
}
|
||||
|
||||
public function test_create_log_and_get_latest(): void
|
||||
{
|
||||
$service = new ClassPreparationLogService();
|
||||
$created = $service->createLog('101', '1-A', '2025-2026', ['Small Table' => 2], '2025-09-01 00:00:00');
|
||||
|
||||
$this->assertTrue($created);
|
||||
$this->assertDatabaseHas('class_preparation_log', [
|
||||
'class_section_id' => 101,
|
||||
'school_year' => '2025-2026',
|
||||
]);
|
||||
|
||||
$log = $service->getLatestLog('101', '2025-2026');
|
||||
$this->assertNotNull($log);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\Services\ClassPreparation;
|
||||
|
||||
use App\Services\ClassPreparation\ClassPreparationRosterService;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Tests\TestCase;
|
||||
|
||||
class ClassPreparationRosterServiceTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_get_class_section_student_counts(): void
|
||||
{
|
||||
$this->seedRoster();
|
||||
|
||||
$service = new ClassPreparationRosterService();
|
||||
$rows = $service->getClassSectionStudentCounts('2025-2026', 'Fall', true);
|
||||
|
||||
$this->assertCount(1, $rows);
|
||||
$this->assertSame(101, (int) $rows[0]->class_section_id);
|
||||
$this->assertSame(2, (int) $rows[0]->student_count);
|
||||
}
|
||||
|
||||
public function test_get_student_count_for_section(): void
|
||||
{
|
||||
$this->seedRoster();
|
||||
|
||||
$service = new ClassPreparationRosterService();
|
||||
$count = $service->getStudentCountForSection('2025-2026', 'Fall', true, '101');
|
||||
|
||||
$this->assertSame(2, $count);
|
||||
}
|
||||
|
||||
private function seedRoster(): void
|
||||
{
|
||||
DB::table('students')->insert([
|
||||
[
|
||||
'id' => 1,
|
||||
'school_id' => 'S-1',
|
||||
'firstname' => 'Student',
|
||||
'lastname' => 'One',
|
||||
'age' => 8,
|
||||
'gender' => 'Male',
|
||||
'photo_consent' => 1,
|
||||
'parent_id' => 1,
|
||||
'year_of_registration' => '2025',
|
||||
'school_year' => '2025-2026',
|
||||
'semester' => 'Fall',
|
||||
'is_active' => 1,
|
||||
],
|
||||
[
|
||||
'id' => 2,
|
||||
'school_id' => 'S-2',
|
||||
'firstname' => 'Student',
|
||||
'lastname' => 'Two',
|
||||
'age' => 9,
|
||||
'gender' => 'Female',
|
||||
'photo_consent' => 1,
|
||||
'parent_id' => 1,
|
||||
'year_of_registration' => '2025',
|
||||
'school_year' => '2025-2026',
|
||||
'semester' => 'Fall',
|
||||
'is_active' => 1,
|
||||
],
|
||||
]);
|
||||
|
||||
DB::table('student_class')->insert([
|
||||
[
|
||||
'student_id' => 1,
|
||||
'class_section_id' => 101,
|
||||
'semester' => 'Fall',
|
||||
'school_year' => '2025-2026',
|
||||
],
|
||||
[
|
||||
'student_id' => 2,
|
||||
'class_section_id' => 101,
|
||||
'semester' => 'Fall',
|
||||
'school_year' => '2025-2026',
|
||||
],
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\Services\ClassPreparation;
|
||||
|
||||
use App\Services\ClassPreparation\ClassPreparationService;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Tests\TestCase;
|
||||
|
||||
class ClassPreparationServiceTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_list_prep_returns_sections_and_totals(): void
|
||||
{
|
||||
$this->seedPrepData();
|
||||
|
||||
$service = new ClassPreparationService();
|
||||
$payload = $service->listPrep('2025-2026', 'Fall');
|
||||
|
||||
$this->assertSame('2025-2026', $payload['schoolYear']);
|
||||
$this->assertSame('Fall', $payload['semester']);
|
||||
$this->assertNotEmpty($payload['results']);
|
||||
$this->assertArrayHasKey('Small Table', $payload['totals']);
|
||||
}
|
||||
|
||||
public function test_mark_printed_creates_logs(): void
|
||||
{
|
||||
$this->seedPrepData();
|
||||
|
||||
$service = new ClassPreparationService();
|
||||
$count = $service->markPrinted('2025-2026', 'Fall', [101]);
|
||||
|
||||
$this->assertSame(1, $count);
|
||||
$this->assertDatabaseHas('class_preparation_log', [
|
||||
'class_section_id' => 101,
|
||||
'school_year' => '2025-2026',
|
||||
]);
|
||||
}
|
||||
|
||||
private function seedPrepData(): void
|
||||
{
|
||||
DB::table('configuration')->insert([
|
||||
['id' => 1, 'config_key' => 'school_year', 'config_value' => '2025-2026'],
|
||||
['id' => 2, 'config_key' => 'semester', 'config_value' => 'Fall'],
|
||||
]);
|
||||
|
||||
DB::table('classSection')->insert([
|
||||
'id' => 1,
|
||||
'class_id' => 1,
|
||||
'class_section_id' => 101,
|
||||
'class_section_name' => '1-A',
|
||||
'semester' => 'Fall',
|
||||
'school_year' => '2025-2026',
|
||||
]);
|
||||
|
||||
DB::table('students')->insert([
|
||||
'school_id' => 'S-1',
|
||||
'firstname' => 'Student',
|
||||
'lastname' => 'One',
|
||||
'age' => 8,
|
||||
'gender' => 'Male',
|
||||
'photo_consent' => 1,
|
||||
'parent_id' => 1,
|
||||
'year_of_registration' => '2025',
|
||||
'school_year' => '2025-2026',
|
||||
'semester' => 'Fall',
|
||||
'is_active' => 1,
|
||||
]);
|
||||
|
||||
DB::table('student_class')->insert([
|
||||
'student_id' => 1,
|
||||
'class_section_id' => 101,
|
||||
'semester' => 'Fall',
|
||||
'school_year' => '2025-2026',
|
||||
]);
|
||||
|
||||
DB::table('inventory_categories')->insert([
|
||||
'type' => 'classroom',
|
||||
'name' => 'Small Table',
|
||||
]);
|
||||
|
||||
DB::table('inventory_items')->insert([
|
||||
'type' => 'classroom',
|
||||
'category_id' => 1,
|
||||
'name' => 'Small Table',
|
||||
'quantity' => 10,
|
||||
'good_qty' => 10,
|
||||
'school_year' => '2025-2026',
|
||||
'semester' => 'Fall',
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user