Browse Source

fix tests

I unfortunately can’t seem to understand this test: `should execute all
the postprocessors when uploading a file` in Core.test.js:
https://github.com/transloadit/uppy/blob/6bee4f427f911cf7aef8280cefed35f
eb771774b/src/core/Core.test.js#L388

@richardwillars could you please help explain why the fileID is used
there and how, and if it’s wrong to change it the way I did here?
Artur Paikin 7 years ago
parent
commit
80636d125c
3 changed files with 8 additions and 6 deletions
  1. 3 2
      src/core/Core.test.js
  2. 0 1
      src/core/Utils.js
  3. 5 3
      src/core/Utils.test.js

+ 3 - 2
src/core/Core.test.js

@@ -402,8 +402,9 @@ describe('src/Core', () => {
         .then(() => core.upload())
         .then(() => {
           expect(postprocessor1.mock.calls.length).toEqual(1)
-          const lastModifiedTime = new Date()
-          const fileId = 'foojpg' + lastModifiedTime.getTime()
+          // const lastModifiedTime = new Date()
+          // const fileId = 'foojpg' + lastModifiedTime.getTime()
+          const fileId = 'uppy-foojpg-image'
 
           expect(postprocessor1.mock.calls[0][0].length).toEqual(1)
           expect(postprocessor1.mock.calls[0][0][0].substring(0, 17)).toEqual(

+ 0 - 1
src/core/Utils.js

@@ -120,7 +120,6 @@ function generateFileID (file) {
     'uppy',
     file.name ? file.name.toLowerCase().replace(/[^A-Z0-9]/ig, '') : '',
     file.type,
-    file.hui,
     file.data.size,
     file.data.lastModified
   ].filter(val => val).join('-')

+ 5 - 3
src/core/Utils.test.js

@@ -5,16 +5,18 @@ const sampleImageDataURI =
 
 describe('core/utils', () => {
   describe('generateFileID', () => {
-    it('should take the filename object and produce a lowercase file id made up of the name and lastModified date', () => {
+    it('should take the filename object and produce a lowercase file id made up of uppy- prefix, file name (cleaned up to be lowercase, letters and numbers only), type, size and lastModified date', () => {
       const fileObj = {
         name: 'fOo0Fi@£$.jpg',
+        type: 'image/jpeg',
         data: {
-          lastModified: '2017-08-31T00:00:00.000Z'
+          lastModified: '2017-08-31T00:00:00.000Z',
+          size: 2271173
         }
       }
 
       expect(utils.generateFileID(fileObj)).toEqual(
-        'foo0fijpg2017-08-31T00:00:00.000Z'
+        'uppy-foo0fijpg-image/jpeg-2271173-2017-08-31T00:00:00.000Z'
       )
     })
   })