refactor(domain): 集中电池业务常量
This commit is contained in:
+25
-12
@@ -1,5 +1,13 @@
|
||||
import { describe, expect, test } from 'bun:test'
|
||||
import { createBatteriesResponse, createDashboardSnapshot, getDeviceStatus, toBatteryInfo } from './battery'
|
||||
import {
|
||||
createBatteriesResponse,
|
||||
createDashboardSnapshot,
|
||||
DEVICE_STATUS,
|
||||
getDeviceStatus,
|
||||
MYSQL_BOOLEAN,
|
||||
POWER_STATUS,
|
||||
toBatteryInfo,
|
||||
} from './battery'
|
||||
|
||||
const rows = [
|
||||
{
|
||||
@@ -8,8 +16,8 @@ const rows = [
|
||||
mac: 'RING-A03',
|
||||
devModel: '2401-A',
|
||||
devName: 'RING-A03',
|
||||
isLowPower: 'false',
|
||||
powerStatus: 2,
|
||||
isLowPower: MYSQL_BOOLEAN.FALSE,
|
||||
powerStatus: POWER_STATUS.FULL,
|
||||
power: 94,
|
||||
createTime: new Date('2026-05-10T23:00:00.000Z'),
|
||||
remark: 'v3.8.2',
|
||||
@@ -20,8 +28,8 @@ const rows = [
|
||||
mac: 'RING-B11',
|
||||
devModel: '2402-B',
|
||||
devName: 'RING-B11',
|
||||
isLowPower: 'true',
|
||||
powerStatus: 1,
|
||||
isLowPower: MYSQL_BOOLEAN.TRUE,
|
||||
powerStatus: POWER_STATUS.CHARGING,
|
||||
power: 84,
|
||||
createTime: '2026-05-10 22:00:00',
|
||||
remark: null,
|
||||
@@ -30,9 +38,9 @@ const rows = [
|
||||
|
||||
describe('battery domain', () => {
|
||||
test('preserves legacy SOH status thresholds', () => {
|
||||
expect(getDeviceStatus(91)).toBe('健康')
|
||||
expect(getDeviceStatus(90)).toBe('关注')
|
||||
expect(getDeviceStatus(85)).toBe('预警')
|
||||
expect(getDeviceStatus(91)).toBe(DEVICE_STATUS.HEALTHY)
|
||||
expect(getDeviceStatus(90)).toBe(DEVICE_STATUS.WATCH)
|
||||
expect(getDeviceStatus(85)).toBe(DEVICE_STATUS.WARNING)
|
||||
})
|
||||
|
||||
test('builds batteries response counters from records', () => {
|
||||
@@ -54,10 +62,15 @@ describe('battery domain', () => {
|
||||
|
||||
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.devices.every((device) => device.soh === null)).toBe(true)
|
||||
expect(snapshot.devices.every((device) => device.soh30d === null)).toBe(true)
|
||||
expect(snapshot.devices.every((device) => device.soh90d === null)).toBe(true)
|
||||
expect(snapshot.soh.history).toHaveLength(0)
|
||||
expect(snapshot.soh.forecast).toHaveLength(0)
|
||||
expect(snapshot.summary.totalDevices).toBe(snapshot.devices.length)
|
||||
expect(snapshot.summary.avgSoh).toBeNull()
|
||||
expect(snapshot.summary.avgSoh30d).toBeNull()
|
||||
expect(snapshot.summary.avgSoh90d).toBeNull()
|
||||
expect(snapshot.summary.warningCount + snapshot.summary.watchCount + snapshot.summary.healthyCount).toBe(
|
||||
snapshot.devices.length,
|
||||
)
|
||||
@@ -93,7 +106,7 @@ describe('battery domain', () => {
|
||||
expect(predicted?.sohSource).toBe('prediction')
|
||||
expect(predicted?.soh30d).toBe(58)
|
||||
expect(predicted?.soh90d).toBe(52)
|
||||
expect(predicted?.status).toBe('预警')
|
||||
expect(predicted?.status).toBe(DEVICE_STATUS.WARNING)
|
||||
expect(predicted?.firmware).toBe('XGBoost')
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user