Skip to content

Commit

Permalink
Merge pull request #6723 from guardian/ahe/knip-ignore-in-file-produc…
Browse files Browse the repository at this point in the history
…tion-mode

Knip: remove exports used only in test files
  • Loading branch information
andrewHEguardian authored Jan 24, 2025
2 parents f0e5e1e + 037103c commit 8f68545
Show file tree
Hide file tree
Showing 13 changed files with 14 additions and 377 deletions.
79 changes: 0 additions & 79 deletions support-frontend/assets/helpers/__tests__/contributionsTests.ts

This file was deleted.

52 changes: 0 additions & 52 deletions support-frontend/assets/helpers/contributions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,19 +82,6 @@ export type ContributionTypes = Record<
ContributionTypeSetting[]
>;

type ParseError = 'ParseError';

type ValidationError = 'TooMuch' | 'TooLittle';

type ParsedContribution =
| {
valid: true;
amount: number;
}
| {
error: ParseError;
};

type Config = Record<
ContributionType,
{
Expand Down Expand Up @@ -306,42 +293,6 @@ function getConfigMinAmount(
return config[countryGroupId][contribType].min;
}

function validateContribution(
input: number,
contributionType: ContributionType,
countryGroupId: CountryGroupId,
): ValidationError | null | undefined {
if (input < config[countryGroupId][contributionType].min) {
return 'TooLittle';
} else if (input > config[countryGroupId][contributionType].max) {
return 'TooMuch';
}

return null;
}

function parseContribution(input: string): ParsedContribution {
const amount = Number(input);

if (input === '' || Number.isNaN(amount)) {
return {
error: 'ParseError',
};
}

return {
valid: true,
amount: roundToDecimalPlaces(amount),
};
}

function getMinContribution(
contributionType: ContributionType,
countryGroupId: CountryGroupId,
): number {
return config[countryGroupId][contributionType].min;
}

function toContributionType(
s: string | null | undefined,
): ContributionType | null | undefined {
Expand Down Expand Up @@ -408,9 +359,6 @@ export {
getConfigMinAmount,
toContributionType,
generateContributionTypes,
validateContribution,
parseContribution,
getMinContribution,
billingPeriodFromContrib,
getAmount,
contributionsOnlyAmountsTestName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import {
} from 'helpers/productPrice/billingPeriods';
import type { BillingPeriod } from 'helpers/productPrice/billingPeriods';
import {
getAdverbialSubscriptionDescription,
getAppliedPromoDescription,
getPriceDescription,
getSimplifiedPriceDescription,
} from 'helpers/productPrice/priceDescriptions';
Expand Down Expand Up @@ -95,38 +93,6 @@ describe('getPriceDescription', () => {
});
});

describe('getAppliedPromoDescription', () => {
const productPriceWithLandingPageDiscount: ProductPrice = {
price: 11.99,
currency: 'GBP',
fixedTerm: false,
promotions: [
{
name: 'Sept 2021 Discount',
description: '50% off for 3 months',
promoCode: 'DK0NT24WG',
discountedPrice: 5.99,
numberOfDiscountedPeriods: 3,
discount: {
amount: 50,
durationMonths: 3,
},
landingPage: {
title: 'Sept 2021 Discount',
description: '50% off for 3 months',
roundel: 'Save 50% for 3 months!',
},
},
],
};

it('should return a landing page promotion roundel description', () => {
expect(
getAppliedPromoDescription(productPriceWithLandingPageDiscount),
).toBe('Save 50% for 3 months!');
});
});

describe('getSimplifiedPriceDescription', () => {
it('should return a price description', () => {
expect(
Expand Down Expand Up @@ -162,11 +128,3 @@ describe('getSimplifiedPriceDescription', () => {
).toEqual('per month, then £11.99 per month');
});
});

describe('getAdverbialSubscriptionDescription', () => {
it('should return an adverbial subscription description', () => {
expect(
getAdverbialSubscriptionDescription(productPrice, monthlyBillingPeriod),
).toEqual('Subscribe monthly for £11.99');
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import type {
ProductPrices,
} from 'helpers/productPrice/productPrices';
import {
displayPrice,
getCountryGroup,
getCurrency,
getFirstValidPrice,
Expand Down Expand Up @@ -223,29 +222,3 @@ describe('showPrice', () => {
expect(showPrice(productPrice, false)).toEqual('$6.99');
});
});

describe('displayPrice', () => {
const productPrices = {
'United Kingdom': {
Collection: {
Weekend: {
Monthly: {
GBP: {
price: 20.76,
savingVsRetail: 20,
currency: 'GBP',
fixedTerm: false,
promotions: [],
},
},
},
},
},
} as unknown as ProductPrices;

it('should return the price prepended with a glyph', () => {
expect(
displayPrice(productPrices, 'GB', 'Monthly', 'Collection', 'Weekend'),
).toEqual('£20.76');
});
});
14 changes: 0 additions & 14 deletions support-frontend/assets/helpers/productPrice/billingPeriods.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,6 @@ function billingPeriodNoun(
}
}

function billingPeriodAdverb(billingPeriod: BillingPeriod): string {
switch (billingPeriod) {
case Annual:
return 'Annually';

case Quarterly:
return 'Quarterly';

default:
return 'Monthly';
}
}

function billingPeriodTitle(
billingPeriod: BillingPeriod,
fixedTerm = false,
Expand All @@ -65,7 +52,6 @@ export {
Monthly,
Quarterly,
billingPeriodNoun,
billingPeriodAdverb,
billingPeriodTitle,
weeklyBillingPeriods,
weeklyGiftBillingPeriods,
Expand Down
41 changes: 2 additions & 39 deletions support-frontend/assets/helpers/productPrice/priceDescriptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,8 @@ import {
glyph as shortGlyph,
} from 'helpers/internationalisation/currency';
import type { BillingPeriod } from 'helpers/productPrice/billingPeriods';
import {
billingPeriodAdverb,
billingPeriodNoun as upperCaseNoun,
} from 'helpers/productPrice/billingPeriods';
import { billingPeriodNoun as upperCaseNoun } from 'helpers/productPrice/billingPeriods';
import type { ProductPrice } from 'helpers/productPrice/productPrices';
import type { Promotion } from 'helpers/productPrice/promotions';
import { getAppliedPromo, hasDiscount } from 'helpers/productPrice/promotions';
import { fixDecimals } from 'helpers/productPrice/subscriptions';

Expand Down Expand Up @@ -123,10 +119,6 @@ function getPriceDescription(
);
}

function getAppliedPromoDescription(productPrice: ProductPrice): string {
return getAppliedPromo(productPrice.promotions)?.landingPage?.roundel ?? '';
}

function getSimplifiedPriceDescription(
productPrice: ProductPrice,
billingPeriod: BillingPeriod,
Expand Down Expand Up @@ -154,33 +146,4 @@ function getSimplifiedPriceDescription(
)}`;
}

function getPriceForDescription(
productPrice: ProductPrice,
promotion: Promotion | undefined,
) {
if (hasDiscount(promotion)) {
return promotion.discountedPrice;
}

return productPrice.price;
}

function getAdverbialSubscriptionDescription(
productPrice: ProductPrice,
billingPeriod: BillingPeriod,
): string {
const glyph = shortGlyph(productPrice.currency);
const promotion = getAppliedPromo(productPrice.promotions);
const price = getPriceForDescription(productPrice, promotion);
return `Subscribe ${billingPeriodAdverb(
billingPeriod,
).toLowerCase()} for ${displayPrice(glyph, price)}`;
}

export {
displayPrice,
getPriceDescription,
getAppliedPromoDescription,
getSimplifiedPriceDescription,
getAdverbialSubscriptionDescription,
};
export { displayPrice, getPriceDescription, getSimplifiedPriceDescription };
18 changes: 0 additions & 18 deletions support-frontend/assets/helpers/productPrice/productPrices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,23 +78,6 @@ const showPrice = (p: ProductPrice, isExtended = true): string => {
return `${showGlyph(p.currency)}${fixDecimals(p.price)}`;
};

const displayPrice = (
productPrices: ProductPrices,
country: IsoCountry,
billingPeriod: BillingPeriod,
fulfilmentOption: FulfilmentOptions = NoFulfilmentOptions,
productOption: ProductOptions = NoProductOptions,
): string =>
showPrice(
getProductPrice(
productPrices,
country,
billingPeriod,
fulfilmentOption,
productOption,
),
);

function getCurrency(country: IsoCountry): IsoCurrency {
const { currency } = getCountryGroup(country);
return currency;
Expand Down Expand Up @@ -122,7 +105,6 @@ export {
getCurrency,
getCountryGroup,
showPrice,
displayPrice,
isNumeric,
getDiscountVsRetail,
};
Original file line number Diff line number Diff line change
@@ -1,13 +1,4 @@
export type Day = 0 | 1 | 2 | 3 | 4 | 5 | 6;
const DeliveryDays = {
Sunday: 0,
Monday: 1,
Tuesday: 2,
Wednesday: 3,
Thursday: 4,
Friday: 5,
Saturday: 6,
};
const milsInADay = 1000 * 60 * 60 * 24;
export const numberOfWeeksWeDeliverTo = 4;

Expand Down Expand Up @@ -43,9 +34,4 @@ const getDeliveryDays = (
return deliveryDays;
};

export {
jsDayToFulfilmentDay,
getDeliveryDays,
getNextDeliveryDay,
DeliveryDays,
};
export { jsDayToFulfilmentDay, getDeliveryDays, getNextDeliveryDay };
Loading

0 comments on commit 8f68545

Please sign in to comment.