|
| 1 | +const Parse = require('parse/node'); |
| 2 | +const { TestUtils } = require('parse-server'); |
| 3 | +const { PARSE_APP_ID, PARSE_MASTER_KEY, reconfigureServer, serverURL } = require('./mocks/server'); |
| 4 | +const { httpRequest } = require('./support/request'); |
| 5 | + |
| 6 | +const fileData = 'hello world'; |
| 7 | + |
| 8 | +describe('S3Adapter integration tests', () => { |
| 9 | + beforeEach(async () => { |
| 10 | + process.env.TESTING = true; |
| 11 | + |
| 12 | + await reconfigureServer(); |
| 13 | + |
| 14 | + Parse.initialize(PARSE_APP_ID); |
| 15 | + Parse.serverURL = serverURL; |
| 16 | + Parse.CoreManager.set('SERVER_URL', serverURL); |
| 17 | + Parse.CoreManager.set('MASTER_KEY', PARSE_MASTER_KEY); |
| 18 | + }, 60 * 1000); |
| 19 | + |
| 20 | + afterAll(async () => { |
| 21 | + Parse.Storage._clear(); |
| 22 | + await TestUtils.destroyAllDataPermanently(true); |
| 23 | + }); |
| 24 | + |
| 25 | + it('should create a file in Parse Server', async () => { |
| 26 | + const fileName = 'test-1.txt'; |
| 27 | + |
| 28 | + const base64 = Buffer.from(fileData).toString('base64'); |
| 29 | + const file = new Parse.File(fileName, { base64 }); |
| 30 | + |
| 31 | + await file.save(); |
| 32 | + |
| 33 | + expect(file).toBeDefined(); |
| 34 | + expect(file.url()).toContain(fileName); |
| 35 | + }); |
| 36 | + |
| 37 | + it( |
| 38 | + 'should read the contents of the file', |
| 39 | + async () => { |
| 40 | + const fileName = 'test-2.txt'; |
| 41 | + const base64 = Buffer.from(fileData).toString('base64'); |
| 42 | + const file = new Parse.File(fileName, { base64 }); |
| 43 | + await file.save(); |
| 44 | + const fileLink = file.url(); |
| 45 | + |
| 46 | + const response = await httpRequest(fileLink); |
| 47 | + const text = response.toString(); |
| 48 | + |
| 49 | + expect(text).toBe(fileData); // Check if the contents match the original data |
| 50 | + }, |
| 51 | + 60 * 1000 |
| 52 | + ); |
| 53 | + |
| 54 | + it( |
| 55 | + 'should delete the file', |
| 56 | + async () => { |
| 57 | + const fileName = 'test-3.txt'; |
| 58 | + |
| 59 | + const base64 = Buffer.from(fileData).toString('base64'); |
| 60 | + const file = new Parse.File(fileName, { base64 }); |
| 61 | + await file.save(); |
| 62 | + |
| 63 | + const fileLink = file.url(); |
| 64 | + await file.destroy(); |
| 65 | + |
| 66 | + return expectAsync(httpRequest(fileLink)).toBeRejectedWithError( |
| 67 | + 'Request failed with status code 404' |
| 68 | + ); |
| 69 | + }, |
| 70 | + 60 * 1000 |
| 71 | + ); |
| 72 | +}); |
0 commit comments