import { describe, it, expect } from 'vitest';
import { logoType, logoContentType } from '@/lib/logo';

const bytes = (...b: number[]) => new Uint8Array([...b, ...new Array(16).fill(0)]);

describe('logo türü', () => {
  it('PNG, JPG ve WEBP dosyalarını içerikten tanır', () => {
    expect(logoType(bytes(0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a))?.ext).toBe('png');
    expect(logoType(bytes(0xff, 0xd8, 0xff, 0xe0))?.ext).toBe('jpg');
    expect(logoType(new Uint8Array([...Buffer.from('RIFF'), 0, 0, 0, 0, ...Buffer.from('WEBP'), 0, 0, 0, 0]))?.ext).toBe('webp');
  });
  it('SVG ve uzantısı değiştirilmiş dosyaları reddeder', () => {
    expect(logoType(new Uint8Array(Buffer.from('<svg xmlns="http://www.w3.org/2000/svg"><script>alert(1)</script></svg>')))).toBeNull();
    expect(logoType(new Uint8Array(Buffer.from('GIF89a........')))).toBeNull();
    expect(logoType(new Uint8Array([]))).toBeNull();
  });
  it('depolama anahtarından içerik türü', () => {
    expect(logoContentType('logos/u/a.png')).toBe('image/png');
    expect(logoContentType('logos/u/a.webp')).toBe('image/webp');
    expect(logoContentType('logos/u/a.jpg')).toBe('image/jpeg');
  });
});
