blob: 314f86825b92ba48da62775e2c9c932bbca964d3 [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 {When} = require('cucumber');
17const _ = require('lodash');
18const util = require('./Utils.js');
19_.templateSettings.interpolate = /{([\s\S]+?)}/g;
20
21function getPath(path, context) {
22 let compiled = _.template(path);
23 return compiled(context);
24}
25/**
26 * @module Rest_Calls
27 * @description makes a GET request to the given path (path is appended after the "onboarding-api/v1.0" prefix)<br>
28 * @exampleFile Example_Rest_Calls.feature
29 * @step I want to get path {string}
30 **/
31When('I want to get path {string}', function(string) {
32 let path = getPath(string, this.context);
33 return util.request(this.context, 'GET', path);
34});
35
36/**
37 * @module Rest_Calls
38 * @description makes a DELETE request to the given path and appends the saved property (path is appended after the "onboarding-api/v1.0" prefix)<br>
39 * @exampleFile Example_Rest_Calls.feature
40 * @step I want to delete for path {string} with the value from saved property {string}
41 **/
42When('I want to delete for path {string} with the value from saved property {string}', function(string, string2) {
43 let path = getPath(string, this.context);
44 path += '/' + this.context[string2];
45 return util.request(this.context, 'DELETE', path);
46});
47
48
49/**
50 * @module Rest_Calls
51 * @description makes a PUT request to the given path and sends the input data from the context (path is appended after the "onboarding-api/v1.0" prefix)<br>
52 * @exampleFile Example_Rest_Calls.feature
53 * @step I want to update for path {string} with the input data from the context
54 **/
55When('I want to update for path {string} with the input data from the context', function(string) {
56 let path = getPath(string, this.context);
57 return util.request(this.context, 'PUT', path, this.context.inputData);
58});
59
60/**
61 * @module Rest_Calls
62 * @description makes a POST request to the given path and sends the input data from the context (path is appended after the "onboarding-api/v1.0" prefix)<br>
63 * @exampleFile Example_Rest_Calls.feature
64 * @step I want to create for path {string} with the input data from the context
65 **/
66When('I want to create for path {string} with the input data from the context', function(string) {
67 let path = getPath(string, this.context);
68 return util.request(this.context, 'POST', path, this.context.inputData);
69});