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.

3.8 KB
Raw Blame
import { describe, expect, it } from 'vitest';
import {
  AUDIT_REFRESH_BUTTON_CLASS,
  AUDIT_EVENT_CONFIG_CHANGE_LABEL,
  AUDIT_EVENT_FILTER_ALL_LABEL,
  AUDIT_SUCCESS_FILTER_FAILED_ONLY_LABEL,
  AUDIT_SUCCESS_FILTER_SUCCESS_ONLY_LABEL,
  AUDIT_TOOLBAR_BUTTON_CLASS,
  AUDIT_VERIFY_ALL_BUTTON_CLASS,
  AUDIT_VERIFY_ROW_BUTTON_CLASS,
  AUDIT_VERIFICATION_FILTER_ALL_LABEL,
  AUDIT_VERIFICATION_FILTER_NEEDS_LABEL,
  getAuditEventStatusPresentation,
  getAuditEventTypeBadgeClass,
  getAuditLogFetchErrorMessage,
  getAuditLogFeatureGateCopy,
  getAuditVerificationBadgePresentation,
} from '@/utils/auditLogPresentation';

describe('auditLogPresentation', () => {
  it('returns canonical event type badge classes', () => {
    expect(getAuditEventTypeBadgeClass('login')).toContain('bg-blue-100');
    expect(getAuditEventTypeBadgeClass('config_change')).toContain('bg-yellow-100');
    expect(getAuditEventTypeBadgeClass('startup')).toContain('bg-green-100');
    expect(getAuditEventTypeBadgeClass('logout')).toContain('bg-surface-alt');
  });

  it('returns canonical verification badge presentation', () => {
    expect(getAuditVerificationBadgePresentation(undefined)).toEqual({
      label: 'Not checked',
      className: 'bg-surface-alt text-base-content',
    });
    expect(getAuditVerificationBadgePresentation({ status: 'verified' })).toEqual({
      label: 'Verified',
      className: 'bg-green-100 text-green-800 dark:bg-green-900/25 dark:text-green-200',
    });
    expect(getAuditVerificationBadgePresentation({ status: 'failed' })).toEqual({
      label: 'Failed',
      className: 'bg-red-100 text-red-800 dark:bg-red-900/25 dark:text-red-200',
    });
  });

  it('returns canonical event status icon presentation', () => {
    expect(getAuditEventStatusPresentation(true)).toMatchObject({
      className: 'w-4 h-4 text-emerald-400',
    });
    expect(getAuditEventStatusPresentation(false)).toMatchObject({
      className: 'w-4 h-4 text-rose-400',
    });
  });

  it('returns paid-runtime feature gate copy when Pro hooks are unavailable', () => {
    expect(getAuditLogFeatureGateCopy({ paidRuntimeRequired: true })).toMatchObject({
      title: 'Pulse Pro runtime required',
      body: expect.stringContaining('private Pulse Pro runtime'),
    });
  });

  it('maps structured audit fetch errors to operator-facing copy', () => {
    expect(getAuditLogFetchErrorMessage({ code: 'audit_store_busy' })).toContain('storage is busy');
    expect(getAuditLogFetchErrorMessage({ code: 'audit_store_unavailable' })).toContain(
      'storage is unavailable',
    );
    expect(getAuditLogFetchErrorMessage({ code: 'query_failed' })).toContain('audit query failure');
    expect(
      getAuditLogFetchErrorMessage(
        new Error('Failed to fetch audit events: Internal Server Error'),
      ),
    ).toContain('internal error');
  });

  it('exposes canonical audit action button classes', () => {
    expect(AUDIT_TOOLBAR_BUTTON_CLASS).toContain('border border-border');
    expect(AUDIT_TOOLBAR_BUTTON_CLASS).toContain('min-h-11 sm:min-h-10');
    expect(AUDIT_REFRESH_BUTTON_CLASS).toContain('text-base-content');
    expect(AUDIT_VERIFY_ALL_BUTTON_CLASS).toContain('text-blue-700');
    expect(AUDIT_VERIFY_ALL_BUTTON_CLASS).toContain('min-h-11 sm:min-h-10');
    expect(AUDIT_VERIFY_ROW_BUTTON_CLASS).toContain('text-blue-600');
    expect(AUDIT_VERIFY_ROW_BUTTON_CLASS).toContain('min-h-11 sm:min-h-10');
  });

  it('exposes canonical audit filter option labels', () => {
    expect(AUDIT_EVENT_FILTER_ALL_LABEL).toBe('All events');
    expect(AUDIT_EVENT_CONFIG_CHANGE_LABEL).toBe('Config change');
    expect(AUDIT_SUCCESS_FILTER_SUCCESS_ONLY_LABEL).toBe('Success only');
    expect(AUDIT_SUCCESS_FILTER_FAILED_ONLY_LABEL).toBe('Failed only');
    expect(AUDIT_VERIFICATION_FILTER_ALL_LABEL).toBe('All verification');
    expect(AUDIT_VERIFICATION_FILTER_NEEDS_LABEL).toBe('Needs verification');
  });
});