From 747a86bb94006aaca721cfc0c0ce7061643a9ea6 Mon Sep 17 00:00:00 2001
From: chenyc <501753378@qq.com>
Date: 星期四, 20 八月 2026 12:19:35 +0800
Subject: [PATCH] gx

---
 test/app.test.js |   88 ++++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 84 insertions(+), 4 deletions(-)

diff --git a/test/app.test.js b/test/app.test.js
index 637b81c..3ba5c89 100644
--- a/test/app.test.js
+++ b/test/app.test.js
@@ -1,7 +1,87 @@
 const assert = require('assert');
+const { createOnMetricHandler, getBloodPressureOptions } = require('../app');
 
-describe('应用程序功能测试', () => {
-    it('应该返回正确的结果', () => {
-        assert.strictEqual(1 + 1, 2);
+describe('app', () => {
+  it('defaults blood pressure immediate flush to enabled', () => {
+    assert.deepStrictEqual(getBloodPressureOptions({}), {
+      publishTime: true,
+      flushImmediately: true,
     });
-});
\ No newline at end of file
+
+    assert.deepStrictEqual(getBloodPressureOptions({
+      protocol: {
+        bloodPressure: {
+          publishTime: false,
+          flushImmediately: false,
+        },
+      },
+    }), {
+      publishTime: false,
+      flushImmediately: false,
+    });
+  });
+
+  it('flushes the full cached payload immediately after blood pressure arrives in batch mode', async () => {
+    const calls = [];
+    const handler = createOnMetricHandler({
+      logger: { info() {}, error() {} },
+      sendOptions: { mode: 'batch' },
+      bloodPressureOptions: { flushImmediately: true },
+      aggregator: {
+        ingest: async (device, metric) => {
+          calls.push({ type: 'ingest', deviceId: device.deviceId, metric });
+          return true;
+        },
+        flush: async (options) => {
+          calls.push({ type: 'flush', options });
+          return true;
+        },
+      },
+    });
+
+    await handler(
+      { deviceId: 'JH-001' },
+      { N: 120, O: 80, P: 89, M: '2026-04-30 10:20:30' },
+      { protocol: 'blood-pressure' },
+    );
+
+    assert.deepStrictEqual(calls, [
+      {
+        type: 'ingest',
+        deviceId: 'JH-001',
+        metric: { N: 120, O: 80, P: 89, M: '2026-04-30 10:20:30' },
+      },
+      {
+        type: 'flush',
+        options: { reason: 'blood-pressure', deviceId: 'JH-001' },
+      },
+    ]);
+  });
+
+  it('does not trigger immediate flush for non-blood-pressure metrics', async () => {
+    const calls = [];
+    const handler = createOnMetricHandler({
+      logger: { info() {}, error() {} },
+      sendOptions: { mode: 'batch' },
+      bloodPressureOptions: { flushImmediately: true },
+      aggregator: {
+        ingest: async () => {
+          calls.push('ingest');
+          return true;
+        },
+        flush: async () => {
+          calls.push('flush');
+          return true;
+        },
+      },
+    });
+
+    await handler(
+      { deviceId: 'JH-001' },
+      { F: 36.7 },
+      { protocol: 'jhm' },
+    );
+
+    assert.deepStrictEqual(calls, ['ingest']);
+  });
+});

--
Gitblit v1.8.0