Merge branch 'api-v3' of github.com:HabitRPG/habitrpg into api-v3
This commit is contained in:
+3
-1
@@ -2,6 +2,8 @@ language: node_js
|
||||
node_js:
|
||||
- '4.2'
|
||||
before_install:
|
||||
- "npm install -g npm@3"
|
||||
- "npm install -g gulp"
|
||||
- "sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 7F0CEB10"
|
||||
- "echo 'deb http://downloads-distro.mongodb.org/repo/ubuntu-upstart dist 10gen' | sudo tee /etc/apt/sources.list.d/mongodb.list"
|
||||
- "sudo apt-get update"
|
||||
@@ -12,4 +14,4 @@ before_script:
|
||||
- "until nc -z localhost 27017; do echo Waiting for MongoDB; sleep 1; done"
|
||||
- "export DISPLAY=:99"
|
||||
after_script:
|
||||
- "./node_modules/.bin/lcov-result-merger 'coverage/**/*.info' | ./node_modules/coveralls/bin/coveralls.js"
|
||||
- "./node_modules/.bin/lcov-result-merger 'coverage/**/*.info' | ./node_modules/coveralls/bin/coveralls.js"
|
||||
|
||||
+9
-17
@@ -12,7 +12,7 @@
|
||||
"babel": "^5.5.4",
|
||||
"body-parser": "^1.14.1",
|
||||
"bower": "~1.3.12",
|
||||
"browserify": "~3.30.2",
|
||||
"browserify": "~12.0.1",
|
||||
"coffee-script": "1.6.x",
|
||||
"coffeeify": "0.6.0",
|
||||
"compression": "^1.6.0",
|
||||
@@ -37,10 +37,9 @@
|
||||
"grunt-contrib-uglify": "~0.6.0",
|
||||
"grunt-contrib-watch": "~0.6.1",
|
||||
"grunt-hashres": "~0.4.1",
|
||||
"grunt-karma": "~0.6.2",
|
||||
"grunt-karma": "~0.12.1",
|
||||
"gulp": "^3.9.0",
|
||||
"gulp-babel": "^5.2.1",
|
||||
"gulp-clean": "^0.3.1",
|
||||
"gulp-eslint": "^1.0.0",
|
||||
"gulp-grunt": "^0.5.2",
|
||||
"gulp-imagemin": "^2.3.0",
|
||||
@@ -108,27 +107,20 @@
|
||||
"event-stream": "^3.2.2",
|
||||
"expect.js": "~0.2.0",
|
||||
"istanbul": "^0.3.14",
|
||||
"karma": "~0.10.2",
|
||||
"karma-chai-plugins": "~0.1.0",
|
||||
"karma-chrome-launcher": "~0.1.0",
|
||||
"karma-coffee-preprocessor": "~0.1.0",
|
||||
"karma-coverage": "^0.3.1",
|
||||
"karma-firefox-launcher": "~0.1.0",
|
||||
"karma-html2js-preprocessor": "~0.1.0",
|
||||
"karma-jasmine": "~0.1.3",
|
||||
"karma": "~0.13.15",
|
||||
"karma-chai-plugins": "~0.6.0",
|
||||
"karma-coverage": "^0.5.3",
|
||||
"karma-mocha": "^0.2.0",
|
||||
"karma-mocha-reporter": "^1.1.1",
|
||||
"karma-ng-html2js-preprocessor": "~0.1.0",
|
||||
"karma-phantomjs-launcher": "~0.1.0",
|
||||
"karma-requirejs": "~0.2.0",
|
||||
"requirejs": "~2.1",
|
||||
"karma-script-launcher": "~0.1.0",
|
||||
"karma-phantomjs-launcher": "~0.2.1",
|
||||
"lcov-result-merger": "^1.0.2",
|
||||
"lodash.defaultsdeep": "^3.10.0",
|
||||
"mocha": "^2.3.3",
|
||||
"mongodb": "^2.0.46",
|
||||
"mongoskin": "~0.6.1",
|
||||
"protractor": "~2.0.0",
|
||||
"protractor": "~2.5.1",
|
||||
"rewire": "^2.3.3",
|
||||
"rimraf": "^2.4.3",
|
||||
"shelljs": "^0.4.0",
|
||||
"sinon": "^1.17.2",
|
||||
"sinon-chai": "^2.8.0",
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import gulp from 'gulp';
|
||||
import imagemin from 'gulp-imagemin';
|
||||
import spritesmith from 'gulp.spritesmith';
|
||||
import clean from 'gulp-clean';
|
||||
import clean from 'rimraf';
|
||||
import sizeOf from 'image-size';
|
||||
import mergeStream from 'merge-stream';
|
||||
import {basename} from 'path';
|
||||
@@ -25,10 +25,7 @@ gulp.task('sprites:largeSprites', () => {
|
||||
});
|
||||
|
||||
gulp.task('sprites:clean', (done) => {
|
||||
gulp.src(`${DIST_PATH}spritesmith*`)
|
||||
.pipe(clean());
|
||||
|
||||
done();
|
||||
clean(`${DIST_PATH}spritesmith*`, done);
|
||||
});
|
||||
|
||||
gulp.task('sprites:checkCompiledDimensions', ['sprites:main', 'sprites:largeSprites'], () => {
|
||||
|
||||
+4
-2
@@ -297,6 +297,7 @@ gulp.task('test:e2e:safe', ['test:prepare', 'test:prepare:server'], (cb) => {
|
||||
});
|
||||
|
||||
gulp.task('test:api-v2', ['test:prepare:server'], (done) => {
|
||||
process.env.API_VERSION = 'v2';
|
||||
awaitPort(TEST_SERVER_PORT).then(() => {
|
||||
runMochaTests('./test/api/v2/**/*.js', server, done)
|
||||
});
|
||||
@@ -329,15 +330,16 @@ gulp.task('test:api-v3', ['test:api-v3:unit', 'test:api-v3:integration']);
|
||||
|
||||
gulp.task('test:api-v3:watch', ['test:api-v3:unit:watch', 'test:api-v3:integration:watch']);
|
||||
|
||||
gulp.task('test:api-v3:unit', ['test:prepare:server'], (done) => {
|
||||
gulp.task('test:api-v3:unit', (done) => {
|
||||
runMochaTests('./test/api/v3/unit/**/*.js', null, done)
|
||||
});
|
||||
|
||||
gulp.task('test:api-v3:unit:watch', ['test:prepare:server'], () => {
|
||||
gulp.task('test:api-v3:unit:watch', () => {
|
||||
gulp.watch(['website/src/**', 'test/api/v3/unit/**'], ['test:api-v3:unit']);
|
||||
});
|
||||
|
||||
gulp.task('test:api-v3:integration', ['test:prepare:server'], (done) => {
|
||||
process.env.API_VERSION = 'v3';
|
||||
awaitPort(TEST_SERVER_PORT).then(() => {
|
||||
runMochaTests('./test/api/v3/unit/**/*.js', server, done)
|
||||
});
|
||||
|
||||
@@ -1,33 +1,29 @@
|
||||
import {
|
||||
generateRes,
|
||||
generateReq,
|
||||
generateNext,
|
||||
} from '../../../../helpers/api-unit.helper';
|
||||
|
||||
import errorHandler from '../../../../../website/src/middlewares/api-v3/errorHandler';
|
||||
|
||||
import { BadRequest } from '../../../../../website/src/libs/api-v3/errors';
|
||||
import logger from '../../../../../website/src/libs/api-v3/logger';
|
||||
|
||||
describe('errorHandler', () => {
|
||||
let res, req;
|
||||
let res, req, next;
|
||||
|
||||
beforeEach(() => {
|
||||
res = {
|
||||
status: sinon.stub().returnsThis(),
|
||||
json: sinon.stub(),
|
||||
};
|
||||
req = {
|
||||
originalUrl: 'foo',
|
||||
headers: {},
|
||||
body: {},
|
||||
};
|
||||
res = generateRes();
|
||||
req = generateReq();
|
||||
next = generateNext();
|
||||
|
||||
sinon.stub(logger, 'error');
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
logger.error.restore();
|
||||
sandbox.stub(logger, 'error');
|
||||
});
|
||||
|
||||
it('sends internal server error if error is not a CustomError', () => {
|
||||
let error = new Error();
|
||||
|
||||
errorHandler(error, req, res);
|
||||
errorHandler(error, req, res, next);
|
||||
|
||||
expect(res.status).to.be.calledOnce;
|
||||
expect(res.json).to.be.calledOnce;
|
||||
@@ -42,7 +38,7 @@ describe('errorHandler', () => {
|
||||
it('sends CustomError', () => {
|
||||
let error = new BadRequest();
|
||||
|
||||
errorHandler(error, req, res);
|
||||
errorHandler(error, req, res, next);
|
||||
|
||||
expect(res.status).to.be.calledOnce;
|
||||
expect(res.json).to.be.calledOnce;
|
||||
@@ -57,7 +53,7 @@ describe('errorHandler', () => {
|
||||
it('logs error', () => {
|
||||
let error = new BadRequest();
|
||||
|
||||
errorHandler(error, req, res);
|
||||
errorHandler(error, req, res, next);
|
||||
|
||||
expect(logger.error).to.be.calledOnce;
|
||||
expect(logger.error).to.be.calledWith(error.stack, {
|
||||
@@ -68,7 +64,6 @@ describe('errorHandler', () => {
|
||||
});
|
||||
|
||||
it('does not send error if error is not defined', () => {
|
||||
let next = sinon.stub();
|
||||
errorHandler(null, req, res, next);
|
||||
|
||||
expect(next).to.be.calledOnce;
|
||||
|
||||
@@ -208,9 +208,10 @@ export function resetHabiticaDB() {
|
||||
}
|
||||
|
||||
function _requestMaker(user, method, additionalSets) {
|
||||
const API_V = process.env.API_VERSION || 'v2'
|
||||
return (route, send, query) => {
|
||||
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/${API_V}${route}`)
|
||||
.accept('application/json');
|
||||
|
||||
if (user && user._id && user.apiToken) {
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
// @TODO: remove when lodash can be upgraded
|
||||
import defaults from 'lodash.defaultsdeep';
|
||||
import { model as User } from '../../website/src/models/user'
|
||||
import { model as Group } from '../../website/src/models/group'
|
||||
import i18n from '../../common/script/src/i18n';
|
||||
require('coffee-script');
|
||||
i18n.translations = require('../../website/src/libs/i18n.js').translations;
|
||||
|
||||
afterEach(() => {
|
||||
sandbox.restore();
|
||||
});
|
||||
|
||||
export function generateUser(options={}) {
|
||||
return new User(options).toObject();
|
||||
}
|
||||
|
||||
export function generateGroup(options={}) {
|
||||
return new Group(options).toObject();
|
||||
}
|
||||
|
||||
export function generateRes(options={}) {
|
||||
let defaultRes = {
|
||||
send: sandbox.stub(),
|
||||
status: sandbox.stub().returnsThis(),
|
||||
json: sandbox.stub(),
|
||||
locals: {
|
||||
user: generateUser(options.localsUser),
|
||||
group: generateGroup(options.localsGroup),
|
||||
},
|
||||
};
|
||||
|
||||
return defaults(options, defaultRes);
|
||||
}
|
||||
|
||||
export function generateReq(options={}) {
|
||||
let defaultReq = {
|
||||
body: {},
|
||||
query: {},
|
||||
};
|
||||
|
||||
return defaults(options, defaultReq);
|
||||
}
|
||||
|
||||
export function generateNext(func) {
|
||||
return func || sandbox.stub();
|
||||
}
|
||||
@@ -8,3 +8,5 @@ global.sinon = require("sinon");
|
||||
chai.use(require("sinon-chai"))
|
||||
chai.use(require("chai-as-promised"));
|
||||
global.expect = chai.expect
|
||||
|
||||
global.sandbox = sinon.sandbox.create();
|
||||
|
||||
Reference in New Issue
Block a user