Fix daily_summary dan hourly_summary aggregation, tambah fallback logic untuk dashboard, update validator untuk camera dan location type

This commit is contained in:
mwpn
2025-12-18 11:13:06 +07:00
parent 9416de7d87
commit d05fa2f4cd
31 changed files with 2041 additions and 45 deletions

110
bin/test_api_local.php Normal file
View File

@@ -0,0 +1,110 @@
<?php
declare(strict_types=1);
/**
* Script untuk test API lokal
* Usage: php bin/test_api_local.php [base_url]
* Default: http://localhost:8000
*/
$baseUrl = $argv[1] ?? 'http://localhost:8000';
echo "=== Test API Lokal ===\n";
echo "Base URL: {$baseUrl}\n\n";
$tests = [
[
'name' => 'Health Check',
'method' => 'GET',
'url' => "{$baseUrl}/health",
'headers' => [],
'body' => null
],
[
'name' => 'Login (Invalid - untuk test)',
'method' => 'POST',
'url' => "{$baseUrl}/auth/v1/login",
'headers' => ['Content-Type: application/json'],
'body' => json_encode(['username' => 'test', 'password' => 'test'])
],
[
'name' => 'Get Locations (No Auth - akan 401)',
'method' => 'GET',
'url' => "{$baseUrl}/retribusi/v1/frontend/locations",
'headers' => [],
'body' => null
],
[
'name' => 'Dashboard Summary (No Auth - akan 401)',
'method' => 'GET',
'url' => "{$baseUrl}/retribusi/v1/dashboard/summary",
'headers' => [],
'body' => null
],
[
'name' => 'Realtime Snapshot (No Auth - akan 401)',
'method' => 'GET',
'url' => "{$baseUrl}/retribusi/v1/realtime/snapshot",
'headers' => [],
'body' => null
],
];
foreach ($tests as $test) {
echo "Test: {$test['name']}\n";
echo " URL: {$test['url']}\n";
$ch = curl_init($test['url']);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $test['method']);
if (!empty($test['headers'])) {
curl_setopt($ch, CURLOPT_HTTPHEADER, $test['headers']);
}
if ($test['body'] !== null) {
curl_setopt($ch, CURLOPT_POSTFIELDS, $test['body']);
}
$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$error = curl_error($ch);
curl_close($ch);
if ($error) {
echo " ❌ Error: {$error}\n";
} else {
echo " Status: {$httpCode}\n";
if ($httpCode >= 200 && $httpCode < 300) {
echo " ✅ Success\n";
$data = json_decode($response, true);
if ($data) {
echo " Response: " . json_encode($data, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE) . "\n";
} else {
echo " Response: {$response}\n";
}
} elseif ($httpCode === 401) {
echo " ⚠️ Unauthorized (Expected - butuh JWT token)\n";
} elseif ($httpCode === 422) {
echo " ⚠️ Validation Error (Expected - parameter tidak valid)\n";
$data = json_decode($response, true);
if ($data) {
echo " Response: " . json_encode($data, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE) . "\n";
}
} else {
echo " ❌ Failed\n";
echo " Response: " . substr($response, 0, 200) . "\n";
}
}
echo "\n";
}
echo "=== Test Selesai ===\n";
echo "\nCatatan:\n";
echo "- Status 401 = Normal (butuh JWT token untuk endpoint protected)\n";
echo "- Status 422 = Normal (validation error, parameter tidak valid)\n";
echo "- Status 200 = Endpoint berfungsi dengan baik\n";