t56-latest-live.mjs 1.2 KB

123456789101112131415161718
  1. import assert from 'node:assert/strict'
  2. import { fetchEquipmentDetailAggregate } from '../../../src/modules/cockpit/services/detailApi.js'
  3. import { metricRows, sectionHasContent, sectionPlaceholder } from '../../../src/modules/cockpit/domain/equipmentDetailView.js'
  4. const baseUrl = process.argv[2]
  5. assert.ok(baseUrl, 'Pass the existing cockpit read-only API base URL')
  6. const deviceCode = process.argv[3] || '21119740'
  7. const result = await fetchEquipmentDetailAggregate(deviceCode, {
  8. config: { dataSource: 'real', api: { baseUrl } },
  9. fetchImpl: (url, options) => fetch(url, { ...options, signal: AbortSignal.timeout(15000) }),
  10. })
  11. const metrics = result.data?.sections?.metrics
  12. const rows = metricRows(metrics?.data)
  13. console.log(JSON.stringify({ deviceCode, aggregate: result.state, metrics: metrics?.state, placeholder: sectionPlaceholder(metrics), rows }, null, 2))
  14. assert.ok(sectionHasContent(metrics), `${deviceCode}: latest metrics must render content, not ${sectionPlaceholder(metrics)}`)
  15. assert.ok(rows.some((row) => row.value !== '—'), `${deviceCode}: expected at least one real reading`)
  16. assert.ok(rows.every((row) => row.name && row.sampledAt), 'Every metric must retain its name and source time')
  17. console.log('PASS real detail API -> latest metric rows')