Files
Web_BLS_OnOffLine_Server/bls-onoffline-backend/tests/processor.test.js

46 lines
1.5 KiB
JavaScript
Raw Normal View History

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('');
});
});