mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-17 06:37:23 +01:00
Move api tests to v2 namespace
This commit is contained in:
@@ -15,7 +15,7 @@ let server;
|
|||||||
|
|
||||||
const TEST_DB_URI = `mongodb://localhost/${TEST_DB}`
|
const TEST_DB_URI = `mongodb://localhost/${TEST_DB}`
|
||||||
|
|
||||||
const API_TEST_COMMAND = 'mocha test/api --recursive --compilers js:babel/register';
|
const API_V2_TEST_COMMAND = 'mocha test/api/v2 --recursive --compilers js:babel/register';
|
||||||
const LEGACY_API_TEST_COMMAND = 'mocha test/api-legacy';
|
const LEGACY_API_TEST_COMMAND = 'mocha test/api-legacy';
|
||||||
const COMMON_TEST_COMMAND = 'mocha test/common --compilers coffee:coffee-script';
|
const COMMON_TEST_COMMAND = 'mocha test/common --compilers coffee:coffee-script';
|
||||||
const CONTENT_TEST_COMMAND = 'mocha test/content --compilers js:babel/register';
|
const CONTENT_TEST_COMMAND = 'mocha test/content --compilers js:babel/register';
|
||||||
@@ -293,12 +293,16 @@ gulp.task('test:e2e:safe', ['test:prepare', 'test:prepare:server'], (cb) => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
gulp.task('test:api', ['test:prepare:server'], (done) => {
|
gulp.task('test:api-v2', ['test:prepare:server'], (done) => {
|
||||||
|
runIntegrationTestsWithMocha('./test/api/v2/**/*.js')
|
||||||
|
});
|
||||||
|
|
||||||
|
function runIntegrationTestsWithMocha(files) {
|
||||||
require('../test/helpers/globals.helper');
|
require('../test/helpers/globals.helper');
|
||||||
|
|
||||||
awaitPort(TEST_SERVER_PORT).then(() => {
|
awaitPort(TEST_SERVER_PORT).then(() => {
|
||||||
let mocha = new Mocha({reporter: 'spec'});
|
let mocha = new Mocha({reporter: 'spec'});
|
||||||
let tests = glob('./test/api/**/*.js');
|
let tests = glob(files);
|
||||||
|
|
||||||
tests.forEach((test) => {
|
tests.forEach((test) => {
|
||||||
delete require.cache[resolve(test)];
|
delete require.cache[resolve(test)];
|
||||||
@@ -313,17 +317,17 @@ gulp.task('test:api', ['test:prepare:server'], (done) => {
|
|||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
}
|
||||||
|
|
||||||
gulp.task('test:api:watch', ['test:prepare:server'], () => {
|
gulp.task('test:api-v2:watch', ['test:prepare:server'], () => {
|
||||||
process.env.RUN_INTEGRATION_TEST_FOREVER = true;
|
process.env.RUN_INTEGRATION_TEST_FOREVER = true;
|
||||||
gulp.watch(['website/src/**', 'test/api/**'], ['test:api']);
|
gulp.watch(['website/src/**', 'test/api/**'], ['test:api']);
|
||||||
});
|
});
|
||||||
|
|
||||||
gulp.task('test:api:safe', ['test:prepare:server'], (done) => {
|
gulp.task('test:api-v2:safe', ['test:prepare:server'], (done) => {
|
||||||
awaitPort(TEST_SERVER_PORT).then(() => {
|
awaitPort(TEST_SERVER_PORT).then(() => {
|
||||||
let runner = exec(
|
let runner = exec(
|
||||||
testBin(API_TEST_COMMAND),
|
testBin(API_V2_TEST_COMMAND),
|
||||||
(err, stdout, stderr) => {
|
(err, stdout, stderr) => {
|
||||||
testResults.push({
|
testResults.push({
|
||||||
suite: 'API Specs\t',
|
suite: 'API Specs\t',
|
||||||
@@ -345,7 +349,7 @@ gulp.task('test', [
|
|||||||
'test:server_side:safe',
|
'test:server_side:safe',
|
||||||
'test:karma:safe',
|
'test:karma:safe',
|
||||||
'test:api-legacy:safe',
|
'test:api-legacy:safe',
|
||||||
'test:api:safe',
|
'test:api-v2:safe',
|
||||||
], () => {
|
], () => {
|
||||||
let totals = [0,0,0];
|
let totals = [0,0,0];
|
||||||
|
|
||||||
|
|||||||
@@ -19,15 +19,15 @@ $ npm install -g gulp
|
|||||||
To run the api tests, make sure the mongo db is up and running and then type this on the command line:
|
To run the api tests, make sure the mongo db is up and running and then type this on the command line:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
$ gulp test:api
|
$ gulp test:api-v2
|
||||||
```
|
```
|
||||||
|
|
||||||
It may take a little while to get going, since it requires the web server to start up before the tests can run.
|
It may take a little while to get going, since it requires the web server to start up before the tests can run.
|
||||||
|
|
||||||
You can also run a watch command for the api tests. This will allow the tests to re-run automatically when you make changes in the `/test/api/` or `/website/src/` directories.
|
You can also run a watch command for the api tests. This will allow the tests to re-run automatically when you make changes in the `/test/api/v2/`.
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
$ gulp test:api:watch
|
$ gulp test:api-v2:watch
|
||||||
```
|
```
|
||||||
|
|
||||||
One caveat. If you have a severe syntax error in your files, the tests may fail to run, but they won't alert you that they are not running. If you ever find your test hanging for a while, run this to get the stackstrace. Once you've fixed the problem, you can resume running the watch comand.
|
One caveat. If you have a severe syntax error in your files, the tests may fail to run, but they won't alert you that they are not running. If you ever find your test hanging for a while, run this to get the stackstrace. Once you've fixed the problem, you can resume running the watch comand.
|
||||||
@@ -3,7 +3,7 @@ import {
|
|||||||
generateUser,
|
generateUser,
|
||||||
resetHabiticaDB,
|
resetHabiticaDB,
|
||||||
requester,
|
requester,
|
||||||
} from '../../helpers/api.helper';
|
} from '../../../helpers/api-integration.helper';
|
||||||
|
|
||||||
describe('GET /groups', () => {
|
describe('GET /groups', () => {
|
||||||
const NUMBER_OF_PUBLIC_GUILDS = 3;
|
const NUMBER_OF_PUBLIC_GUILDS = 3;
|
||||||
@@ -3,7 +3,7 @@ import {
|
|||||||
generateUser,
|
generateUser,
|
||||||
requester,
|
requester,
|
||||||
translate as t,
|
translate as t,
|
||||||
} from '../../helpers/api.helper';
|
} from '../../../helpers/api-integration.helper';
|
||||||
import {
|
import {
|
||||||
find,
|
find,
|
||||||
each
|
each
|
||||||
@@ -3,7 +3,7 @@ import {
|
|||||||
generateUser,
|
generateUser,
|
||||||
requester,
|
requester,
|
||||||
translate as t,
|
translate as t,
|
||||||
} from '../../helpers/api.helper';
|
} from '../../../helpers/api-integration.helper';
|
||||||
|
|
||||||
describe('POST /groups', () => {
|
describe('POST /groups', () => {
|
||||||
|
|
||||||
@@ -3,7 +3,7 @@ import {
|
|||||||
generateUser,
|
generateUser,
|
||||||
requester,
|
requester,
|
||||||
translate as t,
|
translate as t,
|
||||||
} from '../../helpers/api.helper';
|
} from '../../../helpers/api-integration.helper';
|
||||||
|
|
||||||
describe('POST /groups/:id', () => {
|
describe('POST /groups/:id', () => {
|
||||||
|
|
||||||
@@ -3,7 +3,7 @@ import {
|
|||||||
generateUser,
|
generateUser,
|
||||||
requester,
|
requester,
|
||||||
translate as t,
|
translate as t,
|
||||||
} from '../../helpers/api.helper';
|
} from '../../../helpers/api-integration.helper';
|
||||||
import { each, find } from 'lodash';
|
import { each, find } from 'lodash';
|
||||||
|
|
||||||
describe('POST /groups/:id/join', () => {
|
describe('POST /groups/:id/join', () => {
|
||||||
@@ -4,7 +4,7 @@ import {
|
|||||||
generateUser,
|
generateUser,
|
||||||
requester,
|
requester,
|
||||||
translate as t,
|
translate as t,
|
||||||
} from '../../helpers/api.helper';
|
} from '../../../helpers/api-integration.helper';
|
||||||
import { find } from 'lodash';
|
import { find } from 'lodash';
|
||||||
|
|
||||||
describe('POST /groups/:id/leave', () => {
|
describe('POST /groups/:id/leave', () => {
|
||||||
@@ -4,7 +4,7 @@ import {
|
|||||||
generateUser,
|
generateUser,
|
||||||
requester,
|
requester,
|
||||||
translate as t,
|
translate as t,
|
||||||
} from '../../helpers/api.helper';
|
} from '../../../helpers/api-integration.helper';
|
||||||
|
|
||||||
describe('POST /groups/:id/removeMember', () => {
|
describe('POST /groups/:id/removeMember', () => {
|
||||||
|
|
||||||
@@ -3,7 +3,7 @@ import {
|
|||||||
generateUser,
|
generateUser,
|
||||||
requester,
|
requester,
|
||||||
translate as t,
|
translate as t,
|
||||||
} from '../../../helpers/api.helper';
|
} from '../../../../helpers/api-integration.helper';
|
||||||
|
|
||||||
describe('DELETE /groups/:id/chat', () => {
|
describe('DELETE /groups/:id/chat', () => {
|
||||||
let api, group, message, user;
|
let api, group, message, user;
|
||||||
@@ -3,7 +3,7 @@ import {
|
|||||||
generateUser,
|
generateUser,
|
||||||
requester,
|
requester,
|
||||||
translate as t,
|
translate as t,
|
||||||
} from '../../../helpers/api.helper';
|
} from '../../../../helpers/api-integration.helper';
|
||||||
|
|
||||||
describe('GET /groups/:id/chat', () => {
|
describe('GET /groups/:id/chat', () => {
|
||||||
|
|
||||||
@@ -3,7 +3,7 @@ import {
|
|||||||
generateUser,
|
generateUser,
|
||||||
requester,
|
requester,
|
||||||
translate as t,
|
translate as t,
|
||||||
} from '../../../helpers/api.helper';
|
} from '../../../../helpers/api-integration.helper';
|
||||||
|
|
||||||
describe('POST /groups/:id/chat', () => {
|
describe('POST /groups/:id/chat', () => {
|
||||||
|
|
||||||
@@ -3,7 +3,7 @@ import {
|
|||||||
generateUser,
|
generateUser,
|
||||||
requester,
|
requester,
|
||||||
translate as t,
|
translate as t,
|
||||||
} from '../../../helpers/api.helper';
|
} from '../../../../helpers/api-integration.helper';
|
||||||
|
|
||||||
describe('POST /groups/:id/chat/:id/flag', () => {
|
describe('POST /groups/:id/chat/:id/flag', () => {
|
||||||
|
|
||||||
@@ -3,7 +3,7 @@ import {
|
|||||||
generateUser,
|
generateUser,
|
||||||
requester,
|
requester,
|
||||||
translate as t,
|
translate as t,
|
||||||
} from '../../../helpers/api.helper';
|
} from '../../../../helpers/api-integration.helper';
|
||||||
|
|
||||||
describe('POST /groups/:id/chat/:id/like', () => {
|
describe('POST /groups/:id/chat/:id/like', () => {
|
||||||
|
|
||||||
@@ -2,7 +2,7 @@ import {
|
|||||||
generateUser,
|
generateUser,
|
||||||
requester,
|
requester,
|
||||||
translate as t,
|
translate as t,
|
||||||
} from '../../helpers/api.helper';
|
} from '../../../helpers/api-integration.helper';
|
||||||
import {v4 as generateRandomUserName} from 'uuid';
|
import {v4 as generateRandomUserName} from 'uuid';
|
||||||
|
|
||||||
describe('POST /register', () => {
|
describe('POST /register', () => {
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
import {requester} from '../../helpers/api.helper';
|
import {requester} from '../../../helpers/api-integration.helper';
|
||||||
|
|
||||||
describe('Status', () => {
|
describe('Status', () => {
|
||||||
|
|
||||||
@@ -4,7 +4,7 @@ import {
|
|||||||
generateUser,
|
generateUser,
|
||||||
requester,
|
requester,
|
||||||
translate as t,
|
translate as t,
|
||||||
} from '../../helpers/api.helper';
|
} from '../../../helpers/api-integration.helper';
|
||||||
|
|
||||||
describe('DELETE /user', () => {
|
describe('DELETE /user', () => {
|
||||||
let api, user;
|
let api, user;
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
import {
|
import {
|
||||||
generateUser,
|
generateUser,
|
||||||
requester,
|
requester,
|
||||||
} from '../../helpers/api.helper';
|
} from '../../../helpers/api-integration.helper';
|
||||||
|
|
||||||
describe('GET /user', () => {
|
describe('GET /user', () => {
|
||||||
let user;
|
let user;
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
import {
|
import {
|
||||||
generateUser,
|
generateUser,
|
||||||
requester,
|
requester,
|
||||||
} from '../../helpers/api.helper';
|
} from '../../../helpers/api-integration.helper';
|
||||||
|
|
||||||
describe('GET /user/tags', () => {
|
describe('GET /user/tags', () => {
|
||||||
let api, user;
|
let api, user;
|
||||||
@@ -2,7 +2,7 @@ import {
|
|||||||
generateUser,
|
generateUser,
|
||||||
requester,
|
requester,
|
||||||
translate as t,
|
translate as t,
|
||||||
} from '../../helpers/api.helper';
|
} from '../../../helpers/api-integration.helper';
|
||||||
|
|
||||||
describe('GET /user/tags/id', () => {
|
describe('GET /user/tags/id', () => {
|
||||||
let api, user;
|
let api, user;
|
||||||
@@ -2,7 +2,7 @@ import {
|
|||||||
generateUser,
|
generateUser,
|
||||||
requester,
|
requester,
|
||||||
translate as t,
|
translate as t,
|
||||||
} from '../../helpers/api.helper';
|
} from '../../../helpers/api-integration.helper';
|
||||||
|
|
||||||
import { each } from 'lodash';
|
import { each } from 'lodash';
|
||||||
|
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
import {
|
import {
|
||||||
generateUser,
|
generateUser,
|
||||||
requester,
|
requester,
|
||||||
} from '../../../helpers/api.helper';
|
} from '../../../../helpers/api-integration.helper';
|
||||||
import { each } from 'lodash';
|
import { each } from 'lodash';
|
||||||
|
|
||||||
describe('GET /user/anonymized', () => {
|
describe('GET /user/anonymized', () => {
|
||||||
@@ -2,7 +2,7 @@ import {
|
|||||||
generateUser,
|
generateUser,
|
||||||
requester,
|
requester,
|
||||||
translate as t,
|
translate as t,
|
||||||
} from '../../../helpers/api.helper';
|
} from '../../../../helpers/api-integration.helper';
|
||||||
|
|
||||||
import { each } from 'lodash';
|
import { each } from 'lodash';
|
||||||
|
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
import {
|
import {
|
||||||
generateUser,
|
generateUser,
|
||||||
requester,
|
requester,
|
||||||
} from '../../../helpers/api.helper';
|
} from '../../../../helpers/api-integration.helper';
|
||||||
|
|
||||||
describe('POST /user/pushDevice', () => {
|
describe('POST /user/pushDevice', () => {
|
||||||
let api;
|
let api;
|
||||||
@@ -2,7 +2,7 @@ import {
|
|||||||
generateUser,
|
generateUser,
|
||||||
requester,
|
requester,
|
||||||
translate as t,
|
translate as t,
|
||||||
} from '../../../helpers/api.helper';
|
} from '../../../../helpers/api-integration.helper';
|
||||||
|
|
||||||
describe('DELETE /user/tasks/:id', () => {
|
describe('DELETE /user/tasks/:id', () => {
|
||||||
let api, user, task;
|
let api, user, task;
|
||||||
@@ -2,7 +2,7 @@ import {
|
|||||||
generateUser,
|
generateUser,
|
||||||
requester,
|
requester,
|
||||||
translate as t,
|
translate as t,
|
||||||
} from '../../../helpers/api.helper';
|
} from '../../../../helpers/api-integration.helper';
|
||||||
|
|
||||||
describe('GET /user/tasks/', () => {
|
describe('GET /user/tasks/', () => {
|
||||||
let api, user;
|
let api, user;
|
||||||
@@ -2,7 +2,7 @@ import {
|
|||||||
generateUser,
|
generateUser,
|
||||||
requester,
|
requester,
|
||||||
translate as t,
|
translate as t,
|
||||||
} from '../../../helpers/api.helper';
|
} from '../../../../helpers/api-integration.helper';
|
||||||
|
|
||||||
describe('GET /user/tasks/:id', () => {
|
describe('GET /user/tasks/:id', () => {
|
||||||
let api, user, task;
|
let api, user, task;
|
||||||
@@ -2,7 +2,7 @@ import {
|
|||||||
generateUser,
|
generateUser,
|
||||||
requester,
|
requester,
|
||||||
translate as t,
|
translate as t,
|
||||||
} from '../../../helpers/api.helper';
|
} from '../../../../helpers/api-integration.helper';
|
||||||
|
|
||||||
describe('POST /user/tasks', () => {
|
describe('POST /user/tasks', () => {
|
||||||
|
|
||||||
@@ -2,7 +2,7 @@ import {
|
|||||||
generateUser,
|
generateUser,
|
||||||
requester,
|
requester,
|
||||||
translate as t,
|
translate as t,
|
||||||
} from '../../../helpers/api.helper';
|
} from '../../../../helpers/api-integration.helper';
|
||||||
|
|
||||||
describe('PUT /user/tasks/:id', () => {
|
describe('PUT /user/tasks/:id', () => {
|
||||||
let api, user, task;
|
let api, user, task;
|
||||||
Reference in New Issue
Block a user