add test for downvote videoDuration change

This commit is contained in:
Michael C
2022-02-04 00:21:15 -05:00
parent f3d10bd19f
commit 5713b96d13
4 changed files with 44 additions and 18 deletions

View File

@@ -92,25 +92,24 @@ async function checkVideoDuration(UUID: SegmentUUID) {
}
const apiVideoDuration = apiVideoInfo?.data?.lengthSeconds as VideoDuration;
// if no videoDuration return early
if (!apiVideoDuration && apiVideoDuration != 0) return;
if (isNaN(apiVideoDuration)) return;
// fetch latest submission
const latestSubmission = await db.prepare("get", `SELECT "videoDuration, UUID, submissionTime
FROM "sponsorTimes
const latestSubmission = await db.prepare("get", `SELECT "videoDuration", "UUID", "timeSubmitted"
FROM "sponsorTimes"
WHERE "videoID" = ? AND "service" = ? AND
"hidden" = 0 AND "shadowHidden" = 0 AND
"actionType" != 'full' AND
"votes" > -2 AND "videoDuration" != 0
ORDER BY "submissionTime" DESC
TOP 1`,
[videoID, service]) as {videoDuration: VideoDuration, UUID: SegmentUUID, submissionTime: number};
ORDER BY "timeSubmitted" DESC LIMIT 1`,
[videoID, service]) as {videoDuration: VideoDuration, UUID: SegmentUUID, timeSubmitted: number};
if (videoDurationChanged(latestSubmission.videoDuration, apiVideoDuration)) {
Logger.info(`Video duration changed for ${videoID} from ${latestSubmission.videoDuration} to ${apiVideoDuration}`);
await db.prepare("run", `UPDATE "sponsorTimes" SET "hidden" = 1
WHERE videoID = ? AND service = ? AND submissionTime < ?
hidden" = 0 AND "shadowHidden" = 0 AND
WHERE videoID = ? AND service = ? AND timeSubmitted <= ?
AND "hidden" = 0 AND "shadowHidden" = 0 AND
"actionType" != 'full' AND "votes" > -2`,
[videoID, service, latestSubmission.submissionTime]);
[videoID, service, latestSubmission.timeSubmitted]);
}
}
@@ -421,7 +420,7 @@ export async function vote(ip: IPAddress, UUID: SegmentUUID, paramUserID: UserID
// no restrictions on checkDuration
// check duration of all submissions on this video
if (type < 0) {
if (type <= 0) {
checkVideoDuration(UUID);
}
@@ -487,11 +486,8 @@ export async function vote(ip: IPAddress, UUID: SegmentUUID, paramUserID: UserID
&& !finalResponse.blockVote
&& finalResponse.finalStatus === 200;
const tempVIPAbleToVote = isTempVIP
&& (await db.prepare("get", `SELECT COUNT(*) FROM "sponsorTimes" WHERE "userID" = ?`, [nonAnonUserID])) >= 5
&& userAbleToVote;
const ableToVote = isVIP || userAbleToVote || tempVIPAbleToVote;
const ableToVote = isVIP || isTempVIP || userAbleToVote;
if (ableToVote) {
//update the votes table
@@ -504,16 +500,20 @@ export async function vote(ip: IPAddress, UUID: SegmentUUID, paramUserID: UserID
// update the vote count on this sponsorTime
await db.prepare("run", `UPDATE "sponsorTimes" SET "votes" = "votes" + ? WHERE "UUID" = ?`, [incrementAmount - oldIncrementAmount, UUID]);
// additional procesing for VIP
// tempVIP can bring back hidden segments
if (isTempVIP && incrementAmount > 0 && voteTypeEnum === voteTypes.normal) {
await db.prepare("run", `UPDATE "sponsorTimes" SET "hidden" = 0 WHERE "UUID" = ?`, [UUID]);
}
// additional processing for VIP
// on VIP upvote
if (isVIP && incrementAmount > 0 && voteTypeEnum === voteTypes.normal) {
// Update video duration in case that caused it to be hidden
await updateSegmentVideoDuration(UUID);
// unhide & unlock
await db.prepare("run", 'UPDATE "sponsorTimes" SET locked = 1, hidden = 0, "shadowHidden" = 0 WHERE "UUID" = ?', [UUID]);
await db.prepare("run", 'UPDATE "sponsorTimes" SET "locked" = 1, "hidden" = 0, "shadowHidden" = 0 WHERE "UUID" = ?', [UUID]);
// on VIP downvote/ undovote, also unlock submission
} else if (isVIP && incrementAmount <= 0 && voteTypeEnum === voteTypes.normal) {
await db.prepare("run", 'UPDATE "sponsorTimes" SET locked = 0 WHERE "UUID" = ?', [UUID]);
await db.prepare("run", 'UPDATE "sponsorTimes" SET "locked" = 0 WHERE "UUID" = ?', [UUID]);
}
QueryCacher.clearSegmentCache(segmentInfo);

View File

@@ -64,7 +64,6 @@ describe("tempVIP test", function() {
await db.prepare("run", insertSponsorTimeQuery, ["channelid-convert", 1, 9, 0, 1, "tempvip-submit", publicTempVIPOne, 0, 50, "sponsor", 0]);
await db.prepare("run", insertSponsorTimeQuery, ["otherchannel", 1, 9, 0, 1, UUID1, "testman", 0, 50, "sponsor", 0]);
await db.prepare("run", 'INSERT INTO "vipUsers" ("userID") VALUES (?)', [publicPermVIP1]);
await db.prepare("run", 'INSERT INTO "vipUsers" ("userID") VALUES (?)', [publicPermVIP2]);
// clear redis if running consecutive tests

View File

@@ -58,6 +58,12 @@ describe("voteOnSponsorTime", () => {
await db.prepare("run", insertSponsorTimeQuery, ["category-change-test-1", 7, 12, 0, 1, "category-change-uuid-8", categoryChangeUserHash, 0, 50, "intro", "skip", 0, 0]);
await db.prepare("run", insertSponsorTimeQuery, ["duration-update", 1, 10, 0, 0, "duration-update-uuid-1", "testman", 0, 0, "intro", "skip", 0, 0]);
await db.prepare("run", insertSponsorTimeQuery, ["full-video", 1, 10, 0, 0, "full-video-uuid-1", "testman", 0, 0, "sponsor", "full", 0, 0]);
// videoDuration change
await db.prepare("run", insertSponsorTimeQuery, ["duration-changed", 1, 10, 0, 0, "duration-changed-uuid-1", "testman", 1, 0, "sponsor", "skip", 0, 0]);
await db.prepare("run", insertSponsorTimeQuery, ["duration-changed", 1, 11, 0, 0, "duration-changed-uuid-2", "testman", 10, 0, "sponsor", "skip", 0, 0]);
await db.prepare("run", insertSponsorTimeQuery, ["duration-changed", 1, 12, 0, 0, "duration-changed-uuid-3", "testman", 20, 0, "sponsor", "skip", 0, 0]);
// add videoDuration to duration-changed-uuid-2
await db.prepare("run", `UPDATE "sponsorTimes" SET "videoDuration" = 150 WHERE "UUID" = 'duration-changed-uuid-2'`);
const insertWarningQuery = 'INSERT INTO "warnings" ("userID", "issueTime", "issuerUserID", "enabled") VALUES(?, ?, ?, ?)';
await db.prepare("run", insertWarningQuery, [warnUser01Hash, now, warnVip01Hash, 1]);
@@ -585,4 +591,18 @@ describe("voteOnSponsorTime", () => {
done();
});
});
it("Should hide changed submission on any downvote", (done) => {
const UUID = "duration-changed-uuid-3";
const videoID = "duration-changed";
postVote(randomID2, UUID, 0)
.then(async res => {
assert.strictEqual(res.status, 200);
const hiddenSegments = await db.prepare("all", `SELECT "UUID" FROM "sponsorTimes" WHERE "videoID" = ? AND "hidden" = 1`, [videoID]);
assert.strictEqual(hiddenSegments.length, 2);
assert.strictEqual(hiddenSegments[0].UUID, "duration-changed-uuid-1");
assert.strictEqual(hiddenSegments[1].UUID, "duration-changed-uuid-2");
done();
});
});
});

View File

@@ -56,6 +56,13 @@ export class YouTubeApiMock {
authorId: "ChannelID"
} as APIVideoData
};
} else if (obj.id === "duration-changed") {
return {
err: null,
data: {
lengthSeconds: 100,
} as APIVideoData
};
} else {
return {
err: null,