From 7bf09906d34c2cba89cd11c0295fff13255a653d Mon Sep 17 00:00:00 2001 From: Ajay Ramachandran Date: Mon, 5 Apr 2021 22:33:28 -0400 Subject: [PATCH] Prevent voting for highlight category --- src/routes/voteOnSponsorTime.ts | 4 ++++ test/cases/voteOnSponsorTime.ts | 18 ++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/src/routes/voteOnSponsorTime.ts b/src/routes/voteOnSponsorTime.ts index c0aaac0..361e02f 100644 --- a/src/routes/voteOnSponsorTime.ts +++ b/src/routes/voteOnSponsorTime.ts @@ -170,6 +170,10 @@ async function categoryVote(UUID: SegmentUUID, userID: UserID, isVIP: boolean, i res.status(400).send("Category doesn't exist."); return; } + if (category === "highlight") { + res.status(400).send("Cannot vote for this category"); + return; + } const nextCategoryInfo = await db.prepare("get", `select votes from "categoryVotes" where "UUID" = ? and category = ?`, [UUID, category]); diff --git a/test/cases/voteOnSponsorTime.ts b/test/cases/voteOnSponsorTime.ts index 47a1f19..8e1cb61 100644 --- a/test/cases/voteOnSponsorTime.ts +++ b/test/cases/voteOnSponsorTime.ts @@ -264,6 +264,24 @@ describe('voteOnSponsorTime', () => { .catch(err => done(err)); }); + it('Should not able to change to highlight category', (done: Done) => { + fetch(getbaseURL() + + "/api/voteOnSponsorTime?userID=randomID2&UUID=incorrect-category&category=highlight") + .then(async res => { + if (res.status === 400) { + let row = await db.prepare('get', `SELECT "category" FROM "sponsorTimes" WHERE "UUID" = ?`, ["incorrect-category"]); + if (row.category === "sponsor") { + done(); + } else { + done("Vote did not succeed. Submission went from sponsor to " + row.category); + } + } else { + done("Status code was " + res.status); + } + }) + .catch(err => done(err)); + }); + it('Should be able to change your vote for a category and it should add your vote to the database', (done: Done) => { fetch(getbaseURL() + "/api/voteOnSponsorTime?userID=randomID2&UUID=vote-uuid-4&category=outro")