mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-02-14 06:51:19 +00:00
Merge pull request #1060 from hedgedoc/port/mediaE2ETests
PublicE2EMedia: Port the extra test from the private api
This commit is contained in:
commit
3bc0a46630
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 { MockAuthGuard } from '../../src/auth/mock-auth.guard';
|
||||||
import { join } from 'path';
|
import { join } from 'path';
|
||||||
|
|
||||||
describe('Notes', () => {
|
describe('Media', () => {
|
||||||
let app: NestExpressApplication;
|
let app: NestExpressApplication;
|
||||||
let mediaService: MediaService;
|
let mediaService: MediaService;
|
||||||
let uploadPath: string;
|
let uploadPath: string;
|
||||||
|
@ -77,21 +77,54 @@ describe('Notes', () => {
|
||||||
mediaService = moduleRef.get('MediaService');
|
mediaService = moduleRef.get('MediaService');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('POST /media', async () => {
|
describe('POST /media', () => {
|
||||||
const uploadResponse = await request(app.getHttpServer())
|
it('works', async () => {
|
||||||
.post('/media')
|
const uploadResponse = await request(app.getHttpServer())
|
||||||
.attach('file', 'test/public-api/fixtures/test.png')
|
.post('/media')
|
||||||
.set('HedgeDoc-Note', 'test_upload_media')
|
.attach('file', 'test/public-api/fixtures/test.png')
|
||||||
.expect('Content-Type', /json/)
|
.set('HedgeDoc-Note', 'test_upload_media')
|
||||||
.expect(201);
|
.expect('Content-Type', /json/)
|
||||||
const path: string = uploadResponse.body.link;
|
.expect(201);
|
||||||
const testImage = await fs.readFile('test/public-api/fixtures/test.png');
|
const path: string = uploadResponse.body.link;
|
||||||
const downloadResponse = await request(app.getHttpServer()).get(path);
|
const testImage = await fs.readFile('test/public-api/fixtures/test.png');
|
||||||
expect(downloadResponse.body).toEqual(testImage);
|
const downloadResponse = await request(app.getHttpServer()).get(path);
|
||||||
// Remove /upload/ from path as we just need the filename.
|
expect(downloadResponse.body).toEqual(testImage);
|
||||||
const fileName = path.replace('/uploads/', '');
|
// Remove /upload/ from path as we just need the filename.
|
||||||
// delete the file afterwards
|
const fileName = path.replace('/uploads/', '');
|
||||||
await fs.unlink(join(uploadPath, fileName));
|
// 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 () => {
|
it('DELETE /media/{filename}', async () => {
|
||||||
|
|
Loading…
Reference in a new issue