Add new API to purge note history #1064

Signed-off-by: Abhilasha Sinha <abhisinha662000@gmail.com>

Combine the describe block

Signed-off-by: Abhilasha Sinha <abhisinha662000@gmail.com>

Fix naming

Signed-off-by: Abhilasha Sinha <abhisinha662000@gmail.com>

Rename purgeRevision to purgeRevisions

Signed-off-by: Abhilasha Sinha <abhisinha662000@gmail.com>

Fix notes e2e test description

Signed-off-by: Abhilasha Sinha <abhisinha662000@gmail.com>

Add yarn.lock

Fix lint and format

Signed-off-by: Abhilasha Sinha <abhisinha662000@gmail.com>
This commit is contained in:
Abhilasha Sinha 2021-08-30 05:37:35 +05:30 committed by David Mehren
parent 170f4f6759
commit f63a2b79b7
No known key found for this signature in database
GPG key ID: 185982BA4C42B7C3
4 changed files with 147 additions and 0 deletions

View file

@ -97,4 +97,63 @@ describe('RevisionsService', () => {
);
});
});
describe('purgeRevisions', () => {
it('purges the revision history', async () => {
const note = {} as Note;
note.id = 'test';
let revisions: Revision[] = [];
const revision1 = Revision.create('a', 'a');
revision1.id = 1;
const revision2 = Revision.create('b', 'b');
revision2.id = 2;
const revision3 = Revision.create('c', 'c');
revision3.id = 3;
revisions.push(revision1, revision2, revision3);
note.revisions = Promise.resolve(revisions);
jest.spyOn(revisionRepo, 'find').mockResolvedValueOnce(revisions);
jest.spyOn(service, 'getLatestRevision').mockResolvedValueOnce(revision3);
revisionRepo.remove = jest
.fn()
.mockImplementation((deleteList: Revision[]) => {
revisions = revisions.filter(
(item: Revision) => !deleteList.includes(item),
);
return Promise.resolve(deleteList);
});
// expected to return all the purged revisions
expect(await service.purgeRevisions(note)).toHaveLength(2);
// expected to have only the latest revision
const updatedRevisions: Revision[] = [revision3];
expect(revisions).toEqual(updatedRevisions);
});
it('has no effect on revision history when a single revision is present', async () => {
const note = {} as Note;
note.id = 'test';
let revisions: Revision[] = [];
const revision1 = Revision.create('a', 'a');
revision1.id = 1;
revisions.push(revision1);
note.revisions = Promise.resolve(revisions);
jest.spyOn(revisionRepo, 'find').mockResolvedValueOnce(revisions);
jest.spyOn(service, 'getLatestRevision').mockResolvedValueOnce(revision1);
revisionRepo.remove = jest
.fn()
.mockImplementation((deleteList: Revision[]) => {
revisions = revisions.filter(
(item: Revision) => !deleteList.includes(item),
);
return Promise.resolve(deleteList);
});
// expected to return all the purged revisions
expect(await service.purgeRevisions(note)).toHaveLength(0);
// expected to have only the latest revision
const updatedRevisions: Revision[] = [revision1];
expect(revisions).toEqual(updatedRevisions);
});
});
});