From 597dff7ac3e8c35ad341444bed0eed699a1f9d1a Mon Sep 17 00:00:00 2001 From: Ajay Ramachandran Date: Thu, 18 Feb 2021 22:09:57 -0500 Subject: [PATCH] Unlock segment if VIP downvotes --- src/routes/voteOnSponsorTime.ts | 3 +++ test/cases/voteOnSponsorTime.ts | 18 ++++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/src/routes/voteOnSponsorTime.ts b/src/routes/voteOnSponsorTime.ts index 0ea328d..1cc9cda 100644 --- a/src/routes/voteOnSponsorTime.ts +++ b/src/routes/voteOnSponsorTime.ts @@ -378,6 +378,9 @@ export async function voteOnSponsorTime(req: Request, res: Response) { if (isVIP && incrementAmount > 0 && voteTypeEnum === voteTypes.normal) { // Lock this submission db.prepare('run', "UPDATE sponsorTimes SET locked = 1 WHERE UUID = ?", [UUID]); + } else if (isVIP && incrementAmount < 0 && voteTypeEnum === voteTypes.normal) { + // Unlock if a VIP downvotes it + db.prepare('run', "UPDATE sponsorTimes SET locked = 0 WHERE UUID = ?", [UUID]); } //for each positive vote, see if a hidden submission can be shown again diff --git a/test/cases/voteOnSponsorTime.ts b/test/cases/voteOnSponsorTime.ts index 8ac4574..8345448 100644 --- a/test/cases/voteOnSponsorTime.ts +++ b/test/cases/voteOnSponsorTime.ts @@ -465,4 +465,22 @@ describe('voteOnSponsorTime', () => { .catch(err => done(err)); }); + it('VIP downvote should unlock segment', (done: Done) => { + fetch(getbaseURL() + + "/api/voteOnSponsorTime?userID=VIPUser&UUID=segment-locking-uuid-1&type=0") + .then(res => { + if (res.status === 200) { + let row = db.prepare('get', "SELECT locked FROM sponsorTimes WHERE UUID = ?", ["segment-locking-uuid-1"]); + if (!row?.locked) { + done(); + } else { + done("Segment not locked"); + } + } else { + done("Status code was " + res.status + " instead of 200"); + } + }) + .catch(err => done(err)); + }); + });