import test from 'node:test';
import assert from 'node:assert/strict';
import { normalizeAllowedModules } from './module-access.ts';

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

  assert.deepEqual(modules, ['EMPLOYEE_MANAGEMENT', 'APPROVAL_MANAGEMENT']);
});

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

  assert.deepEqual(modules, ['DEPARTMENTS', 'EXTERNAL_DASHBOARD_MANAGEMENT']);
});

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

  assert.deepEqual(modules, ['INTERNAL_DASHBOARD_CONFIG', 'VERIFICATIONS']);
});
