From a55057b210f09c529ec4bcdaf1254684e1399998 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20Poizat?= Date: Thu, 31 Aug 2023 14:21:58 +0200 Subject: [PATCH] feat: Add instance data in loadInstanceOptionsFromStack --- docs/api/cozy-client/classes/CozyClient.md | 10 ++--- packages/cozy-client/src/CozyClient.js | 10 ++++- packages/cozy-client/src/CozyClient.spec.js | 44 +++++++++++++++------ 3 files changed, 45 insertions(+), 19 deletions(-) diff --git a/docs/api/cozy-client/classes/CozyClient.md b/docs/api/cozy-client/classes/CozyClient.md index 5b024213d4..8f0601339e 100644 --- a/docs/api/cozy-client/classes/CozyClient.md +++ b/docs/api/cozy-client/classes/CozyClient.md @@ -1099,7 +1099,7 @@ loadInstanceOptionsFromDOM - Loads the dataset injected by the Stack in web page loadInstanceOptionsFromStack - Loads the instance options from cozy-stack and exposes it through getInstanceOptions -For now only retrieving capabilities is supported +This method is not iso with loadInstanceOptionsFromDOM for now. *Returns* @@ -1604,7 +1604,7 @@ Saves multiple documents in one batch *Defined in* -[packages/cozy-client/src/CozyClient.js:1729](https://github.com/cozy/cozy-client/blob/master/packages/cozy-client/src/CozyClient.js#L1729) +[packages/cozy-client/src/CozyClient.js:1735](https://github.com/cozy/cozy-client/blob/master/packages/cozy-client/src/CozyClient.js#L1735) *** @@ -1628,7 +1628,7 @@ set some data in the store. *Defined in* -[packages/cozy-client/src/CozyClient.js:1702](https://github.com/cozy/cozy-client/blob/master/packages/cozy-client/src/CozyClient.js#L1702) +[packages/cozy-client/src/CozyClient.js:1708](https://github.com/cozy/cozy-client/blob/master/packages/cozy-client/src/CozyClient.js#L1708) *** @@ -1652,7 +1652,7 @@ At any time put an error function *Defined in* -[packages/cozy-client/src/CozyClient.js:1715](https://github.com/cozy/cozy-client/blob/master/packages/cozy-client/src/CozyClient.js#L1715) +[packages/cozy-client/src/CozyClient.js:1721](https://github.com/cozy/cozy-client/blob/master/packages/cozy-client/src/CozyClient.js#L1721) *** @@ -1728,7 +1728,7 @@ Contains the fetched token and the client information. These should be stored an *Defined in* -[packages/cozy-client/src/CozyClient.js:1722](https://github.com/cozy/cozy-client/blob/master/packages/cozy-client/src/CozyClient.js#L1722) +[packages/cozy-client/src/CozyClient.js:1728](https://github.com/cozy/cozy-client/blob/master/packages/cozy-client/src/CozyClient.js#L1728) *** diff --git a/packages/cozy-client/src/CozyClient.js b/packages/cozy-client/src/CozyClient.js index 9658d1169f..95bed8b553 100644 --- a/packages/cozy-client/src/CozyClient.js +++ b/packages/cozy-client/src/CozyClient.js @@ -1676,7 +1676,7 @@ instantiation of the client.` /** * loadInstanceOptionsFromStack - Loads the instance options from cozy-stack and exposes it through getInstanceOptions * - * For now only retrieving capabilities is supported + * This method is not iso with loadInstanceOptionsFromDOM for now. * * @returns {Promise} */ @@ -1685,8 +1685,14 @@ instantiation of the client.` Q('io.cozy.settings').getById('io.cozy.settings.capabilities') ) + const { data: instanceData } = await this.query( + Q('io.cozy.settings').getById('io.cozy.settings.instance') + ) + this.instanceOptions = { - capabilities: data.attributes + capabilities: data.attributes, + locale: instanceData.attributes.locale, + tracking: instanceData.attributes.tracking } this.capabilities = this.instanceOptions.capabilities || null diff --git a/packages/cozy-client/src/CozyClient.spec.js b/packages/cozy-client/src/CozyClient.spec.js index 8edbc23e5c..e9694b7432 100644 --- a/packages/cozy-client/src/CozyClient.spec.js +++ b/packages/cozy-client/src/CozyClient.spec.js @@ -492,9 +492,14 @@ describe('CozyClient logout', () => { }) it('should call reset on each link that can be reset', async () => { - client.query = jest.fn().mockResolvedValueOnce({ - data: { attributes: { file_versioning: true, flat_subdomains: true } } - }) + client.query = jest + .fn() + .mockResolvedValueOnce({ + data: { attributes: { file_versioning: true, flat_subdomains: true } } + }) + .mockResolvedValueOnce({ + data: { attributes: {} } + }) links[0].reset = jest.fn() links[2].reset = jest.fn() await client.login() @@ -512,9 +517,14 @@ describe('CozyClient logout', () => { }) it('should call all reset even if a reset throws an error', async () => { - client.query = jest.fn().mockResolvedValueOnce({ - data: { attributes: { file_versioning: true, flat_subdomains: true } } - }) + client.query = jest + .fn() + .mockResolvedValueOnce({ + data: { attributes: { file_versioning: true, flat_subdomains: true } } + }) + .mockResolvedValueOnce({ + data: { attributes: {} } + }) links[0].reset = jest.fn().mockRejectedValue(new Error('Async error')) links[2].reset = jest.fn() await client.login() @@ -524,9 +534,14 @@ describe('CozyClient logout', () => { }) it('should emit events', async () => { - client.query = jest.fn().mockResolvedValueOnce({ - data: { attributes: { file_versioning: true, flat_subdomains: true } } - }) + client.query = jest + .fn() + .mockResolvedValueOnce({ + data: { attributes: { file_versioning: true, flat_subdomains: true } } + }) + .mockResolvedValueOnce({ + data: { attributes: {} } + }) const originalLogout = client.logout links[0].reset = jest.fn() links[2].reset = jest.fn() @@ -545,9 +560,14 @@ describe('CozyClient logout', () => { }) it('should unregister an oauth client', async () => { - client.query = jest.fn().mockResolvedValueOnce({ - data: { attributes: { file_versioning: true, flat_subdomains: true } } - }) + client.query = jest + .fn() + .mockResolvedValueOnce({ + data: { attributes: { file_versioning: true, flat_subdomains: true } } + }) + .mockResolvedValueOnce({ + data: { attributes: {} } + }) await client.login() stackClient.isRegistered.mockReturnValue(true)