Skip to content

Commit 30b773d

Browse files
authored
Merge pull request #365 from topcoder-platform/increase-cov
Increase testing coverage
2 parents 1d77b48 + 2676dcf commit 30b773d

38 files changed

+2862
-1650
lines changed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,9 @@ Mock API starts after running `docker-compose up` and expose port 4000.
105105

106106
### Notes
107107
There are two parts need to be updated for local development
108-
- https://github.com/topcoder-platform/challenge-api/blob/develop/src/models/Challenge.js#L116
108+
- https://github.com/topcoder-platform/challenge-api/blob/develop/src/models/Challenge.js#L116
109+
`throughput: 'ON_DEMAND',` should be updated to `throughput:{ read: 4, write: 2 },`
110+
- https://github.com/topcoder-platform/challenge-api/blob/develop/src/models/Phase.js#L33
109111
`throughput: 'ON_DEMAND',` should be updated to `throughput:{ read: 4, write: 2 },`
110112
- https://github.com/topcoder-platform/challenge-api/blob/develop/config/default.js#L27-L28
111113
Two aws config should be uncommented

Verification.md

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,98 @@ Run command `npm run view-es-data` to view data store in ES.
2222
- login `https://lauscher.topcoder-dev.com/` with credential `tonyj / appirio123`
2323
- then select topic to view, see app-constants.js Topics field for used topics, then click `View` button to view related messages
2424

25+
26+
## Unit Test Coverage
27+
28+
299 passing (3m)
29+
30+
--------------------------------------|----------|----------|----------|----------|-------------------|
31+
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s |
32+
--------------------------------------|----------|----------|----------|----------|-------------------|
33+
All files | 84.68 | 69.84 | 87.98 | 84.86 | |
34+
challenge-api | 100 | 100 | 100 | 100 | |
35+
app-bootstrap.js | 100 | 100 | 100 | 100 | |
36+
app-constants.js | 100 | 100 | 100 | 100 | |
37+
challenge-api/config | 100 | 97.06 | 100 | 100 | |
38+
default.js | 100 | 96.43 | 100 | 100 | 18,49,59 |
39+
test.js | 100 | 100 | 100 | 100 | |
40+
challenge-api/src/common | 87.8 | 63.33 | 94.12 | 87.91 | |
41+
errors.js | 100 | 50 | 100 | 100 | 23 |
42+
helper.js | 85.85 | 61.8 | 92.75 | 85.9 |... 37,868,881,905 |
43+
logger.js | 92.65 | 63.64 | 100 | 92.65 | 31,59,64,88,122 |
44+
s3ParseUrl.js | 100 | 100 | 100 | 100 | |
45+
challenge-api/src/models | 100 | 50 | 100 | 100 | |
46+
Attachment.js | 100 | 100 | 100 | 100 | |
47+
AuditLog.js | 100 | 100 | 100 | 100 | |
48+
Challenge.js | 100 | 100 | 100 | 100 | |
49+
ChallengeTimelineTemplate.js | 100 | 100 | 100 | 100 | |
50+
ChallengeTrack.js | 100 | 100 | 100 | 100 | |
51+
ChallengeType.js | 100 | 100 | 100 | 100 | |
52+
Phase.js | 100 | 100 | 100 | 100 | |
53+
TimelineTemplate.js | 100 | 100 | 100 | 100 | |
54+
index.js | 100 | 50 | 100 | 100 | 8,18 |
55+
challenge-api/src/services | 82.65 | 68.25 | 83.92 | 82.82 | |
56+
AttachmentService.js | 95.24 | 87.5 | 100 | 95.06 | 133,237,238,239 |
57+
AuditLogService.js | 92.86 | 71.43 | 83.33 | 100 | 16,17,20,23 |
58+
ChallengeService.js | 75.7 | 66.48 | 72.5 | 76.21 |... 1669,1716,1813 |
59+
ChallengeTimelineTemplateService.js | 92.06 | 70.83 | 100 | 90.91 | 46,47,113,119,127 |
60+
ChallengeTrackService.js | 98.21 | 80.77 | 100 | 97.92 | 99 |
61+
ChallengeTypeService.js | 98.31 | 78.57 | 100 | 97.96 | 100 |
62+
PhaseService.js | 100 | 75 | 100 | 100 | 18,19,81 |
63+
TimelineTemplateService.js | 100 | 78.57 | 100 | 100 | 18,19,87 |
64+
--------------------------------------|----------|----------|----------|----------|-------------------|
65+
66+
67+
## E2E API Test Coverage
68+
69+
318 passing (3m)
70+
71+
-----------------------------------------|----------|----------|----------|----------|-------------------|
72+
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s |
73+
-----------------------------------------|----------|----------|----------|----------|-------------------|
74+
All files | 83.27 | 67.78 | 87.84 | 83.41 | |
75+
challenge-api | 93.1 | 79.69 | 96.3 | 92.59 | |
76+
app-bootstrap.js | 100 | 100 | 100 | 100 | |
77+
app-constants.js | 100 | 100 | 100 | 100 | |
78+
app-routes.js | 90.63 | 82.76 | 93.33 | 89.83 |... 67,103,104,108 |
79+
app.js | 93.1 | 77.14 | 100 | 93.1 | 27,65,95,110 |
80+
challenge-api/config | 100 | 97.06 | 100 | 100 | |
81+
default.js | 100 | 96.43 | 100 | 100 | 18,49,59 |
82+
test.js | 100 | 100 | 100 | 100 | |
83+
challenge-api/src | 100 | 100 | 100 | 100 | |
84+
routes.js | 100 | 100 | 100 | 100 | |
85+
challenge-api/src/common | 77.07 | 57.14 | 88.24 | 76.83 | |
86+
errors.js | 100 | 50 | 100 | 100 | 23 |
87+
helper.js | 72.96 | 55.62 | 85.51 | 72.46 |... 00,902,903,905 |
88+
logger.js | 92.65 | 68.18 | 100 | 92.65 | 31,59,64,88,122 |
89+
s3ParseUrl.js | 78.57 | 62.5 | 100 | 78.57 | 22,32,43 |
90+
challenge-api/src/controllers | 98.52 | 50 | 100 | 98.52 | |
91+
AttachmentController.js | 100 | 100 | 100 | 100 | |
92+
AuditLogController.js | 100 | 100 | 100 | 100 | |
93+
ChallengeController.js | 100 | 100 | 100 | 100 | |
94+
ChallengePhaseController.js | 100 | 100 | 100 | 100 | |
95+
ChallengeTimelineTemplateController.js | 100 | 100 | 100 | 100 | |
96+
ChallengeTrackController.js | 100 | 100 | 100 | 100 | |
97+
ChallengeTypeController.js | 100 | 100 | 100 | 100 | |
98+
HealthController.js | 84.62 | 50 | 100 | 84.62 | 26,29 |
99+
TimelineTemplateController.js | 100 | 100 | 100 | 100 | |
100+
challenge-api/src/models | 100 | 50 | 100 | 100 | |
101+
Attachment.js | 100 | 100 | 100 | 100 | |
102+
AuditLog.js | 100 | 100 | 100 | 100 | |
103+
Challenge.js | 100 | 100 | 100 | 100 | |
104+
ChallengeTimelineTemplate.js | 100 | 100 | 100 | 100 | |
105+
ChallengeTrack.js | 100 | 100 | 100 | 100 | |
106+
ChallengeType.js | 100 | 100 | 100 | 100 | |
107+
Phase.js | 100 | 100 | 100 | 100 | |
108+
TimelineTemplate.js | 100 | 100 | 100 | 100 | |
109+
index.js | 100 | 50 | 100 | 100 | 8,18 |
110+
challenge-api/src/services | 81.76 | 66.11 | 82.52 | 82.05 | |
111+
AttachmentService.js | 92.86 | 81.25 | 100 | 92.59 |... 08,237,238,239 |
112+
AuditLogService.js | 85.71 | 64.29 | 66.67 | 100 | 16,17,20,23,24 |
113+
ChallengeService.js | 74.9 | 64.5 | 71.25 | 75.36 |... 1669,1716,1813 |
114+
ChallengeTimelineTemplateService.js | 92.06 | 70.83 | 100 | 90.91 | 46,47,113,119,127 |
115+
ChallengeTrackService.js | 98.21 | 76.92 | 100 | 97.92 | 99 |
116+
ChallengeTypeService.js | 98.31 | 75 | 100 | 97.96 | 100 |
117+
PhaseService.js | 100 | 75 | 100 | 100 | 18,19,81 |
118+
TimelineTemplateService.js | 100 | 78.57 | 100 | 100 | 18,19,87 |
119+
-----------------------------------------|----------|----------|----------|----------|-------------------|

app-constants.js

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -59,15 +59,17 @@ const Topics = {
5959
ChallengeDeleted: 'challenge.notification.delete',
6060
ChallengeTypeCreated: 'test.new.bus.events', // 'challenge.action.type.created',
6161
ChallengeTypeUpdated: 'test.new.bus.events', // 'challenge.action.type.updated',
62+
ChallengeTrackCreated: 'test.new.bus.events', // 'challenge.action.track.created',
63+
ChallengeTrackUpdated: 'test.new.bus.events', // 'challenge.action.track.updated',
6264
ChallengePhaseCreated: 'test.new.bus.events', // 'challenge.action.phase.created',
6365
ChallengePhaseUpdated: 'test.new.bus.events', // 'challenge.action.phase.updated',
6466
ChallengePhaseDeleted: 'test.new.bus.events', // 'challenge.action.phase.deleted',
6567
TimelineTemplateCreated: 'test.new.bus.events', // 'challenge.action.timeline.template.created',
6668
TimelineTemplateUpdated: 'test.new.bus.events', // 'challenge.action.timeline.template.updated',
6769
TimelineTemplateDeleted: 'test.new.bus.events', // 'challenge.action.timeline.template.deleted',
68-
ChallengeTypeTimelineTemplateCreated: 'test.new.bus.events', // 'challenge.action.type.timeline.template.created',
69-
ChallengeTypeTimelineTemplateUpdated: 'test.new.bus.events', // 'challenge.action.type.timeline.template.updated',
70-
ChallengeTypeTimelineTemplateDeleted: 'test.new.bus.events', // 'challenge.action.type.timeline.template.deleted'
70+
ChallengeTimelineTemplateCreated: 'test.new.bus.events', // 'challenge.action.timeline.template.created',
71+
ChallengeTimelineTemplateUpdated: 'test.new.bus.events', // 'challenge.action.timeline.template.updated',
72+
ChallengeTimelineTemplateDeleted: 'test.new.bus.events', // 'challenge.action.timeline.template.deleted'
7173
ChallengeAttachmentCreated: 'test.new.bus.events', // 'challenge.action.attachment.created',
7274
ChallengeAttachmentUpdated: 'test.new.bus.events', // 'challenge.action.attachment.updated',
7375
ChallengeAttachmentDeleted: 'test.new.bus.events' // 'challenge.action.attachment.deleted',
@@ -85,11 +87,6 @@ const challengeTextSortField = {
8587
TypeId: 'typeId'
8688
}
8789

88-
const reviewTypes = {
89-
Community: 'COMMUNITY',
90-
Internal: 'INTERNAL'
91-
}
92-
9390
module.exports = {
9491
UserRoles,
9592
prizeSetTypes,
@@ -100,6 +97,5 @@ module.exports = {
10097
Topics,
10198
challengeTracks,
10299
challengeTextSortField,
103-
DiscussionTypes,
104-
reviewTypes
100+
DiscussionTypes
105101
}

config/default.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ module.exports = {
3232
IS_LOCAL_DB: process.env.IS_LOCAL_DB || true,
3333
DYNAMODB_URL: process.env.DYNAMODB_URL || 'http://localhost:7777',
3434
S3_API_VERSION: process.env.S3_API_VERSION || '2006-03-01',
35-
BUCKET_WHITELIST: process.env.BUCKET_WHITELIST || 'topcoder_01, topcoder_02'
35+
// BUCKET_WHITELIST: process.env.BUCKET_WHITELIST || 'topcoder_01, topcoder_02, key1, key2'
36+
BUCKET_WHITELIST: process.env.BUCKET_WHITELIST || 'topcoder_01, topcoder_02, bucket, key1'
3637
},
3738

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

6263
MANAGER_ROLE_ID: process.env.MANAGER_ROLE_ID || '0e9c6879-39e4-4eb6-b8df-92407890faf1',
6364
OBSERVER_ROLE_ID: process.env.OBSERVER_ROLE_ID || '2a4dc376-a31c-4d00-b173-13934d89e286',

config/test.js

Lines changed: 5 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/swagger.yaml

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2555,10 +2555,6 @@ definitions:
25552555
reviewType:
25562556
type: string
25572557
description: the review type
2558-
enum:
2559-
- 'INTERNAL'
2560-
- 'COMMUNITY'
2561-
default: 'INTERNAL'
25622558
forumId:
25632559
type: integer
25642560
description: the forum id
@@ -2727,6 +2723,7 @@ definitions:
27272723
- prizeSets
27282724
- created
27292725
- createdBy
2726+
- reviewType
27302727
- tags
27312728
- status
27322729
Attachment:
@@ -2970,16 +2967,13 @@ definitions:
29702967
type: string
29712968
reviewType:
29722969
type: string
2973-
enum:
2974-
- 'INTERNAL'
2975-
- 'COMMUNITY'
2976-
default: 'INTERNAL'
29772970
confidentialityType:
29782971
type: string
29792972
forumId:
29802973
type: number
29812974
required:
29822975
- track
2976+
- reviewType
29832977
name:
29842978
type: string
29852979
description:
@@ -3257,6 +3251,7 @@ definitions:
32573251
- prizeSets
32583252
- created
32593253
- createdBy
3254+
- reviewType
32603255
- tags
32613256
- projectId
32623257
- forumId

local/docker-compose.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ services:
33
dynamodb:
44
image: tray/dynamodb-local
55
ports:
6-
- "8000:8000"
7-
command: "-inMemory -port 8000"
6+
- "7777:7777"
7+
command: "-inMemory -port 7777"
88
esearch:
99
image: "docker.elastic.co/elasticsearch/elasticsearch:6.8.0"
1010
ports:

mock-api/app.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,11 @@ app.get('/v5/resources', (req, res) => {
6161
res.json(resources)
6262
})
6363

64+
// post challenge resources
65+
app.post('/v5/resources', (req, res) => {
66+
res.json({})
67+
})
68+
6469
// get challenges member can access to
6570
app.get('/v5/resources/:memberId/challenges', (req, res) => {
6671
const memberId = req.params.memberId
@@ -219,6 +224,33 @@ app.get('/v5/terms/:termId', (req, res) => {
219224
}
220225
})
221226

227+
// get direct project
228+
app.get('/v3/direct/projects/:projectId', (req, res) => {
229+
const projectId = req.params.projectId
230+
if (projectId === '111' || projectId === '123' || projectId === '112233') {
231+
res.json({
232+
projectId,
233+
terms: ['0fcb41d1-ec7c-44bb-8f3b-f017a61cd708', 'be0652ae-8b28-4e91-9b42-8ad00b31e9cb'],
234+
result: {
235+
content: {
236+
billingAccountIds: ['0fcb41d1-ec7c-44bb-8f3b-f017a61cd708', 'be0652ae-8b28-4e91-9b42-8ad00b31e9cb']
237+
}
238+
}
239+
})
240+
} else if (projectId === '200') {
241+
res.status(403).send({
242+
id: '6e97fe68-f89c-4c45-b25b-d17933a3c4b9',
243+
result: {
244+
success: false,
245+
status: 403,
246+
content: { message: 'You do not have permissions to perform this action' }
247+
}
248+
})
249+
} else {
250+
res.status(404).end()
251+
}
252+
})
253+
222254
app.use((req, res) => {
223255
res.status(404).json({ error: 'route not found' })
224256
})

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
"check-timeline-templates": "node src/scripts/check-templates.js",
1717
"view-data": "node src/scripts/view-data.js",
1818
"view-es-data": "node src/scripts/view-es-data.js",
19-
"test": "mocha --require test/prepare.js -t 20000 test/unit/*.test.js --exit",
20-
"e2e": "mocha --require test/prepare.js -t 20000 test/e2e/*.test.js --exit",
19+
"test": "mocha --require test/prepare.js -t 30000 test/unit/*.test.js --exit",
20+
"e2e": "mocha --require test/prepare.js -t 30000 test/e2e/*.test.js --exit",
2121
"test:cov": "nyc --reporter=html --reporter=text npm test",
2222
"e2e:cov": "nyc --reporter=html --reporter=text npm run e2e"
2323
},

src/common/helper.js

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -206,21 +206,6 @@ async function getById (modelName, id) {
206206
})
207207
}
208208

209-
/**
210-
* Get Data by model ids
211-
* @param {String} modelName The dynamoose model name
212-
* @param {Array} ids The ids
213-
* @returns {Promise<Array>} the found entities
214-
*/
215-
async function getByIds (modelName, ids) {
216-
const entities = []
217-
const theIds = ids || []
218-
for (const id of theIds) {
219-
entities.push(await getById(modelName, id))
220-
}
221-
return entities
222-
}
223-
224209
/**
225210
* Validate the data to ensure no duplication
226211
* @param {Object} modelName The dynamoose model name
@@ -295,23 +280,6 @@ async function scan (modelName, scanParams) {
295280
})
296281
}
297282

298-
/**
299-
* Get all data collection (avoid default page limit of DynamoDB) by scan parameters
300-
* @param {Object} modelName The dynamoose model name
301-
* @param {Object} scanParams The scan parameters object
302-
* @returns {Array}
303-
*/
304-
async function scanAll (modelName, scanParams) {
305-
let results = await models[modelName].scan(scanParams).exec()
306-
let lastKey = results.lastKey
307-
while (!_.isUndefined(results.lastKey)) {
308-
const newResult = await models[modelName].scan(scanParams).startAt(lastKey).exec()
309-
results = [...results, ...newResult]
310-
lastKey = newResult.lastKey
311-
}
312-
return results
313-
}
314-
315283
/**
316284
* Test whether the given value is partially match the filter.
317285
* @param {String} filter the filter
@@ -963,11 +931,9 @@ module.exports = {
963931
hasAdminRole,
964932
toString,
965933
getById,
966-
getByIds,
967934
create,
968935
update,
969936
scan,
970-
scanAll,
971937
validateDuplicate,
972938
partialMatch,
973939
validatePhases,

0 commit comments

Comments
 (0)