Skip to content

Commit bd4c497

Browse files
doublefacedoubleface
doubleface
authored andcommittedDec 20, 2021
feat: Use fetchQueryAndGetFromState
With a fetchPolicy to 1 hour since the support mail is not supposed to change often.

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed
 

‎packages/cozy-harvest-lib/src/components/infos/TriggerErrorInfo.spec.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ describe('TriggerErrorInfo', () => {
3333

3434
const setup = ({ props: optionProps } = {}) => {
3535
fakeClient = {
36-
query: jest.fn()
36+
fetchQueryAndGetFromState: jest.fn()
3737
}
3838
const root = render(
3939
<AppLike client={fakeClient}>
@@ -58,8 +58,8 @@ describe('TriggerErrorInfo', () => {
5858
})
5959

6060
it('should render unknown error with configured mail support if any', () => {
61-
fakeClient.query.mockResolvedValue({
62-
data: { attributes: { support_address: 'test@address' } }
61+
fakeClient.fetchQueryAndGetFromState.mockResolvedValue({
62+
data: [{ attributes: { support_address: 'test@address' } }]
6363
})
6464
const { root } = setup({
6565
props: {

‎packages/cozy-harvest-lib/src/helpers/konnectors.js

+9-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import has from 'lodash/has'
33
import trim from 'lodash/trim'
44
import { getBoundT } from '../locales'
55

6-
import { Q } from 'cozy-client'
6+
import { Q, fetchPolicies } from 'cozy-client'
77

88
import * as accounts from './accounts'
99

@@ -168,8 +168,14 @@ export const getErrorLocale = (
168168
}
169169

170170
export const fetchSupportMail = async client => {
171-
const result = await client.query(Q('io.cozy.settings').getById('context'))
172-
return get(result, 'data.attributes.support_address', DEFAULT_SUPPORT_MAIL)
171+
const result = await client.fetchQueryAndGetFromState({
172+
definition: Q('io.cozy.settings').getById('context'),
173+
options: {
174+
as: 'contextSupportMail',
175+
fetchPolicy: fetchPolicies.olderThan(60 * 60 * 1000)
176+
}
177+
})
178+
return get(result, 'data[0].attributes.support_address', DEFAULT_SUPPORT_MAIL)
173179
}
174180

175181
export const getErrorLocaleBound = (

0 commit comments

Comments
 (0)
Please sign in to comment.