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

100% Statements 5/5
68% Branches 17/25
100% Functions 2/2
100% Lines 5/5

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 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45  28x         28x   3x 2x                             2x                                        
import { BasketData } from 'ish-core/models/basket/basket.interface';
import { BasketMapper } from 'ish-core/models/basket/basket.mapper';
 
import { BasketValidationData } from './basket-validation.interface';
import { BasketValidation } from './basket-validation.model';
 
export class BasketValidationMapper {
  static fromData(data: BasketValidationData): BasketValidation {
    if (data) {
      return {
        basket: BasketMapper.fromData(BasketValidationMapper.transform(data)),
        results: {
          valid: data.data.results?.valid,
          adjusted: data.data.results?.adjusted,
          errors: data.data.results?.errors,
          infos: data.data.results?.infos,
        },
        scopes: data.data.scopes,
      };
    }
  }
 
  // eslint-disable-next-line complexity
  private static transform(basketValidationData: BasketValidationData): BasketData {
    return {
      data: basketValidationData.included
        ? basketValidationData.included.basket[basketValidationData.data.basket] || undefined
        : undefined,
      included: basketValidationData.included
        ? {
            invoiceToAddress: basketValidationData.included.basket_invoiceToAddress || undefined,
            lineItems: basketValidationData.included.basket_lineItems || undefined,
            discounts: basketValidationData.included.basket_discounts || undefined,
            lineItems_discounts: basketValidationData.included.basket_lineItems_discounts || undefined,
            commonShipToAddress: basketValidationData.included.basket_commonShipToAddress || undefined,
            commonShippingMethod: basketValidationData.included.basket_commonShippingMethod || undefined,
            payments: basketValidationData.included.basket_payments || undefined,
            payments_paymentMethod: basketValidationData.included.basket_payments_paymentMethod || undefined,
            payments_paymentInstrument: basketValidationData.included.basket_payments_paymentInstrument || undefined,
          }
        : undefined,
    };
  }
}