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, Given} = require('cucumber'); |
| 17 | const assert = require('assert'); |
| 18 | const _ = require('lodash'); |
| 19 | const fs = require('fs'); |
| 20 | const util = require('./Utils.js'); |
| 21 | |
| 22 | /** |
| 23 | * @module InputData |
| 24 | * @description creates an ampty input data object |
| 25 | * @exampleFile Example_Rest_Calls.feature, Example_VLM.feature |
| 26 | * @step I want to create input data |
| 27 | **/ |
| 28 | When('I want to create input data', function () { |
| 29 | this.context.inputData = {}; |
| 30 | }); |
| 31 | |
| 32 | /** |
| 33 | * @module InputData |
| 34 | * @exampleFile Example_Heat.feature |
| 35 | * @description I want to set the input data to:<br> |
| 36 | * """<br> |
| 37 | * {jsonObject}<br> |
| 38 | * """<br> |
| 39 | * @step creates an input data element with the given json object |
| 40 | **/ |
| 41 | When('I want to set the input data to:', function (docString) { |
| 42 | this.context.inputData = JSON.parse(docString); |
| 43 | }); |
| 44 | |
| 45 | /** |
| 46 | * @module InputData |
| 47 | * @description creates an input data object from the json in the given file |
| 48 | * @exampleFile Example_Rest_Calls.feature |
| 49 | * @step I want to set the input data to file {string} |
| 50 | **/ |
| 51 | When('I want to set the input data to file {string}', function (string) { |
| 52 | this.context.inputData = util.getJSONFromFile(string); |
| 53 | }); |
| 54 | |
| 55 | /** |
| 56 | * @module InputData |
| 57 | * @description sets the property on the input data to the given value |
| 58 | * @exampleFile Example_Rest_Calls.feature, Example_VLM.feature |
| 59 | * @step I want to update the input property {string} with value {string} |
| 60 | **/ |
| 61 | Then('I want to update the input property {string} with value {string}', function(string, string2) { |
| 62 | _.set(this.context.inputData, string, string2); |
| 63 | }); |
| 64 | |
| 65 | /** |
| 66 | * @module InputData |
shrikantawachar | 3f55e8e | 2018-07-14 00:18:09 +0530 | [diff] [blame] | 67 | * @description sets the input property on the input data to the value from property |
| 68 | * @exampleFile TestMD5.feature |
| 69 | * @step I want to update the input property {string} from property {string} |
| 70 | **/ |
| 71 | Then('I want to update the input property {string} from property {string}', function(string, string2) { |
| 72 | let val = _.get(this.context, string2); |
| 73 | _.set(this.context.inputData, string, val); |
| 74 | }); |
| 75 | |
| 76 | /** |
| 77 | * @module InputData |
ilanap | 637206b | 2018-02-04 17:06:22 +0200 | [diff] [blame] | 78 | * @description removes a property from the input data object |
| 79 | * @exampleFile Example_Rest_Calls.feature |
| 80 | * @step I want to remove {string} from the input data |
| 81 | **/ |
| 82 | Then('I want to remove {string} from the input data', function(string) { |
| 83 | delete this.context.inputData[string]; |
| 84 | }); |
| 85 | |
| 86 | /** |
| 87 | * @module InputData |
| 88 | * @description sets the input data property to a random value |
| 89 | * @exampleFile Example_Rest_Calls.feature |
| 90 | * @step I want to update the input property {string} with a random value |
| 91 | **/ |
| 92 | Then('I want to update the input property {string} with a random value', function(string) { |
| 93 | _.set(this.context.inputData, string, util.random()); |
| 94 | }); |