Browse Source

core: Tests for { successful, failed }

Renée Kooi 7 years ago
parent
commit
f02c89d5c0
1 changed files with 44 additions and 1 deletions
  1. 44 1
      src/core/Core.test.js

+ 44 - 1
src/core/Core.test.js

@@ -591,7 +591,50 @@ describe('src/Core', () => {
     })
   })
 
-  describe('uploading a file', () => {})
+  describe('uploading a file', () => {
+    it('should return a { successful, failed } pair containing file objects', () => {
+      const core = new Core().run()
+      core.addUploader((fileIDs) => Promise.resolve())
+      return Promise.all([
+        core.addFile({ source: 'jest', name: 'foo.jpg', type: 'image/jpeg', data: new Uint8Array() }),
+        core.addFile({ source: 'jest', name: 'bar.jpg', type: 'image/jpeg', data: new Uint8Array() })
+      ]).then(() => {
+        return expect(core.upload()).resolves.toMatchObject({
+          successful: [
+            { name: 'foo.jpg' },
+            { name: 'bar.jpg' }
+          ],
+          failed: []
+        })
+      })
+    })
+
+    it('should return files with errors in the { failed } key', () => {
+      const core = new Core().run()
+      core.addUploader((fileIDs) => {
+        fileIDs.forEach((fileID) => {
+          if (/bar/.test(core.getFile(fileID).name)) {
+            core.emit('core:upload-error', fileID, new Error('This is bar and I do not like bar'))
+          }
+        })
+        return Promise.resolve()
+      })
+
+      return Promise.all([
+        core.addFile({ source: 'jest', name: 'foo.jpg', type: 'image/jpeg', data: new Uint8Array() }),
+        core.addFile({ source: 'jest', name: 'bar.jpg', type: 'image/jpeg', data: new Uint8Array() })
+      ]).then(() => {
+        return expect(core.upload()).resolves.toMatchObject({
+          successful: [
+            { name: 'foo.jpg' }
+          ],
+          failed: [
+            { name: 'bar.jpg', error: 'This is bar and I do not like bar' }
+          ]
+        })
+      })
+    })
+  })
 
   describe('removing a file', () => {
     it('should remove the file', () => {