mirror of
https://github.com/ajayyy/SponsorBlockServer.git
synced 2025-12-13 15:06:59 +03:00
233
test/cases/getBranding.ts
Normal file
233
test/cases/getBranding.ts
Normal file
@@ -0,0 +1,233 @@
|
||||
import { client } from "../utils/httpClient";
|
||||
import assert from "assert";
|
||||
import { getHash } from "../../src/utils/getHash";
|
||||
import { db } from "../../src/databases/databases";
|
||||
import { Service } from "../../src/types/segments.model";
|
||||
import { BrandingResult, BrandingUUID } from "../../src/types/branding.model";
|
||||
import { partialDeepEquals } from "../utils/partialDeepEquals";
|
||||
|
||||
describe("getBranding", () => {
|
||||
const videoID1 = "videoID1";
|
||||
const videoID2Locked = "videoID2";
|
||||
const videoID2ShadowHide = "videoID3";
|
||||
const videoIDEmpty = "videoID4";
|
||||
|
||||
const videoID1Hash = getHash(videoID1, 1).slice(0, 4);
|
||||
const videoID2LockedHash = getHash(videoID2Locked, 1).slice(0, 4);
|
||||
const videoID2ShadowHideHash = getHash(videoID2ShadowHide, 1).slice(0, 4);
|
||||
const videoIDEmptyHash = "aaaa";
|
||||
|
||||
const endpoint = "/api/branding";
|
||||
const getBranding = (params: Record<string, any>) => client({
|
||||
method: "GET",
|
||||
url: endpoint,
|
||||
params
|
||||
});
|
||||
|
||||
const getBrandingByHash = (hash: string, params: Record<string, any>) => client({
|
||||
method: "GET",
|
||||
url: `${endpoint}/${hash}`,
|
||||
params
|
||||
});
|
||||
|
||||
before(async () => {
|
||||
const titleQuery = `INSERT INTO "titles" ("videoID", "title", "original", "userID", "service", "hashedVideoID", "timeSubmitted", "UUID") VALUES (?, ?, ?, ?, ?, ?, ?, ?)`;
|
||||
const titleVotesQuery = `INSERT INTO "titleVotes" ("UUID", "votes", "locked", "shadowHidden") VALUES (?, ?, ?, ?)`;
|
||||
const thumbnailQuery = `INSERT INTO "thumbnails" ("videoID", "original", "userID", "service", "hashedVideoID", "timeSubmitted", "UUID") VALUES (?, ?, ?, ?, ?, ?, ?)`;
|
||||
const thumbnailTimestampsQuery = `INSERT INTO "thumbnailTimestamps" ("UUID", "timestamp") VALUES (?, ?)`;
|
||||
const thumbnailVotesQuery = `INSERT INTO "thumbnailVotes" ("UUID", "votes", "locked", "shadowHidden") VALUES (?, ?, ?, ?)`;
|
||||
|
||||
await Promise.all([
|
||||
db.prepare("run", titleQuery, [videoID1, "title1", 0, "userID1", Service.YouTube, videoID1Hash, 1, "UUID1"]),
|
||||
db.prepare("run", titleQuery, [videoID1, "title2", 0, "userID2", Service.YouTube, videoID1Hash, 1, "UUID2"]),
|
||||
db.prepare("run", titleQuery, [videoID1, "title3", 1, "userID3", Service.YouTube, videoID1Hash, 1, "UUID3"]),
|
||||
db.prepare("run", thumbnailQuery, [videoID1, 0, "userID1", Service.YouTube, videoID1Hash, 1, "UUID1T"]),
|
||||
db.prepare("run", thumbnailQuery, [videoID1, 1, "userID2", Service.YouTube, videoID1Hash, 1, "UUID2T"]),
|
||||
db.prepare("run", thumbnailQuery, [videoID1, 0, "userID3", Service.YouTube, videoID1Hash, 1, "UUID3T"]),
|
||||
]);
|
||||
|
||||
await Promise.all([
|
||||
db.prepare("run", titleVotesQuery, ["UUID1", 3, 0, 0]),
|
||||
db.prepare("run", titleVotesQuery, ["UUID2", 2, 0, 0]),
|
||||
db.prepare("run", titleVotesQuery, ["UUID3", 1, 0, 0]),
|
||||
db.prepare("run", thumbnailTimestampsQuery, ["UUID1T", 1]),
|
||||
db.prepare("run", thumbnailTimestampsQuery, ["UUID3T", 3]),
|
||||
db.prepare("run", thumbnailVotesQuery, ["UUID1T", 3, 0, 0]),
|
||||
db.prepare("run", thumbnailVotesQuery, ["UUID2T", 2, 0, 0]),
|
||||
db.prepare("run", thumbnailVotesQuery, ["UUID3T", 1, 0, 0])
|
||||
]);
|
||||
|
||||
await Promise.all([
|
||||
db.prepare("run", titleQuery, [videoID2Locked, "title1", 0, "userID1", Service.YouTube, videoID2LockedHash, 1, "UUID11"]),
|
||||
db.prepare("run", titleQuery, [videoID2Locked, "title2", 0, "userID2", Service.YouTube, videoID2LockedHash, 1, "UUID21"]),
|
||||
db.prepare("run", titleQuery, [videoID2Locked, "title3", 1, "userID3", Service.YouTube, videoID2LockedHash, 1, "UUID31"]),
|
||||
db.prepare("run", thumbnailQuery, [videoID2Locked, 0, "userID1", Service.YouTube, videoID2LockedHash, 1, "UUID11T"]),
|
||||
db.prepare("run", thumbnailQuery, [videoID2Locked, 1, "userID2", Service.YouTube, videoID2LockedHash, 1, "UUID21T"]),
|
||||
db.prepare("run", thumbnailQuery, [videoID2Locked, 0, "userID3", Service.YouTube, videoID2LockedHash, 1, "UUID31T"])
|
||||
]);
|
||||
|
||||
await Promise.all([
|
||||
db.prepare("run", titleVotesQuery, ["UUID11", 3, 0, 0]),
|
||||
db.prepare("run", titleVotesQuery, ["UUID21", 2, 0, 0]),
|
||||
db.prepare("run", titleVotesQuery, ["UUID31", 1, 1, 0]),
|
||||
|
||||
db.prepare("run", thumbnailTimestampsQuery, ["UUID11T", 1]),
|
||||
db.prepare("run", thumbnailTimestampsQuery, ["UUID31T", 3]),
|
||||
db.prepare("run", thumbnailVotesQuery, ["UUID11T", 3, 0, 0]),
|
||||
db.prepare("run", thumbnailVotesQuery, ["UUID21T", 2, 0, 0]),
|
||||
db.prepare("run", thumbnailVotesQuery, ["UUID31T", 1, 1, 0]),
|
||||
]);
|
||||
|
||||
await Promise.all([
|
||||
db.prepare("run", titleQuery, [videoID2ShadowHide, "title1", 0, "userID1", Service.YouTube, videoID2ShadowHideHash, 1, "UUID12"]),
|
||||
db.prepare("run", titleQuery, [videoID2ShadowHide, "title2", 0, "userID2", Service.YouTube, videoID2ShadowHideHash, 1, "UUID22"]),
|
||||
db.prepare("run", titleQuery, [videoID2ShadowHide, "title3", 1, "userID3", Service.YouTube, videoID2ShadowHideHash, 1, "UUID32"]),
|
||||
db.prepare("run", thumbnailQuery, [videoID2ShadowHide, 0, "userID1", Service.YouTube, videoID2ShadowHideHash, 1, "UUID12T"]),
|
||||
db.prepare("run", thumbnailQuery, [videoID2ShadowHide, 1, "userID2", Service.YouTube, videoID2ShadowHideHash, 1, "UUID22T"]),
|
||||
db.prepare("run", thumbnailQuery, [videoID2ShadowHide, 0, "userID3", Service.YouTube, videoID2ShadowHideHash, 1, "UUID32T"])
|
||||
]);
|
||||
|
||||
await Promise.all([
|
||||
db.prepare("run", titleVotesQuery, ["UUID12", 3, 0, 0]),
|
||||
db.prepare("run", titleVotesQuery, ["UUID22", 2, 0, 0]),
|
||||
db.prepare("run", titleVotesQuery, ["UUID32", 1, 0, 1]),
|
||||
db.prepare("run", thumbnailTimestampsQuery, ["UUID12T", 1]),
|
||||
db.prepare("run", thumbnailTimestampsQuery, ["UUID32T", 3]),
|
||||
db.prepare("run", thumbnailVotesQuery, ["UUID12T", 3, 0, 0]),
|
||||
db.prepare("run", thumbnailVotesQuery, ["UUID22T", 2, 0, 0]),
|
||||
db.prepare("run", thumbnailVotesQuery, ["UUID32T", 1, 0, 1])
|
||||
]);
|
||||
});
|
||||
|
||||
it("should get top titles and thumbnails", async () => {
|
||||
await checkVideo(videoID1, videoID1Hash, {
|
||||
titles: [{
|
||||
title: "title1",
|
||||
original: false,
|
||||
votes: 3,
|
||||
locked: false,
|
||||
UUID: "UUID1" as BrandingUUID
|
||||
}, {
|
||||
title: "title2",
|
||||
original: false,
|
||||
votes: 2,
|
||||
locked: false,
|
||||
UUID: "UUID2" as BrandingUUID
|
||||
}, {
|
||||
title: "title3",
|
||||
original: true,
|
||||
votes: 1,
|
||||
locked: false,
|
||||
UUID: "UUID3" as BrandingUUID
|
||||
}],
|
||||
thumbnails: [{
|
||||
timestamp: 1,
|
||||
original: false,
|
||||
votes: 3,
|
||||
locked: false,
|
||||
UUID: "UUID1T" as BrandingUUID
|
||||
}, {
|
||||
original: true,
|
||||
votes: 2,
|
||||
locked: false,
|
||||
UUID: "UUID2T" as BrandingUUID
|
||||
}, {
|
||||
timestamp: 3,
|
||||
original: false,
|
||||
votes: 1,
|
||||
locked: false,
|
||||
UUID: "UUID3T" as BrandingUUID
|
||||
}]
|
||||
});
|
||||
});
|
||||
|
||||
it("should get top titles and thumbnails prioritizing locks", async () => {
|
||||
await checkVideo(videoID2Locked, videoID2LockedHash, {
|
||||
titles: [{
|
||||
title: "title3",
|
||||
original: true,
|
||||
votes: 1,
|
||||
locked: true,
|
||||
UUID: "UUID31" as BrandingUUID
|
||||
}, {
|
||||
title: "title1",
|
||||
original: false,
|
||||
votes: 3,
|
||||
locked: false,
|
||||
UUID: "UUID11" as BrandingUUID
|
||||
}, {
|
||||
title: "title2",
|
||||
original: false,
|
||||
votes: 2,
|
||||
locked: false,
|
||||
UUID: "UUID21" as BrandingUUID
|
||||
}],
|
||||
thumbnails: [{
|
||||
timestamp: 3,
|
||||
original: false,
|
||||
votes: 1,
|
||||
locked: true,
|
||||
UUID: "UUID31T" as BrandingUUID
|
||||
}, {
|
||||
timestamp: 1,
|
||||
original: false,
|
||||
votes: 3,
|
||||
locked: false,
|
||||
UUID: "UUID11T" as BrandingUUID
|
||||
}, {
|
||||
original: true,
|
||||
votes: 2,
|
||||
locked: false,
|
||||
UUID: "UUID21T" as BrandingUUID
|
||||
}]
|
||||
});
|
||||
});
|
||||
|
||||
it("should get top titles and hide shadow hidden", async () => {
|
||||
await checkVideo(videoID2ShadowHide, videoID2ShadowHideHash, {
|
||||
titles: [{
|
||||
title: "title1",
|
||||
original: false,
|
||||
votes: 3,
|
||||
locked: false,
|
||||
UUID: "UUID12" as BrandingUUID
|
||||
}, {
|
||||
title: "title2",
|
||||
original: false,
|
||||
votes: 2,
|
||||
locked: false,
|
||||
UUID: "UUID22" as BrandingUUID
|
||||
}],
|
||||
thumbnails: [{
|
||||
timestamp: 1,
|
||||
original: false,
|
||||
votes: 3,
|
||||
locked: false,
|
||||
UUID: "UUID12T" as BrandingUUID
|
||||
}, {
|
||||
original: true,
|
||||
votes: 2,
|
||||
locked: false,
|
||||
UUID: "UUID22T" as BrandingUUID
|
||||
}]
|
||||
});
|
||||
});
|
||||
|
||||
it("should get 404 when nothing", async () => {
|
||||
const result1 = await getBranding({ videoID: videoIDEmpty });
|
||||
const result2 = await getBrandingByHash(videoIDEmptyHash, {});
|
||||
|
||||
assert.strictEqual(result1.status, 404);
|
||||
assert.strictEqual(result2.status, 404);
|
||||
});
|
||||
|
||||
async function checkVideo(videoID: string, videoIDHash: string, expected: BrandingResult) {
|
||||
const result1 = await getBranding({ videoID });
|
||||
const result2 = await getBrandingByHash(videoIDHash, {});
|
||||
|
||||
assert.strictEqual(result1.status, 200);
|
||||
assert.strictEqual(result2.status, 200);
|
||||
assert.deepEqual(result1.data, result2.data[videoID]);
|
||||
assert.ok(partialDeepEquals(result1.data, expected));
|
||||
}
|
||||
});
|
||||
409
test/cases/postBranding.ts
Normal file
409
test/cases/postBranding.ts
Normal file
@@ -0,0 +1,409 @@
|
||||
import { db } from "../../src/databases/databases";
|
||||
import { getHash } from "../../src/utils/getHash";
|
||||
import { client } from "../utils/httpClient";
|
||||
import assert from "assert";
|
||||
import { Service } from "../../src/types/segments.model";
|
||||
|
||||
describe("postBranding", () => {
|
||||
|
||||
const vipUser = `VIPPostBrandingUser${".".repeat(16)}`;
|
||||
const vipUser2 = `VIPPostBrandingUser2${".".repeat(16)}`;
|
||||
const userID1 = `PostBrandingUser1${".".repeat(16)}`;
|
||||
const userID2 = `PostBrandingUser2${".".repeat(16)}`;
|
||||
const userID3 = `PostBrandingUser3${".".repeat(16)}`;
|
||||
const userID4 = `PostBrandingUser4${".".repeat(16)}`;
|
||||
const userID5 = `PostBrandingUser4${".".repeat(16)}`;
|
||||
|
||||
const endpoint = "/api/branding";
|
||||
const postBranding = (data: Record<string, any>) => client({
|
||||
method: "POST",
|
||||
url: endpoint,
|
||||
data
|
||||
});
|
||||
|
||||
const queryTitleByVideo = (videoID: string, all = false) => db.prepare(all ? "all" : "get", `SELECT * FROM "titles" WHERE "videoID" = ? ORDER BY "timeSubmitted" DESC`, [videoID]);
|
||||
const queryThumbnailByVideo = (videoID: string, all = false) => db.prepare(all ? "all" : "get", `SELECT * FROM "thumbnails" WHERE "videoID" = ? ORDER BY "timeSubmitted" DESC`, [videoID]);
|
||||
const queryThumbnailTimestampsByUUID = (UUID: string, all = false) => db.prepare(all ? "all" : "get", `SELECT * FROM "thumbnailTimestamps" WHERE "UUID" = ?`, [UUID]);
|
||||
const queryTitleVotesByUUID = (UUID: string, all = false) => db.prepare(all ? "all" : "get", `SELECT * FROM "titleVotes" WHERE "UUID" = ?`, [UUID]);
|
||||
const queryThumbnailVotesByUUID = (UUID: string, all = false) => db.prepare(all ? "all" : "get", `SELECT * FROM "thumbnailVotes" WHERE "UUID" = ?`, [UUID]);
|
||||
|
||||
before(() => {
|
||||
const insertVipUserQuery = 'INSERT INTO "vipUsers" ("userID") VALUES (?)';
|
||||
db.prepare("run", insertVipUserQuery, [getHash(vipUser)]);
|
||||
db.prepare("run", insertVipUserQuery, [getHash(vipUser2)]);
|
||||
});
|
||||
|
||||
it("Submit only title", async () => {
|
||||
const videoID = "postBrand1";
|
||||
const title = {
|
||||
title: "Some title",
|
||||
original: false
|
||||
};
|
||||
|
||||
const res = await postBranding({
|
||||
title,
|
||||
userID: userID1,
|
||||
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, 0);
|
||||
assert.strictEqual(dbVotes.locked, 0);
|
||||
assert.strictEqual(dbVotes.shadowHidden, 0);
|
||||
});
|
||||
|
||||
it("Submit only original title", async () => {
|
||||
const videoID = "postBrand2";
|
||||
const title = {
|
||||
title: "Some title",
|
||||
original: true
|
||||
};
|
||||
|
||||
const res = await postBranding({
|
||||
title,
|
||||
userID: userID2,
|
||||
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, 0);
|
||||
assert.strictEqual(dbVotes.locked, 0);
|
||||
assert.strictEqual(dbVotes.shadowHidden, 0);
|
||||
});
|
||||
|
||||
it("Submit only original thumbnail", async () => {
|
||||
const videoID = "postBrand3";
|
||||
const thumbnail = {
|
||||
original: true
|
||||
};
|
||||
|
||||
const res = await postBranding({
|
||||
thumbnail,
|
||||
userID: userID3,
|
||||
service: Service.YouTube,
|
||||
videoID
|
||||
});
|
||||
|
||||
assert.strictEqual(res.status, 200);
|
||||
const dbThumbnail = await queryThumbnailByVideo(videoID);
|
||||
const dbVotes = await queryThumbnailVotesByUUID(dbThumbnail.UUID);
|
||||
|
||||
assert.strictEqual(dbThumbnail.original, thumbnail.original ? 1 : 0);
|
||||
|
||||
assert.strictEqual(dbVotes.votes, 0);
|
||||
assert.strictEqual(dbVotes.locked, 0);
|
||||
assert.strictEqual(dbVotes.shadowHidden, 0);
|
||||
});
|
||||
|
||||
it("Submit only custom thumbnail", async () => {
|
||||
const videoID = "postBrand4";
|
||||
const thumbnail = {
|
||||
timestamp: 12.42,
|
||||
original: false
|
||||
};
|
||||
|
||||
const res = await postBranding({
|
||||
thumbnail,
|
||||
userID: userID4,
|
||||
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, 0);
|
||||
assert.strictEqual(dbVotes.locked, 0);
|
||||
assert.strictEqual(dbVotes.shadowHidden, 0);
|
||||
});
|
||||
|
||||
it("Submit title and thumbnail", async () => {
|
||||
const videoID = "postBrand5";
|
||||
const title = {
|
||||
title: "Some title",
|
||||
original: false
|
||||
};
|
||||
const thumbnail = {
|
||||
timestamp: 12.42,
|
||||
original: false
|
||||
};
|
||||
|
||||
const res = await postBranding({
|
||||
title,
|
||||
thumbnail,
|
||||
userID: userID5,
|
||||
service: Service.YouTube,
|
||||
videoID
|
||||
});
|
||||
|
||||
assert.strictEqual(res.status, 200);
|
||||
const dbTitle = await queryTitleByVideo(videoID);
|
||||
const dbTitleVotes = await queryTitleVotesByUUID(dbTitle.UUID);
|
||||
const dbThumbnail = await queryThumbnailByVideo(videoID);
|
||||
const dbThumbnailTimestamps = await queryThumbnailTimestampsByUUID(dbThumbnail.UUID);
|
||||
const dbThumbnailVotes = await queryThumbnailVotesByUUID(dbThumbnail.UUID);
|
||||
|
||||
assert.strictEqual(dbTitle.title, title.title);
|
||||
assert.strictEqual(dbTitle.original, title.original ? 1 : 0);
|
||||
|
||||
assert.strictEqual(dbTitleVotes.votes, 0);
|
||||
assert.strictEqual(dbTitleVotes.locked, 0);
|
||||
assert.strictEqual(dbTitleVotes.shadowHidden, 0);
|
||||
|
||||
assert.strictEqual(dbThumbnailTimestamps.timestamp, thumbnail.timestamp);
|
||||
assert.strictEqual(dbThumbnail.original, thumbnail.original ? 1 : 0);
|
||||
|
||||
assert.strictEqual(dbThumbnailVotes.votes, 0);
|
||||
assert.strictEqual(dbThumbnailVotes.locked, 0);
|
||||
assert.strictEqual(dbThumbnailVotes.shadowHidden, 0);
|
||||
});
|
||||
|
||||
it("Submit title and thumbnail as VIP", async () => {
|
||||
const videoID = "postBrand6";
|
||||
const title = {
|
||||
title: "Some title",
|
||||
original: false
|
||||
};
|
||||
const thumbnail = {
|
||||
timestamp: 12.42,
|
||||
original: false
|
||||
};
|
||||
|
||||
const res = await postBranding({
|
||||
title,
|
||||
thumbnail,
|
||||
userID: vipUser,
|
||||
service: Service.YouTube,
|
||||
videoID
|
||||
});
|
||||
|
||||
assert.strictEqual(res.status, 200);
|
||||
const dbTitle = await queryTitleByVideo(videoID);
|
||||
const dbTitleVotes = await queryTitleVotesByUUID(dbTitle.UUID);
|
||||
const dbThumbnail = await queryThumbnailByVideo(videoID);
|
||||
const dbThumbnailTimestamps = await queryThumbnailTimestampsByUUID(dbThumbnail.UUID);
|
||||
const dbThumbnailVotes = await queryThumbnailVotesByUUID(dbThumbnail.UUID);
|
||||
|
||||
assert.strictEqual(dbTitle.title, title.title);
|
||||
assert.strictEqual(dbTitle.original, title.original ? 1 : 0);
|
||||
|
||||
assert.strictEqual(dbTitleVotes.votes, 0);
|
||||
assert.strictEqual(dbTitleVotes.locked, 1);
|
||||
assert.strictEqual(dbTitleVotes.shadowHidden, 0);
|
||||
|
||||
assert.strictEqual(dbThumbnailTimestamps.timestamp, thumbnail.timestamp);
|
||||
assert.strictEqual(dbThumbnail.original, thumbnail.original ? 1 : 0);
|
||||
|
||||
assert.strictEqual(dbThumbnailVotes.votes, 0);
|
||||
assert.strictEqual(dbThumbnailVotes.locked, 1);
|
||||
assert.strictEqual(dbThumbnailVotes.shadowHidden, 0);
|
||||
});
|
||||
|
||||
it("Submit another title and thumbnail as VIP unlocks others", async () => {
|
||||
const videoID = "postBrand6";
|
||||
const title = {
|
||||
title: "Some other title",
|
||||
original: false
|
||||
};
|
||||
const thumbnail = {
|
||||
timestamp: 15.42,
|
||||
original: false
|
||||
};
|
||||
|
||||
const res = await postBranding({
|
||||
title,
|
||||
thumbnail,
|
||||
userID: vipUser2,
|
||||
service: Service.YouTube,
|
||||
videoID
|
||||
});
|
||||
|
||||
assert.strictEqual(res.status, 200);
|
||||
const dbTitles = await queryTitleByVideo(videoID, true);
|
||||
const dbTitleVotes = await queryTitleVotesByUUID(dbTitles[0].UUID);
|
||||
const dbTitleVotesOld = await queryTitleVotesByUUID(dbTitles[1].UUID);
|
||||
const dbThumbnails = await queryThumbnailByVideo(videoID, true);
|
||||
const dbThumbnailTimestamps = await queryThumbnailTimestampsByUUID(dbThumbnails[0].UUID);
|
||||
const dbThumbnailVotes = await queryThumbnailVotesByUUID(dbThumbnails[0].UUID);
|
||||
const dbThumbnailVotesOld = await queryThumbnailVotesByUUID(dbThumbnails[1].UUID);
|
||||
|
||||
assert.strictEqual(dbTitles[0].title, title.title);
|
||||
assert.strictEqual(dbTitles[0].original, title.original ? 1 : 0);
|
||||
|
||||
assert.strictEqual(dbTitleVotes.votes, 0);
|
||||
assert.strictEqual(dbTitleVotes.locked, 1);
|
||||
assert.strictEqual(dbTitleVotes.shadowHidden, 0);
|
||||
assert.strictEqual(dbTitleVotesOld.locked, 0);
|
||||
|
||||
assert.strictEqual(dbThumbnailTimestamps.timestamp, thumbnail.timestamp);
|
||||
assert.strictEqual(dbThumbnails[0].original, thumbnail.original ? 1 : 0);
|
||||
|
||||
assert.strictEqual(dbThumbnailVotes.votes, 0);
|
||||
assert.strictEqual(dbThumbnailVotes.locked, 1);
|
||||
assert.strictEqual(dbThumbnailVotes.shadowHidden, 0);
|
||||
assert.strictEqual(dbThumbnailVotesOld.locked, 0);
|
||||
});
|
||||
|
||||
it("Vote the same title again", async () => {
|
||||
const videoID = "postBrand1";
|
||||
const title = {
|
||||
title: "Some title",
|
||||
original: false
|
||||
};
|
||||
|
||||
const res = await postBranding({
|
||||
title,
|
||||
userID: userID1,
|
||||
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, 0);
|
||||
assert.strictEqual(dbVotes.locked, 0);
|
||||
assert.strictEqual(dbVotes.shadowHidden, 0);
|
||||
});
|
||||
|
||||
it("Vote for a different title", async () => {
|
||||
const videoID = "postBrand1";
|
||||
const title = {
|
||||
title: "Some other title",
|
||||
original: false
|
||||
};
|
||||
|
||||
const oldDbTitle = await queryTitleByVideo(videoID);
|
||||
|
||||
const res = await postBranding({
|
||||
title,
|
||||
userID: userID1,
|
||||
service: Service.YouTube,
|
||||
videoID
|
||||
});
|
||||
|
||||
assert.strictEqual(res.status, 200);
|
||||
const dbTitle = await queryTitleByVideo(videoID);
|
||||
const dbVotes = await queryTitleVotesByUUID(dbTitle.UUID);
|
||||
const oldDBVotes = await queryTitleVotesByUUID(oldDbTitle.UUID);
|
||||
|
||||
assert.strictEqual(dbTitle.title, title.title);
|
||||
assert.strictEqual(dbTitle.original, title.original ? 1 : 0);
|
||||
|
||||
assert.strictEqual(dbVotes.votes, 0);
|
||||
assert.strictEqual(dbVotes.locked, 0);
|
||||
assert.strictEqual(dbVotes.shadowHidden, 0);
|
||||
|
||||
assert.strictEqual(oldDBVotes.votes, -1);
|
||||
assert.strictEqual(oldDBVotes.locked, 0);
|
||||
assert.strictEqual(oldDBVotes.shadowHidden, 0);
|
||||
});
|
||||
|
||||
it("Vote for the same thumbnail again", async () => {
|
||||
const videoID = "postBrand4";
|
||||
const thumbnail = {
|
||||
timestamp: 12.42,
|
||||
original: false
|
||||
};
|
||||
|
||||
const res = await postBranding({
|
||||
thumbnail,
|
||||
userID: userID4,
|
||||
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, 0);
|
||||
assert.strictEqual(dbVotes.locked, 0);
|
||||
assert.strictEqual(dbVotes.shadowHidden, 0);
|
||||
});
|
||||
|
||||
it("Vote for the same thumbnail again original", async () => {
|
||||
const videoID = "postBrand3";
|
||||
const thumbnail = {
|
||||
original: true
|
||||
};
|
||||
|
||||
const res = await postBranding({
|
||||
thumbnail,
|
||||
userID: userID3,
|
||||
service: Service.YouTube,
|
||||
videoID
|
||||
});
|
||||
|
||||
assert.strictEqual(res.status, 200);
|
||||
const dbThumbnail = await queryThumbnailByVideo(videoID);
|
||||
const dbVotes = await queryThumbnailVotesByUUID(dbThumbnail.UUID);
|
||||
|
||||
assert.strictEqual(dbThumbnail.original, thumbnail.original ? 1 : 0);
|
||||
|
||||
assert.strictEqual(dbVotes.votes, 0);
|
||||
assert.strictEqual(dbVotes.locked, 0);
|
||||
assert.strictEqual(dbVotes.shadowHidden, 0);
|
||||
});
|
||||
|
||||
it("Vote for a different thumbnail", async () => {
|
||||
const videoID = "postBrand4";
|
||||
const thumbnail = {
|
||||
timestamp: 15.34,
|
||||
original: false
|
||||
};
|
||||
|
||||
const oldDbThumbnail = await queryThumbnailByVideo(videoID);
|
||||
|
||||
const res = await postBranding({
|
||||
thumbnail,
|
||||
userID: userID4,
|
||||
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);
|
||||
const oldDBVotes = await queryThumbnailVotesByUUID(oldDbThumbnail.UUID);
|
||||
|
||||
assert.strictEqual(dbThumbnailTimestamps.timestamp, thumbnail.timestamp);
|
||||
assert.strictEqual(dbThumbnail.original, thumbnail.original ? 1 : 0);
|
||||
|
||||
assert.strictEqual(dbVotes.votes, 0);
|
||||
assert.strictEqual(dbVotes.locked, 0);
|
||||
assert.strictEqual(dbVotes.shadowHidden, 0);
|
||||
|
||||
assert.strictEqual(oldDBVotes.votes, -1);
|
||||
assert.strictEqual(oldDBVotes.locked, 0);
|
||||
assert.strictEqual(oldDBVotes.shadowHidden, 0);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user