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'; |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 24 | |
| 25 | describe('License Key Groups Module Tests', function () { |
| 26 | |
| 27 | const LICENSE_MODEL_ID = '555'; |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame^] | 28 | const version = VersionControllerUtilsFactory.build().version; |
| 29 | |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 30 | it('Load License Key Group', () => { |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame^] | 31 | |
| 32 | const licenseKeyGroupsList = buildListFromFactory(LicenseKeyGroupStoreFactory); |
| 33 | |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 34 | 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}) => { |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame^] | 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); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 44 | return {results: licenseKeyGroupsList}; |
| 45 | }); |
| 46 | |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame^] | 47 | return LicenseKeyGroupsActionHelper.fetchLicenseKeyGroupsList(store.dispatch, {licenseModelId: LICENSE_MODEL_ID, version}).then(() => { |
| 48 | expect(store.getState()).toEqual(expectedStore); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 49 | }); |
| 50 | }); |
| 51 | |
| 52 | it('Delete License Key Group', () => { |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame^] | 53 | |
| 54 | const licenseKeyGroupsList = buildListFromFactory(LicenseKeyGroupStoreFactory, 1); |
| 55 | |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 56 | deepFreeze(licenseKeyGroupsList); |
| 57 | const store = storeCreator({ |
| 58 | licenseModel: { |
| 59 | licenseKeyGroup: { |
| 60 | licenseKeyGroupsList |
| 61 | } |
| 62 | } |
| 63 | }); |
| 64 | deepFreeze(store.getState()); |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame^] | 65 | const toBeDeletedLicenseKeyGroupId = licenseKeyGroupsList[0].id; |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 66 | const expectedStore = cloneAndSet(store.getState(), 'licenseModel.licenseKeyGroup.licenseKeyGroupsList', []); |
| 67 | |
| 68 | mockRest.addHandler('destroy', ({data, options, baseUrl}) => { |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame^] | 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); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 72 | }); |
| 73 | |
| 74 | return LicenseKeyGroupsActionHelper.deleteLicenseKeyGroup(store.dispatch, { |
| 75 | licenseKeyGroupId: toBeDeletedLicenseKeyGroupId, |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame^] | 76 | licenseModelId: LICENSE_MODEL_ID, |
| 77 | version |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 78 | }).then(() => { |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame^] | 79 | expect(store.getState()).toEqual(expectedStore); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 80 | }); |
| 81 | }); |
| 82 | |
| 83 | it('Add License Key Group', () => { |
| 84 | |
| 85 | const store = storeCreator(); |
| 86 | deepFreeze(store.getState()); |
| 87 | |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame^] | 88 | const LicenseKeyGroupPost = LicenseKeyGroupPostFactory.build(); |
| 89 | deepFreeze(LicenseKeyGroupPost); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 90 | |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame^] | 91 | const LicenseKeyGroupStore = LicenseKeyGroupStoreFactory.build(); |
| 92 | deepFreeze(LicenseKeyGroupStore); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 93 | |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame^] | 94 | const expectedStore = cloneAndSet(store.getState(), 'licenseModel.licenseKeyGroup.licenseKeyGroupsList', [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 | 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 Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 100 | return { |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame^] | 101 | value: LicenseKeyGroupStore.id |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 102 | }; |
| 103 | }); |
| 104 | |
| 105 | return LicenseKeyGroupsActionHelper.saveLicenseKeyGroup(store.dispatch, { |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame^] | 106 | licenseKeyGroup: LicenseKeyGroupPost, |
| 107 | licenseModelId: LICENSE_MODEL_ID, |
| 108 | version |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 109 | }).then(() => { |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame^] | 110 | expect(store.getState()).toEqual(expectedStore); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 111 | }); |
| 112 | }); |
| 113 | |
| 114 | it('Update License Key Group', () => { |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame^] | 115 | const licenseKeyGroupsList = buildListFromFactory(LicenseKeyGroupStoreFactory, 1); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 116 | 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 | |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame^] | 128 | const licenseKeyGroupUpdatedData = LicenseKeyGroupPostFactory.build({ |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 129 | name: 'lsk1_UPDATE', |
| 130 | description: 'string_UPDATE', |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame^] | 131 | id: toBeUpdatedLicenseKeyGroupId |
| 132 | }); |
| 133 | deepFreeze(licenseKeyGroupUpdatedData); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 134 | |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame^] | 135 | const licenseKeyGroupPutRequest = LicenseKeyGroupPostFactory.build({ |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 136 | name: 'lsk1_UPDATE', |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame^] | 137 | description: 'string_UPDATE' |
| 138 | }); |
| 139 | |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 140 | deepFreeze(licenseKeyGroupPutRequest); |
| 141 | |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame^] | 142 | const expectedStore = cloneAndSet(store.getState(), 'licenseModel.licenseKeyGroup.licenseKeyGroupsList', [licenseKeyGroupUpdatedData]); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 143 | |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame^] | 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); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 148 | }); |
| 149 | |
| 150 | return LicenseKeyGroupsActionHelper.saveLicenseKeyGroup(store.dispatch, { |
| 151 | previousLicenseKeyGroup: previousLicenseKeyGroupData, |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame^] | 152 | licenseKeyGroup: licenseKeyGroupUpdatedData, |
| 153 | licenseModelId: LICENSE_MODEL_ID, |
| 154 | version |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 155 | }).then(() => { |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame^] | 156 | expect(store.getState()).toEqual(expectedStore); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 157 | }); |
| 158 | }); |
| 159 | |
| 160 | }); |