зеркало из https://github.com/mozilla/fxa.git
fix(payments-legacy): support cms localization
Because: - Legacy mapper was not using localization data from the CMS This commit: - Updated legacy mapper to utilize localization data. Closes #FXA-10436
This commit is contained in:
Родитель
811374e473
Коммит
b5a67cef1d
|
@ -147,8 +147,9 @@ describe('StripeMapperService', () => {
|
||||||
expect(nonMatchingPlans[0].split(' - ')[1]).toBe('webIconURL');
|
expect(nonMatchingPlans[0].split(' - ')[1]).toBe('webIconURL');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return data from cms', async () => {
|
it('should return data from cms default locale if no localization data is available', async () => {
|
||||||
const expected = PurchaseWithDetailsOfferingContentTransformedFactory();
|
const expected = PurchaseWithDetailsOfferingContentTransformedFactory();
|
||||||
|
expected.purchaseDetails.data.attributes.localizations.data = [];
|
||||||
mockCMSConfigUtil.transformedPurchaseWithCommonContentForPlanId.mockReturnValueOnce(
|
mockCMSConfigUtil.transformedPurchaseWithCommonContentForPlanId.mockReturnValueOnce(
|
||||||
expected
|
expected
|
||||||
);
|
);
|
||||||
|
@ -178,6 +179,39 @@ describe('StripeMapperService', () => {
|
||||||
expect(nonMatchingPlans).toHaveLength(0);
|
expect(nonMatchingPlans).toHaveLength(0);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should return data from cms for locale when available', async () => {
|
||||||
|
const expected = PurchaseWithDetailsOfferingContentTransformedFactory();
|
||||||
|
mockCMSConfigUtil.transformedPurchaseWithCommonContentForPlanId.mockReturnValueOnce(
|
||||||
|
expected
|
||||||
|
);
|
||||||
|
const productMetadata = {
|
||||||
|
productSet: 'set',
|
||||||
|
productOrder: 'order',
|
||||||
|
};
|
||||||
|
const stripePlan = StripePlanFactory() as Stripe.Plan;
|
||||||
|
stripePlan.product = StripeProductFactory({
|
||||||
|
metadata: productMetadata,
|
||||||
|
});
|
||||||
|
const { mappedPlans, nonMatchingPlans } =
|
||||||
|
await stripeMapper.mapCMSToStripePlans([stripePlan], 'en', false);
|
||||||
|
const actualProduct = mappedPlans[0].product as Stripe.Product;
|
||||||
|
expect(mappedPlans[0].metadata?.['webIconURL']).toBe(
|
||||||
|
expected.purchaseDetails.data.attributes.localizations.data[0]
|
||||||
|
.attributes.webIcon
|
||||||
|
);
|
||||||
|
expect(actualProduct.metadata?.['webIconURL']).toBe(
|
||||||
|
expected.purchaseDetails.data.attributes.localizations.data[0]
|
||||||
|
.attributes.webIcon
|
||||||
|
);
|
||||||
|
expect(actualProduct.metadata?.['productSet']).toBe(
|
||||||
|
productMetadata.productSet
|
||||||
|
);
|
||||||
|
expect(actualProduct.metadata?.['productOrder']).toBe(
|
||||||
|
productMetadata.productOrder
|
||||||
|
);
|
||||||
|
expect(nonMatchingPlans).toHaveLength(0);
|
||||||
|
});
|
||||||
|
|
||||||
it('should return data from CMS and not error on locale plan', async () => {
|
it('should return data from CMS and not error on locale plan', async () => {
|
||||||
const expected = PurchaseWithDetailsOfferingContentTransformedFactory({
|
const expected = PurchaseWithDetailsOfferingContentTransformedFactory({
|
||||||
purchaseDetails: {
|
purchaseDetails: {
|
||||||
|
|
|
@ -95,13 +95,23 @@ export class StripeMapperService {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
const commonContent =
|
const commonContentAttributes =
|
||||||
cmsConfigData.offering.data.attributes.commonContent;
|
cmsConfigData.offering.data.attributes.commonContent.data.attributes;
|
||||||
const purchaseDetails = cmsConfigData.purchaseDetails;
|
const commonContentAttributesLocalized = commonContentAttributes
|
||||||
|
.localizations.data.length
|
||||||
|
? commonContentAttributes.localizations.data[0].attributes
|
||||||
|
: commonContentAttributes;
|
||||||
|
|
||||||
|
const purchaseDetailsAttributes =
|
||||||
|
cmsConfigData.purchaseDetails.data.attributes;
|
||||||
|
const purchaseDetailsLocalizedAttributes = purchaseDetailsAttributes
|
||||||
|
.localizations.data.length
|
||||||
|
? purchaseDetailsAttributes.localizations.data[0].attributes
|
||||||
|
: purchaseDetailsAttributes;
|
||||||
|
|
||||||
const planMapper = new PlanMapperUtil(
|
const planMapper = new PlanMapperUtil(
|
||||||
commonContent.data.attributes,
|
commonContentAttributesLocalized,
|
||||||
purchaseDetails.data.attributes,
|
purchaseDetailsLocalizedAttributes,
|
||||||
mergedStripeMetadata,
|
mergedStripeMetadata,
|
||||||
cmsEnabled
|
cmsEnabled
|
||||||
);
|
);
|
||||||
|
|
|
@ -148,6 +148,7 @@ async function run(config) {
|
||||||
const strapiClient = new StrapiClient(strapiClientConfig, firestore);
|
const strapiClient = new StrapiClient(strapiClientConfig, firestore);
|
||||||
const productConfigurationManager = new ProductConfigurationManager(
|
const productConfigurationManager = new ProductConfigurationManager(
|
||||||
strapiClient,
|
strapiClient,
|
||||||
|
priceManager,
|
||||||
statsd
|
statsd
|
||||||
);
|
);
|
||||||
Container.set(ProductConfigurationManager, productConfigurationManager);
|
Container.set(ProductConfigurationManager, productConfigurationManager);
|
||||||
|
|
|
@ -50,7 +50,6 @@ const {
|
||||||
const {
|
const {
|
||||||
ProductConfigurationManager,
|
ProductConfigurationManager,
|
||||||
PurchaseWithDetailsOfferingContentTransformedFactory,
|
PurchaseWithDetailsOfferingContentTransformedFactory,
|
||||||
PurchaseDetailsTransformedFactory,
|
|
||||||
} = require('@fxa/shared/cms');
|
} = require('@fxa/shared/cms');
|
||||||
|
|
||||||
const customer1 = require('./fixtures/stripe/customer1.json');
|
const customer1 = require('./fixtures/stripe/customer1.json');
|
||||||
|
@ -3426,15 +3425,11 @@ describe('#integration - StripeHelper', () => {
|
||||||
const newWebIconURL = 'http://strapi.example/webicon';
|
const newWebIconURL = 'http://strapi.example/webicon';
|
||||||
const mockCMSConfigUtil = {
|
const mockCMSConfigUtil = {
|
||||||
transformedPurchaseWithCommonContentForPlanId: (planId) => {
|
transformedPurchaseWithCommonContentForPlanId: (planId) => {
|
||||||
return PurchaseWithDetailsOfferingContentTransformedFactory({
|
const mockValue =
|
||||||
purchaseDetails: {
|
PurchaseWithDetailsOfferingContentTransformedFactory();
|
||||||
data: {
|
mockValue.purchaseDetails.data.attributes.webIcon = newWebIconURL;
|
||||||
attributes: PurchaseDetailsTransformedFactory({
|
mockValue.purchaseDetails.data.attributes.localizations.data = [];
|
||||||
webIcon: newWebIconURL,
|
return mockValue;
|
||||||
}),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
});
|
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
const mockProductConfigurationManager = {
|
const mockProductConfigurationManager = {
|
||||||
|
|
Загрузка…
Ссылка в новой задаче