feat: 添加 G5 状态表 IP 同步功能,新增 upsert 方法并更新相关测试

This commit is contained in:
2026-03-18 11:51:17 +08:00
parent 381080fee0
commit fa363835a3
7 changed files with 223 additions and 1 deletions

View File

@@ -1,5 +1,5 @@
import { describe, it, expect } from 'vitest';
import { mapCurrentStatusToG5Code } from '../src/db/g5DatabaseManager.js';
import { dedupeRoomStatusSyncRows, mapCurrentStatusToG5Code } from '../src/db/g5DatabaseManager.js';
describe('G5 current_status mapping', () => {
it('maps on/off/restart to numeric codes', () => {
@@ -12,4 +12,16 @@ describe('G5 current_status mapping', () => {
expect(mapCurrentStatusToG5Code('idle')).toBe(0);
expect(mapCurrentStatusToG5Code(null)).toBe(0);
});
it('dedupes room status sync rows by hotel_id and room_id using first row', () => {
const rows = dedupeRoomStatusSyncRows([
{ hotel_id: 101, room_id: '8001', ip: '10.0.0.1:1234' },
{ hotel_id: 101, room_id: '8001', ip: '10.0.0.2:5678' },
{ hotel_id: 101, room_id: '8002', ip: '10.0.0.3:9012' }
]);
expect(rows).toHaveLength(2);
expect(rows[0]).toEqual({ hotel_id: 101, room_id: '8001', ip: '10.0.0.1:1234' });
expect(rows[1]).toEqual({ hotel_id: 101, room_id: '8002', ip: '10.0.0.3:9012' });
});
});