Skip to content

Commit fa71ad5

Browse files
authored
Merge pull request #206 from mark-nakachon/develop
unit test & final fix changes
2 parents 05a464a + 737b9d3 commit fa71ad5

File tree

9 files changed

+306
-168
lines changed

9 files changed

+306
-168
lines changed

config/test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ module.exports = {
77
LOG_LEVEL: 'info',
88
WEB_SERVER_PORT: 3010,
99
AUTH_SECRET: 'mysecret',
10-
VALID_ISSUERS: '["https://api.topcoder.com"]',
10+
VALID_ISSUERS: process.env.VALID_ISSUERS ? process.env.VALID_ISSUERS.replace(/\\"/g, '') : '["https://api.topcoder.com","https://topcoder-dev.auth0.com/"]',
1111
API_VERSION: process.env.API_VERSION || '/api/v5',
1212
aws: {
1313
AWS_REGION: process.env.AWS_REGION || 'us-east-1', // AWS Region to be used by the application
@@ -16,14 +16,14 @@ module.exports = {
1616
S3_BUCKET: process.env.S3_BUCKET_TEST || 'tc-testing-submissions' // S3 Bucket to which submissions need to be uploaded
1717
},
1818
BUSAPI_EVENTS_URL: 'https://api.topcoder-dev.com/v5/bus/events',
19+
BUSAPI_URL: 'https://api.topcoder-dev.com/v5',
1920
CHALLENGEAPI_V5_URL: 'https://api.topcoder-dev.com/v5/challenges',
2021
esConfig: {
2122
ES_INDEX: process.env.ES_INDEX_TEST || 'submission-test',
2223
ES_TYPE: process.env.ES_TYPE_TEST || '_doc' // ES 6.x accepts only 1 Type per index and it's mandatory to define it
2324
},
2425
AUTH0_URL: process.env.AUTH0_URL, // Auth0 credentials for Submission Service
25-
AUTH0_AUDIENCE: process.env.AUTH0_AUDIENCE || 'https://www.topcoder.com',
26-
TOKEN_CACHE_TIME: process.env.TOKEN_CACHE_TIME,
26+
AUTH0_AUDIENCE: process.env.AUTH0_AUDIENCE,
2727
AUTH0_CLIENT_ID: process.env.AUTH0_CLIENT_ID,
2828
AUTH0_CLIENT_SECRET: process.env.AUTH0_CLIENT_SECRET,
2929
USER_TOKEN: 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJyb2xlcyI6WyJUb3Bjb2RlciBVc2VyIl0sImlzcyI6Imh0dHBzOi8vYXBpLnRvcGNvZGVyLmNvbSIsImhhbmRsZSI6IlNoYXJhdGhrdW1hcjkyIiwiZXhwIjo1NTUzMDE5OTI1OSwidXNlcklkIjoiNDA0OTMwNTAiLCJpYXQiOjE1MzAxOTg2NTksImVtYWlsIjoiU2hhcmF0aGt1bWFyOTJAdG9wY29kZXIuY29tIiwianRpIjoiYzNhYzYwOGEtNTZiZS00NWQwLThmNmEtMzFmZTk0Yjk1NjFjIn0.2gtNJwhcv7MYc-muX3Nv-B0RdWbhMRl7-xrwFUsLazM',

src/common/helper.js

Lines changed: 23 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ function autoWrapExpress (obj) {
5353
return obj
5454
}
5555
_.each(obj, (value, key) => {
56-
obj[key] = autoWrapExpress(value); //eslint-disable-line
56+
obj[key] = autoWrapExpress(value); //eslint-disable-line
5757
})
5858
return obj
5959
}
@@ -676,39 +676,31 @@ function * getRoleIdToRoleNameMap () {
676676
* @param {Object} challengeDetails the challenge details
677677
* @returns {('Scheduled' | 'Open' | 'Closed' | 'Invalid')} status of the phase
678678
*/
679-
function * getPhaseStatus (phaseName, challengeDetails) {
680-
const phases = challengeDetails.phases
681-
if (challengeDetails.status === 'Completed') {
682-
return 'Closed'
683-
} else if (challengeDetails.status === 'Active') {
684-
const queriedPhaseIndex = _.findIndex(phases, phase => {
685-
return phase.name === phaseName
686-
})
687-
// Requested phase name could not be found in phases hence 'Invalid'
688-
if (queriedPhaseIndex === -1) {
689-
return 'Invalid'
690-
}
691-
// If requested phase name is open return 'Open'
692-
if (phases[queriedPhaseIndex].isOpen) {
693-
return 'Open'
694-
}
695-
696-
// Search for phase where isOpen == true from list of phases
697-
// Phases are already in sorted order as per challenge-api repository
698-
const currentOpenPhaseIndex = _.findLastIndex(phases, phase => {
699-
return phase.isOpen === true
700-
})
701-
702-
// if queried phase occurs before current open phase it is 'Closed'
703-
// else it is 'Scheduled'
704-
if (currentOpenPhaseIndex !== -1) {
705-
return currentOpenPhaseIndex > queriedPhaseIndex ? 'Closed' : 'Scheduled'
679+
function getPhaseStatus (phaseName, challengeDetails) {
680+
const { phases } = challengeDetails
681+
const queriedPhaseIndex = _.findIndex(phases, phase => {
682+
return phase.name === phaseName
683+
})
684+
// Requested phase name could not be found in phases hence 'Invalid'
685+
if (queriedPhaseIndex === -1) {
686+
return 'Invalid'
687+
}
688+
// If requested phase name is open return 'Open'
689+
if (phases[queriedPhaseIndex].isOpen) {
690+
return 'Open'
691+
} else {
692+
const { actualEndDate } = phases[queriedPhaseIndex]
693+
if (!_.isEmpty(actualEndDate)) {
694+
const present = new Date().getTime()
695+
const actualDate = new Date(actualEndDate).getTime()
696+
if (present > actualDate) {
697+
return 'Closed'
698+
} else {
699+
return 'Scheduled'
700+
}
706701
} else {
707-
// if no phase is open but the challenge is Active return Scheduled
708702
return 'Scheduled'
709703
}
710-
} else { // if challenge is not in Active or Completed state return Scheduled
711-
return 'Scheduled'
712704
}
713705
}
714706

src/services/SubmissionService.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ const listSubmissionsQuerySchema = {
197197
type: joi.string(),
198198
url: joi.string().uri().trim(),
199199
memberId: joi.alternatives().try(joi.id(), joi.string().uuid()),
200-
challengeId: joi.alternatives().try(joi.id(), joi.string().uuid()),
200+
challengeId: joi.string().uuid(),
201201
legacySubmissionId: joi.alternatives().try(joi.id(), joi.string().uuid()),
202202
legacyUploadId: joi.alternatives().try(joi.id(), joi.string().uuid()),
203203
submissionPhaseId: joi.id(),
@@ -356,7 +356,7 @@ createSubmission.schema = {
356356
fileType: joi.string(),
357357
url: joi.string().uri().trim(),
358358
memberId: joi.alternatives().try(joi.id(), joi.string().uuid()).required(),
359-
challengeId: joi.alternatives().try(joi.id(), joi.string().uuid()).required(),
359+
challengeId: joi.string().uuid().required(),
360360
legacySubmissionId: joi.alternatives().try(joi.id(), joi.string().uuid()),
361361
legacyUploadId: joi.alternatives().try(joi.id(), joi.string().uuid()),
362362
submissionPhaseId: joi.id(),
@@ -480,7 +480,7 @@ updateSubmission.schema = {
480480
type: joi.string(),
481481
url: joi.string().uri().trim().required(),
482482
memberId: joi.alternatives().try(joi.id(), joi.string().uuid()).required(),
483-
challengeId: joi.alternatives().try(joi.id(), joi.string().uuid()).required(),
483+
challengeId: joi.string().uuid().required(),
484484
legacySubmissionId: joi.alternatives().try(joi.id(), joi.string().uuid()),
485485
legacyUploadId: joi.alternatives().try(joi.id(), joi.string().uuid()),
486486
submissionPhaseId: joi.id(),
@@ -506,7 +506,7 @@ patchSubmission.schema = {
506506
type: joi.string(),
507507
url: joi.string().uri().trim(),
508508
memberId: joi.alternatives().try(joi.id(), joi.string().uuid()),
509-
challengeId: joi.alternatives().try(joi.id(), joi.string().uuid()),
509+
challengeId: joi.string().uuid(),
510510
legacySubmissionId: joi.alternatives().try(joi.id(), joi.string().uuid()),
511511
legacyUploadId: joi.alternatives().try(joi.id(), joi.string().uuid()),
512512
submissionPhaseId: joi.id(),

0 commit comments

Comments
 (0)