Skip to content

Commit

Permalink
fix: currency sent to api (#1827)
Browse files Browse the repository at this point in the history
* fix: currency sent to api

* fix: unit test

* fix: currency sent to api

* fix: unit test of currency shop
  • Loading branch information
ClaraLpresta authored Oct 4, 2024
1 parent b13412b commit 3b6e5cc
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
12 changes: 7 additions & 5 deletions _dev/apps/ui/src/providers/shipping-rate-provider.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,8 @@ describe('Product Feed / Step 2 Option 1 / Estimate Shipping', () => {
},
},
];
const transform = toApi(validCarrierFromView);
const currencyShop = 'EUR';
const transform = toApi(validCarrierFromView, currencyShop);

expect(transform).toEqual([
{
Expand All @@ -169,7 +170,7 @@ describe('Product Feed / Step 2 Option 1 / Estimate Shipping', () => {
minDeliveryTime: 5,
maxDeliveryTime: 7,
countries: [],
currency: '',
currency: 'EUR',
freeShippingOverAmount: {
shippingCost: 0,
orderPrice: 0,
Expand Down Expand Up @@ -199,7 +200,8 @@ describe('Product Feed / Step 2 Option 1 / Estimate Shipping', () => {
},
},
];
const transform = toApi(validCarrierFromView);
const currencyShop = 'EUR';
const transform = toApi(validCarrierFromView, currencyShop);

expect(transform).toEqual([
{
Expand All @@ -208,7 +210,7 @@ describe('Product Feed / Step 2 Option 1 / Estimate Shipping', () => {
minDeliveryTime: 5,
maxDeliveryTime: 7,
countries: [],
currency: '',
currency: 'EUR',
freeShippingOverAmount: {
shippingCost: 2.99,
orderPrice: 42.99,
Expand All @@ -221,7 +223,7 @@ describe('Product Feed / Step 2 Option 1 / Estimate Shipping', () => {
});

it('should return an empty array if estimateCarriers is empty', () => {
const transform = toApi([]);
const transform = toApi([], '');

expect(transform).toEqual([]);
});
Expand Down
6 changes: 5 additions & 1 deletion _dev/apps/ui/src/providers/shipping-rate-provider.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {OfferType} from '@/enums/product-feed/offer';
import {RateType} from '@/enums/product-feed/rate';
import store from '@/store';

export type freeShippingOverAmount = {
shippingCost: number|null;
Expand Down Expand Up @@ -134,7 +135,7 @@ export function generateEmptyCarrier(
};
}

export function toApi(customerCarrier: CustomCarrier[]): CustomCarrier[] {
export function toApi(customerCarrier: CustomCarrier[], currencyShop): CustomCarrier[] {
if (customerCarrier === null || customerCarrier.length === 0) {
return [];
}
Expand All @@ -150,6 +151,9 @@ export function toApi(customerCarrier: CustomCarrier[]): CustomCarrier[] {
if (carrier.freeShippingOverAmount.shippingCost === null) {
carrier.freeShippingOverAmount.shippingCost = 0;
}
if (carrier.currency !== currencyShop) {
carrier.currency = currencyShop;
}
});

return toApiFormat;
Expand Down
2 changes: 1 addition & 1 deletion _dev/apps/ui/src/store/modules/product-feed/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ export default {
// Delivery times & rates - Estimate method
const rate = getDataFromLocalStorage('productFeed-rateChosen') || productFeedSettings.rate || undefined;
const estimateCarriers = toApi(
getDataFromLocalStorage('productFeed-estimateCarriers') || productFeedSettings.estimateCarriers,
getDataFromLocalStorage('productFeed-estimateCarriers') || productFeedSettings.estimateCarriers, rootState.app.psxMktgWithGoogleShopCurrency.isoCode,
);
// Attributes mapping
const attributeMapping = (getDataFromLocalStorage('productFeed-attributeMapping')
Expand Down

0 comments on commit 3b6e5cc

Please sign in to comment.