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 committed by David Mehren
parent cbf0ce98dd
commit 5c138e4115
No known key found for this signature in database
GPG key ID: 185982BA4C42B7C3

View file

@ -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}`)