import {
  getWatchedAttachmentRoomIdFromUrl,
  isDirectMessageAttachmentRoomId,
  shouldCopyUploaderMediaToAppData
} from './attachment.logic';

describe('attachment logic', () => {
  it('extracts watched server room ids from room URLs', () => {
    expect(getWatchedAttachmentRoomIdFromUrl('/room/general')).toBe('general');
    expect(getWatchedAttachmentRoomIdFromUrl('/room/general/chat')).toBe('general');
  });

  it('extracts watched direct-message storage ids from DM URLs', () => {
    expect(getWatchedAttachmentRoomIdFromUrl('/dm/alice%3Abob')).toBe('direct-message:alice:bob');
    expect(getWatchedAttachmentRoomIdFromUrl('/pm/dm-group-1?tab=chat')).toBe('direct-message:dm-group-1');
  });

  it('ignores non-message URLs', () => {
    expect(getWatchedAttachmentRoomIdFromUrl('/settings')).toBeNull();
    expect(getWatchedAttachmentRoomIdFromUrl('/dm')).toBeNull();
  });

  it('identifies direct-message attachment storage ids', () => {
    expect(isDirectMessageAttachmentRoomId('direct-message:alice:bob')).toBe(true);
    expect(isDirectMessageAttachmentRoomId('room-1')).toBe(false);
    expect(isDirectMessageAttachmentRoomId(null)).toBe(false);
  });

  it('copies large uploader media into app data when a source path exists', () => {
    expect(shouldCopyUploaderMediaToAppData({
      size: 64 * 1024 * 1024,
      mime: 'video/mp4'
    }, '/home/ludde/video.mp4', true)).toBe(true);
  });

  it('skips app-data copy for small uploads and missing source paths', () => {
    expect(shouldCopyUploaderMediaToAppData({
      size: 1024,
      mime: 'video/mp4'
    }, '/home/ludde/video.mp4', true)).toBe(false);

    expect(shouldCopyUploaderMediaToAppData({
      size: 64 * 1024 * 1024,
      mime: 'video/mp4'
    }, undefined, true)).toBe(false);
  });
});
