uppy/packages/@uppy/utils/src/generateFileID.test.js
Artur Paikin e82ac0f137
core: Don’t add/overwrite existing files, allow duplicates from different folders (#1767)
* Add file.data.relativePath to the file.id

* Don’t add/overwrite a file if a file with the same id already exsists, issue a warning

* override @uppy/tus fingerprint to uppy’s file.id

* combine cordove/react native handling, don’t log twice

* always use onError for errors in addFile

* use file.meta.relativePath instead of file.data.relativePath

what do you think, @lakesare?

* update tests to include allowing/diallowing duplicates and file.id generation with relativePath

* update tus-js-client

* refactor error handling for addFile and upload into a mutual  _showOrLogErrorAndThrow method

* explain duplicate files and relativePath

* throw TypeError vs Error when allowedFileTypes is not an array

* fix tests

* tweak docs

* Emit restriction-failed for all restriction errors, move it to _showOrLogErrorAndThrow
2019-09-19 16:43:51 +03:00

43 lines
1.3 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

const generateFileID = require('./generateFileID')
describe('generateFileID', () => {
it('should take the filename object and produce a lowercase file id made up of uppy- prefix, file name (cleaned up to be lowercase, letters and numbers only), type, relative path (folder) from file.meta.relativePath, size and lastModified date', () => {
const fileObj = {
name: 'fOo0Fi@£$.jpg',
type: 'image/jpeg',
data: {
lastModified: 1498510508000,
size: 2271173
}
}
expect(generateFileID(fileObj)).toEqual(
'uppy-foo0fi////jpg-20-53-14-1e-image/jpeg-2271173-1498510508000'
)
expect(generateFileID({
name: 'джумла-джpумлатест.jpg',
type: 'image/jpeg',
data: {
lastModified: 1498510508000,
size: 2271173
}
})).toEqual(
'uppy-/////////p/////////jpg-11k-11m-123-11s-11r-11g-1d-11k-11m-123-11s-11r-11g-122-11l-121-122-1e-image/jpeg-2271173-1498510508000'
)
expect(generateFileID({
name: 'hello.jpg',
type: 'image/jpeg',
data: {
lastModified: 1498510508000,
size: 2271173
},
meta: {
relativePath: 'folder/a'
}
})).toEqual(
'uppy-hello/jpg-1e-image/jpeg-folder/a-1f-2271173-1498510508000'
)
})
})