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