mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2024-11-22 09:46:30 -05:00
PublicE2EMedia: Port the extra test from the private api
This ports the extra tests in the POST /media test from the private apis to the public apis E2E tests. Also the whole test suit was renamed to 'Media'. Signed-off-by: Philip Molares <philip.molares@udo.edu>
This commit is contained in:
parent
6943399dcf
commit
25e310b7eb
1 changed files with 49 additions and 16 deletions
|
@ -31,7 +31,7 @@ import { TokenAuthGuard } from '../../src/auth/token-auth.guard';
|
|||
import { MockAuthGuard } from '../../src/auth/mock-auth.guard';
|
||||
import { join } from 'path';
|
||||
|
||||
describe('Notes', () => {
|
||||
describe('Media', () => {
|
||||
let app: NestExpressApplication;
|
||||
let mediaService: MediaService;
|
||||
let uploadPath: string;
|
||||
|
@ -77,7 +77,8 @@ describe('Notes', () => {
|
|||
mediaService = moduleRef.get('MediaService');
|
||||
});
|
||||
|
||||
it('POST /media', async () => {
|
||||
describe('POST /media', () => {
|
||||
it('works', async () => {
|
||||
const uploadResponse = await request(app.getHttpServer())
|
||||
.post('/media')
|
||||
.attach('file', 'test/public-api/fixtures/test.png')
|
||||
|
@ -93,6 +94,38 @@ describe('Notes', () => {
|
|||
// delete the file afterwards
|
||||
await fs.unlink(join(uploadPath, fileName));
|
||||
});
|
||||
describe('fails:', () => {
|
||||
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();
|
||||
});
|
||||
it('note does not exist', async () => {
|
||||
await request(app.getHttpServer())
|
||||
.post('/media')
|
||||
.attach('file', 'test/public-api/fixtures/test.zip')
|
||||
.set('HedgeDoc-Note', 'i_dont_exist')
|
||||
.expect(400);
|
||||
expect(await fs.access(uploadPath)).toBeFalsy();
|
||||
});
|
||||
it('mediaBackend error', async () => {
|
||||
await fs.rmdir(uploadPath);
|
||||
await fs.mkdir(uploadPath, {
|
||||
mode: '444',
|
||||
});
|
||||
await request(app.getHttpServer())
|
||||
.post('/media')
|
||||
.attach('file', 'test/public-api/fixtures/test.png')
|
||||
.set('HedgeDoc-Note', 'test_upload_media')
|
||||
.expect('Content-Type', /json/)
|
||||
.expect(500);
|
||||
await fs.rmdir(uploadPath);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('DELETE /media/{filename}', async () => {
|
||||
const testImage = await fs.readFile('test/public-api/fixtures/test.png');
|
||||
|
|
Loading…
Reference in a new issue