diff --git a/packages/manager/apps/pci-private-network/src/__mocks__/catalog.ts b/packages/manager/apps/pci-private-network/src/__mocks__/catalog.ts new file mode 100644 index 000000000000..96b3f0ceafed --- /dev/null +++ b/packages/manager/apps/pci-private-network/src/__mocks__/catalog.ts @@ -0,0 +1,23 @@ +const catalog = { + plans: [ + { + code: 'planCode1', + regions: [ + { + name: 'GRA11', + }, + { name: 'GRA7' }, + ], + }, + { + code: 'planCode2', + regions: [ + { + name: 'SGP1', + }, + ], + }, + ], +}; + +export { catalog }; diff --git a/packages/manager/apps/pci-private-network/src/data/hooks/networks/useNetworks.ts b/packages/manager/apps/pci-private-network/src/data/hooks/networks/useNetworks.ts index f44784bdb09d..184441db999a 100644 --- a/packages/manager/apps/pci-private-network/src/data/hooks/networks/useNetworks.ts +++ b/packages/manager/apps/pci-private-network/src/data/hooks/networks/useNetworks.ts @@ -140,6 +140,7 @@ export const fetchCheckPrivateNetworkCreationStatus = ( error.message as CreationStatus, ), retryDelay: (attemptIndex) => Math.min(1000 * 2 ** attemptIndex, 30000), + staleTime: 0, }); export const useSubnets = ( diff --git a/packages/manager/apps/pci-private-network/src/hooks/useGatewayAvailabilityRegion/useGatewayAvailabilityRegion.spec.tsx b/packages/manager/apps/pci-private-network/src/hooks/useGatewayAvailabilityRegion/useGatewayAvailabilityRegion.spec.tsx deleted file mode 100644 index ec5e59f7c938..000000000000 --- a/packages/manager/apps/pci-private-network/src/hooks/useGatewayAvailabilityRegion/useGatewayAvailabilityRegion.spec.tsx +++ /dev/null @@ -1,48 +0,0 @@ -import { describe, vi } from 'vitest'; -import { renderHook, waitFor } from '@testing-library/react'; -import useGatewayAvailabilityRegion from './useGatewayAvailabilityRegion'; - -vi.mock('@ovh-ux/manager-pci-common', () => ({ - useProject: vi.fn().mockReturnValue({ data: {} }), - useProductAvailability: vi.fn().mockReturnValue({ - data: { - plans: [ - { - code: 'planCode1', - regions: [ - { - name: 'GRA11', - }, - { name: 'GRA7' }, - ], - }, - { - code: 'planCode2', - regions: [ - { - name: 'SGP1', - }, - ], - }, - ], - }, - }), -})); - -describe('useGatewayAvailabilityRegion', () => { - it('should return false when gateway planCode does not exist for the region', () => { - const { result } = renderHook(() => - useGatewayAvailabilityRegion('SGP1', 'planCode1'), - ); - - expect(result.current).toBe(false); - }); - - it('should return true when gateway planCode exist for the region', async () => { - const { result } = renderHook(() => - useGatewayAvailabilityRegion('GRA11', 'planCode1'), - ); - - await waitFor(() => expect(result.current).toBe(true)); - }); -}); diff --git a/packages/manager/apps/pci-private-network/src/hooks/useGatewayAvailabilityRegion/useGatewayAvailabilityRegion.tsx b/packages/manager/apps/pci-private-network/src/hooks/useGatewayAvailabilityRegion/useGatewayAvailabilityRegion.tsx deleted file mode 100644 index 8c7375b0c4ee..000000000000 --- a/packages/manager/apps/pci-private-network/src/hooks/useGatewayAvailabilityRegion/useGatewayAvailabilityRegion.tsx +++ /dev/null @@ -1,22 +0,0 @@ -import { useMemo } from 'react'; -import { useProject, useProductAvailability } from '@ovh-ux/manager-pci-common'; - -export default function useGatewayAvailabilityRegion( - region: string, - planCode: string, -): boolean { - const { data: project } = useProject(); - const { data } = useProductAvailability(project.project_id, { - planCode, - }); - - return useMemo(() => { - const gateway = data?.plans.find(({ code }) => code === planCode); - - if (gateway) { - return gateway.regions.some(({ name }) => name === region); - } - - return false; - }, [data, region]); -} diff --git a/packages/manager/apps/pci-private-network/src/hooks/useIsPlanCodeAvailableInRegion/useIsPlanCodeAvailableInRegion useGatewayAvailabilityRegion.spec.tsx b/packages/manager/apps/pci-private-network/src/hooks/useIsPlanCodeAvailableInRegion/useIsPlanCodeAvailableInRegion.spec.tsx similarity index 71% rename from packages/manager/apps/pci-private-network/src/hooks/useIsPlanCodeAvailableInRegion/useIsPlanCodeAvailableInRegion useGatewayAvailabilityRegion.spec.tsx rename to packages/manager/apps/pci-private-network/src/hooks/useIsPlanCodeAvailableInRegion/useIsPlanCodeAvailableInRegion.spec.tsx index 7c5cca15fd54..e769885b1dbb 100644 --- a/packages/manager/apps/pci-private-network/src/hooks/useIsPlanCodeAvailableInRegion/useIsPlanCodeAvailableInRegion useGatewayAvailabilityRegion.spec.tsx +++ b/packages/manager/apps/pci-private-network/src/hooks/useIsPlanCodeAvailableInRegion/useIsPlanCodeAvailableInRegion.spec.tsx @@ -1,31 +1,12 @@ import { describe, vi } from 'vitest'; import { renderHook, waitFor } from '@testing-library/react'; +import { catalog } from '@/__mocks__/catalog'; import useGatewayAvailabilityRegion from './useIsPlanCodeAvailableInRegion'; vi.mock('@ovh-ux/manager-pci-common', () => ({ useProject: vi.fn().mockReturnValue({ data: {} }), useProductAvailability: vi.fn().mockReturnValue({ - data: { - plans: [ - { - code: 'planCode1', - regions: [ - { - name: 'GRA11', - }, - { name: 'GRA7' }, - ], - }, - { - code: 'planCode2', - regions: [ - { - name: 'SGP1', - }, - ], - }, - ], - }, + data: catalog, }), })); diff --git a/packages/manager/apps/pci-private-network/src/utils/test/test.provider.tsx b/packages/manager/apps/pci-private-network/src/utils/test/test.provider.tsx deleted file mode 100644 index 939a86e6bf3a..000000000000 --- a/packages/manager/apps/pci-private-network/src/utils/test/test.provider.tsx +++ /dev/null @@ -1,16 +0,0 @@ -import { FormProvider, useForm } from 'react-hook-form'; -import { zodResolver } from '@hookform/resolvers/zod'; -import { NewPrivateNetworkForm } from '@/types/private-network-form.type'; -import { NEW_PRIVATE_NETWORK_FORM_SCHEMA } from '@/pages/new/new.constants'; - -export function NewPrivateNetworkWrapper({ - children, -}: { - children: React.ReactNode; -}) { - const form = useForm({ - resolver: zodResolver(NEW_PRIVATE_NETWORK_FORM_SCHEMA), - }); - - return {children}; -}