diff --git a/test/public-api/notes.e2e-spec.ts b/test/public-api/notes.e2e-spec.ts index b86d187fd..03aeda5df 100644 --- a/test/public-api/notes.e2e-spec.ts +++ b/test/public-api/notes.e2e-spec.ts @@ -31,6 +31,7 @@ import { User } from '../../src/users/user.entity'; import { UsersModule } from '../../src/users/users.module'; import { promises as fs } from 'fs'; import { MediaService } from '../../src/media/media.service'; +import { NotePermissionsUpdateDto } from '../../src/notes/note-permissions.dto'; import { join } from 'path'; describe('Notes', () => { @@ -160,6 +161,31 @@ describe('Notes', () => { new NotInDBError("Note with id/alias 'test3' not found."), ); }); + it('works with an existing alias with permissions', async () => { + const note = await notesService.createNote(content, 'test3', user); + const updateNotePermission = new NotePermissionsUpdateDto(); + updateNotePermission.sharedToUsers = [ + { + username: user.userName, + canEdit: true, + }, + ]; + updateNotePermission.sharedToGroups = []; + await notesService.updateNotePermissions(note, updateNotePermission); + const updatedNote = await notesService.getNoteByIdOrAlias(note.alias); + expect(updatedNote.userPermissions).toHaveLength(1); + expect(updatedNote.userPermissions[0].canEdit).toEqual( + updateNotePermission.sharedToUsers[0].canEdit, + ); + expect(updatedNote.userPermissions[0].user.userName).toEqual( + user.userName, + ); + expect(updatedNote.groupPermissions).toHaveLength(0); + await request(app.getHttpServer()).delete('/notes/test3').expect(204); + await expect(notesService.getNoteByIdOrAlias('test3')).rejects.toEqual( + new NotInDBError("Note with id/alias 'test3' not found."), + ); + }); it('fails with a forbidden alias', async () => { await request(app.getHttpServer()) .delete(`/notes/${forbiddenNoteId}`)