2 * Copyright © 2016-2017 European Support Limited
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 const {Then, When} = require('cucumber');
17 const assert = require('assert');
18 const util = require('../cucumber-common/utils/Utils.js');
19 const _ = require('lodash');
21 function getPath(path, context) {
22 let compiled = _.template(path);
23 return compiled(context);
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
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;
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
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;
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}
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;
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}
77 Then('I want to update this questionnaire with value {string} for property {string}', function (string, string2) {
78 _.set(this.context.qdata, string, string2);
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}
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);
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
97 Then('I want to update this questionnaire', function () {
98 return util.request(this.context, 'PUT', this.context.qurl, this.context.qdata);
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}
107 Then('I want to check value of {string} in the questionnaire data with value of property {string}', function (string,
109 expectedValue = _.get(this.context, propertyName)
110 data1 = this.context.qdata;
111 assert.equal(_.get(data1, string), expectedValue);
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}
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;