feat: 添加对 Kafka CurrentStatusrestart 值支持,更新 G5 入库逻辑及相关测试

This commit is contained in:
2026-03-18 09:47:33 +08:00
parent 1329eca99e
commit 381080fee0
9 changed files with 97 additions and 16 deletions

View File

@@ -0,0 +1,15 @@
import { describe, it, expect } from 'vitest';
import { mapCurrentStatusToG5Code } from '../src/db/g5DatabaseManager.js';
describe('G5 current_status mapping', () => {
it('maps on/off/restart to numeric codes', () => {
expect(mapCurrentStatusToG5Code('on')).toBe(1);
expect(mapCurrentStatusToG5Code('off')).toBe(2);
expect(mapCurrentStatusToG5Code('restart')).toBe(3);
});
it('returns 0 for unknown values', () => {
expect(mapCurrentStatusToG5Code('idle')).toBe(0);
expect(mapCurrentStatusToG5Code(null)).toBe(0);
});
});

View File

@@ -26,13 +26,19 @@ describe('Processor Logic', () => {
expect(rows[0].reboot_reason).toBeNull();
});
it('should override current_status to on for reboot data', () => {
const rows = buildRowsFromPayload({ ...basePayload, CurrentStatus: 'off', RebootReason: '0x01' });
it('should preserve restart current_status for reboot data', () => {
const rows = buildRowsFromPayload({ ...basePayload, CurrentStatus: 'restart', RebootReason: '0x01' });
expect(rows).toHaveLength(1);
expect(rows[0].current_status).toBe('on');
expect(rows[0].current_status).toBe('restart');
expect(rows[0].reboot_reason).toBe('0x01');
});
it('should preserve restart current_status for non-reboot data', () => {
const rows = buildRowsFromPayload({ ...basePayload, CurrentStatus: 'restart', RebootReason: null });
expect(rows).toHaveLength(1);
expect(rows[0].current_status).toBe('restart');
});
it('should keep empty optional fields as empty strings', () => {
const rows = buildRowsFromPayload({
...basePayload,