From d14409a5663fffa76f234eaa82bbedcb5cf5888d Mon Sep 17 00:00:00 2001 From: Ray1111-aa Date: Thu, 22 Oct 2026 11:50:30 +0700 Subject: [PATCH] refactor: completely purge SuperAdminSeeder and SampleTestingDataSeeder from database/seeders, move test mocks into tests/TestCase --- database/seeders/DatabaseSeeder.php | 8 +- database/seeders/SampleTestingDataSeeder.php | 222 ------------------- database/seeders/SuperAdminSeeder.php | 33 --- tests/Feature/AuthenticationTest.php | 1 + tests/Feature/SecurityGuardFilterTest.php | 1 + tests/Feature/VehicleActivityTest.php | 1 + tests/Feature/VerificationLogFilterTest.php | 1 + tests/TestCase.php | 193 ++++++++++++++++ 8 files changed, 198 insertions(+), 262 deletions(-) delete mode 100644 database/seeders/SampleTestingDataSeeder.php delete mode 100644 database/seeders/SuperAdminSeeder.php diff --git a/database/seeders/DatabaseSeeder.php b/database/seeders/DatabaseSeeder.php index 7486860..5bb070f 100644 --- a/database/seeders/DatabaseSeeder.php +++ b/database/seeders/DatabaseSeeder.php @@ -14,7 +14,7 @@ class DatabaseSeeder extends Seeder * Mengisi data master esensial sistem: * 1. Master Pos Gerbang (15 Pos) * 2. RBAC Roles & Permissions - * 3. 4 Akun Utama Administrator (Super Admin, HSE, QMA, PG) - Kredensial via .env + * 3. 4 Akun Utama Administrator (Super Admin, HSE, QMA, PG) - Kredensial murni dari .env * 4. 28 Master Template Checksheet P2H & 282 Item Pertanyaan */ public function run(): void @@ -80,11 +80,5 @@ class DatabaseSeeder extends Seeder // 4. Seed 28 Master Template Checksheet P2H Unit Support & Pertanyaan Pemeriksaan $this->call(P2hTemplateSeeder::class); - - // 5. Seed Data Uji Coba Lapangan (Hanya dijalankan di testing atau jika SEED_SAMPLE_DATA=true di .env) - $seedSamples = app()->environment('testing') || filter_var(env('SEED_SAMPLE_DATA', false), FILTER_VALIDATE_BOOLEAN); - if ($seedSamples) { - $this->call(SampleTestingDataSeeder::class); - } } } diff --git a/database/seeders/SampleTestingDataSeeder.php b/database/seeders/SampleTestingDataSeeder.php deleted file mode 100644 index 3aaf48c..0000000 --- a/database/seeders/SampleTestingDataSeeder.php +++ /dev/null @@ -1,222 +0,0 @@ -keyBy('code'); - - // 2. Seed Sample Satpam PG - $guardData = [ - ['badge_id' => 'SEC-001', 'name' => 'Ahmad Fauzi', 'team' => 1, 'gate' => 'BTUNGGAL'], - ['badge_id' => 'SEC-002', 'name' => 'Budi Santoso', 'team' => 2, 'gate' => 'ADIT1'], - ['badge_id' => 'SEC-003', 'name' => 'Hendra Pratama', 'team' => 3, 'gate' => 'REGWEIR'], - ['badge_id' => 'SEC-004', 'name' => 'Rusli Efendi', 'team' => 1, 'gate' => 'ADIT2'], - ['badge_id' => 'SEC-005', 'name' => 'Slamet Widodo', 'team' => 2, 'gate' => 'ADIT3'], - ]; - - foreach ($guardData as $g) { - $gateModel = $createdGates[$g['gate']] ?? Gate::first(); - $guardUser = User::firstOrCreate([ - 'username' => $g['badge_id'], - ], [ - 'name' => $g['name'], - 'email' => strtolower($g['badge_id']) . '@kmh.co.id', - 'password' => Hash::make($defaultPassword), - 'role' => 'gate_officer', - 'gate_id' => $gateModel?->id, - ]); - - if (!$guardUser->hasRole('gate_officer')) { - $guardUser->assignRole('gate_officer'); - } - - SecurityGuard::firstOrCreate([ - 'badge_id' => $g['badge_id'], - ], [ - 'name' => $g['name'], - 'team' => $g['team'], - 'gate_id' => $gateModel?->id, - 'user_id' => $guardUser->id, - 'is_active' => true, - ]); - } - - // 3. Seed Sample Karyawan & Driver (Khusus Uji Coba) - $employeesData = [ - [ - 'nik' => 'KMH-2022-001', - 'name' => 'Eka Sufiatna', - 'unit_kerja' => 'Teknik', - 'division' => 'INFORMATION & TECHNOLOGY', - 'position' => 'IT Division Coordinator', - 'is_operator' => true, - 'simper_expired_at' => Carbon::now()->addMonths(8), - ], - [ - 'nik' => 'KMH-2022-045', - 'name' => 'Wanturi', - 'unit_kerja' => 'Umum', - 'division' => 'GA', - 'position' => 'Driver Operasional', - 'is_operator' => true, - 'simper_expired_at' => Carbon::now()->addMonths(4), - ], - [ - 'nik' => 'KMH-2023-012', - 'name' => 'Randi Kurniawan', - 'unit_kerja' => 'Pembangkit', - 'division' => 'Mechanical', - 'position' => 'Operator Lapangan', - 'is_operator' => true, - 'simper_expired_at' => Carbon::now()->subDays(14), - ], - [ - 'nik' => 'KMH-2021-088', - 'name' => 'Siti Rahma', - 'unit_kerja' => 'Umum', - 'division' => 'Keuangan', - 'position' => 'Staff Finance', - 'is_operator' => false, - 'simper_expired_at' => null, - ], - ]; - - foreach ($employeesData as $emp) { - $empUser = User::firstOrCreate([ - 'username' => $emp['nik'], - ], [ - 'name' => $emp['name'], - 'email' => strtolower(str_replace(['-', ' '], '', $emp['nik'])) . '@kmh.co.id', - 'password' => Hash::make($defaultPassword), - 'role' => 'employee', - ]); - - if (!$empUser->hasRole('employee')) { - $empUser->assignRole('employee'); - } - - $emp['user_id'] = $empUser->id; - Employee::firstOrCreate(['nik' => $emp['nik']], $emp); - } - - // 5. Seed Sample Light Vehicles - Vehicle::firstOrCreate([ - 'code' => 'LV62', - ], [ - 'category' => 'light_vehicle', - 'brand_type' => 'MITSUBISHI - L300 - PICK UP', - 'license_plate' => 'BH 8893 DI', - 'ownership' => 'EKA SUFIATNA', - 'division' => 'IT', - 'status' => 'Operation', - 'current_km' => 12500.00, - ]); - - Vehicle::firstOrCreate([ - 'code' => 'LV01', - ], [ - 'category' => 'light_vehicle', - 'brand_type' => 'TOYOTA HILUX 4X4 DC', - 'license_plate' => 'BH 1024 AB', - 'ownership' => 'PT Kerinci Merangin Hidro', - 'division' => 'HSE', - 'status' => 'Operation', - 'current_km' => 45200.00, - ]); - - Vehicle::firstOrCreate([ - 'code' => 'LV15', - ], [ - 'category' => 'light_vehicle', - 'brand_type' => 'ISUZU D-MAX 4X4', - 'license_plate' => 'BH 9012 CD', - 'ownership' => 'Divisi Bendungan', - 'division' => 'Bendungan', - 'status' => 'Standby', - 'current_km' => 28350.00, - ]); - - // 6. Seed Sample Unit Support - Vehicle::firstOrCreate([ - 'code' => 'EX01', - ], [ - 'category' => 'unit_support', - 'brand_type' => 'KOMATSU PC200-8', - 'unit_category' => 'Excavator', - 'unit_type' => 'Hydraulic Excavator', - 'brand' => 'Komatsu', - 'model_number' => 'PC200-8M0', - 'production_year' => 2021, - 'ownership' => 'PT KMH - Project', - 'division' => 'Civil & Inviro', - 'location' => 'Beringin Tunggal / Tunnel #2', - 'status' => 'Operation', - 'current_km' => 3450.00, - 'fuel_consumption' => 18.50, - 'silo_document' => 'SILO-KMH-2024/091', - 'stnk_document' => 'STNK-BH-EX01', - 'pajak_document' => 'PAJAK-2026/12', - 'kir_document' => 'KIR-2026/08', - ]); - - Vehicle::firstOrCreate([ - 'code' => 'CR01', - ], [ - 'category' => 'unit_support', - 'brand_type' => 'KATO SR-250R', - 'unit_category' => 'Mobile Crane', - 'unit_type' => 'Rough Terrain Crane 25T', - 'brand' => 'Kato', - 'model_number' => 'SR-250R', - 'production_year' => 2019, - 'ownership' => 'PT Kerinci Merangin Hidro', - 'division' => 'Mechanical', - 'location' => 'CCR DAM / Spillway', - 'status' => 'Operation', - 'current_km' => 1820.00, - 'fuel_consumption' => 14.20, - 'silo_document' => 'SILO-KMH-2025/112', - 'kir_document' => 'KIR-2026/10', - ]); - - Vehicle::firstOrCreate([ - 'code' => 'DT02', - ], [ - 'category' => 'unit_support', - 'brand_type' => 'MITSUBISHI FUSO FIGHTER FN62F', - 'license_plate' => 'BH 8412 AA', - 'unit_category' => 'Dump Truck', - 'unit_type' => 'Dump Truck 20 Ton', - 'brand' => 'Mitsubishi Fuso', - 'model_number' => 'FN62F HD', - 'production_year' => 2022, - 'ownership' => 'PT KMH - Project', - 'division' => 'Civil & Inviro', - 'location' => 'Quarry & Disposal Area', - 'status' => 'Standby', - 'current_km' => 14800.00, - 'fuel_consumption' => 28.00, - 'stnk_document' => 'STNK-BH-8412-AA', - 'kir_document' => 'KIR-2026/11', - ]); - } -} diff --git a/database/seeders/SuperAdminSeeder.php b/database/seeders/SuperAdminSeeder.php deleted file mode 100644 index 4ccb2e2..0000000 --- a/database/seeders/SuperAdminSeeder.php +++ /dev/null @@ -1,33 +0,0 @@ - $superAdminConfig['username']], - [ - 'name' => $superAdminConfig['name'] ?? 'Super Administrator', - 'email' => $superAdminConfig['email'] ?? 'superadmin@kmh.co.id', - 'password' => Hash::make($superAdminConfig['password']), - 'role' => 'super_admin', - ] - ); - - if (!$superAdmin->hasRole('super_admin')) { - $superAdmin->assignRole('super_admin'); - } - } - } -} diff --git a/tests/Feature/AuthenticationTest.php b/tests/Feature/AuthenticationTest.php index 5ff2bb9..a50b0d3 100644 --- a/tests/Feature/AuthenticationTest.php +++ b/tests/Feature/AuthenticationTest.php @@ -14,6 +14,7 @@ class AuthenticationTest extends TestCase { parent::setUp(); $this->seed(); + $this->seedSampleData(); } /** diff --git a/tests/Feature/SecurityGuardFilterTest.php b/tests/Feature/SecurityGuardFilterTest.php index 6d7f74f..c19246f 100644 --- a/tests/Feature/SecurityGuardFilterTest.php +++ b/tests/Feature/SecurityGuardFilterTest.php @@ -18,6 +18,7 @@ class SecurityGuardFilterTest extends TestCase { parent::setUp(); $this->seed(); + $this->seedSampleData(); $this->adminPg = User::where('role', 'pg_admin')->first(); } diff --git a/tests/Feature/VehicleActivityTest.php b/tests/Feature/VehicleActivityTest.php index 0741c4a..dafabdd 100644 --- a/tests/Feature/VehicleActivityTest.php +++ b/tests/Feature/VehicleActivityTest.php @@ -22,6 +22,7 @@ class VehicleActivityTest extends TestCase // Seed data dasar $this->seed(); + $this->seedSampleData(); } public function test_form_qr_loads_successfully_for_light_vehicle(): void diff --git a/tests/Feature/VerificationLogFilterTest.php b/tests/Feature/VerificationLogFilterTest.php index 6395a81..a5ad4f0 100644 --- a/tests/Feature/VerificationLogFilterTest.php +++ b/tests/Feature/VerificationLogFilterTest.php @@ -23,6 +23,7 @@ class VerificationLogFilterTest extends TestCase { parent::setUp(); $this->seed(); + $this->seedSampleData(); $this->adminPg = User::where('role', 'pg_admin')->first(); $vehicle = Vehicle::first(); diff --git a/tests/TestCase.php b/tests/TestCase.php index 8579a24..2c9574a 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -2,8 +2,15 @@ namespace Tests; +use App\Models\Employee; +use App\Models\Gate; +use App\Models\SecurityGuard; +use App\Models\User; +use App\Models\Vehicle; +use Carbon\Carbon; use Database\Seeders\RolePermissionSeeder; use Illuminate\Foundation\Testing\TestCase as BaseTestCase; +use Illuminate\Support\Facades\Hash; use Illuminate\Support\Facades\Schema; abstract class TestCase extends BaseTestCase @@ -16,4 +23,190 @@ abstract class TestCase extends BaseTestCase $this->seed(RolePermissionSeeder::class); } } + + /** + * Helper khusus test suite untuk menyiapkan sample testing mock data + * (Pengganti seeder uji coba agar folder database/seeders tetap murni master data). + */ + protected function seedSampleData(): void + { + // 1. Seed Master Gates + if (Gate::count() === 0) { + $gateList = [ + ['code' => 'ADIT1', 'name' => 'Adit 1'], + ['code' => 'ADIT2', 'name' => 'Adit 2'], + ['code' => 'ADIT3', 'name' => 'Adit 3'], + ['code' => 'BDG6', 'name' => 'Bedeng 6'], + ['code' => 'BTUNGGAL', 'name' => 'Beringin Tunggal'], + ['code' => 'CCRDAM', 'name' => 'CCR DAM'], + ['code' => 'CRESTDAM', 'name' => 'Crest DAM'], + ['code' => 'JAKON', 'name' => 'Dermaga Jakon'], + ['code' => 'GUDANG', 'name' => 'Gudang Induk'], + ['code' => 'KUMUN', 'name' => 'Mess Kumun'], + ['code' => 'PHOFFICE', 'name' => 'PH - Office'], + ['code' => 'PHUTAMA', 'name' => 'PH - Utama'], + ['code' => 'REGWEIR', 'name' => 'Regulating Weir'], + ['code' => 'VSHAFT', 'name' => 'Vertical Shaft'], + ['code' => 'VSTPST', 'name' => 'VS - TPST'], + ]; + + foreach ($gateList as $g) { + Gate::firstOrCreate(['code' => $g['code']], ['name' => $g['name'], 'is_active' => true]); + } + } + + // 2. Seed Mock Satpam Guards + $createdGates = Gate::all()->keyBy('code'); + $guardData = [ + ['badge_id' => 'SEC-001', 'name' => 'Ahmad Fauzi', 'team' => 1, 'gate' => 'BTUNGGAL'], + ['badge_id' => 'SEC-002', 'name' => 'Budi Santoso', 'team' => 2, 'gate' => 'ADIT1'], + ['badge_id' => 'SEC-003', 'name' => 'Hendra Pratama', 'team' => 3, 'gate' => 'REGWEIR'], + ['badge_id' => 'SEC-004', 'name' => 'Rusli Efendi', 'team' => 1, 'gate' => 'ADIT2'], + ['badge_id' => 'SEC-005', 'name' => 'Slamet Widodo', 'team' => 2, 'gate' => 'ADIT3'], + ]; + + foreach ($guardData as $g) { + $gateModel = $createdGates[$g['gate']] ?? Gate::first(); + $guardUser = User::firstOrCreate([ + 'username' => $g['badge_id'], + ], [ + 'name' => $g['name'], + 'email' => strtolower($g['badge_id']) . '@kmh.co.id', + 'password' => Hash::make('password'), + 'role' => 'gate_officer', + 'gate_id' => $gateModel?->id, + ]); + + if (!$guardUser->hasRole('gate_officer')) { + $guardUser->assignRole('gate_officer'); + } + + SecurityGuard::firstOrCreate([ + 'badge_id' => $g['badge_id'], + ], [ + 'name' => $g['name'], + 'team' => $g['team'], + 'gate_id' => $gateModel?->id, + 'user_id' => $guardUser->id, + 'is_active' => true, + ]); + } + + // 3. Seed Mock Employees + $employeesData = [ + [ + 'nik' => 'KMH-2022-001', + 'name' => 'Eka Sufiatna', + 'unit_kerja' => 'Teknik', + 'division' => 'INFORMATION & TECHNOLOGY', + 'position' => 'IT Division Coordinator', + 'is_operator' => true, + 'simper_expired_at' => Carbon::now()->addMonths(8), + ], + [ + 'nik' => 'KMH-2022-045', + 'name' => 'Wanturi', + 'unit_kerja' => 'Umum', + 'division' => 'GA', + 'position' => 'Driver Operasional', + 'is_operator' => true, + 'simper_expired_at' => Carbon::now()->addMonths(4), + ], + [ + 'nik' => 'KMH-2023-012', + 'name' => 'Randi Kurniawan', + 'unit_kerja' => 'Pembangkit', + 'division' => 'Mechanical', + 'position' => 'Operator Lapangan', + 'is_operator' => true, + 'simper_expired_at' => Carbon::now()->subDays(14), + ], + [ + 'nik' => 'KMH-2021-088', + 'name' => 'Siti Rahma', + 'unit_kerja' => 'Umum', + 'division' => 'Keuangan', + 'position' => 'Staff Finance', + 'is_operator' => false, + 'simper_expired_at' => null, + ], + ]; + + foreach ($employeesData as $emp) { + $empUser = User::firstOrCreate([ + 'username' => $emp['nik'], + ], [ + 'name' => $emp['name'], + 'email' => strtolower(str_replace(['-', ' '], '', $emp['nik'])) . '@kmh.co.id', + 'password' => Hash::make('password'), + 'role' => 'employee', + ]); + + if (!$empUser->hasRole('employee')) { + $empUser->assignRole('employee'); + } + + $emp['user_id'] = $empUser->id; + Employee::firstOrCreate(['nik' => $emp['nik']], $emp); + } + + // 4. Seed Mock Vehicles + Vehicle::firstOrCreate([ + 'code' => 'LV62', + ], [ + 'category' => 'light_vehicle', + 'brand_type' => 'MITSUBISHI - L300 - PICK UP', + 'license_plate' => 'BH 8893 DI', + 'ownership' => 'EKA SUFIATNA', + 'division' => 'IT', + 'status' => 'Operation', + 'current_km' => 12500.00, + ]); + + Vehicle::firstOrCreate([ + 'code' => 'LV01', + ], [ + 'category' => 'light_vehicle', + 'brand_type' => 'TOYOTA HILUX 4X4 DC', + 'license_plate' => 'BH 1024 AB', + 'ownership' => 'PT Kerinci Merangin Hidro', + 'division' => 'HSE', + 'status' => 'Operation', + 'current_km' => 45200.00, + ]); + + Vehicle::firstOrCreate([ + 'code' => 'LV15', + ], [ + 'category' => 'light_vehicle', + 'brand_type' => 'ISUZU D-MAX 4X4', + 'license_plate' => 'BH 9012 CD', + 'ownership' => 'Divisi Bendungan', + 'division' => 'Bendungan', + 'status' => 'Standby', + 'current_km' => 28350.00, + ]); + + Vehicle::firstOrCreate([ + 'code' => 'EX01', + ], [ + 'category' => 'unit_support', + 'brand_type' => 'KOMATSU PC200-8', + 'unit_category' => 'Excavator', + 'unit_type' => 'Hydraulic Excavator', + 'brand' => 'Komatsu', + 'model_number' => 'PC200-8M0', + 'production_year' => 2021, + 'ownership' => 'PT KMH - Project', + 'division' => 'Civil & Inviro', + 'location' => 'Beringin Tunggal / Tunnel #2', + 'status' => 'Operation', + 'current_km' => 3450.00, + 'fuel_consumption' => 18.50, + 'silo_document' => 'SILO-KMH-2024/091', + 'stnk_document' => 'STNK-BH-EX01', + 'pajak_document' => 'PAJAK-2026/12', + 'kir_document' => 'KIR-2026/08', + ]); + } }