Skip to content
11 changes: 5 additions & 6 deletions __tests__/actions/auth.js
Original file line number Diff line number Diff line change
@@ -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;
},
})));

Expand Down
1 change: 1 addition & 0 deletions config/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
10 changes: 6 additions & 4 deletions src/actions/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 }));
}

Expand Down
8 changes: 4 additions & 4 deletions src/services/__mocks__/challenges.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
});
}
Expand Down Expand Up @@ -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;
});
}
Expand Down
6 changes: 3 additions & 3 deletions src/services/groups.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -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);
Expand Down
17 changes: 5 additions & 12 deletions src/utils/challenge/filter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}

Expand Down