Files
Lucas RayanandClaude Sonnet 5.5 640e52c0c9 Initial commit: CraftDock as of 2026-11-01
The previous GitHub history was lost with the account (the local .git was missing
its refs and most objects), so this repository starts from the existing code.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-01 22:44:39 -03:00

31 lines
1011 B
JavaScript

import { describe, it, expect, vi } from 'vitest';
import { createRconService, RconUnavailableError } from '../../src/services/rconService.js';
function fakeRconClass({ failConnect = false } = {}) {
return class {
static async connect() {
if (failConnect) throw new Error('ECONNREFUSED');
return {
send: vi.fn().mockResolvedValue('command output'),
end: vi.fn().mockResolvedValue(),
on: vi.fn(),
};
}
};
}
const config = { rconHost: 'h', rconPort: 25575, rconPassword: 'p' };
describe('rconService', () => {
it('connects lazily and sends a command', async () => {
const svc = createRconService(config, fakeRconClass());
const out = await svc.send('list');
expect(out).toBe('command output');
});
it('throws RconUnavailableError when connect fails', async () => {
const svc = createRconService(config, fakeRconClass({ failConnect: true }));
await expect(svc.send('list')).rejects.toBeInstanceOf(RconUnavailableError);
});
});