blob: dd09030f4f4b9c08560ef472b714ae6d7c5be9dc [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';
17import 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';
AviZi280f8012017-06-09 02:39:56 +030020import {LicenseKeyGroupStoreFactory, LicenseKeyGroupPostFactory} from 'test-utils/factories/licenseModel/LicenseKeyGroupFactories.js';
Michael Landoefa037d2017-02-19 12:57:33 +020021
22import LicenseKeyGroupsActionHelper from 'sdc-app/onboarding/licenseModel/licenseKeyGroups/LicenseKeyGroupsActionHelper.js';
AviZi280f8012017-06-09 02:39:56 +030023import VersionControllerUtilsFactory from 'test-utils/factories/softwareProduct/VersionControllerUtilsFactory.js';
Michael Landoefa037d2017-02-19 12:57:33 +020024
25describe('License Key Groups Module Tests', function () {
26
27 const LICENSE_MODEL_ID = '555';
AviZi280f8012017-06-09 02:39:56 +030028 const version = VersionControllerUtilsFactory.build().version;
29
Michael Landoefa037d2017-02-19 12:57:33 +020030 it('Load License Key Group', () => {
AviZi280f8012017-06-09 02:39:56 +030031
32 const licenseKeyGroupsList = buildListFromFactory(LicenseKeyGroupStoreFactory);
33
Michael Landoefa037d2017-02-19 12:57:33 +020034 deepFreeze(licenseKeyGroupsList);
35 const store = storeCreator();
36 deepFreeze(store.getState());
37
38 const expectedStore = cloneAndSet(store.getState(), 'licenseModel.licenseKeyGroup.licenseKeyGroupsList', licenseKeyGroupsList);
39
40 mockRest.addHandler('fetch', ({data, options, baseUrl}) => {
AviZi280f8012017-06-09 02:39:56 +030041 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);
Michael Landoefa037d2017-02-19 12:57:33 +020044 return {results: licenseKeyGroupsList};
45 });
46
AviZi280f8012017-06-09 02:39:56 +030047 return LicenseKeyGroupsActionHelper.fetchLicenseKeyGroupsList(store.dispatch, {licenseModelId: LICENSE_MODEL_ID, version}).then(() => {
48 expect(store.getState()).toEqual(expectedStore);
Michael Landoefa037d2017-02-19 12:57:33 +020049 });
50 });
51
52 it('Delete License Key Group', () => {
AviZi280f8012017-06-09 02:39:56 +030053
54 const licenseKeyGroupsList = buildListFromFactory(LicenseKeyGroupStoreFactory, 1);
55
Michael Landoefa037d2017-02-19 12:57:33 +020056 deepFreeze(licenseKeyGroupsList);
57 const store = storeCreator({
58 licenseModel: {
59 licenseKeyGroup: {
60 licenseKeyGroupsList
61 }
62 }
63 });
64 deepFreeze(store.getState());
AviZi280f8012017-06-09 02:39:56 +030065 const toBeDeletedLicenseKeyGroupId = licenseKeyGroupsList[0].id;
Michael Landoefa037d2017-02-19 12:57:33 +020066 const expectedStore = cloneAndSet(store.getState(), 'licenseModel.licenseKeyGroup.licenseKeyGroupsList', []);
67
68 mockRest.addHandler('destroy', ({data, options, baseUrl}) => {
AviZi280f8012017-06-09 02:39:56 +030069 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);
Michael Landoefa037d2017-02-19 12:57:33 +020072 });
73
74 return LicenseKeyGroupsActionHelper.deleteLicenseKeyGroup(store.dispatch, {
75 licenseKeyGroupId: toBeDeletedLicenseKeyGroupId,
AviZi280f8012017-06-09 02:39:56 +030076 licenseModelId: LICENSE_MODEL_ID,
77 version
Michael Landoefa037d2017-02-19 12:57:33 +020078 }).then(() => {
AviZi280f8012017-06-09 02:39:56 +030079 expect(store.getState()).toEqual(expectedStore);
Michael Landoefa037d2017-02-19 12:57:33 +020080 });
81 });
82
83 it('Add License Key Group', () => {
84
85 const store = storeCreator();
86 deepFreeze(store.getState());
87
AviZi280f8012017-06-09 02:39:56 +030088 const LicenseKeyGroupPost = LicenseKeyGroupPostFactory.build();
89 deepFreeze(LicenseKeyGroupPost);
Michael Landoefa037d2017-02-19 12:57:33 +020090
AviZi280f8012017-06-09 02:39:56 +030091 const LicenseKeyGroupStore = LicenseKeyGroupStoreFactory.build();
92 deepFreeze(LicenseKeyGroupStore);
Michael Landoefa037d2017-02-19 12:57:33 +020093
AviZi280f8012017-06-09 02:39:56 +030094 const expectedStore = cloneAndSet(store.getState(), 'licenseModel.licenseKeyGroup.licenseKeyGroupsList', [LicenseKeyGroupStore]);
Michael Landoefa037d2017-02-19 12:57:33 +020095
AviZi280f8012017-06-09 02:39:56 +030096 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);
Michael Landoefa037d2017-02-19 12:57:33 +0200100 return {
AviZi280f8012017-06-09 02:39:56 +0300101 value: LicenseKeyGroupStore.id
Michael Landoefa037d2017-02-19 12:57:33 +0200102 };
103 });
104
105 return LicenseKeyGroupsActionHelper.saveLicenseKeyGroup(store.dispatch, {
AviZi280f8012017-06-09 02:39:56 +0300106 licenseKeyGroup: LicenseKeyGroupPost,
107 licenseModelId: LICENSE_MODEL_ID,
108 version
Michael Landoefa037d2017-02-19 12:57:33 +0200109 }).then(() => {
AviZi280f8012017-06-09 02:39:56 +0300110 expect(store.getState()).toEqual(expectedStore);
Michael Landoefa037d2017-02-19 12:57:33 +0200111 });
112 });
113
114 it('Update License Key Group', () => {
AviZi280f8012017-06-09 02:39:56 +0300115 const licenseKeyGroupsList = buildListFromFactory(LicenseKeyGroupStoreFactory, 1);
Michael Landoefa037d2017-02-19 12:57:33 +0200116 deepFreeze(licenseKeyGroupsList);
117 const store = storeCreator({
118 licenseModel: {
119 licenseKeyGroup: {
120 licenseKeyGroupsList
121 }
122 }
123 });
124
125 const toBeUpdatedLicenseKeyGroupId = licenseKeyGroupsList[0].id;
126 const previousLicenseKeyGroupData = licenseKeyGroupsList[0];
127
AviZi280f8012017-06-09 02:39:56 +0300128 const licenseKeyGroupUpdatedData = LicenseKeyGroupPostFactory.build({
Michael Landoefa037d2017-02-19 12:57:33 +0200129 name: 'lsk1_UPDATE',
130 description: 'string_UPDATE',
AviZi280f8012017-06-09 02:39:56 +0300131 id: toBeUpdatedLicenseKeyGroupId
132 });
133 deepFreeze(licenseKeyGroupUpdatedData);
Michael Landoefa037d2017-02-19 12:57:33 +0200134
AviZi280f8012017-06-09 02:39:56 +0300135 const licenseKeyGroupPutRequest = LicenseKeyGroupPostFactory.build({
Michael Landoefa037d2017-02-19 12:57:33 +0200136 name: 'lsk1_UPDATE',
AviZi280f8012017-06-09 02:39:56 +0300137 description: 'string_UPDATE'
138 });
139
Michael Landoefa037d2017-02-19 12:57:33 +0200140 deepFreeze(licenseKeyGroupPutRequest);
141
AviZi280f8012017-06-09 02:39:56 +0300142 const expectedStore = cloneAndSet(store.getState(), 'licenseModel.licenseKeyGroup.licenseKeyGroupsList', [licenseKeyGroupUpdatedData]);
Michael Landoefa037d2017-02-19 12:57:33 +0200143
AviZi280f8012017-06-09 02:39:56 +0300144 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);
Michael Landoefa037d2017-02-19 12:57:33 +0200148 });
149
150 return LicenseKeyGroupsActionHelper.saveLicenseKeyGroup(store.dispatch, {
151 previousLicenseKeyGroup: previousLicenseKeyGroupData,
AviZi280f8012017-06-09 02:39:56 +0300152 licenseKeyGroup: licenseKeyGroupUpdatedData,
153 licenseModelId: LICENSE_MODEL_ID,
154 version
Michael Landoefa037d2017-02-19 12:57:33 +0200155 }).then(() => {
AviZi280f8012017-06-09 02:39:56 +0300156 expect(store.getState()).toEqual(expectedStore);
Michael Landoefa037d2017-02-19 12:57:33 +0200157 });
158 });
159
160});