From a18ea13f7823a195570ed18cfd4a3d32c9e60ec5 Mon Sep 17 00:00:00 2001 From: cballevre Date: Thu, 24 Nov 2022 18:50:20 +0100 Subject: [PATCH] fix(ContactsCollection): Check selector to prevent undefined This problem appears when you only have partialIndex so the selector which is where return undefined --- packages/cozy-stack-client/src/ContactsCollection.js | 6 +++++- .../cozy-stack-client/src/ContactsCollection.spec.js | 10 ++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/packages/cozy-stack-client/src/ContactsCollection.js b/packages/cozy-stack-client/src/ContactsCollection.js index 5a2f3b9d4..6efa53c93 100644 --- a/packages/cozy-stack-client/src/ContactsCollection.js +++ b/packages/cozy-stack-client/src/ContactsCollection.js @@ -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) diff --git a/packages/cozy-stack-client/src/ContactsCollection.spec.js b/packages/cozy-stack-client/src/ContactsCollection.spec.js index 831e8ba99..a2f37fabf 100644 --- a/packages/cozy-stack-client/src/ContactsCollection.spec.js +++ b/packages/cozy-stack-client/src/ContactsCollection.spec.js @@ -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({