import test from 'node:test';
import assert from 'node:assert/strict';

import {
  filterRequirementProjectOptions,
  filterRequirementVersionOptions,
} from './requirement';

const projects = [
  { id: 'project-1', name: 'Mobile App', productId: 'product-1' },
  { id: 'project-2', name: 'Admin Portal', productId: 'product-1' },
  { id: 'project-3', name: 'Data Console', productId: 'product-2' },
];

const versions = [
  { id: 'version-1', name: 'V1.0 Checkout', projectId: 'project-1' },
  { id: 'version-2', name: 'V1.1 Profile', projectId: 'project-1' },
  { id: 'version-3', name: 'V2.0 Admin', projectId: 'project-2' },
];

test('filters requirement project options by selected product and keyword', () => {
  assert.deepEqual(filterRequirementProjectOptions(projects, '', '').map((project) => project.id), []);
  assert.deepEqual(filterRequirementProjectOptions(projects, 'product-1', '').map((project) => project.id), [
    'project-1',
    'project-2',
  ]);
  assert.deepEqual(filterRequirementProjectOptions(projects, 'product-1', 'portal').map((project) => project.id), [
    'project-2',
  ]);
});

test('filters requirement version options by selected project and keyword', () => {
  assert.deepEqual(filterRequirementVersionOptions(versions, '', '').map((version) => version.id), []);
  assert.deepEqual(filterRequirementVersionOptions(versions, 'project-1', 'v1').map((version) => version.id), [
    'version-1',
    'version-2',
  ]);
  assert.deepEqual(filterRequirementVersionOptions(versions, 'project-2', 'admin').map((version) => version.id), [
    'version-3',
  ]);
});
