t52-device-source.mjs 2.0 KB

1234567891011121314151617181920212223242526272829303132
  1. import assert from 'node:assert/strict'
  2. import { loadEnhancementDevices } from '../../../src/modules/cockpit/services/enhancementDevices.js'
  3. const points = [
  4. { kind: 'monitoring-point', code: 'A', industry: 'WATER_SUPPLY', deviceCodes: ['D1'] },
  5. { kind: 'monitoring-point', code: 'B', industry: 'GAS', deviceCodes: ['D2'] },
  6. { kind: 'unassociated-equipment', code: 'D3', industry: 'GAS', longitude: 110, latitude: 28, coordinate: { renderable: true } },
  7. ]
  8. const calls = []
  9. const result = await loadEnhancementDevices({ objects: points, phase: 'complete', truncated: false }, {
  10. fetchPoint: async (code) => { calls.push(code); return { state: 'success', data: { code,
  11. devices: [{ code: code === 'A' ? 'D1' : 'D2', longitude: 110, latitude: 28, coordinate: { renderable: true } }] } } },
  12. })
  13. assert.deepEqual(calls.sort(), ['A', 'B'])
  14. assert.equal(result.rows.length, 3)
  15. assert.equal(result.rows.find((d) => d.code === 'D2').industry, 'GAS')
  16. assert.equal(result.rows.find((d) => d.code === 'D1').pointCode, 'A')
  17. assert.equal(result.partial, false)
  18. const partial = await loadEnhancementDevices({ objects: points, phase: 'loading' }, {
  19. fetchPoint: async () => ({ state: 'failed', data: null }),
  20. })
  21. assert.equal(partial.partial, true)
  22. assert.equal(partial.failedPoints, 2)
  23. assert.equal(partial.rows.length, 1)
  24. const extra = await loadEnhancementDevices({ objects: [{ kind: 'monitoring-point', code: 'A', deviceCodes: [] }], phase: 'complete' }, {
  25. fetchPoint: async () => ({ state: 'success', data: { code: 'A', devices: [{ code: 'unexpected' }] } }),
  26. })
  27. assert.equal(extra.extraDevices, 1)
  28. assert.equal(extra.partial, true)
  29. const clipped = await loadEnhancementDevices({ objects: [], total: 10, phase: 'complete' })
  30. assert.equal(clipped.partial, true)
  31. console.log('PASS 缺摘要清单、详情集合不一致与缓存截断均不冒称完整覆盖')
  32. console.log('PASS 读取所有当前快照点位设备和独立设备,保留父点与行业;失败/未完成覆盖不冒称完整')