blob: ce35a1c9ce9ca082610a259aa67c6115e9ef4e0d [file] [log] [blame]
ilanap637206b2018-02-04 17:06:22 +02001/*
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 */
16const {Then, When} = require('cucumber');
17const assert = require('assert');
18const util = require('./Utils.js');
19const _ = 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 **/
27Then('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 **/
42Then('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 **/
58Then('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 **/
68Then('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 **/
78Then('I want to update this questionnaire', function () {
79 return util.request(this.context, 'PUT', this.context.qurl, this.context.qdata);
80});