From 36803a429051e117f05236c33dcd9b392143260c Mon Sep 17 00:00:00 2001 From: Rishabh Garg Date: Thu, 27 May 2021 10:49:35 +0530 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20=20Fixed=20incorrect=20`@price.c?= =?UTF-8?q?urrency`=20value=20in=20themes=20(#12987)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit closes https://github.com/TryGhost/Ghost/issues/12986 refs https://github.com/TryGhost/Ghost/commit/1345268089f5ca275e8592953be429f02f1d3b19 As part of changes in 4.6, the default price ids for monthly/yearly prices are stored in new settings - `members_monthly_price_id`, `members_yearly_price_id` - which are used to determine current active prices for the site from list of all existing prices. While the last commit updated the prices to use the settings, the data for currency was still used from non-zero prices instead of the new settings value. - Updated tests to check price currency --- core/frontend/services/theme-engine/middleware.js | 2 +- test/frontend-acceptance/members_spec.js | 4 ++-- test/utils/fixtures/data-generator.js | 6 +++--- test/utils/fixtures/themes/price-data-test-theme/index.hbs | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/core/frontend/services/theme-engine/middleware.js b/core/frontend/services/theme-engine/middleware.js index 6d44694f16..c76a59dbcf 100644 --- a/core/frontend/services/theme-engine/middleware.js +++ b/core/frontend/services/theme-engine/middleware.js @@ -98,7 +98,7 @@ async function haxGetMembersPriceData() { const priceData = { monthly: makePriceObject(monthlyPrice || defaultPrice), yearly: makePriceObject(yearlyPrice || defaultPrice), - currency: nonZeroPrices[0].currency + currency: monthlyPrice ? monthlyPrice.currency : defaultPrice.currency }; return priceData; diff --git a/test/frontend-acceptance/members_spec.js b/test/frontend-acceptance/members_spec.js index 54475c46ce..1a72635d6b 100644 --- a/test/frontend-acceptance/members_spec.js +++ b/test/frontend-acceptance/members_spec.js @@ -130,8 +130,8 @@ describe('Front-end members behaviour', function () { // Check out test/utils/fixtures/themes/price-data-test-theme/index.hbs // To see where this is coming from. // - const legacyUse = /You can use the price data as a number: 12/; - const withPriceHelper = /You can pass price data to the price helper: \$12/; + const legacyUse = /You can use the price data as a number and currency: £12/; + const withPriceHelper = /You can pass price data to the price helper: £12/; should.exist(res.text.match(legacyUse)); should.exist(res.text.match(withPriceHelper)); diff --git a/test/utils/fixtures/data-generator.js b/test/utils/fixtures/data-generator.js index 1dc168ce78..9f88ebb890 100644 --- a/test/utils/fixtures/data-generator.js +++ b/test/utils/fixtures/data-generator.js @@ -497,7 +497,7 @@ DataGenerator.Content = { stripe_product_id: '109c85c734fb9992e7bc30a26af66c22f5c94d8dc62e0a33cb797be902c06b2d', active: true, nickname: 'Monthly', - currency: 'USD', + currency: 'GBP', amount: 1200, type: 'recurring', interval: 'month' @@ -508,7 +508,7 @@ DataGenerator.Content = { stripe_product_id: '109c85c734fb9992e7bc30a26af66c22f5c94d8dc62e0a33cb797be902c06b2d', active: true, nickname: 'Yearly', - currency: 'USD', + currency: 'GBP', amount: 12000, type: 'recurring', interval: 'year' @@ -519,7 +519,7 @@ DataGenerator.Content = { stripe_product_id: '109c85c734fb9992e7bc30a26af66c22f5c94d8dc62e0a33cb797be902c06b2d', active: true, nickname: 'Yearly', - currency: 'USD', + currency: 'GBP', amount: 15000, type: 'recurring', interval: 'year' diff --git a/test/utils/fixtures/themes/price-data-test-theme/index.hbs b/test/utils/fixtures/themes/price-data-test-theme/index.hbs index 55afd904d3..ff13e30b05 100644 --- a/test/utils/fixtures/themes/price-data-test-theme/index.hbs +++ b/test/utils/fixtures/themes/price-data-test-theme/index.hbs @@ -1,5 +1,5 @@

- You can use the price data as a number: {{@price.monthly}} + You can use the price data as a number and currency: {{price currency=@price.currency}}{{@price.monthly}}

You can pass price data to the price helper: {{price @price.monthly}}