add controllers, servoices
This commit is contained in:
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\Services\Incidents;
|
||||
|
||||
use App\Services\Incidents\IncidentAnalysisService;
|
||||
use App\Services\Incidents\IncidentLookupService;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Tests\TestCase;
|
||||
|
||||
class IncidentAnalysisServiceTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_analyze_groups_incidents_by_student(): void
|
||||
{
|
||||
DB::table('classSection')->insert([
|
||||
'id' => 1,
|
||||
'class_section_id' => 1,
|
||||
'class_section_name' => '1A',
|
||||
'class_id' => 1,
|
||||
'semester' => 'Fall',
|
||||
'school_year' => '2025-2026',
|
||||
]);
|
||||
|
||||
DB::table('incident')->insert([
|
||||
[
|
||||
'id' => 1,
|
||||
'student_id' => 10,
|
||||
'student_name' => 'Kid Tester',
|
||||
'grade' => '1',
|
||||
'incident' => 'behavior',
|
||||
'incident_datetime' => '2025-01-02 10:00:00',
|
||||
'incident_state' => 'Closed',
|
||||
'semester' => 'Fall',
|
||||
'school_year' => '2025-2026',
|
||||
],
|
||||
[
|
||||
'id' => 2,
|
||||
'student_id' => 10,
|
||||
'student_name' => 'Kid Tester',
|
||||
'grade' => '1',
|
||||
'incident' => 'behavior',
|
||||
'incident_datetime' => '2025-01-01 10:00:00',
|
||||
'incident_state' => 'Canceled',
|
||||
'semester' => 'Fall',
|
||||
'school_year' => '2025-2026',
|
||||
],
|
||||
]);
|
||||
|
||||
$service = new IncidentAnalysisService(new IncidentLookupService());
|
||||
$result = $service->analyze('2025-2026', 'Fall');
|
||||
|
||||
$this->assertCount(1, $result);
|
||||
$this->assertSame('Kid Tester', $result[0]['student_name']);
|
||||
$this->assertSame('1A', $result[0]['grade']);
|
||||
$this->assertSame(2, $result[0]['total']);
|
||||
$this->assertSame(1, $result[0]['closed']);
|
||||
$this->assertSame(1, $result[0]['canceled']);
|
||||
$this->assertSame('2025-01-02 10:00:00', $result[0]['last_incident']);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\Services\Incidents;
|
||||
|
||||
use App\Services\Incidents\IncidentHistoryService;
|
||||
use App\Services\Incidents\IncidentLookupService;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Tests\TestCase;
|
||||
|
||||
class IncidentHistoryServiceTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_processed_enriches_grade_and_updater_names(): void
|
||||
{
|
||||
DB::table('classSection')->insert([
|
||||
'id' => 1,
|
||||
'class_id' => 1,
|
||||
'class_section_id' => 5,
|
||||
'class_section_name' => '5A',
|
||||
'semester' => 'Fall',
|
||||
'school_year' => '2025-2026',
|
||||
]);
|
||||
|
||||
DB::table('users')->insert([
|
||||
'id' => 3,
|
||||
'school_id' => 1,
|
||||
'firstname' => 'Admin',
|
||||
'lastname' => 'User',
|
||||
'cellphone' => '5555555555',
|
||||
'email' => 'admin@example.com',
|
||||
'address_street' => '123 Main',
|
||||
'city' => 'City',
|
||||
'state' => 'ST',
|
||||
'zip' => '12345',
|
||||
'accept_school_policy' => 1,
|
||||
'is_verified' => 1,
|
||||
'status' => 'Active',
|
||||
'is_suspended' => 0,
|
||||
'failed_attempts' => 0,
|
||||
'password' => bcrypt('secret'),
|
||||
'semester' => 'Fall',
|
||||
'school_year' => '2025-2026',
|
||||
]);
|
||||
|
||||
DB::table('incident')->insert([
|
||||
'student_id' => 1,
|
||||
'student_name' => 'Student One',
|
||||
'grade' => 5,
|
||||
'incident' => 'Test incident',
|
||||
'incident_datetime' => '2025-01-01 10:00:00',
|
||||
'incident_state' => 'open',
|
||||
'updated_by_open' => 3,
|
||||
'open_description' => 'Opened',
|
||||
'semester' => 'Fall',
|
||||
'school_year' => '2025-2026',
|
||||
]);
|
||||
|
||||
$service = new IncidentHistoryService(new IncidentLookupService());
|
||||
$rows = $service->processed('2025-2026', 'Fall');
|
||||
|
||||
$this->assertSame('5A', $rows[0]['grade']);
|
||||
$this->assertSame('Admin User', $rows[0]['updated_by_open_name']);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\Services\Incidents;
|
||||
|
||||
use App\Services\Incidents\IncidentLookupService;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Tests\TestCase;
|
||||
|
||||
class IncidentLookupServiceTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_grade_options_with_active_students(): void
|
||||
{
|
||||
DB::table('classSection')->insert([
|
||||
'id' => 1,
|
||||
'class_id' => 1,
|
||||
'class_section_id' => 10,
|
||||
'class_section_name' => '1A',
|
||||
'semester' => 'Fall',
|
||||
'school_year' => '2025-2026',
|
||||
]);
|
||||
|
||||
DB::table('students')->insert([
|
||||
'id' => 1,
|
||||
'school_id' => 'S1',
|
||||
'firstname' => 'Test',
|
||||
'lastname' => 'Student',
|
||||
'age' => 8,
|
||||
'gender' => 'Male',
|
||||
'photo_consent' => 1,
|
||||
'parent_id' => 1,
|
||||
'year_of_registration' => '2025',
|
||||
'school_year' => '2025-2026',
|
||||
]);
|
||||
|
||||
DB::table('student_class')->insert([
|
||||
'student_id' => 1,
|
||||
'class_section_id' => 10,
|
||||
'semester' => 'Fall',
|
||||
'school_year' => '2025-2026',
|
||||
]);
|
||||
|
||||
$service = new IncidentLookupService();
|
||||
$grades = $service->gradeOptionsWithActiveStudents('2025-2026');
|
||||
|
||||
$this->assertSame([['id' => 10, 'name' => '1A']], $grades);
|
||||
}
|
||||
|
||||
public function test_updater_name_map(): void
|
||||
{
|
||||
DB::table('users')->insert([
|
||||
'id' => 1,
|
||||
'school_id' => 1,
|
||||
'firstname' => 'Jane',
|
||||
'lastname' => 'Doe',
|
||||
'cellphone' => '5555555555',
|
||||
'email' => 'jane@example.com',
|
||||
'address_street' => '123 Main',
|
||||
'city' => 'City',
|
||||
'state' => 'ST',
|
||||
'zip' => '12345',
|
||||
'accept_school_policy' => 1,
|
||||
'is_verified' => 1,
|
||||
'status' => 'Active',
|
||||
'is_suspended' => 0,
|
||||
'failed_attempts' => 0,
|
||||
'password' => bcrypt('secret'),
|
||||
'semester' => 'Fall',
|
||||
'school_year' => '2025-2026',
|
||||
]);
|
||||
|
||||
$service = new IncidentLookupService();
|
||||
$map = $service->updaterNameMap([1]);
|
||||
|
||||
$this->assertSame('Jane Doe', $map[1]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user