[SDC-29] Amdocs OnBoard 1707 initial commit.
[sdc.git] / openecomp-ui / test / licenseModel / featureGroups / test.js
index d334ab7..7d0d724 100644 (file)
@@ -1,75 +1,56 @@
-/*-
- * ============LICENSE_START=======================================================
- * SDC
- * ================================================================================
+/*!
  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
+ *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
- * 
- *      http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
+ * or implied. See the License for the specific language governing
+ * permissions and limitations under the License.
  */
-
-import {expect} from 'chai';
 import deepFreeze from 'deep-freeze';
 import mockRest from 'test-utils/MockRest.js';
-import {cloneAndSet} from 'test-utils/Util.js';
+import {cloneAndSet, buildListFromFactory} from 'test-utils/Util.js';
 import {storeCreator} from 'sdc-app/AppStore.js';
 import FeatureGroupsActionHelper from 'sdc-app/onboarding/licenseModel/featureGroups/FeatureGroupsActionHelper.js';
+import { FeatureGroupStoreFactory, FeatureGroupPostFactory, FeatureGroupDispatchFactory, FeatureGroupPutFactory } from 'test-utils/factories/licenseModel/FeatureGroupFactories.js';
+import VersionControllerUtilsFactory from 'test-utils/factories/softwareProduct/VersionControllerUtilsFactory.js';
 
 
 describe('Feature Groups Module Tests', function () {
 
        const LICENSE_MODEL_ID = '555';
+       const version = VersionControllerUtilsFactory.build().version;
 
        it('Load Feature Groups List', () => {
-               const featureGroupsList = [
-                       {
-                               name: 'fs1',
-                               id: 0,
-                               description: 'fs1-d',
-                               licenseKeyGroupsIds: [1],
-                               entitlementPoolsIds: [1],
-                               refCount: 0
-                       }
-               ];
+
+               const featureGroupsList = buildListFromFactory(FeatureGroupStoreFactory);
                deepFreeze(featureGroupsList);
+
                const store = storeCreator();
                deepFreeze(store.getState());
 
                const expectedStore = cloneAndSet(store.getState(), 'licenseModel.featureGroup.featureGroupsList', featureGroupsList);
 
                mockRest.addHandler('fetch', ({data, options, baseUrl}) => {
-                       expect(baseUrl).to.equal(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/feature-groups`);
-                       expect(data).to.equal(undefined);
-                       expect(options).to.equal(undefined);
+                       expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/feature-groups`);
+                       expect(data).toEqual(undefined);
+                       expect(options).toEqual(undefined);
                        return {results: featureGroupsList};
                });
 
-               return FeatureGroupsActionHelper.fetchFeatureGroupsList(store.dispatch, {licenseModelId: LICENSE_MODEL_ID}).then(() => {
-                       expect(store.getState()).to.deep.equal(expectedStore);
+               return FeatureGroupsActionHelper.fetchFeatureGroupsList(store.dispatch, {licenseModelId: LICENSE_MODEL_ID, version}).then(() => {
+                       expect(store.getState()).toEqual(expectedStore);
                });
        });
 
        it('Delete Feature Group', () => {
-               const featureGroupsList = [
-                       {
-                               name: 'fs1',
-                               id: 0,
-                               description: 'fs1-d',
-                               licenseKeyGroupsIds: [1],
-                               entitlementPoolsIds: [1],
-                               refCount: 0
-                       }
-               ];
+               const featureGroupsList = buildListFromFactory(FeatureGroupStoreFactory, 1);
                deepFreeze(featureGroupsList);
                const store = storeCreator({
                        licenseModel: {
@@ -82,10 +63,12 @@ describe('Feature Groups Module Tests', function () {
 
                const expectedStore = cloneAndSet(store.getState(), 'licenseModel.featureGroup.featureGroupsList', []);
 
+               const idToDelete = featureGroupsList[0].id;
+
                mockRest.addHandler('destroy', ({data, options, baseUrl}) => {
-                       expect(baseUrl).to.equal(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/feature-groups/${featureGroupsList[0].id}`);
-                       expect(data).to.equal(undefined);
-                       expect(options).to.equal(undefined);
+                       expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/feature-groups/${idToDelete}`);
+                       expect(data).toEqual(undefined);
+                       expect(options).toEqual(undefined);
                        return {
                                results: {
                                        returnCode: 'OK'
@@ -95,9 +78,10 @@ describe('Feature Groups Module Tests', function () {
 
                return FeatureGroupsActionHelper.deleteFeatureGroup(store.dispatch, {
                        licenseModelId: LICENSE_MODEL_ID,
-                       featureGroupId: featureGroupsList[0].id
+                       version,
+                       featureGroupId: idToDelete
                }).then(() => {
-                       expect(store.getState()).to.deep.equal(expectedStore);
+                       expect(store.getState()).toEqual(expectedStore);
                });
        });
 
@@ -106,56 +90,62 @@ describe('Feature Groups Module Tests', function () {
                const store = storeCreator();
                deepFreeze(store.getState());
 
-               const featureGroupPostRequest = {
-                       name: 'fs1',
-                       description: 'fs1-d',
-                       partNumber: '123',
+               const FeatureGroupPostRequest = FeatureGroupPostFactory.build({
                        addedLicenseKeyGroupsIds: [1],
                        addedEntitlementPoolsIds: [1]
-               };
-               const featureGroupToAdd = {
-                       name: 'fs1',
-                       description: 'fs1-d',
-                       partNumber: '123',
+               });
+               const featureGroupToAdd = FeatureGroupDispatchFactory.build({
                        licenseKeyGroupsIds: [1],
                        entitlementPoolsIds: [1]
-               };
+               });
+
                const featureGroupIdFromResponse = 'ADDED_ID';
-               const featureGroupAfterAdd = {
+               const featureGroupAfterAdd = FeatureGroupStoreFactory.build({
                        ...featureGroupToAdd,
                        id: featureGroupIdFromResponse
-               };
+               });
 
                const expectedStore = cloneAndSet(store.getState(), 'licenseModel.featureGroup.featureGroupsList', [featureGroupAfterAdd]);
 
-               mockRest.addHandler('create', ({data, options, baseUrl}) => {
-                       expect(baseUrl).to.equal(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/feature-groups`);
-                       expect(data).to.deep.equal(featureGroupPostRequest);
-                       expect(options).to.equal(undefined);
+               mockRest.addHandler('post', ({data, options, baseUrl}) => {
+                       expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/feature-groups`);
+                       expect(data).toEqual(FeatureGroupPostRequest);
+                       expect(options).toEqual(undefined);
                        return {
                                returnCode: 'OK',
                                value: featureGroupIdFromResponse
                        };
                });
 
+               mockRest.addHandler('fetch', ({data, options, baseUrl}) => {
+                       expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/entitlement-pools`);
+                       expect(data).toEqual(undefined);
+                       expect(options).toEqual(undefined);
+                       return {results: []};
+               });
+
+               mockRest.addHandler('fetch', ({data, options, baseUrl}) => {
+                       expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/license-key-groups`);
+                       expect(data).toEqual(undefined);
+                       expect(options).toEqual(undefined);
+                       return {results: []};
+               });
+
+
                return FeatureGroupsActionHelper.saveFeatureGroup(store.dispatch, {
                        licenseModelId: LICENSE_MODEL_ID,
+                       version,
                        featureGroup: featureGroupToAdd
                }).then(() => {
-                       expect(store.getState()).to.deep.equal(expectedStore);
+                       expect(store.getState()).toEqual(expectedStore);
                });
        });
 
        it('Update Feature Group', () => {
-               const featureGroupsList = [{
-                       name: 'fs1',
-                       id: 0,
-                       description: 'fs1-d',
-                       partNumber: '123',
+               const featureGroupsList = buildListFromFactory(FeatureGroupStoreFactory, 1, {
                        licenseKeyGroupsIds: [1],
-                       entitlementPoolsIds: [1],
-                       refCount: 0
-               }];
+                       entitlementPoolsIds: [1]
+               });
                deepFreeze(featureGroupsList);
 
                const store = storeCreator({
@@ -169,44 +159,92 @@ describe('Feature Groups Module Tests', function () {
 
                const toBeUpdatedFeatureGroupId = featureGroupsList[0].id;
                const previousFeatureGroupData = featureGroupsList[0];
-               const featureGroupUpdateData = {
-                       ...featureGroupsList[0],
-                       name: 'fs_UPDATED',
-                       description: 'description_UPDATED',
-                       partNumber: '123_UPDATED',
+
+               const featureGroupUpdateData = FeatureGroupStoreFactory.build({
+                       ...previousFeatureGroupData,
                        licenseKeyGroupsIds: [7],
                        entitlementPoolsIds: [7]
-               };
+               });
                deepFreeze(featureGroupUpdateData);
 
-               const featureGroupPutRequest = {
-                       name: 'fs_UPDATED',
-                       description: 'description_UPDATED',
-                       partNumber: '123_UPDATED',
+               const FeatureGroupPutFactoryRequest = FeatureGroupPutFactory.build({
+                       name: featureGroupUpdateData.name,
+                       description: featureGroupUpdateData.description,
+                       partNumber: featureGroupUpdateData.partNumber,
                        addedLicenseKeyGroupsIds: [7],
                        addedEntitlementPoolsIds: [7],
                        removedLicenseKeyGroupsIds: [1],
                        removedEntitlementPoolsIds: [1]
-               };
-               deepFreeze(featureGroupPutRequest);
+               });
+               deepFreeze(FeatureGroupPutFactoryRequest);
 
                const expectedStore = cloneAndSet(store.getState(), 'licenseModel.featureGroup.featureGroupsList', [featureGroupUpdateData]);
 
 
-               mockRest.addHandler('save', ({data, options, baseUrl}) => {
-                       expect(baseUrl).to.equal(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/feature-groups/${toBeUpdatedFeatureGroupId}`);
-                       expect(data).to.deep.equal(featureGroupPutRequest);
-                       expect(options).to.equal(undefined);
+               mockRest.addHandler('put', ({data, options, baseUrl}) => {
+                       expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/feature-groups/${toBeUpdatedFeatureGroupId}`);
+                       expect(data).toEqual(FeatureGroupPutFactoryRequest);
+                       expect(options).toEqual(undefined);
                        return {returnCode: 'OK'};
                });
 
+               mockRest.addHandler('fetch', ({data, options, baseUrl}) => {
+                       expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/entitlement-pools`);
+                       expect(data).toEqual(undefined);
+                       expect(options).toEqual(undefined);
+                       return {results: []};
+               });
+
+               mockRest.addHandler('fetch', ({data, options, baseUrl}) => {
+                       expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/license-key-groups`);
+                       expect(data).toEqual(undefined);
+                       expect(options).toEqual(undefined);
+                       return {results: []};
+               });
+
                return FeatureGroupsActionHelper.saveFeatureGroup(store.dispatch, {
                        licenseModelId: LICENSE_MODEL_ID,
+                       version,
                        previousFeatureGroup: previousFeatureGroupData,
                        featureGroup: featureGroupUpdateData
                }).then(() => {
-                       expect(store.getState()).to.deep.equal(expectedStore);
+                       expect(store.getState()).toEqual(expectedStore);
                });
+
+       });
+
+       it('Open Editor', () => {
+
+               const store = storeCreator();
+               deepFreeze(store.getState());
+
+               const editorData = FeatureGroupStoreFactory.build();
+               deepFreeze(editorData);
+               const expectedStore = cloneAndSet(store.getState(), 'licenseModel.featureGroup.featureGroupEditor.data', editorData);
+               const LICENSE_MODEL_ID = '123';
+
+               mockRest.addHandler('fetch', ({data, options, baseUrl}) => {
+                       expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/entitlement-pools`);
+                       expect(data).toEqual(undefined);
+                       expect(options).toEqual(undefined);
+                       return {results: []};
+               });
+
+               mockRest.addHandler('fetch', ({data, options, baseUrl}) => {
+                       expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/license-key-groups`);
+                       expect(data).toEqual(undefined);
+                       expect(options).toEqual(undefined);
+                       return {results: []};
+               });
+
+
+               FeatureGroupsActionHelper.openFeatureGroupsEditor(store.dispatch, {featureGroup: editorData, licenseModelId: '123', version});
+               setTimeout(() =>{
+                       expect(store.getState()).toEqual(expectedStore);
+               }, 100);
+
+
+
        });
 
 });