2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 import {expect} from 'chai';
22 import deepFreeze from 'deep-freeze';
23 import mockRest from 'test-utils/MockRest.js';
24 import {cloneAndSet} from 'test-utils/Util.js';
25 import {storeCreator} from 'sdc-app/AppStore.js';
27 import LicenseKeyGroupsActionHelper from 'sdc-app/onboarding/licenseModel/licenseKeyGroups/LicenseKeyGroupsActionHelper.js';
29 describe('License Key Groups Module Tests', function () {
31 const LICENSE_MODEL_ID = '555';
32 it('Load License Key Group', () => {
33 const licenseKeyGroupsList = [
36 description: 'string',
38 operationalScope: {'choices': ['Data_Center'], 'other': ''},
42 deepFreeze(licenseKeyGroupsList);
43 const store = storeCreator();
44 deepFreeze(store.getState());
46 const expectedStore = cloneAndSet(store.getState(), 'licenseModel.licenseKeyGroup.licenseKeyGroupsList', licenseKeyGroupsList);
48 mockRest.addHandler('fetch', ({data, options, baseUrl}) => {
49 expect(baseUrl).to.equal(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/license-key-groups`);
50 expect(data).to.equal(undefined);
51 expect(options).to.equal(undefined);
52 return {results: licenseKeyGroupsList};
55 return LicenseKeyGroupsActionHelper.fetchLicenseKeyGroupsList(store.dispatch, {licenseModelId: LICENSE_MODEL_ID}).then(() => {
56 expect(store.getState()).to.deep.equal(expectedStore);
60 it('Delete License Key Group', () => {
61 const licenseKeyGroupsList = [
64 description: 'string',
66 operationalScope: {'choices': ['Data_Center'], 'other': ''},
70 deepFreeze(licenseKeyGroupsList);
71 const store = storeCreator({
78 deepFreeze(store.getState());
79 const toBeDeletedLicenseKeyGroupId = '0';
80 const expectedStore = cloneAndSet(store.getState(), 'licenseModel.licenseKeyGroup.licenseKeyGroupsList', []);
82 mockRest.addHandler('destroy', ({data, options, baseUrl}) => {
83 expect(baseUrl).to.equal(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/license-key-groups/${toBeDeletedLicenseKeyGroupId}`);
84 expect(data).to.equal(undefined);
85 expect(options).to.equal(undefined);
88 return LicenseKeyGroupsActionHelper.deleteLicenseKeyGroup(store.dispatch, {
89 licenseKeyGroupId: toBeDeletedLicenseKeyGroupId,
90 licenseModelId: LICENSE_MODEL_ID
92 expect(store.getState()).to.deep.equal(expectedStore);
96 it('Add License Key Group', () => {
98 const store = storeCreator();
99 deepFreeze(store.getState());
101 const licenseKeyGroupPostRequest = {
103 description: 'string_ADDED',
104 type: 'Unique_ADDED',
105 operationalScope: {'choices': ['Data_Center'], 'other': ''}
107 deepFreeze(licenseKeyGroupPostRequest);
109 const licenseKeyGroupToAdd = {
110 ...licenseKeyGroupPostRequest
113 deepFreeze(licenseKeyGroupToAdd);
115 const licenseKeyGroupIdFromResponse = 'ADDED_ID';
116 const licenseKeyGroupAfterAdd = {
117 ...licenseKeyGroupToAdd,
118 id: licenseKeyGroupIdFromResponse
120 deepFreeze(licenseKeyGroupAfterAdd);
122 const expectedStore = cloneAndSet(store.getState(), 'licenseModel.licenseKeyGroup.licenseKeyGroupsList', [licenseKeyGroupAfterAdd]);
124 mockRest.addHandler('create', ({options, data, baseUrl}) => {
125 expect(baseUrl).to.equal(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/license-key-groups`);
126 expect(data).to.deep.equal(licenseKeyGroupPostRequest);
127 expect(options).to.equal(undefined);
129 value: licenseKeyGroupIdFromResponse
133 return LicenseKeyGroupsActionHelper.saveLicenseKeyGroup(store.dispatch, {
134 licenseKeyGroup: licenseKeyGroupToAdd,
135 licenseModelId: LICENSE_MODEL_ID
137 expect(store.getState()).to.deep.equal(expectedStore);
141 it('Update License Key Group', () => {
142 const licenseKeyGroupsList = [
145 description: 'string',
147 operationalScope: {'choices': ['Data_Center'], 'other': ''},
151 deepFreeze(licenseKeyGroupsList);
152 const store = storeCreator({
160 const toBeUpdatedLicenseKeyGroupId = licenseKeyGroupsList[0].id;
161 const previousLicenseKeyGroupData = licenseKeyGroupsList[0];
163 const licenseKeyGroupUpdateData = {
164 ...licenseKeyGroupsList[0],
166 description: 'string_UPDATE',
168 operationalScope: {'choices': ['Data_Center'], 'other': ''}
170 deepFreeze(licenseKeyGroupUpdateData);
172 const licenseKeyGroupPutRequest = {
174 description: 'string_UPDATE',
176 operationalScope: {'choices': ['Data_Center'], 'other': ''}
178 deepFreeze(licenseKeyGroupPutRequest);
180 const expectedStore = cloneAndSet(store.getState(), 'licenseModel.licenseKeyGroup.licenseKeyGroupsList', [licenseKeyGroupUpdateData]);
182 mockRest.addHandler('save', ({data, options, baseUrl}) => {
183 expect(baseUrl).to.equal(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/license-key-groups/${toBeUpdatedLicenseKeyGroupId}`);
184 expect(data).to.deep.equal(licenseKeyGroupPutRequest);
185 expect(options).to.equal(undefined);
188 return LicenseKeyGroupsActionHelper.saveLicenseKeyGroup(store.dispatch, {
189 previousLicenseKeyGroup: previousLicenseKeyGroupData,
190 licenseKeyGroup: licenseKeyGroupUpdateData,
191 licenseModelId: LICENSE_MODEL_ID
193 expect(store.getState()).to.deep.equal(expectedStore);