Skip to content

Commit

Permalink
fix(ContactsCollection): Check selector to prevent undefined
Browse files Browse the repository at this point in the history
This problem appears when you only have partialIndex so the selector which is where return undefined
  • Loading branch information
cballevre committed Jan 6, 2023
1 parent b0d4da5 commit a18ea13
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
6 changes: 5 additions & 1 deletion packages/cozy-stack-client/src/ContactsCollection.js
Expand Up @@ -10,7 +10,11 @@ const normalizeMyselfResp = resp => {

class ContactsCollection extends DocumentCollection {
async find(selector, options) {
if (Object.values(selector).length === 1 && selector['me'] == true) {
if (
selector !== undefined &&
Object.values(selector).length === 1 &&
selector['me'] == true
) {
return this.findMyself()
} else {
return super.find(selector, options)
Expand Down
10 changes: 10 additions & 0 deletions packages/cozy-stack-client/src/ContactsCollection.spec.js
Expand Up @@ -36,6 +36,16 @@ describe('ContactsCollection', () => {
jest.spyOn(console, 'warn').mockImplementation(() => {})
})

it('call find route if there is no selector', async () => {
const { col, stackClient } = setup()
await col.find()
expect(stackClient.fetchJSON).toHaveBeenCalledWith(
'POST',
'/data/io.cozy.contacts/_find',
expect.any(Object)
)
})

it('should use a special route for the myself contact', async () => {
const { col, stackClient } = setup()
const resp = await col.find({
Expand Down

0 comments on commit a18ea13

Please sign in to comment.