import {ITreeNode} from "angular-tree-component/dist/defs/api";
export enum GeneralActions {
+ MERGE_OBJECT_BY_PATH = "MERGE_OBJECT_BY_PATH",
UPDATE_LCP_REGIONS_AND_TENANTS = "UPDATE_LCP_REGIONS_AND_TENANTS",
UPDATE_SUBSCRIBERS = "UPDATE_SUBSCRIBERS",
UPDATE_PRODUCT_FAMILIES = "UPDATE_PRODUCT_FAMILIES",
subscriberId: string;
}
+export interface MergeObjectByPathAction extends Action{
+ path: String[];
+ payload: object;
+}
+
export const updateLcpRegionsAndTenants: ActionCreator<UpdateLcpRegionsAndTenantsAction> = lcpRegionsAndTenants => ({
type: GeneralActions.UPDATE_LCP_REGIONS_AND_TENANTS,
lcpRegionsAndTenants: lcpRegionsAndTenants
subscriberId: subscriberId
});
+export const mergeObjectByPathAction : ActionCreator<MergeObjectByPathAction> = (path, payload) => ({
+ type: GeneralActions.MERGE_OBJECT_BY_PATH,
+ path,
+ payload
+});
+
import {LcpRegion} from "../../../models/lcpRegion";
import {Tenant} from "../../../models/tenant";
import {generalReducer} from "./general.reducers";
-import {
- ChangeInstanceCounterAction,
- RemoveInstanceAction,
- DuplicateBulkInstancesAction,
- GeneralActions,
- UpdateAicZonesAction,
- UpdateCategoryParametersAction,
- UpdateProductFamiliesAction,
- UpdateServiceTypesAction,
- UpdateSubscribersAction,
- UpdateUserIdAction, UpdateNetworkCollectionFunction,
-} from "./general.actions";
+import {ChangeInstanceCounterAction, DuplicateBulkInstancesAction, GeneralActions, MergeObjectByPathAction, RemoveInstanceAction, UpdateAicZonesAction, UpdateCategoryParametersAction, UpdateNetworkCollectionFunction, UpdateProductFamiliesAction, UpdateServiceTypesAction, UpdateSubscribersAction, UpdateUserIdAction,} from "./general.actions";
import {SelectOption} from "../../../models/selectOption";
import {ServiceType} from "../../../models/serviceType";
import {ITreeNode} from "angular-tree-component/dist/defs/api";
import {VnfInstance} from "../../../models/vnfInstance";
+import each from "jest-each";
describe('generalReducer', () => {
test('#UPDATE_LCP_REGIONS_AND_TENANTS : should update lcp region and tenants', () => {
expect(state).toBeDefined();
expect(state['networkFunctions']).toBeDefined();
});
+
+ const originalMockObject = {
+ remain: 'forever',
+ obsolete: 'toBeChange'
+ };
+
+ each([
+ [
+ ['serviceInstance', 'serviceModelId', 'vnfs'],
+ {
+ remain: 'forever',
+ obsolete: 'newValue',
+ newField: 'newValue2'
+ }
+ ],
+ [
+ ['serviceInstance', 'nowhere', 'somewhere'],
+ originalMockObject
+ ],
+ ]).
+ test('#MERGE_OBJECT_BY_PATH: should update some object by path %s', (path, expected) => {
+ let state = generalReducer(<any>{serviceInstance : {
+ 'serviceModelId' : {
+ vnfs : originalMockObject,
+ existingVNFCounterMap : {}
+ }
+ }},
+ <MergeObjectByPathAction>{
+ type: GeneralActions.MERGE_OBJECT_BY_PATH,
+ path,
+ payload: {
+ obsolete: 'newValue',
+ newField: 'newValue2'
+ }
+ });
+
+ expect(state).toBeDefined();
+ expect(state.serviceInstance['serviceModelId'].vnfs).toEqual(expected);
+ });
});
import {Action} from "redux";
-import {
- ChangeInstanceCounterAction, RemoveInstanceAction, DuplicateBulkInstancesAction,
- GeneralActions,
- UpdateAicZonesAction, UpdateCategoryParametersAction,
- UpdateLcpRegionsAndTenantsAction, UpdateNetworkCollectionFunction,
- UpdateProductFamiliesAction, UpdateServiceTypesAction,
- UpdateSubscribersAction, UpdateUserIdAction
-} from "./general.actions";
+import {ChangeInstanceCounterAction, DuplicateBulkInstancesAction, GeneralActions, MergeObjectByPathAction, RemoveInstanceAction, UpdateAicZonesAction, UpdateCategoryParametersAction, UpdateLcpRegionsAndTenantsAction, UpdateNetworkCollectionFunction, UpdateProductFamiliesAction, UpdateServiceTypesAction, UpdateSubscribersAction, UpdateUserIdAction} from "./general.actions";
import {TypeNodeInformation} from "../../../../drawingBoard/service-planning/typeNodeInformation.model";
import * as _ from "lodash";
import {ITreeNode} from "angular-tree-component/dist/defs/api";
return newState;
}
+ case GeneralActions.MERGE_OBJECT_BY_PATH : {
+ const mergeObjectByPathAction = <MergeObjectByPathAction>action;
+ let newState = _.cloneDeep(state);
+ let targetObject = _.get(newState, <any>mergeObjectByPathAction.path);
+ if (targetObject) {
+ targetObject = _.merge(targetObject, mergeObjectByPathAction.payload);
+ }
+ return newState;
+ }
+
}
}