mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-18 07:07:35 +01:00
fix tests that require session authentication
This commit is contained in:
@@ -22,6 +22,10 @@ requester.setApiVersion = (version) => {
|
||||
apiVersion = version;
|
||||
};
|
||||
|
||||
// save the last cookie so that it's resent with every request
|
||||
// should be safe since every time a user is generated this will be overwritten
|
||||
let cookie;
|
||||
|
||||
function _requestMaker (user, method, additionalSets) {
|
||||
if (!apiVersion) throw new Error('apiVersion not set');
|
||||
|
||||
@@ -36,6 +40,11 @@ function _requestMaker (user, method, additionalSets) {
|
||||
.set('x-api-key', user.apiToken);
|
||||
}
|
||||
|
||||
// if we previously saved a cookie, send it along the request
|
||||
if (cookie) {
|
||||
request.set('Cookie', cookie);
|
||||
}
|
||||
|
||||
if (additionalSets) {
|
||||
request.set(additionalSets);
|
||||
}
|
||||
@@ -52,6 +61,13 @@ function _requestMaker (user, method, additionalSets) {
|
||||
reject(parsedError);
|
||||
}
|
||||
|
||||
// if any cookies was sent, save it for the next request
|
||||
if (response.headers['set-cookie']) {
|
||||
cookie = response.headers['set-cookie'].map(cookieString => {
|
||||
return cookieString.split(';')[0];
|
||||
}).join('; ');
|
||||
}
|
||||
|
||||
let contentType = response.headers['content-type'] || '';
|
||||
resolve(contentType.indexOf('json') !== -1 ? response.body : response.text);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user