Skip to content
This repository was archived by the owner on Jan 23, 2025. It is now read-only.

Commit 34dbc0b

Browse files
move challenge type IDs to configs instead of constants
1 parent d4c4a9f commit 34dbc0b

File tree

8 files changed

+30
-28
lines changed

8 files changed

+30
-28
lines changed

ReadMe.md

+5-2
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,13 @@ The following parameters can be set in config files or in env variables:
4545
- AUTH0_CLIENT_SECRET: Auth0 client secret, used to get TC M2M token
4646
- AUTH0_PROXY_SERVER_URL: Proxy Auth0 URL, used to get TC M2M token
4747
- V5_CHALLENGE_API_URL: v5 challenge api url, default value is 'http://localhost:4000/v5/challenges'
48-
- V5_CHALLENGE_TYPE_API_URL: v5 challenge type api url, default value is 'http://localhost:4000/v5/challengeTypes'
48+
- V5_CHALLENGE_TYPE_API_URL: v5 challenge type api url, default value is 'http://localhost:4000/v5/challenge-types'
4949
- V4_CHALLENGE_API_URL: v4 challenge api url, default value is 'http://localhost:4000/v4/challenges'
5050
- V4_TECHNOLOGIES_API_URL: v4 technologies api url, default value is 'http://localhost:4000/v4/technologies'
5151
- V4_PLATFORMS_API_URL: v4 platforms api url, default value is 'http://localhost:4000/v4/platforms'
52+
- TASK_TYPE_ID: The v5 Type ID for tasks
53+
- CHALLENGE_TYPE_ID: The v5 Type ID for regular challenges
54+
- FIRST_2_FINISH_TYPE_ID: The v5 Type ID for F2F challenges
5255

5356
There is a `/health` endpoint that checks for the health of the app. This sets up an expressjs server and listens on the environment variable `PORT`. It's not part of the configuration file and needs to be passed as an environment variable
5457

@@ -142,7 +145,7 @@ Please see that 192.168.1.3 is the IP of host machine for docker where we run al
142145
```
143146
KAFKA_URL=192.168.1.3:9092
144147
V5_CHALLENGE_API_URL=http://192.168.1.3:4000/v5/challenges
145-
V5_CHALLENGE_TYPE_API_URL=http://192.168.1.3:4000/v5/challengeTypes
148+
V5_CHALLENGE_TYPE_API_URL=http://192.168.1.3:4000/v5/challenge-types
146149
V4_CHALLENGE_API_URL=http://192.168.1.3:4000/v4/challenges
147150
V4_TECHNOLOGIES_API_URL=http://192.168.1.3:4000/v4/technologies
148151
V4_PLATFORMS_API_URL=http://192.168.1.3:4000/v4/platforms

Verification.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ debug: Successfully processed message
6969
4. Check the mock-api logs:
7070

7171
```sql
72-
debug: GET /v5/challengeTypes/0b2ac310-eaf0-40e3-b66b-37e5e9e09365
72+
debug: GET /v5/challenge-types/0b2ac310-eaf0-40e3-b66b-37e5e9e09365
7373
debug: GET /v4/technologies
7474
debug: GET /v4/platforms
7575
debug: POST /v4/challenges
@@ -152,7 +152,7 @@ debug: Successfully processed message
152152
8. Watch the logs of mock-api :
153153

154154
```bash
155-
debug: GET /v5/challengeTypes/d0f8ad73-d9c6-4dbc-b213-e643f43d28e7
155+
debug: GET /v5/challenge-types/d0f8ad73-d9c6-4dbc-b213-e643f43d28e7
156156
debug: GET /v4/technologies
157157
debug: GET /v4/platforms
158158
debug: GET /v4/challenges/30055016

config/default.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -41,5 +41,10 @@ module.exports = {
4141
// PHASE IDs
4242
REGISTRATION_PHASE_ID: process.env.REGISTRATION_PHASE_ID || 'a93544bc-c165-4af4-b55e-18f3593b457a',
4343
SUBMISSION_PHASE_ID: process.env.SUBMISSION_PHASE_ID || '6950164f-3c5e-4bdc-abc8-22aaf5a1bd49',
44-
CHECKPOINT_SUBMISSION_PHASE_ID: process.env.CHECKPOINT_SUBMISSION_PHASE_ID || 'd8a2cdbe-84d1-4687-ab75-78a6a7efdcc8'
44+
CHECKPOINT_SUBMISSION_PHASE_ID: process.env.CHECKPOINT_SUBMISSION_PHASE_ID || 'd8a2cdbe-84d1-4687-ab75-78a6a7efdcc8',
45+
46+
// challenge types
47+
TASK_TYPE_ID: process.env.TASK_TYPE_ID || 'e885273d-aeda-42c0-917d-bfbf979afbba',
48+
CHALLENGE_TYPE_ID: process.env.CHALLENGE_TYPE_ID || '94eee466-9255-4b60-88d8-4f59c1810dd0',
49+
FIRST_2_FINISH_TYPE_ID: process.env.FIRST_2_FINISH_TYPE_ID || '6950164f-3c5e-4bdc-abc8-22aaf5a1bd49'
4550
}

docker/api.env

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
KAFKA_URL=192.168.1.3:9092
22
V5_CHALLENGE_API_URL=http://192.168.1.3:4000/v5/challenges
3-
V5_CHALLENGE_TYPE_API_URL=http://192.168.1.3:4000/v5/challengeTypes
3+
V5_CHALLENGE_TYPE_API_URL=http://192.168.1.3:4000/v5/challenge-types
44
V4_CHALLENGE_API_URL=http://192.168.1.3:4000/v4/challenges
55
V4_TECHNOLOGIES_API_URL=http://192.168.1.3:4000/v4/technologies
66
V4_PLATFORMS_API_URL=http://192.168.1.3:4000/v4/platforms

src/constants.js

+8-14
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
const _ = require('lodash')
2+
const config = require('config')
23

34
/**
45
* constants
@@ -47,12 +48,6 @@ const challengeStatuses = {
4748
CancelledZeroRegistrations: 'Cancelled - Zero Registrations'
4849
}
4950

50-
const challengeTypes = {
51-
TASK_TYPE_ID: 'e885273d-aeda-42c0-917d-bfbf979afbba',
52-
CHALLENGE_TYPE_ID: '94eee466-9255-4b60-88d8-4f59c1810dd0',
53-
FIRST_2_FINISH_TYPE_ID: '6950164f-3c5e-4bdc-abc8-22aaf5a1bd49'
54-
}
55-
5651
const challengeTracks = {
5752
DEVELOP: 'DEVELOP',
5853
DESIGN: 'DESIGN',
@@ -70,14 +65,14 @@ const challengeAbbreviations = {
7065

7166
const legacySubTrackMapping = {
7267
[_.toLower(challengeTracks.DEVELOP)]: {
73-
[challengeTypes.TASK_TYPE_ID]: challengeAbbreviations.FIRST_2_FINISH,
74-
[challengeTypes.CHALLENGE_TYPE_ID]: challengeAbbreviations.CODE,
75-
[challengeTypes.FIRST_2_FINISH_TYPE_ID]: challengeAbbreviations.FIRST_2_FINISH
68+
[config.TASK_TYPE_ID]: challengeAbbreviations.FIRST_2_FINISH,
69+
[config.CHALLENGE_TYPE_ID]: challengeAbbreviations.CODE,
70+
[config.FIRST_2_FINISH_TYPE_ID]: challengeAbbreviations.FIRST_2_FINISH
7671
},
7772
[_.toLower(challengeTracks.DESIGN)]: {
78-
[challengeTypes.TASK_TYPE_ID]: challengeAbbreviations.DESIGN_FIRST_2_FINISH,
79-
[challengeTypes.CHALLENGE_TYPE_ID]: challengeAbbreviations.APPLICATION_FRONT_END_DESIGN,
80-
[challengeTypes.FIRST_2_FINISH_TYPE_ID]: challengeAbbreviations.DESIGN_FIRST_2_FINISH
73+
[config.TASK_TYPE_ID]: challengeAbbreviations.DESIGN_FIRST_2_FINISH,
74+
[config.CHALLENGE_TYPE_ID]: challengeAbbreviations.APPLICATION_FRONT_END_DESIGN,
75+
[config.FIRST_2_FINISH_TYPE_ID]: challengeAbbreviations.DESIGN_FIRST_2_FINISH
8176
}
8277
}
8378

@@ -89,6 +84,5 @@ module.exports = {
8984
challengeStatuses,
9085
challengeAbbreviations,
9186
challengeTracks,
92-
legacySubTrackMapping,
93-
challengeTypes
87+
legacySubTrackMapping
9488
}

src/services/ProcessorService.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ async function getLegacyTrackInformation (legacyTrack, typeId, m2mToken) {
8888
}
8989

9090
// If it's a private task, set the `task` property to `true`
91-
if (typeId === constants.challengeTypes.TASK_TYPE_ID) {
91+
if (typeId === config.TASK_TYPE_ID) {
9292
// Tasks can only be created for the develop and design tracks
9393
if (data.track !== constants.challengeTracks.DEVELOP && data.track !== constants.challengeTracks.DESIGN) {
9494
throw new Error(`Cannot create a task for track ${data.track}`)
@@ -353,7 +353,7 @@ async function processUpdate (message) {
353353
if (message.payload.status === constants.challengeStatuses.Completed && challenge.currentStatus !== constants.challengeStatuses.Completed) {
354354
const challengeUuid = message.payload.id
355355
const v5Challenge = await helper.getRequest(`${config.V5_CHALLENGE_API_URL}/${challengeUuid}`, m2mToken)
356-
if (v5Challenge.body.typeId === constants.challengeTypes.TASK_TYPE_ID) {
356+
if (v5Challenge.body.typeId === config.TASK_TYPE_ID) {
357357
logger.info('Challenge type is TASK')
358358
if (!message.payload.winners || message.payload.winners.length === 0) {
359359
throw new Error('Cannot close challenge without winners')

test/e2e/test.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ describe('Topcoder - Legacy Challenge Processor E2E Test', () => {
215215
await sendMessage(testTopics.create)
216216
await waitJob()
217217

218-
should.equal(debugLogs[3], 'GET /v5/challengeTypes/2f4ef3a8-ed35-40d1-b8a6-7371a700d098')
218+
should.equal(debugLogs[3], 'GET /v5/challenge-types/2f4ef3a8-ed35-40d1-b8a6-7371a700d098')
219219
should.equal(debugLogs[4], 'GET /v4/technologies')
220220
should.equal(debugLogs[5], 'GET /v4/platforms')
221221
should.equal(debugLogs[8], 'POST /v4/challenges')
@@ -258,7 +258,7 @@ describe('Topcoder - Legacy Challenge Processor E2E Test', () => {
258258
await sendMessage(testTopics.update)
259259
await waitJob()
260260

261-
should.equal(debugLogs[3], 'GET /v5/challengeTypes/2f4ef3a8-ed35-40d1-b8a6-7371a700d098')
261+
should.equal(debugLogs[3], 'GET /v5/challenge-types/2f4ef3a8-ed35-40d1-b8a6-7371a700d098')
262262
should.equal(debugLogs[4], 'GET /v4/technologies')
263263
should.equal(debugLogs[5], 'GET /v4/platforms')
264264
should.equal(debugLogs[8], 'PUT /v4/challenges/30055016')
@@ -279,7 +279,7 @@ describe('Topcoder - Legacy Challenge Processor E2E Test', () => {
279279
await sendMessage(message)
280280
await waitJob()
281281

282-
should.equal(debugLogs[3], 'GET /v5/challengeTypes/2f4ef3a8-ed35-40d1-b8a6-7371a700d098')
282+
should.equal(debugLogs[3], 'GET /v5/challenge-types/2f4ef3a8-ed35-40d1-b8a6-7371a700d098')
283283
should.equal(debugLogs[4], 'GET /v4/technologies')
284284
should.equal(debugLogs[5], 'GET /v4/platforms')
285285
should.equal(debugLogs[8], 'PUT /v4/challenges/30055016')

test/unit/test.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ describe('Topcoder - Legacy Challenge Processor Unit Test', () => {
9595

9696
it('process create challenge success', async () => {
9797
await service.processCreate(testTopics.create)
98-
should.equal(debugLogs[3], 'GET /v5/challengeTypes/2f4ef3a8-ed35-40d1-b8a6-7371a700d098')
98+
should.equal(debugLogs[3], 'GET /v5/challenge-types/2f4ef3a8-ed35-40d1-b8a6-7371a700d098')
9999
should.equal(debugLogs[4], 'GET /v4/technologies')
100100
should.equal(debugLogs[5], 'GET /v4/platforms')
101101
should.equal(debugLogs[8], 'POST /v4/challenges')
@@ -140,7 +140,7 @@ describe('Topcoder - Legacy Challenge Processor Unit Test', () => {
140140

141141
it('process update challenge success', async () => {
142142
await service.processUpdate(testTopics.update)
143-
should.equal(debugLogs[3], 'GET /v5/challengeTypes/2f4ef3a8-ed35-40d1-b8a6-7371a700d098')
143+
should.equal(debugLogs[3], 'GET /v5/challenge-types/2f4ef3a8-ed35-40d1-b8a6-7371a700d098')
144144
should.equal(debugLogs[7], 'GET /v4/challenges/30055016')
145145
should.equal(debugLogs[8], 'PUT /v4/challenges/30055016')
146146
const body = JSON.parse(debugLogs[9])
@@ -158,7 +158,7 @@ describe('Topcoder - Legacy Challenge Processor Unit Test', () => {
158158
const message = _.cloneDeep(testTopics.update)
159159
message.payload.prizeSets = [{ type: 'Check Point', prizes: [{ type: 'first-place', value: 1 }] }]
160160
await service.processUpdate(message)
161-
should.equal(debugLogs[3], 'GET /v5/challengeTypes/2f4ef3a8-ed35-40d1-b8a6-7371a700d098')
161+
should.equal(debugLogs[3], 'GET /v5/challenge-types/2f4ef3a8-ed35-40d1-b8a6-7371a700d098')
162162
should.equal(debugLogs[7], 'GET /v4/challenges/30055016')
163163
should.equal(debugLogs[8], 'PUT /v4/challenges/30055016')
164164
const body = JSON.parse(debugLogs[9])

0 commit comments

Comments
 (0)