From e3c9499b5f16a6bd3468ecf878aa438404a7d830 Mon Sep 17 00:00:00 2001 From: "Luiz R. Rodrigues" Date: Wed, 8 Jul 2020 20:00:56 -0300 Subject: [PATCH 1/2] change loadProfileDone to use v3 instead v5 API --- src/actions/auth.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/actions/auth.js b/src/actions/auth.js index 0a611f43..f758d9ed 100644 --- a/src/actions/auth.js +++ b/src/actions/auth.js @@ -5,23 +5,23 @@ import { createActions } from 'redux-actions'; import { decodeToken } from 'tc-accounts'; -import { getApi } from '../services/api'; +import { getApiV3, getApiV5 } from '../services/api'; /** * @static - * @desc Creates an action that loads Topcoder user profile from v5 API. + * @desc Creates an action that loads Topcoder user profile from v3 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('V5', userTokenV3); + const apiV3 = getApiV3(userTokenV3); + const apiV5 = getApiV5(userTokenV3); return Promise.all([ - api.get(`/members/${user.handle}`) - .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`) + apiV3.get(`/members/${user.handle}`) + .then(res => res.json()).then(res => (res.result.status === 200 ? res.result.content : {})), + apiV5.get(`/groups?memberId=${user.userId}&membershipType=user`) .then(res => (res.ok ? res.json() : new Error(res.statusText))) .then(res => (res.message ? new Error(res.message) : res)), ]).then(([profile, groups]) => ({ ...profile, groups })); From 4b2df6b885cddafa5671934b91552b8a47ad5997 Mon Sep 17 00:00:00 2001 From: "Luiz R. Rodrigues" Date: Wed, 8 Jul 2020 20:18:56 -0300 Subject: [PATCH 2/2] Update tests --- __tests__/actions/auth.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/__tests__/actions/auth.js b/__tests__/actions/auth.js index 2922e0b4..a36ef7e3 100644 --- a/__tests__/actions/auth.js +++ b/__tests__/actions/auth.js @@ -1,13 +1,17 @@ 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'; +const MOCK_PROFILE_REQ_URL = 'https://api.topcoder-dev.com/v3/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_GROUPS_REQ_URL: + content = ['Group1', 'Group2']; + break; + case MOCK_PROFILE_REQ_URL: + content = { result: { content: { userId: 12345 }, status: 200 } }; + break; default: throw new Error('Unexpected URL!'); } return content; pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy