mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-05-12 22:26:08 -04:00
refactor(note): lazy-load relations
Signed-off-by: David Mehren <git@herrmehren.de>
This commit is contained in:
parent
d761ff7f4f
commit
235e4f647c
23 changed files with 343 additions and 284 deletions
|
@ -69,7 +69,7 @@ describe('History', () => {
|
|||
note,
|
||||
user,
|
||||
);
|
||||
const entryDto = testSetup.historyService.toHistoryEntryDto(entry);
|
||||
const entryDto = await testSetup.historyService.toHistoryEntryDto(entry);
|
||||
const response = await agent
|
||||
.get('/api/private/me/history')
|
||||
.expect('Content-Type', /json/)
|
||||
|
@ -92,7 +92,7 @@ describe('History', () => {
|
|||
const pinStatus = true;
|
||||
const lastVisited = new Date('2020-12-01 12:23:34');
|
||||
const postEntryDto = new HistoryEntryImportDto();
|
||||
postEntryDto.note = note2.aliases.filter(
|
||||
postEntryDto.note = (await note2.aliases).filter(
|
||||
(alias) => alias.primary,
|
||||
)[0].name;
|
||||
postEntryDto.pinStatus = pinStatus;
|
||||
|
@ -104,13 +104,15 @@ describe('History', () => {
|
|||
.expect(201);
|
||||
const userEntries = await testSetup.historyService.getEntriesByUser(user);
|
||||
expect(userEntries.length).toEqual(1);
|
||||
expect(userEntries[0].note.aliases[0].name).toEqual(
|
||||
note2.aliases[0].name,
|
||||
expect((await userEntries[0].note.aliases)[0].name).toEqual(
|
||||
(await note2.aliases)[0].name,
|
||||
);
|
||||
expect(userEntries[0].note.aliases[0].primary).toEqual(
|
||||
note2.aliases[0].primary,
|
||||
expect((await userEntries[0].note.aliases)[0].primary).toEqual(
|
||||
(await note2.aliases)[0].primary,
|
||||
);
|
||||
expect((await userEntries[0].note.aliases)[0].id).toEqual(
|
||||
(await note2.aliases)[0].id,
|
||||
);
|
||||
expect(userEntries[0].note.aliases[0].id).toEqual(note2.aliases[0].id);
|
||||
expect(userEntries[0].user.username).toEqual(user.username);
|
||||
expect(userEntries[0].pinStatus).toEqual(pinStatus);
|
||||
expect(userEntries[0].updatedAt).toEqual(lastVisited);
|
||||
|
@ -129,7 +131,7 @@ describe('History', () => {
|
|||
pinStatus = !previousHistory[0].pinStatus;
|
||||
lastVisited = new Date('2020-12-01 23:34:45');
|
||||
postEntryDto = new HistoryEntryImportDto();
|
||||
postEntryDto.note = note2.aliases.filter(
|
||||
postEntryDto.note = (await note2.aliases).filter(
|
||||
(alias) => alias.primary,
|
||||
)[0].name;
|
||||
postEntryDto.pinStatus = pinStatus;
|
||||
|
@ -188,7 +190,8 @@ describe('History', () => {
|
|||
user,
|
||||
);
|
||||
expect(entry.pinStatus).toBeFalsy();
|
||||
const alias = entry.note.aliases.filter((alias) => alias.primary)[0].name;
|
||||
const alias = (await entry.note.aliases).filter((alias) => alias.primary)[0]
|
||||
.name;
|
||||
await agent
|
||||
.put(`/api/private/me/history/${alias || 'undefined'}`)
|
||||
.send({ pinStatus: true })
|
||||
|
@ -201,15 +204,16 @@ describe('History', () => {
|
|||
|
||||
it('DELETE /me/history/:note', async () => {
|
||||
const entry = await historyService.updateHistoryEntryTimestamp(note2, user);
|
||||
const alias = entry.note.aliases.filter((alias) => alias.primary)[0].name;
|
||||
const alias = (await entry.note.aliases).filter((alias) => alias.primary)[0]
|
||||
.name;
|
||||
const entry2 = await historyService.updateHistoryEntryTimestamp(note, user);
|
||||
const entryDto = historyService.toHistoryEntryDto(entry2);
|
||||
const entryDto = await historyService.toHistoryEntryDto(entry2);
|
||||
await agent
|
||||
.delete(`/api/private/me/history/${alias || 'undefined'}`)
|
||||
.expect(200);
|
||||
const userEntries = await historyService.getEntriesByUser(user);
|
||||
expect(userEntries.length).toEqual(1);
|
||||
const userEntryDto = historyService.toHistoryEntryDto(userEntries[0]);
|
||||
const userEntryDto = await historyService.toHistoryEntryDto(userEntries[0]);
|
||||
expect(userEntryDto.identifier).toEqual(entryDto.identifier);
|
||||
expect(userEntryDto.title).toEqual(entryDto.title);
|
||||
expect(userEntryDto.tags).toEqual(entryDto.tags);
|
||||
|
|
|
@ -51,8 +51,9 @@ describe('Me', () => {
|
|||
.expect(200);
|
||||
const history: HistoryEntryDto[] = response.body;
|
||||
expect(history.length).toEqual(1);
|
||||
const historyDto =
|
||||
testSetup.historyService.toHistoryEntryDto(createdHistoryEntry);
|
||||
const historyDto = await testSetup.historyService.toHistoryEntryDto(
|
||||
createdHistoryEntry,
|
||||
);
|
||||
for (const historyEntry of history) {
|
||||
expect(historyEntry.identifier).toEqual(historyDto.identifier);
|
||||
expect(historyEntry.title).toEqual(historyDto.title);
|
||||
|
@ -75,8 +76,9 @@ describe('Me', () => {
|
|||
.expect('Content-Type', /json/)
|
||||
.expect(200);
|
||||
const historyEntry: HistoryEntryDto = response.body;
|
||||
const historyEntryDto =
|
||||
testSetup.historyService.toHistoryEntryDto(createdHistoryEntry);
|
||||
const historyEntryDto = await testSetup.historyService.toHistoryEntryDto(
|
||||
createdHistoryEntry,
|
||||
);
|
||||
expect(historyEntry.identifier).toEqual(historyEntryDto.identifier);
|
||||
expect(historyEntry.title).toEqual(historyEntryDto.title);
|
||||
expect(historyEntry.tags).toEqual(historyEntryDto.tags);
|
||||
|
@ -109,8 +111,12 @@ describe('Me', () => {
|
|||
expect(historyEntry.pinStatus).toEqual(true);
|
||||
let theEntry: HistoryEntryDto;
|
||||
for (const entry of history) {
|
||||
if (entry.note.aliases.find((element) => element.name === noteName)) {
|
||||
theEntry = testSetup.historyService.toHistoryEntryDto(entry);
|
||||
if (
|
||||
(await entry.note.aliases).find(
|
||||
(element) => element.name === noteName,
|
||||
)
|
||||
) {
|
||||
theEntry = await testSetup.historyService.toHistoryEntryDto(entry);
|
||||
}
|
||||
}
|
||||
expect(theEntry.pinStatus).toEqual(true);
|
||||
|
@ -134,7 +140,11 @@ describe('Me', () => {
|
|||
expect(response.body).toEqual({});
|
||||
const history = await testSetup.historyService.getEntriesByUser(user);
|
||||
for (const entry of history) {
|
||||
if (entry.note.aliases.find((element) => element.name === noteName)) {
|
||||
if (
|
||||
(await entry.note.aliases).find(
|
||||
(element) => element.name === noteName,
|
||||
)
|
||||
) {
|
||||
throw new Error('Deleted history entry still in history');
|
||||
}
|
||||
}
|
||||
|
|
|
@ -200,16 +200,16 @@ describe('Notes', () => {
|
|||
updateNotePermission,
|
||||
);
|
||||
const updatedNote = await testSetup.notesService.getNoteByIdOrAlias(
|
||||
note.aliases.filter((alias) => alias.primary)[0].name,
|
||||
(await note.aliases).filter((alias) => alias.primary)[0].name,
|
||||
);
|
||||
expect(updatedNote.userPermissions).toHaveLength(1);
|
||||
expect(updatedNote.userPermissions[0].canEdit).toEqual(
|
||||
expect(await updatedNote.userPermissions).toHaveLength(1);
|
||||
expect((await updatedNote.userPermissions)[0].canEdit).toEqual(
|
||||
updateNotePermission.sharedToUsers[0].canEdit,
|
||||
);
|
||||
expect(updatedNote.userPermissions[0].user.username).toEqual(
|
||||
expect((await updatedNote.userPermissions)[0].user.username).toEqual(
|
||||
user.username,
|
||||
);
|
||||
expect(updatedNote.groupPermissions).toHaveLength(0);
|
||||
expect(await updatedNote.groupPermissions).toHaveLength(0);
|
||||
await request(testSetup.app.getHttpServer())
|
||||
.delete('/api/v2/notes/test3')
|
||||
.expect(204);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue