import { mergeAttachmentLocalPaths } from './attachment-persistence.rules';

describe('attachment persistence rules', () => {
  it('keeps incoming local paths when they are set', () => {
    expect(mergeAttachmentLocalPaths(
      { filePath: '/tmp/new.mp4', savedPath: '/data/saved.mp4' },
      { filePath: '/tmp/old.mp4', savedPath: '/data/old.mp4' }
    )).toEqual({
      filePath: '/tmp/new.mp4',
      savedPath: '/data/saved.mp4'
    });
  });

  it('preserves stored local paths when incoming sync metadata omits them', () => {
    expect(mergeAttachmentLocalPaths(
      {},
      { filePath: '/home/ludde/video.mp4', savedPath: '/appdata/video.mp4' }
    )).toEqual({
      filePath: '/home/ludde/video.mp4',
      savedPath: '/appdata/video.mp4'
    });
  });

  it('does not overwrite a stored path with an explicit null', () => {
    expect(mergeAttachmentLocalPaths(
      { filePath: null, savedPath: null },
      { filePath: '/home/ludde/video.mp4', savedPath: '/appdata/video.mp4' }
    )).toEqual({
      filePath: '/home/ludde/video.mp4',
      savedPath: '/appdata/video.mp4'
    });
  });
});
