UNPKG

2.46 kBJavaScriptView Raw
1const Core = require('@uppy/core')
2const Transloadit = require('./')
3
4describe('Transloadit', () => {
5 it('Throws errors if options are missing', () => {
6 const uppy = new Core()
7
8 expect(() => {
9 uppy.use(Transloadit, { params: {} })
10 }).toThrowError(/The `params\.auth\.key` option is required/)
11 })
12
13 it('Accepts a JSON string as `params` for signature authentication', () => {
14 const uppy = new Core()
15
16 expect(() => {
17 uppy.use(Transloadit, {
18 params: 'not json'
19 })
20 }).toThrowError(/The `params` option is a malformed JSON string/)
21
22 expect(() => {
23 uppy.use(Transloadit, {
24 params: '{"template_id":"some template id string"}'
25 })
26 }).toThrowError(/The `params\.auth\.key` option is required/)
27 expect(() => {
28 uppy.use(Transloadit, {
29 params: '{"auth":{"key":"some auth key string"},"template_id":"some template id string"}'
30 })
31 }).not.toThrowError(/The `params\.auth\.key` option is required/)
32 })
33
34 it('Does not leave lingering progress if getAssemblyOptions fails', () => {
35 const uppy = new Core()
36 uppy.use(Transloadit, {
37 getAssemblyOptions (file) {
38 return Promise.reject(new Error('Failure!'))
39 }
40 })
41
42 uppy.addFile({
43 source: 'jest',
44 name: 'abc',
45 data: new Uint8Array(100)
46 })
47
48 return uppy.upload().then(() => {
49 throw new Error('Should not have succeeded')
50 }, (err) => {
51 const fileID = Object.keys(uppy.getState().files)[0]
52
53 expect(err.message).toBe('Failure!')
54 expect(uppy.getFile(fileID).progress.uploadStarted).toBe(null)
55 })
56 })
57
58 it('Does not leave lingering progress if creating assembly fails', () => {
59 const uppy = new Core()
60 uppy.use(Transloadit, {
61 params: {
62 auth: { key: 'some auth key string' },
63 template_id: 'some template id string'
64 }
65 })
66
67 uppy.getPlugin('Transloadit').client.createAssembly = () =>
68 Promise.reject(new Error('VIDEO_ENCODE_VALIDATION'))
69
70 uppy.addFile({
71 source: 'jest',
72 name: 'abc',
73 data: new Uint8Array(100)
74 })
75
76 return uppy.upload().then(() => {
77 throw new Error('Should not have succeeded')
78 }, (err) => {
79 const fileID = Object.keys(uppy.getState().files)[0]
80
81 expect(err.message).toBe('Transloadit: Could not create Assembly: VIDEO_ENCODE_VALIDATION')
82 expect(uppy.getFile(fileID).progress.uploadStarted).toBe(null)
83 })
84 })
85})