mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2024-11-27 03:58:02 -05:00
HistoryService: Add unit test for getEntryByNoteIdOrAlias
Also add extra test to deleteHistoryEntry Signed-off-by: Philip Molares <philip.molares@udo.edu>
This commit is contained in:
parent
df2f14ffbf
commit
de098cf68e
1 changed files with 38 additions and 3 deletions
|
@ -111,6 +111,32 @@ describe('HistoryService', () => {
|
|||
});
|
||||
});
|
||||
|
||||
describe('getEntryByNoteIdOrAlias', () => {
|
||||
const user = {} as User;
|
||||
const alias = 'alias';
|
||||
describe('works', () => {
|
||||
it('with history entry', async () => {
|
||||
const note = Note.create(user, alias);
|
||||
const historyEntry = HistoryEntry.create(user, note);
|
||||
jest.spyOn(historyRepo, 'findOne').mockResolvedValueOnce(historyEntry);
|
||||
jest.spyOn(noteRepo, 'findOne').mockResolvedValueOnce(note);
|
||||
expect(await service.getEntryByNoteIdOrAlias(alias, user)).toEqual(
|
||||
historyEntry,
|
||||
);
|
||||
});
|
||||
});
|
||||
describe('fails', () => {
|
||||
it('with an non-existing note', async () => {
|
||||
jest.spyOn(noteRepo, 'findOne').mockResolvedValueOnce(undefined);
|
||||
try {
|
||||
await service.getEntryByNoteIdOrAlias(alias, {} as User);
|
||||
} catch (e) {
|
||||
expect(e).toBeInstanceOf(NotInDBError);
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('createOrUpdateHistoryEntry', () => {
|
||||
describe('works', () => {
|
||||
it('without an preexisting entry', async () => {
|
||||
|
@ -221,10 +247,11 @@ describe('HistoryService', () => {
|
|||
);
|
||||
await service.deleteHistoryEntry(alias, user);
|
||||
});
|
||||
|
||||
});
|
||||
describe('fails', () => {
|
||||
const user = {} as User;
|
||||
const alias = 'alias';
|
||||
it('without an entry', async () => {
|
||||
const user = {} as User;
|
||||
const alias = 'alias';
|
||||
const note = Note.create(user, alias);
|
||||
jest.spyOn(historyRepo, 'findOne').mockResolvedValueOnce(undefined);
|
||||
jest.spyOn(noteRepo, 'findOne').mockResolvedValueOnce(note);
|
||||
|
@ -234,6 +261,14 @@ describe('HistoryService', () => {
|
|||
expect(e).toBeInstanceOf(NotInDBError);
|
||||
}
|
||||
});
|
||||
it('without a note', async () => {
|
||||
jest.spyOn(noteRepo, 'findOne').mockResolvedValueOnce(undefined);
|
||||
try {
|
||||
await service.getEntryByNoteIdOrAlias(alias, {} as User);
|
||||
} catch (e) {
|
||||
expect(e).toBeInstanceOf(NotInDBError);
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
|
Loading…
Reference in a new issue