<?php
// tests/test-reports.php — Verify reports list returns correct structure
require_once __DIR__ . '/run.php';

$base    = defined('TEST_BASE_URL') ? TEST_BASE_URL : 'http://localhost/supercerebro';
$session = defined('TEST_SESSION_COOKIE') ? TEST_SESSION_COOKIE : '';

if (!$session) {
    dm_skip('test-reports', 'TEST_SESSION_COOKIE not set — skipping authenticated tests');
    return;
}

$ch = curl_init("{$base}/api/reports.php?action=list&client_id=1");
curl_setopt_array($ch, [
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_TIMEOUT        => 15,
    CURLOPT_HTTPHEADER     => ["Cookie: {$session}"],
]);
$raw  = curl_exec($ch);
$code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);

dm_assert('reports list HTTP 200', $code === 200, "Got HTTP {$code}");

$json = json_decode($raw, true);
dm_assert('reports list ok:true',  !empty($json['ok']),      'Missing ok:true');
dm_assert('reports list has array', isset($json['reports']) && is_array($json['reports']), 'Missing reports array');
