mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-05-19 01:35:18 -04:00
fix: the tests use the new typing from create methods
Signed-off-by: Philip Molares <philip.molares@udo.edu>
This commit is contained in:
parent
d18d23cb16
commit
58d8ff71fe
11 changed files with 77 additions and 65 deletions
|
@ -113,7 +113,7 @@ describe('AliasService', () => {
|
|||
const user = User.create('hardcoded', 'Testy') as User;
|
||||
describe('creates', () => {
|
||||
it('an primary alias if no alias is already present', async () => {
|
||||
const note = Note.create(user);
|
||||
const note = Note.create(user) as Note;
|
||||
jest
|
||||
.spyOn(noteRepo, 'save')
|
||||
.mockImplementationOnce(async (note: Note): Promise<Note> => note);
|
||||
|
@ -124,7 +124,7 @@ describe('AliasService', () => {
|
|||
expect(savedAlias.primary).toBeTruthy();
|
||||
});
|
||||
it('an non-primary alias if an primary alias is already present', async () => {
|
||||
const note = Note.create(user, alias);
|
||||
const note = Note.create(user, alias) as Note;
|
||||
jest
|
||||
.spyOn(noteRepo, 'save')
|
||||
.mockImplementationOnce(async (note: Note): Promise<Note> => note);
|
||||
|
@ -136,11 +136,11 @@ describe('AliasService', () => {
|
|||
});
|
||||
});
|
||||
describe('does not create an alias', () => {
|
||||
const note = Note.create(user, alias2);
|
||||
const note = Note.create(user, alias2) as Note;
|
||||
it('with an already used name', async () => {
|
||||
jest
|
||||
.spyOn(aliasRepo, 'findOne')
|
||||
.mockResolvedValueOnce(Alias.create(alias2));
|
||||
.mockResolvedValueOnce(Alias.create(alias2, note) as Alias);
|
||||
await expect(service.addAlias(note, alias2)).rejects.toThrow(
|
||||
AlreadyInDBError,
|
||||
);
|
||||
|
@ -158,8 +158,8 @@ describe('AliasService', () => {
|
|||
const alias2 = 'testAlias2';
|
||||
const user = User.create('hardcoded', 'Testy') as User;
|
||||
describe('removes one alias correctly', () => {
|
||||
const note = Note.create(user, alias);
|
||||
note.aliases.push(Alias.create(alias2));
|
||||
const note = Note.create(user, alias) as Note;
|
||||
note.aliases.push(Alias.create(alias2, note) as Alias);
|
||||
it('with two aliases', async () => {
|
||||
jest
|
||||
.spyOn(noteRepo, 'save')
|
||||
|
@ -188,8 +188,8 @@ describe('AliasService', () => {
|
|||
});
|
||||
});
|
||||
describe('does not remove one alias', () => {
|
||||
const note = Note.create(user, alias);
|
||||
note.aliases.push(Alias.create(alias2));
|
||||
const note = Note.create(user, alias) as Note;
|
||||
note.aliases.push(Alias.create(alias2, note) as Alias);
|
||||
it('if the alias is unknown', async () => {
|
||||
await expect(service.removeAlias(note, 'non existent')).rejects.toThrow(
|
||||
NotInDBError,
|
||||
|
@ -204,10 +204,11 @@ describe('AliasService', () => {
|
|||
});
|
||||
|
||||
describe('makeAliasPrimary', () => {
|
||||
const alias = Alias.create('testAlias', true);
|
||||
const alias2 = Alias.create('testAlias2');
|
||||
const user = User.create('hardcoded', 'Testy') as User;
|
||||
const note = Note.create(user, alias.name);
|
||||
const aliasName = 'testAlias';
|
||||
const note = Note.create(user, aliasName) as Note;
|
||||
const alias = Alias.create(aliasName, note, true) as Alias;
|
||||
const alias2 = Alias.create('testAlias2', note) as Alias;
|
||||
note.aliases.push(alias2);
|
||||
it('mark the alias as primary', async () => {
|
||||
jest
|
||||
|
@ -256,9 +257,9 @@ describe('AliasService', () => {
|
|||
|
||||
it('toAliasDto correctly creates an AliasDto', () => {
|
||||
const aliasName = 'testAlias';
|
||||
const alias = Alias.create(aliasName, true);
|
||||
const user = User.create('hardcoded', 'Testy') as User;
|
||||
const note = Note.create(user, alias.name);
|
||||
const note = Note.create(user, aliasName) as Note;
|
||||
const alias = Alias.create(aliasName, note, true) as Alias;
|
||||
const aliasDto = service.toAliasDto(alias, note);
|
||||
expect(aliasDto.name).toEqual(aliasName);
|
||||
expect(aliasDto.primaryAlias).toBeTruthy();
|
||||
|
|
|
@ -131,7 +131,7 @@ describe('NotesService', () => {
|
|||
describe('works', () => {
|
||||
const user = User.create('hardcoded', 'Testy') as User;
|
||||
const alias = 'alias';
|
||||
const note = Note.create(user, alias);
|
||||
const note = Note.create(user, alias) as Note;
|
||||
|
||||
it('with no note', async () => {
|
||||
jest.spyOn(noteRepo, 'find').mockResolvedValueOnce(undefined);
|
||||
|
@ -168,7 +168,7 @@ describe('NotesService', () => {
|
|||
const revisions = await newNote.revisions;
|
||||
expect(revisions).toHaveLength(1);
|
||||
expect(revisions[0].content).toEqual(content);
|
||||
expect(newNote.historyEntries).toBeUndefined();
|
||||
expect(newNote.historyEntries).toHaveLength(0);
|
||||
expect(newNote.userPermissions).toHaveLength(0);
|
||||
expect(newNote.groupPermissions).toHaveLength(0);
|
||||
expect(newNote.tags).toHaveLength(0);
|
||||
|
@ -193,7 +193,7 @@ describe('NotesService', () => {
|
|||
const revisions = await newNote.revisions;
|
||||
expect(revisions).toHaveLength(1);
|
||||
expect(revisions[0].content).toEqual(content);
|
||||
expect(newNote.historyEntries).toBeUndefined();
|
||||
expect(newNote.historyEntries).toHaveLength(0);
|
||||
expect(newNote.userPermissions).toHaveLength(0);
|
||||
expect(newNote.groupPermissions).toHaveLength(0);
|
||||
expect(newNote.tags).toHaveLength(0);
|
||||
|
@ -328,7 +328,7 @@ describe('NotesService', () => {
|
|||
describe('deleteNote', () => {
|
||||
it('works', async () => {
|
||||
const user = User.create('hardcoded', 'Testy') as User;
|
||||
const note = Note.create(user);
|
||||
const note = Note.create(user) as Note;
|
||||
jest
|
||||
.spyOn(noteRepo, 'remove')
|
||||
.mockImplementationOnce(async (entry, _) => {
|
||||
|
@ -342,7 +342,7 @@ describe('NotesService', () => {
|
|||
describe('updateNote', () => {
|
||||
it('works', async () => {
|
||||
const user = User.create('hardcoded', 'Testy') as User;
|
||||
const note = Note.create(user);
|
||||
const note = Note.create(user) as Note;
|
||||
const revisionLength = (await note.revisions).length;
|
||||
jest
|
||||
.spyOn(noteRepo, 'save')
|
||||
|
@ -365,8 +365,8 @@ describe('NotesService', () => {
|
|||
const group = Group.create(
|
||||
groupPermissionUpate.groupname,
|
||||
groupPermissionUpate.groupname,
|
||||
);
|
||||
const note = Note.create(user);
|
||||
) as Group;
|
||||
const note = Note.create(user) as Note;
|
||||
describe('works', () => {
|
||||
it('with empty GroupPermissions and with empty UserPermissions', async () => {
|
||||
jest
|
||||
|
@ -668,8 +668,8 @@ describe('NotesService', () => {
|
|||
describe('toNotePermissionsDto', () => {
|
||||
it('works', async () => {
|
||||
const user = User.create('hardcoded', 'Testy') as User;
|
||||
const group = Group.create('testGroup', 'testGroup');
|
||||
const note = Note.create(user);
|
||||
const group = Group.create('testGroup', 'testGroup') as Group;
|
||||
const note = Note.create(user) as Note;
|
||||
note.userPermissions = [
|
||||
{
|
||||
note: note,
|
||||
|
@ -685,7 +685,8 @@ describe('NotesService', () => {
|
|||
},
|
||||
];
|
||||
const permissions = service.toNotePermissionsDto(note);
|
||||
expect(permissions.owner.username).toEqual(user.username);
|
||||
expect(permissions.owner).not.toEqual(null);
|
||||
expect(permissions.owner?.username).toEqual(user.username);
|
||||
expect(permissions.sharedToUsers).toHaveLength(1);
|
||||
expect(permissions.sharedToUsers[0].user.username).toEqual(user.username);
|
||||
expect(permissions.sharedToUsers[0].canEdit).toEqual(true);
|
||||
|
@ -702,7 +703,7 @@ describe('NotesService', () => {
|
|||
const user = User.create('hardcoded', 'Testy') as User;
|
||||
const author = Author.create(1);
|
||||
author.user = user;
|
||||
const group = Group.create('testGroup', 'testGroup');
|
||||
const group = Group.create('testGroup', 'testGroup') as Group;
|
||||
const content = 'testContent';
|
||||
jest
|
||||
.spyOn(noteRepo, 'save')
|
||||
|
@ -738,7 +739,7 @@ describe('NotesService', () => {
|
|||
// @ts-ignore
|
||||
.mockImplementation(() => createQueryBuilder);
|
||||
note.publicId = 'testId';
|
||||
note.aliases = [Alias.create('testAlias', true)];
|
||||
note.aliases = [Alias.create('testAlias', note, true) as Alias];
|
||||
note.title = 'testTitle';
|
||||
note.description = 'testDescription';
|
||||
note.owner = user;
|
||||
|
@ -799,7 +800,7 @@ describe('NotesService', () => {
|
|||
author.user = user;
|
||||
const otherUser = User.create('other hardcoded', 'Testy2') as User;
|
||||
otherUser.username = 'other hardcoded user';
|
||||
const group = Group.create('testGroup', 'testGroup');
|
||||
const group = Group.create('testGroup', 'testGroup') as Group;
|
||||
const content = 'testContent';
|
||||
jest
|
||||
.spyOn(noteRepo, 'save')
|
||||
|
@ -838,7 +839,7 @@ describe('NotesService', () => {
|
|||
// @ts-ignore
|
||||
.mockImplementation(() => createQueryBuilder);
|
||||
note.publicId = 'testId';
|
||||
note.aliases = [Alias.create('testAlias', true)];
|
||||
note.aliases = [Alias.create('testAlias', note, true) as Alias];
|
||||
note.title = 'testTitle';
|
||||
note.description = 'testDescription';
|
||||
note.owner = user;
|
||||
|
|
|
@ -27,10 +27,10 @@ describe('getPrimaryAlias', () => {
|
|||
let note: Note;
|
||||
beforeEach(() => {
|
||||
const user = User.create('hardcoded', 'Testy') as User;
|
||||
note = Note.create(user, alias);
|
||||
note = Note.create(user, alias) as Note;
|
||||
});
|
||||
it('finds correct primary alias', () => {
|
||||
note.aliases.push(Alias.create('annother', false));
|
||||
note.aliases.push(Alias.create('annother', note, false) as Alias);
|
||||
expect(getPrimaryAlias(note)).toEqual(alias);
|
||||
});
|
||||
it('returns undefined if there is no alias', () => {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue