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

Sync master with dev #38

Merged
merged 13 commits into from
Nov 6, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Merge branch 'develop' into dynamodb
  • Loading branch information
callmekatootie committed Oct 26, 2020
commit 983f74e406c4f8412abc6a80dad92bd19a26527f
4 changes: 2 additions & 2 deletions config/default.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ module.exports = {
VALID_ISSUERS: process.env.VALID_ISSUERS ? process.env.VALID_ISSUERS.replace(/\\"/g, '')
: '["https://topcoder-dev.auth0.com/", "https://api.topcoder.com"]',

CHALLENGE_API_URL: process.env.CHALLENGE_API_URL || 'https://api.topcoder-dev.com/v4/challenges',
MEMBER_API_URL: process.env.MEMBER_API_URL || 'https://api.topcoder-dev.com/v3/users',
CHALLENGE_API_URL: process.env.CHALLENGE_API_URL || 'https://api.topcoder-dev.com/v5/challenges',
MEMBER_API_URL: process.env.MEMBER_API_URL || 'https://api.topcoder-dev.com/v5/members',

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

Expand Down
4 changes: 2 additions & 2 deletions config/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*/

module.exports = {
CHALLENGE_API_URL: 'https://api.topcoder-dev.com/v4/challenges',
MEMBER_API_URL: 'https://api.topcoder-dev.com/v3/users',
CHALLENGE_API_URL: 'https://api.topcoder-dev.com/v5/challenges',
MEMBER_API_URL: 'https://api.topcoder-dev.com/v5/members',
MOCK_API_PORT: 3001
}
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@
"get-parameter-names": "^0.3.0",
"http-status-codes": "^1.3.0",
"joi": "^14.0.0",
"lodash": "^4.17.15",
"lodash": "^4.17.19",
"mongoose": "^5.7.5",
"superagent": "^5.1.0",
"tc-core-library-js": "appirio-tech/tc-core-library-js.git#v2.6.3",
"uuid": "^8.3.1",
Expand Down
2 changes: 1 addition & 1 deletion scripts/test-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ const insertData = async () => {
totalTestCases: 6,
groupIds: ['100']
})
for (const groupId of [202343, 20000000, 100, 200]) {
for (const groupId of ['202343', '20000000', '100', '200']) {
await Group.create({
groupId
})
Expand Down
2 changes: 1 addition & 1 deletion src/common/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const m2m = m2mAuth(_.pick(config, ['AUTH0_URL', 'AUTH0_AUDIENCE', 'TOKEN_CACHE_
const isGroupIdValid = async (groupIds) => {
// Get the Group IDs from config
const confGroupIds = _.map(await models.Group.scan().all().exec(), (group) => group.groupId)
if (_.intersectionBy(confGroupIds, groupIds, parseInt).length !== 0) {
if (_.intersection(confGroupIds, groupIds).length !== 0) {
return true
}
return false
Expand Down
2 changes: 1 addition & 1 deletion src/models/Group.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const Schema = dynamoose.Schema

const GroupSchema = new Schema({
groupId: {
type: Number,
type: String,
hashKey: true
}
}, {
Expand Down
4 changes: 2 additions & 2 deletions src/services/GroupService.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ async function createGroup (groupId) {
}

createGroup.schema = {
groupId: joi.id().required()
groupId: joi.string().required()
}

/**
Expand All @@ -45,7 +45,7 @@ async function deleteGroup (groupId) {
}

deleteGroup.schema = {
groupId: joi.id().required()
groupId: joi.string().required()
}

module.exports = {
Expand Down
4 changes: 2 additions & 2 deletions src/services/LeaderboardService.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,9 @@ async function createLeaderboard (challengeId, memberId, review) {
throw new errors.BadRequestError(`Challenge # ${challengeId} doesn't exist`)
}

const groupIds = challenge.groupIds
const groupIds = challenge.groups
if (!(await helper.isGroupIdValid(groupIds))) {
logger.debug(`Group ID (${JSON.stringify(groupIds)}) of Challenge # ${challengeId} does not exist`)
logger.debug(`Group ID (${JSON.stringify(groupIds)}) of Challenge # ${challengeId} is not in the approved list. Ignoring request`)
// Ignore the message
return
}
Expand Down
14 changes: 7 additions & 7 deletions test/common/prepare.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,19 @@ prepare(function (done) {
.persist()
.post('/oauth/token')
.reply(200, { access_token: M2M_FULL_TOKEN })
.get('/v4/challenges?filter=id=30000001')
.get('/v5/challenges?legacyId=30000001')
.reply(200, challengeAPIResponse[0])
.get('/v4/challenges?filter=id=30051825')
.get('/v5/challenges?legacyId=30051825')
.reply(200, challengeAPIResponse[1])
.get('/v4/challenges?filter=id=30051826')
.get('/v5/challenges?legacyId=30051826')
.reply(200, challengeAPIResponse[2])
.get('/v4/challenges?filter=id=31000000')
.get('/v5/challenges?legacyId=31000000')
.reply(200, challengeAPIResponse[3])
.get('/v3/users?filter=id=10000')
.get('/v5/members?userId=10000&fields=userId,handle')
.reply(200, memberAPIResponse[0])
.get('/v3/users?filter=id=8547899')
.get('/v5/members?userId=8547899&fields=userId,handle')
.reply(200, memberAPIResponse[1])
.get('/v3/users?filter=id=22688726')
.get('/v5/members?userId=22688726&fields=userId,handle')
.reply(200, memberAPIResponse[2])

done()
Expand Down
181 changes: 30 additions & 151 deletions test/common/testData.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,160 +36,39 @@ const submissionAPIResponse = [
]

const challengeAPIResponse = [
{
'id': '2587d0de:16de737ff0d:3225',
'result': {
'success': true,
'status': 200,
'metadata': null,
'content': []
},
'version': 'v3'
},
{
'id': '-3254eca5:16658dbed10:2c2a',
'result': {
'success': true,
'status': 200,
'metadata': {
'fields': null,
'totalCount': 1
},
'content': [
{
'groupIds': [
20000000
]
}
]
}
},
{
'id': '-3254eca5:16658dbed10:2c2a',
'result': {
'success': true,
'status': 200,
'metadata': {
'fields': null,
'totalCount': 1
},
'content': [
{
'groupIds': [
202343,
20000000
]
}
]
}
},
{
'id': '-3254eca5:16658dbed10:2c2a',
'result': {
'success': true,
'status': 200,
'metadata': {
'fields': null,
'totalCount': 1
},
'content': [
{
'groupIds': [
30000
]
}
]
}
}
[],
[{
'groups': [
'20000000'
]
}],
[{
'groups': [
'202343',
'20000000'
]
}],
[{
'groups': [
'30000'
]
}]
]

const memberAPIResponse = [
{
'id': '2587d0de:16de737ff0d:3225',
'result': {
'success': true,
'status': 200,
'metadata': null,
'content': []
},
'version': 'v3'
},
{
'id': '311d312:166718c336c:1936',
'result': {
'success': true,
'status': 200,
'metadata': null,
'content': [
{
'id': '8547899',
'modifiedBy': null,
'modifiedAt': '2018-10-14T02:53:38.000Z',
'createdBy': null,
'createdAt': '2004-03-21T21:05:32.000Z',
'handle': 'TonyJ',
'email': '[email protected]',
'firstName': 'Tony',
'lastName': 'L_NAME',
'credential': {
'activationCode': 'UASI7X0JS',
'resetToken': null,
'hasPassword': true
},
'status': 'A',
'country': null,
'regSource': null,
'utmSource': null,
'utmMedium': null,
'utmCampaign': null,
'roles': null,
'ssoLogin': false,
'active': true,
'profile': null,
'emailActive': true
}
]
},
'version': 'v3'
},
{
'id': '2587d0de:16de737ff0d:3203',
'result': {
'success': true,
'status': 200,
'metadata': null,
'content': [
{
'id': '22688726',
'modifiedBy': null,
'modifiedAt': '2019-10-16T03:39:37.000Z',
'createdBy': null,
'createdAt': '2007-07-05T05:25:12.000Z',
'handle': 'vasyl',
'email': '[email protected]',
'firstName': 'F_NAME',
'lastName': 'L_NAME',
'credential': {
'activationCode': 'MC8XPOC3Z7',
'resetToken': null,
'hasPassword': true
},
'status': 'A',
'country': null,
'regSource': null,
'utmSource': null,
'utmMedium': null,
'utmCampaign': null,
'roles': null,
'ssoLogin': false,
'profile': null,
'active': true,
'emailActive': true
}
]
},
'version': 'v3'
}
[],
[
{
'userId': 8547899,
'handle': 'TonyJ'
}
],
[
{
'userId': 22688726,
'handle': 'vasyl'
}
]
]

const M2M_FULL_TOKEN = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJodHRwczovL3RvcGNvZGVyLWRldi5hdXRoMC5jb20vIiwic3ViIjoiOFFvdkRoMjdTckR1MVhTczY4bTIxQTFOQlA4aXN2T3RAY2xpZW50cyIsImF1ZCI6Imh0dHBzOi8vbTJtLnRvcGNvZGVyLWRldi5jb20vIiwiaWF0IjoxNjAzMjE4NjM1LCJleHAiOjIxNDc0ODM2NDgsImF6cCI6IjhRb3ZEaDI3U3JEdTFYU3M2OG0yMUExTkJQOGlzdk90Iiwic2NvcGUiOiJyZWFkOmNoYWxsZW5nZXMgcmVhZDpncm91cHMgcmVhZDpzdWJtaXNzaW9uIHJlYWQ6cmV2aWV3X3R5cGUgdXBkYXRlOnJldmlld19zdW1tYXRpb24gcmVhZDpyZXZpZXdfc3VtbWF0aW9uIGNyZWF0ZTpyZXZpZXdfc3VtbWF0aW9uIHVwZGF0ZTpyZXZpZXcgcmVhZDpyZXZpZXcgZGVsZXRlOnJldmlldyBjcmVhdGU6cmV2aWV3IGFsbDpyZXZpZXcgcmVhZDpwcm9qZWN0IHdyaXRlOmJ1c19hcGkgcmVhZDp1c2VyX3Byb2ZpbGVzIHJlYWQ6cm9sZXMgY3JlYXRlOmxlYWRlcmJvYXJkIHVwZGF0ZTpsZWFkZXJib2FyZCBkZWxldGU6bGVhZGVyYm9hcmQgYWxsOmxlYWRlcmJvYXJkIiwiZ3R5IjoiY2xpZW50LWNyZWRlbnRpYWxzIn0.wAv4YZhNXbPai9zKUfVFBhQ3vq6Itir8265WgybeBVk'
Expand Down
12 changes: 6 additions & 6 deletions test/e2e/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ describe('Topcoder - Leaderboard API E2E Tests', () => {
score: 50
})
expect(res.status).to.equal(204)
expect(debugLogs[3]).to.equal('Group ID ([30000]) of Challenge # 31000000 does not exist')
expect(debugLogs[3]).to.equal('Group ID (["30000"]) of Challenge # 31000000 is not in the approved list. Ignoring request')
})
})

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

describe('create group test', async () => {
it('create group success', async () => {
const groupId = 300
const groupId = '300'
const res = await chai.request(expressApp)
.post(`/v5/leaderboard/groups/${groupId}`)
.set('Authorization', `Bearer ${M2M_FULL_TOKEN}`)
expect(res.status).to.equal(200)
expect(res.body).to.eql({ groupId })
})
it('failure - group wth specified groupId already exist', async () => {
const groupId = 300
const groupId = '300'
const res = await chai.request(expressApp)
.post(`/v5/leaderboard/groups/${groupId}`)
.set('Authorization', `Bearer ${M2M_FULL_TOKEN}`)
Expand All @@ -502,14 +502,14 @@ describe('Topcoder - Leaderboard API E2E Tests', () => {

describe('delete group test', async () => {
it('delete group success', async () => {
const groupId = 300
const groupId = '300'
const res = await chai.request(expressApp)
.delete(`/v5/leaderboard/groups/${groupId}`)
.set('Authorization', `Bearer ${M2M_FULL_TOKEN}`)
expect(res.status).to.equal(204)
})
it('failure - group with specified groupId does not exist', async () => {
const groupId = 300
const groupId = '300'
const res = await chai.request(expressApp)
.delete(`/v5/leaderboard/groups/${groupId}`)
.set('Authorization', `Bearer ${M2M_FULL_TOKEN}`)
Expand Down
Loading
You are viewing a condensed version of this merge commit. You can view the full changes here.