mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-17 23:44:39 -05:00
Fixed helper tests
no refs - updated regex in get price id method to parse id
This commit is contained in:
parent
2076bb2af0
commit
cd2e30a337
3 changed files with 12 additions and 18 deletions
|
@ -6,7 +6,7 @@ export const sites = {
|
||||||
})
|
})
|
||||||
};
|
};
|
||||||
|
|
||||||
function getSiteData({
|
export function getSiteData({
|
||||||
products = getProductsData({numOfProducts: 3}),
|
products = getProductsData({numOfProducts: 3}),
|
||||||
portalProducts = products.map(p => p.id),
|
portalProducts = products.map(p => p.id),
|
||||||
portalPlans: portal_plans = ['free', 'monthly', 'yearly']
|
portalPlans: portal_plans = ['free', 'monthly', 'yearly']
|
||||||
|
@ -188,7 +188,7 @@ function getPriceData({
|
||||||
description = null,
|
description = null,
|
||||||
currency = 'usd',
|
currency = 'usd',
|
||||||
active = true,
|
active = true,
|
||||||
id = `product_${uuidv4()}`
|
id = `price_${uuidv4()}`
|
||||||
}) {
|
}) {
|
||||||
return {
|
return {
|
||||||
id: id,
|
id: id,
|
||||||
|
|
|
@ -68,15 +68,6 @@ export function isPaidMember({member = {}}) {
|
||||||
return (member && member.paid);
|
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}) {
|
export function getProductCurrency({product}) {
|
||||||
if (!product?.monthlyPrice) {
|
if (!product?.monthlyPrice) {
|
||||||
return null;
|
return null;
|
||||||
|
@ -494,9 +485,8 @@ export const createPopupNotification = ({type, status, autoHide, duration, close
|
||||||
};
|
};
|
||||||
|
|
||||||
export function getPriceIdFromPageQuery({site, pageQuery}) {
|
export function getPriceIdFromPageQuery({site, pageQuery}) {
|
||||||
const productMonthlyPriceQueryRegex = /^(?:(\w+?))?\/monthly$/;
|
const productMonthlyPriceQueryRegex = /^(?:(\S+?))?\/monthly$/;
|
||||||
const productYearlyPriceQueryRegex = /^(?:(\w+?))?\/yearly$/;
|
const productYearlyPriceQueryRegex = /^(?:(\S+?))?\/yearly$/;
|
||||||
|
|
||||||
if (productMonthlyPriceQueryRegex.test(pageQuery || '')) {
|
if (productMonthlyPriceQueryRegex.test(pageQuery || '')) {
|
||||||
const [, productId] = pageQuery.match(productMonthlyPriceQueryRegex);
|
const [, productId] = pageQuery.match(productMonthlyPriceQueryRegex);
|
||||||
const product = getProductFromId({site, productId});
|
const product = getProductFromId({site, productId});
|
||||||
|
|
|
@ -1,10 +1,14 @@
|
||||||
import {getPriceIdFromPageQuery} from './helpers';
|
import {getPriceIdFromPageQuery} from './helpers';
|
||||||
import {site} from './fixtures';
|
import * as Fixtures from './fixtures';
|
||||||
|
|
||||||
describe('Helpers - ', () => {
|
describe('Helpers - ', () => {
|
||||||
test('can correctly fetch price id from page query ', () => {
|
test('can correctly fetch price id from page query ', () => {
|
||||||
const mockPriceIdFn = jest.fn(getPriceIdFromPageQuery);
|
const mockPriceIdFn = getPriceIdFromPageQuery;
|
||||||
const value = mockPriceIdFn({site, pageQuery: 'product_1/yearly'});
|
const siteData = Fixtures.getSiteData();
|
||||||
expect(value).toBe('6086eff0823dd7345afc8083');
|
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);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Reference in a new issue