From 5c138e41158c0d6b4335a65155c1ddec3cb63727 Mon Sep 17 00:00:00 2001 From: Philip Molares Date: Wed, 17 Mar 2021 10:30:37 +0100 Subject: [PATCH] PublicNotesE2E: Add extra test for note deletion This test checks if permission are correctly set and no error is thrown if the note is deleted. Signed-off-by: Philip Molares --- test/public-api/notes.e2e-spec.ts | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/test/public-api/notes.e2e-spec.ts b/test/public-api/notes.e2e-spec.ts index dcabd4dd5..63c5e661d 100644 --- a/test/public-api/notes.e2e-spec.ts +++ b/test/public-api/notes.e2e-spec.ts @@ -26,6 +26,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', () => { @@ -155,6 +156,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}`)