import { describe, it, expect } from 'vitest'; import { AvatarFormatter } from './AvatarFormatter'; describe('AvatarFormatter', () => { describe('bufferToBase64', () => { it('should convert ArrayBuffer to base64 string', () => { const buffer = new ArrayBuffer(3); const view = new Uint8Array(buffer); view[0] = 72; // 'H' view[1] = 101; // 'e' view[2] = 108; // 'l' const result = AvatarFormatter.bufferToBase64(buffer); expect(result).toBe('SGVs'); }); it('should handle empty buffer', () => { const buffer = new ArrayBuffer(0); const result = AvatarFormatter.bufferToBase64(buffer); expect(result).toBe(''); }); it('should handle buffer with special characters', () => { const buffer = new ArrayBuffer(4); const view = new Uint8Array(buffer); view[0] = 255; // ÿ view[1] = 254; // Þ view[2] = 253; // Ý view[3] = 252; // Ü const result = AvatarFormatter.bufferToBase64(buffer); expect(result).toBe('/v7+/v4='); }); }); describe('hasValidData', () => { it('should return true for valid buffer and content type', () => { expect(AvatarFormatter.hasValidData('base64data', 'image/png')).toBe(true); }); it('should return false for empty buffer', () => { expect(AvatarFormatter.hasValidData('', 'image/png')).toBe(false); }); it('should return false for empty content type', () => { expect(AvatarFormatter.hasValidData('base64data', '')).toBe(false); }); it('should return false for both empty', () => { expect(AvatarFormatter.hasValidData('', '')).toBe(false); }); }); describe('formatContentType', () => { it('should format image/png to PNG', () => { expect(AvatarFormatter.formatContentType('image/png')).toBe('PNG'); }); it('should format image/jpeg to JPEG', () => { expect(AvatarFormatter.formatContentType('image/jpeg')).toBe('JPEG'); }); it('should format image/gif to GIF', () => { expect(AvatarFormatter.formatContentType('image/gif')).toBe('GIF'); }); it('should handle content type without slash', () => { expect(AvatarFormatter.formatContentType('png')).toBe('png'); }); it('should handle content type with multiple slashes', () => { expect(AvatarFormatter.formatContentType('image/png/test')).toBe('PNG'); }); }); });