Add the addFileNameHash option that allows users to remove the hash f… (#4915)
* Add the addFileNameHash option that allows users to remove the hash from file names * Change option name to preserveFileName * Revert changes to package-lock.json
This commit is contained in:
committed by
Florent Vilmart
parent
0363728b83
commit
6a151ee135
@@ -14,13 +14,13 @@ const mockAdapter = {
|
||||
}
|
||||
|
||||
// Small additional tests to improve overall coverage
|
||||
describe("FilesController",() =>{
|
||||
describe("FilesController", () => {
|
||||
it("should properly expand objects", (done) => {
|
||||
|
||||
const config = Config.get(Parse.applicationId);
|
||||
const gridStoreAdapter = new GridStoreAdapter('mongodb://localhost:27017/parse');
|
||||
const filesController = new FilesController(gridStoreAdapter)
|
||||
const result = filesController.expandFilesInObject(config, function(){});
|
||||
const result = filesController.expandFilesInObject(config, function () { });
|
||||
|
||||
expect(result).toBeUndefined();
|
||||
|
||||
@@ -43,7 +43,7 @@ describe("FilesController",() =>{
|
||||
|
||||
reconfigureServer({ filesAdapter: mockAdapter })
|
||||
.then(() => new Promise(resolve => setTimeout(resolve, 1000)))
|
||||
.then(() => new Parse.File("yolo.txt", [1,2,3], "text/plain").save())
|
||||
.then(() => new Parse.File("yolo.txt", [1, 2, 3], "text/plain").save())
|
||||
.then(
|
||||
() => done.fail('should not succeed'),
|
||||
() => setImmediate(() => Parse.Promise.as('done'))
|
||||
@@ -62,4 +62,40 @@ describe("FilesController",() =>{
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it("should add a unique hash to the file name when the preserveFileName option is false", (done) => {
|
||||
|
||||
const config = Config.get(Parse.applicationId)
|
||||
const gridStoreAdapter = new GridStoreAdapter('mongodb://localhost:27017/parse')
|
||||
spyOn(gridStoreAdapter, 'createFile')
|
||||
gridStoreAdapter.createFile.and.returnValue(Promise.resolve())
|
||||
const fileName = 'randomFileName.pdf'
|
||||
const regexEscapedFileName = fileName.replace(/\./g, "\\$&")
|
||||
const filesController = new FilesController(gridStoreAdapter, null, { preserveFileName: false })
|
||||
|
||||
filesController.createFile(config, fileName)
|
||||
|
||||
expect(gridStoreAdapter.createFile).toHaveBeenCalledTimes(1)
|
||||
expect(gridStoreAdapter.createFile.calls.mostRecent().args[0]).toMatch(`^.{32}_${regexEscapedFileName}$`)
|
||||
|
||||
done();
|
||||
});
|
||||
|
||||
it("should not add a unique hash to the file name when the preserveFileName option is false", (done) => {
|
||||
|
||||
const config = Config.get(Parse.applicationId)
|
||||
const gridStoreAdapter = new GridStoreAdapter('mongodb://localhost:27017/parse')
|
||||
spyOn(gridStoreAdapter, 'createFile')
|
||||
gridStoreAdapter.createFile.and.returnValue(Promise.resolve())
|
||||
const fileName = 'randomFileName.pdf'
|
||||
const filesController = new FilesController(gridStoreAdapter, null, { preserveFileName: true })
|
||||
|
||||
filesController.createFile(config, fileName)
|
||||
|
||||
expect(gridStoreAdapter.createFile).toHaveBeenCalledTimes(1)
|
||||
expect(gridStoreAdapter.createFile.calls.mostRecent().args[0]).toEqual(fileName)
|
||||
|
||||
done();
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user