import { describe, expect, it } from 'vitest';
import { normalizeAllowedModules } from '../../src/lib/admin/module-access';

describe('module access normalization (vitest)', () => {
  it('normalizes explicit enabled modules', () => {
    expect(
      normalizeAllowedModules({
        enabled_modules: ['employee_management', 'approval_management'],
      }),
    ).toEqual(['EMPLOYEE_MANAGEMENT', 'APPROVAL_MANAGEMENT']);
  });

  it('extracts module keys from permissions object', () => {
    expect(
      normalizeAllowedModules({
        permissions: {
          'departments.view': true,
          'external_dashboard_management.update': true,
        },
      }),
    ).toEqual(['DEPARTMENTS', 'EXTERNAL_DASHBOARD_MANAGEMENT']);
  });
});
