All files / src/app/extensions/punchout/store/punchout-functions punchout-functions.effects.ts

95% Statements 19/20
75% Branches 6/8
87.5% Functions 7/8
94.73% Lines 18/19

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 46 47 48 49 50 51 52 536x 6x 6x   6x 6x   6x   6x             6x 4x   4x 4x     3x 2x             4x   4x             4x 4x       1x              
import { Injectable } from '@angular/core';
import { Actions, createEffect, ofType } from '@ngrx/effects';
import { concatMap, map } from 'rxjs/operators';
 
import { displayErrorMessage } from 'ish-core/store/core/messages';
import { mapErrorToAction, mapToPayloadProperty } from 'ish-core/utils/operators';
 
import { PunchoutService } from '../../services/punchout/punchout.service';
 
import {
  transferPunchoutBasket,
  transferPunchoutBasketFail,
  transferPunchoutBasketSuccess,
} from './punchout-functions.actions';
 
@Injectable()
export class PunchoutFunctionsEffects {
  constructor(private punchoutService: PunchoutService, private actions$: Actions) {}
 
  transferPunchoutBasket$ = createEffect(() =>
    this.actions$.pipe(
      ofType(transferPunchoutBasket),
      concatMap(() =>
        this.punchoutService.transferPunchoutBasket().pipe(
          map(() => transferPunchoutBasketSuccess()),
          mapErrorToAction(transferPunchoutBasketFail)
        )
      )
    )
  );
 
  removeBasketFromSessionsStorageAfterSuccessfulTransfer$ = createEffect(
    () =>
      this.actions$.pipe(
        ofType(transferPunchoutBasketSuccess),
        map(() => window.sessionStorage.removeItem('basket-id'))
      ),
    { dispatch: false }
  );
 
  displayPunchoutErrorMessage$ = createEffect(() =>
    this.actions$.pipe(
      ofType(transferPunchoutBasketFail),
      mapToPayloadProperty('error'),
      map(error =>
        displayErrorMessage({
          message: error.message,
        })
      )
    )
  );
}