aboutsummaryrefslogtreecommitdiffstats
path: root/cucumber-js-test-apis-ci/cucumber-common
diff options
context:
space:
mode:
authorilanap <ilanap@amdocs.com>2019-08-05 14:10:34 +0300
committerAvi Gaffa <avi.gaffa@amdocs.com>2019-08-06 10:05:28 +0000
commit5f063227364206daacb507e7ec8de3adbdaac28d (patch)
treef585b09a7449e9de9a669c1b52faf6ab4a4f0fba /cucumber-js-test-apis-ci/cucumber-common
parent031db8630dda9706e22aa3bbdf0f2dfba33fb86e (diff)
Minor feature by checking for status code in addition to error code
Issue-ID: SDC-2483 Signed-off-by: ilanap <ilanap@amdocs.com> Change-Id: Ib26ef4f303f4b996ff0511344507692cdda69e04
Diffstat (limited to 'cucumber-js-test-apis-ci/cucumber-common')
-rw-r--r--cucumber-js-test-apis-ci/cucumber-common/utils/Utils.js51
1 files changed, 30 insertions, 21 deletions
diff --git a/cucumber-js-test-apis-ci/cucumber-common/utils/Utils.js b/cucumber-js-test-apis-ci/cucumber-common/utils/Utils.js
index 22ee775080..ed16d8bbf4 100644
--- a/cucumber-js-test-apis-ci/cucumber-common/utils/Utils.js
+++ b/cucumber-js-test-apis-ci/cucumber-common/utils/Utils.js
@@ -76,6 +76,7 @@ function _requestRest(context, method, path, data, type) {
return _request(context, method, path, options);
}
+
function _request(context, method, path, options) {
console.log('--> Calling REST ' + options.method +' url: ' + options.url);
let inputData = options.json;
@@ -94,36 +95,44 @@ function _request(context, method, path, options) {
return needle(method, options.url, inputData, needleOptions)
.then(function(result) {
context.inputData = null;
- let isExpected = (context.shouldFail) ? (result.statusCode != 200 && result.statusCode != 201) : (result.statusCode == 200 || result.statusCode == 201);
+ let successResult = result.statusCode >= 200 && result.statusCode < 300;
+ let isExpected = context.shouldFail ? !successResult : successResult;
data = result.body;
if (!isExpected) {
console.log('Did not get expected response code');
throw 'Status Code was ' + result.statusCode ;
}
- if (context.shouldFail && context.errorCode) {
- if (typeof data === 'string' && data) {
- data = JSON.parse(data);
- }
- let errorCode = data.errorCode;
- let contextErrorCode = context.errorCode;
- context.errorCode = null;
- if (errorCode !== contextErrorCode) {
- throw 'Error Code was ' + errorCode + ' instead of ' + contextErrorCode;
- }
- }
- if (context.shouldFail && context.errorMessage) {
- if (typeof data === 'string' && data) {
- data = JSON.parse(data);
- }
- let errorMessage = data.message;
- let contextErrorMessage = context.errorMessage;
- context.errorMessage = null;
- if (errorMessage !== contextErrorMessage) {
- throw 'Error Message was ' + errorMessage + ' instead of ' + contextErrorMessage;
+ if (context.statusCode) {
+ let expectedStatusCode = context.statusCode;
+ context.statusCode = null;
+ if (result.statusCode !== expectedStatusCode) {
+ throw 'Response Status Code was ' + result.statusCode + ' instead of ' + expectedStatusCode;
}
}
if (context.shouldFail) {
context.shouldFail = false;
+ if (context.errorCode) {
+ if (typeof data === 'string' && data) {
+ data = JSON.parse(data);
+ }
+ let contextErrorCode = context.errorCode;
+ let errorCode = data.errorCode;
+ context.errorCode = null;
+ if (errorCode !== contextErrorCode) {
+ throw 'Error Code was ' + errorCode + ' instead of ' + contextErrorCode;
+ }
+ }
+ if (context.errorMessage) {
+ if (typeof data === 'string' && data) {
+ data = JSON.parse(data);
+ }
+ let errorMessage = data.message;
+ let contextErrorMessage = context.errorMessage;
+ context.errorMessage = null;
+ if (errorMessage !== contextErrorMessage) {
+ throw 'Error Message was ' + errorMessage + ' instead of ' + contextErrorMessage;
+ }
+ }
return({statusCode: result.statusCode, data: {}});
}