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'); |
ilanap | 061ca93 | 2019-08-04 10:16:33 +0300 | [diff] [blame] | 18 | const util = require('../cucumber-common/utils/Utils.js'); |
ilanap | 637206b | 2018-02-04 17:06:22 +0200 | [diff] [blame] | 19 | const _ = require('lodash'); |
| 20 | |
shrikantawachar | 3f55e8e | 2018-07-14 00:18:09 +0530 | [diff] [blame] | 21 | function getPath(path, context) { |
| 22 | let compiled = _.template(path); |
| 23 | return compiled(context); |
| 24 | } |
| 25 | |
ilanap | 637206b | 2018-02-04 17:06:22 +0200 | [diff] [blame] | 26 | /** |
| 27 | * @module Questionnaire |
| 28 | * @description Gets the questionnaire for the current item and saves it on the context |
| 29 | * @exampleFile Example_VSP.feature |
| 30 | * @step I want to get the questionnaire for this item |
| 31 | **/ |
| 32 | Then('I want to get the questionnaire for this item', function () { |
| 33 | let path = "/vendor-software-products/" + this.context.item.id + "/versions/" + this.context.item.versionId + "/questionnaire"; |
| 34 | return util.request(this.context, 'GET', path).then(result => { |
| 35 | this.context.qdata = JSON.parse(result.data.data); |
| 36 | this.context.qschema = result.data.schema; |
| 37 | this.context.qurl = path; |
| 38 | }); |
| 39 | }); |
| 40 | |
| 41 | /** |
| 42 | * @module Questionnaire |
| 43 | * @description Gets the questionnaire for the current item and component and saves it on the context |
| 44 | * @exampleFile Example_VSP.feature |
| 45 | * @step I want to get the questionnaire for this component |
| 46 | **/ |
| 47 | Then('I want to get the questionnaire for this component', function () { |
| 48 | let path = "/vendor-software-products/" + this.context.item.id + "/versions/" + this.context.item.versionId + "/components/" + this.context.componentId + "/questionnaire"; |
| 49 | return util.request(this.context, 'GET', path).then(result => { |
| 50 | this.context.qdata = JSON.parse(result.data.data); |
| 51 | this.context.qschema = result.data.schema; |
| 52 | this.context.qurl = path; |
| 53 | }); |
| 54 | }); |
| 55 | |
shrikantawachar | 3f55e8e | 2018-07-14 00:18:09 +0530 | [diff] [blame] | 56 | /** |
| 57 | * @module Questionnaire |
| 58 | * @description Gets the questionnaire from path and saves it on the context |
| 59 | * @exampleFile TestMD5.feature |
| 60 | * @step I want to get the questionnaire for this path {string} |
| 61 | **/ |
| 62 | Then('I want to get the questionnaire for this path {string}', function (string) { |
| 63 | let path = getPath(string, this.context); |
| 64 | return util.request(this.context, 'GET', path).then(result => { |
| 65 | this.context.qdata = JSON.parse(result.data.data); |
| 66 | this.context.qschema = result.data.schema; |
| 67 | this.context.qurl = path; |
| 68 | }); |
| 69 | }); |
ilanap | 637206b | 2018-02-04 17:06:22 +0200 | [diff] [blame] | 70 | |
| 71 | /** |
| 72 | * @module Questionnaire |
| 73 | * @description Updates the property for the saved questionnaire |
| 74 | * @exampleFile Example_VSP.feature |
| 75 | * @step I want to update this questionnaire with value {string} for path {string} |
| 76 | **/ |
| 77 | Then('I want to update this questionnaire with value {string} for property {string}', function (string, string2) { |
| 78 | _.set(this.context.qdata, string, string2); |
| 79 | }); |
| 80 | |
| 81 | /** |
| 82 | * @module Questionnaire |
| 83 | * @description Checks the questionnaire data on the context for the given value and property |
| 84 | * @exampleFile Example_VSP.feature |
| 85 | * @step I want to check this questionnaire has value {string} for property {string} |
| 86 | **/ |
| 87 | Then('I want to check this questionnaire has value {string} for property {string}', function (string, string2) { |
| 88 | assert.equal(_.get(this.context.qdata, string), string2); |
| 89 | }); |
| 90 | |
| 91 | /** |
| 92 | * @module Questionnaire |
| 93 | * @description Updates the the questionnaire data from the context to the same url that loaded it |
| 94 | * @exampleFile Example_VSP.feature |
| 95 | * @step I want to update this questionnaire |
| 96 | **/ |
| 97 | Then('I want to update this questionnaire', function () { |
| 98 | return util.request(this.context, 'PUT', this.context.qurl, this.context.qdata); |
sheetalm | 67e400c | 2018-06-12 17:32:56 +0530 | [diff] [blame] | 99 | }); |
| 100 | |
| 101 | /** |
| 102 | * @module Questionnaire |
| 103 | * @description Checks if the value of given property name in questionnaire data on the context is same as provided value |
| 104 | * @exampleFile ComponentData.feature |
| 105 | * @step I want to check value of {string} in the questionnaire data with value of property {string} |
| 106 | */ |
| 107 | Then('I want to check value of {string} in the questionnaire data with value of property {string}', function (string, |
| 108 | propertyName) { |
| 109 | expectedValue = _.get(this.context, propertyName) |
| 110 | data1 = this.context.qdata; |
| 111 | assert.equal(_.get(data1, string), expectedValue); |
| 112 | }); |
| 113 | |
| 114 | /** |
| 115 | * @module Questionnaire - Defined in Questionnaire module since this is used to fetch componentId for which questionnaire is to be fetched |
| 116 | * @description Finds and set componentId in context from list of components in responseData for component name in given property |
| 117 | * @exampleFile ComponentData.feature |
| 118 | * @step I want to set componentId for component name in property {string} |
| 119 | */ |
| 120 | Then('I want to set componentId for component name in property {string}', function (string) { |
| 121 | displayName = _.get(this.context, string); |
| 122 | results = this.context.responseData.results; |
| 123 | for (i=0; i<results.length; i++) { |
| 124 | if (results[i].displayName == displayName ){ |
| 125 | this.context.componentId = results[i].id; |
| 126 | return; |
| 127 | } |
| 128 | } |
ilanap | 637206b | 2018-02-04 17:06:22 +0200 | [diff] [blame] | 129 | }); |