Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.
Mirrored from https://github.com/Camo67/composio.git
Synced Nov 21, 04:45 UTC
| 1 | import mime from 'mime'; |
| 2 | import { describe, it, expect } from 'vitest'; |
| 3 | import { getExtensionFromMimeType, MIME_TYPES_BY_EXTENSION } from '../../src/utils/mime'; |
| 4 | |
| 5 | describe('getExtensionFromMimeType', () => { |
| 6 | it('should return extension for known mimetype', () => { |
| 7 | expect(getExtensionFromMimeType('image/png')).toBe('png'); |
| 8 | expect(getExtensionFromMimeType('application/pdf')).toBe('pdf'); |
| 9 | expect(getExtensionFromMimeType('text/csv')).toBe('csv'); |
| 10 | }); |
| 11 | |
| 12 | it.each(['constructor', '__proto__', 'toString', 'hasOwnProperty'])( |
| 13 | 'does not return an Object.prototype member for %j', |
| 14 | mimeType => { |
| 15 | expect(getExtensionFromMimeType(mimeType)).toBe('bin'); |
| 16 | } |
| 17 | ); |
| 18 | }); |
| 19 | |
| 20 | // The CLI's `composio execute` labels local files with the `mime` package, so the |
| 21 | // SDK must send the same type for the same extension. |
| 22 | describe('MIME_TYPES_BY_EXTENSION', () => { |
| 23 | // Extensions the mime package does not know, kept for parity with the Python SDK. |
| 24 | const EXTENSIONS_UNKNOWN_TO_MIME = [ |
| 25 | '3gpp2', |
| 26 | 'ass', |
| 27 | 'h5', |
| 28 | 'ksh', |
| 29 | 'loas', |
| 30 | 'mpa', |
| 31 | 'nws', |
| 32 | 'ppa', |
| 33 | 'pwz', |
| 34 | 'py', |
| 35 | 'pyc', |
| 36 | 'tgz', |
| 37 | 'wiz', |
| 38 | 'xlb', |
| 39 | 'xpdl', |
| 40 | ]; |
| 41 | const known = Object.fromEntries( |
| 42 | Object.entries(MIME_TYPES_BY_EXTENSION).filter( |
| 43 | ([extension]) => !EXTENSIONS_UNKNOWN_TO_MIME.includes(extension) |
| 44 | ) |
| 45 | ); |
| 46 | |
| 47 | it('matches the mime package for every extension it knows', () => { |
| 48 | const fromMimePackage = Object.fromEntries( |
| 49 | Object.keys(known).map(extension => [extension, mime.getType(`file.${extension}`)]) |
| 50 | ); |
| 51 | expect(fromMimePackage).toEqual(known); |
| 52 | }); |
| 53 | |
| 54 | it('adds only extensions the mime package does not know', () => { |
| 55 | const fromMimePackage = EXTENSIONS_UNKNOWN_TO_MIME.map(extension => |
| 56 | mime.getType(`file.${extension}`) |
| 57 | ); |
| 58 | expect(fromMimePackage).toEqual(EXTENSIONS_UNKNOWN_TO_MIME.map(() => null)); |
| 59 | }); |
| 60 | }); |