mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2024-11-21 17:26:29 -05:00
test(e2e): add more tests for POST /notes
Signed-off-by: Philip Molares <philip.molares@udo.edu>
This commit is contained in:
parent
8201fb8c32
commit
98e2dd0a7c
2 changed files with 98 additions and 28 deletions
|
@ -8,6 +8,7 @@ import { join } from 'path';
|
|||
import request from 'supertest';
|
||||
|
||||
import { NotInDBError } from '../../src/errors/errors';
|
||||
import * as utils from '../../src/notes/utils';
|
||||
import { User } from '../../src/users/user.entity';
|
||||
import { TestSetup, TestSetupBuilder } from '../test-setup';
|
||||
|
||||
|
@ -55,7 +56,8 @@ describe('Notes', () => {
|
|||
await testSetup.cleanup();
|
||||
});
|
||||
|
||||
it('POST /notes', async () => {
|
||||
describe('POST /notes', () => {
|
||||
it('creates a note', async () => {
|
||||
const response = await agent
|
||||
.post('/api/private/notes')
|
||||
.set('Content-Type', 'text/markdown')
|
||||
|
@ -71,6 +73,39 @@ describe('Notes', () => {
|
|||
),
|
||||
).toEqual(content);
|
||||
});
|
||||
describe('does not create a note', () => {
|
||||
it('if content exceeds maxDocumentLength', async () => {
|
||||
const content = 'x'.repeat(
|
||||
(testSetup.configService.get('noteConfig')
|
||||
.maxDocumentLength as number) + 1,
|
||||
);
|
||||
await agent
|
||||
.post('/api/private/notes')
|
||||
.set('Content-Type', 'text/markdown')
|
||||
.send(content)
|
||||
.expect('Content-Type', /json/)
|
||||
.expect(413);
|
||||
});
|
||||
it('if publicId already exists', async () => {
|
||||
// This should not happen, but you at least theoretical it's possible
|
||||
const response = await agent
|
||||
.post('/api/private/notes')
|
||||
.set('Content-Type', 'text/markdown')
|
||||
.send(content)
|
||||
.expect('Content-Type', /json/)
|
||||
.expect(201);
|
||||
jest
|
||||
.spyOn(utils, 'generatePublicId')
|
||||
.mockReturnValueOnce(response.body.metadata?.id);
|
||||
await agent
|
||||
.post('/api/private/notes')
|
||||
.set('Content-Type', 'text/markdown')
|
||||
.send(content)
|
||||
.expect('Content-Type', /json/)
|
||||
.expect(409);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('GET /notes/{note}', () => {
|
||||
it('works with an existing note', async () => {
|
||||
|
|
|
@ -9,6 +9,7 @@ import request from 'supertest';
|
|||
|
||||
import { NotInDBError } from '../../src/errors/errors';
|
||||
import { NotePermissionsUpdateDto } from '../../src/notes/note-permissions.dto';
|
||||
import * as utils from '../../src/notes/utils';
|
||||
import { User } from '../../src/users/user.entity';
|
||||
import { TestSetup, TestSetupBuilder } from '../test-setup';
|
||||
|
||||
|
@ -46,7 +47,8 @@ describe('Notes', () => {
|
|||
await testSetup.cleanup();
|
||||
});
|
||||
|
||||
it('POST /notes', async () => {
|
||||
describe('POST /notes', () => {
|
||||
it('creates a note', async () => {
|
||||
const response = await request(testSetup.app.getHttpServer())
|
||||
.post('/api/v2/notes')
|
||||
.set('Content-Type', 'text/markdown')
|
||||
|
@ -62,6 +64,39 @@ describe('Notes', () => {
|
|||
),
|
||||
).toEqual(content);
|
||||
});
|
||||
describe('does not create a note', () => {
|
||||
it('if content exceeds maxDocumentLength', async () => {
|
||||
const content = 'x'.repeat(
|
||||
(testSetup.configService.get('noteConfig')
|
||||
.maxDocumentLength as number) + 1,
|
||||
);
|
||||
await request(testSetup.app.getHttpServer())
|
||||
.post('/api/v2/notes')
|
||||
.set('Content-Type', 'text/markdown')
|
||||
.send(content)
|
||||
.expect('Content-Type', /json/)
|
||||
.expect(413);
|
||||
});
|
||||
it('if publicId already exists', async () => {
|
||||
// This should not happen, but you at least theoretical it's possible
|
||||
const response = await request(testSetup.app.getHttpServer())
|
||||
.post('/api/v2/notes')
|
||||
.set('Content-Type', 'text/markdown')
|
||||
.send(content)
|
||||
.expect('Content-Type', /json/)
|
||||
.expect(201);
|
||||
jest
|
||||
.spyOn(utils, 'generatePublicId')
|
||||
.mockReturnValueOnce(response.body.metadata?.id);
|
||||
await request(testSetup.app.getHttpServer())
|
||||
.post('/api/v2/notes')
|
||||
.set('Content-Type', 'text/markdown')
|
||||
.send(content)
|
||||
.expect('Content-Type', /json/)
|
||||
.expect(409);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('GET /notes/{note}', () => {
|
||||
it('works with an existing note', async () => {
|
||||
|
|
Loading…
Reference in a new issue