添加 Kafka 消费者、数据库写入、Redis 集成等核心模块,实现设备上下线事件处理 - 创建项目基础目录结构与配置文件 - 实现 Kafka 消费逻辑与手动提交偏移量 - 添加 PostgreSQL 数据库连接与分区表管理 - 集成 Redis 用于错误队列和项目心跳 - 包含数据处理逻辑,区分重启与非重启数据 - 提供数据库初始化脚本与分区创建工具 - 添加单元测试与代码校验脚本
46 lines
1.5 KiB
JavaScript
46 lines
1.5 KiB
JavaScript
import { describe, it, expect } from 'vitest';
|
|
import { buildRowsFromPayload } from '../src/processor/index.js';
|
|
|
|
describe('Processor Logic', () => {
|
|
const basePayload = {
|
|
HotelCode: '1085',
|
|
MAC: '00:1A:2B:3C:4D:5E',
|
|
HostNumber: '091123987456',
|
|
RoomNumber: '8888房',
|
|
EndPoint: '50.2.60.1:6543',
|
|
CurrentStatus: 'off',
|
|
CurrentTime: '2026-02-02T10:30:00Z',
|
|
UnixTime: 1770000235000,
|
|
LauncherVersion: '1.0.0'
|
|
};
|
|
|
|
it('should validate required fields', () => {
|
|
expect(() => buildRowsFromPayload({})).toThrow();
|
|
expect(() => buildRowsFromPayload({ ...basePayload, UnixTime: undefined })).toThrow();
|
|
});
|
|
|
|
it('should use current_status from payload for non-reboot data', () => {
|
|
const rows = buildRowsFromPayload({ ...basePayload, RebootReason: null });
|
|
expect(rows).toHaveLength(1);
|
|
expect(rows[0].current_status).toBe('off');
|
|
expect(rows[0].reboot_reason).toBeNull();
|
|
});
|
|
|
|
it('should override current_status to on for reboot data', () => {
|
|
const rows = buildRowsFromPayload({ ...basePayload, CurrentStatus: 'off', RebootReason: '0x01' });
|
|
expect(rows).toHaveLength(1);
|
|
expect(rows[0].current_status).toBe('on');
|
|
expect(rows[0].reboot_reason).toBe('0x01');
|
|
});
|
|
|
|
it('should keep empty optional fields as empty strings', () => {
|
|
const rows = buildRowsFromPayload({
|
|
...basePayload,
|
|
LauncherVersion: '',
|
|
RebootReason: ''
|
|
});
|
|
expect(rows[0].launcher_version).toBe('');
|
|
expect(rows[0].reboot_reason).toBe('');
|
|
});
|
|
});
|