All files / src/app/extensions/punchout/store/cxml-configuration cxml-configuration.reducer.ts

85.71% Statements 6/7
100% Branches 0/0
50% Functions 1/2
85.71% Lines 6/7

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 435x     5x       5x               5x           5x                           1x              
import { createReducer, on } from '@ngrx/store';
 
import { HttpError } from 'ish-core/models/http-error/http-error.model';
import { setErrorOn, setLoadingOn, unsetLoadingAndErrorOn } from 'ish-core/utils/ngrx-creators';
 
import { CxmlConfiguration } from '../../models/cxml-configuration/cxml-configuration.model';
 
import { cxmlConfigurationActions, cxmlConfigurationApiActions } from './cxml-configuration.actions';
 
export interface CxmlConfigurationState {
  configuration: CxmlConfiguration[];
  loading: boolean;
  error: HttpError;
}
 
const initialState: CxmlConfigurationState = {
  configuration: [],
  loading: false,
  error: undefined,
};
 
export const cxmlConfigurationReducer = createReducer(
  initialState,
  setLoadingOn(cxmlConfigurationActions.loadCXMLConfiguration, cxmlConfigurationActions.updateCXMLConfiguration),
  unsetLoadingAndErrorOn(
    cxmlConfigurationApiActions.loadCXMLConfigurationSuccess,
    cxmlConfigurationApiActions.updateCXMLConfigurationSuccess
  ),
  setErrorOn(
    cxmlConfigurationApiActions.loadCXMLConfigurationFail,
    cxmlConfigurationApiActions.updateCXMLConfigurationFail
  ),
  on(
    cxmlConfigurationApiActions.loadCXMLConfigurationSuccess,
    cxmlConfigurationApiActions.updateCXMLConfigurationSuccess,
    (state, { payload: { configuration } }): CxmlConfigurationState => ({
      ...state,
      configuration,
    })
  ),
  on(cxmlConfigurationActions.resetCXMLConfiguration, (): CxmlConfigurationState => initialState)
);