MediaE2E: Extract 'uploads' deletion

The deletion of upload was moved to beforeEach and afterEach block in the 'POST /media' > 'fails' tests.
The test if the folder was not created, because there was no file uploaded, now correctly expects the behaviour.

Signed-off-by: Philip Molares <philip.molares@udo.edu>
This commit is contained in:
Philip Molares 2021-03-31 22:41:38 +02:00
parent d586b84d8b
commit 5a3ddc28fc
2 changed files with 16 additions and 8 deletions

View file

@ -99,13 +99,16 @@ describe('Media', () => {
await fs.unlink(join(uploadPath, fileName));
});
describe('fails:', () => {
beforeEach(async () => {
await fs.rmdir(uploadPath, { recursive: true });
});
it('MIME type not supported', async () => {
await request(app.getHttpServer())
.post('/media')
.attach('file', 'test/private-api/fixtures/test.zip')
.set('HedgeDoc-Note', 'test_upload_media')
.expect(400);
expect(await fs.access(uploadPath)).toBeFalsy();
await expect(fs.access(uploadPath)).rejects.toBeDefined();
});
it('note does not exist', async () => {
await request(app.getHttpServer())
@ -113,10 +116,9 @@ describe('Media', () => {
.attach('file', 'test/private-api/fixtures/test.zip')
.set('HedgeDoc-Note', 'i_dont_exist')
.expect(400);
expect(await fs.access(uploadPath)).toBeFalsy();
await expect(fs.access(uploadPath)).rejects.toBeDefined();
});
it('mediaBackend error', async () => {
await fs.rmdir(uploadPath);
await fs.mkdir(uploadPath, {
mode: '444',
});
@ -126,7 +128,9 @@ describe('Media', () => {
.set('HedgeDoc-Note', 'test_upload_media')
.expect('Content-Type', /json/)
.expect(500);
await fs.rmdir(uploadPath);
});
afterEach(async () => {
await fs.rmdir(uploadPath, { recursive: true });
});
});
});

View file

@ -95,13 +95,16 @@ describe('Media', () => {
await fs.unlink(join(uploadPath, fileName));
});
describe('fails:', () => {
beforeEach(async () => {
await fs.rmdir(uploadPath, { recursive: true });
});
it('MIME type not supported', async () => {
await request(app.getHttpServer())
.post('/media')
.attach('file', 'test/public-api/fixtures/test.zip')
.set('HedgeDoc-Note', 'test_upload_media')
.expect(400);
expect(await fs.access(uploadPath)).toBeFalsy();
await expect(fs.access(uploadPath)).rejects.toBeDefined();
});
it('note does not exist', async () => {
await request(app.getHttpServer())
@ -109,10 +112,9 @@ describe('Media', () => {
.attach('file', 'test/public-api/fixtures/test.zip')
.set('HedgeDoc-Note', 'i_dont_exist')
.expect(400);
expect(await fs.access(uploadPath)).toBeFalsy();
await expect(fs.access(uploadPath)).rejects.toBeDefined();
});
it('mediaBackend error', async () => {
await fs.rmdir(uploadPath);
await fs.mkdir(uploadPath, {
mode: '444',
});
@ -122,7 +124,9 @@ describe('Media', () => {
.set('HedgeDoc-Note', 'test_upload_media')
.expect('Content-Type', /json/)
.expect(500);
await fs.rmdir(uploadPath);
});
afterEach(async () => {
await fs.rmdir(uploadPath, { recursive: true });
});
});
});