2 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
4 * 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
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * 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.
16 import deepFreeze from 'deep-freeze';
17 import mockRest from 'test-utils/MockRest.js';
18 import {cloneAndSet, buildListFromFactory} from 'test-utils/Util.js';
19 import {storeCreator} from 'sdc-app/AppStore.js';
20 import {LicenseKeyGroupStoreFactory, LicenseKeyGroupPostFactory} from 'test-utils/factories/licenseModel/LicenseKeyGroupFactories.js';
22 import LicenseKeyGroupsActionHelper from 'sdc-app/onboarding/licenseModel/licenseKeyGroups/LicenseKeyGroupsActionHelper.js';
23 import VersionControllerUtilsFactory from 'test-utils/factories/softwareProduct/VersionControllerUtilsFactory.js';
25 describe('License Key Groups Module Tests', function () {
27 const LICENSE_MODEL_ID = '555';
28 const version = VersionControllerUtilsFactory.build().version;
30 it('Load License Key Group', () => {
32 const licenseKeyGroupsList = buildListFromFactory(LicenseKeyGroupStoreFactory);
34 deepFreeze(licenseKeyGroupsList);
35 const store = storeCreator();
36 deepFreeze(store.getState());
38 const expectedStore = cloneAndSet(store.getState(), 'licenseModel.licenseKeyGroup.licenseKeyGroupsList', licenseKeyGroupsList);
40 mockRest.addHandler('fetch', ({data, options, baseUrl}) => {
41 expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/license-key-groups`);
42 expect(data).toEqual(undefined);
43 expect(options).toEqual(undefined);
44 return {results: licenseKeyGroupsList};
47 return LicenseKeyGroupsActionHelper.fetchLicenseKeyGroupsList(store.dispatch, {licenseModelId: LICENSE_MODEL_ID, version}).then(() => {
48 expect(store.getState()).toEqual(expectedStore);
52 it('Delete License Key Group', () => {
54 const licenseKeyGroupsList = buildListFromFactory(LicenseKeyGroupStoreFactory, 1);
56 deepFreeze(licenseKeyGroupsList);
57 const store = storeCreator({
64 deepFreeze(store.getState());
65 const toBeDeletedLicenseKeyGroupId = licenseKeyGroupsList[0].id;
66 const expectedStore = cloneAndSet(store.getState(), 'licenseModel.licenseKeyGroup.licenseKeyGroupsList', []);
68 mockRest.addHandler('destroy', ({data, options, baseUrl}) => {
69 expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/license-key-groups/${toBeDeletedLicenseKeyGroupId}`);
70 expect(data).toEqual(undefined);
71 expect(options).toEqual(undefined);
74 return LicenseKeyGroupsActionHelper.deleteLicenseKeyGroup(store.dispatch, {
75 licenseKeyGroupId: toBeDeletedLicenseKeyGroupId,
76 licenseModelId: LICENSE_MODEL_ID,
79 expect(store.getState()).toEqual(expectedStore);
83 it('Add License Key Group', () => {
85 const store = storeCreator();
86 deepFreeze(store.getState());
88 const LicenseKeyGroupPost = LicenseKeyGroupPostFactory.build();
89 deepFreeze(LicenseKeyGroupPost);
91 const LicenseKeyGroupStore = LicenseKeyGroupStoreFactory.build();
92 deepFreeze(LicenseKeyGroupStore);
94 const expectedStore = cloneAndSet(store.getState(), 'licenseModel.licenseKeyGroup.licenseKeyGroupsList', [LicenseKeyGroupStore]);
96 mockRest.addHandler('post', ({options, data, baseUrl}) => {
97 expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/license-key-groups`);
98 expect(data).toEqual(LicenseKeyGroupPost);
99 expect(options).toEqual(undefined);
101 value: LicenseKeyGroupStore.id
105 return LicenseKeyGroupsActionHelper.saveLicenseKeyGroup(store.dispatch, {
106 licenseKeyGroup: LicenseKeyGroupPost,
107 licenseModelId: LICENSE_MODEL_ID,
110 expect(store.getState()).toEqual(expectedStore);
114 it('Update License Key Group', () => {
115 const licenseKeyGroupsList = buildListFromFactory(LicenseKeyGroupStoreFactory, 1);
116 deepFreeze(licenseKeyGroupsList);
117 const store = storeCreator({
125 const toBeUpdatedLicenseKeyGroupId = licenseKeyGroupsList[0].id;
126 const previousLicenseKeyGroupData = licenseKeyGroupsList[0];
128 const licenseKeyGroupUpdatedData = LicenseKeyGroupPostFactory.build({
130 description: 'string_UPDATE',
131 id: toBeUpdatedLicenseKeyGroupId
133 deepFreeze(licenseKeyGroupUpdatedData);
135 const licenseKeyGroupPutRequest = LicenseKeyGroupPostFactory.build({
137 description: 'string_UPDATE'
140 deepFreeze(licenseKeyGroupPutRequest);
142 const expectedStore = cloneAndSet(store.getState(), 'licenseModel.licenseKeyGroup.licenseKeyGroupsList', [licenseKeyGroupUpdatedData]);
144 mockRest.addHandler('put', ({data, options, baseUrl}) => {
145 expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/license-key-groups/${toBeUpdatedLicenseKeyGroupId}`);
146 expect(data).toEqual(licenseKeyGroupPutRequest);
147 expect(options).toEqual(undefined);
150 return LicenseKeyGroupsActionHelper.saveLicenseKeyGroup(store.dispatch, {
151 previousLicenseKeyGroup: previousLicenseKeyGroupData,
152 licenseKeyGroup: licenseKeyGroupUpdatedData,
153 licenseModelId: LICENSE_MODEL_ID,
156 expect(store.getState()).toEqual(expectedStore);