mirror of
https://github.com/ajayyy/SponsorBlockServer.git
synced 2025-12-11 14:07:09 +03:00
everything after postClearCache
This commit is contained in:
@@ -21,31 +21,31 @@ describe("voteOnSponsorTime", () => {
|
||||
const MILLISECONDS_IN_HOUR = 3600000;
|
||||
const warningExpireTime = MILLISECONDS_IN_HOUR * config.hoursAfterWarningExpires;
|
||||
|
||||
const insertSponsorTimeQuery = 'INSERT INTO "sponsorTimes" ("videoID", "startTime", "endTime", "votes", "UUID", "userID", "timeSubmitted", "views", "category", "shadowHidden", "hidden", "hashedVideoID") VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)';
|
||||
await db.prepare("run", insertSponsorTimeQuery, ["vote-testtesttest", 1, 11, 2, "vote-uuid-0", "testman", 0, 50, "sponsor", 0, 0, getHash("vote-testtesttest", 1)]);
|
||||
await db.prepare("run", insertSponsorTimeQuery, ["vote-testtesttest2", 1, 11, 2, "vote-uuid-1", "testman", 0, 50, "sponsor", 0, 0, getHash("vote-testtesttest2", 1)]);
|
||||
await db.prepare("run", insertSponsorTimeQuery, ["vote-testtesttest2", 1, 11, 10, "vote-uuid-1.5", "testman", 0, 50, "outro", 0, 0, getHash("vote-testtesttest2", 1)]);
|
||||
await db.prepare("run", insertSponsorTimeQuery, ["vote-testtesttest2", 1, 11, 10, "vote-uuid-1.6", "testman", 0, 50, "interaction", 0, 0, getHash("vote-testtesttest2", 1)]);
|
||||
await db.prepare("run", insertSponsorTimeQuery, ["vote-testtesttest3", 20, 33, 10, "vote-uuid-2", "testman", 0, 50, "intro", 0, 0, getHash("vote-testtesttest3", 1)]);
|
||||
await db.prepare("run", insertSponsorTimeQuery, ["vote-testtesttest,test", 1, 11, 100, "vote-uuid-3", "testman", 0, 50, "sponsor", 0, 0, getHash("vote-testtesttest,test", 1)]);
|
||||
await db.prepare("run", insertSponsorTimeQuery, ["vote-test3", 1, 11, 2, "vote-uuid-4", "testman", 0, 50, "sponsor", 0, 0, getHash("vote-test3", 1)]);
|
||||
await db.prepare("run", insertSponsorTimeQuery, ["vote-test3", 7, 22, -3, "vote-uuid-5", "testman", 0, 50, "intro", 0, 0, getHash("vote-test3", 1)]);
|
||||
await db.prepare("run", insertSponsorTimeQuery, ["vote-test3", 7, 22, -3, "vote-uuid-5_1", "testman", 0, 50, "intro", 0, 0, getHash("vote-test3", 1)]);
|
||||
await db.prepare("run", insertSponsorTimeQuery, ["vote-multiple", 1, 11, 2, "vote-uuid-6", "testman", 0, 50, "intro", 0, 0, getHash("vote-multiple", 1)]);
|
||||
await db.prepare("run", insertSponsorTimeQuery, ["vote-multiple", 20, 33, 2, "vote-uuid-7", "testman", 0, 50, "intro", 0, 0, getHash("vote-multiple", 1)]);
|
||||
await db.prepare("run", insertSponsorTimeQuery, ["voter-submitter", 1, 11, 2, "vote-uuid-8", getHash("randomID"), 0, 50, "sponsor", 0, 0, getHash("voter-submitter", 1)]);
|
||||
await db.prepare("run", insertSponsorTimeQuery, ["voter-submitter2", 1, 11, 2, "vote-uuid-9", getHash("randomID2"), 0, 50, "sponsor", 0, 0, getHash("voter-submitter2", 1)]);
|
||||
await db.prepare("run", insertSponsorTimeQuery, ["voter-submitter2", 1, 11, 2, "vote-uuid-10", getHash("randomID3"), 0, 50, "sponsor", 0, 0, getHash("voter-submitter2", 1)]);
|
||||
await db.prepare("run", insertSponsorTimeQuery, ["voter-submitter2", 1, 11, 2, "vote-uuid-11", getHash("randomID4"), 0, 50, "sponsor", 0, 0, getHash("voter-submitter2", 1)]);
|
||||
await db.prepare("run", insertSponsorTimeQuery, ["own-submission-video", 1, 11, 500, "own-submission-uuid", getHash("own-submission-id"), 0, 50, "sponsor", 0, 0, getHash("own-submission-video", 1)]);
|
||||
await db.prepare("run", insertSponsorTimeQuery, ["not-own-submission-video", 1, 11, 500, "not-own-submission-uuid", getHash("somebody-else-id"), 0, 50, "sponsor", 0, 0, getHash("not-own-submission-video", 1)]);
|
||||
await db.prepare("run", insertSponsorTimeQuery, ["incorrect-category", 1, 11, 500, "incorrect-category", getHash("somebody-else-id"), 0, 50, "sponsor", 0, 0, getHash("incorrect-category", 1)]);
|
||||
await db.prepare("run", insertSponsorTimeQuery, ["incorrect-category-change", 1, 11, 500, "incorrect-category-change", getHash("somebody-else-id"), 0, 50, "sponsor", 0, 0, getHash("incorrect-category-change", 1)]);
|
||||
await db.prepare("run", insertSponsorTimeQuery, ["vote-testtesttest", 1, 11, 2, "warnvote-uuid-0", "testman", 0, 50, "sponsor", 0, 0, getHash("vote-testtesttest", 1)]);
|
||||
await db.prepare("run", insertSponsorTimeQuery, ["no-sponsor-segments-video", 1, 11, 2, "no-sponsor-segments-uuid-0", "no-sponsor-segments", 0, 50, "sponsor", 0, 0, getHash("no-sponsor-segments-video", 1)]);
|
||||
await db.prepare("run", insertSponsorTimeQuery, ["no-sponsor-segments-video", 1, 11, 2, "no-sponsor-segments-uuid-1", "no-sponsor-segments", 0, 50, "intro", 0, 0, getHash("no-sponsor-segments-video", 1)]);
|
||||
await db.prepare("run", insertSponsorTimeQuery, ["segment-locking-video", 1, 11, 2, "segment-locking-uuid-1", "segment-locking-user", 0, 50, "intro", 0, 0, getHash("segment-locking-video", 1)]);
|
||||
await db.prepare("run", insertSponsorTimeQuery, ["segment-hidden-video", 1, 11, 2, "segment-hidden-uuid-1", "segment-hidden-user", 0, 50, "intro", 0, 1, getHash("segment-locking-video", 1)]);
|
||||
const insertSponsorTimeQuery = 'INSERT INTO "sponsorTimes" ("videoID", "startTime", "endTime", "votes", "UUID", "userID", "timeSubmitted", "views", "category", "shadowHidden", "hidden") VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)';
|
||||
await db.prepare("run", insertSponsorTimeQuery, ["vote-testtesttest", 1, 11, 2, "vote-uuid-0", "testman", 0, 50, "sponsor", 0, 0]);
|
||||
await db.prepare("run", insertSponsorTimeQuery, ["vote-testtesttest2", 1, 11, 2, "vote-uuid-1", "testman", 0, 50, "sponsor", 0, 0]);
|
||||
await db.prepare("run", insertSponsorTimeQuery, ["vote-testtesttest2", 1, 11, 10, "vote-uuid-1.5", "testman", 0, 50, "outro", 0, 0]);
|
||||
await db.prepare("run", insertSponsorTimeQuery, ["vote-testtesttest2", 1, 11, 10, "vote-uuid-1.6", "testman", 0, 50, "interaction", 0, 0]);
|
||||
await db.prepare("run", insertSponsorTimeQuery, ["vote-testtesttest3", 20, 33, 10, "vote-uuid-2", "testman", 0, 50, "intro", 0, 0]);
|
||||
await db.prepare("run", insertSponsorTimeQuery, ["vote-testtesttest,test", 1, 11, 100, "vote-uuid-3", "testman", 0, 50, "sponsor", 0, 0]);
|
||||
await db.prepare("run", insertSponsorTimeQuery, ["vote-test3", 1, 11, 2, "vote-uuid-4", "testman", 0, 50, "sponsor", 0, 0]);
|
||||
await db.prepare("run", insertSponsorTimeQuery, ["vote-test3", 7, 22, -3, "vote-uuid-5", "testman", 0, 50, "intro", 0, 0]);
|
||||
await db.prepare("run", insertSponsorTimeQuery, ["vote-test3", 7, 22, -3, "vote-uuid-5_1", "testman", 0, 50, "intro", 0, 0]);
|
||||
await db.prepare("run", insertSponsorTimeQuery, ["vote-multiple", 1, 11, 2, "vote-uuid-6", "testman", 0, 50, "intro", 0, 0]);
|
||||
await db.prepare("run", insertSponsorTimeQuery, ["vote-multiple", 20, 33, 2, "vote-uuid-7", "testman", 0, 50, "intro", 0, 0]);
|
||||
await db.prepare("run", insertSponsorTimeQuery, ["voter-submitter", 1, 11, 2, "vote-uuid-8", getHash("randomID"), 0, 50, "sponsor", 0, 0]);
|
||||
await db.prepare("run", insertSponsorTimeQuery, ["voter-submitter2", 1, 11, 2, "vote-uuid-9", getHash("randomID2"), 0, 50, "sponsor", 0, 0]);
|
||||
await db.prepare("run", insertSponsorTimeQuery, ["voter-submitter2", 1, 11, 2, "vote-uuid-10", getHash("randomID3"), 0, 50, "sponsor", 0, 0]);
|
||||
await db.prepare("run", insertSponsorTimeQuery, ["voter-submitter2", 1, 11, 2, "vote-uuid-11", getHash("randomID4"), 0, 50, "sponsor", 0, 0]);
|
||||
await db.prepare("run", insertSponsorTimeQuery, ["own-submission-video", 1, 11, 500, "own-submission-uuid", getHash("own-submission-id"), 0, 50, "sponsor", 0, 0]);
|
||||
await db.prepare("run", insertSponsorTimeQuery, ["not-own-submission-video", 1, 11, 500, "not-own-submission-uuid", getHash("somebody-else-id"), 0, 50, "sponsor", 0, 0]);
|
||||
await db.prepare("run", insertSponsorTimeQuery, ["incorrect-category", 1, 11, 500, "incorrect-category", getHash("somebody-else-id"), 0, 50, "sponsor", 0, 0]);
|
||||
await db.prepare("run", insertSponsorTimeQuery, ["incorrect-category-change", 1, 11, 500, "incorrect-category-change", getHash("somebody-else-id"), 0, 50, "sponsor", 0, 0]);
|
||||
await db.prepare("run", insertSponsorTimeQuery, ["vote-testtesttest", 1, 11, 2, "warnvote-uuid-0", "testman", 0, 50, "sponsor", 0, 0]);
|
||||
await db.prepare("run", insertSponsorTimeQuery, ["no-sponsor-segments-video", 1, 11, 2, "no-sponsor-segments-uuid-0", "no-sponsor-segments", 0, 50, "sponsor", 0, 0]);
|
||||
await db.prepare("run", insertSponsorTimeQuery, ["no-sponsor-segments-video", 1, 11, 2, "no-sponsor-segments-uuid-1", "no-sponsor-segments", 0, 50, "intro", 0, 0]);
|
||||
await db.prepare("run", insertSponsorTimeQuery, ["segment-locking-video", 1, 11, 2, "segment-locking-uuid-1", "segment-locking-user", 0, 50, "intro", 0, 0]);
|
||||
await db.prepare("run", insertSponsorTimeQuery, ["segment-hidden-video", 1, 11, 2, "segment-hidden-uuid-1", "segment-hidden-user", 0, 50, "intro", 0, 1]);
|
||||
|
||||
const insertWarningQuery = 'INSERT INTO "warnings" ("userID", "issueTime", "issuerUserID", "enabled") VALUES(?, ?, ?, ?)';
|
||||
await db.prepare("run", insertWarningQuery, [warnUser01Hash, now, warnVip01Hash, 1]);
|
||||
@@ -63,13 +63,17 @@ describe("voteOnSponsorTime", () => {
|
||||
|
||||
await db.prepare("run", 'INSERT INTO "lockCategories" ("videoID", "userID", "category") VALUES (?, ?, ?)', ["no-sponsor-segments-video", "someUser", "sponsor"]);
|
||||
});
|
||||
// constants
|
||||
const endpoint = `${getbaseURL()}/api/voteOnSponsorTime`;
|
||||
const getSegmentVotes = (UUID: string) => db.prepare("get", `SELECT "votes" FROM "sponsorTimes" WHERE "UUID" = ?`, [UUID]);
|
||||
const getSegmentCategory = (UUID: string) => db.prepare("get", `SELECT "category" FROM "sponsorTimes" WHERE "UUID" = ?`, [UUID]);
|
||||
|
||||
it("Should be able to upvote a segment", (done: Done) => {
|
||||
fetch(`${getbaseURL()
|
||||
}/api/voteOnSponsorTime?userID=randomID&UUID=vote-uuid-0&type=1`)
|
||||
const UUID = "vote-uuid-0";
|
||||
fetch(`${endpoint}?userID=randomID&UUID=${UUID}&type=1`)
|
||||
.then(async res => {
|
||||
assert.strictEqual(res.status, 200);
|
||||
const row = await db.prepare("get", `SELECT "votes" FROM "sponsorTimes" WHERE "UUID" = ?`, ["vote-uuid-0"]);
|
||||
const row = await getSegmentVotes(UUID);
|
||||
assert.strictEqual(row.votes, 3);
|
||||
done();
|
||||
})
|
||||
@@ -77,11 +81,11 @@ describe("voteOnSponsorTime", () => {
|
||||
});
|
||||
|
||||
it("Should be able to downvote a segment", (done: Done) => {
|
||||
fetch(`${getbaseURL()
|
||||
}/api/voteOnSponsorTime?userID=randomID2&UUID=vote-uuid-2&type=0`)
|
||||
const UUID = "vote-uuid-2";
|
||||
fetch(`${endpoint}?userID=randomID2&UUID=${UUID}&type=0`)
|
||||
.then(async res => {
|
||||
assert.strictEqual(res.status, 200);
|
||||
const row = await db.prepare("get", `SELECT "votes" FROM "sponsorTimes" WHERE "UUID" = ?`, ["vote-uuid-2"]);
|
||||
const row = await getSegmentVotes(UUID);
|
||||
assert.ok(row.votes < 10);
|
||||
done();
|
||||
})
|
||||
@@ -89,11 +93,11 @@ describe("voteOnSponsorTime", () => {
|
||||
});
|
||||
|
||||
it("Should not be able to downvote the same segment when voting from a different user on the same IP", (done: Done) => {
|
||||
fetch(`${getbaseURL()
|
||||
}/api/voteOnSponsorTime?userID=randomID3&UUID=vote-uuid-2&type=0`)
|
||||
const UUID = "vote-uuid-2";
|
||||
fetch(`${endpoint}?userID=randomID3&UUID=${UUID}&type=0`)
|
||||
.then(async res => {
|
||||
assert.strictEqual(res.status, 200);
|
||||
const row = await db.prepare("get", `SELECT "votes" FROM "sponsorTimes" WHERE "UUID" = ?`, ["vote-uuid-2"]);
|
||||
const row = await getSegmentVotes(UUID);
|
||||
assert.strictEqual(row.votes, 9);
|
||||
done();
|
||||
})
|
||||
@@ -101,11 +105,10 @@ describe("voteOnSponsorTime", () => {
|
||||
});
|
||||
|
||||
it("Should not be able to downvote a segment if the user is shadow banned", (done: Done) => {
|
||||
fetch(`${getbaseURL()
|
||||
}/api/voteOnSponsorTime?userID=randomID4&UUID=vote-uuid-1.6&type=0`)
|
||||
fetch(`${endpoint}?userID=randomID4&UUID=vote-uuid-1.6&type=0`)
|
||||
.then(async res => {
|
||||
assert.strictEqual(res.status, 200);
|
||||
const row = await db.prepare("get", `SELECT "votes" FROM "sponsorTimes" WHERE "UUID" = ?`, ["vote-uuid-1.6"]);
|
||||
const row = await getSegmentVotes("vote-uuid-1.6");
|
||||
assert.strictEqual(row.votes, 10);
|
||||
done();
|
||||
})
|
||||
@@ -113,11 +116,10 @@ describe("voteOnSponsorTime", () => {
|
||||
});
|
||||
|
||||
it("Should not be able to upvote a segment if the user hasn't submitted yet", (done: Done) => {
|
||||
fetch(`${getbaseURL()
|
||||
}/api/voteOnSponsorTime?userID=hasNotSubmittedID&UUID=vote-uuid-1&type=1`)
|
||||
fetch(`${endpoint}?userID=hasNotSubmittedID&UUID=vote-uuid-1&type=1`)
|
||||
.then(async res => {
|
||||
assert.strictEqual(res.status, 200);
|
||||
const row = await db.prepare("get", `SELECT "votes" FROM "sponsorTimes" WHERE "UUID" = ?`, ["vote-uuid-1"]);
|
||||
const row = await getSegmentVotes("vote-uuid-1");
|
||||
assert.strictEqual(row.votes, 2);
|
||||
done();
|
||||
})
|
||||
@@ -125,11 +127,10 @@ describe("voteOnSponsorTime", () => {
|
||||
});
|
||||
|
||||
it("Should not be able to downvote a segment if the user hasn't submitted yet", (done: Done) => {
|
||||
fetch(`${getbaseURL()
|
||||
}/api/voteOnSponsorTime?userID=hasNotSubmittedID&UUID=vote-uuid-1.5&type=0`)
|
||||
fetch(`${endpoint}?userID=hasNotSubmittedID&UUID=vote-uuid-1.5&type=0`)
|
||||
.then(async res => {
|
||||
assert.strictEqual(res.status, 200);
|
||||
const row = await db.prepare("get", `SELECT "votes" FROM "sponsorTimes" WHERE "UUID" = ?`, ["vote-uuid-1.5"]);
|
||||
const row = await getSegmentVotes("vote-uuid-1.5");
|
||||
assert.strictEqual(row.votes, 10);
|
||||
done();
|
||||
})
|
||||
@@ -137,11 +138,10 @@ describe("voteOnSponsorTime", () => {
|
||||
});
|
||||
|
||||
it("VIP should be able to completely downvote a segment", (done: Done) => {
|
||||
fetch(`${getbaseURL()
|
||||
}/api/voteOnSponsorTime?userID=VIPUser&UUID=vote-uuid-3&type=0`)
|
||||
fetch(`${endpoint}?userID=VIPUser&UUID=vote-uuid-3&type=0`)
|
||||
.then(async res => {
|
||||
assert.strictEqual(res.status, 200);
|
||||
const row = await db.prepare("get", `SELECT "votes" FROM "sponsorTimes" WHERE "UUID" = ?`, ["vote-uuid-3"]);
|
||||
const row = await getSegmentVotes("vote-uuid-3");
|
||||
assert.ok(row.votes <= -2);
|
||||
done();
|
||||
})
|
||||
@@ -149,11 +149,10 @@ describe("voteOnSponsorTime", () => {
|
||||
});
|
||||
|
||||
it("should be able to completely downvote your own segment", (done: Done) => {
|
||||
fetch(`${getbaseURL()
|
||||
}/api/voteOnSponsorTime?userID=own-submission-id&UUID=own-submission-uuid&type=0`)
|
||||
fetch(`${endpoint}?userID=own-submission-id&UUID=own-submission-uuid&type=0`)
|
||||
.then(async res => {
|
||||
assert.strictEqual(res.status, 200);
|
||||
const row = await db.prepare("get", `SELECT "votes" FROM "sponsorTimes" WHERE "UUID" = ?`, ["own-submission-uuid"]);
|
||||
const row = await getSegmentVotes("own-submission-uuid");
|
||||
assert.ok(row.votes <= -2);
|
||||
done();
|
||||
})
|
||||
@@ -161,11 +160,10 @@ describe("voteOnSponsorTime", () => {
|
||||
});
|
||||
|
||||
it("should not be able to completely downvote somebody elses segment", (done: Done) => {
|
||||
fetch(`${getbaseURL()
|
||||
}/api/voteOnSponsorTime?userID=randomID2&UUID=not-own-submission-uuid&type=0`)
|
||||
fetch(`${endpoint}?userID=randomID2&UUID=not-own-submission-uuid&type=0`)
|
||||
.then(async res => {
|
||||
assert.strictEqual(res.status, 200);
|
||||
const row = await db.prepare("get", `SELECT "votes" FROM "sponsorTimes" WHERE "UUID" = ?`, ["not-own-submission-uuid"]);
|
||||
const row = await getSegmentVotes("not-own-submission-uuid");
|
||||
assert.strictEqual(row.votes, 499);
|
||||
done();
|
||||
})
|
||||
@@ -173,12 +171,12 @@ describe("voteOnSponsorTime", () => {
|
||||
});
|
||||
|
||||
it("Should be able to vote for a category and it should add your vote to the database", (done: Done) => {
|
||||
fetch(`${getbaseURL()
|
||||
}/api/voteOnSponsorTime?userID=randomID2&UUID=vote-uuid-4&category=intro`)
|
||||
const UUID = "vote-uuid-4";
|
||||
fetch(`${endpoint}?userID=randomID2&UUID=${UUID}&category=intro`)
|
||||
.then(async res => {
|
||||
assert.strictEqual(res.status, 200);
|
||||
const row = await db.prepare("get", `SELECT "category" FROM "sponsorTimes" WHERE "UUID" = ?`, ["vote-uuid-4"]);
|
||||
const categoryRows = await db.prepare("all", `SELECT votes, category FROM "categoryVotes" WHERE "UUID" = ?`, ["vote-uuid-4"]);
|
||||
const row = await getSegmentCategory(UUID);
|
||||
const categoryRows = await db.prepare("all", `SELECT votes, category FROM "categoryVotes" WHERE "UUID" = ?`, [UUID]);
|
||||
assert.strictEqual(row.category, "sponsor");
|
||||
assert.strictEqual(categoryRows.length, 2);
|
||||
assert.strictEqual(categoryRows[0].votes, 1);
|
||||
@@ -191,11 +189,11 @@ describe("voteOnSponsorTime", () => {
|
||||
});
|
||||
|
||||
it("Should not able to change to an invalid category", (done: Done) => {
|
||||
fetch(`${getbaseURL()
|
||||
}/api/voteOnSponsorTime?userID=randomID2&UUID=incorrect-category&category=fakecategory`)
|
||||
const UUID = "incorrect-category";
|
||||
fetch(`${endpoint}?userID=randomID2&UUID=${UUID}&category=fakecategory`)
|
||||
.then(async res => {
|
||||
assert.strictEqual(res.status, 400);
|
||||
const row = await db.prepare("get", `SELECT "category" FROM "sponsorTimes" WHERE "UUID" = ?`, ["incorrect-category"]);
|
||||
const row = await getSegmentCategory(UUID);
|
||||
assert.strictEqual(row.category, "sponsor");
|
||||
done();
|
||||
})
|
||||
@@ -203,11 +201,11 @@ describe("voteOnSponsorTime", () => {
|
||||
});
|
||||
|
||||
it("Should not able to change to highlight category", (done: Done) => {
|
||||
fetch(`${getbaseURL()
|
||||
}/api/voteOnSponsorTime?userID=randomID2&UUID=incorrect-category&category=highlight`)
|
||||
const UUID = "incorrect-category";
|
||||
fetch(`${endpoint}?userID=randomID2&UUID=${UUID}&category=highlight`)
|
||||
.then(async res => {
|
||||
assert.strictEqual(res.status, 400);
|
||||
const row = await db.prepare("get", `SELECT "category" FROM "sponsorTimes" WHERE "UUID" = ?`, ["incorrect-category"]);
|
||||
const row = await getSegmentCategory(UUID);
|
||||
assert.strictEqual(row.category, "sponsor");
|
||||
done();
|
||||
})
|
||||
@@ -215,12 +213,12 @@ describe("voteOnSponsorTime", () => {
|
||||
});
|
||||
|
||||
it("Should be able to change your vote for a category and it should add your vote to the database", (done: Done) => {
|
||||
fetch(`${getbaseURL()
|
||||
}/api/voteOnSponsorTime?userID=randomID2&UUID=vote-uuid-4&category=outro`)
|
||||
const UUID = "vote-uuid-4";
|
||||
fetch(`${endpoint}?userID=randomID2&UUID=${UUID}&category=outro`)
|
||||
.then(async res => {
|
||||
if (res.status === 200) {
|
||||
const submissionRow = await db.prepare("get", `SELECT "category" FROM "sponsorTimes" WHERE "UUID" = ?`, ["vote-uuid-4"]);
|
||||
const categoryRows = await db.prepare("all", `SELECT votes, category FROM "categoryVotes" WHERE "UUID" = ?`, ["vote-uuid-4"]);
|
||||
const submissionRow = await getSegmentCategory(UUID);
|
||||
const categoryRows = await db.prepare("all", `SELECT votes, category FROM "categoryVotes" WHERE "UUID" = ?`, [UUID]);
|
||||
let introVotes = 0;
|
||||
let outroVotes = 0;
|
||||
let sponsorVotes = 0;
|
||||
@@ -244,11 +242,11 @@ describe("voteOnSponsorTime", () => {
|
||||
|
||||
|
||||
it("Should not be able to change your vote to an invalid category", (done: Done) => {
|
||||
const UUID = "incorrect-category-change";
|
||||
const vote = (inputCat: string, assertCat: string, callback: Done) => {
|
||||
fetch(`${getbaseURL()
|
||||
}/api/voteOnSponsorTime?userID=randomID2&UUID=incorrect-category-change&category=${inputCat}`)
|
||||
fetch(`${endpoint}?userID=randomID2&UUID=${UUID}&category=${inputCat}`)
|
||||
.then(async () => {
|
||||
const row = await db.prepare("get", `SELECT "category" FROM "sponsorTimes" WHERE "UUID" = ?`, ["incorrect-category-change"]);
|
||||
const row = await getSegmentCategory(UUID);
|
||||
assert.strictEqual(row.category, assertCat);
|
||||
callback();
|
||||
})
|
||||
@@ -261,12 +259,12 @@ describe("voteOnSponsorTime", () => {
|
||||
|
||||
|
||||
it("VIP should be able to vote for a category and it should immediately change", (done: Done) => {
|
||||
fetch(`${getbaseURL()
|
||||
}/api/voteOnSponsorTime?userID=VIPUser&UUID=vote-uuid-5&category=outro`)
|
||||
const UUID = "vote-uuid-5";
|
||||
fetch(`${endpoint}?userID=VIPUser&UUID=${UUID}&category=outro`)
|
||||
.then(async res => {
|
||||
assert.strictEqual(res.status, 200);
|
||||
const row = await db.prepare("get", `SELECT "category" FROM "sponsorTimes" WHERE "UUID" = ?`, ["vote-uuid-5"]);
|
||||
const row2 = await db.prepare("get", `SELECT votes FROM "categoryVotes" WHERE "UUID" = ? and category = ?`, ["vote-uuid-5", "outro"]);
|
||||
const row = await getSegmentCategory(UUID);
|
||||
const row2 = await db.prepare("get", `SELECT votes FROM "categoryVotes" WHERE "UUID" = ? and category = ?`, [UUID, "outro"]);
|
||||
assert.strictEqual(row.category, "outro");
|
||||
assert.strictEqual(row2.votes, 500);
|
||||
done();
|
||||
@@ -275,11 +273,11 @@ describe("voteOnSponsorTime", () => {
|
||||
});
|
||||
|
||||
it("Submitter should be able to vote for a category and it should immediately change", (done: Done) => {
|
||||
fetch(`${getbaseURL()
|
||||
}/api/voteOnSponsorTime?userID=testman&UUID=vote-uuid-5_1&category=outro`)
|
||||
const UUID = "vote-uuid-5_1";
|
||||
fetch(`${endpoint}?userID=testman&UUID=${UUID}&category=outro`)
|
||||
.then(async res => {
|
||||
assert.strictEqual(res.status, 200);
|
||||
const row = await db.prepare("get", `SELECT "category" FROM "sponsorTimes" WHERE "UUID" = ?`, ["vote-uuid-5"]);
|
||||
const row = await getSegmentCategory("vote-uuid-5");
|
||||
assert.strictEqual(row.category, "outro");
|
||||
done();
|
||||
})
|
||||
@@ -287,8 +285,8 @@ describe("voteOnSponsorTime", () => {
|
||||
});
|
||||
|
||||
it("Should not be able to category-vote on an invalid UUID submission", (done: Done) => {
|
||||
fetch(`${getbaseURL()
|
||||
}/api/voteOnSponsorTime?userID=randomID3&UUID=invalid-uuid&category=intro`)
|
||||
const UUID = "invalid-uuid";
|
||||
fetch(`${endpoint}?userID=randomID3&UUID=${UUID}&category=intro`)
|
||||
.then(async res => {
|
||||
assert.strictEqual(res.status, 400);
|
||||
done();
|
||||
@@ -297,11 +295,11 @@ describe("voteOnSponsorTime", () => {
|
||||
});
|
||||
|
||||
it('Non-VIP should not be able to upvote "dead" submission', (done: Done) => {
|
||||
fetch(`${getbaseURL()
|
||||
}/api/voteOnSponsorTime?userID=randomID2&UUID=vote-uuid-5&type=1`)
|
||||
const UUID = "vote-uuid-5";
|
||||
fetch(`${endpoint}?userID=randomID2&UUID=${UUID}&type=1`)
|
||||
.then(async res => {
|
||||
assert.strictEqual(res.status, 403);
|
||||
const row = await db.prepare("get", `SELECT "votes" FROM "sponsorTimes" WHERE "UUID" = ?`, ["vote-uuid-5"]);
|
||||
const row = await getSegmentVotes(UUID);
|
||||
assert.strictEqual(row.votes, -3);
|
||||
done();
|
||||
})
|
||||
@@ -309,11 +307,11 @@ describe("voteOnSponsorTime", () => {
|
||||
});
|
||||
|
||||
it('Non-VIP should not be able to downvote "dead" submission', (done: Done) => {
|
||||
fetch(`${getbaseURL()
|
||||
}/api/voteOnSponsorTime?userID=randomID2&UUID=vote-uuid-5&type=0`)
|
||||
const UUID = "vote-uuid-5";
|
||||
fetch(`${endpoint}?userID=randomID2&UUID=${UUID}&type=0`)
|
||||
.then(async res => {
|
||||
assert.strictEqual(res.status, 200);
|
||||
const row = await db.prepare("get", `SELECT "votes" FROM "sponsorTimes" WHERE "UUID" = ?`, ["vote-uuid-5"]);
|
||||
const row = await getSegmentVotes(UUID);
|
||||
assert.strictEqual(row.votes, -3);
|
||||
done();
|
||||
})
|
||||
@@ -321,11 +319,11 @@ describe("voteOnSponsorTime", () => {
|
||||
});
|
||||
|
||||
it('VIP should be able to upvote "dead" submission', (done: Done) => {
|
||||
fetch(`${getbaseURL()
|
||||
}/api/voteOnSponsorTime?userID=VIPUser&UUID=vote-uuid-5&type=1`)
|
||||
const UUID = "vote-uuid-5";
|
||||
fetch(`${endpoint}?userID=VIPUser&UUID=${UUID}&type=1`)
|
||||
.then(async res => {
|
||||
assert.strictEqual(res.status, 200);
|
||||
const row = await db.prepare("get", `SELECT "votes" FROM "sponsorTimes" WHERE "UUID" = ?`, ["vote-uuid-5"]);
|
||||
const row = await getSegmentVotes(UUID);
|
||||
assert.ok(row.votes > -3);
|
||||
done();
|
||||
})
|
||||
@@ -333,8 +331,8 @@ describe("voteOnSponsorTime", () => {
|
||||
});
|
||||
|
||||
it("Should not be able to upvote a segment (Too many warning)", (done: Done) => {
|
||||
fetch(`${getbaseURL()
|
||||
}/api/voteOnSponsorTime?userID=warn-voteuser01&UUID=warnvote-uuid-0&type=1`)
|
||||
const UUID = "warnvote-uuid-0";
|
||||
fetch(`${endpoint}?userID=warn-voteuser01&UUID=${UUID}&type=1`)
|
||||
.then(async res => {
|
||||
assert.strictEqual(res.status, 403);
|
||||
done();
|
||||
@@ -343,11 +341,11 @@ describe("voteOnSponsorTime", () => {
|
||||
});
|
||||
|
||||
it("Non-VIP should not be able to downvote on a segment with no-segments category", (done: Done) => {
|
||||
fetch(`${getbaseURL()
|
||||
}/api/voteOnSponsorTime?userID=randomID&UUID=no-sponsor-segments-uuid-0&type=0`)
|
||||
const UUID = "no-sponsor-segments-uuid-0";
|
||||
fetch(`${endpoint}?userID=randomID&UUID=${UUID}&type=0`)
|
||||
.then(async res => {
|
||||
assert.strictEqual(res.status, 200);
|
||||
const row = await db.prepare("get", `SELECT "votes" FROM "sponsorTimes" WHERE "UUID" = ?`, ["no-sponsor-segments-uuid-0"]);
|
||||
const row = await getSegmentVotes(UUID);
|
||||
assert.strictEqual(row.votes, 2);
|
||||
done();
|
||||
})
|
||||
@@ -355,11 +353,11 @@ describe("voteOnSponsorTime", () => {
|
||||
});
|
||||
|
||||
it("Non-VIP should be able to upvote on a segment with no-segments category", (done: Done) => {
|
||||
fetch(`${getbaseURL()
|
||||
}/api/voteOnSponsorTime?userID=randomID&UUID=no-sponsor-segments-uuid-0&type=1`)
|
||||
const UUID = "no-sponsor-segments-uuid-0";
|
||||
fetch(`${endpoint}?userID=randomID&UUID=${UUID}&type=1`)
|
||||
.then(async res => {
|
||||
assert.strictEqual(res.status, 200);
|
||||
const row = await db.prepare("get", `SELECT "votes" FROM "sponsorTimes" WHERE "UUID" = ?`, ["no-sponsor-segments-uuid-0"]);
|
||||
const row = await getSegmentVotes(UUID);
|
||||
assert.strictEqual(row.votes, 3);
|
||||
done();
|
||||
})
|
||||
@@ -367,11 +365,11 @@ describe("voteOnSponsorTime", () => {
|
||||
});
|
||||
|
||||
it("Non-VIP should not be able to category vote on a segment with no-segments category", (done: Done) => {
|
||||
fetch(`${getbaseURL()
|
||||
}/api/voteOnSponsorTime?userID=randomID&UUID=no-sponsor-segments-uuid-0&category=outro`)
|
||||
const UUID = "no-sponsor-segments-uuid-0";
|
||||
fetch(`${endpoint}?userID=randomID&UUID=${UUID}&category=outro`)
|
||||
.then(async res => {
|
||||
assert.strictEqual(res.status, 200);
|
||||
const row = await db.prepare("get", `SELECT "category" FROM "sponsorTimes" WHERE "UUID" = ?`, ["no-sponsor-segments-uuid-0"]);
|
||||
const row = await getSegmentCategory(UUID);
|
||||
assert.strictEqual(row.category, "sponsor");
|
||||
done();
|
||||
})
|
||||
@@ -379,11 +377,11 @@ describe("voteOnSponsorTime", () => {
|
||||
});
|
||||
|
||||
it("VIP upvote should lock segment", (done: Done) => {
|
||||
fetch(`${getbaseURL()
|
||||
}/api/voteOnSponsorTime?userID=VIPUser&UUID=segment-locking-uuid-1&type=1`)
|
||||
const UUID = "segment-locking-uuid-1";
|
||||
fetch(`${endpoint}?userID=VIPUser&UUID=${UUID}&type=1`)
|
||||
.then(async res => {
|
||||
assert.strictEqual(res.status, 200);
|
||||
const row = await db.prepare("get", `SELECT "locked" FROM "sponsorTimes" WHERE "UUID" = ?`, ["segment-locking-uuid-1"]);
|
||||
const row = await db.prepare("get", `SELECT "locked" FROM "sponsorTimes" WHERE "UUID" = ?`, [UUID]);
|
||||
assert.strictEqual(row.locked, 1);
|
||||
done();
|
||||
})
|
||||
@@ -391,11 +389,11 @@ describe("voteOnSponsorTime", () => {
|
||||
});
|
||||
|
||||
it("VIP downvote should unlock segment", (done: Done) => {
|
||||
fetch(`${getbaseURL()
|
||||
}/api/voteOnSponsorTime?userID=VIPUser&UUID=segment-locking-uuid-1&type=0`)
|
||||
const UUID = "segment-locking-uuid-1";
|
||||
fetch(`${endpoint}?userID=VIPUser&UUID=${UUID}&type=0`)
|
||||
.then(async res => {
|
||||
assert.strictEqual(res.status, 200);
|
||||
const row = await db.prepare("get", `SELECT "locked" FROM "sponsorTimes" WHERE "UUID" = ?`, ["segment-locking-uuid-1"]);
|
||||
const row = await db.prepare("get", `SELECT "locked" FROM "sponsorTimes" WHERE "UUID" = ?`, [UUID]);
|
||||
assert.strictEqual(row.locked, 0);
|
||||
done();
|
||||
})
|
||||
@@ -403,11 +401,11 @@ describe("voteOnSponsorTime", () => {
|
||||
});
|
||||
|
||||
it("VIP upvote should unhide segment", (done: Done) => {
|
||||
fetch(`${getbaseURL()
|
||||
}/api/voteOnSponsorTime?userID=VIPUser&UUID=segment-hidden-uuid-1&type=1`)
|
||||
const UUID = "segment-hidden-uuid-1";
|
||||
fetch(`${endpoint}?userID=VIPUser&UUID=${UUID}&type=1`)
|
||||
.then(async res => {
|
||||
assert.strictEqual(res.status, 200);
|
||||
const row = await db.prepare("get", `SELECT "hidden" FROM "sponsorTimes" WHERE "UUID" = ?`, ["segment-hidden-uuid-1"]);
|
||||
const row = await db.prepare("get", `SELECT "hidden" FROM "sponsorTimes" WHERE "UUID" = ?`, [UUID]);
|
||||
assert.strictEqual(row.hidden, 0);
|
||||
done();
|
||||
})
|
||||
@@ -415,11 +413,11 @@ describe("voteOnSponsorTime", () => {
|
||||
});
|
||||
|
||||
it("Should be able to undo-vote a segment", (done: Done) => {
|
||||
fetch(`${getbaseURL()
|
||||
}/api/voteOnSponsorTime?userID=randomID2&UUID=vote-uuid-2&type=20`)
|
||||
const UUID = "vote-uuid-2";
|
||||
fetch(`${endpoint}?userID=randomID2&UUID=${UUID}&type=20`)
|
||||
.then(async res => {
|
||||
assert.strictEqual(res.status, 200);
|
||||
const row = await db.prepare("get", `SELECT "votes" FROM "sponsorTimes" WHERE "UUID" = ?`, ["vote-uuid-2"]);
|
||||
const row = await getSegmentVotes(UUID);
|
||||
assert.strictEqual(row.votes, 10);
|
||||
done();
|
||||
})
|
||||
@@ -427,7 +425,8 @@ describe("voteOnSponsorTime", () => {
|
||||
});
|
||||
|
||||
it("Should not be able to vote with type 10", (done: Done) => {
|
||||
fetch(`${getbaseURL() }/api/voteOnSponsorTime?userID=VIPUser&UUID=segment-locking-uuid-1&type=10`)
|
||||
const UUID = "segment-locking-uuid-1";
|
||||
fetch(`${endpoint}?userID=VIPUser&UUID=${UUID}&type=10`)
|
||||
.then(res => {
|
||||
assert.strictEqual(res.status, 400);
|
||||
done();
|
||||
@@ -436,7 +435,8 @@ describe("voteOnSponsorTime", () => {
|
||||
});
|
||||
|
||||
it("Should not be able to vote with type 11", (done: Done) => {
|
||||
fetch(`${getbaseURL() }/api/voteOnSponsorTime?userID=VIPUser&UUID=segment-locking-uuid-1&type=11`)
|
||||
const UUID = "segment-locking-uuid-1";
|
||||
fetch(`${endpoint}?userID=VIPUser&UUID=${UUID}&type=11`)
|
||||
.then(res => {
|
||||
assert.strictEqual(res.status, 400);
|
||||
done();
|
||||
|
||||
Reference in New Issue
Block a user