From f214ec77a161a34fd8edd113aa75ff07ab165fc6 Mon Sep 17 00:00:00 2001 From: Justin Gasper Date: Mon, 18 Jul 2022 10:01:33 +1000 Subject: [PATCH] July 2022 updates, cherry picked * Fix searching for TCO challenges * Fix searching by tags --- .circleci/config.yml | 1 + docs/swagger.yaml | 5 ++ ...oder-challenge-api.postman_collection.json | 78 ++++++++++++++++++- src/services/ChallengeService.js | 14 +++- test/unit/ChallengeService.test.js | 8 ++ 5 files changed, 100 insertions(+), 6 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 19a2a8fd..b49f0029 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -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. diff --git a/docs/swagger.yaml b/docs/swagger.yaml index 154d0a89..ec5fbba6 100644 --- a/docs/swagger.yaml +++ b/docs/swagger.yaml @@ -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 diff --git a/docs/topcoder-challenge-api.postman_collection.json b/docs/topcoder-challenge-api.postman_collection.json index 559db55b..83b93e63 100644 --- a/docs/topcoder-challenge-api.postman_collection.json +++ b/docs/topcoder-challenge-api.postman_collection.json @@ -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": [ { @@ -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": [] } ] }, diff --git a/src/services/ChallengeService.js b/src/services/ChallengeService.js index d7a01d55..cd1939d1 100644 --- a/src/services/ChallengeService.js +++ b/src/services/ChallengeService.js @@ -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 { @@ -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: { @@ -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, @@ -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) } diff --git a/test/unit/ChallengeService.test.js b/test/unit/ChallengeService.test.js index 0f449fe6..4f950548 100644 --- a/test/unit/ChallengeService.test.js +++ b/test/unit/ChallengeService.test.js @@ -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'] })