From c49690670eaa47a906d7c7574517fa788f87b993 Mon Sep 17 00:00:00 2001 From: Vasilica Date: Fri, 29 Jul 2022 17:30:37 +0300 Subject: [PATCH 1/7] PROD-2487 - Add functionality to handle api for TcAcademy certifications --- src/actions/index.js | 2 ++ src/actions/tc-academy.js | 35 +++++++++++++++++++++ src/reducers/index.js | 3 ++ src/reducers/tc-academy.js | 63 ++++++++++++++++++++++++++++++++++++++ src/services/index.js | 2 ++ src/services/tc-academy.js | 37 ++++++++++++++++++++++ 6 files changed, 142 insertions(+) create mode 100644 src/actions/tc-academy.js create mode 100644 src/reducers/tc-academy.js create mode 100644 src/services/tc-academy.js diff --git a/src/actions/index.js b/src/actions/index.js index b053ae50..5e7e1d53 100644 --- a/src/actions/index.js +++ b/src/actions/index.js @@ -15,6 +15,7 @@ import settingsActions from './settings'; import lookerActions from './looker'; import memberSearchActions from './member-search'; import notificationActions from './notifications'; +import tcAcademyActions from './tc-academy'; export const actions = { auth: authActions.auth, @@ -34,6 +35,7 @@ export const actions = { looker: lookerActions.looker, memberSearch: memberSearchActions.memberSearch, notifications: notificationActions.notifications, + tcAcademy: tcAcademyActions.tcAcademy, }; export default undefined; diff --git a/src/actions/tc-academy.js b/src/actions/tc-academy.js new file mode 100644 index 00000000..0ecbae9c --- /dev/null +++ b/src/actions/tc-academy.js @@ -0,0 +1,35 @@ +import { redux } from 'topcoder-react-utils'; +import { getService } from 'services/tc-academy'; + +const tcAcademyService = getService(); + +/** + * @static + * @desc Creates an action that signals beginning of user tc-academy certifications loading. + * @return {Action} + */ +function getTcaCertificationsInit(userId) { + return { userId }; +} + +/** + * @static + * @desc Creates an action that loads user tc-academy certifications from API v2. + * @param {String} userId User id. + * @return {Action} + */ +async function getTcaCertificationsDone(userId) { + const res = await tcAcademyService.getCertifications(userId); + + return { + userId, + certifications: res, + }; +} + +export default redux.createActions({ + TC_ACADEMY: { + GET_TCA_CERTIFICATIONS_INIT: getTcaCertificationsInit, + GET_TCA_CERTIFICATIONS_DONE: getTcaCertificationsDone, + }, +}); diff --git a/src/reducers/index.js b/src/reducers/index.js index e016d5b0..49a78503 100644 --- a/src/reducers/index.js +++ b/src/reducers/index.js @@ -13,6 +13,7 @@ import challenge, { factory as challengeFactory } from './challenge'; import profile, { factory as profileFactory } from './profile'; import members, { factory as membersFactory } from './members'; import notifications, { factory as notificationsFactory } from './notifications'; +import tcAcademy, { factory as tcAcademyFactory } from './tc-academy'; import lookup, { factory as lookupFactory } from './lookup'; import memberTasks, { factory as memberTasksFactory } from './member-tasks'; import reviewOpportunity, { factory as reviewOpportunityFactory } @@ -44,6 +45,7 @@ export function factory(options) { looker: lookerFactory(options), memberSearch: memberSearchFactory(options), notifications: notificationsFactory(options), + tcAcademy: tcAcademyFactory(options), }); } @@ -65,4 +67,5 @@ export default ({ looker, memberSearch, notifications, + tcAcademy, }); diff --git a/src/reducers/tc-academy.js b/src/reducers/tc-academy.js new file mode 100644 index 00000000..a893cf1a --- /dev/null +++ b/src/reducers/tc-academy.js @@ -0,0 +1,63 @@ +/** + * Reducer for TC Academy + */ + +import { handleActions } from 'redux-actions'; +import actions from 'actions/tc-academy'; + +/** + * Handles TCACADEMY/GET_TCA_CERTIFICATIONS_INIT action. + * @param {Object} state + * @return {Object} New state + */ +function onGetTcaCertificationsInit(state) { + return { + ...state, + certifications: [], + failed: false, + loading: true, + }; +} + +/** + * Handles TCACADEMY/GET_TCA_CERTIFICATIONS_DONE actions. + * @param {Object} state Previous state. + * @param {Object} action Action. + */ +function onGetTcaCertificationsDone(state, action) { + return { + ...state, + certifications: [], + ...(action.error ? {} : action.payload), + failed: action.error, + loading: false, + }; +} + +/** + * Creates a new challenges reducer with the specified initial state. + * @param {Object} initialState Optional. Initial state. + * @return challenges reducer. + */ +function create(initialState) { + const a = actions.tcAcademy; + + return handleActions({ + [a.getTcaCertificationsInit]: onGetTcaCertificationsInit, + [a.getTcaCertificationsDone]: onGetTcaCertificationsDone, + }, initialState || {}); +} + +/** + * Factory which creates a new reducer with its initial state tailored to the + * given options object, if specified (for server-side rendering). If options + * object is not specified, it creates just the default reducer. Accepted options are: + * @return {Promise} + * @resolves {Function(state, action): state} New reducer. + */ +export function factory() { + return Promise.resolve(create()); +} + +/* Default reducer with empty initial state. */ +export default create(); diff --git a/src/services/index.js b/src/services/index.js index 76e2c457..7907db9d 100644 --- a/src/services/index.js +++ b/src/services/index.js @@ -17,6 +17,7 @@ import * as userTraits from './user-traits'; import * as submissions from './submissions'; import * as memberSearch from './member-search'; import * as notifications from './notifications'; +import * as tcAcademy from './tc-academy'; export const services = { api, @@ -35,6 +36,7 @@ export const services = { submissions, memberSearch, notifications, + tcAcademy, }; export default undefined; diff --git a/src/services/tc-academy.js b/src/services/tc-academy.js new file mode 100644 index 00000000..e1256686 --- /dev/null +++ b/src/services/tc-academy.js @@ -0,0 +1,37 @@ +import { getApi } from './api'; + +/** + * Topcoder Academy service class + */ +class TcAcademyService { + constructor() { + this.private = { + api: getApi('V5'), + }; + } + + /** + * + * @param {string} userId Get all user's certifications (completed) + * @returns + */ + getCertifications(userId) { + return this.private.api.get(`/learning-paths/completed-certifications/${userId}`) + .then(res => (res.ok ? res.json() : new Error(res.statusText))); + } +} + +/** + * Returns a new or existing service instance. + * @return {TcAcademyService} Topcoder Academy service instance + */ +let lastInstance = null; +export function getService() { + if (!lastInstance) { + lastInstance = new TcAcademyService(); + } + return lastInstance; +} + +/* Using default export would be confusing in this case. */ +export default undefined; From 06d84d570d69f4c9bac9f5c61ae1ae343bae65f5 Mon Sep 17 00:00:00 2001 From: Vasilica Date: Fri, 29 Jul 2022 17:35:29 +0300 Subject: [PATCH 2/7] update test snapshots --- __tests__/__snapshots__/index.js.snap | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/__tests__/__snapshots__/index.js.snap b/__tests__/__snapshots__/index.js.snap index 351b4e3c..322e47a7 100644 --- a/__tests__/__snapshots__/index.js.snap +++ b/__tests__/__snapshots__/index.js.snap @@ -206,6 +206,10 @@ Object { "getCommunityStatsDone": [Function], "getCommunityStatsInit": [Function], }, + "tcAcademy": Object { + "getTcaCertificationsDone": [Function], + "getTcaCertificationsInit": [Function], + }, "terms": Object { "agreeTermDone": [Function], "agreeTermInit": [Function], @@ -288,6 +292,7 @@ Object { "reviewOpportunity": [Function], "settings": [Function], "stats": [Function], + "tcAcademy": [Function], "terms": [Function], }, "services": Object { @@ -354,6 +359,10 @@ Object { "default": undefined, "getService": [Function], }, + "tcAcademy": Object { + "default": undefined, + "getService": [Function], + }, "terms": Object { "default": undefined, "getService": [Function], From cc1a3d877583ee27f109a7be4e8536d0baa14ce4 Mon Sep 17 00:00:00 2001 From: Luiz Ricardo Rodrigues Date: Wed, 3 Aug 2022 01:30:17 -0300 Subject: [PATCH 3/7] ci: added tag test-release --- .circleci/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 0e161844..e8eac28e 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -28,7 +28,7 @@ jobs: - attach_workspace: at: . - run: echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" >> ~/.npmrc - - run: npm publish + - run: npm publish --tag test-release # dont change anything workflows: version: 2 From f1159b061e12a17951484616c5622752fe237bd6 Mon Sep 17 00:00:00 2001 From: Luiz Ricardo Rodrigues Date: Wed, 3 Aug 2022 01:31:06 -0300 Subject: [PATCH 4/7] fix: for issue PROD-2487 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index f1328538..a116be79 100644 --- a/package.json +++ b/package.json @@ -31,7 +31,7 @@ "lint:js": "./node_modules/.bin/eslint --ext .js,.jsx .", "test": "npm run lint && npm run jest" }, - "version": "1.2.7", + "version": "1000.29.6", "dependencies": { "auth0-js": "^6.8.4", "config": "^3.2.0", From e60ba9297da299e5d0520d8360bdb332119baae5 Mon Sep 17 00:00:00 2001 From: Luiz Ricardo Rodrigues Date: Fri, 5 Aug 2022 00:44:33 -0300 Subject: [PATCH 5/7] fix: for issue PROD-2487 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index a116be79..13f30527 100644 --- a/package.json +++ b/package.json @@ -31,7 +31,7 @@ "lint:js": "./node_modules/.bin/eslint --ext .js,.jsx .", "test": "npm run lint && npm run jest" }, - "version": "1000.29.6", + "version": "1000.29.7", "dependencies": { "auth0-js": "^6.8.4", "config": "^3.2.0", From 72ade95228078acf31872e30c20152bbd712efc6 Mon Sep 17 00:00:00 2001 From: Luiz Ricardo Rodrigues Date: Fri, 5 Aug 2022 02:55:06 -0300 Subject: [PATCH 6/7] ci: remove tag test-release --- .circleci/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index e8eac28e..0e161844 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -28,7 +28,7 @@ jobs: - attach_workspace: at: . - run: echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" >> ~/.npmrc - - run: npm publish --tag test-release + - run: npm publish # dont change anything workflows: version: 2 From 1113bd0a1ca3522985cb6d7cda2ac644bdeef051 Mon Sep 17 00:00:00 2001 From: Luiz Ricardo Rodrigues Date: Fri, 5 Aug 2022 02:56:09 -0300 Subject: [PATCH 7/7] fix: for issue PROD-2487 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 13f30527..78ff4f26 100644 --- a/package.json +++ b/package.json @@ -31,7 +31,7 @@ "lint:js": "./node_modules/.bin/eslint --ext .js,.jsx .", "test": "npm run lint && npm run jest" }, - "version": "1000.29.7", + "version": "1.2.8", "dependencies": { "auth0-js": "^6.8.4", "config": "^3.2.0",