2018-03-28 22:04:59 +00:00
|
|
|
import {Before, When, Then} from "cucumber";
|
2017-12-04 21:39:55 +00:00
|
|
|
import seleniumWebdriver = require("selenium-webdriver");
|
|
|
|
import Assert = require("assert");
|
|
|
|
import Request = require("request-promise");
|
|
|
|
import Bluebird = require("bluebird");
|
|
|
|
|
2018-03-28 22:04:59 +00:00
|
|
|
When("I query {string}", function (url: string) {
|
|
|
|
const that = this;
|
|
|
|
return Request(url, { followRedirect: false })
|
|
|
|
.then(function(response) {
|
|
|
|
that.response = response;
|
|
|
|
})
|
|
|
|
.catch(function(err: Error) {
|
|
|
|
that.error = err;
|
|
|
|
})
|
|
|
|
});
|
2017-12-04 21:39:55 +00:00
|
|
|
|
2018-03-28 22:04:59 +00:00
|
|
|
Then("I get error code 401", function() {
|
|
|
|
const that = this;
|
|
|
|
return new Bluebird(function(resolve, reject) {
|
|
|
|
if(that.error && that.error.statusCode == 401) {
|
|
|
|
resolve();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if(that.response)
|
|
|
|
reject(new Error("No error thrown"));
|
|
|
|
else if(that.error.statusCode != 401)
|
2018-08-09 20:24:02 +00:00
|
|
|
reject(new Error(`Error code (${that.error.statusCode}) != 401`));
|
2018-03-28 22:04:59 +00:00
|
|
|
}
|
2017-12-04 21:39:55 +00:00
|
|
|
});
|
2018-03-28 22:04:59 +00:00
|
|
|
});
|
2017-12-04 21:39:55 +00:00
|
|
|
|
2018-03-28 22:04:59 +00:00
|
|
|
Then("I get redirected to {string}", function(url: string) {
|
|
|
|
const that = this;
|
|
|
|
return new Bluebird(function(resolve, reject) {
|
|
|
|
if(that.error && that.error.statusCode == 302
|
|
|
|
&& that.error.message.indexOf(url) > -1) {
|
|
|
|
resolve();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
reject(new Error("Not redirected"));
|
|
|
|
}
|
2017-12-04 21:39:55 +00:00
|
|
|
});
|
|
|
|
});
|