Files

47 lines
1.5 KiB
TypeScript
Raw Permalink Normal View History

import { expect, tap } from '@git.zone/tstest/tapbundle';
import { HomeAssistantMikrotikIntegration, type IMikrotikCommand, type IMikrotikConfig } from '../../ts/integrations/mikrotik/index.js';
const config: IMikrotikConfig = {
host: '192.168.88.1',
snapshot: {
connected: true,
router: {
name: 'API Router',
host: '192.168.88.1',
serialNumber: 'MK123456',
actions: ['reboot'],
},
resources: {},
devices: [],
interfaces: [],
sensors: {},
},
};
tap.test('does not fake RouterOS/API command success without injected executor', async () => {
const runtime = await new HomeAssistantMikrotikIntegration().setup(config, {});
const result = await runtime.callService!({ domain: 'mikrotik', service: 'reboot', target: {} });
expect(result.success).toBeFalse();
expect(result.error || '').toInclude('not faked');
await runtime.destroy();
});
tap.test('executes explicit RouterOS/API commands through injected executor', async () => {
let command: IMikrotikCommand | undefined;
const runtime = await new HomeAssistantMikrotikIntegration().setup({
...config,
commandExecutor: async (commandArg) => {
command = commandArg;
return { success: true, data: { accepted: true } };
},
}, {});
const result = await runtime.callService!({ domain: 'mikrotik', service: 'reboot', target: {} });
expect(result.success).toBeTrue();
expect(command?.path).toEqual('/system/reboot');
await runtime.destroy();
});
export default tap.start();