import test from 'node:test';
import assert from 'node:assert/strict';
import { countUnreadNotifications, sortNotificationsNewestFirst } from './notification';

test('countUnreadNotifications counts only rows without readAt', () => {
  assert.equal(countUnreadNotifications([
    { id: 'n-1', readAt: null } as any,
    { id: 'n-2', readAt: '2026-07-08T08:00:00.000Z' } as any,
    { id: 'n-3' } as any,
  ]), 2);
});

test('sortNotificationsNewestFirst keeps newest createdAt first', () => {
  const sorted = sortNotificationsNewestFirst([
    { id: 'old', createdAt: '2026-07-07T08:00:00.000Z' } as any,
    { id: 'new', createdAt: '2026-07-08T08:00:00.000Z' } as any,
  ]);

  assert.deepEqual(sorted.map((item) => item.id), ['new', 'old']);
});
