blob: 7fee19a2c20ca9d7201358ccd09c9bbad03ad6e5 [file] [log] [blame]
ayalaben3fb47c42018-06-24 10:42:43 +03001/*
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, Given} = require('cucumber');
17const assert = require('assert');
18const _ = require('lodash');
19const fs = require('fs');
20const util = require('./Utils.js');
21
ayalaben688de372018-08-23 13:38:49 +030022function getPath(path, context) {
23 let compiled = _.template(path);
24 return compiled(context);
25}
26
ayalaben3fb47c42018-06-24 10:42:43 +030027/**
28 * @module InputData
29 * @description creates an ampty input data object
30 * @exampleFile Example_Rest_Calls.feature, Example_VLM.feature
31 * @step I want to create input data
32 **/
33When('I want to create input data', function () {
34 this.context.inputData = {};
35});
36
37/**
38 * @module InputData
39 * @exampleFile Example_Heat.feature
40 * @description I want to set the input data to:<br>
41 * """<br>
42 * {jsonObject}<br>
43 * """<br>
44 * @step creates an input data element with the given json object
45 **/
46When('I want to set the input data to:', function (docString) {
47 this.context.inputData = JSON.parse(docString);
48});
49
50/**
51 * @module InputData
52 * @description creates an input data object from the json in the given file
53 * @exampleFile Example_Rest_Calls.feature
54 * @step I want to set the input data to file {string}
55 **/
56When('I want to set the input data to file {string}', function (string) {
57 this.context.inputData = util.getJSONFromFile(string);
58});
59
60/**
61 * @module InputData
62 * @description sets the property on the input data to the given value
63 * @exampleFile Example_Rest_Calls.feature, Example_VLM.feature
64 * @step I want to update the input property {string} with value {string}
65 **/
66Then('I want to update the input property {string} with value {string}', function(string, string2) {
ayalaben688de372018-08-23 13:38:49 +030067 let value = getPath(string2, this.context);
68 _.set(this.context.inputData, string, value);
ayalaben3fb47c42018-06-24 10:42:43 +030069});
70
71/**
72 * @module InputData
talig8f91bb12018-07-23 10:15:59 +030073 * @description sets the property on the input data to the value of the given property
74 * @exampleFile WorkflowList.feature
75 * @step I want to update the input property {string} with value of property {string}
76 **/
77Then('I want to update the input property {string} with value of property {string}', function(string, string2) {
78 _.set(this.context.inputData, string, _.get(this.context, string2));
79});
80
81/**
82 * @module InputData
ayalaben3fb47c42018-06-24 10:42:43 +030083 * @description removes a property from the input data object
84 * @exampleFile Example_Rest_Calls.feature
85 * @step I want to remove {string} from the input data
86 **/
87Then('I want to remove {string} from the input data', function(string) {
88 delete this.context.inputData[string];
89});
90
91/**
92 * @module InputData
93 * @description sets the input data property to a random value
94 * @exampleFile Example_Rest_Calls.feature
95 * @step I want to update the input property {string} with a random value
96 **/
97Then('I want to update the input property {string} with a random value', function(string) {
98 _.set(this.context.inputData, string, util.random());
99});