Skip to content

Commit 93447c6

Browse files
Increase testing coverage
1 parent 8a00869 commit 93447c6

38 files changed

+2866
-1660
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: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,14 @@ module.exports = {
2525
KAFKA_ERROR_TOPIC: process.env.KAFKA_ERROR_TOPIC || 'common.error.reporting',
2626

2727
AMAZON: {
28-
// AWS_ACCESS_KEY_ID: process.env.AWS_FAKE_ID || 'FAKE_ACCESS_KEY',
29-
// AWS_SECRET_ACCESS_KEY: process.env.AWS_FAKE_KEY || 'FAKE_SECRET_ACCESS_KEY',
28+
AWS_ACCESS_KEY_ID: process.env.AWS_FAKE_ID || 'FAKE_ACCESS_KEY',
29+
AWS_SECRET_ACCESS_KEY: process.env.AWS_FAKE_KEY || 'FAKE_SECRET_ACCESS_KEY',
3030
AWS_REGION: process.env.AWS_REGION || 'ap-northeast-1',
3131
IS_LOCAL_DB: process.env.IS_LOCAL_DB || true,
3232
DYNAMODB_URL: process.env.DYNAMODB_URL || 'http://localhost:7777',
3333
S3_API_VERSION: process.env.S3_API_VERSION || '2006-03-01',
34-
BUCKET_WHITELIST: process.env.BUCKET_WHITELIST || 'topcoder_01, topcoder_02'
34+
// BUCKET_WHITELIST: process.env.BUCKET_WHITELIST || 'topcoder_01, topcoder_02, key1, key2'
35+
BUCKET_WHITELIST: process.env.BUCKET_WHITELIST || 'topcoder_01, topcoder_02, bucket, key1'
3536
},
3637

3738
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
@@ -2550,10 +2550,6 @@ definitions:
25502550
reviewType:
25512551
type: string
25522552
description: the review type
2553-
enum:
2554-
- 'INTERNAL'
2555-
- 'COMMUNITY'
2556-
default: 'INTERNAL'
25572553
forumId:
25582554
type: integer
25592555
description: the forum id
@@ -2722,6 +2718,7 @@ definitions:
27222718
- prizeSets
27232719
- created
27242720
- createdBy
2721+
- reviewType
27252722
- tags
27262723
- status
27272724
Attachment:
@@ -2965,16 +2962,13 @@ definitions:
29652962
type: string
29662963
reviewType:
29672964
type: string
2968-
enum:
2969-
- 'INTERNAL'
2970-
- 'COMMUNITY'
2971-
default: 'INTERNAL'
29722965
confidentialityType:
29732966
type: string
29742967
forumId:
29752968
type: number
29762969
required:
29772970
- track
2971+
- reviewType
29782972
name:
29792973
type: string
29802974
description:
@@ -3252,6 +3246,7 @@ definitions:
32523246
- prizeSets
32533247
- created
32543248
- createdBy
3249+
- reviewType
32553250
- tags
32563251
- projectId
32573252
- 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
@@ -15,8 +15,8 @@
1515
"seed-tables": "node src/scripts/seed-tables.js",
1616
"view-data": "node src/scripts/view-data.js",
1717
"view-es-data": "node src/scripts/view-es-data.js",
18-
"test": "mocha --require test/prepare.js -t 20000 test/unit/*.test.js --exit",
19-
"e2e": "mocha --require test/prepare.js -t 20000 test/e2e/*.test.js --exit",
18+
"test": "mocha --require test/prepare.js -t 30000 test/unit/*.test.js --exit",
19+
"e2e": "mocha --require test/prepare.js -t 30000 test/e2e/*.test.js --exit",
2020
"test:cov": "nyc --reporter=html --reporter=text npm test",
2121
"e2e:cov": "nyc --reporter=html --reporter=text npm run e2e"
2222
},

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
@@ -931,11 +899,9 @@ module.exports = {
931899
hasAdminRole,
932900
toString,
933901
getById,
934-
getByIds,
935902
create,
936903
update,
937904
scan,
938-
scanAll,
939905
validateDuplicate,
940906
partialMatch,
941907
validatePhases,

0 commit comments

Comments
 (0)