mirror of
https://github.com/ajayyy/SponsorBlockServer.git
synced 2025-12-13 06:57:05 +03:00
Fix voting on an existing submission not working.
This commit is contained in:
@@ -133,8 +133,6 @@ async function handleExistingVotes(type: BrandingType, videoID: VideoID,
|
|||||||
* Will update public vote totals and locked status.
|
* Will update public vote totals and locked status.
|
||||||
*/
|
*/
|
||||||
async function updateVoteTotals(type: BrandingType, existingVote: ExistingVote, UUID: BrandingUUID, isVip: boolean): Promise<void> {
|
async function updateVoteTotals(type: BrandingType, existingVote: ExistingVote, UUID: BrandingUUID, isVip: boolean): Promise<void> {
|
||||||
if (!existingVote) return;
|
|
||||||
|
|
||||||
const table = type === BrandingType.Title ? `"titleVotes"` : `"thumbnailVotes"`;
|
const table = type === BrandingType.Title ? `"titleVotes"` : `"thumbnailVotes"`;
|
||||||
|
|
||||||
// Don't upvote if we vote on the same submission
|
// Don't upvote if we vote on the same submission
|
||||||
|
|||||||
@@ -448,6 +448,59 @@ describe("postBranding", () => {
|
|||||||
assert.strictEqual(oldDBVotes.shadowHidden, 0);
|
assert.strictEqual(oldDBVotes.shadowHidden, 0);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("Vote for an existing title from another user", async () => {
|
||||||
|
const videoID = "postBrand1";
|
||||||
|
const title = {
|
||||||
|
title: "Some other title",
|
||||||
|
original: false
|
||||||
|
};
|
||||||
|
|
||||||
|
const res = await postBranding({
|
||||||
|
title,
|
||||||
|
userID: userID4,
|
||||||
|
service: Service.YouTube,
|
||||||
|
videoID
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.strictEqual(res.status, 200);
|
||||||
|
const dbTitle = await queryTitleByVideo(videoID);
|
||||||
|
const dbVotes = await queryTitleVotesByUUID(dbTitle.UUID);
|
||||||
|
|
||||||
|
assert.strictEqual(dbTitle.title, title.title);
|
||||||
|
assert.strictEqual(dbTitle.original, title.original ? 1 : 0);
|
||||||
|
|
||||||
|
assert.strictEqual(dbVotes.votes, 1);
|
||||||
|
assert.strictEqual(dbVotes.locked, 0);
|
||||||
|
assert.strictEqual(dbVotes.shadowHidden, 0);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("Vote for the same thumbnail from a different user", async () => {
|
||||||
|
const videoID = "postBrand4";
|
||||||
|
const thumbnail = {
|
||||||
|
timestamp: 15.34,
|
||||||
|
original: false
|
||||||
|
};
|
||||||
|
|
||||||
|
const res = await postBranding({
|
||||||
|
thumbnail,
|
||||||
|
userID: userID1,
|
||||||
|
service: Service.YouTube,
|
||||||
|
videoID
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.strictEqual(res.status, 200);
|
||||||
|
const dbThumbnail = await queryThumbnailByVideo(videoID);
|
||||||
|
const dbThumbnailTimestamps = await queryThumbnailTimestampsByUUID(dbThumbnail.UUID);
|
||||||
|
const dbVotes = await queryThumbnailVotesByUUID(dbThumbnail.UUID);
|
||||||
|
|
||||||
|
assert.strictEqual(dbThumbnailTimestamps.timestamp, thumbnail.timestamp);
|
||||||
|
assert.strictEqual(dbThumbnail.original, thumbnail.original ? 1 : 0);
|
||||||
|
|
||||||
|
assert.strictEqual(dbVotes.votes, 1);
|
||||||
|
assert.strictEqual(dbVotes.locked, 0);
|
||||||
|
assert.strictEqual(dbVotes.shadowHidden, 0);
|
||||||
|
});
|
||||||
|
|
||||||
it("Submit from unverified user", async () => {
|
it("Submit from unverified user", async () => {
|
||||||
const videoID = "postBrandUnverified";
|
const videoID = "postBrandUnverified";
|
||||||
const title = {
|
const title = {
|
||||||
|
|||||||
Reference in New Issue
Block a user