Skip to content

Commit bbdece6

Browse files
Merge pull request #406 from topcoder-platform/revert-365-increase-cov
Revert "Increase testing coverage"
2 parents 30b773d + 15b6407 commit bbdece6

38 files changed

+1650
-2862
lines changed

README.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,7 @@ 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
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
108+
- https://github.com/topcoder-platform/challenge-api/blob/develop/src/models/Challenge.js#L116
111109
`throughput: 'ON_DEMAND',` should be updated to `throughput:{ read: 4, write: 2 },`
112110
- https://github.com/topcoder-platform/challenge-api/blob/develop/config/default.js#L27-L28
113111
Two aws config should be uncommented

Verification.md

Lines changed: 0 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -22,98 +22,3 @@ 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: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,17 +59,15 @@ 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',
6462
ChallengePhaseCreated: 'test.new.bus.events', // 'challenge.action.phase.created',
6563
ChallengePhaseUpdated: 'test.new.bus.events', // 'challenge.action.phase.updated',
6664
ChallengePhaseDeleted: 'test.new.bus.events', // 'challenge.action.phase.deleted',
6765
TimelineTemplateCreated: 'test.new.bus.events', // 'challenge.action.timeline.template.created',
6866
TimelineTemplateUpdated: 'test.new.bus.events', // 'challenge.action.timeline.template.updated',
6967
TimelineTemplateDeleted: 'test.new.bus.events', // 'challenge.action.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'
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'
7371
ChallengeAttachmentCreated: 'test.new.bus.events', // 'challenge.action.attachment.created',
7472
ChallengeAttachmentUpdated: 'test.new.bus.events', // 'challenge.action.attachment.updated',
7573
ChallengeAttachmentDeleted: 'test.new.bus.events' // 'challenge.action.attachment.deleted',
@@ -87,6 +85,11 @@ const challengeTextSortField = {
8785
TypeId: 'typeId'
8886
}
8987

88+
const reviewTypes = {
89+
Community: 'COMMUNITY',
90+
Internal: 'INTERNAL'
91+
}
92+
9093
module.exports = {
9194
UserRoles,
9295
prizeSetTypes,
@@ -97,5 +100,6 @@ module.exports = {
97100
Topics,
98101
challengeTracks,
99102
challengeTextSortField,
100-
DiscussionTypes
103+
DiscussionTypes,
104+
reviewTypes
101105
}

config/default.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,7 @@ 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, key1, key2'
36-
BUCKET_WHITELIST: process.env.BUCKET_WHITELIST || 'topcoder_01, topcoder_02, bucket, key1'
35+
BUCKET_WHITELIST: process.env.BUCKET_WHITELIST || 'topcoder_01, topcoder_02'
3736
},
3837

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

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

config/test.js

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

docs/swagger.yaml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2555,6 +2555,10 @@ definitions:
25552555
reviewType:
25562556
type: string
25572557
description: the review type
2558+
enum:
2559+
- 'INTERNAL'
2560+
- 'COMMUNITY'
2561+
default: 'INTERNAL'
25582562
forumId:
25592563
type: integer
25602564
description: the forum id
@@ -2723,7 +2727,6 @@ definitions:
27232727
- prizeSets
27242728
- created
27252729
- createdBy
2726-
- reviewType
27272730
- tags
27282731
- status
27292732
Attachment:
@@ -2967,13 +2970,16 @@ definitions:
29672970
type: string
29682971
reviewType:
29692972
type: string
2973+
enum:
2974+
- 'INTERNAL'
2975+
- 'COMMUNITY'
2976+
default: 'INTERNAL'
29702977
confidentialityType:
29712978
type: string
29722979
forumId:
29732980
type: number
29742981
required:
29752982
- track
2976-
- reviewType
29772983
name:
29782984
type: string
29792985
description:
@@ -3251,7 +3257,6 @@ definitions:
32513257
- prizeSets
32523258
- created
32533259
- createdBy
3254-
- reviewType
32553260
- tags
32563261
- projectId
32573262
- 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-
- "7777:7777"
7-
command: "-inMemory -port 7777"
6+
- "8000:8000"
7+
command: "-inMemory -port 8000"
88
esearch:
99
image: "docker.elastic.co/elasticsearch/elasticsearch:6.8.0"
1010
ports:

mock-api/app.js

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,6 @@ 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-
6964
// get challenges member can access to
7065
app.get('/v5/resources/:memberId/challenges', (req, res) => {
7166
const memberId = req.params.memberId
@@ -224,33 +219,6 @@ app.get('/v5/terms/:termId', (req, res) => {
224219
}
225220
})
226221

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-
254222
app.use((req, res) => {
255223
res.status(404).json({ error: 'route not found' })
256224
})

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 30000 test/unit/*.test.js --exit",
20-
"e2e": "mocha --require test/prepare.js -t 30000 test/e2e/*.test.js --exit",
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",
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: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,21 @@ 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+
209224
/**
210225
* Validate the data to ensure no duplication
211226
* @param {Object} modelName The dynamoose model name
@@ -280,6 +295,23 @@ async function scan (modelName, scanParams) {
280295
})
281296
}
282297

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+
283315
/**
284316
* Test whether the given value is partially match the filter.
285317
* @param {String} filter the filter
@@ -931,9 +963,11 @@ module.exports = {
931963
hasAdminRole,
932964
toString,
933965
getById,
966+
getByIds,
934967
create,
935968
update,
936969
scan,
970+
scanAll,
937971
validateDuplicate,
938972
partialMatch,
939973
validatePhases,

0 commit comments

Comments
 (0)