Skip to content

Commit

Permalink
feat: Add instance data in loadInstanceOptionsFromStack
Browse files Browse the repository at this point in the history
  • Loading branch information
zatteo committed Aug 31, 2023
1 parent e03c217 commit 1c62657
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 19 deletions.
10 changes: 5 additions & 5 deletions docs/api/cozy-client/classes/CozyClient.md
Original file line number Diff line number Diff line change
Expand Up @@ -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*

Expand Down Expand Up @@ -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)

***

Expand All @@ -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)

***

Expand All @@ -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)

***

Expand Down Expand Up @@ -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)

***

Expand Down
10 changes: 8 additions & 2 deletions packages/cozy-client/src/CozyClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -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<void>}
*/
Expand All @@ -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
Expand Down
44 changes: 32 additions & 12 deletions packages/cozy-client/src/CozyClient.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: { locale: 'fr', tracking: true } }
})
links[0].reset = jest.fn()
links[2].reset = jest.fn()
await client.login()
Expand All @@ -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: { locale: 'fr', tracking: true } }
})
links[0].reset = jest.fn().mockRejectedValue(new Error('Async error'))
links[2].reset = jest.fn()
await client.login()
Expand All @@ -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: { locale: 'fr', tracking: true } }
})
const originalLogout = client.logout
links[0].reset = jest.fn()
links[2].reset = jest.fn()
Expand All @@ -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: { locale: 'fr', tracking: true } }
})
await client.login()
stackClient.isRegistered.mockReturnValue(true)

Expand Down

0 comments on commit 1c62657

Please sign in to comment.