diff --git a/src/routes/postBranding.ts b/src/routes/postBranding.ts index 541b3f4..0b5901d 100644 --- a/src/routes/postBranding.ts +++ b/src/routes/postBranding.ts @@ -63,7 +63,7 @@ export async function postBranding(req: Request, res: Response) { if (isVip) { // unlock all other titles - await db.prepare("run", `UPDATE "titleVotes" SET "locked" = 0 FROM "titles" WHERE "titleVotes"."UUID" != ? AND "titles"."UUID" != ? AND "titles"."videoID" = ?`, [UUID, UUID, videoID]); + await db.prepare("run", `UPDATE "titleVotes" as tv SET "locked" = 0 FROM "titles" t WHERE tv."UUID" = t."UUID" AND tv."UUID" != ? AND t."videoID" = ?`, [UUID, videoID]); } } })(), (async () => { @@ -91,7 +91,7 @@ export async function postBranding(req: Request, res: Response) { if (isVip) { // unlock all other titles - await db.prepare("run", `UPDATE "thumbnailVotes" SET "locked" = 0 FROM "thumbnails" WHERE "thumbnailVotes"."UUID" != ? AND "thumbnails"."UUID" != ? AND "thumbnails"."videoID" = ?`, [UUID, UUID, videoID]); + await db.prepare("run", `UPDATE "thumbnailVotes" as tv SET "locked" = 0 FROM "thumbnails" t WHERE tv."UUID" = t."UUID" AND tv."UUID" != ? AND t."videoID" = ?`, [UUID, videoID]); } } } diff --git a/test/cases/postBranding.ts b/test/cases/postBranding.ts index 36b878a..249c6de 100644 --- a/test/cases/postBranding.ts +++ b/test/cases/postBranding.ts @@ -31,6 +31,20 @@ describe("postBranding", () => { const insertVipUserQuery = 'INSERT INTO "vipUsers" ("userID") VALUES (?)'; db.prepare("run", insertVipUserQuery, [getHash(vipUser)]); db.prepare("run", insertVipUserQuery, [getHash(vipUser2)]); + + const insertTitleQuery = 'INSERT INTO "titles" ("videoID", "title", "original", "userID", "service", "hashedVideoID", "timeSubmitted", "UUID") VALUES (?, ?, ?, ?, ?, ?, ?, ?)'; + db.prepare("run", insertTitleQuery, ["postBrandLocked1", "Some title", 0, getHash(userID1), Service.YouTube, getHash("postBrandLocked1"), Date.now(), "postBrandLocked1"]); + db.prepare("run", insertTitleQuery, ["postBrandLocked2", "Some title", 1, getHash(userID2), Service.YouTube, getHash("postBrandLocked2"), Date.now(), "postBrandLocked2"]); + const insertTitleVotesQuery = 'INSERT INTO "titleVotes" ("UUID", "votes", "locked", "shadowHidden") VALUES (?, ?, ?, ?);'; + db.prepare("run", insertTitleVotesQuery, ["postBrandLocked1", 0, 1, 0]); + db.prepare("run", insertTitleVotesQuery, ["postBrandLocked2", 0, 1, 0]); + + const insertThumbnailQuery = 'INSERT INTO "thumbnails" ("videoID", "original", "userID", "service", "hashedVideoID", "timeSubmitted", "UUID") VALUES (?, ?, ?, ?, ?, ?, ?)'; + db.prepare("run", insertThumbnailQuery, ["postBrandLocked1", 0, getHash(userID3), Service.YouTube, getHash("postBrandLocked1"), Date.now(), "postBrandLocked1"]); + db.prepare("run", insertThumbnailQuery, ["postBrandLocked2", 1, getHash(userID4), Service.YouTube, getHash("postBrandLocked2"), Date.now(), "postBrandLocked2"]); + const insertThumbnailVotesQuery = 'INSERT INTO "thumbnailVotes" ("UUID", "votes", "locked", "shadowHidden") VALUES (?, ?, ?, ?);'; + db.prepare("run", insertThumbnailVotesQuery, ["postBrandLocked1", 0, 1, 0]); + db.prepare("run", insertThumbnailVotesQuery, ["postBrandLocked2", 0, 1, 0]); }); it("Submit only title", async () => { @@ -261,6 +275,17 @@ describe("postBranding", () => { assert.strictEqual(dbThumbnailVotes.locked, 1); assert.strictEqual(dbThumbnailVotes.shadowHidden, 0); assert.strictEqual(dbThumbnailVotesOld.locked, 0); + + const otherSegmentTitleVotes1 = await queryTitleVotesByUUID("postBrandLocked1"); + const otherSegmentTitleVotes2 = await queryTitleVotesByUUID("postBrandLocked2"); + const otherSegmentThumbnailVotes1 = await queryThumbnailVotesByUUID("postBrandLocked1"); + const otherSegmentThumbnailVotes2 = await queryThumbnailVotesByUUID("postBrandLocked2"); + + // They should remain locked + assert.strictEqual(otherSegmentTitleVotes1.locked, 1); + assert.strictEqual(otherSegmentTitleVotes2.locked, 1); + assert.strictEqual(otherSegmentThumbnailVotes1.locked, 1); + assert.strictEqual(otherSegmentThumbnailVotes2.locked, 1); }); it("Vote the same title again", async () => {