From 5a3ddc28fc7341e55362a413d1901a1771c4a4e8 Mon Sep 17 00:00:00 2001 From: Philip Molares Date: Wed, 31 Mar 2021 22:41:38 +0200 Subject: [PATCH] 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 --- test/private-api/media.e2e-spec.ts | 12 ++++++++---- test/public-api/media.e2e-spec.ts | 12 ++++++++---- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/test/private-api/media.e2e-spec.ts b/test/private-api/media.e2e-spec.ts index 5920ab3e5..7270661aa 100644 --- a/test/private-api/media.e2e-spec.ts +++ b/test/private-api/media.e2e-spec.ts @@ -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 }); }); }); }); diff --git a/test/public-api/media.e2e-spec.ts b/test/public-api/media.e2e-spec.ts index 78a95b56f..d8c3f3b63 100644 --- a/test/public-api/media.e2e-spec.ts +++ b/test/public-api/media.e2e-spec.ts @@ -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 }); }); }); });