mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2024-11-25 11:16:31 -05: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:
|
case Permission.OWNER:
|
||||||
return await this.isOwner(user, note);
|
return await this.isOwner(user, note);
|
||||||
}
|
}
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public async checkMediaDeletePermission(
|
public async checkMediaDeletePermission(
|
||||||
|
|
|
@ -63,21 +63,44 @@ describe('Media', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('POST /media', () => {
|
describe('POST /media', () => {
|
||||||
it('works', async () => {
|
describe('works', () => {
|
||||||
const uploadResponse = await agent
|
it('with user', async () => {
|
||||||
.post('/api/private/media')
|
const uploadResponse = await agent
|
||||||
.attach('file', 'test/private-api/fixtures/test.png')
|
.post('/api/private/media')
|
||||||
.set('HedgeDoc-Note', 'test_upload_media')
|
.attach('file', 'test/private-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.url;
|
.expect(201);
|
||||||
const testImage = await fs.readFile('test/private-api/fixtures/test.png');
|
const path: string = uploadResponse.body.url;
|
||||||
const downloadResponse = await agent.get(path);
|
const testImage = await fs.readFile(
|
||||||
expect(downloadResponse.body).toEqual(testImage);
|
'test/private-api/fixtures/test.png',
|
||||||
// Remove /uploads/ from path as we just need the filename.
|
);
|
||||||
const fileName = path.replace('/uploads/', '');
|
const downloadResponse = await agent.get(path);
|
||||||
// delete the file afterwards
|
expect(downloadResponse.body).toEqual(testImage);
|
||||||
await fs.unlink(join(uploadPath, fileName));
|
// 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:', () => {
|
describe('fails:', () => {
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
|
|
|
@ -93,6 +93,15 @@ describe('Media', () => {
|
||||||
.expect('Content-Type', /json/)
|
.expect('Content-Type', /json/)
|
||||||
.expect(500);
|
.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 () => {
|
afterEach(async () => {
|
||||||
await ensureDeleted(uploadPath);
|
await ensureDeleted(uploadPath);
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue