|
@@ -1,7 +1,7 @@
|
|
|
const AssemblyOptions = require('./AssemblyOptions')
|
|
|
|
|
|
describe('Transloadit/AssemblyOptions', () => {
|
|
|
- it('Validates response from getAssemblyOptions()', () => {
|
|
|
+ it('Validates response from getAssemblyOptions()', async () => {
|
|
|
const options = new AssemblyOptions([
|
|
|
{ name: 'testfile' }
|
|
|
], {
|
|
@@ -13,12 +13,12 @@ describe('Transloadit/AssemblyOptions', () => {
|
|
|
}
|
|
|
})
|
|
|
|
|
|
- return expect(options.build()).rejects.toThrow(
|
|
|
+ await expect(options.build()).rejects.toThrow(
|
|
|
/The `params\.auth\.key` option is required/
|
|
|
)
|
|
|
})
|
|
|
|
|
|
- it('Uses different assemblies for different params', () => {
|
|
|
+ it('Uses different assemblies for different params', async () => {
|
|
|
const data = Buffer.alloc(10)
|
|
|
data.size = data.byteLength
|
|
|
|
|
@@ -38,16 +38,15 @@ describe('Transloadit/AssemblyOptions', () => {
|
|
|
})
|
|
|
})
|
|
|
|
|
|
- return options.build().then((assemblies) => {
|
|
|
- expect(assemblies).toHaveLength(4)
|
|
|
- expect(assemblies[0].options.params.steps.fake_step.data).toBe('a.png')
|
|
|
- expect(assemblies[1].options.params.steps.fake_step.data).toBe('b.png')
|
|
|
- expect(assemblies[2].options.params.steps.fake_step.data).toBe('c.png')
|
|
|
- expect(assemblies[3].options.params.steps.fake_step.data).toBe('d.png')
|
|
|
- })
|
|
|
+ const assemblies = await options.build()
|
|
|
+ expect(assemblies).toHaveLength(4)
|
|
|
+ expect(assemblies[0].options.params.steps.fake_step.data).toBe('a.png')
|
|
|
+ expect(assemblies[1].options.params.steps.fake_step.data).toBe('b.png')
|
|
|
+ expect(assemblies[2].options.params.steps.fake_step.data).toBe('c.png')
|
|
|
+ expect(assemblies[3].options.params.steps.fake_step.data).toBe('d.png')
|
|
|
})
|
|
|
|
|
|
- it('Should merge files with same parameters into one Assembly', () => {
|
|
|
+ it('Should merge files with same parameters into one Assembly', async () => {
|
|
|
const data = Buffer.alloc(10)
|
|
|
const data2 = Buffer.alloc(20)
|
|
|
|
|
@@ -67,26 +66,25 @@ describe('Transloadit/AssemblyOptions', () => {
|
|
|
})
|
|
|
})
|
|
|
|
|
|
- return options.build().then((assemblies) => {
|
|
|
- expect(assemblies).toHaveLength(2)
|
|
|
- expect(assemblies[0].fileIDs).toHaveLength(3)
|
|
|
- expect(assemblies[1].fileIDs).toHaveLength(1)
|
|
|
- expect(assemblies[0].options.params.steps.fake_step.data).toBe(10)
|
|
|
- expect(assemblies[1].options.params.steps.fake_step.data).toBe(20)
|
|
|
- })
|
|
|
+ const assemblies = await options.build()
|
|
|
+ expect(assemblies).toHaveLength(2)
|
|
|
+ expect(assemblies[0].fileIDs).toHaveLength(3)
|
|
|
+ expect(assemblies[1].fileIDs).toHaveLength(1)
|
|
|
+ expect(assemblies[0].options.params.steps.fake_step.data).toBe(10)
|
|
|
+ expect(assemblies[1].options.params.steps.fake_step.data).toBe(20)
|
|
|
})
|
|
|
|
|
|
- it('Does not create an Assembly if no files are being uploaded', () => {
|
|
|
+ it('Does not create an Assembly if no files are being uploaded', async () => {
|
|
|
const options = new AssemblyOptions([], {
|
|
|
getAssemblyOptions () {
|
|
|
throw new Error('should not create Assembly')
|
|
|
}
|
|
|
})
|
|
|
|
|
|
- return expect(options.build()).resolves.toEqual([])
|
|
|
+ await expect(options.build()).resolves.toEqual([])
|
|
|
})
|
|
|
|
|
|
- it('Creates an Assembly if no files are being uploaded but `alwaysRunAssembly` is enabled', () => {
|
|
|
+ it('Creates an Assembly if no files are being uploaded but `alwaysRunAssembly` is enabled', async () => {
|
|
|
const options = new AssemblyOptions([], {
|
|
|
alwaysRunAssembly: true,
|
|
|
getAssemblyOptions (file) {
|
|
@@ -100,6 +98,39 @@ describe('Transloadit/AssemblyOptions', () => {
|
|
|
}
|
|
|
})
|
|
|
|
|
|
- return expect(options.build()).resolves.toHaveLength(1)
|
|
|
+ await expect(options.build()).resolves.toHaveLength(1)
|
|
|
+ })
|
|
|
+
|
|
|
+ it('Collects metadata if `fields` is an array', async () => {
|
|
|
+ function defaultGetAssemblyOptions (file, options) {
|
|
|
+ return {
|
|
|
+ params: options.params,
|
|
|
+ signature: options.signature,
|
|
|
+ fields: options.fields
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ const options = new AssemblyOptions([{
|
|
|
+ id: 1,
|
|
|
+ meta: { watermark: 'Some text' }
|
|
|
+ }, {
|
|
|
+ id: 2,
|
|
|
+ meta: { watermark: 'ⓒ Transloadit GmbH' }
|
|
|
+ }], {
|
|
|
+ fields: ['watermark'],
|
|
|
+ params: {
|
|
|
+ auth: { key: 'fake key' }
|
|
|
+ },
|
|
|
+ getAssemblyOptions: defaultGetAssemblyOptions
|
|
|
+ })
|
|
|
+
|
|
|
+ const assemblies = await options.build()
|
|
|
+ expect(assemblies).toHaveLength(2)
|
|
|
+ expect(assemblies[0].options.fields).toMatchObject({
|
|
|
+ watermark: 'Some text'
|
|
|
+ })
|
|
|
+ expect(assemblies[1].options.fields).toMatchObject({
|
|
|
+ watermark: 'ⓒ Transloadit GmbH'
|
|
|
+ })
|
|
|
})
|
|
|
})
|