All files / src/app/core/models/payment payment.mapper.ts

75% Statements 3/4
81.81% Branches 9/11
100% Functions 1/1
75% Lines 3/4

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            36x           2x       2x                        
import { PaymentInstrument } from 'ish-core/models/payment-instrument/payment-instrument.model';
import { PaymentMethodBaseData } from 'ish-core/models/payment-method/payment-method.interface';
 
import { PaymentData } from './payment.interface';
import { Payment } from './payment.model';
 
export class PaymentMapper {
  static fromIncludeData(
    paymentData: PaymentData,
    paymentMethodData: PaymentMethodBaseData,
    paymentInstrument: PaymentInstrument
  ): Payment {
    Iif (!paymentData) {
      throw new Error(`'paymentData' is required`);
    }
 
    return {
      id: paymentData.id,
      capabilities: paymentMethodData ? paymentMethodData.capabilities : undefined,
      description: paymentMethodData ? paymentMethodData.description : undefined,
      displayName: paymentMethodData ? paymentMethodData.displayName : undefined,
      paymentInstrument: paymentInstrument ? paymentInstrument : { id: paymentData.paymentInstrument },
      redirectUrl: paymentData.redirect ? paymentData.redirect.redirectUrl : undefined,
      redirectRequired: paymentData.redirectRequired,
      status: paymentData.status,
    };
  }
}