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

Commit 2a6738d

Browse files
committed
Merge branch 'develop'
2 parents 81f76d4 + 34dbc0b commit 2a6738d

File tree

8 files changed

+94
-40
lines changed

8 files changed

+94
-40
lines changed

ReadMe.md

Lines changed: 5 additions & 2 deletions
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ module.exports = {
4343
SUBMISSION_PHASE_ID: process.env.SUBMISSION_PHASE_ID || '6950164f-3c5e-4bdc-abc8-22aaf5a1bd49',
4444
CHECKPOINT_SUBMISSION_PHASE_ID: process.env.CHECKPOINT_SUBMISSION_PHASE_ID || 'd8a2cdbe-84d1-4687-ab75-78a6a7efdcc8',
4545

46-
// Challenge Type IDs
47-
TASK_TYPE_ID: process.env.TASK_TYPE_ID || 'e885273d-aeda-42c0-917d-bfbf979afbba'
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'
4850
}

docker/api.env

Lines changed: 1 addition & 1 deletion
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

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
const _ = require('lodash')
2+
const config = require('config')
3+
14
/**
25
* constants
36
*/
@@ -45,10 +48,32 @@ const challengeStatuses = {
4548
CancelledZeroRegistrations: 'Cancelled - Zero Registrations'
4649
}
4750

51+
const challengeTracks = {
52+
DEVELOP: 'DEVELOP',
53+
DESIGN: 'DESIGN',
54+
DATA_SCIENCE: 'DATA_SCIENCE',
55+
QA: 'QA'
56+
}
57+
4858
const challengeAbbreviations = {
4959
TASK: 'TASK',
5060
FIRST_2_FINISH: 'FIRST_2_FINISH',
51-
DESIGN_FIRST_2_FINISH: 'DESIGN_FIRST_2_FINISH'
61+
DESIGN_FIRST_2_FINISH: 'DESIGN_FIRST_2_FINISH',
62+
CODE: 'CODE',
63+
APPLICATION_FRONT_END_DESIGN: 'APPLICATION_FRONT_END_DESIGN'
64+
}
65+
66+
const legacySubTrackMapping = {
67+
[_.toLower(challengeTracks.DEVELOP)]: {
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
71+
},
72+
[_.toLower(challengeTracks.DESIGN)]: {
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
76+
}
5277
}
5378

5479
module.exports = {
@@ -57,5 +82,7 @@ module.exports = {
5782
EVENT_MIME_TYPE,
5883
createChallengeStatusesMap,
5984
challengeStatuses,
60-
challengeAbbreviations
85+
challengeAbbreviations,
86+
challengeTracks,
87+
legacySubTrackMapping
6188
}

src/services/ProcessorService.js

Lines changed: 47 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,49 @@ async function getDirectProjectId (m2mToken, projectId) {
5555
return response.body
5656
}
5757

58+
/**
59+
* Get legacy challenge track and subTrack values based on the v5 legacy.track and typeId
60+
* @param {String} legacyTrack the legacy.track value from the v5 challenge object
61+
* @param {String} typeId the v5 type ID
62+
* @param {String} m2mToken the M2M token
63+
*/
64+
async function getLegacyTrackInformation (legacyTrack, typeId, m2mToken) {
65+
const data = {
66+
track: _.toUpper(legacyTrack)
67+
}
68+
if (_.isUndefined(data.track)) {
69+
throw new Error(`Cannot create a challenge without a track. Please use one of [${_.values(constants.challengeTracks).join(', ')}]`)
70+
}
71+
if (_.isUndefined(typeId)) {
72+
throw new Error('Cannot create a challenge without a typeId.')
73+
}
74+
75+
// Use the configured subTrack if set for the given track/typeId
76+
if (constants.legacySubTrackMapping[_.toLower(legacyTrack)] && constants.legacySubTrackMapping[_.toLower(legacyTrack)][typeId]) {
77+
data.subTrack = constants.legacySubTrackMapping[_.toLower(legacyTrack)][typeId]
78+
} else {
79+
// otherwise fetch v4 challenge type based on the v5 type.legacyId
80+
const v5Type = await helper.getRequest(`${config.V5_CHALLENGE_TYPE_API_URL}/${typeId}`, m2mToken)
81+
const v4TypeList = await helper.getRequest(`${config.V4_CHALLENGE_TYPE_API_URL}`, m2mToken)
82+
const v4Type = _.find(_.get(v4TypeList, 'body.result.content', []), type => type.id === v5Type.body.legacyId)
83+
if (!v4Type) {
84+
throw new Error(`There is no mapping between v5 Type ${v5Type.body.name} and V4`)
85+
}
86+
data.subTrack = v4Type.subTrack
87+
data.legacyTypeId = v5Type.body.legacyId
88+
}
89+
90+
// If it's a private task, set the `task` property to `true`
91+
if (typeId === config.TASK_TYPE_ID) {
92+
// Tasks can only be created for the develop and design tracks
93+
if (data.track !== constants.challengeTracks.DEVELOP && data.track !== constants.challengeTracks.DESIGN) {
94+
throw new Error(`Cannot create a task for track ${data.track}`)
95+
}
96+
data.task = true
97+
}
98+
return data
99+
}
100+
58101
/**
59102
* Construct DTO from Kafka message payload.
60103
* @param {Object} payload the Kafka message payload
@@ -71,8 +114,11 @@ async function parsePayload (payload, m2mToken, isCreated = true) {
71114
projectId = _.get((await getDirectProjectId(m2mToken, payload.projectId)), 'directProjectId')
72115
if (!projectId) throw new Error(`Could not find Direct Project ID for Project ${payload.projectId}`)
73116
}
117+
118+
const legacyTrackInfo = await getLegacyTrackInformation(_.get(payload, 'legacy.track'), payload.typeId, m2mToken)
119+
74120
const data = {
75-
track: _.get(payload, 'legacy.track'), // FIXME: thomas
121+
...legacyTrackInfo,
76122
name: payload.name,
77123
reviewType: _.get(payload, 'legacy.reviewType'),
78124
projectId,
@@ -94,30 +140,6 @@ async function parsePayload (payload, m2mToken, isCreated = true) {
94140
data.submissionVisibility = true
95141
data.milestoneId = 1
96142
}
97-
if (payload.typeId) {
98-
const v5Type = await helper.getRequest(`${config.V5_CHALLENGE_TYPE_API_URL}/${payload.typeId}`, m2mToken)
99-
const v4TypeList = await helper.getRequest(`${config.V4_CHALLENGE_TYPE_API_URL}`, m2mToken)
100-
const v4Type = _.find(_.get(v4TypeList, 'body.result.content', []), type => type.id === v5Type.body.legacyId)
101-
if (!v4Type) {
102-
throw new Error(`There is no mapping between v5 Type ${v5Type.body.name} and V4`)
103-
}
104-
data.subTrack = v4Type.subTrack
105-
// TASK is named as FIRST_2_FINISH on legacy
106-
if (v5Type.body.abbreviation === constants.challengeAbbreviations.TASK) {
107-
data.task = true
108-
switch (_.toLower(_.toString(data.track))) {
109-
case 'develop':
110-
data.subTrack = constants.challengeAbbreviations.FIRST_2_FINISH
111-
break
112-
case 'design':
113-
data.subTrack = constants.challengeAbbreviations.DESIGN_FIRST_2_FINISH
114-
break
115-
default:
116-
throw new Error(`Cannot create a task for track ${data.track}`)
117-
}
118-
}
119-
data.legacyTypeId = v5Type.body.legacyId
120-
}
121143
if (payload.description) {
122144
try {
123145
data.detailedRequirements = converter.makeHtml(payload.description)

test/e2e/test.js

Lines changed: 3 additions & 3 deletions
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

Lines changed: 3 additions & 3 deletions
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)