Parcourir la source

Fix Transloadit plugin tests. (#180)

Renée Kooi il y a 8 ans
Parent
commit
9a84327447
2 fichiers modifiés avec 29 ajouts et 6 suppressions
  1. 1 1
      src/plugins/Transloadit/index.js
  2. 28 5
      test/unit/Transloadit.spec.js

+ 1 - 1
src/plugins/Transloadit/index.js

@@ -42,7 +42,7 @@ module.exports = class Transloadit extends Plugin {
     }
     }
 
 
     if (!params.auth || !params.auth.key) {
     if (!params.auth || !params.auth.key) {
-      throw new Error('Transloadit: The `params.auth.key` option is required.' +
+      throw new Error('Transloadit: The `params.auth.key` option is required. ' +
         'You can find your Transloadit API key at https://transloadit.com/accounts/credentials.')
         'You can find your Transloadit API key at https://transloadit.com/accounts/credentials.')
     }
     }
 
 

+ 28 - 5
test/unit/Transloadit.spec.js

@@ -2,16 +2,39 @@ import test from 'tape'
 import Core from '../../src/core/Core'
 import Core from '../../src/core/Core'
 import Transloadit from '../../src/plugins/Transloadit'
 import Transloadit from '../../src/plugins/Transloadit'
 
 
-test('Throws errors if options are missing', (t) => {
+test('Transloadit: Throws errors if options are missing', (t) => {
   const uppy = new Core()
   const uppy = new Core()
 
 
   t.throws(() => {
   t.throws(() => {
-    uppy.use(Transloadit, { key: null, templateId: 'abc' })
-  }, 'The `key` option is required.')
+    uppy.use(Transloadit, {})
+  }, /The `params` option is required/)
 
 
   t.throws(() => {
   t.throws(() => {
-    uppy.use(Transloadit, { key: 'abc', templateId: null })
-  }, 'The `templateId` option is required.')
+    uppy.use(Transloadit, { params: {} })
+  }, /The `params\.auth\.key` option is required/)
+
+  t.end()
+})
+
+test('Transloadit: Accepts a JSON string as `params` for signature authentication', (t) => {
+  const uppy = new Core()
+
+  t.throws(() => {
+    uppy.use(Transloadit, {
+      params: 'not json'
+    })
+  }, /The `params` option is a malformed JSON string/)
+
+  t.throws(() => {
+    uppy.use(Transloadit, {
+      params: '{"template_id":"some template id string"}'
+    })
+  }, /The `params\.auth\.key` option is required/)
+  t.doesNotThrow(() => {
+    uppy.use(Transloadit, {
+      params: '{"auth":{"key":"some auth key string"},"template_id":"some template id string"}'
+    })
+  }, /The `params\.auth\.key` option is required/)
 
 
   t.end()
   t.end()
 })
 })