All files / src/contexts/cartContext helpers.tsx

11.76% Statements 2/17
0% Branches 0/4
0% Functions 0/6
16.67% Lines 2/12

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22    5x                     5x                
import { CartItem } from './types';
 
export const equalsIgnoreOrder = (a: string[], b: string[]) => {
  if (a.length !== b.length) return false;
  const uniqueValues = new Set([...a, ...b]);
  for (const v of uniqueValues) {
    const aCount = a.filter(e => e === v).length;
    const bCount = b.filter(e => e === v).length;
    if (aCount !== bCount) return false;
  }
  return true;
}
 
export const mergeArraysBySku = (magentoProducts: CartItem[], strapiProducts: any[]) => {
  return magentoProducts.map(magentoProduct => {
    const index = strapiProducts.findIndex(strapiProduct => strapiProduct.sku === magentoProduct.product.sku);
    return {
      ...magentoProduct,
      strapiProduct: strapiProducts[index]
    }
  })
}