mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2024-11-24 18:56:32 -05:00
test: note length check works on note creation
Signed-off-by: Philip Molares <philip.molares@udo.edu>
This commit is contained in:
parent
5275f6b876
commit
9bf85a671d
3 changed files with 71 additions and 0 deletions
|
@ -28,6 +28,7 @@ import { NoteConfig } from '../config/note.config';
|
|||
import {
|
||||
AlreadyInDBError,
|
||||
ForbiddenIdError,
|
||||
MaximumDocumentLengthExceededError,
|
||||
NotInDBError,
|
||||
} from '../errors/errors';
|
||||
import { eventModuleConfig, NoteEvent } from '../events';
|
||||
|
@ -464,6 +465,37 @@ describe('NotesService', () => {
|
|||
expect(await newNote.aliases).toHaveLength(1);
|
||||
expect((await newNote.aliases)[0].name).toEqual(alias);
|
||||
});
|
||||
describe('with maxDocumentLength 1000', () => {
|
||||
beforeEach(() => (noteMockConfig.maxDocumentLength = 1000));
|
||||
it('and content has length maxDocumentLength', async () => {
|
||||
const content = 'x'.repeat(noteMockConfig.maxDocumentLength);
|
||||
const newNote = await service.createNote(content, user, alias);
|
||||
const revisions = await newNote.revisions;
|
||||
expect(revisions).toHaveLength(1);
|
||||
expect(revisions[0].content).toEqual(content);
|
||||
expect(await newNote.historyEntries).toHaveLength(1);
|
||||
expect(await (await newNote.historyEntries)[0].user).toEqual(user);
|
||||
expect(await newNote.userPermissions).toHaveLength(0);
|
||||
const groupPermissions = await newNote.groupPermissions;
|
||||
expect(groupPermissions).toHaveLength(2);
|
||||
expect(groupPermissions[0].canEdit).toEqual(
|
||||
everyoneDefaultAccessPermission === DefaultAccessPermission.WRITE,
|
||||
);
|
||||
expect((await groupPermissions[0].group).name).toEqual(
|
||||
SpecialGroup.EVERYONE,
|
||||
);
|
||||
expect(groupPermissions[1].canEdit).toEqual(
|
||||
loggedinDefaultAccessPermission === DefaultAccessPermission.WRITE,
|
||||
);
|
||||
expect((await groupPermissions[1].group).name).toEqual(
|
||||
SpecialGroup.LOGGED_IN,
|
||||
);
|
||||
expect(await newNote.tags).toHaveLength(0);
|
||||
expect(await newNote.owner).toEqual(user);
|
||||
expect(await newNote.aliases).toHaveLength(1);
|
||||
expect((await newNote.aliases)[0].name).toEqual(alias);
|
||||
});
|
||||
});
|
||||
describe('with other', () => {
|
||||
beforeEach(
|
||||
() =>
|
||||
|
@ -510,6 +542,19 @@ describe('NotesService', () => {
|
|||
AlreadyInDBError,
|
||||
);
|
||||
});
|
||||
describe('with maxDocumentLength 1000', () => {
|
||||
beforeEach(() => (noteMockConfig.maxDocumentLength = 1000));
|
||||
it('document is too long', async () => {
|
||||
mockGroupRepo();
|
||||
jest.spyOn(noteRepo, 'save').mockImplementationOnce(async () => {
|
||||
throw new Error();
|
||||
});
|
||||
const content = 'x'.repeat(noteMockConfig.maxDocumentLength + 1);
|
||||
await expect(
|
||||
service.createNote(content, user, alias),
|
||||
).rejects.toThrow(MaximumDocumentLengthExceededError);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
@ -126,6 +126,19 @@ describe('Notes', () => {
|
|||
.expect('Content-Type', /json/)
|
||||
.expect(409);
|
||||
});
|
||||
|
||||
it('fails with a content, that is too long', async () => {
|
||||
const content = 'x'.repeat(
|
||||
(testSetup.configService.get('noteConfig')
|
||||
.maxDocumentLength as number) + 1,
|
||||
);
|
||||
await agent
|
||||
.post('/api/private/notes/test2')
|
||||
.set('Content-Type', 'text/markdown')
|
||||
.send(content)
|
||||
.expect('Content-Type', /json/)
|
||||
.expect(413);
|
||||
});
|
||||
});
|
||||
|
||||
describe('DELETE /notes/{note}', () => {
|
||||
|
|
|
@ -124,6 +124,19 @@ describe('Notes', () => {
|
|||
.expect('Content-Type', /json/)
|
||||
.expect(409);
|
||||
});
|
||||
|
||||
it('fails with a content, that is too long', async () => {
|
||||
const content = 'x'.repeat(
|
||||
(testSetup.configService.get('noteConfig')
|
||||
.maxDocumentLength as number) + 1,
|
||||
);
|
||||
await request(testSetup.app.getHttpServer())
|
||||
.post('/api/v2/notes/test2')
|
||||
.set('Content-Type', 'text/markdown')
|
||||
.send(content)
|
||||
.expect('Content-Type', /json/)
|
||||
.expect(413);
|
||||
});
|
||||
});
|
||||
|
||||
describe('DELETE /notes/{note}', () => {
|
||||
|
|
Loading…
Reference in a new issue