Skip to content

July 2022 updates, cherry picked (v1.4.10) #509

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
Jul 19, 2022
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
1 change: 1 addition & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ workflows:
- develop
- fix/challenge-timelines-edit-routes
- test/performance-profile
- July2022Updates

# Production builds are exectuted only on tagged commits to the
# master branch.
Expand Down
5 changes: 5 additions & 0 deletions docs/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,11 @@ paths:
type: array
items:
type: string
- name: tco
in: query
description: Filter by tco eligible events
required: false
type: boolean
- name: includeAllEvents
in: query
description: Require all provided events to be present on a challenge for a match
Expand Down
78 changes: 76 additions & 2 deletions docs/topcoder-challenge-api.postman_collection.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
{
"info": {
"_postman_id": "76b5f465-ec2b-493e-b489-7a7ecaf47926",
"_postman_id": "51d151f8-d3f4-42b2-9ebe-6b76d419d750",
"name": "E2E Tests",
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json",
"_exporter_id": "3014204"
},
"item": [
{
Expand Down Expand Up @@ -3851,6 +3852,79 @@
}
},
"response": []
},
{
"name": "Get TCO Eligible Challenges",
"event": [
{
"listen": "test",
"script": {
"exec": [
"pm.test(\"Status code is 200\", function () {\r",
" pm.response.to.have.status(200);\r",
"});"
],
"type": "text/javascript"
}
},
{
"listen": "prerequest",
"script": {
"exec": [
""
],
"type": "text/javascript"
}
}
],
"protocolProfileBehavior": {
"disableBodyPruning": true
},
"request": {
"method": "GET",
"header": [
{
"key": "Authorization",
"value": "Bearer {{TOKEN}}",
"type": "text"
},
{
"key": "Content-Type",
"name": "Content-Type",
"value": "application/json",
"type": "text"
}
],
"body": {
"mode": "raw",
"raw": "",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "{{URL}}/challenges?tco=true&status=Active",
"host": [
"{{URL}}"
],
"path": [
"challenges"
],
"query": [
{
"key": "tco",
"value": "true"
},
{
"key": "status",
"value": "Active"
}
]
}
},
"response": []
}
]
},
Expand Down
14 changes: 10 additions & 4 deletions src/services/ChallengeService.js
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,8 @@ async function searchChallenges (currentUser, criteria) {
should: [
{ wildcard: { name: `*${criteria.search}*` } },
{ wildcard: { name: `${criteria.search}*` } },
{ wildcard: { name: `*${criteria.search}` } }
{ wildcard: { name: `*${criteria.search}` } },
{ match_phrase: { tags: criteria.search } },
]
} })
} else {
Expand Down Expand Up @@ -404,6 +405,10 @@ async function searchChallenges (currentUser, criteria) {

const groupsQuery = []

if (criteria.tco) {
boolQuery.push({ match_phrase_prefix: { 'events.key': 'tco' } })
}

if (criteria.events) {
boolQuery.push({
bool: {
Expand Down Expand Up @@ -662,14 +667,14 @@ async function searchChallenges (currentUser, criteria) {
}
}

logger.debug(`es Query ${JSON.stringify(esQuery)}`)
logger.debug(`es Query ${JSON.stringify(esQuery, null, 4)}`)
// Search with constructed query
let docs
try {
docs = await esClient.search(esQuery)
} catch (e) {
// Catch error when the ES is fresh and has no data
logger.error(`Query Error from ES ${JSON.stringify(e)}`)
logger.error(`Query Error from ES ${JSON.stringify(e, null, 4)}`)
docs = {
hits: {
total: 0,
Expand Down Expand Up @@ -791,7 +796,8 @@ searchChallenges.schema = {
includeAllEvents: Joi.boolean().default(true),
useSchedulingAPI: Joi.boolean(),
totalPrizesFrom: Joi.number().min(0),
totalPrizesTo: Joi.number().min(0)
totalPrizesTo: Joi.number().min(0),
tco: Joi.boolean().default(false)
}).unknown(true)
}

Expand Down
8 changes: 8 additions & 0 deletions test/unit/ChallengeService.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -579,6 +579,14 @@ describe('challenge service unit tests', () => {
should.equal(testHelper.deepCompareArrays(result.terms, _.map(data.defaultProjectTerms, t => t.id)), true)
})

it('search challenges successfully 5 - with tco eligible events', async () => {
const result = await service.searchChallenges({ isMachine: true }, { tco: true })
should.equal(result.total, 0)
should.equal(result.page, 1)
should.equal(result.perPage, 20)
should.equal(result.result.length, 0)
})

it('search challenges - invalid name', async () => {
try {
await service.searchChallenges({ isMachine: true }, { name: ['invalid'] })
Expand Down