mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-18 07:07:35 +01:00
Update requester to take in additional set parameters.
This commit is contained in:
@@ -16,12 +16,12 @@ const API_TEST_SERVER_PORT = 3003;
|
|||||||
// Sets up an abject that can make all REST requests
|
// Sets up an abject that can make all REST requests
|
||||||
// If a user is passed in, the uuid and api token of
|
// If a user is passed in, the uuid and api token of
|
||||||
// the user are used to make the requests
|
// the user are used to make the requests
|
||||||
export function requester(user={}) {
|
export function requester(user={}, additionalSets) {
|
||||||
return {
|
return {
|
||||||
get: _requestMaker(user, 'get'),
|
get: _requestMaker(user, 'get', additionalSets),
|
||||||
post: _requestMaker(user, 'post'),
|
post: _requestMaker(user, 'post', additionalSets),
|
||||||
put: _requestMaker(user, 'put'),
|
put: _requestMaker(user, 'put', additionalSets),
|
||||||
del: _requestMaker(user, 'del'),
|
del: _requestMaker(user, 'del', additionalSets),
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -207,18 +207,22 @@ export function resetHabiticaDB() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function _requestMaker(user, method) {
|
function _requestMaker(user, method, additionalSets) {
|
||||||
return (route, send, query) => {
|
return (route, send, query) => {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
let request = superagent[method](`http://localhost:${API_TEST_SERVER_PORT}/api/v2${route}`)
|
let request = superagent[method](`http://localhost:${API_TEST_SERVER_PORT}/api/v2${route}`)
|
||||||
.accept('application/json');
|
.accept('application/json');
|
||||||
|
|
||||||
if (user._id && user.apiToken) {
|
if (user && user._id && user.apiToken) {
|
||||||
request
|
request
|
||||||
.set('x-api-user', user._id)
|
.set('x-api-user', user._id)
|
||||||
.set('x-api-key', user.apiToken);
|
.set('x-api-key', user.apiToken);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (additionalSets) {
|
||||||
|
request.set(additionalSets);
|
||||||
|
}
|
||||||
|
|
||||||
request
|
request
|
||||||
.query(query)
|
.query(query)
|
||||||
.send(send)
|
.send(send)
|
||||||
|
|||||||
Reference in New Issue
Block a user