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 {When} = require('cucumber'); |
| 17 | const _ = require('lodash'); |
| 18 | const util = require('./Utils.js'); |
| 19 | _.templateSettings.interpolate = /{([\s\S]+?)}/g; |
| 20 | |
| 21 | function 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 | **/ |
| 31 | When('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 | **/ |
| 42 | When('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 | **/ |
| 55 | When('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 | **/ |
| 66 | When('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 | }); |