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>
This commit is contained in:
commit
640e52c0c9
99 files changed
+12115
No files matched your search
@@ -0,0 +1,33 @@
|
||||
import { describe, it, expect, vi } from 'vitest';
|
||||
import { buildStatusPayload } from '../../src/sockets/statusSocket.js';
|
||||
|
||||
describe('buildStatusPayload', () => {
|
||||
it('aggregates state, stats and players when running', async () => {
|
||||
const dockerService = {
|
||||
inspect: vi.fn().mockResolvedValue({ state: 'running', type: 'PAPER' }),
|
||||
stats: vi.fn().mockResolvedValue({ cpuPct: 5, memUsedMb: 256, memPct: 25 }),
|
||||
};
|
||||
const appState = {
|
||||
getAdapter: vi.fn().mockResolvedValue({
|
||||
listPlayers: vi.fn().mockResolvedValue({ online: 2, max: 20, players: ['a', 'b'] }),
|
||||
}),
|
||||
};
|
||||
const payload = await buildStatusPayload({ dockerService, appState });
|
||||
expect(payload).toMatchObject({
|
||||
state: 'running', cpuPct: 5, memPct: 25,
|
||||
players: { online: 2, max: 20, players: ['a', 'b'] },
|
||||
});
|
||||
});
|
||||
|
||||
it('returns zeros and empty players when not running', async () => {
|
||||
const dockerService = {
|
||||
inspect: vi.fn().mockResolvedValue({ state: 'exited', type: 'PAPER' }),
|
||||
stats: vi.fn(),
|
||||
};
|
||||
const appState = { getAdapter: vi.fn() };
|
||||
const payload = await buildStatusPayload({ dockerService, appState });
|
||||
expect(payload.state).toBe('exited');
|
||||
expect(payload.players).toEqual({ online: 0, max: 0, players: [] });
|
||||
expect(dockerService.stats).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user