1 | const getFileType = require('./getFileType')
|
2 |
|
3 | describe('getFileType', () => {
|
4 | it('should trust the filetype if the file comes from a remote source', () => {
|
5 | const file = {
|
6 | isRemote: true,
|
7 | type: 'audio/webm',
|
8 | name: 'foo.webm'
|
9 | }
|
10 | expect(getFileType(file)).toEqual('audio/webm')
|
11 | })
|
12 |
|
13 | it('should determine the filetype from the mimetype', () => {
|
14 | const file = {
|
15 | type: 'audio/webm',
|
16 | name: 'foo.webm',
|
17 | data: 'sdfsdfhq9efbicw'
|
18 | }
|
19 | expect(getFileType(file)).toEqual('audio/webm')
|
20 | })
|
21 |
|
22 | it('should determine the filetype from the extension', () => {
|
23 | const fileMP3 = {
|
24 | name: 'foo.mp3',
|
25 | data: 'sdfsfhfh329fhwihs'
|
26 | }
|
27 | const fileYAML = {
|
28 | name: 'bar.yaml',
|
29 | data: 'sdfsfhfh329fhwihs'
|
30 | }
|
31 | const fileMKV = {
|
32 | name: 'bar.mkv',
|
33 | data: 'sdfsfhfh329fhwihs'
|
34 | }
|
35 | const toUpper = (file) => Object.assign({}, file, { name: file.name.toUpperCase() })
|
36 | expect(getFileType(fileMP3)).toEqual('audio/mp3')
|
37 | expect(getFileType(toUpper(fileMP3))).toEqual('audio/mp3')
|
38 | expect(getFileType(fileYAML)).toEqual('text/yaml')
|
39 | expect(getFileType(toUpper(fileYAML))).toEqual('text/yaml')
|
40 | expect(getFileType(fileMKV)).toEqual('video/x-matroska')
|
41 | expect(getFileType(toUpper(fileMKV))).toEqual('video/x-matroska')
|
42 | })
|
43 |
|
44 | it('should fail gracefully if unable to detect', () => {
|
45 | const file = {
|
46 | name: 'foobar',
|
47 | data: 'sdfsfhfh329fhwihs'
|
48 | }
|
49 | expect(getFileType(file)).toEqual('application/octet-stream')
|
50 | })
|
51 | })
|