waterSupplyThreshold.test.mjs 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. import test from 'node:test'
  2. import assert from 'node:assert/strict'
  3. import {
  4. buildThresholdQuery,
  5. buildThresholdSavePayload,
  6. buildThresholdUpdatePayload
  7. } from '../src/utils/waterSupplyUiModel.js'
  8. test('builds the flat batch-save contract expected by the threshold API', () => {
  9. const payload = buildThresholdSavePayload({
  10. id: 'draft-id',
  11. deviceCodes: [' WS-FLOW-1 ', '', 'WS-FLOW-2', 'WS-FLOW-1'],
  12. warningType: ' 流量预警 ',
  13. warningCode: ' WARN-FLOW ',
  14. minValue: '20',
  15. maxValue: '40',
  16. periodStart: '08:00',
  17. periodEnd: '20:00',
  18. remark: ' 高峰期阈值 '
  19. })
  20. assert.deepEqual(payload, {
  21. deviceCodes: ['WS-FLOW-1', 'WS-FLOW-2'],
  22. warningType: '流量预警',
  23. warningCode: 'WARN-FLOW',
  24. minValue: 20,
  25. maxValue: 40,
  26. periodStart: '08:00',
  27. periodEnd: '20:00',
  28. remark: '高峰期阈值'
  29. })
  30. })
  31. test('builds an update payload that preserves the threshold id', () => {
  32. const payload = buildThresholdUpdatePayload({
  33. id: 'threshold-id',
  34. deviceCode: 'WS-FLOW-1',
  35. warningType: '流量预警',
  36. warningCode: 'WARN-FLOW',
  37. minValue: 20,
  38. maxValue: 40,
  39. periodStart: '08:00',
  40. periodEnd: '20:00',
  41. createTime: '2026-09-02 10:00:00'
  42. })
  43. assert.deepEqual(payload, {
  44. id: 'threshold-id',
  45. deviceCode: 'WS-FLOW-1',
  46. warningType: '流量预警',
  47. warningCode: 'WARN-FLOW',
  48. minValue: 20,
  49. maxValue: 40,
  50. periodStart: '08:00',
  51. periodEnd: '20:00'
  52. })
  53. })
  54. test('builds threshold list filters without alarm-only fields', () => {
  55. const query = buildThresholdQuery({
  56. pageNum: 2,
  57. pageSize: 20,
  58. deviceCode: 'WS-FLOW-1',
  59. warningType: '流量预警',
  60. keyword: ' ',
  61. alarmLevel: 2,
  62. alarmStatus: 0
  63. })
  64. assert.deepEqual(query, {
  65. pageNum: 2,
  66. pageSize: 20,
  67. deviceCode: 'WS-FLOW-1',
  68. warningType: '流量预警'
  69. })
  70. })