Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "fix(pci.rancher): change method for pricing (#14008)" #14126

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
Loading