fix: the tests use the new typing from create methods

Signed-off-by: Philip Molares <philip.molares@udo.edu>
This commit is contained in:
Philip Molares 2021-09-25 11:55:35 +02:00 committed by David Mehren
parent 8cda5f99fb
commit b1d4696895
No known key found for this signature in database
GPG key ID: 185982BA4C42B7C3
11 changed files with 77 additions and 65 deletions

View file

@ -62,9 +62,9 @@ describe('AuthService', () => {
user = User.create('hardcoded', 'Testy') as User; user = User.create('hardcoded', 'Testy') as User;
authToken = AuthToken.create( authToken = AuthToken.create(
'testKeyId',
user, user,
'testToken', 'testToken',
'testKeyId',
'abc', 'abc',
new Date(new Date().getTime() + 60000), // make this AuthToken valid for 1min new Date(new Date().getTime() + 60000), // make this AuthToken valid for 1min
) as AuthToken; ) as AuthToken;

View file

@ -39,7 +39,7 @@ describe('GroupsService', () => {
service = module.get<GroupsService>(GroupsService); service = module.get<GroupsService>(GroupsService);
groupRepo = module.get<Repository<Group>>(getRepositoryToken(Group)); groupRepo = module.get<Repository<Group>>(getRepositoryToken(Group));
group = Group.create('testGroup', 'Superheros'); group = Group.create('testGroup', 'Superheros') as Group;
}); });
it('should be defined', () => { it('should be defined', () => {

View file

@ -144,7 +144,10 @@ describe('HistoryService', () => {
describe('works', () => { describe('works', () => {
const user = {} as User; const user = {} as User;
const alias = 'alias'; const alias = 'alias';
const historyEntry = HistoryEntry.create(user, Note.create(user, alias)); const historyEntry = HistoryEntry.create(
user,
Note.create(user, alias) as Note,
) as HistoryEntry;
it('without an preexisting entry', async () => { it('without an preexisting entry', async () => {
jest.spyOn(historyRepo, 'findOne').mockResolvedValueOnce(undefined); jest.spyOn(historyRepo, 'findOne').mockResolvedValueOnce(undefined);
jest jest
@ -153,7 +156,7 @@ describe('HistoryService', () => {
async (entry: HistoryEntry): Promise<HistoryEntry> => entry, async (entry: HistoryEntry): Promise<HistoryEntry> => entry,
); );
const createHistoryEntry = await service.updateHistoryEntryTimestamp( const createHistoryEntry = await service.updateHistoryEntryTimestamp(
Note.create(user, alias), Note.create(user, alias) as Note,
user, user,
); );
expect(createHistoryEntry.note.aliases).toHaveLength(1); expect(createHistoryEntry.note.aliases).toHaveLength(1);
@ -171,7 +174,7 @@ describe('HistoryService', () => {
async (entry: HistoryEntry): Promise<HistoryEntry> => entry, async (entry: HistoryEntry): Promise<HistoryEntry> => entry,
); );
const createHistoryEntry = await service.updateHistoryEntryTimestamp( const createHistoryEntry = await service.updateHistoryEntryTimestamp(
Note.create(user, alias), Note.create(user, alias) as Note,
user, user,
); );
expect(createHistoryEntry.note.aliases).toHaveLength(1); expect(createHistoryEntry.note.aliases).toHaveLength(1);
@ -189,7 +192,7 @@ describe('HistoryService', () => {
describe('updateHistoryEntry', () => { describe('updateHistoryEntry', () => {
const user = {} as User; const user = {} as User;
const alias = 'alias'; const alias = 'alias';
const note = Note.create(user, alias); const note = Note.create(user, alias) as Note;
beforeEach(() => { beforeEach(() => {
const createQueryBuilder = { const createQueryBuilder = {
leftJoinAndSelect: () => createQueryBuilder, leftJoinAndSelect: () => createQueryBuilder,
@ -206,7 +209,7 @@ describe('HistoryService', () => {
}); });
describe('works', () => { describe('works', () => {
it('with an entry', async () => { it('with an entry', async () => {
const historyEntry = HistoryEntry.create(user, note); const historyEntry = HistoryEntry.create(user, note) as HistoryEntry;
jest.spyOn(historyRepo, 'findOne').mockResolvedValueOnce(historyEntry); jest.spyOn(historyRepo, 'findOne').mockResolvedValueOnce(historyEntry);
jest jest
.spyOn(historyRepo, 'save') .spyOn(historyRepo, 'save')
@ -242,8 +245,8 @@ describe('HistoryService', () => {
describe('works', () => { describe('works', () => {
const user = {} as User; const user = {} as User;
const alias = 'alias'; const alias = 'alias';
const note = Note.create(user, alias); const note = Note.create(user, alias) as Note;
const historyEntry = HistoryEntry.create(user, note); const historyEntry = HistoryEntry.create(user, note) as HistoryEntry;
it('with an entry', async () => { it('with an entry', async () => {
jest.spyOn(historyRepo, 'find').mockResolvedValueOnce([historyEntry]); jest.spyOn(historyRepo, 'find').mockResolvedValueOnce([historyEntry]);
jest jest
@ -258,8 +261,8 @@ describe('HistoryService', () => {
}); });
it('with multiple entries', async () => { it('with multiple entries', async () => {
const alias2 = 'alias2'; const alias2 = 'alias2';
const note2 = Note.create(user, alias2); const note2 = Note.create(user, alias2) as Note;
const historyEntry2 = HistoryEntry.create(user, note2); const historyEntry2 = HistoryEntry.create(user, note2) as HistoryEntry;
jest jest
.spyOn(historyRepo, 'find') .spyOn(historyRepo, 'find')
.mockResolvedValueOnce([historyEntry, historyEntry2]); .mockResolvedValueOnce([historyEntry, historyEntry2]);
@ -292,8 +295,8 @@ describe('HistoryService', () => {
it('with an entry', async () => { it('with an entry', async () => {
const user = {} as User; const user = {} as User;
const alias = 'alias'; const alias = 'alias';
const note = Note.create(user, alias); const note = Note.create(user, alias) as Note;
const historyEntry = HistoryEntry.create(user, note); const historyEntry = HistoryEntry.create(user, note) as HistoryEntry;
jest.spyOn(historyRepo, 'findOne').mockResolvedValueOnce(historyEntry); jest.spyOn(historyRepo, 'findOne').mockResolvedValueOnce(historyEntry);
const createQueryBuilder = { const createQueryBuilder = {
leftJoinAndSelect: () => createQueryBuilder, leftJoinAndSelect: () => createQueryBuilder,
@ -322,7 +325,7 @@ describe('HistoryService', () => {
const user = {} as User; const user = {} as User;
const alias = 'alias'; const alias = 'alias';
it('without an entry', async () => { it('without an entry', async () => {
const note = Note.create(user, alias); const note = Note.create(user, alias) as Note;
const createQueryBuilder = { const createQueryBuilder = {
leftJoinAndSelect: () => createQueryBuilder, leftJoinAndSelect: () => createQueryBuilder,
where: () => createQueryBuilder, where: () => createQueryBuilder,
@ -347,7 +350,7 @@ describe('HistoryService', () => {
it('works', async () => { it('works', async () => {
const user = {} as User; const user = {} as User;
const alias = 'alias'; const alias = 'alias';
const note = Note.create(user, alias); const note = Note.create(user, alias) as Note;
const historyEntry = HistoryEntry.create(user, note); const historyEntry = HistoryEntry.create(user, note);
const historyEntryImport: HistoryEntryImportDto = { const historyEntryImport: HistoryEntryImportDto = {
lastVisited: new Date('2020-12-01 12:23:34'), lastVisited: new Date('2020-12-01 12:23:34'),
@ -397,14 +400,14 @@ describe('HistoryService', () => {
const alias = 'alias'; const alias = 'alias';
const title = 'title'; const title = 'title';
const tags = ['tag1', 'tag2']; const tags = ['tag1', 'tag2'];
const note = Note.create(user, alias); const note = Note.create(user, alias) as Note;
note.title = title; note.title = title;
note.tags = tags.map((tag) => { note.tags = tags.map((tag) => {
const newTag = new Tag(); const newTag = new Tag();
newTag.name = tag; newTag.name = tag;
return newTag; return newTag;
}); });
const historyEntry = HistoryEntry.create(user, note); const historyEntry = HistoryEntry.create(user, note) as HistoryEntry;
historyEntry.pinStatus = true; historyEntry.pinStatus = true;
const createQueryBuilder = { const createQueryBuilder = {
leftJoinAndSelect: () => createQueryBuilder, leftJoinAndSelect: () => createQueryBuilder,

View file

@ -15,8 +15,8 @@ describe('getIdentifier', () => {
let entry: HistoryEntry; let entry: HistoryEntry;
beforeEach(() => { beforeEach(() => {
const user = User.create('hardcoded', 'Testy') as User; const user = User.create('hardcoded', 'Testy') as User;
note = Note.create(user, alias); note = Note.create(user, alias) as Note;
entry = HistoryEntry.create(user, note); entry = HistoryEntry.create(user, note) as HistoryEntry;
}); });
it('returns the publicId if there are no aliases', () => { it('returns the publicId if there are no aliases', () => {
note.aliases = undefined as unknown as Alias[]; note.aliases = undefined as unknown as Alias[];

View file

@ -95,7 +95,7 @@ describe('IdentityService', () => {
describe('loginWithLocalIdentity', () => { describe('loginWithLocalIdentity', () => {
it('works', async () => { it('works', async () => {
const identity = Identity.create(user, ProviderType.LOCAL); const identity = Identity.create(user, ProviderType.LOCAL) as Identity;
identity.passwordHash = await hashPassword(password); identity.passwordHash = await hashPassword(password);
user.identities = Promise.resolve([identity]); user.identities = Promise.resolve([identity]);
await expect( await expect(

View file

@ -106,7 +106,7 @@ describe('MediaService', () => {
beforeEach(() => { beforeEach(() => {
user = User.create('hardcoded', 'Testy') as User; user = User.create('hardcoded', 'Testy') as User;
const alias = 'alias'; const alias = 'alias';
note = Note.create(user, alias); note = Note.create(user, alias) as Note;
jest.spyOn(userRepo, 'findOne').mockResolvedValueOnce(user); jest.spyOn(userRepo, 'findOne').mockResolvedValueOnce(user);
const createQueryBuilder = { const createQueryBuilder = {
leftJoinAndSelect: () => createQueryBuilder, leftJoinAndSelect: () => createQueryBuilder,
@ -289,12 +289,12 @@ describe('MediaService', () => {
describe('removeNoteFromMediaUpload', () => { describe('removeNoteFromMediaUpload', () => {
it('works', async () => { it('works', async () => {
const mockNote = {} as Note;
mockNote.aliases = [Alias.create('test', mockNote, true) as Alias];
const mockMediaUploadEntry = { const mockMediaUploadEntry = {
id: 'testMediaUpload', id: 'testMediaUpload',
backendData: 'testBackendData', backendData: 'testBackendData',
note: { note: mockNote,
aliases: [Alias.create('test', true)],
} as Note,
user: { user: {
username: 'hardcoded', username: 'hardcoded',
} as User, } as User,

View file

@ -113,7 +113,7 @@ describe('AliasService', () => {
const user = User.create('hardcoded', 'Testy') as User; const user = User.create('hardcoded', 'Testy') as User;
describe('creates', () => { describe('creates', () => {
it('an primary alias if no alias is already present', async () => { it('an primary alias if no alias is already present', async () => {
const note = Note.create(user); const note = Note.create(user) as Note;
jest jest
.spyOn(noteRepo, 'save') .spyOn(noteRepo, 'save')
.mockImplementationOnce(async (note: Note): Promise<Note> => note); .mockImplementationOnce(async (note: Note): Promise<Note> => note);
@ -124,7 +124,7 @@ describe('AliasService', () => {
expect(savedAlias.primary).toBeTruthy(); expect(savedAlias.primary).toBeTruthy();
}); });
it('an non-primary alias if an primary alias is already present', async () => { 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 jest
.spyOn(noteRepo, 'save') .spyOn(noteRepo, 'save')
.mockImplementationOnce(async (note: Note): Promise<Note> => note); .mockImplementationOnce(async (note: Note): Promise<Note> => note);
@ -136,11 +136,11 @@ describe('AliasService', () => {
}); });
}); });
describe('does not create an alias', () => { 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 () => { it('with an already used name', async () => {
jest jest
.spyOn(aliasRepo, 'findOne') .spyOn(aliasRepo, 'findOne')
.mockResolvedValueOnce(Alias.create(alias2)); .mockResolvedValueOnce(Alias.create(alias2, note) as Alias);
await expect(service.addAlias(note, alias2)).rejects.toThrow( await expect(service.addAlias(note, alias2)).rejects.toThrow(
AlreadyInDBError, AlreadyInDBError,
); );
@ -158,8 +158,8 @@ describe('AliasService', () => {
const alias2 = 'testAlias2'; const alias2 = 'testAlias2';
const user = User.create('hardcoded', 'Testy') as User; const user = User.create('hardcoded', 'Testy') as User;
describe('removes one alias correctly', () => { describe('removes one alias correctly', () => {
const note = Note.create(user, alias); const note = Note.create(user, alias) as Note;
note.aliases.push(Alias.create(alias2)); note.aliases.push(Alias.create(alias2, note) as Alias);
it('with two aliases', async () => { it('with two aliases', async () => {
jest jest
.spyOn(noteRepo, 'save') .spyOn(noteRepo, 'save')
@ -188,8 +188,8 @@ describe('AliasService', () => {
}); });
}); });
describe('does not remove one alias', () => { describe('does not remove one alias', () => {
const note = Note.create(user, alias); const note = Note.create(user, alias) as Note;
note.aliases.push(Alias.create(alias2)); note.aliases.push(Alias.create(alias2, note) as Alias);
it('if the alias is unknown', async () => { it('if the alias is unknown', async () => {
await expect(service.removeAlias(note, 'non existent')).rejects.toThrow( await expect(service.removeAlias(note, 'non existent')).rejects.toThrow(
NotInDBError, NotInDBError,
@ -204,10 +204,11 @@ describe('AliasService', () => {
}); });
describe('makeAliasPrimary', () => { describe('makeAliasPrimary', () => {
const alias = Alias.create('testAlias', true);
const alias2 = Alias.create('testAlias2');
const user = User.create('hardcoded', 'Testy') as User; 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); note.aliases.push(alias2);
it('mark the alias as primary', async () => { it('mark the alias as primary', async () => {
jest jest
@ -256,9 +257,9 @@ describe('AliasService', () => {
it('toAliasDto correctly creates an AliasDto', () => { it('toAliasDto correctly creates an AliasDto', () => {
const aliasName = 'testAlias'; const aliasName = 'testAlias';
const alias = Alias.create(aliasName, true);
const user = User.create('hardcoded', 'Testy') as User; 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); const aliasDto = service.toAliasDto(alias, note);
expect(aliasDto.name).toEqual(aliasName); expect(aliasDto.name).toEqual(aliasName);
expect(aliasDto.primaryAlias).toBeTruthy(); expect(aliasDto.primaryAlias).toBeTruthy();

View file

@ -131,7 +131,7 @@ describe('NotesService', () => {
describe('works', () => { describe('works', () => {
const user = User.create('hardcoded', 'Testy') as User; const user = User.create('hardcoded', 'Testy') as User;
const alias = 'alias'; const alias = 'alias';
const note = Note.create(user, alias); const note = Note.create(user, alias) as Note;
it('with no note', async () => { it('with no note', async () => {
jest.spyOn(noteRepo, 'find').mockResolvedValueOnce(undefined); jest.spyOn(noteRepo, 'find').mockResolvedValueOnce(undefined);
@ -168,7 +168,7 @@ describe('NotesService', () => {
const revisions = await newNote.revisions; const revisions = await newNote.revisions;
expect(revisions).toHaveLength(1); expect(revisions).toHaveLength(1);
expect(revisions[0].content).toEqual(content); expect(revisions[0].content).toEqual(content);
expect(newNote.historyEntries).toBeUndefined(); expect(newNote.historyEntries).toHaveLength(0);
expect(newNote.userPermissions).toHaveLength(0); expect(newNote.userPermissions).toHaveLength(0);
expect(newNote.groupPermissions).toHaveLength(0); expect(newNote.groupPermissions).toHaveLength(0);
expect(newNote.tags).toHaveLength(0); expect(newNote.tags).toHaveLength(0);
@ -193,7 +193,7 @@ describe('NotesService', () => {
const revisions = await newNote.revisions; const revisions = await newNote.revisions;
expect(revisions).toHaveLength(1); expect(revisions).toHaveLength(1);
expect(revisions[0].content).toEqual(content); expect(revisions[0].content).toEqual(content);
expect(newNote.historyEntries).toBeUndefined(); expect(newNote.historyEntries).toHaveLength(0);
expect(newNote.userPermissions).toHaveLength(0); expect(newNote.userPermissions).toHaveLength(0);
expect(newNote.groupPermissions).toHaveLength(0); expect(newNote.groupPermissions).toHaveLength(0);
expect(newNote.tags).toHaveLength(0); expect(newNote.tags).toHaveLength(0);
@ -328,7 +328,7 @@ describe('NotesService', () => {
describe('deleteNote', () => { describe('deleteNote', () => {
it('works', async () => { it('works', async () => {
const user = User.create('hardcoded', 'Testy') as User; const user = User.create('hardcoded', 'Testy') as User;
const note = Note.create(user); const note = Note.create(user) as Note;
jest jest
.spyOn(noteRepo, 'remove') .spyOn(noteRepo, 'remove')
.mockImplementationOnce(async (entry, _) => { .mockImplementationOnce(async (entry, _) => {
@ -342,7 +342,7 @@ describe('NotesService', () => {
describe('updateNote', () => { describe('updateNote', () => {
it('works', async () => { it('works', async () => {
const user = User.create('hardcoded', 'Testy') as User; 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; const revisionLength = (await note.revisions).length;
jest jest
.spyOn(noteRepo, 'save') .spyOn(noteRepo, 'save')
@ -365,8 +365,8 @@ describe('NotesService', () => {
const group = Group.create( const group = Group.create(
groupPermissionUpate.groupname, groupPermissionUpate.groupname,
groupPermissionUpate.groupname, groupPermissionUpate.groupname,
); ) as Group;
const note = Note.create(user); const note = Note.create(user) as Note;
describe('works', () => { describe('works', () => {
it('with empty GroupPermissions and with empty UserPermissions', async () => { it('with empty GroupPermissions and with empty UserPermissions', async () => {
jest jest
@ -668,8 +668,8 @@ describe('NotesService', () => {
describe('toNotePermissionsDto', () => { describe('toNotePermissionsDto', () => {
it('works', async () => { it('works', async () => {
const user = User.create('hardcoded', 'Testy') as User; const user = User.create('hardcoded', 'Testy') as User;
const group = Group.create('testGroup', 'testGroup'); const group = Group.create('testGroup', 'testGroup') as Group;
const note = Note.create(user); const note = Note.create(user) as Note;
note.userPermissions = [ note.userPermissions = [
{ {
note: note, note: note,
@ -685,7 +685,8 @@ describe('NotesService', () => {
}, },
]; ];
const permissions = service.toNotePermissionsDto(note); 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).toHaveLength(1);
expect(permissions.sharedToUsers[0].user.username).toEqual(user.username); expect(permissions.sharedToUsers[0].user.username).toEqual(user.username);
expect(permissions.sharedToUsers[0].canEdit).toEqual(true); expect(permissions.sharedToUsers[0].canEdit).toEqual(true);
@ -702,7 +703,7 @@ describe('NotesService', () => {
const user = User.create('hardcoded', 'Testy') as User; const user = User.create('hardcoded', 'Testy') as User;
const author = Author.create(1); const author = Author.create(1);
author.user = user; author.user = user;
const group = Group.create('testGroup', 'testGroup'); const group = Group.create('testGroup', 'testGroup') as Group;
const content = 'testContent'; const content = 'testContent';
jest jest
.spyOn(noteRepo, 'save') .spyOn(noteRepo, 'save')
@ -738,7 +739,7 @@ describe('NotesService', () => {
// @ts-ignore // @ts-ignore
.mockImplementation(() => createQueryBuilder); .mockImplementation(() => createQueryBuilder);
note.publicId = 'testId'; note.publicId = 'testId';
note.aliases = [Alias.create('testAlias', true)]; note.aliases = [Alias.create('testAlias', note, true) as Alias];
note.title = 'testTitle'; note.title = 'testTitle';
note.description = 'testDescription'; note.description = 'testDescription';
note.owner = user; note.owner = user;
@ -799,7 +800,7 @@ describe('NotesService', () => {
author.user = user; author.user = user;
const otherUser = User.create('other hardcoded', 'Testy2') as User; const otherUser = User.create('other hardcoded', 'Testy2') as User;
otherUser.username = 'other hardcoded user'; otherUser.username = 'other hardcoded user';
const group = Group.create('testGroup', 'testGroup'); const group = Group.create('testGroup', 'testGroup') as Group;
const content = 'testContent'; const content = 'testContent';
jest jest
.spyOn(noteRepo, 'save') .spyOn(noteRepo, 'save')
@ -838,7 +839,7 @@ describe('NotesService', () => {
// @ts-ignore // @ts-ignore
.mockImplementation(() => createQueryBuilder); .mockImplementation(() => createQueryBuilder);
note.publicId = 'testId'; note.publicId = 'testId';
note.aliases = [Alias.create('testAlias', true)]; note.aliases = [Alias.create('testAlias', note, true) as Alias];
note.title = 'testTitle'; note.title = 'testTitle';
note.description = 'testDescription'; note.description = 'testDescription';
note.owner = user; note.owner = user;

View file

@ -27,10 +27,10 @@ describe('getPrimaryAlias', () => {
let note: Note; let note: Note;
beforeEach(() => { beforeEach(() => {
const user = User.create('hardcoded', 'Testy') as User; 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', () => { 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); expect(getPrimaryAlias(note)).toEqual(alias);
}); });
it('returns undefined if there is no alias', () => { it('returns undefined if there is no alias', () => {

View file

@ -265,30 +265,36 @@ describe('PermissionsService', () => {
const everybody: Group = Group.create( const everybody: Group = Group.create(
SpecialGroup.EVERYONE, SpecialGroup.EVERYONE,
SpecialGroup.EVERYONE, SpecialGroup.EVERYONE,
); ) as Group;
everybody.special = true; everybody.special = true;
result[SpecialGroup.EVERYONE] = everybody; result[SpecialGroup.EVERYONE] = everybody;
const loggedIn = Group.create( const loggedIn = Group.create(
SpecialGroup.LOGGED_IN, SpecialGroup.LOGGED_IN,
SpecialGroup.LOGGED_IN, SpecialGroup.LOGGED_IN,
); ) as Group;
loggedIn.special = true; loggedIn.special = true;
result[SpecialGroup.LOGGED_IN] = loggedIn; result[SpecialGroup.LOGGED_IN] = loggedIn;
const user1group = Group.create('user1group', 'user1group'); const user1group = Group.create('user1group', 'user1group') as Group;
user1group.members = [user1]; user1group.members = [user1];
result['user1group'] = user1group; result['user1group'] = user1group;
const user2group = Group.create('user2group', 'user2group'); const user2group = Group.create('user2group', 'user2group') as Group;
user2group.members = [user2]; user2group.members = [user2];
result['user2group'] = user2group; result['user2group'] = user2group;
const user1and2group = Group.create('user1and2group', 'user1and2group'); const user1and2group = Group.create(
'user1and2group',
'user1and2group',
) as Group;
user1and2group.members = [user1, user2]; user1and2group.members = [user1, user2];
result['user1and2group'] = user1and2group; result['user1and2group'] = user1and2group;
const user2and1group = Group.create('user2and1group', 'user2and1group'); const user2and1group = Group.create(
'user2and1group',
'user2and1group',
) as Group;
user2and1group.members = [user2, user1]; user2and1group.members = [user2, user1];
result['user2and1group'] = user2and1group; result['user2and1group'] = user2and1group;
@ -308,7 +314,7 @@ describe('PermissionsService', () => {
group: Group, group: Group,
write: boolean, write: boolean,
): NoteGroupPermission { ): NoteGroupPermission {
return NoteGroupPermission.create(group, write); return NoteGroupPermission.create(group, {} as Note, write);
} }
const everybodyRead = createNoteGroupPermission( const everybodyRead = createNoteGroupPermission(

View file

@ -89,7 +89,8 @@ describe('RevisionsService', () => {
describe('getRevision', () => { describe('getRevision', () => {
it('returns a revision', async () => { it('returns a revision', async () => {
const revision = Revision.create('', ''); const note = {} as Note;
const revision = Revision.create('', '', note) as Revision;
jest.spyOn(revisionRepo, 'findOne').mockResolvedValueOnce(revision); jest.spyOn(revisionRepo, 'findOne').mockResolvedValueOnce(revision);
expect(await service.getRevision({} as Note, 1)).toEqual(revision); expect(await service.getRevision({} as Note, 1)).toEqual(revision);
}); });
@ -106,11 +107,11 @@ describe('RevisionsService', () => {
const note = {} as Note; const note = {} as Note;
note.id = 'test'; note.id = 'test';
let revisions: Revision[] = []; let revisions: Revision[] = [];
const revision1 = Revision.create('a', 'a'); const revision1 = Revision.create('a', 'a', note) as Revision;
revision1.id = 1; revision1.id = 1;
const revision2 = Revision.create('b', 'b'); const revision2 = Revision.create('b', 'b', note) as Revision;
revision2.id = 2; revision2.id = 2;
const revision3 = Revision.create('c', 'c'); const revision3 = Revision.create('c', 'c', note) as Revision;
revision3.id = 3; revision3.id = 3;
revisions.push(revision1, revision2, revision3); revisions.push(revision1, revision2, revision3);
note.revisions = Promise.resolve(revisions); note.revisions = Promise.resolve(revisions);
@ -136,7 +137,7 @@ describe('RevisionsService', () => {
const note = {} as Note; const note = {} as Note;
note.id = 'test'; note.id = 'test';
let revisions: Revision[] = []; let revisions: Revision[] = [];
const revision1 = Revision.create('a', 'a'); const revision1 = Revision.create('a', 'a', note) as Revision;
revision1.id = 1; revision1.id = 1;
revisions.push(revision1); revisions.push(revision1);
note.revisions = Promise.resolve(revisions); note.revisions = Promise.resolve(revisions);