Skip to content

Revert "Increase testing coverage" #406

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,7 @@ Mock API starts after running `docker-compose up` and expose port 4000.

### Notes
There are two parts need to be updated for local development
- https://github.com/topcoder-platform/challenge-api/blob/develop/src/models/Challenge.js#L116
`throughput: 'ON_DEMAND',` should be updated to `throughput:{ read: 4, write: 2 },`
- https://github.com/topcoder-platform/challenge-api/blob/develop/src/models/Phase.js#L33
- https://github.com/topcoder-platform/challenge-api/blob/develop/src/models/Challenge.js#L116
`throughput: 'ON_DEMAND',` should be updated to `throughput:{ read: 4, write: 2 },`
- https://github.com/topcoder-platform/challenge-api/blob/develop/config/default.js#L27-L28
Two aws config should be uncommented
Expand Down
95 changes: 0 additions & 95 deletions Verification.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,98 +22,3 @@ Run command `npm run view-es-data` to view data store in ES.
- login `https://lauscher.topcoder-dev.com/` with credential `tonyj / appirio123`
- then select topic to view, see app-constants.js Topics field for used topics, then click `View` button to view related messages


## Unit Test Coverage

299 passing (3m)

--------------------------------------|----------|----------|----------|----------|-------------------|
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s |
--------------------------------------|----------|----------|----------|----------|-------------------|
All files | 84.68 | 69.84 | 87.98 | 84.86 | |
challenge-api | 100 | 100 | 100 | 100 | |
app-bootstrap.js | 100 | 100 | 100 | 100 | |
app-constants.js | 100 | 100 | 100 | 100 | |
challenge-api/config | 100 | 97.06 | 100 | 100 | |
default.js | 100 | 96.43 | 100 | 100 | 18,49,59 |
test.js | 100 | 100 | 100 | 100 | |
challenge-api/src/common | 87.8 | 63.33 | 94.12 | 87.91 | |
errors.js | 100 | 50 | 100 | 100 | 23 |
helper.js | 85.85 | 61.8 | 92.75 | 85.9 |... 37,868,881,905 |
logger.js | 92.65 | 63.64 | 100 | 92.65 | 31,59,64,88,122 |
s3ParseUrl.js | 100 | 100 | 100 | 100 | |
challenge-api/src/models | 100 | 50 | 100 | 100 | |
Attachment.js | 100 | 100 | 100 | 100 | |
AuditLog.js | 100 | 100 | 100 | 100 | |
Challenge.js | 100 | 100 | 100 | 100 | |
ChallengeTimelineTemplate.js | 100 | 100 | 100 | 100 | |
ChallengeTrack.js | 100 | 100 | 100 | 100 | |
ChallengeType.js | 100 | 100 | 100 | 100 | |
Phase.js | 100 | 100 | 100 | 100 | |
TimelineTemplate.js | 100 | 100 | 100 | 100 | |
index.js | 100 | 50 | 100 | 100 | 8,18 |
challenge-api/src/services | 82.65 | 68.25 | 83.92 | 82.82 | |
AttachmentService.js | 95.24 | 87.5 | 100 | 95.06 | 133,237,238,239 |
AuditLogService.js | 92.86 | 71.43 | 83.33 | 100 | 16,17,20,23 |
ChallengeService.js | 75.7 | 66.48 | 72.5 | 76.21 |... 1669,1716,1813 |
ChallengeTimelineTemplateService.js | 92.06 | 70.83 | 100 | 90.91 | 46,47,113,119,127 |
ChallengeTrackService.js | 98.21 | 80.77 | 100 | 97.92 | 99 |
ChallengeTypeService.js | 98.31 | 78.57 | 100 | 97.96 | 100 |
PhaseService.js | 100 | 75 | 100 | 100 | 18,19,81 |
TimelineTemplateService.js | 100 | 78.57 | 100 | 100 | 18,19,87 |
--------------------------------------|----------|----------|----------|----------|-------------------|


## E2E API Test Coverage

318 passing (3m)

-----------------------------------------|----------|----------|----------|----------|-------------------|
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s |
-----------------------------------------|----------|----------|----------|----------|-------------------|
All files | 83.27 | 67.78 | 87.84 | 83.41 | |
challenge-api | 93.1 | 79.69 | 96.3 | 92.59 | |
app-bootstrap.js | 100 | 100 | 100 | 100 | |
app-constants.js | 100 | 100 | 100 | 100 | |
app-routes.js | 90.63 | 82.76 | 93.33 | 89.83 |... 67,103,104,108 |
app.js | 93.1 | 77.14 | 100 | 93.1 | 27,65,95,110 |
challenge-api/config | 100 | 97.06 | 100 | 100 | |
default.js | 100 | 96.43 | 100 | 100 | 18,49,59 |
test.js | 100 | 100 | 100 | 100 | |
challenge-api/src | 100 | 100 | 100 | 100 | |
routes.js | 100 | 100 | 100 | 100 | |
challenge-api/src/common | 77.07 | 57.14 | 88.24 | 76.83 | |
errors.js | 100 | 50 | 100 | 100 | 23 |
helper.js | 72.96 | 55.62 | 85.51 | 72.46 |... 00,902,903,905 |
logger.js | 92.65 | 68.18 | 100 | 92.65 | 31,59,64,88,122 |
s3ParseUrl.js | 78.57 | 62.5 | 100 | 78.57 | 22,32,43 |
challenge-api/src/controllers | 98.52 | 50 | 100 | 98.52 | |
AttachmentController.js | 100 | 100 | 100 | 100 | |
AuditLogController.js | 100 | 100 | 100 | 100 | |
ChallengeController.js | 100 | 100 | 100 | 100 | |
ChallengePhaseController.js | 100 | 100 | 100 | 100 | |
ChallengeTimelineTemplateController.js | 100 | 100 | 100 | 100 | |
ChallengeTrackController.js | 100 | 100 | 100 | 100 | |
ChallengeTypeController.js | 100 | 100 | 100 | 100 | |
HealthController.js | 84.62 | 50 | 100 | 84.62 | 26,29 |
TimelineTemplateController.js | 100 | 100 | 100 | 100 | |
challenge-api/src/models | 100 | 50 | 100 | 100 | |
Attachment.js | 100 | 100 | 100 | 100 | |
AuditLog.js | 100 | 100 | 100 | 100 | |
Challenge.js | 100 | 100 | 100 | 100 | |
ChallengeTimelineTemplate.js | 100 | 100 | 100 | 100 | |
ChallengeTrack.js | 100 | 100 | 100 | 100 | |
ChallengeType.js | 100 | 100 | 100 | 100 | |
Phase.js | 100 | 100 | 100 | 100 | |
TimelineTemplate.js | 100 | 100 | 100 | 100 | |
index.js | 100 | 50 | 100 | 100 | 8,18 |
challenge-api/src/services | 81.76 | 66.11 | 82.52 | 82.05 | |
AttachmentService.js | 92.86 | 81.25 | 100 | 92.59 |... 08,237,238,239 |
AuditLogService.js | 85.71 | 64.29 | 66.67 | 100 | 16,17,20,23,24 |
ChallengeService.js | 74.9 | 64.5 | 71.25 | 75.36 |... 1669,1716,1813 |
ChallengeTimelineTemplateService.js | 92.06 | 70.83 | 100 | 90.91 | 46,47,113,119,127 |
ChallengeTrackService.js | 98.21 | 76.92 | 100 | 97.92 | 99 |
ChallengeTypeService.js | 98.31 | 75 | 100 | 97.96 | 100 |
PhaseService.js | 100 | 75 | 100 | 100 | 18,19,81 |
TimelineTemplateService.js | 100 | 78.57 | 100 | 100 | 18,19,87 |
-----------------------------------------|----------|----------|----------|----------|-------------------|
16 changes: 10 additions & 6 deletions app-constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,17 +59,15 @@ const Topics = {
ChallengeDeleted: 'challenge.notification.delete',
ChallengeTypeCreated: 'test.new.bus.events', // 'challenge.action.type.created',
ChallengeTypeUpdated: 'test.new.bus.events', // 'challenge.action.type.updated',
ChallengeTrackCreated: 'test.new.bus.events', // 'challenge.action.track.created',
ChallengeTrackUpdated: 'test.new.bus.events', // 'challenge.action.track.updated',
ChallengePhaseCreated: 'test.new.bus.events', // 'challenge.action.phase.created',
ChallengePhaseUpdated: 'test.new.bus.events', // 'challenge.action.phase.updated',
ChallengePhaseDeleted: 'test.new.bus.events', // 'challenge.action.phase.deleted',
TimelineTemplateCreated: 'test.new.bus.events', // 'challenge.action.timeline.template.created',
TimelineTemplateUpdated: 'test.new.bus.events', // 'challenge.action.timeline.template.updated',
TimelineTemplateDeleted: 'test.new.bus.events', // 'challenge.action.timeline.template.deleted',
ChallengeTimelineTemplateCreated: 'test.new.bus.events', // 'challenge.action.timeline.template.created',
ChallengeTimelineTemplateUpdated: 'test.new.bus.events', // 'challenge.action.timeline.template.updated',
ChallengeTimelineTemplateDeleted: 'test.new.bus.events', // 'challenge.action.timeline.template.deleted'
ChallengeTypeTimelineTemplateCreated: 'test.new.bus.events', // 'challenge.action.type.timeline.template.created',
ChallengeTypeTimelineTemplateUpdated: 'test.new.bus.events', // 'challenge.action.type.timeline.template.updated',
ChallengeTypeTimelineTemplateDeleted: 'test.new.bus.events', // 'challenge.action.type.timeline.template.deleted'
ChallengeAttachmentCreated: 'test.new.bus.events', // 'challenge.action.attachment.created',
ChallengeAttachmentUpdated: 'test.new.bus.events', // 'challenge.action.attachment.updated',
ChallengeAttachmentDeleted: 'test.new.bus.events' // 'challenge.action.attachment.deleted',
Expand All @@ -87,6 +85,11 @@ const challengeTextSortField = {
TypeId: 'typeId'
}

const reviewTypes = {
Community: 'COMMUNITY',
Internal: 'INTERNAL'
}

module.exports = {
UserRoles,
prizeSetTypes,
Expand All @@ -97,5 +100,6 @@ module.exports = {
Topics,
challengeTracks,
challengeTextSortField,
DiscussionTypes
DiscussionTypes,
reviewTypes
}
5 changes: 2 additions & 3 deletions config/default.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ module.exports = {
IS_LOCAL_DB: process.env.IS_LOCAL_DB || true,
DYNAMODB_URL: process.env.DYNAMODB_URL || 'http://localhost:7777',
S3_API_VERSION: process.env.S3_API_VERSION || '2006-03-01',
// BUCKET_WHITELIST: process.env.BUCKET_WHITELIST || 'topcoder_01, topcoder_02, key1, key2'
BUCKET_WHITELIST: process.env.BUCKET_WHITELIST || 'topcoder_01, topcoder_02, bucket, key1'
BUCKET_WHITELIST: process.env.BUCKET_WHITELIST || 'topcoder_01, topcoder_02'
},

ES: {
Expand All @@ -58,7 +57,7 @@ module.exports = {
// copilot resource role ids allowed to upload attachment
COPILOT_RESOURCE_ROLE_IDS: process.env.COPILOT_RESOURCE_ROLE_IDS
? process.env.COPILOT_RESOURCE_ROLE_IDS.split(',') : ['10ba038e-48da-487b-96e8-8d3b99b6d18b'],
SUBMITTER_ROLE_ID: process.env.SUBMITTER_ROLE_ID || '10ba038e-48da-487b-96e8-8d3b99b6d18a',
SUBMITTER_ROLE_ID: process.env.SUBMITTER_ROLE_ID || '732339e7-8e30-49d7-9198-cccf9451e221',

MANAGER_ROLE_ID: process.env.MANAGER_ROLE_ID || '0e9c6879-39e4-4eb6-b8df-92407890faf1',
OBSERVER_ROLE_ID: process.env.OBSERVER_ROLE_ID || '2a4dc376-a31c-4d00-b173-13934d89e286',
Expand Down
6 changes: 1 addition & 5 deletions config/test.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 8 additions & 3 deletions docs/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2555,6 +2555,10 @@ definitions:
reviewType:
type: string
description: the review type
enum:
- 'INTERNAL'
- 'COMMUNITY'
default: 'INTERNAL'
forumId:
type: integer
description: the forum id
Expand Down Expand Up @@ -2723,7 +2727,6 @@ definitions:
- prizeSets
- created
- createdBy
- reviewType
- tags
- status
Attachment:
Expand Down Expand Up @@ -2967,13 +2970,16 @@ definitions:
type: string
reviewType:
type: string
enum:
- 'INTERNAL'
- 'COMMUNITY'
default: 'INTERNAL'
confidentialityType:
type: string
forumId:
type: number
required:
- track
- reviewType
name:
type: string
description:
Expand Down Expand Up @@ -3251,7 +3257,6 @@ definitions:
- prizeSets
- created
- createdBy
- reviewType
- tags
- projectId
- forumId
Expand Down
4 changes: 2 additions & 2 deletions local/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ services:
dynamodb:
image: tray/dynamodb-local
ports:
- "7777:7777"
command: "-inMemory -port 7777"
- "8000:8000"
command: "-inMemory -port 8000"
esearch:
image: "docker.elastic.co/elasticsearch/elasticsearch:6.8.0"
ports:
Expand Down
32 changes: 0 additions & 32 deletions mock-api/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,6 @@ app.get('/v5/resources', (req, res) => {
res.json(resources)
})

// post challenge resources
app.post('/v5/resources', (req, res) => {
res.json({})
})

// get challenges member can access to
app.get('/v5/resources/:memberId/challenges', (req, res) => {
const memberId = req.params.memberId
Expand Down Expand Up @@ -224,33 +219,6 @@ app.get('/v5/terms/:termId', (req, res) => {
}
})

// get direct project
app.get('/v3/direct/projects/:projectId', (req, res) => {
const projectId = req.params.projectId
if (projectId === '111' || projectId === '123' || projectId === '112233') {
res.json({
projectId,
terms: ['0fcb41d1-ec7c-44bb-8f3b-f017a61cd708', 'be0652ae-8b28-4e91-9b42-8ad00b31e9cb'],
result: {
content: {
billingAccountIds: ['0fcb41d1-ec7c-44bb-8f3b-f017a61cd708', 'be0652ae-8b28-4e91-9b42-8ad00b31e9cb']
}
}
})
} else if (projectId === '200') {
res.status(403).send({
id: '6e97fe68-f89c-4c45-b25b-d17933a3c4b9',
result: {
success: false,
status: 403,
content: { message: 'You do not have permissions to perform this action' }
}
})
} else {
res.status(404).end()
}
})

app.use((req, res) => {
res.status(404).json({ error: 'route not found' })
})
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
"check-timeline-templates": "node src/scripts/check-templates.js",
"view-data": "node src/scripts/view-data.js",
"view-es-data": "node src/scripts/view-es-data.js",
"test": "mocha --require test/prepare.js -t 30000 test/unit/*.test.js --exit",
"e2e": "mocha --require test/prepare.js -t 30000 test/e2e/*.test.js --exit",
"test": "mocha --require test/prepare.js -t 20000 test/unit/*.test.js --exit",
"e2e": "mocha --require test/prepare.js -t 20000 test/e2e/*.test.js --exit",
"test:cov": "nyc --reporter=html --reporter=text npm test",
"e2e:cov": "nyc --reporter=html --reporter=text npm run e2e"
},
Expand Down
34 changes: 34 additions & 0 deletions src/common/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,21 @@ async function getById (modelName, id) {
})
}

/**
* Get Data by model ids
* @param {String} modelName The dynamoose model name
* @param {Array} ids The ids
* @returns {Promise<Array>} the found entities
*/
async function getByIds (modelName, ids) {
const entities = []
const theIds = ids || []
for (const id of theIds) {
entities.push(await getById(modelName, id))
}
return entities
}

/**
* Validate the data to ensure no duplication
* @param {Object} modelName The dynamoose model name
Expand Down Expand Up @@ -280,6 +295,23 @@ async function scan (modelName, scanParams) {
})
}

/**
* Get all data collection (avoid default page limit of DynamoDB) by scan parameters
* @param {Object} modelName The dynamoose model name
* @param {Object} scanParams The scan parameters object
* @returns {Array}
*/
async function scanAll (modelName, scanParams) {
let results = await models[modelName].scan(scanParams).exec()
let lastKey = results.lastKey
while (!_.isUndefined(results.lastKey)) {
const newResult = await models[modelName].scan(scanParams).startAt(lastKey).exec()
results = [...results, ...newResult]
lastKey = newResult.lastKey
}
return results
}

/**
* Test whether the given value is partially match the filter.
* @param {String} filter the filter
Expand Down Expand Up @@ -931,9 +963,11 @@ module.exports = {
hasAdminRole,
toString,
getById,
getByIds,
create,
update,
scan,
scanAll,
validateDuplicate,
partialMatch,
validatePhases,
Expand Down
Loading