-
-
Notifications
You must be signed in to change notification settings - Fork 727
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: traffic limits for enterprise-payg (#8596)
- Loading branch information
Showing
5 changed files
with
110 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
frontend/src/component/admin/network/NetworkTrafficUsage/hooks/useTrafficLimit.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import { renderHook } from '@testing-library/react'; | ||
import { useTrafficLimit } from './useTrafficLimit'; | ||
import useUiConfig from 'hooks/api/getters/useUiConfig/useUiConfig'; | ||
import { useUiFlag } from 'hooks/useUiFlag'; | ||
import { vi, describe, it, expect } from 'vitest'; | ||
|
||
vi.mock('hooks/api/getters/useUiConfig/useUiConfig'); | ||
vi.mock('hooks/useUiFlag'); | ||
|
||
describe('useTrafficLimit', () => { | ||
it('should return requests limit if user is on pro plan', () => { | ||
vi.mocked(useUiConfig).mockReturnValue({ | ||
isPro: () => true, | ||
isEnterprise: () => false, | ||
uiConfig: { | ||
billing: 'pay-as-you-go', | ||
}, | ||
} as any); | ||
vi.mocked(useUiFlag).mockReturnValue(false); | ||
|
||
const { result } = renderHook(() => useTrafficLimit()); | ||
|
||
expect(result.current).toBe(53_000_000); | ||
}); | ||
|
||
it('should return PAYG plan requests limit if enterprise-payg is enabled and billing is pay-as-you-go', () => { | ||
vi.mocked(useUiConfig).mockReturnValue({ | ||
isPro: () => false, | ||
isEnterprise: () => true, | ||
uiConfig: { billing: 'pay-as-you-go' }, | ||
} as any); | ||
vi.mocked(useUiFlag).mockReturnValue(true); | ||
|
||
const { result } = renderHook(() => useTrafficLimit()); | ||
|
||
expect(result.current).toBe(53_000_000); | ||
}); | ||
|
||
it('should return 0 if user is not on pro plan and pay-as-you-go conditions are not met', () => { | ||
vi.mocked(useUiConfig).mockReturnValue({ | ||
isPro: () => false, | ||
isEnterprise: () => false, | ||
uiConfig: {}, | ||
} as any); | ||
vi.mocked(useUiFlag).mockReturnValue(false); | ||
|
||
const { result } = renderHook(() => useTrafficLimit()); | ||
|
||
expect(result.current).toBe(0); | ||
}); | ||
|
||
it('should return 0 if user is not on pro plan and flag is disabled', () => { | ||
vi.mocked(useUiConfig).mockReturnValue({ | ||
isPro: () => false, | ||
isEnterprise: () => true, | ||
uiConfig: { billing: 'pay-as-you-go' }, | ||
} as any); | ||
vi.mocked(useUiFlag).mockReturnValue(false); | ||
|
||
const { result } = renderHook(() => useTrafficLimit()); | ||
|
||
expect(result.current).toBe(0); | ||
}); | ||
|
||
it('should return 0 if enterprise PAYG is enabled but billing is not pay-as-you-go', () => { | ||
vi.mocked(useUiConfig).mockReturnValue({ | ||
isPro: () => false, | ||
isEnterprise: () => false, | ||
uiConfig: { billing: 'subscription' }, | ||
} as any); | ||
vi.mocked(useUiFlag).mockReturnValue(true); | ||
|
||
const { result } = renderHook(() => useTrafficLimit()); | ||
|
||
expect(result.current).toBe(0); | ||
}); | ||
}); |
24 changes: 24 additions & 0 deletions
24
frontend/src/component/admin/network/NetworkTrafficUsage/hooks/useTrafficLimit.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import useUiConfig from 'hooks/api/getters/useUiConfig/useUiConfig'; | ||
import { useUiFlag } from 'hooks/useUiFlag'; | ||
|
||
const proPlanIncludedRequests = 53_000_000; | ||
const paygPlanIncludedRequests = proPlanIncludedRequests; | ||
|
||
export const useTrafficLimit = () => { | ||
const { isPro, isEnterprise, uiConfig } = useUiConfig(); | ||
const isEnterprisePaygEnabled = useUiFlag('enterprise-payg'); | ||
|
||
if (isPro()) { | ||
return proPlanIncludedRequests; | ||
} | ||
|
||
if ( | ||
isEnterprisePaygEnabled && | ||
isEnterprise() && | ||
uiConfig.billing === 'pay-as-you-go' | ||
) { | ||
return paygPlanIncludedRequests; | ||
} | ||
|
||
return 0; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters