import { test } from 'node:test';
import assert from 'node:assert/strict';
import { TodoStore } from './todo.js';

test('add returns an id', () => {
  const store = new TodoStore();
  const id = store.add('buy milk');
  assert.ok(typeof id === 'number', 'id should be a number');
});

test('list returns all items', () => {
  const store = new TodoStore();
  store.add('task one');
  store.add('task two');
  assert.equal(store.list().length, 2);
});

test('remove deletes an item', () => {
  const store = new TodoStore();
  const id = store.add('delete me');
  store.remove(id);
  assert.equal(store.list().length, 0);
});

test('complete marks item done', () => {
  const store = new TodoStore();
  const id = store.add('buy milk');
  store.complete(id);
  const item = store.list().find(i => i.id === id);
  assert.ok(item, 'item should still exist after completing');
  assert.equal(item.done, true, 'item.done should be true after complete()');
});

test('complete does not affect other items', () => {
  const store = new TodoStore();
  const id1 = store.add('task one');
  const id2 = store.add('task two');
  store.complete(id1);
  const item2 = store.list().find(i => i.id === id2);
  assert.equal(item2.done, false, 'other items should remain undone');
});
