const test = require('node:test');
const assert = require('node:assert/strict');

const EndpointUtils = require('../src/helper/endpointUtils.js');

test('generateMenuUtilsData returns helpers and compatibility options', () => {
  const endpointUtils = new EndpointUtils();
  const data = endpointUtils.generateMenuUtilsData('measurement', {
    customCheck: 'function(value) { return !!value; }',
  });

  assert.equal(data.nodeName, 'measurement');
  assert.equal(typeof data.helpers.validateRequired, 'string');
  assert.equal(typeof data.helpers.customCheck, 'string');
  assert.equal(data.options.autoLoadLegacy, true);
});

test('generateMenuUtilsBootstrap points to data and legacy endpoints', () => {
  const endpointUtils = new EndpointUtils();
  const script = endpointUtils.generateMenuUtilsBootstrap('measurement');

  assert.match(script, /menuUtilsData\.json/);
  assert.match(script, /menuUtils\.legacy\.js/);
  assert.match(script, /window\.EVOLV\.nodes/);
});

