mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2024-11-25 11:16:31 -05:00
PublicE2E: Add test for GET /me/history/{note} in me.e2e-spec.ts
add test for GET /me/history/{note} add error cases to PUT /me/history/{note} and DELETE /me/history/{note} activate missing test GET /me/notes/ Signed-off-by: Philip Molares <philip.molares@udo.edu>
This commit is contained in:
parent
82ef4a10cb
commit
50d950c5f2
1 changed files with 108 additions and 43 deletions
|
@ -33,6 +33,7 @@ import { ConfigModule } from '@nestjs/config';
|
||||||
import mediaConfigMock from '../../src/config/media.config.mock';
|
import mediaConfigMock from '../../src/config/media.config.mock';
|
||||||
import appConfigMock from '../../src/config/app.config.mock';
|
import appConfigMock from '../../src/config/app.config.mock';
|
||||||
import { User } from '../../src/users/user.entity';
|
import { User } from '../../src/users/user.entity';
|
||||||
|
import { NoteMetadataDto } from '../../src/notes/note-metadata.dto';
|
||||||
|
|
||||||
// TODO Tests have to be reworked using UserService functions
|
// TODO Tests have to be reworked using UserService functions
|
||||||
|
|
||||||
|
@ -99,62 +100,126 @@ describe('Notes', () => {
|
||||||
.expect('Content-Type', /json/)
|
.expect('Content-Type', /json/)
|
||||||
.expect(200);
|
.expect(200);
|
||||||
const history = <HistoryEntryDto[]>response.body;
|
const history = <HistoryEntryDto[]>response.body;
|
||||||
|
expect(history.length).toEqual(1);
|
||||||
|
const historyDto = historyService.toHistoryEntryDto(createdHistoryEntry);
|
||||||
for (const historyEntry of history) {
|
for (const historyEntry of history) {
|
||||||
if (historyEntry.identifier === 'testGetHistory') {
|
expect(historyEntry.identifier).toEqual(historyDto.identifier);
|
||||||
expect(historyEntry).toEqual(createdHistoryEntry);
|
expect(historyEntry.title).toEqual(historyDto.title);
|
||||||
}
|
expect(historyEntry.tags).toEqual(historyDto.tags);
|
||||||
|
expect(historyEntry.pinStatus).toEqual(historyDto.pinStatus);
|
||||||
|
expect(historyEntry.lastVisited).toEqual(
|
||||||
|
historyDto.lastVisited.toISOString(),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
it(`PUT /me/history/{note}`, async () => {
|
describe(`GET /me/history/{note}`, () => {
|
||||||
const noteName = 'testGetNoteHistory2';
|
it('works with an existing note', async () => {
|
||||||
const note = await notesService.createNote('', noteName);
|
const noteName = 'testGetNoteHistory2';
|
||||||
await historyService.createOrUpdateHistoryEntry(note, user);
|
const note = await notesService.createNote('', noteName);
|
||||||
const historyEntryUpdateDto = new HistoryEntryUpdateDto();
|
const createdHistoryEntry = await historyService.createOrUpdateHistoryEntry(
|
||||||
historyEntryUpdateDto.pinStatus = true;
|
note,
|
||||||
const response = await request(app.getHttpServer())
|
user,
|
||||||
.put('/me/history/' + noteName)
|
);
|
||||||
.send(historyEntryUpdateDto)
|
const response = await request(app.getHttpServer())
|
||||||
.expect(200);
|
.get(`/me/history/${noteName}`)
|
||||||
const history = await historyService.getEntriesByUser(user);
|
.expect('Content-Type', /json/)
|
||||||
let historyEntry: HistoryEntryDto = response.body;
|
.expect(200);
|
||||||
expect(historyEntry.pinStatus).toEqual(true);
|
const historyEntry = <HistoryEntryDto>response.body;
|
||||||
historyEntry = null;
|
const historyEntryDto = historyService.toHistoryEntryDto(
|
||||||
for (const e of history) {
|
createdHistoryEntry,
|
||||||
if (e.note.alias === noteName) {
|
);
|
||||||
historyEntry = historyService.toHistoryEntryDto(e);
|
expect(historyEntry.identifier).toEqual(historyEntryDto.identifier);
|
||||||
}
|
expect(historyEntry.title).toEqual(historyEntryDto.title);
|
||||||
}
|
expect(historyEntry.tags).toEqual(historyEntryDto.tags);
|
||||||
expect(historyEntry.pinStatus).toEqual(true);
|
expect(historyEntry.pinStatus).toEqual(historyEntryDto.pinStatus);
|
||||||
|
expect(historyEntry.lastVisited).toEqual(
|
||||||
|
historyEntryDto.lastVisited.toISOString(),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
it('fails with a non-existing note', async () => {
|
||||||
|
await request(app.getHttpServer())
|
||||||
|
.get('/me/history/i_dont_exist')
|
||||||
|
.expect('Content-Type', /json/)
|
||||||
|
.expect(404);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it(`DELETE /me/history/{note}`, async () => {
|
describe(`PUT /me/history/{note}`, () => {
|
||||||
const noteName = 'testGetNoteHistory3';
|
it('works', async () => {
|
||||||
const note = await notesService.createNote('', noteName);
|
const noteName = 'testGetNoteHistory3';
|
||||||
await historyService.createOrUpdateHistoryEntry(note, user);
|
const note = await notesService.createNote('', noteName);
|
||||||
const response = await request(app.getHttpServer())
|
await historyService.createOrUpdateHistoryEntry(note, user);
|
||||||
.delete(`/me/history/${noteName}`)
|
const historyEntryUpdateDto = new HistoryEntryUpdateDto();
|
||||||
.expect(204);
|
historyEntryUpdateDto.pinStatus = true;
|
||||||
expect(response.body).toEqual({});
|
const response = await request(app.getHttpServer())
|
||||||
const history = await historyService.getEntriesByUser(user);
|
.put('/me/history/' + noteName)
|
||||||
let historyEntry: HistoryEntry = null;
|
.send(historyEntryUpdateDto)
|
||||||
for (const e of history) {
|
.expect(200);
|
||||||
if (e.note.alias === noteName) {
|
const history = await historyService.getEntriesByUser(user);
|
||||||
historyEntry = e;
|
let historyEntry: HistoryEntryDto = response.body;
|
||||||
|
expect(historyEntry.pinStatus).toEqual(true);
|
||||||
|
historyEntry = null;
|
||||||
|
for (const e of history) {
|
||||||
|
if (e.note.alias === noteName) {
|
||||||
|
historyEntry = historyService.toHistoryEntryDto(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
expect(historyEntry.pinStatus).toEqual(true);
|
||||||
return expect(historyEntry).toBeNull();
|
});
|
||||||
|
it('fails with a non-existing note', async () => {
|
||||||
|
await request(app.getHttpServer())
|
||||||
|
.put('/me/history/i_dont_exist')
|
||||||
|
.expect('Content-Type', /json/)
|
||||||
|
.expect(404);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it.skip(`GET /me/notes/`, async () => {
|
describe(`DELETE /me/history/{note}`, () => {
|
||||||
// TODO use function from HistoryService to add an History Entry
|
it('works', async () => {
|
||||||
await notesService.createNote('This is a test note.', 'test7');
|
const noteName = 'testGetNoteHistory4';
|
||||||
// usersService.getALLNotesOwnedByUser() TODO Implement function
|
const note = await notesService.createNote('', noteName);
|
||||||
|
await historyService.createOrUpdateHistoryEntry(note, user);
|
||||||
|
const response = await request(app.getHttpServer())
|
||||||
|
.delete(`/me/history/${noteName}`)
|
||||||
|
.expect(204);
|
||||||
|
expect(response.body).toEqual({});
|
||||||
|
const history = await historyService.getEntriesByUser(user);
|
||||||
|
let historyEntry: HistoryEntry = null;
|
||||||
|
for (const e of history) {
|
||||||
|
if (e.note.alias === noteName) {
|
||||||
|
historyEntry = e;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return expect(historyEntry).toBeNull();
|
||||||
|
});
|
||||||
|
describe('fails', () => {
|
||||||
|
it('with a non-existing note', async () => {
|
||||||
|
await request(app.getHttpServer())
|
||||||
|
.delete('/me/history/i_dont_exist')
|
||||||
|
.expect(404);
|
||||||
|
});
|
||||||
|
it('with a non-existing history entry', async () => {
|
||||||
|
const noteName = 'testGetNoteHistory5';
|
||||||
|
await notesService.createNote('', noteName);
|
||||||
|
await request(app.getHttpServer())
|
||||||
|
.delete(`/me/history/${noteName}`)
|
||||||
|
.expect(404);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it(`GET /me/notes/`, async () => {
|
||||||
|
const noteName = 'testNote';
|
||||||
|
await notesService.createNote('', noteName, user);
|
||||||
const response = await request(app.getHttpServer())
|
const response = await request(app.getHttpServer())
|
||||||
.get('/me/notes/')
|
.get('/me/notes/')
|
||||||
.expect('Content-Type', /json/)
|
.expect('Content-Type', /json/)
|
||||||
.expect(200);
|
.expect(200);
|
||||||
expect(response.body.revisions).toHaveLength(1);
|
const noteMetaDtos = response.body as NoteMetadataDto[];
|
||||||
|
expect(noteMetaDtos).toHaveLength(1);
|
||||||
|
expect(noteMetaDtos[0].alias).toEqual(noteName);
|
||||||
|
expect(noteMetaDtos[0].updateUser.userName).toEqual(user.userName);
|
||||||
});
|
});
|
||||||
|
|
||||||
afterAll(async () => {
|
afterAll(async () => {
|
||||||
|
|
Loading…
Reference in a new issue