add common method for getting max allowed instances of vfModule + UT 59/99459/1
authorEylon Malin <eylon.malin@intl.att.com>
Wed, 11 Dec 2019 06:11:02 +0000 (08:11 +0200)
committerEylon Malin <eylon.malin@intl.att.com>
Wed, 11 Dec 2019 06:11:02 +0000 (08:11 +0200)
Issue-ID: VID-726
Signed-off-by: Eylon Malin <eylon.malin@intl.att.com>
Change-Id: Ib4597a027a6ac519ca2290d41b0f3208d47cc5b3

vid-webpack-master/src/app/shared/utils/util.spec.ts
vid-webpack-master/src/app/shared/utils/utils.ts

index 4b39764..ae39238 100644 (file)
@@ -1,24 +1,8 @@
 import {Utils} from "./utils";
 import {Utils} from "./utils";
-import {TestBed} from "@angular/core/testing";
 import each from "jest-each";
 
 
 describe('Util', () => {
 import each from "jest-each";
 
 
 describe('Util', () => {
-  let util: Utils;
-
-  beforeAll(done => (async () => {
-    TestBed.configureTestingModule({
-
-    });
-    await TestBed.compileComponents();
-
-    util = new Utils();
-
-  })().then(done).catch(done.fail));
-
-  test('should be defined', () => {
-    expect(util).toBeDefined();
-  });
 
   test('hasContents should return false if object is undefined or null or empty', () => {
     expect(Utils.hasContents(undefined)).toBeFalsy();
 
   test('hasContents should return false if object is undefined or null or empty', () => {
     expect(Utils.hasContents(undefined)).toBeFalsy();
@@ -40,4 +24,28 @@ describe('Util', () => {
     expect(Utils.isALaCarte(instantiationType)).toEqual(expected);
   });
 
     expect(Utils.isALaCarte(instantiationType)).toEqual(expected);
   });
 
+  each([
+    ["empty properties, empty flags",{}, {}, 1],
+    ["null properties, undefined flags",null, undefined, 1],
+    ["max_instances 3, flag is on", {max_instances:3}, {FLAG_2002_UNLIMITED_MAX: true}, 3],
+    ["max_instances 3, flag is off", {max_instances:3}, {FLAG_2002_UNLIMITED_MAX: false}, 3],
+    ["null properties, flag is on", null, {FLAG_2002_UNLIMITED_MAX: true}, null],
+    ["null properties, flag is off", null, {FLAG_2002_UNLIMITED_MAX: false}, 1],
+    ["undefined properties, flag is off", undefined, {FLAG_2002_UNLIMITED_MAX: false}, 1],
+  ]).test('getMaxFirstLevel %s', (desc, properties, flags, expected) => {
+    expect(Utils.getMaxFirstLevel(properties, flags)).toEqual(expected);
+  });
+
+  each([
+    ["empty properties, empty flags",{}, {}, 1],
+    ["null properties, undefined flags",null, undefined, 1],
+    ["wrong field, flag is on", {max_instances:3}, {FLAG_2002_UNLIMITED_MAX: true}, null],
+    ["maxCountInstances 3, flag is on", {maxCountInstances:3}, {FLAG_2002_UNLIMITED_MAX: true}, 3],
+    ["maxCountInstances 3, flag is off", {maxCountInstances:3}, {FLAG_2002_UNLIMITED_MAX: true}, 3],
+  ]).test('getMaxFirstLevel %s', (desc, properties, flags, expected) => {
+    expect(Utils.getMaxVfModule(properties, flags)).toEqual(expected);
+  });
+
+
+
 });
 });
index cd7ebdf..3db7707 100644 (file)
@@ -3,11 +3,18 @@ import * as _ from 'lodash'
 export class Utils {
 
   static getMaxFirstLevel(properties, flags: { [key: string]: boolean }) : number | null{
 export class Utils {
 
   static getMaxFirstLevel(properties, flags: { [key: string]: boolean }) : number | null{
-    if (flags && !!flags['FLAG_2002_UNLIMITED_MAX']) {
-      return !_.isNil(properties) && !_.isNil(properties.max_instances) ? properties.max_instances : null;
-    } else {
-      return properties.max_instances || 1;
+    return this.getMaxInstancesAllowed(properties, 'max_instances', flags)
+  }
+
+  static getMaxVfModule(properties, flags: { [key: string]: boolean }) : number | null{
+    return this.getMaxInstancesAllowed(properties, 'maxCountInstances', flags)
+  }
+
+  static getMaxInstancesAllowed(properties, filedName: string, flags: { [key: string]: boolean }) : number | null{
+    if (!_.isNil(properties) && !_.isNil(properties[filedName])) {
+      return properties[filedName];
     }
     }
+    return (flags && !!flags['FLAG_2002_UNLIMITED_MAX']) ? null : 1;
   }
 
   public static clampNumber = (number, min, max) => {
   }
 
   public static clampNumber = (number, min, max) => {