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

describe('module-access', () => {
  it('normalizeAllowedModules reads explicit module arrays', () => {
    const modules = normalizeAllowedModules({
      enabled_modules: ['employee_management', 'approval_management'],
    });

    expect(modules).toEqual(['EMPLOYEE_MANAGEMENT', 'APPROVAL_MANAGEMENT']);
  });

  it('normalizeAllowedModules derives module keys from permissions object', () => {
    const modules = normalizeAllowedModules({
      permissions: {
        'departments.view': true,
        'external_dashboard_management.update': true,
      },
    });

    expect(modules).toEqual(['DEPARTMENTS', 'EXTERNAL_DASHBOARD_MANAGEMENT']);
  });

  it('normalizeAllowedModules derives module keys from permission keys list', () => {
    const modules = normalizeAllowedModules({
      permission_keys: ['INTERNAL_DASHBOARD_CONFIG:View', 'VERIFICATIONS_VIEW'],
    });

    expect(modules).toEqual(['INTERNAL_DASHBOARD_CONFIG', 'VERIFICATIONS']);
  });
});
