feat: 添加对 Kafka CurrentStatus 的 restart 值支持,更新 G5 入库逻辑及相关测试
This commit is contained in:
15
bls-onoffline-backend/tests/g5DatabaseManager.test.js
Normal file
15
bls-onoffline-backend/tests/g5DatabaseManager.test.js
Normal 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);
|
||||
});
|
||||
});
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user