Skip to content

Commit

Permalink
upd: request header names are evaluated
Browse files Browse the repository at this point in the history
add: assertResponseDoesNotContainHeader, setAccessToken, unsetAccessToken methods
fix: setBearerToken can add the Authorization header when undefined
  • Loading branch information
theTestTube authored and seymen committed Dec 8, 2016
1 parent 8334b84 commit 90283c8
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions source/apickli/apickli.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ var dom = require('xmldom').DOMParser;
var fs = require('fs');
var jsonSchemaValidator = require('is-my-json-valid');

var accessToken;
var accessToken = undefined;
var globalVariables = {};

var ATTRIBUTE = 2;
Expand Down Expand Up @@ -244,6 +244,12 @@ Apickli.prototype.assertResponseCode = function(responseCode) {
return getAssertionResult(success, responseCode, realResponseCode, this);
};

Apickli.prototype.assertResponseDoesNotContainHeader = function(header, callback) {
header = this.replaceVariables(header);
var success = typeof this.getResponseObject().headers[header.toLowerCase()] == 'undefined';
return getAssertionResult(success, true, false, this);
};

Apickli.prototype.assertResponseContainsHeader = function(header, callback) {
header = this.replaceVariables(header);
var success = typeof this.getResponseObject().headers[header.toLowerCase()] != 'undefined';
Expand Down Expand Up @@ -308,13 +314,24 @@ Apickli.prototype.evaluatePathInResponseBody = function(path) {
return evaluatePath(path, this.getResponseObject().body);
};

Apickli.prototype.setAccessToken = function(token) {
accessToken = token;
};

Apickli.prototype.unsetAccessToken = function() {
accessToken = undefined;
};

Apickli.prototype.setAccessTokenFromResponseBodyPath = function(path) {
path = this.replaceVariables(path);
accessToken = evaluatePath(path, this.getResponseObject().body);
this.setAccessToken(evaluatePath(path, this.getResponseObject().body));
};

Apickli.prototype.setBearerToken = function() {
this.addRequestHeader('Authorization', 'Bearer ' + accessToken);
if (accessToken)
return this.addRequestHeader('Authorization', 'Bearer ' + accessToken);
else
return false;
};

Apickli.prototype.storeValueInScenarioScope = function(variableName, value) {
Expand Down

0 comments on commit 90283c8

Please sign in to comment.