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 <philip.molares@udo.edu>
This commit is contained in:
Philip Molares 2021-03-17 10:30:37 +01:00
parent 1aa9b5f915
commit c6612f55c7

View file

@ -31,6 +31,7 @@ import { User } from '../../src/users/user.entity';
import { UsersModule } from '../../src/users/users.module'; import { UsersModule } from '../../src/users/users.module';
import { promises as fs } from 'fs'; import { promises as fs } from 'fs';
import { MediaService } from '../../src/media/media.service'; import { MediaService } from '../../src/media/media.service';
import { NotePermissionsUpdateDto } from '../../src/notes/note-permissions.dto';
import { join } from 'path'; import { join } from 'path';
describe('Notes', () => { describe('Notes', () => {
@ -160,6 +161,31 @@ describe('Notes', () => {
new NotInDBError("Note with id/alias 'test3' not found."), 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 () => { it('fails with a forbidden alias', async () => {
await request(app.getHttpServer()) await request(app.getHttpServer())
.delete(`/notes/${forbiddenNoteId}`) .delete(`/notes/${forbiddenNoteId}`)