Allow validateFilename to return a string or Parse Error (#6246)

This commit is contained in:
Mike Patnode
2019-12-02 17:47:22 -08:00
committed by Diamond Lewis
parent b75a73c7b8
commit a7cb381fbf
2 changed files with 22 additions and 2 deletions

View File

@@ -16,7 +16,9 @@ const mockAdapter = {
deleteFile: () => {},
getFileData: () => {},
getFileLocation: () => 'xyz',
validateFilename: () => {},
validateFilename: () => {
return null;
},
};
// Small additional tests to improve overall coverage
@@ -77,6 +79,19 @@ describe('FilesController', () => {
});
});
it('should create a parse error when a string is returned', done => {
const mock2 = mockAdapter;
mock2.validateFilename = () => {
return 'Bad file! No biscuit!';
};
const filesController = new FilesController(mockAdapter);
const error = filesController.validateFilename();
expect(typeof error).toBe('object');
expect(error.message.indexOf('biscuit')).toBe(13);
expect(error.code).toBe(Parse.Error.INVALID_FILE_NAME);
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 GridFSBucketAdapter(