@@ -221,101 +221,91 @@ describe('FilesController', () => {
221
221
222
222
it ( 'should return valid filename or url from createFile response when provided' , async ( ) => {
223
223
const config = Config . get ( Parse . applicationId ) ;
224
-
224
+
225
225
// 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' ) ;
237
235
} ;
238
-
239
236
const controllerWithReturn = new FilesController ( adapterWithReturn ) ;
240
237
const result1 = await controllerWithReturn . createFile (
241
238
config ,
242
- 'originalfile .txt' ,
239
+ 'originalFile .txt' ,
243
240
'data' ,
244
241
'text/plain'
245
242
) ;
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' ) ;
249
245
250
246
// 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 ( ) ;
259
250
} ;
260
-
251
+ adapterWithoutReturn . getFileLocation = ( config , filename ) => {
252
+ return Promise . resolve ( `http://default.url/${ filename } ` ) ;
253
+ } ;
254
+
261
255
const controllerWithoutReturn = new FilesController ( adapterWithoutReturn ) ;
262
256
const result2 = await controllerWithoutReturn . createFile (
263
257
config ,
264
- 'originalfile .txt' ,
258
+ 'originalFile .txt' ,
265
259
'data' ,
266
260
'text/plain' ,
267
261
{ } ,
268
262
{ preserveFileName : true } // To make filename predictable
269
263
) ;
270
264
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' ) ;
273
267
274
268
// Test case 3: adapter returns partial info (only url)
275
269
// This is a valid scenario, as the adapter may return a modified filename
276
270
// 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' ) ;
287
279
} ;
288
280
289
281
const controllerWithPartial = new FilesController ( adapterWithOnlyURL ) ;
290
282
const result3 = await controllerWithPartial . createFile (
291
283
config ,
292
- 'originalfile .txt' ,
284
+ 'originalFile .txt' ,
293
285
'data' ,
294
286
'text/plain' ,
295
287
{ } ,
296
288
{ preserveFileName : true } // To make filename predictable
297
289
) ;
298
290
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
301
293
302
294
// 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 } ` ) ;
313
303
} ;
314
304
315
305
const controllerWithOnlyFilename = new FilesController ( adapterWithOnlyFilename ) ;
316
306
const result4 = await controllerWithOnlyFilename . createFile (
317
307
config ,
318
- 'originalfile .txt' ,
308
+ 'originalFile .txt' ,
319
309
'data' ,
320
310
'text/plain' ,
321
311
{ } ,
0 commit comments