refactor(domain): 标注 SoH 来源语义

This commit is contained in:
2026-05-11 22:39:05 +08:00
parent 6ff9dbe772
commit 29e70fea9a
2 changed files with 33 additions and 16 deletions
+5 -1
View File
@@ -44,14 +44,17 @@ describe('battery domain', () => {
expect(response.total).toBe(items.length)
expect(response.lowPower).toBe(1)
expect(response.charging).toBe(1)
expect(response.nextCursor).toBeNull()
expect(response.items[0]?.createTime).toBe('2026-05-10T23:00:00.000Z')
})
test('creates old dashboard aggregate shape from deterministic records', () => {
test('creates dashboard aggregate shape without using power as fake SOH', () => {
const now = new Date('2026-05-11T00:00:00.000Z')
const snapshot = createDashboardSnapshot(rows.map(toBatteryInfo), now)
expect(snapshot.devices).toHaveLength(2)
expect(snapshot.devices.every((device) => device.sohSource === 'unavailable')).toBe(true)
expect(snapshot.devices.every((device) => device.soh === 0)).toBe(true)
expect(snapshot.soh.history).toHaveLength(12)
expect(snapshot.soh.forecast).toHaveLength(4)
expect(snapshot.summary.totalDevices).toBe(snapshot.devices.length)
@@ -87,6 +90,7 @@ describe('battery domain', () => {
const predicted = snapshot.devices.find((device) => device.id === 'RING-A03')
expect(predicted?.soh).toBe(60)
expect(predicted?.sohSource).toBe('prediction')
expect(predicted?.soh30d).toBe(58)
expect(predicted?.soh90d).toBe(52)
expect(predicted?.status).toBe('预警')