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 { setWorldConstructor } = require('cucumber'); |
| 17 | const config = require('../config.json'); |
| 18 | var {setDefaultTimeout} = require('cucumber'); |
| 19 | |
| 20 | /** |
| 21 | * @module Context |
| 22 | * @description Context that is used per feature file and can be accessed as 'this.context' in all steps.<Br> |
| 23 | *<Br> |
| 24 | * Contains the following items:<br> |
| 25 | * <li>this.context.server <ul>REST server and onboarding prefix including version. set either in configuration file or from the command line or SERVER environment variable</ul> |
| 26 | * <li>this.context.vlm <ul>When a VLM has been created, this has the an id and versionId set to the correct IDs.</ul> |
| 27 | * <li>this.context.vsp <ul>When a VSP has been created, this has the an id and versionId and componentId set to the correct IDs.</ul> |
| 28 | * <li>this.context.item <ul>When a VLM or VSP has been created, this has the an id and versionId set to the correct IDs.</ul> |
| 29 | * <li>this.context <ul>Object with properties that were saved in the steps.</ul> |
| 30 | * <li>this.context.inputdata <ul><b>Automatically updated with the last responseData from the Rest call</b><br>Object with properties that were prepares in the steps.</ul> |
| 31 | * <li>this.context.responseData <ul>Response from the last REST call.</ul> |
| 32 | **/ |
| 33 | class CustomWorld { |
| 34 | constructor(options) { |
| 35 | this.context = {} |
| 36 | if (options.parameters && options.parameters.server) { |
| 37 | this.context.server = options.parameters.server; |
| 38 | } else if (process.env.SERVER) { |
| 39 | this.context.server = process.env.SERVER; |
| 40 | } else { |
| 41 | this.context.server = config.server; |
| 42 | } |
ilanap | 6c87274 | 2018-02-18 11:02:03 +0200 | [diff] [blame] | 43 | this.context.server = (config.protocol + '://' + this.context.server + ':' + config.port); |
ilanap | 637206b | 2018-02-04 17:06:22 +0200 | [diff] [blame] | 44 | |
| 45 | |
| 46 | this.context.headers = {}; |
| 47 | this.context.headers['USER_ID'] = 'cs0008'; |
| 48 | |
| 49 | this.context.vlm = {id: null, versionId: null}; |
| 50 | this.context.vsp = {id: null, versionId: null}; |
| 51 | this.context.item = {id: null, versionId: null, componentId: null}; |
| 52 | |
| 53 | this.context.shouldFail = false; |
| 54 | this.context.errorCode = null; |
| 55 | this.context.inputData = null; |
| 56 | this.context.responseData = null; |
| 57 | |
ilanap | 6c87274 | 2018-02-18 11:02:03 +0200 | [diff] [blame] | 58 | this.context.prefix = config.prefix; |
| 59 | |
ilanap | 637206b | 2018-02-04 17:06:22 +0200 | [diff] [blame] | 60 | this.setServer = function(server) { |
ilanap | 6c87274 | 2018-02-18 11:02:03 +0200 | [diff] [blame] | 61 | this.context.server = (config.protocol + '://' + this.context.server + ':' + config.port); |
ilanap | 637206b | 2018-02-04 17:06:22 +0200 | [diff] [blame] | 62 | } |
| 63 | |
| 64 | setDefaultTimeout(60 * 1000); |
| 65 | } |
| 66 | } |
| 67 | |
| 68 | |
| 69 | setWorldConstructor(CustomWorld) |