describe('Services - Hex Conversion', () => { let services: Services; beforeEach(() => { services = new Services(); }); describe('hexToBlob', () => { it('should convert hex string to blob correctly', () => { const hexString = '48656c6c6f20576f726c64'; // "Hello World" in hex const blob = services.hexToBlob(hexString); expect(blob).toBeInstanceOf(Blob); expect(blob.type).toBe('application/octet-stream'); expect(blob.size).toBe(11); // "Hello World" is 11 bytes }); it('should handle empty hex string', () => { const hexString = ''; const blob = services.hexToBlob(hexString); expect(blob).toBeInstanceOf(Blob); expect(blob.size).toBe(0); }); it('should handle single byte hex string', () => { const hexString = '41'; // 'A' in hex const blob = services.hexToBlob(hexString); expect(blob).toBeInstanceOf(Blob); expect(blob.size).toBe(1); }); }); describe('hexToUInt8Array', () => { it('should convert hex string to Uint8Array correctly', () => { const hexString = '48656c6c6f20576f726c64'; // "Hello World" in hex const uint8Array = services.hexToUInt8Array(hexString); expect(uint8Array).toBeInstanceOf(Uint8Array); expect(uint8Array.length).toBe(11); expect(uint8Array[0]).toBe(72); // 'H' ASCII expect(uint8Array[10]).toBe(100); // 'd' ASCII }); it('should throw error for odd length hex string', () => { const hexString = '48656c6c6f20576f726c6'; // Odd length expect(() => { services.hexToUInt8Array(hexString); }).toThrow('Invalid hex string: length must be even'); }); it('should handle empty hex string', () => { const hexString = ''; const uint8Array = services.hexToUInt8Array(hexString); expect(uint8Array).toBeInstanceOf(Uint8Array); expect(uint8Array.length).toBe(0); }); }); describe('blobToHex', () => { it('should convert blob to hex string correctly', async () => { const testData = new Uint8Array([72, 101, 108, 108, 111]); // "Hello" const blob = new Blob([testData], { type: 'text/plain' }); const hexString = await services.blobToHex(blob); expect(hexString).toBe('48656c6c6f'); }); it('should handle empty blob', async () => { const blob = new Blob([], { type: 'text/plain' }); const hexString = await services.blobToHex(blob); expect(hexString).toBe(''); }); }); });