- 新增 Kafka 消费者实现,支持消息处理和错误处理。 - 实现 OffsetTracker 类,用于跟踪消息偏移量。 - 新增消息解析和数据库插入逻辑,支持从 Kafka 消息构建数据库行。 - 实现 UDP 数据包解析功能,支持不同类型的 UDP 消息。 - 新增 Redis 错误队列处理,支持错误重试机制。 - 实现 Redis 客户端和集成类,支持日志记录和心跳机制。 - 添加 Zod 验证模式,确保 Kafka 消息有效性。 - 新增日志记录和指标收集工具,支持系统监控。 - 添加 UUID 生成工具,支持唯一标识符生成。 - 编写处理器逻辑的单元测试,确保功能正确性。 - 配置 Vite 构建工具,支持 Node.js 环境下的构建。
55 lines
1.7 KiB
JavaScript
55 lines
1.7 KiB
JavaScript
import { describe, it, expect } from 'vitest';
|
|
import { buildRowsFromPayload } from '../src/processor/index.js';
|
|
|
|
describe('Register Processor', () => {
|
|
const basePayload = {
|
|
ts_ms: 1770000235000,
|
|
upgrade_ts_ms: 1770001235000,
|
|
hotel_id: 1085,
|
|
room_id: '8888',
|
|
device_id: '091123987456',
|
|
is_send: 0,
|
|
app_version: '2.1.0',
|
|
launcher_version: '1.0.0',
|
|
config_version: 'cfg-v8'
|
|
};
|
|
|
|
it('should map payload into register and room-status rows', () => {
|
|
const rows = buildRowsFromPayload(basePayload);
|
|
|
|
expect(rows.registerRows).toHaveLength(1);
|
|
expect(rows.roomStatusRows).toHaveLength(1);
|
|
|
|
expect(rows.registerRows[0].hotel_id).toBe(1085);
|
|
expect(rows.registerRows[0].room_id).toBe('8888');
|
|
expect(rows.registerRows[0].device_id).toBe('091123987456');
|
|
|
|
expect(rows.roomStatusRows[0].register_ts_ms).toBe(1770000235000);
|
|
expect(rows.roomStatusRows[0].upgrade_ts_ms).toBe(1770001235000);
|
|
});
|
|
|
|
it('should force hotel_id to 0 when out of int2 range', () => {
|
|
const rows = buildRowsFromPayload({ ...basePayload, hotel_id: 60000 });
|
|
expect(rows.registerRows[0].hotel_id).toBe(0);
|
|
expect(rows.roomStatusRows[0].hotel_id).toBe(0);
|
|
});
|
|
|
|
it('should convert udp_raw byte array to base64 text', () => {
|
|
const rows = buildRowsFromPayload({
|
|
...basePayload,
|
|
udp_raw: [1, 2, 3, 4]
|
|
});
|
|
expect(rows.registerRows[0].udp_raw).toBe('AQIDBA==');
|
|
});
|
|
|
|
it('should strip NUL bytes from text fields', () => {
|
|
const rows = buildRowsFromPayload({
|
|
...basePayload,
|
|
app_version: 'v1\u0000\u0000.2',
|
|
room_num_remark: 'A\u0000B'
|
|
});
|
|
expect(rows.registerRows[0].app_version).toBe('v1.2');
|
|
expect(rows.registerRows[0].room_num_remark).toBe('AB');
|
|
});
|
|
});
|