Skip to content

Commit

Permalink
clean up tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mtrezza committed Oct 22, 2024
1 parent 4b3228c commit 2270c56
Showing 1 changed file with 26 additions and 42 deletions.
68 changes: 26 additions & 42 deletions spec/integration.spec.js
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'
);
});
});

0 comments on commit 2270c56

Please sign in to comment.