blob: c21d18f146726d872c9aeba0cfa60fa5f91d577b [file] [log] [blame]
Michael Landoefa037d2017-02-19 12:57:33 +02001/*-
2 * ============LICENSE_START=======================================================
3 * SDC
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
19 */
20
21import {expect} from 'chai';
22import deepFreeze from 'deep-freeze';
23import mockRest from 'test-utils/MockRest.js';
24import {cloneAndSet} from 'test-utils/Util.js';
25import {storeCreator} from 'sdc-app/AppStore.js';
26import LicenseModelCreationActionHelper from 'sdc-app/onboarding/licenseModel/creation/LicenseModelCreationActionHelper.js';
27
28describe('License Model Module Tests', function () {
29 it('Add License Model', () => {
30 const store = storeCreator();
31 deepFreeze(store.getState());
32
33 const licenseModelPostRequest = deepFreeze({
34 vendorName: 'vlm1',
35 description: 'string',
36 iconRef: 'icon'
37 });
38
39 const licenseModelToAdd = deepFreeze({
40 ...licenseModelPostRequest
41 });
42
43 const licenseModelIdFromResponse = 'ADDED_ID';
44 const licenseModelAfterAdd = deepFreeze({
45 ...licenseModelToAdd,
46 id: licenseModelIdFromResponse
47 });
48
49 const expectedStore = cloneAndSet(store.getState(), 'licenseModelList', [licenseModelAfterAdd]);
50
51 mockRest.addHandler('create', ({options, data, baseUrl}) => {
52 expect(baseUrl).to.equal('/onboarding-api/v1.0/vendor-license-models/');
53 expect(data).to.deep.equal(licenseModelPostRequest);
54 expect(options).to.equal(undefined);
55 return {
56 value: licenseModelIdFromResponse
57 };
58 });
59
60 return LicenseModelCreationActionHelper.createLicenseModel(store.dispatch, {
61 licenseModel: licenseModelToAdd
62 }).then(() => {
63 expect(store.getState()).to.deep.equal(expectedStore);
64 });
65 });
66});