it('beforeSaveFile should change values by returning new fileObject', async () => {
await reconfigureServer({ filesAdapter: mockAdapter });
const createFileSpy = spyOn(mockAdapter, 'createFile').and.callThrough();
Parse.Cloud.beforeSaveFile(async (req) => {
expect(req.triggerName).toEqual('beforeSaveFile');
expect(req.fileSize).toBe(3);
const newFile = new Parse.File('donald_duck.pdf', [4, 5, 6], 'application/pdf');
newFile.setMetadata({ foo: 'bar' });
newFile.setTags({ tagA: 'some-tag' });
return newFile;
});
const file = new Parse.File('popeye.txt', [1, 2, 3], 'text/plain');
const result = await file.save({ useMasterKey: true });
expect(result).toBeInstanceOf(Parse.File);
const newData = new Buffer([4, 5, 6]);
const newContentType = 'application/pdf';
const newOptions = {
tags: {
tagA: 'some-tag',
},
metadata: {
foo: 'bar',
},
};
expect(createFileSpy).toHaveBeenCalledWith(jasmine.any(String), newData, newContentType, newOptions);
const expectedFileName = 'donald_duck.pdf';
expect(file._name.indexOf(expectedFileName)).toBe(file._name.length - expectedFileName.length);
});