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

import type { WorkActivity } from './work-activity';
import { mergeWorkActivities } from './work-activity';

function activity(id: string, summary: string): WorkActivity {
  return {
    id,
    actorId: '张三',
    date: '2026-06-26',
    occurredAt: `2026-06-26T0${id.length}:00:00.000Z`,
    sourceType: 'dev_task',
    sourceId: id,
    action: 'dev_task_started',
    category: 'progress',
    title: summary,
    summary,
  };
}

test('mergeWorkActivities preserves remote records and appends local records', () => {
  const merged = mergeWorkActivities([activity('act-1', '远端记录')], [activity('act-2', '本地新增')]);

  assert.deepEqual(merged.map((item) => item.id), ['act-1', 'act-2']);
});

test('mergeWorkActivities lets newer local records replace the same id', () => {
  const merged = mergeWorkActivities([activity('act-1', '远端旧记录')], [activity('act-1', '本地新记录')]);

  assert.equal(merged.length, 1);
  assert.equal(merged[0].summary, '本地新记录');
});
