mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2024-12-22 15:11:34 +00: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
|
@ -62,7 +62,6 @@ export class PermissionsService {
|
|||
case Permission.OWNER:
|
||||
return await this.isOwner(user, note);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public async checkMediaDeletePermission(
|
||||
|
|
|
@ -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 () => {
|
||||
|
|
|
@ -93,6 +93,15 @@ describe('Media', () => {
|
|||
.expect('Content-Type', /json/)
|
||||
.expect(500);
|
||||
});
|
||||
it('no file uploaded', async () => {
|
||||
await request(testSetup.app.getHttpServer())
|
||||
.post('/api/v2/media')
|
||||
.set('Authorization', `Bearer ${testSetup.authTokens[0].secret}`)
|
||||
.set('HedgeDoc-Note', 'testAlias1')
|
||||
.expect('Content-Type', /json/)
|
||||
.expect(400);
|
||||
});
|
||||
|
||||
afterEach(async () => {
|
||||
await ensureDeleted(uploadPath);
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue