Browse Source

transloadit: Add test for `alwaysRunAssembly`

Renée Kooi 7 years ago
parent
commit
5750efab90
2 changed files with 22 additions and 2 deletions
  1. 3 2
      src/plugins/Transloadit/index.js
  2. 19 0
      test/unit/Transloadit.spec.js

+ 3 - 2
src/plugins/Transloadit/index.js

@@ -289,8 +289,9 @@ module.exports = class Transloadit extends Plugin {
       optionsPromise = this.getAssemblyOptions(fileIDs)
         .then((allOptions) => this.dedupeAssemblyOptions(allOptions))
     } else if (this.opts.alwaysRunAssembly) {
-      optionsPromise = Promise.resolve().then(() => {
-        const options = this.opts.getAssemblyOptions(null, this.opts)
+      optionsPromise = Promise.resolve(
+        this.opts.getAssemblyOptions(null, this.opts)
+      ).then((options) => {
         this.validateParams(options.params)
         return [
           { fileIDs, options }

+ 19 - 0
test/unit/Transloadit.spec.js

@@ -165,3 +165,22 @@ test('Does not create an assembly if no files are being uploaded', (t) => {
     t.end()
   }).catch(t.fail)
 })
+
+test('Creates an assembly if no files are being uploaded but `alwaysRunAssembly` is enabled', (t) => {
+  t.plan(1)
+
+  const uppy = new Core()
+  uppy.use(Transloadit, {
+    alwaysRunAssembly: true,
+    getAssemblyOptions (file) {
+      t.equal(file, null, 'should call getAssemblyOptions with `null`')
+      return Promise.reject()
+    }
+  })
+
+  uppy.upload().then(() => {
+    t.fail('should be rejected by `getAssemblyOptions`')
+  }, () => {
+    t.end()
+  })
+})