@@ -221,101 +221,91 @@ describe('FilesController', () => {
221221
222222 it ( 'should return valid filename or url from createFile response when provided' , async ( ) => {
223223 const config = Config . get ( Parse . applicationId ) ;
224-
224+
225225 // Test case 1: adapter returns new filename and url
226- const adapterWithReturn = {
227- createFile : ( ) => {
228- return Promise . resolve ( {
229- name : 'newfilename.txt' ,
230- url : 'http://new.url/newfilename.txt'
231- } ) ;
232- } ,
233- getFileLocation : ( ) => {
234- return Promise . resolve ( 'http://default.url/file.txt' ) ;
235- } ,
236- validateFilename : ( ) => null
226+ const adapterWithReturn = { ...mockAdapter } ;
227+ adapterWithReturn . createFile = ( ) => {
228+ return Promise . resolve ( {
229+ name : 'newFilename.txt' ,
230+ url : 'http://new.url/newFilename.txt'
231+ } ) ;
232+ } ;
233+ adapterWithReturn . getFileLocation = ( ) => {
234+ return Promise . resolve ( 'http://default.url/file.txt' ) ;
237235 } ;
238-
239236 const controllerWithReturn = new FilesController ( adapterWithReturn ) ;
240237 const result1 = await controllerWithReturn . createFile (
241238 config ,
242- 'originalfile .txt' ,
239+ 'originalFile .txt' ,
243240 'data' ,
244241 'text/plain'
245242 ) ;
246-
247- expect ( result1 . name ) . toBe ( 'newfilename.txt' ) ;
248- expect ( result1 . url ) . toBe ( 'http://new.url/newfilename.txt' ) ;
243+ expect ( result1 . name ) . toBe ( 'newFilename.txt' ) ;
244+ expect ( result1 . url ) . toBe ( 'http://new.url/newFilename.txt' ) ;
249245
250246 // Test case 2: adapter returns nothing, falling back to default behavior
251- const adapterWithoutReturn = {
252- createFile : ( ) => {
253- return Promise . resolve ( ) ;
254- } ,
255- getFileLocation : ( config , filename ) => {
256- return Promise . resolve ( `http://default.url/${ filename } ` ) ;
257- } ,
258- validateFilename : ( ) => null
247+ const adapterWithoutReturn = { ...mockAdapter } ;
248+ adapterWithoutReturn . createFile = ( ) => {
249+ return Promise . resolve ( ) ;
259250 } ;
260-
251+ adapterWithoutReturn . getFileLocation = ( config , filename ) => {
252+ return Promise . resolve ( `http://default.url/${ filename } ` ) ;
253+ } ;
254+
261255 const controllerWithoutReturn = new FilesController ( adapterWithoutReturn ) ;
262256 const result2 = await controllerWithoutReturn . createFile (
263257 config ,
264- 'originalfile .txt' ,
258+ 'originalFile .txt' ,
265259 'data' ,
266260 'text/plain' ,
267261 { } ,
268262 { preserveFileName : true } // To make filename predictable
269263 ) ;
270264
271- expect ( result2 . name ) . toBe ( 'originalfile .txt' ) ;
272- expect ( result2 . url ) . toBe ( 'http://default.url/originalfile .txt' ) ;
265+ expect ( result2 . name ) . toBe ( 'originalFile .txt' ) ;
266+ expect ( result2 . url ) . toBe ( 'http://default.url/originalFile .txt' ) ;
273267
274268 // Test case 3: adapter returns partial info (only url)
275269 // This is a valid scenario, as the adapter may return a modified filename
276270 // but may result in a mismatch between the filename and the resource URL
277- const adapterWithOnlyURL = {
278- createFile : ( ) => {
279- return Promise . resolve ( {
280- url : 'http://new.url/partialfile.txt'
281- } ) ;
282- } ,
283- getFileLocation : ( ) => {
284- return Promise . resolve ( 'http://default.url/file.txt' ) ;
285- } ,
286- validateFilename : ( ) => null
271+ const adapterWithOnlyURL = { ...mockAdapter } ;
272+ adapterWithOnlyURL . createFile = ( ) => {
273+ return Promise . resolve ( {
274+ url : 'http://new.url/partialFile.txt'
275+ } ) ;
276+ } ;
277+ adapterWithOnlyURL . getFileLocation = ( ) => {
278+ return Promise . resolve ( 'http://default.url/file.txt' ) ;
287279 } ;
288280
289281 const controllerWithPartial = new FilesController ( adapterWithOnlyURL ) ;
290282 const result3 = await controllerWithPartial . createFile (
291283 config ,
292- 'originalfile .txt' ,
284+ 'originalFile .txt' ,
293285 'data' ,
294286 'text/plain' ,
295287 { } ,
296288 { preserveFileName : true } // To make filename predictable
297289 ) ;
298290
299- expect ( result3 . name ) . toBe ( 'originalfile .txt' ) ;
300- expect ( result3 . url ) . toBe ( 'http://new.url/partialfile .txt' ) ; // Technically, the resource does not need to match the filename
291+ expect ( result3 . name ) . toBe ( 'originalFile .txt' ) ;
292+ expect ( result3 . url ) . toBe ( 'http://new.url/partialFile .txt' ) ; // Technically, the resource does not need to match the filename
301293
302294 // Test case 4: adapter returns only filename
303- const adapterWithOnlyFilename = {
304- createFile : ( ) => {
305- return Promise . resolve ( {
306- name : 'newname.txt'
307- } ) ;
308- } ,
309- getFileLocation : ( config , filename ) => {
310- return Promise . resolve ( `http://default.url/${ filename } ` ) ;
311- } ,
312- validateFilename : ( ) => null
295+ const adapterWithOnlyFilename = { ...mockAdapter } ;
296+ adapterWithOnlyFilename . createFile = ( ) => {
297+ return Promise . resolve ( {
298+ name : 'newname.txt'
299+ } ) ;
300+ } ;
301+ adapterWithOnlyFilename . getFileLocation = ( config , filename ) => {
302+ return Promise . resolve ( `http://default.url/${ filename } ` ) ;
313303 } ;
314304
315305 const controllerWithOnlyFilename = new FilesController ( adapterWithOnlyFilename ) ;
316306 const result4 = await controllerWithOnlyFilename . createFile (
317307 config ,
318- 'originalfile .txt' ,
308+ 'originalFile .txt' ,
319309 'data' ,
320310 'text/plain' ,
321311 { } ,
0 commit comments