diff --git a/packages/manager/apps/pci-rancher/src/utils/rancherPrices.test.ts b/packages/manager/apps/pci-rancher/src/utils/rancherPrices.test.ts index 3a7ae8d0b8d4..1d37d85c04df 100644 --- a/packages/manager/apps/pci-rancher/src/utils/rancherPrices.test.ts +++ b/packages/manager/apps/pci-rancher/src/utils/rancherPrices.test.ts @@ -2,13 +2,13 @@ import { RancherPlanCode, RancherPlanName } from '@/types/api.type'; import { findPlanByCode, isConsumptionPlan, + calculateMonthlyPrice, getRancherPlanName, getPlanPricing, } from './rancherPrices'; import { mockCatalog } from '@/_mock_/catalog'; describe('Rancher Prices Utilities', () => { - const EXPECTED_MONTHLY_PRICING = 73_000; describe('findPlanByCode', () => { it('should find a plan by its code', () => { const result = findPlanByCode( @@ -39,6 +39,18 @@ describe('Rancher Prices Utilities', () => { }); }); + describe('calculateMonthlyPrice', () => { + it('should calculate monthly price from hourly price', () => { + const result = calculateMonthlyPrice(100); + expect(result).toBe(72000); + }); + + it('should return 0 if hourly price is 0', () => { + const result = calculateMonthlyPrice(0); + expect(result).toBe(0); + }); + }); + describe('getRancherPlanName', () => { it('should return OVHCLOUD_EDITION for ovhcloud plans', () => { const result = getRancherPlanName(RancherPlanCode.OVHCLOUD_EDITION); @@ -52,7 +64,7 @@ describe('Rancher Prices Utilities', () => { }); describe('getPlanPricing', () => { - it('should calculate EXPECTED_MONTHLY_PRICING correctly for OVHCLOUD_EDITION', () => { + it('should calculate pricing correctly for OVHCLOUD_EDITION', () => { const result = getPlanPricing( mockCatalog, RancherPlanCode.OVHCLOUD_EDITION, @@ -60,7 +72,7 @@ describe('Rancher Prices Utilities', () => { expect(result).toEqual({ name: RancherPlanName.OVHCLOUD_EDITION, hourlyPrice: 100, - monthlyPrice: EXPECTED_MONTHLY_PRICING, + monthlyPrice: 72000, }); }); diff --git a/packages/manager/apps/pci-rancher/src/utils/rancherPrices.ts b/packages/manager/apps/pci-rancher/src/utils/rancherPrices.ts index ee5ec878cca1..1fc00ef47318 100644 --- a/packages/manager/apps/pci-rancher/src/utils/rancherPrices.ts +++ b/packages/manager/apps/pci-rancher/src/utils/rancherPrices.ts @@ -1,4 +1,3 @@ -import { convertHourlyPriceToMonthly } from '@ovh-ux/manager-react-components'; import { TAddon, TCatalog } from '@ovh-ux/manager-pci-common'; import { RancherPlanCode, RancherPlanName } from '@/types/api.type'; @@ -8,6 +7,9 @@ export const findPlanByCode = (catalog: TCatalog, planCode: RancherPlanCode) => export const isConsumptionPlan = (plan: TAddon) => plan?.pricings?.[0]?.capacities.includes('consumption'); +export const calculateMonthlyPrice = (hourlyPrice: number) => + hourlyPrice * 720 || 0; + export const getRancherPlanName = (planCode: RancherPlanCode) => planCode.includes('ovhcloud') ? RancherPlanName.OVHCLOUD_EDITION @@ -20,7 +22,7 @@ export const getPlanPricing = ( const plan = findPlanByCode(catalog, planCode); const isConsumption = isConsumptionPlan(plan); const hourlyPrice = plan?.pricings?.[0]?.price || 0; - const monthlyPrice = convertHourlyPriceToMonthly(hourlyPrice); + const monthlyPrice = calculateMonthlyPrice(hourlyPrice); const name = getRancherPlanName(planCode); return isConsumption && hourlyPrice