blob: 15e1deecd6bcc8f9e8e6a9fefac72d12a43511ce [file] [log] [blame]
AviZi280f8012017-06-09 02:39:56 +03001/*!
Michael Landoefa037d2017-02-19 12:57:33 +02002 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
AviZi280f8012017-06-09 02:39:56 +03003 *
Michael Landoefa037d2017-02-19 12:57:33 +02004 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
AviZi280f8012017-06-09 02:39:56 +03007 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
Michael Landoefa037d2017-02-19 12:57:33 +020010 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
AviZi280f8012017-06-09 02:39:56 +030012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
13 * or implied. See the License for the specific language governing
14 * permissions and limitations under the License.
Michael Landoefa037d2017-02-19 12:57:33 +020015 */
Michael Landoefa037d2017-02-19 12:57:33 +020016import deepFreeze from 'deep-freeze';
Michael Landoefa037d2017-02-19 12:57:33 +020017import mockRest from 'test-utils/MockRest.js';
AviZi280f8012017-06-09 02:39:56 +030018import {cloneAndSet, buildListFromFactory} from 'test-utils/Util.js';
Michael Landoefa037d2017-02-19 12:57:33 +020019import {storeCreator} from 'sdc-app/AppStore.js';
20import EntitlementPoolsActionHelper from 'sdc-app/onboarding/licenseModel/entitlementPools/EntitlementPoolsActionHelper.js';
AviZi280f8012017-06-09 02:39:56 +030021import {EntitlementPoolStoreFactory, EntitlementPoolPostFactory} from 'test-utils/factories/licenseModel/EntitlementPoolFactories.js';
22import VersionControllerUtilsFactory from 'test-utils/factories/softwareProduct/VersionControllerUtilsFactory.js';
Michael Landoefa037d2017-02-19 12:57:33 +020023
24describe('Entitlement Pools Module Tests', function () {
25
26 const LICENSE_MODEL_ID = '555';
AviZi280f8012017-06-09 02:39:56 +030027 const version = VersionControllerUtilsFactory.build().version;
Michael Landoefa037d2017-02-19 12:57:33 +020028
29 it('Load Entitlement Pools List', () => {
AviZi280f8012017-06-09 02:39:56 +030030
31 const entitlementPoolsList = buildListFromFactory(EntitlementPoolStoreFactory);
Michael Landoefa037d2017-02-19 12:57:33 +020032 deepFreeze(entitlementPoolsList);
33 const store = storeCreator();
34 deepFreeze(store.getState());
35
36 const expectedStore = cloneAndSet(store.getState(), 'licenseModel.entitlementPool.entitlementPoolsList', entitlementPoolsList);
37
38 mockRest.addHandler('fetch', ({data, options, baseUrl}) => {
AviZi280f8012017-06-09 02:39:56 +030039 expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/entitlement-pools`);
40 expect(data).toEqual(undefined);
41 expect(options).toEqual(undefined);
Michael Landoefa037d2017-02-19 12:57:33 +020042 return {results: entitlementPoolsList};
43 });
44
AviZi280f8012017-06-09 02:39:56 +030045 return EntitlementPoolsActionHelper.fetchEntitlementPoolsList(store.dispatch, {licenseModelId: LICENSE_MODEL_ID, version}).then(() => {
46 expect(store.getState()).toEqual(expectedStore);
Michael Landoefa037d2017-02-19 12:57:33 +020047 });
48 });
49
50 it('Delete Entitlement Pool', () => {
Michael Landoefa037d2017-02-19 12:57:33 +020051
AviZi280f8012017-06-09 02:39:56 +030052 const entitlementPoolsList = buildListFromFactory(EntitlementPoolStoreFactory,1);
Michael Landoefa037d2017-02-19 12:57:33 +020053 deepFreeze(entitlementPoolsList);
54 const store = storeCreator({
55 licenseModel: {
56 entitlementPool: {
57 entitlementPoolsList
58 }
59 }
60 });
61 deepFreeze(store.getState());
62
63 const expectedStore = cloneAndSet(store.getState(), 'licenseModel.entitlementPool.entitlementPoolsList', []);
64
65 mockRest.addHandler('destroy', ({data, options, baseUrl}) => {
AviZi280f8012017-06-09 02:39:56 +030066 expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/entitlement-pools/${entitlementPoolsList[0].id}`);
67 expect(data).toEqual(undefined);
68 expect(options).toEqual(undefined);
Michael Landoefa037d2017-02-19 12:57:33 +020069 return {
70 results: {
71 returnCode: 'OK'
72 }
73 };
74 });
75
76 return EntitlementPoolsActionHelper.deleteEntitlementPool(store.dispatch, {
77 licenseModelId: LICENSE_MODEL_ID,
AviZi280f8012017-06-09 02:39:56 +030078 version,
Michael Landoefa037d2017-02-19 12:57:33 +020079 entitlementPoolId: entitlementPoolsList[0].id
80 }).then(() => {
AviZi280f8012017-06-09 02:39:56 +030081 expect(store.getState()).toEqual(expectedStore);
Michael Landoefa037d2017-02-19 12:57:33 +020082 });
83 });
84
85 it('Add Entitlement Pool', () => {
86
87 const store = storeCreator();
88 deepFreeze(store.getState());
89
AviZi280f8012017-06-09 02:39:56 +030090 const EntitlementPoolPostRequest = EntitlementPoolPostFactory.build();
91
92 deepFreeze(EntitlementPoolPostRequest);
93
Michael Landoefa037d2017-02-19 12:57:33 +020094 const entitlementPoolIdFromResponse = 'ADDED_ID';
AviZi280f8012017-06-09 02:39:56 +030095 const entitlementPoolAfterAdd = EntitlementPoolStoreFactory.build({id: entitlementPoolIdFromResponse});
96 deepFreeze(entitlementPoolAfterAdd);
Michael Landoefa037d2017-02-19 12:57:33 +020097
98 const expectedStore = cloneAndSet(store.getState(), 'licenseModel.entitlementPool.entitlementPoolsList', [entitlementPoolAfterAdd]);
99
AviZi280f8012017-06-09 02:39:56 +0300100 mockRest.addHandler('post', ({data, options, baseUrl}) => {
101 expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/entitlement-pools`);
102 expect(data).toEqual(EntitlementPoolPostRequest);
103 expect(options).toEqual(undefined);
Michael Landoefa037d2017-02-19 12:57:33 +0200104 return {
105 returnCode: 'OK',
106 value: entitlementPoolIdFromResponse
107 };
108 });
109
110 return EntitlementPoolsActionHelper.saveEntitlementPool(store.dispatch,
111 {
112 licenseModelId: LICENSE_MODEL_ID,
AviZi280f8012017-06-09 02:39:56 +0300113 version,
Michael Landoefa037d2017-02-19 12:57:33 +0200114 previousEntitlementPool: null,
AviZi280f8012017-06-09 02:39:56 +0300115 entitlementPool: EntitlementPoolPostRequest
Michael Landoefa037d2017-02-19 12:57:33 +0200116 }
117 ).then(() => {
AviZi280f8012017-06-09 02:39:56 +0300118 expect(store.getState()).toEqual(expectedStore);
Michael Landoefa037d2017-02-19 12:57:33 +0200119 });
120 });
121
122 it('Update Entitlement Pool', () => {
AviZi280f8012017-06-09 02:39:56 +0300123
124 const entitlementPoolsList = buildListFromFactory(EntitlementPoolStoreFactory, 1);
Michael Landoefa037d2017-02-19 12:57:33 +0200125 deepFreeze(entitlementPoolsList);
126
127 const store = storeCreator({
128 licenseModel: {
129 entitlementPool: {
130 entitlementPoolsList
131 }
132 }
133 });
AviZi280f8012017-06-09 02:39:56 +0300134
Michael Landoefa037d2017-02-19 12:57:33 +0200135 deepFreeze(store.getState());
136
137 const toBeUpdatedEntitlementPoolId = entitlementPoolsList[0].id;
138 const previousEntitlementPoolData = entitlementPoolsList[0];
AviZi280f8012017-06-09 02:39:56 +0300139 const entitlementPoolUpdateData = EntitlementPoolStoreFactory.build({name: 'ep1_UPDATED', description: 'string_UPDATED', id: toBeUpdatedEntitlementPoolId});
Michael Landoefa037d2017-02-19 12:57:33 +0200140 deepFreeze(entitlementPoolUpdateData);
141
AviZi280f8012017-06-09 02:39:56 +0300142 const entitlementPoolPutRequest = EntitlementPoolPostFactory.build({name: 'ep1_UPDATED', description: 'string_UPDATED'});
Michael Landoefa037d2017-02-19 12:57:33 +0200143 deepFreeze(entitlementPoolPutRequest);
144
145 const expectedStore = cloneAndSet(store.getState(), 'licenseModel.entitlementPool.entitlementPoolsList', [entitlementPoolUpdateData]);
146
147
AviZi280f8012017-06-09 02:39:56 +0300148 mockRest.addHandler('put', ({data, options, baseUrl}) => {
149 expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/entitlement-pools/${toBeUpdatedEntitlementPoolId}`);
150 expect(data).toEqual(entitlementPoolPutRequest);
151 expect(options).toEqual(undefined);
Michael Landoefa037d2017-02-19 12:57:33 +0200152 return {returnCode: 'OK'};
153 });
154
155 return EntitlementPoolsActionHelper.saveEntitlementPool(store.dispatch, {
156 licenseModelId: LICENSE_MODEL_ID,
AviZi280f8012017-06-09 02:39:56 +0300157 version,
Michael Landoefa037d2017-02-19 12:57:33 +0200158 previousEntitlementPool: previousEntitlementPoolData,
159 entitlementPool: entitlementPoolUpdateData
160 }).then(() => {
AviZi280f8012017-06-09 02:39:56 +0300161 expect(store.getState()).toEqual(expectedStore);
Michael Landoefa037d2017-02-19 12:57:33 +0200162 });
163 });
164
165});