Skip to content

Commit

Permalink
feat: Allow to skip maintenance for konnector with a flag
Browse files Browse the repository at this point in the history
  • Loading branch information
cballevre committed Nov 9, 2023
1 parent 39bb5c9 commit 64da8a7
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 4 deletions.
@@ -1,13 +1,28 @@
import { useQuery } from 'cozy-client'
import flag from 'cozy-flags'

import { buildAppsRegistryBySlug } from '../../helpers/queries'

const useMaintenanceStatus = slug => {
const skipMaintenanceList = flag('harvest.skip-maintenance-for.list') ?? []
const skipMaintenance = skipMaintenanceList.includes(slug)

const registryQuery = buildAppsRegistryBySlug(slug)
const registryResult = useQuery(
registryQuery.definition,
registryQuery.options
)
const registryResult = useQuery(registryQuery.definition, {
...registryQuery.options,
enabled: !skipMaintenance
})

if (skipMaintenance) {
return {
data: {
isInMaintenance: false,
messages: {}
},
fetchStatus: 'loaded',
lastError: null
}
}

return {
data: {
Expand Down
Expand Up @@ -2,9 +2,12 @@ import { renderHook } from '@testing-library/react-hooks'
import React from 'react'

import { CozyProvider, createMockClient } from 'cozy-client'
import flag from 'cozy-flags'

import useMaintenanceStatus from './useMaintenanceStatus'

jest.mock('cozy-flags')

describe('useMaintenanceStatus', () => {
const setup = (slug = 'test') => {
const mockClient = createMockClient({
Expand Down Expand Up @@ -65,4 +68,15 @@ describe('useMaintenanceStatus', () => {
new Error('Failed to found konnector')
)
})

it('should not be consider under maintenance if the slug is declared in the skip flag', async () => {
flag.mockReturnValue(['test'])

const { result } = setup()

expect(result.current.fetchStatus).toBe('loaded')
expect(result.current.data.isInMaintenance).toBe(false)
expect(result.current.data.messages).toEqual({})
expect(result.current.lastError).toBe(null)
})
})

0 comments on commit 64da8a7

Please sign in to comment.