Skip to content

Commit

Permalink
revert: "fix(pci.rancher): change method for pricing (#14008)" (#14126)
Browse files Browse the repository at this point in the history
This reverts commit 830fd40.

Co-authored-by: Eric Ciccotti <[email protected]>
  • Loading branch information
Eric-ciccotti and Eric Ciccotti authored Nov 15, 2024
1 parent a3722e6 commit 3e3a076
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
18 changes: 15 additions & 3 deletions packages/manager/apps/pci-rancher/src/utils/rancherPrices.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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);
Expand All @@ -52,15 +64,15 @@ 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,
);
expect(result).toEqual({
name: RancherPlanName.OVHCLOUD_EDITION,
hourlyPrice: 100,
monthlyPrice: EXPECTED_MONTHLY_PRICING,
monthlyPrice: 72000,
});
});

Expand Down
6 changes: 4 additions & 2 deletions packages/manager/apps/pci-rancher/src/utils/rancherPrices.ts
Original file line number Diff line number Diff line change
@@ -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';

Expand All @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 3e3a076

Please sign in to comment.