Skip to content

Commit

Permalink
test: Add a unit test for ensureIndex that tests a partial filter
Browse files Browse the repository at this point in the history
This replies to #1506 (comment)
  • Loading branch information
Ldoppea committed Sep 24, 2024
1 parent fd3414c commit 66e8275
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions packages/cozy-pouch-link/src/CozyPouchLink.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -599,6 +599,28 @@ describe('CozyPouchLink', () => {
})
})

it('should handle partial filters', async () => {
spy = jest.spyOn(PouchDB.prototype, 'createIndex').mockReturnValue({})
await setup()
await link.ensureIndex(TODO_DOCTYPE, {
indexedFields: ['myIndex'],
partialFilter: { SOME_FIELD: { $exists: true } }
})
expect(spy).toHaveBeenCalled()
expect(spy).toHaveBeenCalledWith({
index: {
ddoc: 'by_myIndex_filter_(SOME_FIELD_$exists_true)',
fields: ['myIndex'],
indexName: 'by_myIndex_filter_(SOME_FIELD_$exists_true)',
partial_filter_selector: {
SOME_FIELD: {
$exists: true
}
}
}
})
})

it('uses the specified index', async () => {
let spyIndex = jest
.spyOn(CozyPouchLink.prototype, 'ensureIndex')
Expand Down

0 comments on commit 66e8275

Please sign in to comment.