diff --git a/packages/cozy-pouch-link/src/CozyPouchLink.js b/packages/cozy-pouch-link/src/CozyPouchLink.js index aec391478..6191ac02d 100644 --- a/packages/cozy-pouch-link/src/CozyPouchLink.js +++ b/packages/cozy-pouch-link/src/CozyPouchLink.js @@ -539,7 +539,13 @@ class PouchLink extends CozyLink { async deleteDocument(mutation) { const res = await this.dbMethod('remove', mutation) - return parseMutationResult(mutation.document, res) + const document = { + ...mutation.document, + _id: res.id, + _rev: res.rev, + _deleted: true + } + return parseMutationResult(document, res) } async dbMethod(method, mutation) { diff --git a/packages/cozy-pouch-link/src/CozyPouchLink.spec.js b/packages/cozy-pouch-link/src/CozyPouchLink.spec.js index 6de9c44aa..9d1a05ea0 100644 --- a/packages/cozy-pouch-link/src/CozyPouchLink.spec.js +++ b/packages/cozy-pouch-link/src/CozyPouchLink.spec.js @@ -609,4 +609,21 @@ describe('CozyPouchLink', () => { spyIndex.mockRestore() }) }) + + describe('deleteDocument', () => { + it('should add _rev and _deleted prop to a deleted document', async () => { + await setup() + const document = { id: 'docId', rev: '123', ok: true } + link.dbMethod = jest.fn().mockReturnValue(document) + const res = await link.deleteDocument({ document }) + + expect(res).toMatchObject({ + id: 'docId', + _id: 'docId', + rev: '123', + _rev: '123', + _deleted: true + }) + }) + }) })