mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-17 14:47:53 +01:00
Set up new api test structure
This commit is contained in:
@@ -284,7 +284,8 @@ gulp.task('test:e2e:safe', ['test:prepare'], (cb) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
gulp.task('test:api', ['test:startServer', 'test:prepare:mongo'], (done) => {
|
gulp.task('test:api', ['test:startServer', 'test:prepare:mongo'], (done) => {
|
||||||
let mocha = new Mocha();
|
require('../test/helpers/globals.helper');
|
||||||
|
let mocha = new Mocha({reporter: 'spec'});
|
||||||
let tests = glob('./test/api/**/*.js');
|
let tests = glob('./test/api/**/*.js');
|
||||||
|
|
||||||
tests.forEach((test) => {
|
tests.forEach((test) => {
|
||||||
|
|||||||
21
test/api/get-status.js
Normal file
21
test/api/get-status.js
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
import {requester} from '../helpers/api.helper';
|
||||||
|
|
||||||
|
describe('Status', () => {
|
||||||
|
let api;
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
api = requester();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('returns a status of up when server is up', (done) => {
|
||||||
|
api.get('/status')
|
||||||
|
.then((res) => {
|
||||||
|
expect(res.code).to.eql(200);
|
||||||
|
expect(res.body.status).to.eql('up');
|
||||||
|
done();
|
||||||
|
})
|
||||||
|
.catch((err) => {
|
||||||
|
done(err);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -1 +1,39 @@
|
|||||||
require('./globals.helper');
|
import superagent from 'superagent';
|
||||||
|
|
||||||
|
export function requester(user={}) {
|
||||||
|
return {
|
||||||
|
get: _requestMaker(user, 'get'),
|
||||||
|
post: _requestMaker(user, 'post'),
|
||||||
|
put: _requestMaker(user, 'put'),
|
||||||
|
del: _requestMaker(user, 'del'),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function _requestMaker(user, method) {
|
||||||
|
return (route, options={}) => {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
let request = superagent[method](`http://localhost:3003/api/v2${route}`)
|
||||||
|
.accept('application/json');
|
||||||
|
|
||||||
|
if (user._id && user.apiToken) {
|
||||||
|
request
|
||||||
|
.set('x-api-user', user._id)
|
||||||
|
.set('x-api-key', user.apiToken);
|
||||||
|
}
|
||||||
|
|
||||||
|
request
|
||||||
|
.query(options.query)
|
||||||
|
.send(options.send)
|
||||||
|
.end((err, response) => {
|
||||||
|
if (err) { return reject(err); }
|
||||||
|
|
||||||
|
let res = {
|
||||||
|
code: response.statusCode,
|
||||||
|
body: response.body,
|
||||||
|
}
|
||||||
|
|
||||||
|
resolve(res);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -5,4 +5,4 @@
|
|||||||
--growl
|
--growl
|
||||||
--debug
|
--debug
|
||||||
--globals io
|
--globals io
|
||||||
--require test/helpers/globals.helper
|
--require ./test/helpers/globals.helper
|
||||||
|
|||||||
Reference in New Issue
Block a user