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

Commit 983f74e

Browse files
Merge branch 'develop' into dynamodb
2 parents 706a217 + 6e04ab5 commit 983f74e

File tree

13 files changed

+383
-380
lines changed

13 files changed

+383
-380
lines changed

config/default.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ module.exports = {
99
VALID_ISSUERS: process.env.VALID_ISSUERS ? process.env.VALID_ISSUERS.replace(/\\"/g, '')
1010
: '["https://topcoder-dev.auth0.com/", "https://api.topcoder.com"]',
1111

12-
CHALLENGE_API_URL: process.env.CHALLENGE_API_URL || 'https://api.topcoder-dev.com/%3Cspan%20class="x x-first x-last">v4/challenges',
13-
MEMBER_API_URL: process.env.MEMBER_API_URL || 'https://api.topcoder-dev.com/%3Cspan%20class="x x-first x-last">v3/users',
12+
CHALLENGE_API_URL: process.env.CHALLENGE_API_URL || 'https://api.topcoder-dev.com/%3Cspan%20class="x x-first x-last">v5/challenges',
13+
MEMBER_API_URL: process.env.MEMBER_API_URL || 'https://api.topcoder-dev.com/%3Cspan%20class="x x-first x-last">v5/members',
1414

1515
SCORE_RESET_TIME: process.env.SCORE_RESET_TIME || 10000, // 10 seconds default
1616

config/test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*/
44

55
module.exports = {
6-
CHALLENGE_API_URL: 'https://api.topcoder-dev.com/%3Cspan%20class="x x-first x-last">v4/challenges',
7-
MEMBER_API_URL: 'https://api.topcoder-dev.com/%3Cspan%20class="x x-first x-last">v3/users',
6+
CHALLENGE_API_URL: 'https://api.topcoder-dev.com/%3Cspan%20class="x x-first x-last">v5/challenges',
7+
MEMBER_API_URL: 'https://api.topcoder-dev.com/%3Cspan%20class="x x-first x-last">v5/members',
88
MOCK_API_PORT: 3001
99
}

package-lock.json

Lines changed: 317 additions & 194 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@
3535
"get-parameter-names": "^0.3.0",
3636
"http-status-codes": "^1.3.0",
3737
"joi": "^14.0.0",
38-
"lodash": "^4.17.15",
38+
"lodash": "^4.17.19",
39+
"mongoose": "^5.7.5",
3940
"superagent": "^5.1.0",
4041
"tc-core-library-js": "appirio-tech/tc-core-library-js.git#v2.6.3",
4142
"uuid": "^8.3.1",

scripts/test-data.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ const insertData = async () => {
8383
totalTestCases: 6,
8484
groupIds: ['100']
8585
})
86-
for (const groupId of [202343, 20000000, 100, 200]) {
86+
for (const groupId of ['202343', '20000000', '100', '200']) {
8787
await Group.create({
8888
groupId
8989
})

src/common/helper.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ const m2m = m2mAuth(_.pick(config, ['AUTH0_URL', 'AUTH0_AUDIENCE', 'TOKEN_CACHE_
1818
const isGroupIdValid = async (groupIds) => {
1919
// Get the Group IDs from config
2020
const confGroupIds = _.map(await models.Group.scan().all().exec(), (group) => group.groupId)
21-
if (_.intersectionBy(confGroupIds, groupIds, parseInt).length !== 0) {
21+
if (_.intersection(confGroupIds, groupIds).length !== 0) {
2222
return true
2323
}
2424
return false

src/models/Group.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const Schema = dynamoose.Schema
99

1010
const GroupSchema = new Schema({
1111
groupId: {
12-
type: Number,
12+
type: String,
1313
hashKey: true
1414
}
1515
}, {

src/services/GroupService.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ async function createGroup (groupId) {
2929
}
3030

3131
createGroup.schema = {
32-
groupId: joi.id().required()
32+
groupId: joi.string().required()
3333
}
3434

3535
/**
@@ -45,7 +45,7 @@ async function deleteGroup (groupId) {
4545
}
4646

4747
deleteGroup.schema = {
48-
groupId: joi.id().required()
48+
groupId: joi.string().required()
4949
}
5050

5151
module.exports = {

src/services/LeaderboardService.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -76,21 +76,21 @@ async function createLeaderboard (challengeId, memberId, review) {
7676
const { testsPassed, totalTestCases } = calculateResult(review)
7777

7878
const challengeDetailRes = await helper.reqToAPI(
79-
`${config.CHALLENGE_API_URL}?filter=id=${challengeId}`)
80-
const challenge = _.get(challengeDetailRes, 'body.result.content[0]')
79+
`${config.CHALLENGE_API_URL}?legacyId=${challengeId}`)
80+
const challenge = _.get(challengeDetailRes, 'body[0]')
8181
if (!challenge) {
8282
throw new errors.BadRequestError(`Challenge # ${challengeId} doesn't exist`)
8383
}
8484

85-
const groupIds = challenge.groupIds
85+
const groupIds = challenge.groups
8686
if (!(await helper.isGroupIdValid(groupIds))) {
87-
logger.debug(`Group ID (${JSON.stringify(groupIds)}) of Challenge # ${challengeId} does not exist`)
87+
logger.debug(`Group ID (${JSON.stringify(groupIds)}) of Challenge # ${challengeId} is not in the approved list. Ignoring request`)
8888
// Ignore the message
8989
return
9090
}
9191

92-
const memberDetailRes = await helper.reqToAPI(`${config.MEMBER_API_URL}?filter=id=${memberId}`)
93-
const member = _.get(memberDetailRes, 'body.result.content[0]')
92+
const memberDetailRes = await helper.reqToAPI(`${config.MEMBER_API_URL}?userId=${memberId}&fields=userId,handle`)
93+
const member = _.get(memberDetailRes, 'body[0]')
9494
if (!member) {
9595
throw new errors.BadRequestError(`Member # ${memberId} doesn't exist`)
9696
}

test/common/prepare.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,19 @@ prepare(function (done) {
1111
.persist()
1212
.post('/oauth/token')
1313
.reply(200, { access_token: M2M_FULL_TOKEN })
14-
.get('/v4/challenges?filter=id=30000001')
14+
.get('/v5/challenges?legacyId=30000001')
1515
.reply(200, challengeAPIResponse[0])
16-
.get('/v4/challenges?filter=id=30051825')
16+
.get('/v5/challenges?legacyId=30051825')
1717
.reply(200, challengeAPIResponse[1])
18-
.get('/v4/challenges?filter=id=30051826')
18+
.get('/v5/challenges?legacyId=30051826')
1919
.reply(200, challengeAPIResponse[2])
20-
.get('/v4/challenges?filter=id=31000000')
20+
.get('/v5/challenges?legacyId=31000000')
2121
.reply(200, challengeAPIResponse[3])
22-
.get('/v3/users?filter=id=10000')
22+
.get('/v5/members?userId=10000&fields=userId,handle')
2323
.reply(200, memberAPIResponse[0])
24-
.get('/v3/users?filter=id=8547899')
24+
.get('/v5/members?userId=8547899&fields=userId,handle')
2525
.reply(200, memberAPIResponse[1])
26-
.get('/v3/users?filter=id=22688726')
26+
.get('/v5/members?userId=22688726&fields=userId,handle')
2727
.reply(200, memberAPIResponse[2])
2828

2929
done()

test/common/testData.js

Lines changed: 30 additions & 151 deletions
Original file line numberDiff line numberDiff line change
@@ -36,160 +36,39 @@ const submissionAPIResponse = [
3636
]
3737

3838
const challengeAPIResponse = [
39-
{
40-
'id': '2587d0de:16de737ff0d:3225',
41-
'result': {
42-
'success': true,
43-
'status': 200,
44-
'metadata': null,
45-
'content': []
46-
},
47-
'version': 'v3'
48-
},
49-
{
50-
'id': '-3254eca5:16658dbed10:2c2a',
51-
'result': {
52-
'success': true,
53-
'status': 200,
54-
'metadata': {
55-
'fields': null,
56-
'totalCount': 1
57-
},
58-
'content': [
59-
{
60-
'groupIds': [
61-
20000000
62-
]
63-
}
64-
]
65-
}
66-
},
67-
{
68-
'id': '-3254eca5:16658dbed10:2c2a',
69-
'result': {
70-
'success': true,
71-
'status': 200,
72-
'metadata': {
73-
'fields': null,
74-
'totalCount': 1
75-
},
76-
'content': [
77-
{
78-
'groupIds': [
79-
202343,
80-
20000000
81-
]
82-
}
83-
]
84-
}
85-
},
86-
{
87-
'id': '-3254eca5:16658dbed10:2c2a',
88-
'result': {
89-
'success': true,
90-
'status': 200,
91-
'metadata': {
92-
'fields': null,
93-
'totalCount': 1
94-
},
95-
'content': [
96-
{
97-
'groupIds': [
98-
30000
99-
]
100-
}
101-
]
102-
}
103-
}
39+
[],
40+
[{
41+
'groups': [
42+
'20000000'
43+
]
44+
}],
45+
[{
46+
'groups': [
47+
'202343',
48+
'20000000'
49+
]
50+
}],
51+
[{
52+
'groups': [
53+
'30000'
54+
]
55+
}]
10456
]
10557

10658
const memberAPIResponse = [
107-
{
108-
'id': '2587d0de:16de737ff0d:3225',
109-
'result': {
110-
'success': true,
111-
'status': 200,
112-
'metadata': null,
113-
'content': []
114-
},
115-
'version': 'v3'
116-
},
117-
{
118-
'id': '311d312:166718c336c:1936',
119-
'result': {
120-
'success': true,
121-
'status': 200,
122-
'metadata': null,
123-
'content': [
124-
{
125-
'id': '8547899',
126-
'modifiedBy': null,
127-
'modifiedAt': '2018-10-14T02:53:38.000Z',
128-
'createdBy': null,
129-
'createdAt': '2004-03-21T21:05:32.000Z',
130-
'handle': 'TonyJ',
131-
'email': '[email protected]',
132-
'firstName': 'Tony',
133-
'lastName': 'L_NAME',
134-
'credential': {
135-
'activationCode': 'UASI7X0JS',
136-
'resetToken': null,
137-
'hasPassword': true
138-
},
139-
'status': 'A',
140-
'country': null,
141-
'regSource': null,
142-
'utmSource': null,
143-
'utmMedium': null,
144-
'utmCampaign': null,
145-
'roles': null,
146-
'ssoLogin': false,
147-
'active': true,
148-
'profile': null,
149-
'emailActive': true
150-
}
151-
]
152-
},
153-
'version': 'v3'
154-
},
155-
{
156-
'id': '2587d0de:16de737ff0d:3203',
157-
'result': {
158-
'success': true,
159-
'status': 200,
160-
'metadata': null,
161-
'content': [
162-
{
163-
'id': '22688726',
164-
'modifiedBy': null,
165-
'modifiedAt': '2019-10-16T03:39:37.000Z',
166-
'createdBy': null,
167-
'createdAt': '2007-07-05T05:25:12.000Z',
168-
'handle': 'vasyl',
169-
'email': '[email protected]',
170-
'firstName': 'F_NAME',
171-
'lastName': 'L_NAME',
172-
'credential': {
173-
'activationCode': 'MC8XPOC3Z7',
174-
'resetToken': null,
175-
'hasPassword': true
176-
},
177-
'status': 'A',
178-
'country': null,
179-
'regSource': null,
180-
'utmSource': null,
181-
'utmMedium': null,
182-
'utmCampaign': null,
183-
'roles': null,
184-
'ssoLogin': false,
185-
'profile': null,
186-
'active': true,
187-
'emailActive': true
188-
}
189-
]
190-
},
191-
'version': 'v3'
192-
}
59+
[],
60+
[
61+
{
62+
'userId': 8547899,
63+
'handle': 'TonyJ'
64+
}
65+
],
66+
[
67+
{
68+
'userId': 22688726,
69+
'handle': 'vasyl'
70+
}
71+
]
19372
]
19473

19574
const M2M_FULL_TOKEN = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJodHRwczovL3RvcGNvZGVyLWRldi5hdXRoMC5jb20vIiwic3ViIjoiOFFvdkRoMjdTckR1MVhTczY4bTIxQTFOQlA4aXN2T3RAY2xpZW50cyIsImF1ZCI6Imh0dHBzOi8vbTJtLnRvcGNvZGVyLWRldi5jb20vIiwiaWF0IjoxNjAzMjE4NjM1LCJleHAiOjIxNDc0ODM2NDgsImF6cCI6IjhRb3ZEaDI3U3JEdTFYU3M2OG0yMUExTkJQOGlzdk90Iiwic2NvcGUiOiJyZWFkOmNoYWxsZW5nZXMgcmVhZDpncm91cHMgcmVhZDpzdWJtaXNzaW9uIHJlYWQ6cmV2aWV3X3R5cGUgdXBkYXRlOnJldmlld19zdW1tYXRpb24gcmVhZDpyZXZpZXdfc3VtbWF0aW9uIGNyZWF0ZTpyZXZpZXdfc3VtbWF0aW9uIHVwZGF0ZTpyZXZpZXcgcmVhZDpyZXZpZXcgZGVsZXRlOnJldmlldyBjcmVhdGU6cmV2aWV3IGFsbDpyZXZpZXcgcmVhZDpwcm9qZWN0IHdyaXRlOmJ1c19hcGkgcmVhZDp1c2VyX3Byb2ZpbGVzIHJlYWQ6cm9sZXMgY3JlYXRlOmxlYWRlcmJvYXJkIHVwZGF0ZTpsZWFkZXJib2FyZCBkZWxldGU6bGVhZGVyYm9hcmQgYWxsOmxlYWRlcmJvYXJkIiwiZ3R5IjoiY2xpZW50LWNyZWRlbnRpYWxzIn0.wAv4YZhNXbPai9zKUfVFBhQ3vq6Itir8265WgybeBVk'

test/e2e/test.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,7 @@ describe('Topcoder - Leaderboard API E2E Tests', () => {
374374
score: 50
375375
})
376376
expect(res.status).to.equal(204)
377-
expect(debugLogs[3]).to.equal('Group ID ([30000]) of Challenge # 31000000 does not exist')
377+
expect(debugLogs[3]).to.equal('Group ID (["30000"]) of Challenge # 31000000 is not in the approved list. Ignoring request')
378378
})
379379
})
380380

@@ -477,21 +477,21 @@ describe('Topcoder - Leaderboard API E2E Tests', () => {
477477
const res = await chai.request(expressApp)
478478
.get(`/v5/leaderboard/groups`)
479479
expect(res.status).to.equal(200)
480-
expect(res.body).to.eql([202343, 100, 200, 20000000])
480+
expect(res.body).to.eql(['202343', '100', '20000000', '200'])
481481
})
482482
})
483483

484484
describe('create group test', async () => {
485485
it('create group success', async () => {
486-
const groupId = 300
486+
const groupId = '300'
487487
const res = await chai.request(expressApp)
488488
.post(`/v5/leaderboard/groups/${groupId}`)
489489
.set('Authorization', `Bearer ${M2M_FULL_TOKEN}`)
490490
expect(res.status).to.equal(200)
491491
expect(res.body).to.eql({ groupId })
492492
})
493493
it('failure - group wth specified groupId already exist', async () => {
494-
const groupId = 300
494+
const groupId = '300'
495495
const res = await chai.request(expressApp)
496496
.post(`/v5/leaderboard/groups/${groupId}`)
497497
.set('Authorization', `Bearer ${M2M_FULL_TOKEN}`)
@@ -502,14 +502,14 @@ describe('Topcoder - Leaderboard API E2E Tests', () => {
502502

503503
describe('delete group test', async () => {
504504
it('delete group success', async () => {
505-
const groupId = 300
505+
const groupId = '300'
506506
const res = await chai.request(expressApp)
507507
.delete(`/v5/leaderboard/groups/${groupId}`)
508508
.set('Authorization', `Bearer ${M2M_FULL_TOKEN}`)
509509
expect(res.status).to.equal(204)
510510
})
511511
it('failure - group with specified groupId does not exist', async () => {
512-
const groupId = 300
512+
const groupId = '300'
513513
const res = await chai.request(expressApp)
514514
.delete(`/v5/leaderboard/groups/${groupId}`)
515515
.set('Authorization', `Bearer ${M2M_FULL_TOKEN}`)

0 commit comments

Comments
 (0)