import test from 'node:test';
import assert from 'node:assert/strict';
import {
  DEFAULT_AUTOMATION_CONTEXTS,
  resolveAutomationContexts,
  sanitizeAutomationContexts,
} from './automation-context-config-service.js';

test('default automation contexts include base handling context', () => {
  assert.ok(DEFAULT_AUTOMATION_CONTEXTS.some((item) => item.id === 'none-default'));
});

test('sanitizeAutomationContexts falls back to defaults', () => {
  const items = sanitizeAutomationContexts([]);
  assert.ok(items.some((item) => item.id === 'auto-worker-default'));
});

test('resolveAutomationContexts returns only explicitly selected contexts', () => {
  const contexts = resolveAutomationContexts(
    [
      {
        id: 'ctx-1',
        title: 'A',
        content: 'A',
        enabled: true,
        defaultSelected: true,
        updatedAt: '2026-04-29T00:00:00.000Z',
      },
      {
        id: 'ctx-2',
        title: 'B',
        content: 'B',
        enabled: true,
        defaultSelected: false,
        updatedAt: '2026-04-29T00:00:00.000Z',
      },
    ],
    ['ctx-2'],
  );

  assert.deepEqual(
    contexts.map((item) => item.id),
    ['ctx-2'],
  );
});
