-
-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
26 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,53 +1,37 @@ | ||
const { httpRequest } = require('./support/request'); | ||
|
||
const fileData = 'hello world'; | ||
|
||
describe('S3Adapter integration tests', () => { | ||
it('should create a file in Parse Server', async () => { | ||
const fileName = 'test-1.txt'; | ||
const base64 = Buffer.from('1').toString('base64'); | ||
const file = new Parse.File('file.txt', { base64 }); | ||
await file.save(); | ||
|
||
const base64 = Buffer.from(fileData).toString('base64'); | ||
const file = new Parse.File(fileName, { base64 }); | ||
expect(file).toBeDefined(); | ||
expect(file.url()).toMatch(/file.txt$/); | ||
}); | ||
|
||
it('should read the contents of the file', async () => { | ||
const base64 = Buffer.from('1').toString('base64'); | ||
const file = new Parse.File('file.txt', { base64 }); | ||
await file.save(); | ||
const fileLink = file.url(); | ||
|
||
expect(file).toBeDefined(); | ||
expect(file.url()).toContain(fileName); | ||
const response = await httpRequest(fileLink); | ||
const text = response.toString(); | ||
|
||
expect(text).toBe('1'); | ||
}); | ||
|
||
it( | ||
'should read the contents of the file', | ||
async () => { | ||
const fileName = 'test-2.txt'; | ||
const base64 = Buffer.from(fileData).toString('base64'); | ||
const file = new Parse.File(fileName, { base64 }); | ||
await file.save(); | ||
const fileLink = file.url(); | ||
|
||
const response = await httpRequest(fileLink); | ||
const text = response.toString(); | ||
|
||
expect(text).toBe(fileData); // Check if the contents match the original data | ||
}, | ||
60 * 1000 | ||
); | ||
|
||
it( | ||
'should delete the file', | ||
async () => { | ||
const fileName = 'test-3.txt'; | ||
|
||
const base64 = Buffer.from(fileData).toString('base64'); | ||
const file = new Parse.File(fileName, { base64 }); | ||
await file.save(); | ||
|
||
const fileLink = file.url(); | ||
await file.destroy(); | ||
|
||
return expectAsync(httpRequest(fileLink)).toBeRejectedWithError( | ||
'Request failed with status code 404' | ||
); | ||
}, | ||
60 * 1000 | ||
); | ||
it('should delete the file', async () => { | ||
const base64 = Buffer.from('1').toString('base64'); | ||
const file = new Parse.File('file.txt', { base64 }); | ||
await file.save(); | ||
|
||
const fileLink = file.url(); | ||
await file.destroy(); | ||
|
||
await expectAsync(httpRequest(fileLink)).toBeRejectedWithError( | ||
'Request failed with status code 404' | ||
); | ||
}); | ||
}); |