ilanap | 637206b | 2018-02-04 17:06:22 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright © 2016-2017 European Support Limited |
| 3 | * |
| 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 |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | const {Then, When} = require('cucumber'); |
| 17 | const assert = require('assert'); |
| 18 | const util = require('./Utils.js'); |
| 19 | const _ = require('lodash'); |
| 20 | |
| 21 | |
| 22 | /** |
| 23 | * @module VSP |
| 24 | * @description Creates a new VSP with a random name and saves the id and versionId on the context item object and the context vsp object<br> |
| 25 | * Input data will be taken from the 'resources/json/createVSP.json' file. |
| 26 | * Vendor id and name are taken from the vlm on the context (requires a VLM to be created first). |
| 27 | * @exampleFile Example_VSP.feature |
| 28 | * @step I want to create a VSP with onboarding type {string} |
| 29 | **/ |
| 30 | When('I want to create a VSP with onboarding type {string}', function(string) { |
| 31 | let inputData = util.getJSONFromFile('resources/json/createVSP.json'); |
| 32 | inputData.onboardingMethod = string; |
| 33 | inputData.vendorName = this.context.vlm.name; |
| 34 | inputData.vendorId = this.context.vlm.id; |
| 35 | inputData.name = util.random(); |
| 36 | let path = '/vendor-software-products'; |
| 37 | return util.request(this.context, 'POST', path, inputData).then(result => { |
| 38 | this.context.item = {id : result.data.itemId, versionId: result.data.version.id}; |
| 39 | this.context.vsp = {id : result.data.itemId, versionId: result.data.version.id}; |
| 40 | }); |
| 41 | }); |
| 42 | |
| 43 | /** |
| 44 | * @module VSP |
| 45 | * @description Creates a new VSP with the 'NetowrkPackage' onboarding type and with a random name and saves the id and versionId on the context item object and the context vsp object<br> |
| 46 | * Input data will be taken from the 'resources/json/createVSP.json' file. |
| 47 | * Vendor id and name are taken from the vlm on the context (requires a VLM to be created first). |
| 48 | * @exampleFile Example_VSP.feature |
| 49 | * @step I want to create a VSP with onboarding type {string} |
| 50 | **/ |
shrikantawachar | 3f55e8e | 2018-07-14 00:18:09 +0530 | [diff] [blame] | 51 | When('I want to create a VSP with onboarding type Manual', function() { |
| 52 | let inputData = util.getJSONFromFile('resources/json/createManualVSP.json'); |
ilanap | 637206b | 2018-02-04 17:06:22 +0200 | [diff] [blame] | 53 | inputData.vendorName = this.context.vlm.name; |
| 54 | inputData.vendorId = this.context.vlm.id; |
| 55 | inputData.name = util.random(); |
shrikantawachar | 3f55e8e | 2018-07-14 00:18:09 +0530 | [diff] [blame] | 56 | inputData.licensingVersion = this.context.licensingVersion; |
| 57 | inputData.licensingData.licenseAgreement = this.context.licenseAgreement; |
| 58 | inputData.licensingData.featureGroups[0] = this.context.featureGroupId; |
ilanap | 637206b | 2018-02-04 17:06:22 +0200 | [diff] [blame] | 59 | let path = '/vendor-software-products'; |
| 60 | return util.request(this.context, 'POST', path, inputData).then(result => { |
| 61 | this.context.item = {id : result.data.itemId, versionId: result.data.version.id}; |
| 62 | this.context.vsp = {id : result.data.itemId, versionId: result.data.version.id}; |
| 63 | }); |
| 64 | }); |
| 65 | |
| 66 | |
| 67 | /** |
| 68 | * @module VSP |
| 69 | * @exampleFile Example_VSP.feature |
| 70 | * @step I want to submit this VSP |
| 71 | **/ |
| 72 | Then('I want to submit this VSP', function () { |
| 73 | let path = '/vendor-software-products/' + this.context.item.id + '/versions/' + this.context.item.versionId + '/actions'; |
| 74 | let inputData = {action: 'Submit'}; |
| 75 | return util.request(this.context, 'PUT', path, inputData); |
| 76 | }); |
| 77 | |
| 78 | /** |
| 79 | * @module VSP |
| 80 | * @exampleFile Example_VSP.feature |
| 81 | * @step I want to package this VSP |
| 82 | **/ |
| 83 | Then('I want to package this VSP', function () { |
| 84 | let path = '/vendor-software-products/' + this.context.item.id + '/versions/' + this.context.item.versionId + '/actions'; |
| 85 | let inputData = {action: 'Create_Package'}; |
| 86 | return util.request(this.context, 'PUT', path, inputData); |
| 87 | }); |
| 88 | |
| 89 | /** |
| 90 | * @module VSP |
| 91 | * @description Adds a component to the current item |
| 92 | * @exampleFile Example_VSP.feature |
| 93 | * @step I want to add a component |
| 94 | **/ |
| 95 | Then('I want to add a component', function () { |
| 96 | let path = '/vendor-software-products/' + this.context.item.id + '/versions/' + this.context.item.versionId + '/components'; |
| 97 | let inputData = {name: 'Cucumber Name', displayName: 'Cucumber', description: 'Cucumber Description'}; |
| 98 | return util.request(this.context, 'POST', path, inputData).then(result => { |
| 99 | this.context.componentId = result.data.vfcId; |
| 100 | }); |
| 101 | }); |
| 102 | |
| 103 | |
| 104 | /** |
| 105 | * @module VSP |
| 106 | * @description Downloads the packaged file for this component to the given path |
| 107 | * @exampleFile Example_VSP.feature |
| 108 | * @step I want to get the package for this Item to path {string} |
| 109 | **/ |
| 110 | When('I want to get the package for this Item to path {string}', function (string, callback) { |
| 111 | let path = '/vendor-software-products/packages/' + this.context.item.id; |
| 112 | return [util.download(this.context, path, string, callback)]; |
ayalaben | aad2781 | 2018-02-18 10:03:22 +0200 | [diff] [blame] | 113 | }); |
| 114 | |
| 115 | |
| 116 | /** |
| 117 | * @module VSP |
| 118 | * @exampleFile DeleteVSPDraft.feature |
| 119 | * @step I want to delete this VSP |
| 120 | **/ |
| 121 | Then('I want to delete this VSP', function() { |
| 122 | let path = '/vendor-software-products/' + this.context.item.id ; |
| 123 | return util.request(this.context, 'DELETE', path); |
ayalaben | 705fc2b | 2018-03-15 15:59:25 +0200 | [diff] [blame] | 124 | }); |
| 125 | |
| 126 | /** |
| 127 | * @module VSP |
| 128 | * @exampleFile ArchiveItem.feature |
| 129 | * @step I want to list Archived VSPs |
| 130 | **/ |
| 131 | Then('I want to list Archived VSPs', function() { |
| 132 | let path = '/vendor-software-products/?Status=ARCHIVED'; |
| 133 | return util.request(this.context, 'GET', path); |
| 134 | }); |
| 135 | |
| 136 | /** |
| 137 | * @module VSP |
| 138 | * @exampleFile ArchiveItem.feature |
| 139 | * @step I want to list Active VSPs |
| 140 | **/ |
| 141 | Then('I want to list Active VSPs', function() { |
| 142 | let path = '/vendor-software-products'; |
| 143 | return util.request(this.context, 'GET', path); |
| 144 | }); |
| 145 | |
| 146 | |
| 147 | /** |
| 148 | * @module VSP |
| 149 | * @exampleFile FilterArchivedVSPpackage.feature |
| 150 | * @step I want to list Archived VSPs packages |
| 151 | **/ |
| 152 | Then('I want to list Archived VSPs packages', function() { |
| 153 | let path = '/vendor-software-products/packages?Status=ARCHIVED'; |
| 154 | return util.request(this.context, 'GET', path); |
| 155 | }); |
| 156 | |
| 157 | /** |
| 158 | * @module VSP |
| 159 | * @exampleFile FilterArchivedVSPpackage.feature |
| 160 | * @step I want to list Active VSPs packages |
| 161 | **/ |
| 162 | Then('I want to list Active VSPs packages', function() { |
| 163 | let path = '/vendor-software-products/packages'; |
| 164 | return util.request(this.context, 'GET', path); |
| 165 | |
| 166 | }); |
| 167 | |
| 168 | /** |
| 169 | * @module VSP |
| 170 | * @exampleFile FilterArchivedVSPpackage.feature |
| 171 | * @step I want to check that VSP package exits in response |
| 172 | **/ |
| 173 | Then('I want to check that VSP package exits in response', function() { |
| 174 | |
| 175 | const packages = this.context.responseData.results; |
| 176 | const id = this.context.item.id; |
| 177 | var testResult = false; |
| 178 | |
| 179 | for(var i=0; i< packages.length; i++){ |
| 180 | if (id == packages[i].packageId){ |
| 181 | testResult = true; |
| 182 | } |
| 183 | } |
| 184 | assert.equal(testResult,true); |
ilanap | 637206b | 2018-02-04 17:06:22 +0200 | [diff] [blame] | 185 | }); |