import {
  describe,
  it,
  expect
} from 'vitest';
import { findMissingIds } from './message-sync.rules';

describe('message-sync.rules', () => {
  it('requests ids with newer revision or mismatched head hash', () => {
    const localMap = new Map([['m1', { ts: 10, rc: 0, ac: 0, revision: 1, headHash: 'aaa' }], ['m2', { ts: 10, rc: 0, ac: 0, revision: 2, headHash: 'bbb' }]]);
    const missing = findMissingIds([
      { id: 'm1', ts: 10, rc: 0, ac: 0, revision: 2, headHash: 'ccc' },
      { id: 'm2', ts: 10, rc: 0, ac: 0, revision: 2, headHash: 'bbb' },
      { id: 'm3', ts: 1, rc: 0, ac: 0, revision: 0, headHash: 'ddd' }
    ], localMap);

    expect(missing).toEqual(['m1', 'm3']);
  });
});
