2026-03-18 09:47:33 +08:00
|
|
|
import { describe, it, expect } from 'vitest';
|
2026-03-18 11:51:17 +08:00
|
|
|
import { dedupeRoomStatusSyncRows, mapCurrentStatusToG5Code } from '../src/db/g5DatabaseManager.js';
|
2026-03-18 09:47:33 +08:00
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
});
|
2026-03-18 11:51:17 +08:00
|
|
|
|
|
|
|
|
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' });
|
|
|
|
|
});
|
2026-03-18 09:47:33 +08:00
|
|
|
});
|