fix: save created revision on realtime note destroy

Signed-off-by: Tilman Vatteroth <git@tilmanvatteroth.de>
This commit is contained in:
Tilman Vatteroth 2023-06-21 13:11:30 +02:00
parent b3eb6e4339
commit cf02c35b49
4 changed files with 84 additions and 4 deletions

View file

@ -364,4 +364,50 @@ describe('RevisionsService', () => {
expect(saveSpy).not.toHaveBeenCalled();
});
});
describe('createAndSaveRevision', () => {
it('creates and saves a new revision', async () => {
const newRevision = Mock.of<Revision>();
const createRevisionSpy = jest
.spyOn(service, 'createRevision')
.mockResolvedValue(newRevision);
const repoSaveSpy = jest
.spyOn(revisionRepo, 'save')
.mockResolvedValue(newRevision);
const note = Mock.of<Note>({});
const newContent = 'MockContent';
const yjsState = [0, 1, 2, 3, 4, 5];
await service.createAndSaveRevision(note, newContent, yjsState);
expect(createRevisionSpy).toHaveBeenCalledWith(
note,
newContent,
yjsState,
);
expect(repoSaveSpy).toHaveBeenCalledWith(newRevision);
});
it("doesn't save if no revision has been created", async () => {
const createRevisionSpy = jest
.spyOn(service, 'createRevision')
.mockResolvedValue(undefined);
const repoSaveSpy = jest
.spyOn(revisionRepo, 'save')
.mockRejectedValue(new Error("shouldn't have been called"));
const note = Mock.of<Note>({});
const newContent = 'MockContent';
const yjsState = [0, 1, 2, 3, 4, 5];
await service.createAndSaveRevision(note, newContent, yjsState);
expect(createRevisionSpy).toHaveBeenCalledWith(
note,
newContent,
yjsState,
);
expect(repoSaveSpy).not.toHaveBeenCalled();
});
});
});