All files / src/app/core/models/basket-info basket-info.mapper.ts

100% Statements 11/11
100% Branches 2/2
100% Functions 6/6
100% Lines 10/10

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 23 24 25    29x           11x 11x   11x 11x 2x 2x   11x 1x   1x          
import { BasketInfo } from './basket-info.model';
 
export class BasketInfoMapper {
  static fromInfo(payload: { infos: BasketInfo[]; itemId?: string }): BasketInfo[] {
    /**
     * Minor infos or causes, that should not be displayed at the moment.
     * Remove "basket.line_item.add_item_added_to_existing_line_item.info" from the causes array, to redirect the user to the cart after adding the same product to the cart.
     */
    const minorInfos = ['basket.line_item.deletion.info'];
    const minorCauses = ['basket.line_item.add_item_added_to_existing_line_item.info'];
 
    const { itemId } = payload;
    const infos = payload?.infos
      ?.filter(info => !minorInfos.includes(info.code))
      ?.filter(info => !info.causes?.find(cause => minorCauses.includes(cause.code)));
 
    return itemId
      ? infos?.map(info => ({
          ...info,
          causes: info?.causes?.map(cause => ({ ...cause, parameters: { ...cause.parameters, lineItemId: itemId } })),
        }))
      : infos;
  }
}