mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-20 22:42:53 -05:00
Merged v5.22.5 into main
v5.22.5
This commit is contained in:
commit
c32a013087
4 changed files with 60 additions and 15 deletions
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "ghost-admin",
|
||||
"version": "5.22.4",
|
||||
"version": "5.22.5",
|
||||
"description": "Ember.js admin client for Ghost",
|
||||
"author": "Ghost Foundation",
|
||||
"homepage": "http://ghost.org",
|
||||
|
|
|
@ -46,14 +46,10 @@ class ProductsImporter extends BaseImporter {
|
|||
this.requiredExistingData.stripe_prices,
|
||||
{id: row.monthly_price_id}
|
||||
);
|
||||
if (!monthlyStripePrice) {
|
||||
invalidRows.push(row.id);
|
||||
return;
|
||||
}
|
||||
row.monthly_price = row.monthly_price || monthlyStripePrice.amount;
|
||||
row.currency = monthlyStripePrice.currency;
|
||||
row.monthly_price = row.monthly_price || monthlyStripePrice?.amount;
|
||||
row.currency = monthlyStripePrice?.currency;
|
||||
}
|
||||
if (!row.yearly_price) {
|
||||
if (!row.yearly_price || !row.currency) {
|
||||
const yearlyStripePrice = _.find(
|
||||
this.requiredFromFile.stripe_prices,
|
||||
{id: row.yearly_price_id}
|
||||
|
@ -61,11 +57,11 @@ class ProductsImporter extends BaseImporter {
|
|||
this.requiredExistingData.stripe_prices,
|
||||
{id: row.yearly_price_id}
|
||||
);
|
||||
if (!yearlyStripePrice) {
|
||||
invalidRows.push(row.id);
|
||||
return;
|
||||
}
|
||||
row.yearly_price = row.yearly_price || yearlyStripePrice.amount;
|
||||
row.yearly_price = row.yearly_price || yearlyStripePrice?.amount;
|
||||
row.currency = yearlyStripePrice?.currency;
|
||||
}
|
||||
if (!row.yearly_price || !row.currency || !row.monthly_price) {
|
||||
invalidRows.push(row.id);
|
||||
}
|
||||
});
|
||||
this.dataToImport = this.dataToImport.filter(item => !invalidRows.includes(item.id));
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "ghost",
|
||||
"version": "5.22.4",
|
||||
"version": "5.22.5",
|
||||
"description": "The professional publishing platform",
|
||||
"author": "Ghost Foundation",
|
||||
"homepage": "https://ghost.org",
|
||||
|
|
|
@ -15,6 +15,20 @@ const fakeProducts = [{
|
|||
updated_at: '2022-10-21T04:47:42.000Z',
|
||||
monthly_price_id: 'price_1',
|
||||
yearly_price_id: 'price_2'
|
||||
},{
|
||||
id: 'product_2',
|
||||
name: 'New One',
|
||||
slug: 'new-one',
|
||||
active: 1,
|
||||
welcome_page_url: null,
|
||||
visibility: 'public',
|
||||
trial_days: 0,
|
||||
description: null,
|
||||
type: 'paid',
|
||||
created_at: '2022-10-20T11:11:32.000Z',
|
||||
updated_at: '2022-10-21T04:47:42.000Z',
|
||||
monthly_price_id: 'invalid_price_1',
|
||||
yearly_price_id: 'invalid_price_2'
|
||||
}];
|
||||
|
||||
const fakePrices = [{
|
||||
|
@ -44,11 +58,39 @@ const fakePrices = [{
|
|||
description: null,
|
||||
created_at: '2022-10-27T02:51:28.000Z',
|
||||
updated_at: '2022-10-27T02:51:28.000Z'
|
||||
},
|
||||
{
|
||||
id: 'invalid_price_2',
|
||||
stripe_price_id: 'price_XXXXXXXXXXXXXXXXXXXXXXXX',
|
||||
stripe_product_id: 'prod_XXXXXXXXXXXXXX',
|
||||
active: 1,
|
||||
nickname: 'Yearly',
|
||||
currency: 'usd',
|
||||
amount: 0,
|
||||
type: 'recurring',
|
||||
interval: 'year',
|
||||
description: null,
|
||||
created_at: '2022-10-27T02:51:28.000Z',
|
||||
updated_at: '2022-10-27T02:51:28.000Z'
|
||||
},
|
||||
{
|
||||
id: 'invalid_price_2',
|
||||
stripe_price_id: 'price_XXXXXXXXXXXXXXXXXXXXXXXX',
|
||||
stripe_product_id: 'prod_XXXXXXXXXXXXXX',
|
||||
active: 1,
|
||||
nickname: 'Yearly',
|
||||
currency: 'usd',
|
||||
amount: 0,
|
||||
type: 'recurring',
|
||||
interval: 'year',
|
||||
description: null,
|
||||
created_at: '2022-10-27T02:51:28.000Z',
|
||||
updated_at: '2022-10-27T02:51:28.000Z'
|
||||
}];
|
||||
|
||||
describe('ProductsImporter', function () {
|
||||
describe('#beforeImport', function () {
|
||||
it('Removes the sender_email column', function () {
|
||||
it('Uses the stripe_prices to populate pricing data', function () {
|
||||
const importer = new ProductsImporter({products: fakeProducts, stripe_prices: fakePrices});
|
||||
|
||||
importer.beforeImport();
|
||||
|
@ -60,5 +102,12 @@ describe('ProductsImporter', function () {
|
|||
assert(product.monthly_price === 500);
|
||||
assert(product.yearly_price === 5000);
|
||||
});
|
||||
|
||||
it('Does not import products with invalid price data', function () {
|
||||
const importer = new ProductsImporter({products: fakeProducts, stripe_prices: fakePrices});
|
||||
|
||||
importer.beforeImport();
|
||||
assert(importer.dataToImport.length === 1);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Add table
Reference in a new issue