blob: 4671f36db560c700dda918df527019c271f2600a [file] [log] [blame]
ilanap637206b2018-02-04 17:06:22 +02001/*
shrikantawachar9f330602018-02-12 16:57:59 +05302 * Copyright © 2016-2018 European Support Limited
ilanap637206b2018-02-04 17:06:22 +02003 *
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');
ilanap061ca932019-08-04 10:16:33 +030018const util = require('../cucumber-common/utils/Utils.js');
ilanap637206b2018-02-04 17:06:22 +020019_.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
shrikantawachar9f330602018-02-12 16:57:59 +053048/**
49 * @module Rest_Calls
50 * @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>
51 * @exampleFile Example_Rest_Calls.feature
52 * @step I want to delete for path {string} with the value from saved property {string}
53 **/
54When('I want to delete for path {string}', function (string) {
55 let path = getPath(string, this.context);
56 //path += '/' + this.context[string2];
57 return util.request(this.context, 'DELETE', path);
58});
ilanap637206b2018-02-04 17:06:22 +020059
60/**
61 * @module Rest_Calls
62 * @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>
63 * @exampleFile Example_Rest_Calls.feature
64 * @step I want to update for path {string} with the input data from the context
65 **/
66When('I want to update 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, 'PUT', path, this.context.inputData);
69});
70
71/**
72 * @module Rest_Calls
73 * @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>
74 * @exampleFile Example_Rest_Calls.feature
75 * @step I want to create for path {string} with the input data from the context
76 **/
77When('I want to create for path {string} with the input data from the context', function(string) {
78 let path = getPath(string, this.context);
79 return util.request(this.context, 'POST', path, this.context.inputData);
80});