Update API routes in public API E2E tests

Signed-off-by: David Mehren <git@herrmehren.de>
This commit is contained in:
David Mehren 2021-10-15 16:53:10 +02:00
parent 1cc797f13d
commit 4805c9c5c5
No known key found for this signature in database
GPG key ID: 185982BA4C42B7C3
4 changed files with 64 additions and 64 deletions

View file

@ -49,7 +49,7 @@ describe('Notes', () => {
const newAlias = 'normalAlias';
newAliasDto.newAlias = newAlias;
const metadata = await request(testSetup.app.getHttpServer())
.post(`/alias`)
.post(`/api/v2/alias`)
.set('Content-Type', 'application/json')
.send(newAliasDto)
.expect(201);
@ -57,7 +57,7 @@ describe('Notes', () => {
expect(metadata.body.primaryAlias).toBeFalsy();
expect(metadata.body.noteId).toEqual(publicId);
const note = await request(testSetup.app.getHttpServer())
.get(`/notes/${newAlias}`)
.get(`/api/v2/notes/${newAlias}`)
.expect(200);
expect(note.body.metadata.aliases).toContain(newAlias);
expect(note.body.metadata.primaryAlias).toBeTruthy();
@ -68,7 +68,7 @@ describe('Notes', () => {
it('because of a forbidden alias', async () => {
newAliasDto.newAlias = forbiddenNoteId;
await request(testSetup.app.getHttpServer())
.post(`/alias`)
.post(`/api/v2/alias`)
.set('Content-Type', 'application/json')
.send(newAliasDto)
.expect(400);
@ -76,7 +76,7 @@ describe('Notes', () => {
it('because of a alias that is a public id', async () => {
newAliasDto.newAlias = publicId;
await request(testSetup.app.getHttpServer())
.post(`/alias`)
.post(`/api/v2/alias`)
.set('Content-Type', 'application/json')
.send(newAliasDto)
.expect(400);
@ -103,7 +103,7 @@ describe('Notes', () => {
it('updates a note with a normal alias', async () => {
const metadata = await request(testSetup.app.getHttpServer())
.put(`/alias/${newAlias}`)
.put(`/api/v2/alias/${newAlias}`)
.set('Content-Type', 'application/json')
.send(changeAliasDto)
.expect(200);
@ -111,7 +111,7 @@ describe('Notes', () => {
expect(metadata.body.primaryAlias).toBeTruthy();
expect(metadata.body.noteId).toEqual(publicId);
const note = await request(testSetup.app.getHttpServer())
.get(`/notes/${newAlias}`)
.get(`/api/v2/notes/${newAlias}`)
.expect(200);
expect(note.body.metadata.aliases).toContain(newAlias);
expect(note.body.metadata.primaryAlias).toBeTruthy();
@ -121,7 +121,7 @@ describe('Notes', () => {
describe('does not update', () => {
it('a note with unknown alias', async () => {
await request(testSetup.app.getHttpServer())
.put(`/alias/i_dont_exist`)
.put(`/api/v2/alias/i_dont_exist`)
.set('Content-Type', 'application/json')
.send(changeAliasDto)
.expect(404);
@ -129,7 +129,7 @@ describe('Notes', () => {
it('if the property primaryAlias is false', async () => {
changeAliasDto.primaryAlias = false;
await request(testSetup.app.getHttpServer())
.put(`/alias/${newAlias}`)
.put(`/api/v2/alias/${newAlias}`)
.set('Content-Type', 'application/json')
.send(changeAliasDto)
.expect(400);
@ -151,16 +151,16 @@ describe('Notes', () => {
it('deletes a normal alias', async () => {
await request(testSetup.app.getHttpServer())
.delete(`/alias/${newAlias}`)
.delete(`/api/v2/alias/${newAlias}`)
.expect(204);
await request(testSetup.app.getHttpServer())
.get(`/notes/${newAlias}`)
.get(`/api/v2/notes/${newAlias}`)
.expect(404);
});
it('does not delete an unknown alias', async () => {
await request(testSetup.app.getHttpServer())
.delete(`/alias/i_dont_exist`)
.delete(`/api/v2/alias/i_dont_exist`)
.expect(404);
});
@ -168,19 +168,19 @@ describe('Notes', () => {
const note = await testSetup.notesService.getNoteByIdOrAlias(testAlias);
await testSetup.aliasService.addAlias(note, newAlias);
await request(testSetup.app.getHttpServer())
.delete(`/alias/${testAlias}`)
.delete(`/api/v2/alias/${testAlias}`)
.expect(400);
await request(testSetup.app.getHttpServer())
.get(`/notes/${newAlias}`)
.get(`/api/v2/notes/${newAlias}`)
.expect(200);
});
it('deletes a primary alias (if it is the only one)', async () => {
await request(testSetup.app.getHttpServer())
.delete(`/alias/${newAlias}`)
.delete(`/api/v2/alias/${newAlias}`)
.expect(204);
await request(testSetup.app.getHttpServer())
.delete(`/alias/${testAlias}`)
.delete(`/api/v2/alias/${testAlias}`)
.expect(204);
});
});

View file

@ -34,7 +34,7 @@ describe('Me', () => {
it(`GET /me`, async () => {
const userInfo = testSetup.userService.toUserDto(user);
const response = await request(testSetup.app.getHttpServer())
.get('/me')
.get('/api/v2/me')
.expect('Content-Type', /json/)
.expect(200);
expect(response.body).toEqual(userInfo);
@ -46,7 +46,7 @@ describe('Me', () => {
const createdHistoryEntry =
await testSetup.historyService.updateHistoryEntryTimestamp(note, user);
const response = await request(testSetup.app.getHttpServer())
.get('/me/history')
.get('/api/v2/me/history')
.expect('Content-Type', /json/)
.expect(200);
const history: HistoryEntryDto[] = response.body;
@ -71,7 +71,7 @@ describe('Me', () => {
const createdHistoryEntry =
await testSetup.historyService.updateHistoryEntryTimestamp(note, user);
const response = await request(testSetup.app.getHttpServer())
.get(`/me/history/${noteName}`)
.get(`/api/v2/me/history/${noteName}`)
.expect('Content-Type', /json/)
.expect(200);
const historyEntry: HistoryEntryDto = response.body;
@ -87,7 +87,7 @@ describe('Me', () => {
});
it('fails with a non-existing note', async () => {
await request(testSetup.app.getHttpServer())
.get('/me/history/i_dont_exist')
.get('/api/v2/me/history/i_dont_exist')
.expect('Content-Type', /json/)
.expect(404);
});
@ -101,7 +101,7 @@ describe('Me', () => {
const historyEntryUpdateDto = new HistoryEntryUpdateDto();
historyEntryUpdateDto.pinStatus = true;
const response = await request(testSetup.app.getHttpServer())
.put('/me/history/' + noteName)
.put('/api/v2/me/history/' + noteName)
.send(historyEntryUpdateDto)
.expect(200);
const history = await testSetup.historyService.getEntriesByUser(user);
@ -117,7 +117,7 @@ describe('Me', () => {
});
it('fails with a non-existing note', async () => {
await request(testSetup.app.getHttpServer())
.put('/me/history/i_dont_exist')
.put('/api/v2/me/history/i_dont_exist')
.expect('Content-Type', /json/)
.expect(404);
});
@ -129,7 +129,7 @@ describe('Me', () => {
const note = await testSetup.notesService.createNote('', noteName);
await testSetup.historyService.updateHistoryEntryTimestamp(note, user);
const response = await request(testSetup.app.getHttpServer())
.delete(`/me/history/${noteName}`)
.delete(`/api/v2/me/history/${noteName}`)
.expect(204);
expect(response.body).toEqual({});
const history = await testSetup.historyService.getEntriesByUser(user);
@ -142,14 +142,14 @@ describe('Me', () => {
describe('fails', () => {
it('with a non-existing note', async () => {
await request(testSetup.app.getHttpServer())
.delete('/me/history/i_dont_exist')
.delete('/api/v2/me/history/i_dont_exist')
.expect(404);
});
it('with a non-existing history entry', async () => {
const noteName = 'testGetNoteHistory5';
await testSetup.notesService.createNote('', noteName);
await request(testSetup.app.getHttpServer())
.delete(`/me/history/${noteName}`)
.delete(`/api/v2/me/history/${noteName}`)
.expect(404);
});
});
@ -159,7 +159,7 @@ describe('Me', () => {
const noteName = 'testNote';
await testSetup.notesService.createNote('', noteName, user);
const response = await request(testSetup.app.getHttpServer())
.get('/me/notes/')
.get('/api/v2/me/notes/')
.expect('Content-Type', /json/)
.expect(200);
const noteMetaDtos = response.body as NoteMetadataDto[];
@ -181,7 +181,7 @@ describe('Me', () => {
);
const httpServer = testSetup.app.getHttpServer();
const response1 = await request(httpServer)
.get('/me/media/')
.get('/api/v2/me/media/')
.expect('Content-Type', /json/)
.expect(200);
expect(response1.body).toHaveLength(0);
@ -193,7 +193,7 @@ describe('Me', () => {
const url3 = await testSetup.mediaService.saveFile(testImage, user, note2);
const response = await request(httpServer)
.get('/me/media/')
.get('/api/v2/me/media/')
.expect('Content-Type', /json/)
.expect(200);
expect(response.body).toHaveLength(4);

View file

@ -45,7 +45,7 @@ describe('Media', () => {
describe('POST /media', () => {
it('works', async () => {
const uploadResponse = await request(testSetup.app.getHttpServer())
.post('/media')
.post('/api/v2/media')
.attach('file', 'test/public-api/fixtures/test.png')
.set('HedgeDoc-Note', 'test_upload_media')
.expect('Content-Type', /json/)
@ -67,7 +67,7 @@ describe('Media', () => {
});
it('MIME type not supported', async () => {
await request(testSetup.app.getHttpServer())
.post('/media')
.post('/api/v2/media')
.attach('file', 'test/public-api/fixtures/test.zip')
.set('HedgeDoc-Note', 'test_upload_media')
.expect(400);
@ -75,7 +75,7 @@ describe('Media', () => {
});
it('note does not exist', async () => {
await request(testSetup.app.getHttpServer())
.post('/media')
.post('/api/v2/media')
.attach('file', 'test/public-api/fixtures/test.zip')
.set('HedgeDoc-Note', 'i_dont_exist')
.expect(400);
@ -86,7 +86,7 @@ describe('Media', () => {
mode: '444',
});
await request(testSetup.app.getHttpServer())
.post('/media')
.post('/api/v2/media')
.attach('file', 'test/public-api/fixtures/test.png')
.set('HedgeDoc-Note', 'test_upload_media')
.expect('Content-Type', /json/)
@ -107,7 +107,7 @@ describe('Media', () => {
);
const filename = url.split('/').pop() || '';
await request(testSetup.app.getHttpServer())
.delete('/media/' + filename)
.delete('/api/v2/media/' + filename)
.expect(204);
});

View file

@ -43,7 +43,7 @@ describe('Notes', () => {
it('POST /notes', async () => {
const response = await request(testSetup.app.getHttpServer())
.post('/notes')
.post('/api/v2/notes')
.set('Content-Type', 'text/markdown')
.send(content)
.expect('Content-Type', /json/)
@ -63,7 +63,7 @@ describe('Notes', () => {
// check if we can succefully get a note that exists
await testSetup.notesService.createNote(content, 'test1', user);
const response = await request(testSetup.app.getHttpServer())
.get('/notes/test1')
.get('/api/v2/notes/test1')
.expect('Content-Type', /json/)
.expect(200);
expect(response.body.content).toEqual(content);
@ -71,14 +71,14 @@ describe('Notes', () => {
it('fails with an non-existing note', async () => {
// check if a missing note correctly returns 404
await request(testSetup.app.getHttpServer())
.get('/notes/i_dont_exist')
.get('/api/v2/notes/i_dont_exist')
.expect('Content-Type', /json/)
.expect(404);
});
it('fails with a forbidden note id', async () => {
// check if a forbidden note correctly returns 400
await request(testSetup.app.getHttpServer())
.get('/notes/forbiddenNoteId')
.get('/api/v2/notes/forbiddenNoteId')
.expect('Content-Type', /json/)
.expect(400);
});
@ -87,7 +87,7 @@ describe('Notes', () => {
describe('POST /notes/{note}', () => {
it('works with a non-existing alias', async () => {
const response = await request(testSetup.app.getHttpServer())
.post('/notes/test2')
.post('/api/v2/notes/test2')
.set('Content-Type', 'text/markdown')
.send(content)
.expect('Content-Type', /json/)
@ -104,7 +104,7 @@ describe('Notes', () => {
it('fails with a forbidden alias', async () => {
await request(testSetup.app.getHttpServer())
.post(`/notes/${forbiddenNoteId}`)
.post(`/api/v2/notes/${forbiddenNoteId}`)
.set('Content-Type', 'text/markdown')
.send(content)
.expect('Content-Type', /json/)
@ -113,7 +113,7 @@ describe('Notes', () => {
it('fails with a existing alias', async () => {
await request(testSetup.app.getHttpServer())
.post('/notes/test2')
.post('/api/v2/notes/test2')
.set('Content-Type', 'text/markdown')
.send(content)
.expect('Content-Type', /json/)
@ -132,7 +132,7 @@ describe('Notes', () => {
);
await testSetup.mediaService.saveFile(testImage, user, note);
await request(testSetup.app.getHttpServer())
.delete(`/notes/${noteId}`)
.delete(`/api/v2/notes/${noteId}`)
.set('Content-Type', 'application/json')
.send({
keepMedia: false,
@ -160,7 +160,7 @@ describe('Notes', () => {
note,
);
await request(testSetup.app.getHttpServer())
.delete(`/notes/${noteId}`)
.delete(`/api/v2/notes/${noteId}`)
.set('Content-Type', 'application/json')
.send({
keepMedia: true,
@ -210,7 +210,7 @@ describe('Notes', () => {
);
expect(updatedNote.groupPermissions).toHaveLength(0);
await request(testSetup.app.getHttpServer())
.delete('/notes/test3')
.delete('/api/v2/notes/test3')
.expect(204);
await expect(
testSetup.notesService.getNoteByIdOrAlias('test3'),
@ -220,12 +220,12 @@ describe('Notes', () => {
});
it('fails with a forbidden alias', async () => {
await request(testSetup.app.getHttpServer())
.delete(`/notes/${forbiddenNoteId}`)
.delete(`/api/v2/notes/${forbiddenNoteId}`)
.expect(400);
});
it('fails with a non-existing alias', async () => {
await request(testSetup.app.getHttpServer())
.delete('/notes/i_dont_exist')
.delete('/api/v2/notes/i_dont_exist')
.expect(404);
});
});
@ -235,7 +235,7 @@ describe('Notes', () => {
it('works with existing alias', async () => {
await testSetup.notesService.createNote(content, 'test4', user);
const response = await request(testSetup.app.getHttpServer())
.put('/notes/test4')
.put('/api/v2/notes/test4')
.set('Content-Type', 'text/markdown')
.send(changedContent)
.expect(200);
@ -248,14 +248,14 @@ describe('Notes', () => {
});
it('fails with a forbidden alias', async () => {
await request(testSetup.app.getHttpServer())
.put(`/notes/${forbiddenNoteId}`)
.put(`/api/v2/notes/${forbiddenNoteId}`)
.set('Content-Type', 'text/markdown')
.send(changedContent)
.expect(400);
});
it('fails with a non-existing alias', async () => {
await request(testSetup.app.getHttpServer())
.put('/notes/i_dont_exist')
.put('/api/v2/notes/i_dont_exist')
.set('Content-Type', 'text/markdown')
.expect('Content-Type', /json/)
.expect(404);
@ -266,7 +266,7 @@ describe('Notes', () => {
it('returns complete metadata object', async () => {
await testSetup.notesService.createNote(content, 'test5', user);
const metadata = await request(testSetup.app.getHttpServer())
.get('/notes/test5/metadata')
.get('/api/v2/notes/test5/metadata')
.expect(200);
expect(typeof metadata.body.id).toEqual('string');
expect(metadata.body.aliases).toEqual(['test5']);
@ -290,14 +290,14 @@ describe('Notes', () => {
it('fails with a forbidden alias', async () => {
await request(testSetup.app.getHttpServer())
.get(`/notes/${forbiddenNoteId}/metadata`)
.get(`/api/v2/notes/${forbiddenNoteId}/metadata`)
.expect(400);
});
it('fails with non-existing alias', async () => {
// check if a missing note correctly returns 404
await request(testSetup.app.getHttpServer())
.get('/notes/i_dont_exist/metadata')
.get('/api/v2/notes/i_dont_exist/metadata')
.expect('Content-Type', /json/)
.expect(404);
});
@ -316,7 +316,7 @@ describe('Notes', () => {
// update the note
await testSetup.notesService.updateNote(note, 'More test content');
const metadata = await request(testSetup.app.getHttpServer())
.get('/notes/test5a/metadata')
.get('/api/v2/notes/test5a/metadata')
.expect(200);
expect(metadata.body.createTime).toEqual(createDate.toISOString());
expect(metadata.body.updateTime).not.toEqual(createDate.toISOString());
@ -327,7 +327,7 @@ describe('Notes', () => {
it('works with existing alias', async () => {
await testSetup.notesService.createNote(content, 'test6', user);
const response = await request(testSetup.app.getHttpServer())
.get('/notes/test6/revisions')
.get('/api/v2/notes/test6/revisions')
.expect('Content-Type', /json/)
.expect(200);
expect(response.body).toHaveLength(1);
@ -335,14 +335,14 @@ describe('Notes', () => {
it('fails with a forbidden alias', async () => {
await request(testSetup.app.getHttpServer())
.get(`/notes/${forbiddenNoteId}/revisions`)
.get(`/api/v2/notes/${forbiddenNoteId}/revisions`)
.expect(400);
});
it('fails with non-existing alias', async () => {
// check if a missing note correctly returns 404
await request(testSetup.app.getHttpServer())
.get('/notes/i_dont_exist/revisions')
.get('/api/v2/notes/i_dont_exist/revisions')
.expect('Content-Type', /json/)
.expect(404);
});
@ -357,20 +357,20 @@ describe('Notes', () => {
);
const revision = await testSetup.notesService.getLatestRevision(note);
const response = await request(testSetup.app.getHttpServer())
.get(`/notes/test7/revisions/${revision.id}`)
.get(`/api/v2/notes/test7/revisions/${revision.id}`)
.expect('Content-Type', /json/)
.expect(200);
expect(response.body.content).toEqual(content);
});
it('fails with a forbidden alias', async () => {
await request(testSetup.app.getHttpServer())
.get(`/notes/${forbiddenNoteId}/revisions/1`)
.get(`/api/v2/notes/${forbiddenNoteId}/revisions/1`)
.expect(400);
});
it('fails with non-existing alias', async () => {
// check if a missing note correctly returns 404
await request(testSetup.app.getHttpServer())
.get('/notes/i_dont_exist/revisions/1')
.get('/api/v2/notes/i_dont_exist/revisions/1')
.expect('Content-Type', /json/)
.expect(404);
});
@ -380,19 +380,19 @@ describe('Notes', () => {
it('works with an existing alias', async () => {
await testSetup.notesService.createNote(content, 'test8', user);
const response = await request(testSetup.app.getHttpServer())
.get('/notes/test8/content')
.get('/api/v2/notes/test8/content')
.expect(200);
expect(response.text).toEqual(content);
});
it('fails with a forbidden alias', async () => {
await request(testSetup.app.getHttpServer())
.get(`/notes/${forbiddenNoteId}/content`)
.get(`/api/v2/notes/${forbiddenNoteId}/content`)
.expect(400);
});
it('fails with non-existing alias', async () => {
// check if a missing note correctly returns 404
await request(testSetup.app.getHttpServer())
.get('/notes/i_dont_exist/content')
.get('/api/v2/notes/i_dont_exist/content')
.expect('Content-Type', /text\/markdown/)
.expect(404);
});
@ -414,7 +414,7 @@ describe('Notes', () => {
);
const httpServer = testSetup.app.getHttpServer();
const response = await request(httpServer)
.get(`/notes/${alias}/media/`)
.get(`/api/v2/notes/${alias}/media/`)
.expect('Content-Type', /json/)
.expect(200);
expect(response.body).toHaveLength(0);
@ -432,7 +432,7 @@ describe('Notes', () => {
);
const responseAfter = await request(httpServer)
.get(`/notes/${alias}/media/`)
.get(`/api/v2/notes/${alias}/media/`)
.expect('Content-Type', /json/)
.expect(200);
expect(responseAfter.body).toHaveLength(1);
@ -447,7 +447,7 @@ describe('Notes', () => {
});
it('fails, when note does not exist', async () => {
await request(testSetup.app.getHttpServer())
.get(`/notes/i_dont_exist/media/`)
.get(`/api/v2/notes/i_dont_exist/media/`)
.expect('Content-Type', /json/)
.expect(404);
});
@ -459,7 +459,7 @@ describe('Notes', () => {
user2,
);
await request(testSetup.app.getHttpServer())
.get(`/notes/${alias}/media/`)
.get(`/api/v2/notes/${alias}/media/`)
.expect('Content-Type', /json/)
.expect(401);
});