Skip to content

Commit bcf862f

Browse files
authored
Merge pull request #509 from topcoder-platform/July2022Updates
July 2022 updates, cherry picked (v1.4.10)
2 parents fae139c + f214ec7 commit bcf862f

File tree

5 files changed

+100
-6
lines changed

5 files changed

+100
-6
lines changed

Diff for: .circleci/config.yml

+1
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ workflows:
7272
- develop
7373
- fix/challenge-timelines-edit-routes
7474
- test/performance-profile
75+
- July2022Updates
7576

7677
# Production builds are exectuted only on tagged commits to the
7778
# master branch.

Diff for: docs/swagger.yaml

+5
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,11 @@ paths:
390390
type: array
391391
items:
392392
type: string
393+
- name: tco
394+
in: query
395+
description: Filter by tco eligible events
396+
required: false
397+
type: boolean
393398
- name: includeAllEvents
394399
in: query
395400
description: Require all provided events to be present on a challenge for a match

Diff for: docs/topcoder-challenge-api.postman_collection.json

+76-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
{
22
"info": {
3-
"_postman_id": "76b5f465-ec2b-493e-b489-7a7ecaf47926",
3+
"_postman_id": "51d151f8-d3f4-42b2-9ebe-6b76d419d750",
44
"name": "E2E Tests",
5-
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
5+
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json",
6+
"_exporter_id": "3014204"
67
},
78
"item": [
89
{
@@ -3851,6 +3852,79 @@
38513852
}
38523853
},
38533854
"response": []
3855+
},
3856+
{
3857+
"name": "Get TCO Eligible Challenges",
3858+
"event": [
3859+
{
3860+
"listen": "test",
3861+
"script": {
3862+
"exec": [
3863+
"pm.test(\"Status code is 200\", function () {\r",
3864+
" pm.response.to.have.status(200);\r",
3865+
"});"
3866+
],
3867+
"type": "text/javascript"
3868+
}
3869+
},
3870+
{
3871+
"listen": "prerequest",
3872+
"script": {
3873+
"exec": [
3874+
""
3875+
],
3876+
"type": "text/javascript"
3877+
}
3878+
}
3879+
],
3880+
"protocolProfileBehavior": {
3881+
"disableBodyPruning": true
3882+
},
3883+
"request": {
3884+
"method": "GET",
3885+
"header": [
3886+
{
3887+
"key": "Authorization",
3888+
"value": "Bearer {{TOKEN}}",
3889+
"type": "text"
3890+
},
3891+
{
3892+
"key": "Content-Type",
3893+
"name": "Content-Type",
3894+
"value": "application/json",
3895+
"type": "text"
3896+
}
3897+
],
3898+
"body": {
3899+
"mode": "raw",
3900+
"raw": "",
3901+
"options": {
3902+
"raw": {
3903+
"language": "json"
3904+
}
3905+
}
3906+
},
3907+
"url": {
3908+
"raw": "{{URL}}/challenges?tco=true&status=Active",
3909+
"host": [
3910+
"{{URL}}"
3911+
],
3912+
"path": [
3913+
"challenges"
3914+
],
3915+
"query": [
3916+
{
3917+
"key": "tco",
3918+
"value": "true"
3919+
},
3920+
{
3921+
"key": "status",
3922+
"value": "Active"
3923+
}
3924+
]
3925+
}
3926+
},
3927+
"response": []
38543928
}
38553929
]
38563930
},

Diff for: src/services/ChallengeService.js

+10-4
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,8 @@ async function searchChallenges (currentUser, criteria) {
273273
should: [
274274
{ wildcard: { name: `*${criteria.search}*` } },
275275
{ wildcard: { name: `${criteria.search}*` } },
276-
{ wildcard: { name: `*${criteria.search}` } }
276+
{ wildcard: { name: `*${criteria.search}` } },
277+
{ match_phrase: { tags: criteria.search } },
277278
]
278279
} })
279280
} else {
@@ -404,6 +405,10 @@ async function searchChallenges (currentUser, criteria) {
404405

405406
const groupsQuery = []
406407

408+
if (criteria.tco) {
409+
boolQuery.push({ match_phrase_prefix: { 'events.key': 'tco' } })
410+
}
411+
407412
if (criteria.events) {
408413
boolQuery.push({
409414
bool: {
@@ -662,14 +667,14 @@ async function searchChallenges (currentUser, criteria) {
662667
}
663668
}
664669

665-
logger.debug(`es Query ${JSON.stringify(esQuery)}`)
670+
logger.debug(`es Query ${JSON.stringify(esQuery, null, 4)}`)
666671
// Search with constructed query
667672
let docs
668673
try {
669674
docs = await esClient.search(esQuery)
670675
} catch (e) {
671676
// Catch error when the ES is fresh and has no data
672-
logger.error(`Query Error from ES ${JSON.stringify(e)}`)
677+
logger.error(`Query Error from ES ${JSON.stringify(e, null, 4)}`)
673678
docs = {
674679
hits: {
675680
total: 0,
@@ -791,7 +796,8 @@ searchChallenges.schema = {
791796
includeAllEvents: Joi.boolean().default(true),
792797
useSchedulingAPI: Joi.boolean(),
793798
totalPrizesFrom: Joi.number().min(0),
794-
totalPrizesTo: Joi.number().min(0)
799+
totalPrizesTo: Joi.number().min(0),
800+
tco: Joi.boolean().default(false)
795801
}).unknown(true)
796802
}
797803

Diff for: test/unit/ChallengeService.test.js

+8
Original file line numberDiff line numberDiff line change
@@ -579,6 +579,14 @@ describe('challenge service unit tests', () => {
579579
should.equal(testHelper.deepCompareArrays(result.terms, _.map(data.defaultProjectTerms, t => t.id)), true)
580580
})
581581

582+
it('search challenges successfully 5 - with tco eligible events', async () => {
583+
const result = await service.searchChallenges({ isMachine: true }, { tco: true })
584+
should.equal(result.total, 0)
585+
should.equal(result.page, 1)
586+
should.equal(result.perPage, 20)
587+
should.equal(result.result.length, 0)
588+
})
589+
582590
it('search challenges - invalid name', async () => {
583591
try {
584592
await service.searchChallenges({ isMachine: true }, { name: ['invalid'] })

0 commit comments

Comments
 (0)