0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-02-10 23:36:14 -05:00

Fixed helper tests

no refs

- updated regex in get price id method to parse id
This commit is contained in:
Rishabh 2021-10-14 22:54:25 +05:30
parent 2076bb2af0
commit cd2e30a337
3 changed files with 12 additions and 18 deletions

View file

@ -6,7 +6,7 @@ export const sites = {
})
};
function getSiteData({
export function getSiteData({
products = getProductsData({numOfProducts: 3}),
portalProducts = products.map(p => p.id),
portalPlans: portal_plans = ['free', 'monthly', 'yearly']
@ -188,7 +188,7 @@ function getPriceData({
description = null,
currency = 'usd',
active = true,
id = `product_${uuidv4()}`
id = `price_${uuidv4()}`
}) {
return {
id: id,

View file

@ -68,15 +68,6 @@ export function isPaidMember({member = {}}) {
return (member && member.paid);
}
export function getUpgradePrices({site, member}) {
const activePrice = getMemberActivePrice({member});
if (activePrice) {
return getFilteredPrices({prices: this.prices, currency: activePrice.currency});
}
return getAvailablePrices({site});
}
export function getProductCurrency({product}) {
if (!product?.monthlyPrice) {
return null;
@ -494,9 +485,8 @@ export const createPopupNotification = ({type, status, autoHide, duration, close
};
export function getPriceIdFromPageQuery({site, pageQuery}) {
const productMonthlyPriceQueryRegex = /^(?:(\w+?))?\/monthly$/;
const productYearlyPriceQueryRegex = /^(?:(\w+?))?\/yearly$/;
const productMonthlyPriceQueryRegex = /^(?:(\S+?))?\/monthly$/;
const productYearlyPriceQueryRegex = /^(?:(\S+?))?\/yearly$/;
if (productMonthlyPriceQueryRegex.test(pageQuery || '')) {
const [, productId] = pageQuery.match(productMonthlyPriceQueryRegex);
const product = getProductFromId({site, productId});

View file

@ -1,10 +1,14 @@
import {getPriceIdFromPageQuery} from './helpers';
import {site} from './fixtures';
import * as Fixtures from './fixtures';
describe('Helpers - ', () => {
test('can correctly fetch price id from page query ', () => {
const mockPriceIdFn = jest.fn(getPriceIdFromPageQuery);
const value = mockPriceIdFn({site, pageQuery: 'product_1/yearly'});
expect(value).toBe('6086eff0823dd7345afc8083');
const mockPriceIdFn = getPriceIdFromPageQuery;
const siteData = Fixtures.getSiteData();
const testProduct = siteData.products?.[0];
const pageQuery = `${testProduct?.id}/yearly`;
const expectedPriceId = testProduct.yearlyPrice.id;
const value = mockPriceIdFn({site: siteData, pageQuery});
expect(value).toBe(expectedPriceId);
});
});