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