Skip to content
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
10 changes: 10 additions & 0 deletions src/services/ChallengeService.js
Original file line number Diff line number Diff line change
Expand Up @@ -1410,6 +1410,13 @@ async function searchChallenges(currentUser, criteria) {
});
}

// handle approvalStatus
if (!_.isNil(criteria.approvalStatus)) {
prismaFilter.where.AND.push({
approvalStatus: criteria.approvalStatus.toUpperCase(),
});
}

_.forEach(_.keys(criteria), (key) => {
if (_.toString(key).indexOf("meta.") > -1) {
// Parse and use metadata key
Expand Down Expand Up @@ -2129,6 +2136,9 @@ searchChallenges.schema = {
status: Joi.string()
.valid(..._.values(ChallengeStatusEnum))
.insensitive(),
approvalStatus: Joi.string()
.valid(..._.values(CHALLENGE_APPROVAL_STATUS))
.insensitive(),
group: Joi.string(),
startDateStart: Joi.date(),
startDateEnd: Joi.date(),
Expand Down
20 changes: 20 additions & 0 deletions test/unit/ChallengeService.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1190,6 +1190,16 @@ describe("challenge service unit tests", () => {
should.equal(result.result[0].name, data.challenge.name);
});

it("search challenges by approvalStatus case-insensitively", async () => {
const result = await service.searchChallenges(
{ isMachine: true },
{ approvalStatus: "approved" },
);

should.equal(result.total > 0, true);
should.equal(result.result.every((challenge) => challenge.approvalStatus === "APPROVED"), true);
});

it("search challenges successfully 3", async () => {
const res = await service.searchChallenges(
{ isMachine: true },
Expand Down Expand Up @@ -1403,6 +1413,16 @@ describe("challenge service unit tests", () => {
}
throw new Error("should not reach here");
});

it("search challenges - invalid approvalStatus", async () => {
try {
await service.searchChallenges({ isMachine: true }, { approvalStatus: "INVALID" });
} catch (e) {
should.equal(e.message.includes("approvalStatus") && e.message.includes("must be one of"), true);
return;
}
throw new Error("should not reach here");
});
});

describe("update challenge tests", () => {
Expand Down
Loading