Skip to content

Commit 270c92a

Browse files
committed
Split into separate test
1 parent 59ed527 commit 270c92a

File tree

1 file changed

+24
-21
lines changed

1 file changed

+24
-21
lines changed

spec/FilesController.spec.js

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -219,10 +219,8 @@ describe('FilesController', () => {
219219
done();
220220
});
221221

222-
it('should return valid filename or url from createFile response when provided', async () => {
222+
it('should return filename and url when adapter returns both', async () => {
223223
const config = Config.get(Parse.applicationId);
224-
225-
// Test case 1: adapter returns new filename and url
226224
const adapterWithReturn = { ...mockAdapter };
227225
adapterWithReturn.createFile = () => {
228226
return Promise.resolve({
@@ -234,17 +232,20 @@ describe('FilesController', () => {
234232
return Promise.resolve('http://default.url/file.txt');
235233
};
236234
const controllerWithReturn = new FilesController(adapterWithReturn, null, { preserveFileName: true });
237-
// preserveFileName is true to make filename behaviors predictable
238-
const result1 = await controllerWithReturn.createFile(
235+
236+
const result = await controllerWithReturn.createFile(
239237
config,
240238
'originalFile.txt',
241239
'data',
242240
'text/plain'
243241
);
244-
expect(result1.name).toBe('newFilename.txt');
245-
expect(result1.url).toBe('http://new.url/newFilename.txt');
242+
243+
expect(result.name).toBe('newFilename.txt');
244+
expect(result.url).toBe('http://new.url/newFilename.txt');
245+
});
246246

247-
// Test case 2: adapter returns nothing, falling back to default behavior
247+
it('should use original filename and generate url when adapter returns nothing', async () => {
248+
const config = Config.get(Parse.applicationId);
248249
const adapterWithoutReturn = { ...mockAdapter };
249250
adapterWithoutReturn.createFile = () => {
250251
return Promise.resolve();
@@ -254,20 +255,20 @@ describe('FilesController', () => {
254255
};
255256

256257
const controllerWithoutReturn = new FilesController(adapterWithoutReturn, null, { preserveFileName: true });
257-
const result2 = await controllerWithoutReturn.createFile(
258+
const result = await controllerWithoutReturn.createFile(
258259
config,
259260
'originalFile.txt',
260261
'data',
261262
'text/plain',
262263
{}
263264
);
264265

265-
expect(result2.name).toBe('originalFile.txt');
266-
expect(result2.url).toBe('http://default.url/originalFile.txt');
266+
expect(result.name).toBe('originalFile.txt');
267+
expect(result.url).toBe('http://default.url/originalFile.txt');
268+
});
267269

268-
// Test case 3: adapter returns partial info (only url)
269-
// This is a valid scenario, as the adapter may return a modified filename
270-
// but may result in a mismatch between the filename and the resource URL
270+
it('should use original filename when adapter returns only url', async () => {
271+
const config = Config.get(Parse.applicationId);
271272
const adapterWithOnlyURL = { ...mockAdapter };
272273
adapterWithOnlyURL.createFile = () => {
273274
return Promise.resolve({
@@ -279,18 +280,20 @@ describe('FilesController', () => {
279280
};
280281

281282
const controllerWithPartial = new FilesController(adapterWithOnlyURL, null, { preserveFileName: true });
282-
const result3 = await controllerWithPartial.createFile(
283+
const result = await controllerWithPartial.createFile(
283284
config,
284285
'originalFile.txt',
285286
'data',
286287
'text/plain',
287288
{}
288289
);
289290

290-
expect(result3.name).toBe('originalFile.txt');
291-
expect(result3.url).toBe('http://new.url/partialFile.txt'); // Technically, the resource does not need to match the filename
291+
expect(result.name).toBe('originalFile.txt');
292+
expect(result.url).toBe('http://new.url/partialFile.txt');
293+
});
292294

293-
// Test case 4: adapter returns only filename
295+
it('should use adapter filename and generate url when adapter returns only filename', async () => {
296+
const config = Config.get(Parse.applicationId);
294297
const adapterWithOnlyFilename = { ...mockAdapter };
295298
adapterWithOnlyFilename.createFile = () => {
296299
return Promise.resolve({
@@ -302,15 +305,15 @@ describe('FilesController', () => {
302305
};
303306

304307
const controllerWithOnlyFilename = new FilesController(adapterWithOnlyFilename, null, { preserveFileName: true });
305-
const result4 = await controllerWithOnlyFilename.createFile(
308+
const result = await controllerWithOnlyFilename.createFile(
306309
config,
307310
'originalFile.txt',
308311
'data',
309312
'text/plain',
310313
{}
311314
);
312315

313-
expect(result4.name).toBe('newname.txt');
314-
expect(result4.url).toBe('http://default.url/newname.txt');
316+
expect(result.name).toBe('newname.txt');
317+
expect(result.url).toBe('http://default.url/newname.txt');
315318
});
316319
});

0 commit comments

Comments
 (0)