Skip to content

Commit

Permalink
feat: Add deleted true to a deleted doc with CozyPouchLink
Browse files Browse the repository at this point in the history
  • Loading branch information
JF-Cozy committed Aug 23, 2021
1 parent b0f6d2f commit 144be1d
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
8 changes: 7 additions & 1 deletion packages/cozy-pouch-link/src/CozyPouchLink.js
Expand Up @@ -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) {
Expand Down
17 changes: 17 additions & 0 deletions packages/cozy-pouch-link/src/CozyPouchLink.spec.js
Expand Up @@ -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
})
})
})
})

0 comments on commit 144be1d

Please sign in to comment.