AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 1 | /*! |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 2 | * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 3 | * |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 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 |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 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. |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 15 | */ |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 16 | import deepFreeze from 'deep-freeze'; |
| 17 | import mockRest from 'test-utils/MockRest.js'; |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 18 | import {cloneAndSet, buildListFromFactory} from 'test-utils/Util.js'; |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 19 | import {storeCreator} from 'sdc-app/AppStore.js'; |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 20 | import {LicenseKeyGroupStoreFactory, LicenseKeyGroupPostFactory} from 'test-utils/factories/licenseModel/LicenseKeyGroupFactories.js'; |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 21 | |
| 22 | import LicenseKeyGroupsActionHelper from 'sdc-app/onboarding/licenseModel/licenseKeyGroups/LicenseKeyGroupsActionHelper.js'; |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 23 | import VersionControllerUtilsFactory from 'test-utils/factories/softwareProduct/VersionControllerUtilsFactory.js'; |
Avi Ziv | 61070c9 | 2017-07-26 17:37:57 +0300 | [diff] [blame] | 24 | import {LimitItemFactory, LimitPostFactory} from 'test-utils/factories/licenseModel/LimitFactories.js'; |
az2497 | 644017c | 2017-08-10 17:49:40 +0300 | [diff] [blame] | 25 | import {getStrValue} from 'nfvo-utils/getValue.js'; |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 26 | |
| 27 | describe('License Key Groups Module Tests', function () { |
| 28 | |
| 29 | const LICENSE_MODEL_ID = '555'; |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 30 | const version = VersionControllerUtilsFactory.build().version; |
| 31 | |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 32 | it('Load License Key Group', () => { |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 33 | |
| 34 | const licenseKeyGroupsList = buildListFromFactory(LicenseKeyGroupStoreFactory); |
| 35 | |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 36 | deepFreeze(licenseKeyGroupsList); |
| 37 | const store = storeCreator(); |
| 38 | deepFreeze(store.getState()); |
| 39 | |
| 40 | const expectedStore = cloneAndSet(store.getState(), 'licenseModel.licenseKeyGroup.licenseKeyGroupsList', licenseKeyGroupsList); |
| 41 | |
| 42 | mockRest.addHandler('fetch', ({data, options, baseUrl}) => { |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 43 | expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/license-key-groups`); |
| 44 | expect(data).toEqual(undefined); |
| 45 | expect(options).toEqual(undefined); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 46 | return {results: licenseKeyGroupsList}; |
| 47 | }); |
| 48 | |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 49 | return LicenseKeyGroupsActionHelper.fetchLicenseKeyGroupsList(store.dispatch, {licenseModelId: LICENSE_MODEL_ID, version}).then(() => { |
| 50 | expect(store.getState()).toEqual(expectedStore); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 51 | }); |
| 52 | }); |
| 53 | |
| 54 | it('Delete License Key Group', () => { |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 55 | |
| 56 | const licenseKeyGroupsList = buildListFromFactory(LicenseKeyGroupStoreFactory, 1); |
| 57 | |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 58 | deepFreeze(licenseKeyGroupsList); |
| 59 | const store = storeCreator({ |
| 60 | licenseModel: { |
| 61 | licenseKeyGroup: { |
| 62 | licenseKeyGroupsList |
| 63 | } |
| 64 | } |
| 65 | }); |
| 66 | deepFreeze(store.getState()); |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 67 | const toBeDeletedLicenseKeyGroupId = licenseKeyGroupsList[0].id; |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 68 | const expectedStore = cloneAndSet(store.getState(), 'licenseModel.licenseKeyGroup.licenseKeyGroupsList', []); |
| 69 | |
| 70 | mockRest.addHandler('destroy', ({data, options, baseUrl}) => { |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 71 | expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/license-key-groups/${toBeDeletedLicenseKeyGroupId}`); |
| 72 | expect(data).toEqual(undefined); |
| 73 | expect(options).toEqual(undefined); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 74 | }); |
| 75 | |
| 76 | return LicenseKeyGroupsActionHelper.deleteLicenseKeyGroup(store.dispatch, { |
| 77 | licenseKeyGroupId: toBeDeletedLicenseKeyGroupId, |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 78 | licenseModelId: LICENSE_MODEL_ID, |
| 79 | version |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 80 | }).then(() => { |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 81 | expect(store.getState()).toEqual(expectedStore); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 82 | }); |
| 83 | }); |
| 84 | |
| 85 | it('Add License Key Group', () => { |
| 86 | |
| 87 | const store = storeCreator(); |
| 88 | deepFreeze(store.getState()); |
| 89 | |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 90 | const LicenseKeyGroupPost = LicenseKeyGroupPostFactory.build(); |
| 91 | deepFreeze(LicenseKeyGroupPost); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 92 | |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 93 | const LicenseKeyGroupStore = LicenseKeyGroupStoreFactory.build(); |
| 94 | deepFreeze(LicenseKeyGroupStore); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 95 | |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 96 | const expectedStore = cloneAndSet(store.getState(), 'licenseModel.licenseKeyGroup.licenseKeyGroupsList', [LicenseKeyGroupStore]); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 97 | |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 98 | mockRest.addHandler('post', ({options, data, baseUrl}) => { |
| 99 | expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/license-key-groups`); |
| 100 | expect(data).toEqual(LicenseKeyGroupPost); |
| 101 | expect(options).toEqual(undefined); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 102 | return { |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 103 | value: LicenseKeyGroupStore.id |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 104 | }; |
| 105 | }); |
| 106 | |
| 107 | return LicenseKeyGroupsActionHelper.saveLicenseKeyGroup(store.dispatch, { |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 108 | licenseKeyGroup: LicenseKeyGroupPost, |
| 109 | licenseModelId: LICENSE_MODEL_ID, |
| 110 | version |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 111 | }).then(() => { |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 112 | expect(store.getState()).toEqual(expectedStore); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 113 | }); |
| 114 | }); |
| 115 | |
| 116 | it('Update License Key Group', () => { |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 117 | const licenseKeyGroupsList = buildListFromFactory(LicenseKeyGroupStoreFactory, 1); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 118 | deepFreeze(licenseKeyGroupsList); |
| 119 | const store = storeCreator({ |
| 120 | licenseModel: { |
| 121 | licenseKeyGroup: { |
| 122 | licenseKeyGroupsList |
| 123 | } |
| 124 | } |
| 125 | }); |
| 126 | |
| 127 | const toBeUpdatedLicenseKeyGroupId = licenseKeyGroupsList[0].id; |
| 128 | const previousLicenseKeyGroupData = licenseKeyGroupsList[0]; |
| 129 | |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 130 | const licenseKeyGroupUpdatedData = LicenseKeyGroupPostFactory.build({ |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 131 | name: 'lsk1_UPDATE', |
| 132 | description: 'string_UPDATE', |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 133 | id: toBeUpdatedLicenseKeyGroupId |
| 134 | }); |
| 135 | deepFreeze(licenseKeyGroupUpdatedData); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 136 | |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 137 | const licenseKeyGroupPutRequest = LicenseKeyGroupPostFactory.build({ |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 138 | name: 'lsk1_UPDATE', |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 139 | description: 'string_UPDATE' |
| 140 | }); |
| 141 | |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 142 | deepFreeze(licenseKeyGroupPutRequest); |
| 143 | |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 144 | const expectedStore = cloneAndSet(store.getState(), 'licenseModel.licenseKeyGroup.licenseKeyGroupsList', [licenseKeyGroupUpdatedData]); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 145 | |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 146 | mockRest.addHandler('put', ({data, options, baseUrl}) => { |
| 147 | expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/license-key-groups/${toBeUpdatedLicenseKeyGroupId}`); |
| 148 | expect(data).toEqual(licenseKeyGroupPutRequest); |
| 149 | expect(options).toEqual(undefined); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 150 | }); |
| 151 | |
| 152 | return LicenseKeyGroupsActionHelper.saveLicenseKeyGroup(store.dispatch, { |
| 153 | previousLicenseKeyGroup: previousLicenseKeyGroupData, |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 154 | licenseKeyGroup: licenseKeyGroupUpdatedData, |
| 155 | licenseModelId: LICENSE_MODEL_ID, |
| 156 | version |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 157 | }).then(() => { |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 158 | expect(store.getState()).toEqual(expectedStore); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 159 | }); |
| 160 | }); |
| 161 | |
Avi Ziv | 61070c9 | 2017-07-26 17:37:57 +0300 | [diff] [blame] | 162 | it('Load Limits List', () => { |
| 163 | |
az2497 | 644017c | 2017-08-10 17:49:40 +0300 | [diff] [blame] | 164 | const limitsList = LimitItemFactory.buildList(3); |
Avi Ziv | 61070c9 | 2017-07-26 17:37:57 +0300 | [diff] [blame] | 165 | deepFreeze(limitsList); |
| 166 | const store = storeCreator(); |
| 167 | deepFreeze(store.getState()); |
| 168 | |
| 169 | const expectedStore = cloneAndSet(store.getState(), 'licenseModel.licenseKeyGroup.licenseKeyGroupsEditor.limitsList', limitsList); |
| 170 | const licenseKeyGroup = LicenseKeyGroupStoreFactory.build(); |
| 171 | mockRest.addHandler('fetch', ({data, options, baseUrl}) => { |
| 172 | expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/license-key-groups/${licenseKeyGroup.id}/limits`); |
| 173 | expect(data).toEqual(undefined); |
| 174 | expect(options).toEqual(undefined); |
| 175 | return {results: limitsList}; |
| 176 | }); |
| 177 | |
| 178 | return LicenseKeyGroupsActionHelper.fetchLimits(store.dispatch, {licenseModelId: LICENSE_MODEL_ID, version, licenseKeyGroup}).then(() => { |
| 179 | expect(store.getState()).toEqual(expectedStore); |
| 180 | }); |
| 181 | }); |
| 182 | |
| 183 | it('Add Limit', () => { |
| 184 | |
| 185 | const store = storeCreator(); |
| 186 | deepFreeze(store.getState()); |
| 187 | |
| 188 | const limitToAdd = LimitPostFactory.build(); |
az2497 | 644017c | 2017-08-10 17:49:40 +0300 | [diff] [blame] | 189 | let limitFromBE = {...limitToAdd}; |
| 190 | limitFromBE.metric = getStrValue(limitFromBE.metric); |
| 191 | limitFromBE.unit = getStrValue(limitFromBE.unit); |
Avi Ziv | 61070c9 | 2017-07-26 17:37:57 +0300 | [diff] [blame] | 192 | |
| 193 | deepFreeze(limitToAdd); |
az2497 | 644017c | 2017-08-10 17:49:40 +0300 | [diff] [blame] | 194 | deepFreeze(limitFromBE); |
Avi Ziv | 61070c9 | 2017-07-26 17:37:57 +0300 | [diff] [blame] | 195 | |
| 196 | const LimitIdFromResponse = 'ADDED_ID'; |
| 197 | const limitAddedItem = {...limitToAdd, id: LimitIdFromResponse}; |
| 198 | deepFreeze(limitAddedItem); |
| 199 | const licenseKeyGroup = LicenseKeyGroupStoreFactory.build(); |
| 200 | |
| 201 | const expectedStore = cloneAndSet(store.getState(), 'licenseModel.licenseKeyGroup.licenseKeyGroupsEditor.limitsList', [limitAddedItem]); |
| 202 | |
| 203 | mockRest.addHandler('post', ({data, options, baseUrl}) => { |
| 204 | expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/license-key-groups/${licenseKeyGroup.id}/limits`); |
az2497 | 644017c | 2017-08-10 17:49:40 +0300 | [diff] [blame] | 205 | expect(data).toEqual(limitFromBE); |
Avi Ziv | 61070c9 | 2017-07-26 17:37:57 +0300 | [diff] [blame] | 206 | expect(options).toEqual(undefined); |
| 207 | return { |
| 208 | returnCode: 'OK', |
| 209 | value: LimitIdFromResponse |
| 210 | }; |
| 211 | }); |
| 212 | |
| 213 | mockRest.addHandler('fetch', ({data, options, baseUrl}) => { |
| 214 | expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/license-key-groups/${licenseKeyGroup.id}/limits`); |
| 215 | expect(data).toEqual(undefined); |
| 216 | expect(options).toEqual(undefined); |
| 217 | return {results: [limitAddedItem]}; |
| 218 | }); |
| 219 | |
| 220 | return LicenseKeyGroupsActionHelper.submitLimit(store.dispatch, |
| 221 | { |
| 222 | licenseModelId: LICENSE_MODEL_ID, |
az2497 | 644017c | 2017-08-10 17:49:40 +0300 | [diff] [blame] | 223 | version, |
Avi Ziv | 61070c9 | 2017-07-26 17:37:57 +0300 | [diff] [blame] | 224 | licenseKeyGroup, |
| 225 | limit: limitToAdd |
| 226 | } |
| 227 | ).then(() => { |
| 228 | expect(store.getState()).toEqual(expectedStore); |
| 229 | }); |
| 230 | }); |
| 231 | |
| 232 | it('Delete Limit', () => { |
| 233 | |
az2497 | 644017c | 2017-08-10 17:49:40 +0300 | [diff] [blame] | 234 | const limitsList = LimitItemFactory.buildList(1); |
Avi Ziv | 61070c9 | 2017-07-26 17:37:57 +0300 | [diff] [blame] | 235 | deepFreeze(limitsList); |
az2497 | 644017c | 2017-08-10 17:49:40 +0300 | [diff] [blame] | 236 | |
Avi Ziv | 61070c9 | 2017-07-26 17:37:57 +0300 | [diff] [blame] | 237 | const store = storeCreator({ |
| 238 | licenseModel: { |
| 239 | entitlementPool: { |
| 240 | entitlementPoolEditor: { |
| 241 | limitsList |
| 242 | } |
| 243 | } |
| 244 | } |
| 245 | }); |
| 246 | deepFreeze(store.getState()); |
| 247 | |
| 248 | const licenseKeyGroup = LicenseKeyGroupStoreFactory.build(); |
| 249 | const expectedStore = cloneAndSet(store.getState(), 'licenseModel.licenseKeyGroup.licenseKeyGroupsEditor.limitsList', []); |
| 250 | |
| 251 | mockRest.addHandler('destroy', ({data, options, baseUrl}) => { |
| 252 | expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/license-key-groups/${licenseKeyGroup.id}/limits/${limitsList[0].id}`); |
| 253 | expect(data).toEqual(undefined); |
| 254 | expect(options).toEqual(undefined); |
| 255 | return { |
| 256 | results: { |
| 257 | returnCode: 'OK' |
| 258 | } |
| 259 | }; |
| 260 | }); |
| 261 | |
| 262 | mockRest.addHandler('fetch', ({data, options, baseUrl}) => { |
| 263 | expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/license-key-groups/${licenseKeyGroup.id}/limits`); |
| 264 | expect(data).toEqual(undefined); |
| 265 | expect(options).toEqual(undefined); |
| 266 | return {results: []}; |
| 267 | }); |
| 268 | |
| 269 | return LicenseKeyGroupsActionHelper.deleteLimit(store.dispatch, { |
| 270 | licenseModelId: LICENSE_MODEL_ID, |
| 271 | version, |
| 272 | licenseKeyGroup, |
| 273 | limit: limitsList[0] |
| 274 | }).then(() => { |
| 275 | expect(store.getState()).toEqual(expectedStore); |
| 276 | }); |
| 277 | }); |
| 278 | |
| 279 | it('Update Limit', () => { |
| 280 | |
az2497 | 644017c | 2017-08-10 17:49:40 +0300 | [diff] [blame] | 281 | const limitsList = LimitItemFactory.buildList(1); |
Avi Ziv | 61070c9 | 2017-07-26 17:37:57 +0300 | [diff] [blame] | 282 | deepFreeze(limitsList); |
| 283 | const licenseKeyGroup = LicenseKeyGroupStoreFactory.build(); |
| 284 | const store = storeCreator({ |
| 285 | licenseModel: { |
| 286 | licenseKeyGroup: { |
| 287 | licenseKeyGroupsEditor: { |
| 288 | limitsList |
| 289 | } |
| 290 | } |
| 291 | } |
| 292 | }); |
| 293 | |
| 294 | deepFreeze(store.getState()); |
| 295 | |
az2497 | 644017c | 2017-08-10 17:49:40 +0300 | [diff] [blame] | 296 | |
Avi Ziv | 61070c9 | 2017-07-26 17:37:57 +0300 | [diff] [blame] | 297 | const previousData = limitsList[0]; |
| 298 | deepFreeze(previousData); |
| 299 | const limitId = limitsList[0].id; |
Avi Ziv | 61070c9 | 2017-07-26 17:37:57 +0300 | [diff] [blame] | 300 | |
az2497 | 644017c | 2017-08-10 17:49:40 +0300 | [diff] [blame] | 301 | let updatedLimit = {...previousData, name: 'updatedLimit'}; |
| 302 | const updatedLimitForPut = {...updatedLimit, id: undefined}; |
| 303 | updatedLimit.metric = {choice: updatedLimit.metric, other: ''}; |
| 304 | updatedLimit.unit = {choice: updatedLimit.unit, other: ''}; |
| 305 | deepFreeze(updatedLimit); |
| 306 | |
| 307 | const expectedStore = cloneAndSet(store.getState(), 'licenseModel.licenseKeyGroup.licenseKeyGroupsEditor.limitsList', [updatedLimitForPut]); |
Avi Ziv | 61070c9 | 2017-07-26 17:37:57 +0300 | [diff] [blame] | 308 | |
| 309 | |
| 310 | mockRest.addHandler('put', ({data, options, baseUrl}) => { |
| 311 | expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/license-key-groups/${licenseKeyGroup.id}/limits/${limitId}`); |
| 312 | expect(data).toEqual(updatedLimitForPut); |
| 313 | expect(options).toEqual(undefined); |
| 314 | return {returnCode: 'OK'}; |
| 315 | }); |
| 316 | |
| 317 | mockRest.addHandler('fetch', ({data, options, baseUrl}) => { |
| 318 | expect(baseUrl).toEqual(`/onboarding-api/v1.0/vendor-license-models/${LICENSE_MODEL_ID}/versions/${version.id}/license-key-groups/${licenseKeyGroup.id}/limits`); |
| 319 | expect(data).toEqual(undefined); |
| 320 | expect(options).toEqual(undefined); |
az2497 | 644017c | 2017-08-10 17:49:40 +0300 | [diff] [blame] | 321 | return {results: [updatedLimitForPut]}; |
Avi Ziv | 61070c9 | 2017-07-26 17:37:57 +0300 | [diff] [blame] | 322 | }); |
| 323 | |
| 324 | return LicenseKeyGroupsActionHelper.submitLimit(store.dispatch, |
| 325 | { |
| 326 | licenseModelId: LICENSE_MODEL_ID, |
az2497 | 644017c | 2017-08-10 17:49:40 +0300 | [diff] [blame] | 327 | version, |
Avi Ziv | 61070c9 | 2017-07-26 17:37:57 +0300 | [diff] [blame] | 328 | licenseKeyGroup, |
| 329 | limit: updatedLimit |
| 330 | } |
| 331 | ).then(() => { |
| 332 | expect(store.getState()).toEqual(expectedStore); |
| 333 | }); |
| 334 | }); |
| 335 | |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 336 | }); |