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

100% Statements 7/7
100% Branches 0/0
100% Functions 2/2
100% Lines 7/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 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 585x     5x         5x                 5x             5x                                       6x             3x            
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 { OciConfigurationItem } from '../../models/oci-configuration-item/oci-configuration-item.model';
import { OciOptions } from '../../models/oci-options/oci-options.model';
 
import { ociConfigurationActions, ociConfigurationApiActions } from './oci-configuration.actions';
 
export interface OciConfigurationState {
  configuration: OciConfigurationItem[];
  loading: boolean;
  error: HttpError;
  options: OciOptions;
}
 
const initialState: OciConfigurationState = {
  configuration: [],
  options: undefined,
  loading: false,
  error: undefined,
};
 
export const ociConfigurationReducer = createReducer(
  initialState,
  setLoadingOn(
    ociConfigurationActions.loadOCIConfiguration,
    ociConfigurationActions.loadOCIConfigurationOptions,
    ociConfigurationActions.updateOCIConfiguration
  ),
  unsetLoadingAndErrorOn(
    ociConfigurationApiActions.loadOCIConfigurationSuccess,
    ociConfigurationApiActions.loadOCIConfigurationOptionsSuccess,
    ociConfigurationApiActions.updateOCIConfigurationSuccess
  ),
  setErrorOn(
    ociConfigurationApiActions.loadOCIConfigurationFail,
    ociConfigurationApiActions.loadOCIConfigurationOptionsFail,
    ociConfigurationApiActions.updateOCIConfigurationFail
  ),
  on(
    ociConfigurationApiActions.loadOCIConfigurationSuccess,
    ociConfigurationApiActions.updateOCIConfigurationSuccess,
    (state, { payload: { configuration } }): OciConfigurationState => ({
      ...state,
      configuration,
    })
  ),
  on(
    ociConfigurationApiActions.loadOCIConfigurationOptionsSuccess,
    (state, { payload: { options } }): OciConfigurationState => ({
      ...state,
      options,
    })
  )
);