diff --git a/test/api/v3/integration/chat/GET-chat.test.js b/test/api/v3/integration/chat/GET-chat.test.js index cb1e0996e6..dbd631e362 100644 --- a/test/api/v3/integration/chat/GET-chat.test.js +++ b/test/api/v3/integration/chat/GET-chat.test.js @@ -2,7 +2,7 @@ import { generateUser, generateGroup, translate as t, -} from '../../../../helpers/api-integration.helper'; +} from '../../../../helpers/api-v3-integration.helper'; describe('GET /groups/:groupId/chat', () => { let user; diff --git a/test/api/v3/integration/chat/POST-chat.flag.test.js b/test/api/v3/integration/chat/POST-chat.flag.test.js index b71d462e5a..47ba58b046 100644 --- a/test/api/v3/integration/chat/POST-chat.flag.test.js +++ b/test/api/v3/integration/chat/POST-chat.flag.test.js @@ -1,7 +1,7 @@ import { generateUser, translate as t, -} from '../../../../helpers/api-integration.helper'; +} from '../../../../helpers/api-v3-integration.helper'; import { find } from 'lodash'; describe('POST /chat/:chatId/flag', () => { diff --git a/test/api/v3/integration/chat/POST-chat.like.test.js b/test/api/v3/integration/chat/POST-chat.like.test.js index 05d40f6e9f..cf266431ba 100644 --- a/test/api/v3/integration/chat/POST-chat.like.test.js +++ b/test/api/v3/integration/chat/POST-chat.like.test.js @@ -1,7 +1,7 @@ import { generateUser, translate as t, -} from '../../../../helpers/api-integration.helper'; +} from '../../../../helpers/api-v3-integration.helper'; import { find } from 'lodash'; describe('POST /chat/:chatId/like', () => { diff --git a/test/api/v3/integration/chat/POST-chat.test.js b/test/api/v3/integration/chat/POST-chat.test.js index 37403ed12d..fe943bfb1c 100644 --- a/test/api/v3/integration/chat/POST-chat.test.js +++ b/test/api/v3/integration/chat/POST-chat.test.js @@ -1,7 +1,7 @@ import { generateUser, translate as t, -} from '../../../../helpers/api-integration.helper'; +} from '../../../../helpers/api-v3-integration.helper'; describe('POST /chat', () => { let user; diff --git a/test/api/v3/integration/groups/POST-groups.test.js b/test/api/v3/integration/groups/POST-groups.test.js index 3515f07cec..8a64ef4bb5 100644 --- a/test/api/v3/integration/groups/POST-groups.test.js +++ b/test/api/v3/integration/groups/POST-groups.test.js @@ -1,7 +1,7 @@ import { generateUser, translate as t, -} from '../../../../helpers/api-integration.helper'; +} from '../../../../helpers/api-v3-integration.helper'; describe('POST /group', () => { let user; diff --git a/test/api/v3/integration/groups/POST-groups_groupId_join.js b/test/api/v3/integration/groups/POST-groups_groupId_join.js index 2c36d12f19..ca7c8317b5 100644 --- a/test/api/v3/integration/groups/POST-groups_groupId_join.js +++ b/test/api/v3/integration/groups/POST-groups_groupId_join.js @@ -1,7 +1,7 @@ import { generateUser, translate as t, -} from '../../../../helpers/api-integration.helper'; +} from '../../../../helpers/api-v3-integration.helper'; import { v4 as generateUUID } from 'uuid'; describe('POST /group/:groupId/join', () => { diff --git a/test/api/v3/integration/groups/POST-groups_invite.test.js b/test/api/v3/integration/groups/POST-groups_invite.test.js index 2466bdf649..42719c0fcd 100644 --- a/test/api/v3/integration/groups/POST-groups_invite.test.js +++ b/test/api/v3/integration/groups/POST-groups_invite.test.js @@ -1,7 +1,7 @@ import { generateUser, translate as t, -} from '../../../../helpers/api-integration.helper'; +} from '../../../../helpers/api-v3-integration.helper'; import { v4 as generateUUID } from 'uuid'; const INVITES_LIMIT = 100; diff --git a/test/api/v3/integration/groups/PUT-groups.test.js b/test/api/v3/integration/groups/PUT-groups.test.js index 6700374697..5c23668ddf 100644 --- a/test/api/v3/integration/groups/PUT-groups.test.js +++ b/test/api/v3/integration/groups/PUT-groups.test.js @@ -1,7 +1,7 @@ import { generateUser, translate as t, -} from '../../../../helpers/api-integration.helper'; +} from '../../../../helpers/api-v3-integration.helper'; describe('PUT /group', () => { let groupLeader; diff --git a/test/helpers/api-v3-integration.helper.js b/test/helpers/api-v3-integration.helper.js index dba72ca99d..30898513e2 100644 --- a/test/helpers/api-v3-integration.helper.js +++ b/test/helpers/api-v3-integration.helper.js @@ -14,6 +14,15 @@ import i18n from '../../common/script/src/i18n'; i18n.translations = require('../../website/src/libs/api-v3/i18n').translations; const API_TEST_SERVER_PORT = 3003; +const API_V = process.env.API_VERSION || 'v2'; // eslint-disable-line no-process-env +const ROUTES = { + v2: { + register: '/register', + }, + v3: { + register: '/user/auth/local/register', + }, +}; class ApiUser { constructor (options) { @@ -96,7 +105,7 @@ export function generateUser (update = {}) { let request = _requestMaker({}, 'post'); return new Promise((resolve, reject) => { - request('/user/auth/local/register', { + request(ROUTES[API_V].register, { username, email, password, @@ -114,15 +123,15 @@ export function generateUser (update = {}) { // Generates a new group. Requires a user object, which // will will become the groups leader. Takes an update // argument which will update group -export function generateGroup (leader, update = {}) { +export function generateGroup (leader, details = {}, update = {}) { let request = _requestMaker(leader, 'post'); return new Promise((resolve, reject) => { - request('/groups').then((group) => { + request('/groups', details).then((group) => { _updateDocument('groups', group, update, () => { resolve(group); - }).catch(reject); - }); + }); + }).catch(reject); }); } @@ -241,7 +250,7 @@ export function resetHabiticaDB () { function _requestMaker (user, method, additionalSets) { return (route, send, query) => { return new Promise((resolve, reject) => { - let request = superagent[method](`http://localhost:${API_TEST_SERVER_PORT}/api/v3${route}`) + let request = superagent[method](`http://localhost:${API_TEST_SERVER_PORT}/api/${API_V}${route}`) .accept('application/json'); if (user && user._id && user.apiToken) { @@ -261,11 +270,20 @@ function _requestMaker (user, method, additionalSets) { if (err) { if (!err.response) return reject(err); - return reject({ - code: err.status, - error: err.response.body.error, - message: err.response.body.message, - }); + if (API_V === 'v3') { + return reject({ + code: err.status, + error: err.response.body.error, + message: err.response.body.message, + }); + } else if (API_V === 'v2') { + return reject({ + code: err.status, + text: err.response.body.err, + }); + } + + return reject(err); } resolve(response.body);