mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-05-20 02:05:21 -04:00
fix: increase test coverage
Signed-off-by: Yannick Bungers <git@innay.de>
This commit is contained in:
parent
dad60a25ea
commit
d73bbcaeff
3 changed files with 47 additions and 16 deletions
|
@ -63,21 +63,44 @@ describe('Media', () => {
|
|||
});
|
||||
|
||||
describe('POST /media', () => {
|
||||
it('works', async () => {
|
||||
const uploadResponse = await agent
|
||||
.post('/api/private/media')
|
||||
.attach('file', 'test/private-api/fixtures/test.png')
|
||||
.set('HedgeDoc-Note', 'test_upload_media')
|
||||
.expect('Content-Type', /json/)
|
||||
.expect(201);
|
||||
const path: string = uploadResponse.body.url;
|
||||
const testImage = await fs.readFile('test/private-api/fixtures/test.png');
|
||||
const downloadResponse = await agent.get(path);
|
||||
expect(downloadResponse.body).toEqual(testImage);
|
||||
// Remove /uploads/ from path as we just need the filename.
|
||||
const fileName = path.replace('/uploads/', '');
|
||||
// delete the file afterwards
|
||||
await fs.unlink(join(uploadPath, fileName));
|
||||
describe('works', () => {
|
||||
it('with user', async () => {
|
||||
const uploadResponse = await agent
|
||||
.post('/api/private/media')
|
||||
.attach('file', 'test/private-api/fixtures/test.png')
|
||||
.set('HedgeDoc-Note', 'test_upload_media')
|
||||
.expect('Content-Type', /json/)
|
||||
.expect(201);
|
||||
const path: string = uploadResponse.body.url;
|
||||
const testImage = await fs.readFile(
|
||||
'test/private-api/fixtures/test.png',
|
||||
);
|
||||
const downloadResponse = await agent.get(path);
|
||||
expect(downloadResponse.body).toEqual(testImage);
|
||||
// Remove /uploads/ from path as we just need the filename.
|
||||
const fileName = path.replace('/uploads/', '');
|
||||
// delete the file afterwards
|
||||
await fs.unlink(join(uploadPath, fileName));
|
||||
});
|
||||
it('without user', async () => {
|
||||
const agent = request.agent(testSetup.app.getHttpServer());
|
||||
const uploadResponse = await agent
|
||||
.post('/api/private/media')
|
||||
.attach('file', 'test/private-api/fixtures/test.png')
|
||||
.set('HedgeDoc-Note', 'test_upload_media')
|
||||
.expect('Content-Type', /json/)
|
||||
.expect(201);
|
||||
const path: string = uploadResponse.body.url;
|
||||
const testImage = await fs.readFile(
|
||||
'test/private-api/fixtures/test.png',
|
||||
);
|
||||
const downloadResponse = await agent.get(path);
|
||||
expect(downloadResponse.body).toEqual(testImage);
|
||||
// Remove /uploads/ from path as we just need the filename.
|
||||
const fileName = path.replace('/uploads/', '');
|
||||
// delete the file afterwards
|
||||
await fs.unlink(join(uploadPath, fileName));
|
||||
});
|
||||
});
|
||||
describe('fails:', () => {
|
||||
beforeEach(async () => {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue