Skip to content

armgit / Pulse

Public Imported from GitHub
0

Real-time monitoring dashboard for Proxmox VE, PBS, Docker, Kubernetes, TrueNAS and vSphere. Self-hosted, with alerts for failed backups, full disks, unhealthy containers and offline nodes.

2.0 KB
Raw Blame
import { beforeEach, describe, expect, it, vi } from 'vitest';
vi.mock('@/utils/apiClient', () => ({ apiFetchJSON: vi.fn() }));
import { ResourceActionsAPI } from '@/api/resourceActions';
import { apiFetchJSON } from '@/utils/apiClient';

describe('ResourceActionsAPI durable inbox', () => {
  const fetchJSON = vi.mocked(apiFetchJSON);
  beforeEach(() => fetchJSON.mockReset());

  it('lists canonical pending and settled action views without a local projection', async () => {
    fetchJSON.mockResolvedValue({ view: 'pending', actions: [], count: 0 });
    await ResourceActionsAPI.listActions('pending', 75);
    expect(fetchJSON).toHaveBeenCalledWith('/api/actions?view=pending&limit=75');
  });

  it('loads durable action detail by encoded server action id', async () => {
    fetchJSON.mockResolvedValue({ audit: {}, events: [] });
    await ResourceActionsAPI.getAction('action/one');
    expect(fetchJSON).toHaveBeenCalledWith('/api/actions/action%2Fone');
  });

  it('refreshes the exact reviewed action plan', async () => {
    fetchJSON.mockResolvedValue({ audit: {}, events: [] });
    await ResourceActionsAPI.refreshAction('action/one', ' sha256:reviewed ');
    expect(fetchJSON).toHaveBeenCalledWith('/api/actions/action%2Fone/refresh', {
      method: 'POST',
      body: JSON.stringify({ planHash: 'sha256:reviewed' }),
    });
  });

  it('records a justified operator audit override without a plan hash or resend', async () => {
    fetchJSON.mockResolvedValue({ actionId: 'action/one', state: 'failed' });
    await ResourceActionsAPI.forceFailAction(
      'action/one',
      '  Checked the running container image.  ',
    );
    expect(fetchJSON).toHaveBeenCalledWith('/api/actions/action%2Fone/force-fail', {
      method: 'POST',
      body: JSON.stringify({ reason: 'Checked the running container image.' }),
    });
    await expect(ResourceActionsAPI.forceFailAction('action/one', '  ')).rejects.toThrow(
      'Record what you verified directly',
    );
    expect(fetchJSON).toHaveBeenCalledTimes(1);
  });
});