import { test } from 'node:test';
import assert from 'node:assert/strict';
import { tickets, cases } from './fixtures.mjs';

// BUGGY=1 demonstrates the failing regression test. Otherwise test the fix.
const { selectTickets } = await import(process.env.BUGGY === '1' ? './broken.mjs' : './fixed.mjs');

for (const scenario of cases) {
  test(scenario.name, () => {
    assert.deepEqual(selectTickets(tickets, scenario.options).map(ticket => ticket.id), scenario.expected);
  });
}

test('Empty input returns an empty list', () => {
  assert.deepEqual(selectTickets([], { priority: 0 }), []);
});

test('The input array and tickets stay unchanged', () => {
  const before = JSON.stringify(tickets);
  const selected = selectTickets(tickets, { priority: 2 });
  assert.equal(JSON.stringify(tickets), before);
  assert.notEqual(selected, tickets);
});
