mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-17 14:47:53 +01:00
Adjust api helper
This commit is contained in:
@@ -10,8 +10,7 @@ describe('Status', () => {
|
|||||||
it('returns a status of up when server is up', (done) => {
|
it('returns a status of up when server is up', (done) => {
|
||||||
api.get('/status')
|
api.get('/status')
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
expect(res.code).to.eql(200);
|
expect(res.status).to.eql('up');
|
||||||
expect(res.body.status).to.eql('up');
|
|
||||||
done();
|
done();
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
import superagent from 'superagent';
|
import superagent from 'superagent';
|
||||||
|
|
||||||
|
const API_TEST_SERVER_PORT = 3003;
|
||||||
|
|
||||||
export function requester(user={}) {
|
export function requester(user={}) {
|
||||||
return {
|
return {
|
||||||
get: _requestMaker(user, 'get'),
|
get: _requestMaker(user, 'get'),
|
||||||
@@ -10,9 +12,9 @@ export function requester(user={}) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function _requestMaker(user, method) {
|
function _requestMaker(user, method) {
|
||||||
return (route, options={}) => {
|
return (route, send, query) => {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
let request = superagent[method](`http://localhost:3003/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._id && user.apiToken) {
|
||||||
@@ -22,17 +24,12 @@ function _requestMaker(user, method) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
request
|
request
|
||||||
.query(options.query)
|
.query(query)
|
||||||
.send(options.send)
|
.send(send)
|
||||||
.end((err, response) => {
|
.end((err, response) => {
|
||||||
if (err) { return reject(err); }
|
if (err) { return reject(err); }
|
||||||
|
|
||||||
let res = {
|
resolve(response.body);
|
||||||
code: response.statusCode,
|
|
||||||
body: response.body,
|
|
||||||
}
|
|
||||||
|
|
||||||
resolve(res);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user