mirror of
https://github.com/ajayyy/SponsorBlockServer.git
synced 2025-12-06 11:36:58 +03:00
everything after postClearCache
This commit is contained in:
@@ -6,6 +6,7 @@ import assert from "assert";
|
||||
|
||||
const VIPUser = "clearCacheVIP";
|
||||
const regularUser = "regular-user";
|
||||
const endpoint = `${getbaseURL()}/api/clearCache`;
|
||||
|
||||
describe("postClearCache", () => {
|
||||
before(async () => {
|
||||
@@ -15,8 +16,7 @@ describe("postClearCache", () => {
|
||||
});
|
||||
|
||||
it("Should be able to clear cache for existing video", (done: Done) => {
|
||||
fetch(`${getbaseURL()
|
||||
}/api/clearCache?userID=${VIPUser}&videoID=clear-test`, {
|
||||
fetch(`${endpoint}?userID=${VIPUser}&videoID=clear-test`, {
|
||||
method: "POST"
|
||||
})
|
||||
.then(res => {
|
||||
@@ -27,8 +27,7 @@ describe("postClearCache", () => {
|
||||
});
|
||||
|
||||
it("Should be able to clear cache for nonexistent video", (done: Done) => {
|
||||
fetch(`${getbaseURL()
|
||||
}/api/clearCache?userID=${VIPUser}&videoID=dne-video`, {
|
||||
fetch(`${endpoint}?userID=${VIPUser}&videoID=dne-video`, {
|
||||
method: "POST"
|
||||
})
|
||||
.then(res => {
|
||||
@@ -39,8 +38,7 @@ describe("postClearCache", () => {
|
||||
});
|
||||
|
||||
it("Should get 403 as non-vip", (done: Done) => {
|
||||
fetch(`${getbaseURL()
|
||||
}/api/clearCache?userID=${regularUser}&videoID=clear-tes`, {
|
||||
fetch(`${endpoint}?userID=${regularUser}&videoID=clear-tes`, {
|
||||
method: "POST"
|
||||
})
|
||||
.then(async res => {
|
||||
@@ -51,8 +49,7 @@ describe("postClearCache", () => {
|
||||
});
|
||||
|
||||
it("Should give 400 with missing videoID", (done: Done) => {
|
||||
fetch(`${getbaseURL()
|
||||
}/api/clearCache?userID=${VIPUser}`, {
|
||||
fetch(`${endpoint}?userID=${VIPUser}`, {
|
||||
method: "POST"
|
||||
})
|
||||
.then(async res => {
|
||||
@@ -63,8 +60,7 @@ describe("postClearCache", () => {
|
||||
});
|
||||
|
||||
it("Should give 400 with missing userID", (done: Done) => {
|
||||
fetch(`${getbaseURL()
|
||||
}/api/clearCache?userID=${VIPUser}`, {
|
||||
fetch(`${endpoint}?userID=${VIPUser}`, {
|
||||
method: "POST"
|
||||
})
|
||||
.then(async res => {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import fetch from "node-fetch";
|
||||
import {Done, getbaseURL} from "../utils";
|
||||
import {Done, getbaseURL, postJSON} from "../utils";
|
||||
import {db} from "../../src/databases/databases";
|
||||
import {getHash} from "../../src/utils/getHash";
|
||||
import {IDatabase} from "../../src/databases/IDatabase";
|
||||
@@ -32,9 +32,8 @@ async function dbSponsorTimesCompareExpect(db: IDatabase, videoId: string, expec
|
||||
|
||||
describe("postPurgeAllSegments", function () {
|
||||
const privateVipUserID = "VIPUser-purgeAll";
|
||||
const route = "/api/purgeAllSegments";
|
||||
const vipUserID = getHash(privateVipUserID);
|
||||
const baseURL = getbaseURL();
|
||||
const endpoint = `${getbaseURL()}/api/purgeAllSegments`;
|
||||
|
||||
before(async function () {
|
||||
// startTime and endTime get set in beforeEach for consistency
|
||||
@@ -47,11 +46,8 @@ describe("postPurgeAllSegments", function () {
|
||||
});
|
||||
|
||||
it("Reject non-VIP user", function (done: Done) {
|
||||
fetch(`${baseURL}${route}`, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
fetch(endpoint, {
|
||||
...postJSON,
|
||||
body: JSON.stringify({
|
||||
videoID: "vsegpurge01",
|
||||
userID: "segshift_randomuser001",
|
||||
@@ -65,11 +61,8 @@ describe("postPurgeAllSegments", function () {
|
||||
});
|
||||
|
||||
it("Purge all segments success", function (done: Done) {
|
||||
fetch(`${baseURL}${route}`, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
fetch(endpoint, {
|
||||
...postJSON,
|
||||
body: JSON.stringify({
|
||||
videoID: "vsegpurge01",
|
||||
userID: privateVipUserID,
|
||||
@@ -83,12 +76,7 @@ describe("postPurgeAllSegments", function () {
|
||||
});
|
||||
|
||||
it("Should return 400 if missing body", function (done: Done) {
|
||||
fetch(`${baseURL}${route}`, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
}
|
||||
})
|
||||
fetch(endpoint, { ...postJSON })
|
||||
.then(async res => {
|
||||
assert.strictEqual(res.status, 400);
|
||||
done();
|
||||
|
||||
@@ -12,32 +12,32 @@ const mockManager = ImportMock.mockStaticClass(YouTubeAPIModule, "YouTubeAPI");
|
||||
const sinonStub = mockManager.mock("listVideos");
|
||||
sinonStub.callsFake(YouTubeApiMock.listVideos);
|
||||
|
||||
// Constant and helpers
|
||||
const submitUserOne = `PostSkipUser1${".".repeat(18)}`;
|
||||
const submitUserTwo = `PostSkipUser2${".".repeat(18)}`;
|
||||
const submitUserThree = `PostSkipUser3${".".repeat(18)}`;
|
||||
|
||||
const warnUser01 = "warn-user01-qwertyuiopasdfghjklzxcvbnm";
|
||||
const warnUser01Hash = getHash(warnUser01);
|
||||
const warnUser02 = "warn-user02-qwertyuiopasdfghjklzxcvbnm";
|
||||
const warnUser02Hash = getHash(warnUser02);
|
||||
const warnUser03 = "warn-user03-qwertyuiopasdfghjklzxcvbnm";
|
||||
const warnUser03Hash = getHash(warnUser03);
|
||||
const warnUser04 = "warn-user04-qwertyuiopasdfghjklzxcvbnm";
|
||||
const warnUser04Hash = getHash(warnUser04);
|
||||
|
||||
const submitUserOneHash = getHash(submitUserOne);
|
||||
const submitVIPuser = `VIPPostSkipUser${".".repeat(16)}`;
|
||||
const warnVideoID = "dQw4w9WgXcF";
|
||||
const badInputVideoID = "dQw4w9WgXcQ";
|
||||
|
||||
const queryDatabase = async (videoID: string) => await db.prepare("get", `SELECT "startTime", "endTime", "locked", "category" FROM "sponsorTimes" WHERE "videoID" = ?`, [videoID]);
|
||||
const queryDatabaseActionType = async(videoID: string) => await db.prepare("get", `SELECT "startTime", "endTime", "locked", "category", "actionType" FROM "sponsorTimes" WHERE "videoID" = ?`, [videoID]);
|
||||
const queryDatabaseDuration = async (videoID: string) => await db.prepare("get", `SELECT "startTime", "endTime", "locked", "category", "videoDuration" FROM "sponsorTimes" WHERE "videoID" = ?`, [videoID]);
|
||||
|
||||
const endpoint = `${getbaseURL()}/api/skipSegments`;
|
||||
|
||||
describe("postSkipSegments", () => {
|
||||
// Constant and helpers
|
||||
const submitUserOne = `PostSkipUser1${".".repeat(18)}`;
|
||||
const submitUserTwo = `PostSkipUser2${".".repeat(18)}`;
|
||||
const submitUserThree = `PostSkipUser3${".".repeat(18)}`;
|
||||
|
||||
const warnUser01 = "warn-user01-qwertyuiopasdfghjklzxcvbnm";
|
||||
const warnUser01Hash = getHash(warnUser01);
|
||||
const warnUser02 = "warn-user02-qwertyuiopasdfghjklzxcvbnm";
|
||||
const warnUser02Hash = getHash(warnUser02);
|
||||
const warnUser03 = "warn-user03-qwertyuiopasdfghjklzxcvbnm";
|
||||
const warnUser03Hash = getHash(warnUser03);
|
||||
const warnUser04 = "warn-user04-qwertyuiopasdfghjklzxcvbnm";
|
||||
const warnUser04Hash = getHash(warnUser04);
|
||||
|
||||
const submitUserOneHash = getHash(submitUserOne);
|
||||
const submitVIPuser = `VIPPostSkipUser${".".repeat(16)}`;
|
||||
const warnVideoID = "dQw4w9WgXcF";
|
||||
const badInputVideoID = "dQw4w9WgXcQ";
|
||||
|
||||
const queryDatabase = async (videoID: string) => await db.prepare("get", `SELECT "startTime", "endTime", "locked", "category" FROM "sponsorTimes" WHERE "videoID" = ?`, [videoID]);
|
||||
const queryDatabaseActionType = async(videoID: string) => await db.prepare("get", `SELECT "startTime", "endTime", "locked", "category", "actionType" FROM "sponsorTimes" WHERE "videoID" = ?`, [videoID]);
|
||||
const queryDatabaseDuration = async (videoID: string) => await db.prepare("get", `SELECT "startTime", "endTime", "locked", "category", "videoDuration" FROM "sponsorTimes" WHERE "videoID" = ?`, [videoID]);
|
||||
|
||||
const endpoint = `${getbaseURL()}/api/skipSegments`;
|
||||
|
||||
before(() => {
|
||||
const insertSponsorTimeQuery = 'INSERT INTO "sponsorTimes" ("videoID", "startTime", "endTime", "votes", "UUID", "userID", "timeSubmitted", views, category, "shadowHidden", "hashedVideoID") VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)';
|
||||
db.prepare("run", insertSponsorTimeQuery, ["80percent_video", 0, 1000, 0, "80percent-uuid-0", submitUserOneHash, 0, 0, "interaction", 0, "80percent_video"]);
|
||||
@@ -598,7 +598,6 @@ describe("postSkipSegments", () => {
|
||||
})
|
||||
.then( async res => {
|
||||
assert.strictEqual(res.status, 403);
|
||||
console.log(res.text());
|
||||
done();
|
||||
})
|
||||
.catch(err => done(err));
|
||||
@@ -611,7 +610,6 @@ describe("postSkipSegments", () => {
|
||||
})
|
||||
.then(async res => {
|
||||
assert.strictEqual(res.status, 200);
|
||||
console.log(res.text());
|
||||
done();
|
||||
})
|
||||
.catch(err => done(err));
|
||||
|
||||
@@ -1,10 +1,14 @@
|
||||
import fetch from "node-fetch";
|
||||
import {Done, getbaseURL, partialDeepEquals} from "../utils";
|
||||
import {Done, getbaseURL, partialDeepEquals, postJSON} from "../utils";
|
||||
import {db} from "../../src/databases/databases";
|
||||
import {getHash} from "../../src/utils/getHash";
|
||||
import assert from "assert";
|
||||
|
||||
describe("postWarning", () => {
|
||||
// constants
|
||||
const endpoint = `${getbaseURL()}/api/warnUser`;
|
||||
const getWarning = async (userID: string) => await db.prepare("get", `SELECT "userID", "issueTime", "issuerUserID", enabled, "reason" FROM warnings WHERE "userID" = ?`, [userID]);
|
||||
|
||||
before(async () => {
|
||||
await db.prepare("run", `INSERT INTO "vipUsers" ("userID") VALUES (?)`, [getHash("warning-vip")]);
|
||||
});
|
||||
@@ -15,16 +19,13 @@ describe("postWarning", () => {
|
||||
userID: "warning-0",
|
||||
reason: "warning-reason-0"
|
||||
};
|
||||
fetch(`${getbaseURL()}/api/warnUser`, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
fetch(endpoint, {
|
||||
...postJSON,
|
||||
body: JSON.stringify(json),
|
||||
})
|
||||
.then(async res => {
|
||||
assert.strictEqual(res.status, 200);
|
||||
const row = await db.prepare("get", `SELECT "userID", "issueTime", "issuerUserID", enabled, "reason" FROM warnings WHERE "userID" = ?`, [json.userID]);
|
||||
const row = await getWarning(json.userID);
|
||||
const expected = {
|
||||
enabled: 1,
|
||||
issuerUserID: getHash(json.issuerUserID),
|
||||
@@ -42,16 +43,13 @@ describe("postWarning", () => {
|
||||
userID: "warning-0",
|
||||
};
|
||||
|
||||
fetch(`${getbaseURL()}/api/warnUser`, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
fetch(endpoint, {
|
||||
...postJSON,
|
||||
body: JSON.stringify(json),
|
||||
})
|
||||
.then(async res => {
|
||||
assert.strictEqual(res.status, 409);
|
||||
const row = await db.prepare("get", `SELECT "userID", "issueTime", "issuerUserID", enabled FROM warnings WHERE "userID" = ?`, [json.userID]);
|
||||
const row = await getWarning(json.userID);
|
||||
const expected = {
|
||||
enabled: 1,
|
||||
issuerUserID: getHash(json.issuerUserID),
|
||||
@@ -69,16 +67,13 @@ describe("postWarning", () => {
|
||||
enabled: false
|
||||
};
|
||||
|
||||
fetch(`${getbaseURL()}/api/warnUser`, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
fetch(endpoint, {
|
||||
...postJSON,
|
||||
body: JSON.stringify(json),
|
||||
})
|
||||
.then(async res => {
|
||||
assert.strictEqual(res.status, 200);
|
||||
const row = await db.prepare("get", `SELECT "userID", "issueTime", "issuerUserID", enabled FROM warnings WHERE "userID" = ?`, [json.userID]);
|
||||
const row = await getWarning(json.userID);
|
||||
const expected = {
|
||||
enabled: 0
|
||||
};
|
||||
@@ -94,11 +89,8 @@ describe("postWarning", () => {
|
||||
userID: "warning-1",
|
||||
};
|
||||
|
||||
fetch(`${getbaseURL()}/api/warnUser`, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
fetch(endpoint, {
|
||||
...postJSON,
|
||||
body: JSON.stringify(json),
|
||||
})
|
||||
.then(res => {
|
||||
@@ -109,12 +101,7 @@ describe("postWarning", () => {
|
||||
});
|
||||
|
||||
it("Should return 400 if missing body", (done: Done) => {
|
||||
fetch(`${getbaseURL()}/api/warnUser`, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
}
|
||||
})
|
||||
fetch(endpoint, postJSON)
|
||||
.then(async res => {
|
||||
assert.strictEqual(res.status, 400);
|
||||
done();
|
||||
@@ -129,16 +116,13 @@ describe("postWarning", () => {
|
||||
enabled: true
|
||||
};
|
||||
|
||||
fetch(`${getbaseURL()}/api/warnUser`, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
fetch(endpoint, {
|
||||
...postJSON,
|
||||
body: JSON.stringify(json),
|
||||
})
|
||||
.then(async res => {
|
||||
assert.strictEqual(res.status, 200);
|
||||
const data = await db.prepare("get", `SELECT "userID", "issueTime", "issuerUserID", enabled FROM warnings WHERE "userID" = ?`, [json.userID]);
|
||||
const data = await getWarning(json.userID);
|
||||
const expected = {
|
||||
enabled: 1
|
||||
};
|
||||
|
||||
@@ -4,117 +4,128 @@ import { UserID } from "../../src/types/user.model";
|
||||
import { getHash } from "../../src/utils/getHash";
|
||||
import { getReputation, calculateReputationFromMetrics } from "../../src/utils/reputation";
|
||||
|
||||
const userIDLowSubmissions = "reputation-lowsubmissions" as UserID;
|
||||
const userIDHighDownvotes = "reputation-highdownvotes" as UserID;
|
||||
const userIDHighNonSelfDownvotes = "reputation-highnonselfdownvotes" as UserID;
|
||||
const userIDNewSubmissions = "reputation-newsubmissions" as UserID;
|
||||
const userIDLowSum = "reputation-lowsum" as UserID;
|
||||
const userIDHighRepBeforeManualVote = "reputation-oldhighrep" as UserID;
|
||||
const userIDHighRep = "reputation-highrep" as UserID;
|
||||
const userIDHighRepAndLocked = "reputation-highlockedrep" as UserID;
|
||||
const userIDHaveMostUpvotedInLockedVideo = "reputation-mostupvotedaslocked" as UserID;
|
||||
|
||||
describe("reputation", () => {
|
||||
// constants
|
||||
const userIDLowSubmissions = "reputation-lowsubmissions" as UserID;
|
||||
const userHashLowSubmissions = getHash(userIDLowSubmissions);
|
||||
const userIDHighDownvotes = "reputation-highdownvotes" as UserID;
|
||||
const userHashHighDownvotes = getHash(userIDHighDownvotes);
|
||||
const userIDHighNonSelfDownvotes = "reputation-highnonselfdownvotes" as UserID;
|
||||
const userHashHighNonSelfDownvotes = getHash(userIDHighNonSelfDownvotes);
|
||||
const userIDNewSubmissions = "reputation-newsubmissions" as UserID;
|
||||
const userHashNewSubmissions = getHash(userIDNewSubmissions);
|
||||
const userIDLowSum = "reputation-lowsum" as UserID;
|
||||
const userHashLowSum = getHash(userIDLowSum);
|
||||
const userIDHighRepBeforeManualVote = "reputation-oldhighrep" as UserID;
|
||||
const userHashHighRepBeforeManualVote = getHash(userIDHighRepBeforeManualVote);
|
||||
const userIDHighRep = "reputation-highrep" as UserID;
|
||||
const userHashHighRep = getHash(userIDHighRep);
|
||||
const userIDHighRepAndLocked = "reputation-highlockedrep" as UserID;
|
||||
const userHashHighAndLocked = getHash(userIDHighRepAndLocked);
|
||||
const userIDHaveMostUpvotedInLockedVideo = "reputation-mostupvotedaslocked" as UserID;
|
||||
const userHashHaveMostUpvotedInLockedVideo = getHash(userIDHaveMostUpvotedInLockedVideo);
|
||||
|
||||
before(async function() {
|
||||
this.timeout(5000); // this preparation takes longer then usual
|
||||
const videoID = "reputation-videoID";
|
||||
const videoID2 = "reputation-videoID-2";
|
||||
|
||||
const sponsorTimesInsertQuery = 'INSERT INTO "sponsorTimes" ("videoID", "startTime", "endTime", "votes", "locked", "UUID", "userID", "timeSubmitted", "views", "category", "service", "videoDuration", "hidden", "shadowHidden", "hashedVideoID") VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)';
|
||||
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 2, 0, "reputation-0-uuid-0", getHash(userIDLowSubmissions), 1606240000000, 50, "sponsor", "YouTube", 100, 0, 0, getHash(videoID, 1)]);
|
||||
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 2, 0, "reputation-0-uuid-1", getHash(userIDLowSubmissions), 1606240000000, 50, "sponsor", "YouTube", 100, 0, 0, getHash(videoID, 1)]);
|
||||
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 100, 0, "reputation-0-uuid-2", getHash(userIDLowSubmissions), 1606240000000, 50, "sponsor", "YouTube", 100, 0, 0, getHash(videoID, 1)]);
|
||||
const sponsorTimesInsertQuery = 'INSERT INTO "sponsorTimes" ("videoID", "startTime", "endTime", "votes", "locked", "UUID", "userID", "timeSubmitted", "views", "category", "hidden", "shadowHidden") VALUES(?,?,?,?,?,?,?,?,?,?,?,?)';
|
||||
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 2, 0, "reputation-0-uuid-0", userHashLowSubmissions, 1606240000000, 50, "sponsor", 0, 0]);
|
||||
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 2, 0, "reputation-0-uuid-1", userHashLowSubmissions, 1606240000000, 50, "sponsor", 0, 0]);
|
||||
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 100, 0, "reputation-0-uuid-2", userHashLowSubmissions, 1606240000000, 50, "sponsor", 0, 0]);
|
||||
|
||||
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 2, 0, "reputation-1-uuid-0", getHash(userIDHighDownvotes), 1606240000000, 50, "sponsor", "YouTube", 100, 0, 0, getHash(videoID, 1)]);
|
||||
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, -2, 0, "reputation-1-uuid-1", getHash(userIDHighDownvotes), 1606240000000, 50, "sponsor", "YouTube", 100, 0, 0, getHash(videoID, 1)]);
|
||||
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, -2, 0, "reputation-1-uuid-2", getHash(userIDHighDownvotes), 1606240000000, 50, "sponsor", "YouTube", 100, 0, 0, getHash(videoID, 1)]);
|
||||
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, -2, 0, "reputation-1-uuid-3", getHash(userIDHighDownvotes), 1606240000000, 50, "sponsor", "YouTube", 100, 0, 0, getHash(videoID, 1)]);
|
||||
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, -2, 0, "reputation-1-uuid-4", getHash(userIDHighDownvotes), 1606240000000, 50, "sponsor", "YouTube", 100, 0, 0, getHash(videoID, 1)]);
|
||||
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, -1, 0, "reputation-1-uuid-5", getHash(userIDHighDownvotes), 1606240000000, 50, "sponsor", "YouTube", 100, 0, 0, getHash(videoID, 1)]);
|
||||
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 0, 0, "reputation-1-uuid-6", getHash(userIDHighDownvotes), 1606240000000, 50, "sponsor", "YouTube", 100, 0, 0, getHash(videoID, 1)]);
|
||||
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 0, 0, "reputation-1-uuid-7", getHash(userIDHighDownvotes), 1606240000000, 50, "sponsor", "YouTube", 100, 0, 0, getHash(videoID, 1)]);
|
||||
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 2, 0, "reputation-1-uuid-0", userHashHighDownvotes, 1606240000000, 50, "sponsor", 0, 0]);
|
||||
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, -2, 0, "reputation-1-uuid-1", userHashHighDownvotes, 1606240000000, 50, "sponsor", 0, 0]);
|
||||
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, -2, 0, "reputation-1-uuid-2", userHashHighDownvotes, 1606240000000, 50, "sponsor", 0, 0]);
|
||||
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, -2, 0, "reputation-1-uuid-3", userHashHighDownvotes, 1606240000000, 50, "sponsor", 0, 0]);
|
||||
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, -2, 0, "reputation-1-uuid-4", userHashHighDownvotes, 1606240000000, 50, "sponsor", 0, 0]);
|
||||
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, -1, 0, "reputation-1-uuid-5", userHashHighDownvotes, 1606240000000, 50, "sponsor", 0, 0]);
|
||||
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 0, 0, "reputation-1-uuid-6", userHashHighDownvotes, 1606240000000, 50, "sponsor", 0, 0]);
|
||||
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 0, 0, "reputation-1-uuid-7", userHashHighDownvotes, 1606240000000, 50, "sponsor", 0, 0]);
|
||||
|
||||
// First video is considered a normal downvote, second is considered a self-downvote (ie. they didn't resubmit to fix their downvote)
|
||||
await db.prepare("run", sponsorTimesInsertQuery, [`${videoID}A`, 1, 11, 2, 0, "reputation-1-1-uuid-0", getHash(userIDHighNonSelfDownvotes), 1606240000000, 50, "sponsor", "YouTube", 100, 0, 0, getHash(videoID, 1)]);
|
||||
await db.prepare("run", sponsorTimesInsertQuery, [`${videoID}A`, 1, 11, 2, 0, "reputation-1-1-uuid-0", userHashHighNonSelfDownvotes, 1606240000000, 50, "sponsor", 0, 0]);
|
||||
// Different category, same video
|
||||
await db.prepare("run", sponsorTimesInsertQuery, [`${videoID}A`, 1, 11, -2, 0, "reputation-1-1-uuid-1", getHash(userIDHighNonSelfDownvotes), 1606240000000, 50, "intro", "YouTube", 100, 0, 0, getHash(videoID, 1)]);
|
||||
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 0, 0, "reputation-1-1-uuid-2", getHash(userIDHighNonSelfDownvotes), 1606240000000, 50, "sponsor", "YouTube", 100, 0, 0, getHash(videoID, 1)]);
|
||||
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 0, 0, "reputation-1-1-uuid-3", getHash(userIDHighNonSelfDownvotes), 1606240000000, 50, "sponsor", "YouTube", 100, 0, 0, getHash(videoID, 1)]);
|
||||
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 0, 0, "reputation-1-1-uuid-4", getHash(userIDHighNonSelfDownvotes), 1606240000000, 50, "sponsor", "YouTube", 100, 0, 0, getHash(videoID, 1)]);
|
||||
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, -1, 0, "reputation-1-1-uuid-5", getHash(userIDHighNonSelfDownvotes), 1606240000000, 50, "sponsor", "YouTube", 100, 0, 0, getHash(videoID, 1)]);
|
||||
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 0, 0, "reputation-1-1-uuid-6", getHash(userIDHighNonSelfDownvotes), 1606240000000, 50, "sponsor", "YouTube", 100, 0, 0, getHash(videoID, 1)]);
|
||||
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 0, 0, "reputation-1-1-uuid-7", getHash(userIDHighNonSelfDownvotes), 1606240000000, 50, "sponsor", "YouTube", 100, 0, 0, getHash(videoID, 1)]);
|
||||
await db.prepare("run", sponsorTimesInsertQuery, [`${videoID}A`, 1, 11, -2, 0, "reputation-1-1-uuid-1", userHashHighNonSelfDownvotes, 1606240000000, 50, "intro", 0, 0]);
|
||||
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 0, 0, "reputation-1-1-uuid-2", userHashHighNonSelfDownvotes, 1606240000000, 50, "sponsor", 0, 0]);
|
||||
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 0, 0, "reputation-1-1-uuid-3", userHashHighNonSelfDownvotes, 1606240000000, 50, "sponsor", 0, 0]);
|
||||
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 0, 0, "reputation-1-1-uuid-4", userHashHighNonSelfDownvotes, 1606240000000, 50, "sponsor", 0, 0]);
|
||||
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, -1, 0, "reputation-1-1-uuid-5", userHashHighNonSelfDownvotes, 1606240000000, 50, "sponsor", 0, 0]);
|
||||
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 0, 0, "reputation-1-1-uuid-6", userHashHighNonSelfDownvotes, 1606240000000, 50, "sponsor", 0, 0]);
|
||||
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 0, 0, "reputation-1-1-uuid-7", userHashHighNonSelfDownvotes, 1606240000000, 50, "sponsor", 0, 0]);
|
||||
|
||||
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 2, 0, "reputation-2-uuid-0", getHash(userIDNewSubmissions), Date.now(), 50, "sponsor", "YouTube", 100, 0, 0, getHash(videoID, 1)]);
|
||||
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 2, 0, "reputation-2-uuid-1", getHash(userIDNewSubmissions), Date.now(), 50, "sponsor", "YouTube", 100, 0, 0, getHash(videoID, 1)]);
|
||||
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 2, 0, "reputation-2-uuid-2", getHash(userIDNewSubmissions), Date.now(), 50, "sponsor", "YouTube", 100, 0, 0, getHash(videoID, 1)]);
|
||||
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 2, 0, "reputation-2-uuid-3", getHash(userIDNewSubmissions), Date.now(), 50, "sponsor", "YouTube", 100, 0, 0, getHash(videoID, 1)]);
|
||||
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 2, 0, "reputation-2-uuid-4", getHash(userIDNewSubmissions), Date.now(), 50, "sponsor", "YouTube", 100, 0, 0, getHash(videoID, 1)]);
|
||||
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, -1, 0, "reputation-2-uuid-5", getHash(userIDNewSubmissions), 1606240000000, 50, "sponsor", "YouTube", 100, 0, 0, getHash(videoID, 1)]);
|
||||
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 0, 0, "reputation-2-uuid-6", getHash(userIDNewSubmissions), 1606240000000, 50, "sponsor", "YouTube", 100, 0, 0, getHash(videoID, 1)]);
|
||||
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 0, 0, "reputation-2-uuid-7", getHash(userIDNewSubmissions), 1606240000000, 50, "sponsor", "YouTube", 100, 0, 0, getHash(videoID, 1)]);
|
||||
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 2, 0, "reputation-2-uuid-0", userHashNewSubmissions, Date.now(), 50, "sponsor", 0, 0]);
|
||||
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 2, 0, "reputation-2-uuid-1", userHashNewSubmissions, Date.now(), 50, "sponsor", 0, 0]);
|
||||
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 2, 0, "reputation-2-uuid-2", userHashNewSubmissions, Date.now(), 50, "sponsor", 0, 0]);
|
||||
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 2, 0, "reputation-2-uuid-3", userHashNewSubmissions, Date.now(), 50, "sponsor", 0, 0]);
|
||||
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 2, 0, "reputation-2-uuid-4", userHashNewSubmissions, Date.now(), 50, "sponsor", 0, 0]);
|
||||
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, -1, 0, "reputation-2-uuid-5", userHashNewSubmissions, 1606240000000, 50, "sponsor", 0, 0]);
|
||||
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 0, 0, "reputation-2-uuid-6", userHashNewSubmissions, 1606240000000, 50, "sponsor", 0, 0]);
|
||||
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 0, 0, "reputation-2-uuid-7", userHashNewSubmissions, 1606240000000, 50, "sponsor", 0, 0]);
|
||||
|
||||
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 2, 0, "reputation-3-uuid-0", getHash(userIDLowSum), 1606240000000, 50, "sponsor", "YouTube", 100, 0, 0, getHash(videoID, 1)]);
|
||||
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 1, 0, "reputation-3-uuid-1", getHash(userIDLowSum), 1606240000000, 50, "sponsor", "YouTube", 100, 0, 0, getHash(videoID, 1)]);
|
||||
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 0, 0, "reputation-3-uuid-2", getHash(userIDLowSum), 1606240000000, 50, "sponsor", "YouTube", 100, 0, 0, getHash(videoID, 1)]);
|
||||
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 0, 0, "reputation-3-uuid-3", getHash(userIDLowSum), 1606240000000, 50, "sponsor", "YouTube", 100, 0, 0, getHash(videoID, 1)]);
|
||||
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 1, 0, "reputation-3-uuid-4", getHash(userIDLowSum), 1606240000000, 50, "sponsor", "YouTube", 100, 0, 0, getHash(videoID, 1)]);
|
||||
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, -1, 0, "reputation-3-uuid-5", getHash(userIDLowSum), 1606240000000, 50, "sponsor", "YouTube", 100, 0, 0, getHash(videoID, 1)]);
|
||||
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 0, 0, "reputation-3-uuid-6", getHash(userIDLowSum), 1606240000000, 50, "sponsor", "YouTube", 100, 0, 0, getHash(videoID, 1)]);
|
||||
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 0, 0, "reputation-3-uuid-7", getHash(userIDLowSum), 1606240000000, 50, "sponsor", "YouTube", 100, 0, 0, getHash(videoID, 1)]);
|
||||
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 2, 0, "reputation-3-uuid-0", userHashLowSum, 1606240000000, 50, "sponsor", 0, 0]);
|
||||
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 1, 0, "reputation-3-uuid-1", userHashLowSum, 1606240000000, 50, "sponsor", 0, 0]);
|
||||
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 0, 0, "reputation-3-uuid-2", userHashLowSum, 1606240000000, 50, "sponsor", 0, 0]);
|
||||
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 0, 0, "reputation-3-uuid-3", userHashLowSum, 1606240000000, 50, "sponsor", 0, 0]);
|
||||
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 1, 0, "reputation-3-uuid-4", userHashLowSum, 1606240000000, 50, "sponsor", 0, 0]);
|
||||
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, -1, 0, "reputation-3-uuid-5", userHashLowSum, 1606240000000, 50, "sponsor", 0, 0]);
|
||||
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 0, 0, "reputation-3-uuid-6", userHashLowSum, 1606240000000, 50, "sponsor", 0, 0]);
|
||||
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 0, 0, "reputation-3-uuid-7", userHashLowSum, 1606240000000, 50, "sponsor", 0, 0]);
|
||||
|
||||
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 2, 0, "reputation-4-uuid-0", getHash(userIDHighRepBeforeManualVote), 0, 50, "sponsor", "YouTube", 100, 0, 0, getHash(videoID, 1)]);
|
||||
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 2, 0, "reputation-4-uuid-1", getHash(userIDHighRepBeforeManualVote), 0, 50, "sponsor", "YouTube", 100, 0, 0, getHash(videoID, 1)]);
|
||||
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 2, 0, "reputation-4-uuid-2", getHash(userIDHighRepBeforeManualVote), 0, 50, "sponsor", "YouTube", 100, 0, 0, getHash(videoID, 1)]);
|
||||
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 2, 0, "reputation-4-uuid-3", getHash(userIDHighRepBeforeManualVote), 0, 50, "sponsor", "YouTube", 100, 0, 0, getHash(videoID, 1)]);
|
||||
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 2, 0, "reputation-4-uuid-4", getHash(userIDHighRepBeforeManualVote), 0, 50, "sponsor", "YouTube", 100, 0, 0, getHash(videoID, 1)]);
|
||||
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, -1, 0, "reputation-4-uuid-5", getHash(userIDHighRepBeforeManualVote), 0, 50, "sponsor", "YouTube", 100, 0, 0, getHash(videoID, 1)]);
|
||||
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 0, 0, "reputation-4-uuid-6", getHash(userIDHighRepBeforeManualVote), 0, 50, "sponsor", "YouTube", 100, 0, 0, getHash(videoID, 1)]);
|
||||
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 0, 0, "reputation-4-uuid-7", getHash(userIDHighRepBeforeManualVote), 0, 50, "sponsor", "YouTube", 100, 0, 0, getHash(videoID, 1)]);
|
||||
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 2, 0, "reputation-4-uuid-0", userHashHighRepBeforeManualVote, 0, 50, "sponsor", 0, 0]);
|
||||
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 2, 0, "reputation-4-uuid-1", userHashHighRepBeforeManualVote, 0, 50, "sponsor", 0, 0]);
|
||||
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 2, 0, "reputation-4-uuid-2", userHashHighRepBeforeManualVote, 0, 50, "sponsor", 0, 0]);
|
||||
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 2, 0, "reputation-4-uuid-3", userHashHighRepBeforeManualVote, 0, 50, "sponsor", 0, 0]);
|
||||
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 2, 0, "reputation-4-uuid-4", userHashHighRepBeforeManualVote, 0, 50, "sponsor", 0, 0]);
|
||||
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, -1, 0, "reputation-4-uuid-5", userHashHighRepBeforeManualVote, 0, 50, "sponsor", 0, 0]);
|
||||
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 0, 0, "reputation-4-uuid-6", userHashHighRepBeforeManualVote, 0, 50, "sponsor", 0, 0]);
|
||||
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 0, 0, "reputation-4-uuid-7", userHashHighRepBeforeManualVote, 0, 50, "sponsor", 0, 0]);
|
||||
|
||||
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 2, 0, "reputation-5-uuid-0", getHash(userIDHighRep), 1606240000000, 50, "sponsor", "YouTube", 100, 0, 0, getHash(videoID, 1)]);
|
||||
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 2, 0, "reputation-5-uuid-1", getHash(userIDHighRep), 1606240000000, 50, "sponsor", "YouTube", 100, 0, 0, getHash(videoID, 1)]);
|
||||
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 2, 0, "reputation-5-uuid-2", getHash(userIDHighRep), 1606240000000, 50, "sponsor", "YouTube", 100, 0, 0, getHash(videoID, 1)]);
|
||||
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 2, 0, "reputation-5-uuid-3", getHash(userIDHighRep), 1606240000000, 50, "sponsor", "YouTube", 100, 0, 0, getHash(videoID, 1)]);
|
||||
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 2, 0, "reputation-5-uuid-4", getHash(userIDHighRep), 1606240000000, 50, "sponsor", "YouTube", 100, 0, 0, getHash(videoID, 1)]);
|
||||
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, -1, 0, "reputation-5-uuid-5", getHash(userIDHighRep), 1606240000000, 50, "sponsor", "YouTube", 100, 0, 0, getHash(videoID, 1)]);
|
||||
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 0, 0, "reputation-5-uuid-6", getHash(userIDHighRep), 1606240000000, 50, "sponsor", "YouTube", 100, 0, 0, getHash(videoID, 1)]);
|
||||
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 0, 0, "reputation-5-uuid-7", getHash(userIDHighRep), 1606240000000, 50, "sponsor", "YouTube", 100, 0, 0, getHash(videoID, 1)]);
|
||||
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 2, 0, "reputation-5-uuid-0", userHashHighRep, 1606240000000, 50, "sponsor", 0, 0]);
|
||||
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 2, 0, "reputation-5-uuid-1", userHashHighRep, 1606240000000, 50, "sponsor", 0, 0]);
|
||||
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 2, 0, "reputation-5-uuid-2", userHashHighRep, 1606240000000, 50, "sponsor", 0, 0]);
|
||||
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 2, 0, "reputation-5-uuid-3", userHashHighRep, 1606240000000, 50, "sponsor", 0, 0]);
|
||||
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 2, 0, "reputation-5-uuid-4", userHashHighRep, 1606240000000, 50, "sponsor", 0, 0]);
|
||||
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, -1, 0, "reputation-5-uuid-5", userHashHighRep, 1606240000000, 50, "sponsor", 0, 0]);
|
||||
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 0, 0, "reputation-5-uuid-6", userHashHighRep, 1606240000000, 50, "sponsor", 0, 0]);
|
||||
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 0, 0, "reputation-5-uuid-7", userHashHighRep, 1606240000000, 50, "sponsor", 0, 0]);
|
||||
|
||||
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 2, 1, "reputation-6-uuid-0", getHash(userIDHighRepAndLocked), 1606240000000, 50, "sponsor", "YouTube", 100, 0, 0, getHash(videoID, 1)]);
|
||||
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 2, 1, "reputation-6-uuid-1", getHash(userIDHighRepAndLocked), 1606240000000, 50, "sponsor", "YouTube", 100, 0, 0, getHash(videoID, 1)]);
|
||||
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 2, 1, "reputation-6-uuid-2", getHash(userIDHighRepAndLocked), 1606240000000, 50, "sponsor", "YouTube", 100, 0, 0, getHash(videoID, 1)]);
|
||||
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 2, 1, "reputation-6-uuid-3", getHash(userIDHighRepAndLocked), 1606240000000, 50, "sponsor", "YouTube", 100, 0, 0, getHash(videoID, 1)]);
|
||||
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 2, 0, "reputation-6-uuid-4", getHash(userIDHighRepAndLocked), 1606240000000, 50, "sponsor", "YouTube", 100, 0, 0, getHash(videoID, 1)]);
|
||||
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, -1, 0, "reputation-6-uuid-5", getHash(userIDHighRepAndLocked), 1606240000000, 50, "sponsor", "YouTube", 100, 0, 0, getHash(videoID, 1)]);
|
||||
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 0, 0, "reputation-6-uuid-6", getHash(userIDHighRepAndLocked), 1606240000000, 50, "sponsor", "YouTube", 100, 0, 0, getHash(videoID, 1)]);
|
||||
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 0, 0, "reputation-6-uuid-7", getHash(userIDHighRepAndLocked), 1606240000000, 50, "sponsor", "YouTube", 100, 0, 0, getHash(videoID, 1)]);
|
||||
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 2, 1, "reputation-6-uuid-0", userHashHighAndLocked, 1606240000000, 50, "sponsor", 0, 0]);
|
||||
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 2, 1, "reputation-6-uuid-1", userHashHighAndLocked, 1606240000000, 50, "sponsor", 0, 0]);
|
||||
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 2, 1, "reputation-6-uuid-2", userHashHighAndLocked, 1606240000000, 50, "sponsor", 0, 0]);
|
||||
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 2, 1, "reputation-6-uuid-3", userHashHighAndLocked, 1606240000000, 50, "sponsor", 0, 0]);
|
||||
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 2, 0, "reputation-6-uuid-4", userHashHighAndLocked, 1606240000000, 50, "sponsor", 0, 0]);
|
||||
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, -1, 0, "reputation-6-uuid-5", userHashHighAndLocked, 1606240000000, 50, "sponsor", 0, 0]);
|
||||
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 0, 0, "reputation-6-uuid-6", userHashHighAndLocked, 1606240000000, 50, "sponsor", 0, 0]);
|
||||
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 0, 0, "reputation-6-uuid-7", userHashHighAndLocked, 1606240000000, 50, "sponsor", 0, 0]);
|
||||
|
||||
//Record has most upvoted
|
||||
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 5, 0, "reputation-7-uuid-0", getHash(userIDHaveMostUpvotedInLockedVideo), 1606240000000, 50, "sponsor", "YouTube", 100, 0, 0, getHash(videoID, 1)]);
|
||||
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 101, 0, "reputation-7-uuid-1", getHash(userIDHaveMostUpvotedInLockedVideo), 1606240000000, 50, "intro", "YouTube", 100, 0, 0, getHash(videoID, 1)]);
|
||||
await db.prepare("run", sponsorTimesInsertQuery, [videoID2, 1, 11, 5, 0, "reputation-7-uuid-8", getHash(userIDHaveMostUpvotedInLockedVideo), 1606240000000, 50, "sponsor", "YouTube", 100, 0, 0, getHash(videoID2, 1)]);
|
||||
await db.prepare("run", sponsorTimesInsertQuery, [videoID2, 1, 11, 0, 0, "reputation-7-uuid-9", getHash(userIDHaveMostUpvotedInLockedVideo), 1606240000000, 50, "sponsor", "YouTube", 100, 0, 0, getHash(videoID2, 1)]);
|
||||
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 5, 0, "reputation-7-uuid-0", userHashHaveMostUpvotedInLockedVideo, 1606240000000, 50, "sponsor", 0, 0]);
|
||||
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 101, 0, "reputation-7-uuid-1", userHashHaveMostUpvotedInLockedVideo, 1606240000000, 50, "intro", 0, 0]);
|
||||
await db.prepare("run", sponsorTimesInsertQuery, [videoID2, 1, 11, 5, 0, "reputation-7-uuid-8", userHashHaveMostUpvotedInLockedVideo, 1606240000000, 50, "sponsor", 0, 0]);
|
||||
await db.prepare("run", sponsorTimesInsertQuery, [videoID2, 1, 11, 0, 0, "reputation-7-uuid-9", userHashHaveMostUpvotedInLockedVideo, 1606240000000, 50, "sponsor", 0, 0]);
|
||||
// other segments
|
||||
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 2, 0, "reputation-7-uuid-2", getHash(userIDHaveMostUpvotedInLockedVideo), 1606240000000, 50, "sponsor", "YouTube", 100, 0, 0, getHash(videoID, 1)]);
|
||||
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 2, 0, "reputation-7-uuid-3", getHash(userIDHaveMostUpvotedInLockedVideo), 1606240000000, 50, "sponsor", "YouTube", 100, 0, 0, getHash(videoID, 1)]);
|
||||
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 2, 0, "reputation-7-uuid-4", getHash(userIDHaveMostUpvotedInLockedVideo), 1606240000000, 50, "sponsor", "YouTube", 100, 0, 0, getHash(videoID, 1)]);
|
||||
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, -1, 0, "reputation-7-uuid-5", getHash(userIDHaveMostUpvotedInLockedVideo), 1606240000000, 50, "sponsor", "YouTube", 100, 0, 0, getHash(videoID, 1)]);
|
||||
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 0, 0, "reputation-7-uuid-6", getHash(userIDHaveMostUpvotedInLockedVideo), 1606240000000, 50, "sponsor", "YouTube", 100, 0, 0, getHash(videoID, 1)]);
|
||||
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 0, 0, "reputation-7-uuid-7", getHash(userIDHaveMostUpvotedInLockedVideo), 1606240000000, 50, "sponsor", "YouTube", 100, 0, 0, getHash(videoID, 1)]);
|
||||
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 2, 0, "reputation-7-uuid-2", userHashHaveMostUpvotedInLockedVideo, 1606240000000, 50, "sponsor", 0, 0]);
|
||||
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 2, 0, "reputation-7-uuid-3", userHashHaveMostUpvotedInLockedVideo, 1606240000000, 50, "sponsor", 0, 0]);
|
||||
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 2, 0, "reputation-7-uuid-4", userHashHaveMostUpvotedInLockedVideo, 1606240000000, 50, "sponsor", 0, 0]);
|
||||
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, -1, 0, "reputation-7-uuid-5", userHashHaveMostUpvotedInLockedVideo, 1606240000000, 50, "sponsor", 0, 0]);
|
||||
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 0, 0, "reputation-7-uuid-6", userHashHaveMostUpvotedInLockedVideo, 1606240000000, 50, "sponsor", 0, 0]);
|
||||
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 0, 0, "reputation-7-uuid-7", userHashHaveMostUpvotedInLockedVideo, 1606240000000, 50, "sponsor", 0, 0]);
|
||||
|
||||
// lock video
|
||||
const insertVipUserQuery = 'INSERT INTO "vipUsers" ("userID") VALUES (?)';
|
||||
await db.prepare("run", insertVipUserQuery, [getHash("VIPUser-getLockCategories")]);
|
||||
|
||||
const insertLockCategoryQuery = 'INSERT INTO "lockCategories" ("userID", "videoID", "category", "hashedVideoID") VALUES (?, ?, ?, ?)';
|
||||
await db.prepare("run", insertLockCategoryQuery, [getHash("VIPUser-getLockCategories"), videoID, "sponsor", getHash(videoID, 1)]);
|
||||
await db.prepare("run", insertLockCategoryQuery, [getHash("VIPUser-getLockCategories"), videoID, "intro", getHash(videoID, 1)]);
|
||||
await db.prepare("run", insertLockCategoryQuery, [getHash("VIPUser-getLockCategories"), videoID2, "sponsor", getHash(videoID2, 1)]);
|
||||
const insertLockCategoryQuery = 'INSERT INTO "lockCategories" ("userID", "videoID", "category") VALUES (?, ?, ?)';
|
||||
await db.prepare("run", insertLockCategoryQuery, [getHash("VIPUser-getLockCategories"), videoID, "sponsor"]);
|
||||
await db.prepare("run", insertLockCategoryQuery, [getHash("VIPUser-getLockCategories"), videoID, "intro"]);
|
||||
await db.prepare("run", insertLockCategoryQuery, [getHash("VIPUser-getLockCategories"), videoID2, "sponsor"]);
|
||||
});
|
||||
|
||||
it("user in grace period", async () => {
|
||||
assert.strictEqual(await getReputation(getHash(userIDLowSubmissions)), 0);
|
||||
const data = await getReputation(getHash(userIDLowSubmissions));
|
||||
assert.strictEqual(data, 0);
|
||||
});
|
||||
|
||||
it("user with high downvote ratio", async () => {
|
||||
@@ -128,9 +139,9 @@ describe("reputation", () => {
|
||||
oldUpvotedSubmissions: 1,
|
||||
mostUpvotedInLockedVideoSum: 0
|
||||
};
|
||||
|
||||
assert.strictEqual(await getReputation(getHash(userIDHighDownvotes)), calculateReputationFromMetrics(metrics));
|
||||
assert.strictEqual(await getReputation(getHash(userIDHighDownvotes)), -2.125);
|
||||
const data = await getReputation(getHash(userIDHighDownvotes));
|
||||
assert.strictEqual(data, calculateReputationFromMetrics(metrics));
|
||||
assert.strictEqual(data, -2.125);
|
||||
});
|
||||
|
||||
it("user with high non self downvote ratio", async () => {
|
||||
@@ -144,20 +155,21 @@ describe("reputation", () => {
|
||||
oldUpvotedSubmissions: 1,
|
||||
mostUpvotedInLockedVideoSum: 0
|
||||
};
|
||||
assert.strictEqual(await getReputation(getHash(userIDHighNonSelfDownvotes)), calculateReputationFromMetrics(metrics));
|
||||
assert.strictEqual(await getReputation(getHash(userIDHighNonSelfDownvotes)), -1.6428571428571428);
|
||||
const data = await getReputation(userHashHighNonSelfDownvotes);
|
||||
assert.strictEqual(data, calculateReputationFromMetrics(metrics));
|
||||
assert.strictEqual(data, -1.6428571428571428);
|
||||
});
|
||||
|
||||
it("user with mostly new submissions", async () => {
|
||||
assert.strictEqual(await getReputation(getHash(userIDNewSubmissions)), 0);
|
||||
assert.strictEqual(await getReputation(userHashNewSubmissions), 0);
|
||||
});
|
||||
|
||||
it("user with not enough vote sum", async () => {
|
||||
assert.strictEqual(await getReputation(getHash(userIDLowSum)), 0);
|
||||
assert.strictEqual(await getReputation(userHashLowSum), 0);
|
||||
});
|
||||
|
||||
it("user with lots of old votes (before autovote was disabled) ", async () => {
|
||||
assert.strictEqual(await getReputation(getHash(userIDHighRepBeforeManualVote)), 0);
|
||||
assert.strictEqual(await getReputation(userHashHighRepBeforeManualVote), 0);
|
||||
});
|
||||
|
||||
it("user with high reputation", async () => {
|
||||
@@ -171,8 +183,9 @@ describe("reputation", () => {
|
||||
oldUpvotedSubmissions: 5,
|
||||
mostUpvotedInLockedVideoSum: 0
|
||||
};
|
||||
assert.strictEqual(await getReputation(getHash(userIDHighRep)), calculateReputationFromMetrics(metrics));
|
||||
assert.strictEqual(await getReputation(getHash(userIDHighRep)), 0.19310344827586207);
|
||||
const data = await getReputation(userHashHighRep);
|
||||
assert.strictEqual(data, calculateReputationFromMetrics(metrics));
|
||||
assert.strictEqual(data, 0.19310344827586207);
|
||||
});
|
||||
|
||||
it("user with high reputation and locked segments", async () => {
|
||||
@@ -186,8 +199,9 @@ describe("reputation", () => {
|
||||
oldUpvotedSubmissions: 5,
|
||||
mostUpvotedInLockedVideoSum: 0
|
||||
};
|
||||
assert.strictEqual(await getReputation(getHash(userIDHighRepAndLocked)), calculateReputationFromMetrics(metrics));
|
||||
assert.strictEqual(await getReputation(getHash(userIDHighRepAndLocked)), 1.793103448275862);
|
||||
const data = await getReputation(userHashHighAndLocked);
|
||||
assert.strictEqual(data, calculateReputationFromMetrics(metrics));
|
||||
assert.strictEqual(data, 1.793103448275862);
|
||||
});
|
||||
|
||||
it("user with most upvoted segments in locked video", async () => {
|
||||
@@ -201,8 +215,9 @@ describe("reputation", () => {
|
||||
oldUpvotedSubmissions: 6,
|
||||
mostUpvotedInLockedVideoSum: 2
|
||||
};
|
||||
assert.strictEqual(await getReputation(getHash(userIDHaveMostUpvotedInLockedVideo)), calculateReputationFromMetrics(metrics));
|
||||
assert.strictEqual(await getReputation(getHash(userIDHaveMostUpvotedInLockedVideo)), 6.158620689655172);
|
||||
const data = await getReputation(userHashHaveMostUpvotedInLockedVideo);
|
||||
assert.strictEqual(data, calculateReputationFromMetrics(metrics));
|
||||
assert.strictEqual(data, 6.158620689655172);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
@@ -1,46 +1,47 @@
|
||||
import fetch from "node-fetch";
|
||||
import {Done, getbaseURL} from "../utils";
|
||||
import {Done, getbaseURL, postJSON} from "../utils";
|
||||
import {db} from "../../src/databases/databases";
|
||||
import {getHash} from "../../src/utils/getHash";
|
||||
import {IDatabase} from "../../src/databases/IDatabase";
|
||||
import assert from "assert";
|
||||
|
||||
async function dbSponsorTimesAdd(db: IDatabase, videoID: string, startTime: number, endTime: number, UUID: string, category: string) {
|
||||
const votes = 0,
|
||||
userID = 0,
|
||||
timeSubmitted = 0,
|
||||
views = 0,
|
||||
shadowHidden = 0,
|
||||
hashedVideoID = `hash_${UUID}`;
|
||||
await db.prepare("run", `INSERT INTO
|
||||
"sponsorTimes" ("videoID", "startTime", "endTime", "votes", "UUID",
|
||||
"userID", "timeSubmitted", "views", "category", "shadowHidden", "hashedVideoID")
|
||||
VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`,
|
||||
[videoID, startTime, endTime, votes, UUID, userID, timeSubmitted, views, category, shadowHidden, hashedVideoID]);
|
||||
}
|
||||
describe("segmentShift", function () {
|
||||
// functions
|
||||
async function dbSponsorTimesAdd(db: IDatabase, videoID: string, startTime: number, endTime: number, UUID: string, category: string) {
|
||||
const votes = 0,
|
||||
userID = 0,
|
||||
timeSubmitted = 0,
|
||||
views = 0,
|
||||
shadowHidden = 0,
|
||||
hashedVideoID = `hash_${UUID}`;
|
||||
await db.prepare("run", `INSERT INTO
|
||||
"sponsorTimes" ("videoID", "startTime", "endTime", "votes", "UUID",
|
||||
"userID", "timeSubmitted", "views", "category", "shadowHidden", "hashedVideoID")
|
||||
VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`,
|
||||
[videoID, startTime, endTime, votes, UUID, userID, timeSubmitted, views, category, shadowHidden, hashedVideoID]);
|
||||
}
|
||||
|
||||
async function dbSponsorTimesSetByUUID(db: IDatabase, UUID: string, startTime: number, endTime: number) {
|
||||
await db.prepare("run", `UPDATE "sponsorTimes" SET "startTime" = ?, "endTime" = ? WHERE "UUID" = ?`, [startTime, endTime, UUID]);
|
||||
}
|
||||
async function dbSponsorTimesSetByUUID(db: IDatabase, UUID: string, startTime: number, endTime: number) {
|
||||
await db.prepare("run", `UPDATE "sponsorTimes" SET "startTime" = ?, "endTime" = ? WHERE "UUID" = ?`, [startTime, endTime, UUID]);
|
||||
}
|
||||
|
||||
async function dbSponsorTimesCompareExpect(db: IDatabase, expect: any): Promise<void> {
|
||||
for (let i = 0, len = expect.length; i < len; i++) {
|
||||
const expectSeg = expect[i];
|
||||
const seg = await db.prepare("get", `SELECT "startTime", "endTime" FROM "sponsorTimes" WHERE "UUID" = ?`, [expectSeg.UUID]);
|
||||
if ("removed" in expect) {
|
||||
assert.ok(expect.removed);
|
||||
assert.strictEqual(seg.votes, -2);
|
||||
assert.deepStrictEqual(seg, expectSeg);
|
||||
assert.strictEqual(seg.startTime, expectSeg.startTime);
|
||||
assert.strictEqual(seg.endTime, expectSeg.endTime);
|
||||
async function dbSponsorTimesCompareExpect(db: IDatabase, expect: any): Promise<void> {
|
||||
for (let i = 0, len = expect.length; i < len; i++) {
|
||||
const expectSeg = expect[i];
|
||||
const seg = await db.prepare("get", `SELECT "startTime", "endTime" FROM "sponsorTimes" WHERE "UUID" = ?`, [expectSeg.UUID]);
|
||||
if ("removed" in expect) {
|
||||
assert.ok(expect.removed);
|
||||
assert.strictEqual(seg.votes, -2);
|
||||
assert.deepStrictEqual(seg, expectSeg);
|
||||
assert.strictEqual(seg.startTime, expectSeg.startTime);
|
||||
assert.strictEqual(seg.endTime, expectSeg.endTime);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
describe("segmentShift", function () {
|
||||
// constants
|
||||
const privateVipUserID = "VIPUser-segmentShift";
|
||||
const vipUserID = getHash(privateVipUserID);
|
||||
const baseURL = getbaseURL();
|
||||
const endpoint = `${getbaseURL()}/api/segmentShift`;
|
||||
|
||||
before(async function () {
|
||||
// startTime and endTime get set in beforeEach for consistency
|
||||
@@ -60,11 +61,8 @@ describe("segmentShift", function () {
|
||||
});
|
||||
|
||||
it("Reject none VIP user", function (done: Done) {
|
||||
fetch(`${baseURL}/api/segmentShift`, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
fetch(endpoint, {
|
||||
...postJSON,
|
||||
body: JSON.stringify({
|
||||
videoID: "vsegshift01",
|
||||
userID: "segshift_randomuser001",
|
||||
@@ -80,11 +78,8 @@ describe("segmentShift", function () {
|
||||
});
|
||||
|
||||
it("Shift is outside segments", function (done: Done) {
|
||||
fetch(`${baseURL}/api/segmentShift`, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
fetch(endpoint, {
|
||||
...postJSON,
|
||||
body: JSON.stringify({
|
||||
videoID: "vsegshift01",
|
||||
userID: privateVipUserID,
|
||||
@@ -94,39 +89,31 @@ describe("segmentShift", function () {
|
||||
})
|
||||
.then(async res => {
|
||||
assert.strictEqual(res.status, 200);
|
||||
const expect = [
|
||||
{
|
||||
UUID: "vsegshifttest01uuid01",
|
||||
startTime: 0,
|
||||
endTime: 10,
|
||||
},
|
||||
{
|
||||
UUID: "vsegshifttest01uuid02",
|
||||
startTime: 50,
|
||||
endTime: 80,
|
||||
},
|
||||
{
|
||||
UUID: "vsegshifttest01uuid03",
|
||||
startTime: 30,
|
||||
endTime: 35,
|
||||
},
|
||||
{
|
||||
UUID: "vsegshifttest01uuid04",
|
||||
startTime: 110,
|
||||
endTime: 130,
|
||||
},
|
||||
];
|
||||
const expect = [{
|
||||
UUID: "vsegshifttest01uuid01",
|
||||
startTime: 0,
|
||||
endTime: 10,
|
||||
}, {
|
||||
UUID: "vsegshifttest01uuid02",
|
||||
startTime: 50,
|
||||
endTime: 80,
|
||||
}, {
|
||||
UUID: "vsegshifttest01uuid03",
|
||||
startTime: 30,
|
||||
endTime: 35,
|
||||
}, {
|
||||
UUID: "vsegshifttest01uuid04",
|
||||
startTime: 110,
|
||||
endTime: 130,
|
||||
}];
|
||||
done(await dbSponsorTimesCompareExpect(db, expect));
|
||||
})
|
||||
.catch(err => done(err));
|
||||
});
|
||||
|
||||
it("Shift is inside segment", function (done: Done) {
|
||||
fetch(`${baseURL}/api/segmentShift`, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
fetch(endpoint, {
|
||||
...postJSON,
|
||||
body: JSON.stringify({
|
||||
videoID: "vsegshift01",
|
||||
userID: privateVipUserID,
|
||||
@@ -136,39 +123,31 @@ describe("segmentShift", function () {
|
||||
})
|
||||
.then(async res => {
|
||||
assert.strictEqual(res.status, 200);
|
||||
const expect = [
|
||||
{
|
||||
UUID: "vsegshifttest01uuid01",
|
||||
startTime: 0,
|
||||
endTime: 10,
|
||||
},
|
||||
{
|
||||
UUID: "vsegshifttest01uuid02",
|
||||
startTime: 60,
|
||||
endTime: 80,
|
||||
},
|
||||
{
|
||||
UUID: "vsegshifttest01uuid03",
|
||||
startTime: 40,
|
||||
endTime: 45,
|
||||
},
|
||||
{
|
||||
UUID: "vsegshifttest01uuid04",
|
||||
startTime: 110,
|
||||
endTime: 130,
|
||||
},
|
||||
];
|
||||
const expect = [{
|
||||
UUID: "vsegshifttest01uuid01",
|
||||
startTime: 0,
|
||||
endTime: 10,
|
||||
}, {
|
||||
UUID: "vsegshifttest01uuid02",
|
||||
startTime: 60,
|
||||
endTime: 80,
|
||||
}, {
|
||||
UUID: "vsegshifttest01uuid03",
|
||||
startTime: 40,
|
||||
endTime: 45,
|
||||
}, {
|
||||
UUID: "vsegshifttest01uuid04",
|
||||
startTime: 110,
|
||||
endTime: 130,
|
||||
}];
|
||||
done(await dbSponsorTimesCompareExpect(db, expect));
|
||||
})
|
||||
.catch(err => done(err));
|
||||
});
|
||||
|
||||
it("Shift is overlaping startTime of segment", function (done: Done) {
|
||||
fetch(`${baseURL}/api/segmentShift`, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
fetch(endpoint, {
|
||||
...postJSON,
|
||||
body: JSON.stringify({
|
||||
videoID: "vsegshift01",
|
||||
userID: privateVipUserID,
|
||||
@@ -178,39 +157,31 @@ describe("segmentShift", function () {
|
||||
})
|
||||
.then(async res => {
|
||||
assert.strictEqual(res.status, 200);
|
||||
const expect = [
|
||||
{
|
||||
UUID: "vsegshifttest01uuid01",
|
||||
startTime: 0,
|
||||
endTime: 10,
|
||||
},
|
||||
{
|
||||
UUID: "vsegshifttest01uuid02",
|
||||
startTime: 50,
|
||||
endTime: 80,
|
||||
},
|
||||
{
|
||||
UUID: "vsegshifttest01uuid03",
|
||||
startTime: 32,
|
||||
endTime: 35,
|
||||
},
|
||||
{
|
||||
UUID: "vsegshifttest01uuid04",
|
||||
startTime: 110,
|
||||
endTime: 130,
|
||||
},
|
||||
];
|
||||
const expect = [{
|
||||
UUID: "vsegshifttest01uuid01",
|
||||
startTime: 0,
|
||||
endTime: 10,
|
||||
}, {
|
||||
UUID: "vsegshifttest01uuid02",
|
||||
startTime: 50,
|
||||
endTime: 80,
|
||||
}, {
|
||||
UUID: "vsegshifttest01uuid03",
|
||||
startTime: 32,
|
||||
endTime: 35,
|
||||
}, {
|
||||
UUID: "vsegshifttest01uuid04",
|
||||
startTime: 110,
|
||||
endTime: 130,
|
||||
}];
|
||||
done(await dbSponsorTimesCompareExpect(db, expect));
|
||||
})
|
||||
.catch(err => done(err));
|
||||
});
|
||||
|
||||
it("Shift is overlaping endTime of segment", function (done: Done) {
|
||||
fetch(`${baseURL}/api/segmentShift`, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
fetch(endpoint, {
|
||||
...postJSON,
|
||||
body: JSON.stringify({
|
||||
videoID: "vsegshift01",
|
||||
userID: privateVipUserID,
|
||||
@@ -220,39 +191,31 @@ describe("segmentShift", function () {
|
||||
})
|
||||
.then(async res => {
|
||||
assert.strictEqual(res.status, 200);
|
||||
const expect = [
|
||||
{
|
||||
UUID: "vsegshifttest01uuid01",
|
||||
startTime: 0,
|
||||
endTime: 10,
|
||||
},
|
||||
{
|
||||
UUID: "vsegshifttest01uuid02",
|
||||
startTime: 60,
|
||||
endTime: 85,
|
||||
},
|
||||
{
|
||||
UUID: "vsegshifttest01uuid03",
|
||||
startTime: 40,
|
||||
endTime: 45,
|
||||
},
|
||||
{
|
||||
UUID: "vsegshifttest01uuid04",
|
||||
startTime: 110,
|
||||
endTime: 130,
|
||||
},
|
||||
];
|
||||
const expect = [{
|
||||
UUID: "vsegshifttest01uuid01",
|
||||
startTime: 0,
|
||||
endTime: 10,
|
||||
}, {
|
||||
UUID: "vsegshifttest01uuid02",
|
||||
startTime: 60,
|
||||
endTime: 85,
|
||||
}, {
|
||||
UUID: "vsegshifttest01uuid03",
|
||||
startTime: 40,
|
||||
endTime: 45,
|
||||
}, {
|
||||
UUID: "vsegshifttest01uuid04",
|
||||
startTime: 110,
|
||||
endTime: 130,
|
||||
}];
|
||||
done(await dbSponsorTimesCompareExpect(db, expect));
|
||||
})
|
||||
.catch(err => done(err));
|
||||
});
|
||||
|
||||
it("Shift is overlaping segment", function (done: Done) {
|
||||
fetch(`${baseURL}/api/segmentShift`, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
fetch(endpoint, {
|
||||
...postJSON,
|
||||
body: JSON.stringify({
|
||||
videoID: "vsegshift01",
|
||||
userID: privateVipUserID,
|
||||
@@ -262,29 +225,24 @@ describe("segmentShift", function () {
|
||||
})
|
||||
.then(async res => {
|
||||
assert.strictEqual(res.status, 200);
|
||||
const expect = [
|
||||
{
|
||||
UUID: "vsegshifttest01uuid01",
|
||||
startTime: 0,
|
||||
endTime: 10,
|
||||
},
|
||||
{
|
||||
UUID: "vsegshifttest01uuid02",
|
||||
startTime: 40,
|
||||
endTime: 70,
|
||||
},
|
||||
{
|
||||
UUID: "vsegshifttest01uuid03",
|
||||
startTime: 40,
|
||||
endTime: 45,
|
||||
removed: true,
|
||||
},
|
||||
{
|
||||
UUID: "vsegshifttest01uuid04",
|
||||
startTime: 100,
|
||||
endTime: 120,
|
||||
},
|
||||
];
|
||||
const expect = [{
|
||||
UUID: "vsegshifttest01uuid01",
|
||||
startTime: 0,
|
||||
endTime: 10,
|
||||
}, {
|
||||
UUID: "vsegshifttest01uuid02",
|
||||
startTime: 40,
|
||||
endTime: 70,
|
||||
}, {
|
||||
UUID: "vsegshifttest01uuid03",
|
||||
startTime: 40,
|
||||
endTime: 45,
|
||||
removed: true,
|
||||
}, {
|
||||
UUID: "vsegshifttest01uuid04",
|
||||
startTime: 100,
|
||||
endTime: 120,
|
||||
}];
|
||||
done(await dbSponsorTimesCompareExpect(db, expect));
|
||||
})
|
||||
.catch(err => done(err));
|
||||
|
||||
@@ -60,6 +60,7 @@ async function testUserNameChangelog(userID: string, newUserName: string, oldUse
|
||||
}
|
||||
|
||||
describe("setUsername", () => {
|
||||
const endpoint = `${getbaseURL()}/api/setUsername`;
|
||||
before(async () => {
|
||||
await addUsername(getHash(user01PrivateUserID), username01, 0);
|
||||
await addUsername(getHash(user02PrivateUserID), username02, 0);
|
||||
@@ -71,7 +72,7 @@ describe("setUsername", () => {
|
||||
});
|
||||
|
||||
it("Should be able to set username that has never been set", (done: Done) => {
|
||||
fetch(`${getbaseURL()}/api/setUsername?userID=${user00PrivateUserID}&username=${username00}`, {
|
||||
fetch(`${endpoint}?userID=${user00PrivateUserID}&username=${username00}`, {
|
||||
method: "POST",
|
||||
})
|
||||
.then(async res => {
|
||||
@@ -85,7 +86,7 @@ describe("setUsername", () => {
|
||||
});
|
||||
|
||||
it("Should return 200", (done: Done) => {
|
||||
fetch(`${getbaseURL()}/api/setUsername?userID=${user01PrivateUserID}&username=Changed%20Username`, {
|
||||
fetch(`${endpoint}?userID=${user01PrivateUserID}&username=Changed%20Username`, {
|
||||
method: "POST",
|
||||
})
|
||||
.then(async res => {
|
||||
@@ -96,7 +97,7 @@ describe("setUsername", () => {
|
||||
});
|
||||
|
||||
it('Should return 400 for missing param "userID"', (done: Done) => {
|
||||
fetch(`${getbaseURL()}/api/setUsername?username=MyUsername`, {
|
||||
fetch(`${endpoint}?username=MyUsername`, {
|
||||
method: "POST",
|
||||
})
|
||||
.then(res => {
|
||||
@@ -107,7 +108,7 @@ describe("setUsername", () => {
|
||||
});
|
||||
|
||||
it('Should return 400 for missing param "username"', (done: Done) => {
|
||||
fetch(`${getbaseURL()}/api/setUsername?userID=test`, {
|
||||
fetch(`${endpoint}?userID=test`, {
|
||||
method: "POST",
|
||||
})
|
||||
.then(res => {
|
||||
@@ -119,7 +120,7 @@ describe("setUsername", () => {
|
||||
|
||||
it('Should return 400 for "username" longer then 64 characters', (done: Done) => {
|
||||
const username65 = "0000000000000000000000000000000000000000000000000000000000000000X";
|
||||
fetch(`${getbaseURL()}/api/setUsername?userID=test&username=${encodeURIComponent(username65)}`, {
|
||||
fetch(`${endpoint}?userID=test&username=${encodeURIComponent(username65)}`, {
|
||||
method: "POST",
|
||||
})
|
||||
.then(res => {
|
||||
@@ -131,7 +132,7 @@ describe("setUsername", () => {
|
||||
|
||||
it('Should not change username if it contains "discord"', (done: Done) => {
|
||||
const newUsername = "discord.me";
|
||||
fetch(`${getbaseURL()}/api/setUsername?userID=${user02PrivateUserID}&username=${encodeURIComponent(newUsername)}`, {
|
||||
fetch(`${endpoint}?userID=${user02PrivateUserID}&username=${encodeURIComponent(newUsername)}`, {
|
||||
method: "POST",
|
||||
})
|
||||
.then(async res => {
|
||||
@@ -145,7 +146,7 @@ describe("setUsername", () => {
|
||||
|
||||
it("Should be able to change username", (done: Done) => {
|
||||
const newUsername = "newUsername";
|
||||
fetch(`${getbaseURL()}/api/setUsername?userID=${user03PrivateUserID}&username=${encodeURIComponent(newUsername)}`, {
|
||||
fetch(`${endpoint}?userID=${user03PrivateUserID}&username=${encodeURIComponent(newUsername)}`, {
|
||||
method: "POST",
|
||||
})
|
||||
.then(async () => {
|
||||
@@ -159,7 +160,7 @@ describe("setUsername", () => {
|
||||
|
||||
it("Should not be able to change locked username", (done: Done) => {
|
||||
const newUsername = "newUsername";
|
||||
fetch(`${getbaseURL()}/api/setUsername?userID=${user04PrivateUserID}&username=${encodeURIComponent(newUsername)}`, {
|
||||
fetch(`${endpoint}?userID=${user04PrivateUserID}&username=${encodeURIComponent(newUsername)}`, {
|
||||
method: "POST",
|
||||
})
|
||||
.then(async () => {
|
||||
@@ -173,7 +174,7 @@ describe("setUsername", () => {
|
||||
|
||||
it("Should filter out unicode control characters", (done: Done) => {
|
||||
const newUsername = "This\nUsername+has\tInvalid+Characters";
|
||||
fetch(`${getbaseURL()}/api/setUsername?userID=${user05PrivateUserID}&username=${encodeURIComponent(newUsername)}`, {
|
||||
fetch(`${endpoint}?userID=${user05PrivateUserID}&username=${encodeURIComponent(newUsername)}`, {
|
||||
method: "POST",
|
||||
})
|
||||
.then(async () => {
|
||||
@@ -186,7 +187,7 @@ describe("setUsername", () => {
|
||||
|
||||
it("Incorrect adminUserID should return 403", (done: Done) => {
|
||||
const newUsername = "New Username";
|
||||
fetch(`${getbaseURL()}/api/setUsername?adminUserID=invalidAdminID&userID=${getHash(user06PrivateUserID)}&username=${encodeURIComponent(newUsername)}`, {
|
||||
fetch(`${endpoint}?adminUserID=invalidAdminID&userID=${getHash(user06PrivateUserID)}&username=${encodeURIComponent(newUsername)}`, {
|
||||
method: "POST",
|
||||
})
|
||||
.then(async res => {
|
||||
@@ -198,7 +199,7 @@ describe("setUsername", () => {
|
||||
|
||||
it("Admin should be able to change username", (done: Done) => {
|
||||
const newUsername = "New Username";
|
||||
fetch(`${getbaseURL()}/api/setUsername?adminUserID=${adminPrivateUserID}&userID=${getHash(user06PrivateUserID)}&username=${encodeURIComponent(newUsername)}`, {
|
||||
fetch(`${endpoint}?adminUserID=${adminPrivateUserID}&userID=${getHash(user06PrivateUserID)}&username=${encodeURIComponent(newUsername)}`, {
|
||||
method: "POST",
|
||||
})
|
||||
.then(async () => {
|
||||
@@ -212,7 +213,7 @@ describe("setUsername", () => {
|
||||
|
||||
it("Admin should be able to change locked username", (done: Done) => {
|
||||
const newUsername = "New Username";
|
||||
fetch(`${getbaseURL()}/api/setUsername?adminUserID=${adminPrivateUserID}&userID=${getHash(user07PrivateUserID)}&username=${encodeURIComponent(newUsername)}`, {
|
||||
fetch(`${endpoint}?adminUserID=${adminPrivateUserID}&userID=${getHash(user07PrivateUserID)}&username=${encodeURIComponent(newUsername)}`, {
|
||||
method: "POST",
|
||||
})
|
||||
.then(async () => {
|
||||
|
||||
@@ -3,8 +3,16 @@ import {db} from "../../src/databases/databases";
|
||||
import {Done, getbaseURL} from "../utils";
|
||||
import {getHash} from "../../src/utils/getHash";
|
||||
import assert from "assert";
|
||||
import { Category } from "../../src/types/segments.model";
|
||||
|
||||
describe("shadowBanUser", () => {
|
||||
const endpoint = `${getbaseURL()}/api/shadowBanUser`;
|
||||
const getShadowBan = (userID: string) => db.prepare("get", `SELECT * FROM "shadowBannedUsers" WHERE "userID" = ?`, [userID]);
|
||||
const getShadowBanSegments = (userID: string, status: number) => db.prepare("all", `SELECT "shadowHidden" FROM "sponsorTimes" WHERE "userID" = ? AND "shadowHidden" = ?`, [userID, status]);
|
||||
const getShadowBanSegmentCategory = (userID: string, status: number): Promise<{shadowHidden: number, category: Category}[]> => db.prepare("all", `SELECT "shadowHidden", "category" FROM "sponsorTimes" WHERE "userID" = ? AND "shadowHidden" = ?`, [userID, status]);
|
||||
|
||||
const VIPuserID = "shadow-ban-vip";
|
||||
|
||||
before(async () => {
|
||||
const insertQuery = `INSERT INTO "sponsorTimes" ("videoID", "startTime", "endTime", "votes", "locked", "UUID", "userID", "timeSubmitted", "views", "category", "service", "videoDuration", "hidden", "shadowHidden", "hashedVideoID") VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`;
|
||||
await db.prepare("run", insertQuery, ["testtesttest", 1, 11, 2, 0, "shadow-1-uuid-0", "shadowBanned", 0, 50, "sponsor", "YouTube", 100, 0, 0, getHash("testtesttest", 1)]);
|
||||
@@ -24,19 +32,18 @@ describe("shadowBanUser", () => {
|
||||
await db.prepare("run", `INSERT INTO "shadowBannedUsers" ("userID") VALUES(?)`, ["shadowBanned3"]);
|
||||
await db.prepare("run", `INSERT INTO "shadowBannedUsers" ("userID") VALUES(?)`, ["shadowBanned4"]);
|
||||
|
||||
await db.prepare("run", `INSERT INTO "vipUsers" ("userID") VALUES(?)`, [getHash("shadow-ban-vip")]);
|
||||
await db.prepare("run", `INSERT INTO "vipUsers" ("userID") VALUES(?)`, [getHash(VIPuserID)]);
|
||||
});
|
||||
|
||||
|
||||
it("Should be able to ban user and hide submissions", (done: Done) => {
|
||||
fetch(`${getbaseURL()
|
||||
}/api/shadowBanUser?userID=shadowBanned&adminUserID=shadow-ban-vip`, {
|
||||
const userID = "shadowBanned";
|
||||
fetch(`${endpoint}?userID=${userID}&adminUserID=${VIPuserID}`, {
|
||||
method: "POST"
|
||||
})
|
||||
.then(async res => {
|
||||
assert.strictEqual(res.status, 200);
|
||||
const videoRow = await db.prepare("all", `SELECT "shadowHidden" FROM "sponsorTimes" WHERE "userID" = ? AND "shadowHidden" = ?`, ["shadowBanned", 1]);
|
||||
const shadowRow = await db.prepare("get", `SELECT * FROM "shadowBannedUsers" WHERE "userID" = ?`, ["shadowBanned"]);
|
||||
const videoRow = await getShadowBanSegments(userID, 1);
|
||||
const shadowRow = await getShadowBan(userID);
|
||||
assert.ok(shadowRow);
|
||||
assert.strictEqual(videoRow.length, 3);
|
||||
done();
|
||||
@@ -45,14 +52,14 @@ describe("shadowBanUser", () => {
|
||||
});
|
||||
|
||||
it("Should be able to unban user without unhiding submissions", (done: Done) => {
|
||||
fetch(`${getbaseURL()
|
||||
}/api/shadowBanUser?userID=shadowBanned&adminUserID=shadow-ban-vip&enabled=false&unHideOldSubmissions=false`, {
|
||||
const userID = "shadowBanned";
|
||||
fetch(`${endpoint}?userID=${userID}&adminUserID=${VIPuserID}&enabled=false&unHideOldSubmissions=false`, {
|
||||
method: "POST"
|
||||
})
|
||||
.then(async res => {
|
||||
assert.strictEqual(res.status, 200);
|
||||
const videoRow = await db.prepare("all", `SELECT "shadowHidden" FROM "sponsorTimes" WHERE "userID" = ? AND "shadowHidden" = ?`, ["shadowBanned", 1]);
|
||||
const shadowRow = await db.prepare("get", `SELECT * FROM "shadowBannedUsers" WHERE "userID" = ?`, ["shadowBanned"]);
|
||||
const videoRow = await getShadowBanSegments(userID, 1);
|
||||
const shadowRow = await getShadowBan(userID);
|
||||
assert.ok(!shadowRow);
|
||||
assert.strictEqual(videoRow.length, 3);
|
||||
done();
|
||||
@@ -61,14 +68,14 @@ describe("shadowBanUser", () => {
|
||||
});
|
||||
|
||||
it("Should be able to ban user and hide submissions from only some categories", (done: Done) => {
|
||||
fetch(`${getbaseURL()
|
||||
}/api/shadowBanUser?userID=shadowBanned2&adminUserID=shadow-ban-vip&categories=["sponsor"]`, {
|
||||
const userID = "shadowBanned2";
|
||||
fetch(`${endpoint}?userID=${userID}&adminUserID=${VIPuserID}&categories=["sponsor"]`, {
|
||||
method: "POST"
|
||||
})
|
||||
.then(async res => {
|
||||
assert.strictEqual(res.status, 200);
|
||||
const videoRow: {category: string, shadowHidden: number}[] = (await db.prepare("all", `SELECT "shadowHidden", "category" FROM "sponsorTimes" WHERE "userID" = ? AND "shadowHidden" = ?`, ["shadowBanned2", 1]));
|
||||
const shadowRow = await db.prepare("get", `SELECT * FROM "shadowBannedUsers" WHERE "userID" = ?`, ["shadowBanned2"]);
|
||||
const videoRow = await getShadowBanSegmentCategory(userID, 1);
|
||||
const shadowRow = await getShadowBan(userID);
|
||||
assert.ok(shadowRow);
|
||||
assert.strictEqual(videoRow.length, 2);
|
||||
assert.strictEqual(videoRow.filter((elem) => elem.category === "sponsor").length, 2);
|
||||
@@ -78,14 +85,14 @@ describe("shadowBanUser", () => {
|
||||
});
|
||||
|
||||
it("Should be able to unban user and unhide submissions", (done: Done) => {
|
||||
fetch(`${getbaseURL()
|
||||
}/api/shadowBanUser?userID=shadowBanned2&adminUserID=shadow-ban-vip&enabled=false`, {
|
||||
const userID = "shadowBanned2";
|
||||
fetch(`${endpoint}?userID=${userID}&adminUserID=${VIPuserID}&enabled=false`, {
|
||||
method: "POST"
|
||||
})
|
||||
.then(async res => {
|
||||
assert.strictEqual(res.status, 200);
|
||||
const videoRow = await db.prepare("all", `SELECT "shadowHidden" FROM "sponsorTimes" WHERE "userID" = ? AND "shadowHidden" = ?`, ["shadowBanned2", 1]);
|
||||
const shadowRow = await db.prepare("get", `SELECT * FROM "shadowBannedUsers" WHERE "userID" = ?`, ["shadowBanned2"]);
|
||||
const videoRow = await getShadowBanSegments(userID, 1);
|
||||
const shadowRow = await getShadowBan(userID);
|
||||
assert.ok(!shadowRow);
|
||||
assert.strictEqual(videoRow?.length, 0);
|
||||
done();
|
||||
@@ -94,14 +101,14 @@ describe("shadowBanUser", () => {
|
||||
});
|
||||
|
||||
it("Should be able to unban user and unhide some submissions", (done: Done) => {
|
||||
fetch(`${getbaseURL()
|
||||
}/api/shadowBanUser?userID=shadowBanned3&adminUserID=shadow-ban-vip&enabled=false&categories=["sponsor"]`, {
|
||||
const userID = "shadowBanned3";
|
||||
fetch(`${endpoint}?userID=${userID}&adminUserID=${VIPuserID}&enabled=false&categories=["sponsor"]`, {
|
||||
method: "POST"
|
||||
})
|
||||
.then(async res => {
|
||||
assert.strictEqual(res.status, 200);
|
||||
const videoRow = await db.prepare("all", `SELECT "shadowHidden", "category" FROM "sponsorTimes" WHERE "userID" = ? AND "shadowHidden" = ?`, ["shadowBanned3", 1]);
|
||||
const shadowRow = await db.prepare("get", `SELECT * FROM "shadowBannedUsers" WHERE "userID" = ?`, ["shadowBanned3"]);
|
||||
const videoRow = await getShadowBanSegmentCategory(userID, 1);
|
||||
const shadowRow = await getShadowBan(userID);
|
||||
assert.ok(!shadowRow);
|
||||
assert.strictEqual(videoRow.length, 1);
|
||||
assert.strictEqual(videoRow[0].category, "intro");
|
||||
@@ -111,14 +118,14 @@ describe("shadowBanUser", () => {
|
||||
});
|
||||
|
||||
it("Should get 409 when re-shadowbanning user", (done: Done) => {
|
||||
fetch(`${getbaseURL()
|
||||
}/api/shadowBanUser?userID=shadowBanned4&adminUserID=shadow-ban-vip&enabled=true&categories=["sponsor"]&unHideOldSubmissions=false`, {
|
||||
const userID = "shadowBanned4";
|
||||
fetch(`${endpoint}?userID=${userID}&adminUserID=${VIPuserID}&enabled=true&categories=["sponsor"]&unHideOldSubmissions=false`, {
|
||||
method: "POST"
|
||||
})
|
||||
.then(async res => {
|
||||
assert.strictEqual(res.status, 409);
|
||||
const videoRow = await db.prepare("all", `SELECT "shadowHidden", "category" FROM "sponsorTimes" WHERE "userID" = ? AND "shadowHidden" = ?`, ["shadowBanned4", 0]);
|
||||
const shadowRow = await db.prepare("get", `SELECT * FROM "shadowBannedUsers" WHERE "userID" = ?`, ["shadowBanned4"]);
|
||||
const videoRow = await getShadowBanSegmentCategory(userID, 0);
|
||||
const shadowRow = await getShadowBan(userID);
|
||||
assert.ok(shadowRow); // ban still exists
|
||||
assert.strictEqual(videoRow.length, 1); // videos should not be hidden
|
||||
assert.strictEqual(videoRow[0].category, "sponsor");
|
||||
@@ -128,14 +135,14 @@ describe("shadowBanUser", () => {
|
||||
});
|
||||
|
||||
it("Should be able to re-shadowban user to hide old submissions", (done: Done) => {
|
||||
fetch(`${getbaseURL()
|
||||
}/api/shadowBanUser?userID=shadowBanned4&adminUserID=shadow-ban-vip&enabled=true&categories=["sponsor"]&unHideOldSubmissions=true`, {
|
||||
const userID = "shadowBanned4";
|
||||
fetch(`${endpoint}?userID=${userID}&adminUserID=${VIPuserID}&enabled=true&categories=["sponsor"]&unHideOldSubmissions=true`, {
|
||||
method: "POST"
|
||||
})
|
||||
.then(async res => {
|
||||
assert.strictEqual(res.status, 200);
|
||||
const videoRow = await db.prepare("all", `SELECT "shadowHidden", "category" FROM "sponsorTimes" WHERE "userID" = ? AND "shadowHidden" = ?`, ["shadowBanned4", 1]);
|
||||
const shadowRow = await db.prepare("get", `SELECT * FROM "shadowBannedUsers" WHERE "userID" = ?`, ["shadowBanned4"]);
|
||||
const videoRow = await getShadowBanSegmentCategory(userID, 1);
|
||||
const shadowRow = await getShadowBan(userID);
|
||||
assert.ok(shadowRow); // ban still exists
|
||||
assert.strictEqual(videoRow.length, 1); // videos should be hidden
|
||||
assert.strictEqual(videoRow[0].category, "sponsor");
|
||||
@@ -143,5 +150,4 @@ describe("shadowBanUser", () => {
|
||||
})
|
||||
.catch(err => done(err));
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
@@ -1,10 +1,13 @@
|
||||
import fetch from "node-fetch";
|
||||
import * as utils from "../utils";
|
||||
import { getbaseURL, postJSON } from "../utils";
|
||||
import { getHash } from "../../src/utils/getHash";
|
||||
import { db } from "../../src/databases/databases";
|
||||
import assert from "assert";
|
||||
|
||||
describe("unBan", () => {
|
||||
const endpoint = `${getbaseURL()}/api/shadowBanUser`;
|
||||
const VIPuser = "VIPUser-unBan";
|
||||
const videoIDUnBanCheck = (videoID: string, userID: string, status: number) => db.prepare("all", 'SELECT * FROM "sponsorTimes" WHERE "videoID" = ? AND "userID" = ? AND "shadowHidden" = ?', [videoID, userID, status]);
|
||||
before(async () => {
|
||||
const insertShadowBannedUserQuery = 'INSERT INTO "shadowBannedUsers" VALUES(?)';
|
||||
await db.prepare("run", insertShadowBannedUserQuery, ["testMan-unBan"]);
|
||||
@@ -12,10 +15,10 @@ describe("unBan", () => {
|
||||
await db.prepare("run", insertShadowBannedUserQuery, ["testEntity-unBan"]);
|
||||
|
||||
const insertVipUserQuery = 'INSERT INTO "vipUsers" ("userID") VALUES (?)';
|
||||
await db.prepare("run", insertVipUserQuery, [getHash("VIPUser-unBan")]);
|
||||
await db.prepare("run", insertVipUserQuery, [getHash(VIPuser)]);
|
||||
|
||||
const insertLockCategoryQuery = 'INSERT INTO "lockCategories" ("userID", "videoID", "category") VALUES(?, ?, ?)';
|
||||
await db.prepare("run", insertLockCategoryQuery, [getHash("VIPUser-unBan"), "unBan-videoID-1", "sponsor"]);
|
||||
await db.prepare("run", insertLockCategoryQuery, [getHash(VIPuser), "unBan-videoID-1", "sponsor"]);
|
||||
|
||||
const insertSponsorTimeQuery = 'INSERT INTO "sponsorTimes" ("videoID", "startTime", "endTime", "votes", "UUID", "userID", "timeSubmitted", views, category, "shadowHidden", "hashedVideoID") VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)';
|
||||
await db.prepare("run", insertSponsorTimeQuery, ["unBan-videoID-0", 1, 11, 2, "unBan-uuid-0", "testMan-unBan", 0, 50, "sponsor", 1, getHash("unBan-videoID-0", 1)]);
|
||||
@@ -25,16 +28,13 @@ describe("unBan", () => {
|
||||
});
|
||||
|
||||
it("Should be able to unban a user and re-enable shadow banned segments", (done) => {
|
||||
fetch(`${utils.getbaseURL()
|
||||
}/api/shadowBanUser?userID=testMan-unBan&adminUserID=VIPUser-unBan&enabled=false`, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
const userID = "testMan-unBan";
|
||||
fetch(`${endpoint}?userID=${userID}&adminUserID=${VIPuser}&enabled=false`, {
|
||||
...postJSON
|
||||
})
|
||||
.then(async res => {
|
||||
assert.strictEqual(res.status, 200);
|
||||
const result = await db.prepare("all", 'SELECT * FROM "sponsorTimes" WHERE "videoID" = ? AND "userID" = ? AND "shadowHidden" = ?', ["unBan-videoID-0", "testMan-unBan", 1]);
|
||||
const result = await videoIDUnBanCheck("unBan-videoID-0", userID, 1);
|
||||
assert.strictEqual(result.length, 0);
|
||||
done();
|
||||
})
|
||||
@@ -42,16 +42,13 @@ describe("unBan", () => {
|
||||
});
|
||||
|
||||
it("Should be able to unban a user and re-enable shadow banned segments without lockCategories entrys", (done) => {
|
||||
fetch(`${utils.getbaseURL()
|
||||
}/api/shadowBanUser?userID=testWoman-unBan&adminUserID=VIPUser-unBan&enabled=false`, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
const userID = "testWoman-unBan";
|
||||
fetch(`${endpoint}?userID=${userID}&adminUserID=${VIPuser}&enabled=false`, {
|
||||
...postJSON
|
||||
})
|
||||
.then(async res => {
|
||||
assert.strictEqual(res.status, 200);
|
||||
const result = await db.prepare("all", 'SELECT * FROM "sponsorTimes" WHERE "videoID" = ? AND "userID" = ? AND "shadowHidden" = ?', ["unBan-videoID-1", "testWoman-unBan", 1]);
|
||||
const result = await videoIDUnBanCheck("unBan-videoID-1", userID, 1);
|
||||
assert.strictEqual(result.length, 1);
|
||||
done();
|
||||
})
|
||||
@@ -59,16 +56,13 @@ describe("unBan", () => {
|
||||
});
|
||||
|
||||
it("Should be able to unban a user and re-enable shadow banned segments with a mix of lockCategories entrys", (done) => {
|
||||
fetch(`${utils.getbaseURL()
|
||||
}/api/shadowBanUser?userID=testEntity-unBan&adminUserID=VIPUser-unBan&enabled=false`, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
const userID = "testEntity-unBan";
|
||||
fetch(`${endpoint}?userID=${userID}&adminUserID=${VIPuser}&enabled=false`, {
|
||||
...postJSON
|
||||
})
|
||||
.then(async res => {
|
||||
assert.strictEqual(res.status, 200);
|
||||
const result = await db.prepare("all", 'SELECT * FROM "sponsorTimes" WHERE "userID" = ? AND "shadowHidden" = ?', ["testEntity-unBan", 1]);
|
||||
const result = await db.prepare("all", 'SELECT * FROM "sponsorTimes" WHERE "userID" = ? AND "shadowHidden" = ?', [userID, 1]);
|
||||
assert.strictEqual(result.length, 1);
|
||||
done();
|
||||
})
|
||||
|
||||
@@ -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