blob: 442f7bf91f7f18026d97b5106873f021c68af175 [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';
AviZi280f8012017-06-09 02:39:56 +030017import pickBy from 'lodash/pickBy';
Michael Landoefa037d2017-02-19 12:57:33 +020018import mockRest from 'test-utils/MockRest.js';
AviZi280f8012017-06-09 02:39:56 +030019import {cloneAndSet, buildListFromFactory} from 'test-utils/Util.js';
Michael Landoefa037d2017-02-19 12:57:33 +020020import {storeCreator} from 'sdc-app/AppStore.js';
21import LicenseAgreementActionHelper from 'sdc-app/onboarding/licenseModel/licenseAgreement/LicenseAgreementActionHelper.js';
22
AviZi280f8012017-06-09 02:39:56 +030023import { LicenseAgreementStoreFactory, LicenseAgreementDispatchFactory, LicenseAgreementPostFactory, LicenseAgreementPutFactory } from 'test-utils/factories/licenseModel/LicenseAgreementFactories.js';
24import VersionControllerUtilsFactory from 'test-utils/factories/softwareProduct/VersionControllerUtilsFactory.js';
Michael Landoefa037d2017-02-19 12:57:33 +020025
26describe('License Agreement Module Tests', () => {
27
28 const LICENSE_MODEL_ID = '777';
AviZi280f8012017-06-09 02:39:56 +030029 const version = VersionControllerUtilsFactory.build().version;
Michael Landoefa037d2017-02-19 12:57:33 +020030
31 it('Load License Agreement List', () => {
AviZi280f8012017-06-09 02:39:56 +030032 const licenseAgreementList = buildListFromFactory(LicenseAgreementStoreFactory);
33
Michael Landoefa037d2017-02-19 12:57:33 +020034 const store = storeCreator();
35 deepFreeze(store.getState());
36
37 const expectedStore = cloneAndSet(store.getState(), 'licenseModel.licenseAgreement.licenseAgreementList', licenseAgreementList);
38
39 mockRest.addHandler('fetch', ({options, data, baseUrl}) => {
AviZi280f8012017-06-09 02:39:56 +030040 expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/license-agreements`);
41 expect(data).toEqual(undefined);
42 expect(options).toEqual(undefined);
Michael Landoefa037d2017-02-19 12:57:33 +020043 return {results: licenseAgreementList};
44 });
AviZi280f8012017-06-09 02:39:56 +030045 return LicenseAgreementActionHelper.fetchLicenseAgreementList(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 License Agreement', () => {
AviZi280f8012017-06-09 02:39:56 +030051 const licenseAgreementList = buildListFromFactory(LicenseAgreementStoreFactory, 1);
Michael Landoefa037d2017-02-19 12:57:33 +020052 const store = storeCreator({
53 licenseModel: {
54 licenseAgreement: {
55 licenseAgreementList
56 }
57 }
58 });
59 deepFreeze(store.getState());
AviZi280f8012017-06-09 02:39:56 +030060 const toBeDeletedLicenseAgreementId = licenseAgreementList[0].id;
Michael Landoefa037d2017-02-19 12:57:33 +020061 const expectedStore = cloneAndSet(store.getState(), 'licenseModel.licenseAgreement.licenseAgreementList', []);
62
63 mockRest.addHandler('destroy', ({data, options, baseUrl}) => {
AviZi280f8012017-06-09 02:39:56 +030064 expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/license-agreements/${toBeDeletedLicenseAgreementId}`);
65 expect(data).toEqual(undefined);
66 expect(options).toEqual(undefined);
Michael Landoefa037d2017-02-19 12:57:33 +020067 });
68
69 return LicenseAgreementActionHelper.deleteLicenseAgreement(store.dispatch, {
70 licenseAgreementId: toBeDeletedLicenseAgreementId,
AviZi280f8012017-06-09 02:39:56 +030071 licenseModelId: LICENSE_MODEL_ID,
72 version
Michael Landoefa037d2017-02-19 12:57:33 +020073 }).then(() => {
AviZi280f8012017-06-09 02:39:56 +030074 expect(store.getState()).toEqual(expectedStore);
Michael Landoefa037d2017-02-19 12:57:33 +020075 });
76 });
77
78 it('Add License Agreement', () => {
79 const store = storeCreator();
80 deepFreeze(store.getState());
Michael Landoefa037d2017-02-19 12:57:33 +020081
AviZi280f8012017-06-09 02:39:56 +030082 const licenseAgreementToAdd = LicenseAgreementDispatchFactory.build();
83
84 const LicenseAgreementPostRequest = LicenseAgreementPostFactory.build(
85 pickBy(licenseAgreementToAdd, (val, key) => key !== 'featureGroupsIds')
86 );
87
88 deepFreeze(LicenseAgreementPostRequest);
Michael Landoefa037d2017-02-19 12:57:33 +020089
90 const licenseAgreementIdFromResponse = 'ADDED_ID';
AviZi280f8012017-06-09 02:39:56 +030091 const licenseAgreementAfterAdd = LicenseAgreementStoreFactory.build({
Michael Landoefa037d2017-02-19 12:57:33 +020092 ...licenseAgreementToAdd,
93 id: licenseAgreementIdFromResponse
AviZi280f8012017-06-09 02:39:56 +030094 });
Michael Landoefa037d2017-02-19 12:57:33 +020095 deepFreeze(licenseAgreementAfterAdd);
96
97 const expectedStore = cloneAndSet(store.getState(), 'licenseModel.licenseAgreement.licenseAgreementList', [licenseAgreementAfterAdd]);
98
AviZi280f8012017-06-09 02:39:56 +030099 mockRest.addHandler('post', ({options, data, baseUrl}) => {
100 expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/license-agreements`);
101 expect(data).toEqual(LicenseAgreementPostRequest);
102 expect(options).toEqual(undefined);
Michael Landoefa037d2017-02-19 12:57:33 +0200103 return {
104 value: licenseAgreementIdFromResponse
105 };
106 });
107
108 return LicenseAgreementActionHelper.saveLicenseAgreement(store.dispatch, {
109 licenseAgreement: licenseAgreementToAdd,
AviZi280f8012017-06-09 02:39:56 +0300110 licenseModelId: LICENSE_MODEL_ID,
111 version
Michael Landoefa037d2017-02-19 12:57:33 +0200112 }).then(() => {
AviZi280f8012017-06-09 02:39:56 +0300113 expect(store.getState()).toEqual(expectedStore);
Michael Landoefa037d2017-02-19 12:57:33 +0200114 });
115 });
116
117 it('Update License Agreement', () => {
AviZi280f8012017-06-09 02:39:56 +0300118 const licenseAgreementList = buildListFromFactory(LicenseAgreementStoreFactory, 1, {featureGroupsIds: ['77']});
Michael Landoefa037d2017-02-19 12:57:33 +0200119 const store = storeCreator({
120 licenseModel: {
121 licenseAgreement: {
122 licenseAgreementList
123 }
124 }
125 });
126 deepFreeze(store.getState());
127
Michael Landoefa037d2017-02-19 12:57:33 +0200128 const previousLicenseAgreementData = licenseAgreementList[0];
AviZi280f8012017-06-09 02:39:56 +0300129 const toBeUpdatedLicenseAgreementId = previousLicenseAgreementData.id;
130 const oldFeatureGroupIds = previousLicenseAgreementData.featureGroupsIds;
Michael Landoefa037d2017-02-19 12:57:33 +0200131
AviZi280f8012017-06-09 02:39:56 +0300132 const newFeatureGroupsIds = ['update_id_1', 'update_id_2'];
133
134 const licenseAgreementUpdateData = LicenseAgreementStoreFactory.build({
135 id: toBeUpdatedLicenseAgreementId,
136 featureGroupsIds: newFeatureGroupsIds
137 });
Michael Landoefa037d2017-02-19 12:57:33 +0200138 deepFreeze(licenseAgreementUpdateData);
139
AviZi280f8012017-06-09 02:39:56 +0300140 const LicenseAgreementPutFactoryRequest = LicenseAgreementPutFactory.build({
141 addedFeatureGroupsIds: newFeatureGroupsIds,
142 removedFeatureGroupsIds: oldFeatureGroupIds
143 });
144
145 deepFreeze(LicenseAgreementPutFactoryRequest);
Michael Landoefa037d2017-02-19 12:57:33 +0200146
147 const expectedStore = cloneAndSet(store.getState(), 'licenseModel.licenseAgreement.licenseAgreementList', [licenseAgreementUpdateData]);
148
AviZi280f8012017-06-09 02:39:56 +0300149 mockRest.addHandler('put', ({data, options, baseUrl}) => {
150 expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/license-agreements/${toBeUpdatedLicenseAgreementId}`);
151 expect(data).toEqual(LicenseAgreementPutFactoryRequest);
152 expect(options).toEqual(undefined);
Michael Landoefa037d2017-02-19 12:57:33 +0200153 });
154
155 return LicenseAgreementActionHelper.saveLicenseAgreement(store.dispatch, {
156 licenseModelId: LICENSE_MODEL_ID,
AviZi280f8012017-06-09 02:39:56 +0300157 version,
Michael Landoefa037d2017-02-19 12:57:33 +0200158 previousLicenseAgreement: previousLicenseAgreementData,
159 licenseAgreement: licenseAgreementUpdateData
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});