diff --git a/__tests__/actions/auth.js b/__tests__/actions/auth.js index eff03f17..2922e0b4 100644 --- a/__tests__/actions/auth.js +++ b/__tests__/actions/auth.js @@ -1,17 +1,16 @@ -const MOCK_GROUPS_REQ_URL = 'https://api.topcoder-dev.com/v3/groups?memberId=12345&membershipType=user'; -const MOCK_PROFILE_REQ_URL = 'https://api.topcoder-dev.com/v3/members/username12345'; +const MOCK_GROUPS_REQ_URL = 'https://api.topcoder-dev.com/v5/groups?memberId=12345&membershipType=user'; +const MOCK_PROFILE_REQ_URL = 'https://api.topcoder-dev.com/v5/members/username12345'; jest.mock('isomorphic-fetch', () => jest.fn(url => Promise.resolve({ + ok: true, json: () => { let content; switch (url) { case MOCK_GROUPS_REQ_URL: content = ['Group1', 'Group2']; break; - case MOCK_PROFILE_REQ_URL: content = { userId: 12345 }; break; + case MOCK_PROFILE_REQ_URL: content = [{ userId: 12345 }]; break; default: throw new Error('Unexpected URL!'); } - return { - result: { content, status: 200 }, - }; + return content; }, }))); diff --git a/config/test.js b/config/test.js index add8c31c..1d2ca856 100644 --- a/config/test.js +++ b/config/test.js @@ -2,6 +2,7 @@ module.exports = { API: { V2: 'https://api.topcoder-dev.com/v2', V3: 'https://api.topcoder-dev.com/v3', + V5: 'https://api.topcoder-dev.com/v5', }, dummyConfigKey: 'Dummy config value', SECRET: { diff --git a/src/actions/auth.js b/src/actions/auth.js index c585ec71..0a611f43 100644 --- a/src/actions/auth.js +++ b/src/actions/auth.js @@ -9,19 +9,21 @@ import { getApi } from '../services/api'; /** * @static - * @desc Creates an action that loads Topcoder user profile from v3 API. + * @desc Creates an action that loads Topcoder user profile from v5 API. * @param {String} userTokenV3 v3 authentication token. * @return {Action} */ function loadProfileDone(userTokenV3) { if (!userTokenV3) return Promise.resolve(null); const user = decodeToken(userTokenV3); - const api = getApi('V3', userTokenV3); + const api = getApi('V5', userTokenV3); return Promise.all([ api.get(`/members/${user.handle}`) - .then(res => res.json()).then(res => (res.result.status === 200 ? res.result.content : {})), + .then(res => (res.ok ? res.json() : new Error(res.statusText))) + .then(res => (res.message ? new Error(res.message) : res[0])), api.get(`/groups?memberId=${user.userId}&membershipType=user`) - .then(res => res.json()).then(res => (res.result.status === 200 ? res.result.content : [])), + .then(res => (res.ok ? res.json() : new Error(res.statusText))) + .then(res => (res.message ? new Error(res.message) : res)), ]).then(([profile, groups]) => ({ ...profile, groups })); } diff --git a/src/services/__mocks__/challenges.js b/src/services/__mocks__/challenges.js index 0dc59e7c..2c5e7ae4 100644 --- a/src/services/__mocks__/challenges.js +++ b/src/services/__mocks__/challenges.js @@ -85,8 +85,8 @@ export function normalizeChallengeDetails(v3, v3Filtered, v3User, v2, username) // Fill missing data from v3_filtered if (v3Filtered) { const groups = {}; - if (v3Filtered.groupIds) { - v3Filtered.groupIds.forEach((id) => { + if (v3Filtered.groups) { + v3Filtered.groups.forEach((id) => { groups[id] = true; }); } @@ -165,8 +165,8 @@ export function normalizeChallengeDetails(v3, v3Filtered, v3User, v2, username) export function normalizeChallenge(challenge, username) { const registrationOpen = challenge.allPhases.filter(d => d.name === 'Registration')[0].isOpen ? 'Yes' : 'No'; const groups = {}; - if (challenge.groupIds) { - challenge.groupIds.forEach((id) => { + if (challenge.groups) { + challenge.groups.forEach((id) => { groups[id] = true; }); } diff --git a/src/services/groups.js b/src/services/groups.js index 69603c0f..a3b42a80 100644 --- a/src/services/groups.js +++ b/src/services/groups.js @@ -170,8 +170,8 @@ function mergeGroup(groups, group) { * @param {Object} group * @return {String[]} Array of IDs. */ -export function reduceGroupIds({ oldId, subGroups }) { - let res = [oldId]; +export function reduceGroupIds({ id, subGroups }) { + let res = [id]; if (subGroups) { subGroups.forEach((g) => { res = res.concat(reduceGroupIds(g)); @@ -210,7 +210,7 @@ class GroupService { */ async addMember(groupId, memberId, membershipType) { const response = await this.private.api.postJson(`/groups/${groupId}/members`, { - param: { memberId, membershipType }, + memberId, membershipType, }); return handleApiResponse(response); diff --git a/src/utils/challenge/filter.js b/src/utils/challenge/filter.js index 95b6e18a..ca6de71d 100644 --- a/src/utils/challenge/filter.js +++ b/src/utils/challenge/filter.js @@ -18,7 +18,7 @@ * endDate {Number|String} - Permits only those challenges with submission * deadline before this date. * - * groupIds {Array} - Permits only the challenges belonging to at least one + * groups {Array} - Permits only the challenges belonging to at least one * of the groups which IDs are presented as keys in this object. * * or {Object[]} - All other filter fields applied to the challenge with AND @@ -71,8 +71,8 @@ import { COMPETITION_TRACKS, REVIEW_OPPORTUNITY_TYPES } from '../tc'; */ function filterByGroupIds(challenge, state) { - if (!state.groupIds) return true; - return state.groupIds.some(id => challenge.groups[id]); + if (!state.groups) return true; + return state.groups.some(id => challenge.groups[id]); } function filterByRegistrationOpen(challenge, state) { @@ -343,7 +343,7 @@ export function combine(...filters) { const res = {}; filters.forEach((filter) => { combineEndDate(res, filter); - combineArrayRules(res, filter, 'groupIds'); + combineArrayRules(res, filter, 'groups'); /* TODO: The registrationOpen rule is just ignored for now. */ combineStartDate(res, filter); combineArrayRules(res, filter, 'or', true); @@ -379,15 +379,8 @@ export function combine(...filters) { * @return {Object} */ export function mapToBackend(filter) { - if (filter.or) return {}; - const res = {}; - if (filter.groupIds) res.groupIds = filter.groupIds.join(','); - - /* NOTE: Right now the frontend challenge filter by tag works different, - * it looks for matches in the challenge name OR in the techs / platforms. */ - // if (filter.tags) res.technologies = filter.tags.join(','); - + if (filter.groups) res.groups = filter.groups; return res; }