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 c897619
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 15 deletions.
9 changes: 6 additions & 3 deletions packages/cozy-client/src/CozyClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -1676,17 +1676,20 @@ instantiation of the client.`
/**
* loadInstanceOptionsFromStack - Loads the instance options from cozy-stack and exposes it through getInstanceOptions
*
* For now only retrieving capabilities is supported
*
* @returns {Promise<void>}
*/
async loadInstanceOptionsFromStack() {
const { data } = await this.query(
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,
...instanceData.attributes
}

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: {} }
})
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: {} }
})
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: {} }
})
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: {} }
})
await client.login()
stackClient.isRegistered.mockReturnValue(true)

Expand Down

0 comments on commit c897619

Please sign in to comment.