test: script de validación endpoints ROSABLANCA
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 4.6
parent
fe4e638667
commit
4b710ef33b
@@ -0,0 +1,95 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
$BASE = 'https://app.palmas360.com/rosablanca/php/controller/controller_api_externa.php';
|
||||
$KEY = '39630f8c4743ac0dba3cecb781bc4c0608ba77f7576f74831d779c42c596e7f0';
|
||||
$TODAY = date('Y-m-d');
|
||||
$M1 = date('Y-m-01');
|
||||
|
||||
function hit(string $label, string $url, string $key): void
|
||||
{
|
||||
$ch = curl_init($url);
|
||||
curl_setopt_array($ch, [
|
||||
CURLOPT_RETURNTRANSFER => true,
|
||||
CURLOPT_TIMEOUT => 20,
|
||||
CURLOPT_HTTPHEADER => ["Authorization: Bearer {$key}", 'Accept: application/json'],
|
||||
]);
|
||||
$body = curl_exec($ch);
|
||||
$code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||||
$type = curl_getinfo($ch, CURLINFO_CONTENT_TYPE);
|
||||
$err = curl_error($ch);
|
||||
curl_close($ch);
|
||||
|
||||
if ($err) { echo "❌ [{$label}] cURL: {$err}\n"; return; }
|
||||
|
||||
$isPdf = str_contains($type, 'pdf');
|
||||
$isXls = str_contains($type, 'spreadsheet') || str_contains($type, 'excel');
|
||||
$isJson = str_contains($type, 'json');
|
||||
|
||||
if ($isPdf || $isXls) {
|
||||
$ext = $isPdf ? 'PDF' : 'EXCEL';
|
||||
$size = round(strlen($body) / 1024, 1);
|
||||
echo "✅ [{$label}] HTTP {$code} → {$ext} {$size} KB\n";
|
||||
return;
|
||||
}
|
||||
|
||||
$d = json_decode($body, true);
|
||||
$status = $d['status'] ?? '?';
|
||||
if ($code === 200 && in_array($status, ['1', 'sin_datos'])) {
|
||||
$msg = $d['message'] ?? $d['mensaje'] ?? $d['mensaje'] ?? '';
|
||||
echo "✅ [{$label}] HTTP {$code} status={$status} " . mb_substr($msg, 0, 80) . "\n";
|
||||
} else {
|
||||
$msg = $d['mensaje'] ?? $d['message'] ?? mb_substr($body, 0, 120);
|
||||
echo "❌ [{$label}] HTTP {$code} → {$msg}\n";
|
||||
}
|
||||
}
|
||||
|
||||
// ── 1. Fincas (para obtener un finca_id real) ─────────────────────────────
|
||||
echo "\n── Fincas ──\n";
|
||||
$ch = curl_init("{$BASE}?peticion=fincas");
|
||||
curl_setopt_array($ch, [CURLOPT_RETURNTRANSFER=>true, CURLOPT_TIMEOUT=>10,
|
||||
CURLOPT_HTTPHEADER=>["Authorization: Bearer {$KEY}"]]);
|
||||
$raw = curl_exec($ch); curl_close($ch);
|
||||
$fincas = json_decode($raw, true);
|
||||
$fincaId = 0;
|
||||
if (!empty($fincas['fincas'])) {
|
||||
foreach ($fincas['fincas'] as $f) {
|
||||
echo " id={$f['id']} {$f['label']}\n";
|
||||
if ($fincaId === 0) $fincaId = (int)$f['id'];
|
||||
}
|
||||
} else {
|
||||
echo " " . mb_substr($raw, 0, 200) . "\n";
|
||||
}
|
||||
echo " → Usando finca_id={$fincaId} para los tests filtrados\n";
|
||||
|
||||
// ── 2. Ausentismos texto ──────────────────────────────────────────────────
|
||||
echo "\n── Ausentismos texto ──\n";
|
||||
hit('hoy', "{$BASE}?peticion=ausentismos_bot_texto&fecha_desde={$TODAY}&fecha_hasta={$TODAY}", $KEY);
|
||||
hit('semana', "{$BASE}?peticion=ausentismos_bot_texto&fecha_desde=" . date('Y-m-d', strtotime('-7 days')) . "&fecha_hasta={$TODAY}", $KEY);
|
||||
|
||||
// ── 3. Ausentismos PDF ────────────────────────────────────────────────────
|
||||
echo "\n── Ausentismos PDF (mes) ──\n";
|
||||
hit('mes_pdf', "{$BASE}?peticion=ausentismos_bot_pdf&fecha_desde={$M1}&fecha_hasta={$TODAY}", $KEY);
|
||||
|
||||
// ── 4. Producción total texto ─────────────────────────────────────────────
|
||||
echo "\n── Producción total texto ──\n";
|
||||
hit('sin_finca', "{$BASE}?peticion=produccion_total_bot&fecha_desde={$M1}&fecha_hasta={$TODAY}", $KEY);
|
||||
if ($fincaId > 0)
|
||||
hit("finca_{$fincaId}", "{$BASE}?peticion=produccion_total_bot&fecha_desde={$M1}&fecha_hasta={$TODAY}&finca_id={$fincaId}", $KEY);
|
||||
|
||||
// ── 5. Producción total PDF ───────────────────────────────────────────────
|
||||
echo "\n── Producción total PDF ──\n";
|
||||
if ($fincaId > 0)
|
||||
hit("finca_{$fincaId}", "{$BASE}?peticion=produccion_total_pdf_bot&fecha_desde={$M1}&fecha_hasta={$TODAY}&finca_id={$fincaId}", $KEY);
|
||||
|
||||
// ── 6. Producción por lotes Excel ─────────────────────────────────────────
|
||||
echo "\n── Producción lotes Excel ──\n";
|
||||
hit('lotes', "{$BASE}?peticion=produccion_kilos_lotes&fecha_desde={$M1}&fecha_hasta={$TODAY}", $KEY);
|
||||
|
||||
// ── 7. Ciclos existentes ──────────────────────────────────────────────────
|
||||
echo "\n── Ciclos (spot check) ──\n";
|
||||
hit('cosecha', "{$BASE}?peticion=ciclos_cosecha_dn&fecha_desde={$M1}&finca_id={$fincaId}", $KEY);
|
||||
hit('polinizacion',"{$BASE}?peticion=ciclos_polinizacion_dn&fecha_desde={$M1}&finca_id={$fincaId}", $KEY);
|
||||
hit('mantenimiento',"{$BASE}?peticion=mantenimiento_dn&fecha_desde={$M1}&grupo=0&finca_id={$fincaId}", $KEY);
|
||||
|
||||
echo "\n── Fin del test ──\n";
|
||||
Reference in New Issue
Block a user