Files
Void-Homelab/tests/actions/proxmox.test.js
2026-06-04 21:40:20 +10:00

21 lines
1.1 KiB
JavaScript

import { describe, it, expect, vi } from 'vitest';
import { powerGuest } from '../../lib/actions/channels/proxmox.js';
describe('proxmox channel', () => {
it('POSTs the scoped power op with the token header', async () => {
const fetchMock = vi.fn(async () => ({ ok: true, status: 200, json: async () => ({ data: 'UPID:...' }) }));
const out = await powerGuest({ node: 'z', vmid: 107, op: 'stop', kindPath: 'lxc' },
{ apiUrl: 'https://pve:8006', token: 'user@pve!void=secret', fetchImpl: fetchMock });
expect(out.ok).toBe(true);
const [url, opts] = fetchMock.mock.calls[0];
expect(url).toBe('https://pve:8006/api2/json/nodes/z/lxc/107/status/stop');
expect(opts.method).toBe('POST');
expect(opts.headers.Authorization).toBe('PVEAPIToken=user@pve!void=secret');
});
it('throws on a non-ok response', async () => {
const fetchMock = vi.fn(async () => ({ ok: false, status: 403, text: async () => 'forbidden' }));
await expect(powerGuest({ node: 'z', vmid: 1, op: 'stop', kindPath: 'lxc' },
{ apiUrl: 'https://pve:8006', token: 't', fetchImpl: fetchMock })).rejects.toThrow(/403/);
});
});