remaining tests

This commit is contained in:
Michael C
2021-09-22 23:18:31 -04:00
parent a028eaa41a
commit 4e50f0ab4b
9 changed files with 743 additions and 762 deletions

View File

@@ -1,13 +1,12 @@
import fetch from "node-fetch";
import { Done } from "../utils/utils";
import { getbaseURL } from "../utils/getBaseURL";
import { db } from "../../src/databases/databases";
import { getHash } from "../../src/utils/getHash";
import assert from "assert";
import { client } from "../utils/httpClient";
const VIPUser = "clearCacheVIP";
const regularUser = "regular-user";
const endpoint = `${getbaseURL()}/api/clearCache`;
const endpoint = "/api/clearCache";
const postClearCache = (userID: string, videoID: string) => client({ method: "post", url: endpoint, params: { userID, videoID } });
describe("postClearCache", () => {
before(async () => {
@@ -16,10 +15,8 @@ describe("postClearCache", () => {
await db.prepare("run", `${startOfQuery}('clear-test', 0, 1, 2, 'clear-uuid', 'testman', 0, 50, 'sponsor', 0)`);
});
it("Should be able to clear cache for existing video", (done: Done) => {
fetch(`${endpoint}?userID=${VIPUser}&videoID=clear-test`, {
method: "POST"
})
it("Should be able to clear cache for existing video", (done) => {
postClearCache(VIPUser, "clear-test")
.then(res => {
assert.strictEqual(res.status, 200);
done();
@@ -27,10 +24,8 @@ describe("postClearCache", () => {
.catch(err => done(err));
});
it("Should be able to clear cache for nonexistent video", (done: Done) => {
fetch(`${endpoint}?userID=${VIPUser}&videoID=dne-video`, {
method: "POST"
})
it("Should be able to clear cache for nonexistent video", (done) => {
postClearCache(VIPUser, "dne-video")
.then(res => {
assert.strictEqual(res.status, 200);
done();
@@ -38,10 +33,8 @@ describe("postClearCache", () => {
.catch(err => done(err));
});
it("Should get 403 as non-vip", (done: Done) => {
fetch(`${endpoint}?userID=${regularUser}&videoID=clear-tes`, {
method: "POST"
})
it("Should get 403 as non-vip", (done) => {
postClearCache(regularUser, "clear-test")
.then(async res => {
assert.strictEqual(res.status, 403);
done();
@@ -49,10 +42,8 @@ describe("postClearCache", () => {
.catch(err => done(err));
});
it("Should give 400 with missing videoID", (done: Done) => {
fetch(`${endpoint}?userID=${VIPUser}`, {
method: "POST"
})
it("Should give 400 with missing videoID", (done) => {
client.post(endpoint, { params: { userID: VIPUser } })
.then(async res => {
assert.strictEqual(res.status, 400);
done();
@@ -60,10 +51,8 @@ describe("postClearCache", () => {
.catch(err => done(err));
});
it("Should give 400 with missing userID", (done: Done) => {
fetch(`${endpoint}?userID=${VIPUser}`, {
method: "POST"
})
it("Should give 400 with missing userID", (done) => {
client.post(endpoint, { params: { videoID: "clear-test" } })
.then(async res => {
assert.strictEqual(res.status, 400);
done();

View File

@@ -1,10 +1,8 @@
import fetch from "node-fetch";
import { Done, postJSON } from "../utils/utils";
import { getbaseURL } from "../utils/getBaseURL";
import { db } from "../../src/databases/databases";
import { getHash } from "../../src/utils/getHash";
import { IDatabase } from "../../src/databases/IDatabase";
import assert from "assert";
import { client } from "../utils/httpClient";
async function dbSponsorTimesAdd(db: IDatabase, videoID: string, startTime: number, endTime: number, UUID: string, category: string) {
const votes = 0,
@@ -34,7 +32,8 @@ async function dbSponsorTimesCompareExpect(db: IDatabase, videoId: string, expec
describe("postPurgeAllSegments", function () {
const privateVipUserID = "VIPUser-purgeAll";
const vipUserID = getHash(privateVipUserID);
const endpoint = `${getbaseURL()}/api/purgeAllSegments`;
const endpoint = "/api/purgeAllSegments";
const postSegmentShift = (videoID: string, userID: string) => client.post(endpoint, { videoID, userID });
before(async function () {
// startTime and endTime get set in beforeEach for consistency
@@ -46,29 +45,17 @@ describe("postPurgeAllSegments", function () {
await db.prepare("run", `INSERT INTO "vipUsers" ("userID") VALUES (?)`, [vipUserID]);
});
it("Reject non-VIP user", function (done: Done) {
fetch(endpoint, {
...postJSON,
body: JSON.stringify({
videoID: "vsegpurge01",
userID: "segshift_randomuser001",
}),
})
.then(async res => {
it("Reject non-VIP user", function (done) {
postSegmentShift("vsegpurge01", "segshift_randomuser001")
.then(res => {
assert.strictEqual(res.status, 403);
done();
})
.catch(err => done(err));
});
it("Purge all segments success", function (done: Done) {
fetch(endpoint, {
...postJSON,
body: JSON.stringify({
videoID: "vsegpurge01",
userID: privateVipUserID,
}),
})
it("Purge all segments success", function (done) {
postSegmentShift("vsegpurge01", privateVipUserID)
.then(async res => {
assert.strictEqual(res.status, 200);
done(await dbSponsorTimesCompareExpect(db, "vsegpurge01", 1) || await dbSponsorTimesCompareExpect(db, "vseg-not-purged01", 0));
@@ -76,9 +63,9 @@ describe("postPurgeAllSegments", function () {
.catch(err => done(err));
});
it("Should return 400 if missing body", function (done: Done) {
fetch(endpoint, { ...postJSON })
.then(async res => {
it("Should return 400 if missing body", function (done) {
client.post(endpoint, {})
.then(res => {
assert.strictEqual(res.status, 400);
done();
})

File diff suppressed because it is too large Load Diff

View File

@@ -1,30 +1,25 @@
import fetch from "node-fetch";
import { Done, postJSON } from "../utils/utils";
import { getbaseURL } from "../utils/getBaseURL";
import { partialDeepEquals } from "../utils/partialDeepEquals";
import { db } from "../../src/databases/databases";
import { getHash } from "../../src/utils/getHash";
import assert from "assert";
import { client } from "../utils/httpClient";
describe("postWarning", () => {
// constants
const endpoint = `${getbaseURL()}/api/warnUser`;
const endpoint = "/api/warnUser";
const getWarning = (userID: string) => 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")]);
});
it("Should be able to create warning if vip (exp 200)", (done: Done) => {
it("Should be able to create warning if vip (exp 200)", (done) => {
const json = {
issuerUserID: "warning-vip",
userID: "warning-0",
reason: "warning-reason-0"
};
fetch(endpoint, {
...postJSON,
body: JSON.stringify(json),
})
client.post(endpoint, json)
.then(async res => {
assert.strictEqual(res.status, 200);
const row = await getWarning(json.userID);
@@ -39,16 +34,13 @@ describe("postWarning", () => {
.catch(err => done(err));
});
it("Should be not be able to create a duplicate warning if vip", (done: Done) => {
it("Should be not be able to create a duplicate warning if vip", (done) => {
const json = {
issuerUserID: "warning-vip",
userID: "warning-0",
};
fetch(endpoint, {
...postJSON,
body: JSON.stringify(json),
})
client.post(endpoint, json)
.then(async res => {
assert.strictEqual(res.status, 409);
const row = await getWarning(json.userID);
@@ -62,17 +54,14 @@ describe("postWarning", () => {
.catch(err => done(err));
});
it("Should be able to remove warning if vip", (done: Done) => {
it("Should be able to remove warning if vip", (done) => {
const json = {
issuerUserID: "warning-vip",
userID: "warning-0",
enabled: false
};
fetch(endpoint, {
...postJSON,
body: JSON.stringify(json),
})
client.post(endpoint, json)
.then(async res => {
assert.strictEqual(res.status, 200);
const row = await getWarning(json.userID);
@@ -85,16 +74,13 @@ describe("postWarning", () => {
.catch(err => done(err));
});
it("Should not be able to create warning if not vip (exp 403)", (done: Done) => {
it("Should not be able to create warning if not vip (exp 403)", (done) => {
const json = {
issuerUserID: "warning-not-vip",
userID: "warning-1",
};
fetch(endpoint, {
...postJSON,
body: JSON.stringify(json),
})
client.post(endpoint, json)
.then(res => {
assert.strictEqual(res.status, 403);
done();
@@ -102,8 +88,8 @@ describe("postWarning", () => {
.catch(err => done(err));
});
it("Should return 400 if missing body", (done: Done) => {
fetch(endpoint, postJSON)
it("Should return 400 if missing body", (done) => {
client.post(endpoint, {})
.then(async res => {
assert.strictEqual(res.status, 400);
done();
@@ -111,17 +97,14 @@ describe("postWarning", () => {
.catch(err => done(err));
});
it("Should re-enable disabled warning", (done: Done) => {
it("Should re-enable disabled warning", (done) => {
const json = {
issuerUserID: "warning-vip",
userID: "warning-0",
enabled: true
};
fetch(endpoint, {
...postJSON,
body: JSON.stringify(json),
})
client.post(endpoint, json)
.then(async res => {
assert.strictEqual(res.status, 200);
const data = await getWarning(json.userID);

View File

@@ -1,10 +1,8 @@
import fetch from "node-fetch";
import { Done, postJSON } from "../utils/utils";
import { getbaseURL } from "../utils/getBaseURL";
import { db } from "../../src/databases/databases";
import { getHash } from "../../src/utils/getHash";
import { IDatabase } from "../../src/databases/IDatabase";
import assert from "assert";
import { client } from "../utils/httpClient";
describe("segmentShift", function () {
// functions
@@ -42,7 +40,12 @@ describe("segmentShift", function () {
// constants
const privateVipUserID = "VIPUser-segmentShift";
const vipUserID = getHash(privateVipUserID);
const endpoint = `${getbaseURL()}/api/segmentShift`;
const endpoint = "/api/segmentShift";
const postSegmentShift = async (data: Record<string, any>) => client({
method: "POST",
url: endpoint,
data,
});
before(async function () {
// startTime and endTime get set in beforeEach for consistency
@@ -61,15 +64,12 @@ describe("segmentShift", function () {
await dbSponsorTimesSetByUUID(db, "vsegshifttest01uuid04", 120, 140);
});
it("Reject none VIP user", function (done: Done) {
fetch(endpoint, {
...postJSON,
body: JSON.stringify({
videoID: "vsegshift01",
userID: "segshift_randomuser001",
startTime: 20,
endTime: 30,
}),
it("Reject non VIP user", (done) => {
postSegmentShift({
videoID: "vsegshift01",
userID: "segshift_randomuser001",
startTime: 20,
endTime: 30,
})
.then(async res => {
assert.strictEqual(res.status, 403);
@@ -78,15 +78,12 @@ describe("segmentShift", function () {
.catch(err => done(err));
});
it("Shift is outside segments", function (done: Done) {
fetch(endpoint, {
...postJSON,
body: JSON.stringify({
videoID: "vsegshift01",
userID: privateVipUserID,
startTime: 20,
endTime: 30,
}),
it("Shift is outside segments", (done) => {
postSegmentShift({
videoID: "vsegshift01",
userID: privateVipUserID,
startTime: 20,
endTime: 30,
})
.then(async res => {
assert.strictEqual(res.status, 200);
@@ -112,15 +109,12 @@ describe("segmentShift", function () {
.catch(err => done(err));
});
it("Shift is inside segment", function (done: Done) {
fetch(endpoint, {
...postJSON,
body: JSON.stringify({
videoID: "vsegshift01",
userID: privateVipUserID,
startTime: 65,
endTime: 75,
}),
it("Shift is inside segment", (done) => {
postSegmentShift({
videoID: "vsegshift01",
userID: privateVipUserID,
startTime: 65,
endTime: 75,
})
.then(async res => {
assert.strictEqual(res.status, 200);
@@ -146,15 +140,12 @@ describe("segmentShift", function () {
.catch(err => done(err));
});
it("Shift is overlaping startTime of segment", function (done: Done) {
fetch(endpoint, {
...postJSON,
body: JSON.stringify({
videoID: "vsegshift01",
userID: privateVipUserID,
startTime: 32,
endTime: 42,
}),
it("Shift is overlaping startTime of segment", (done) => {
postSegmentShift({
videoID: "vsegshift01",
userID: privateVipUserID,
startTime: 32,
endTime: 42,
})
.then(async res => {
assert.strictEqual(res.status, 200);
@@ -180,15 +171,12 @@ describe("segmentShift", function () {
.catch(err => done(err));
});
it("Shift is overlaping endTime of segment", function (done: Done) {
fetch(endpoint, {
...postJSON,
body: JSON.stringify({
videoID: "vsegshift01",
userID: privateVipUserID,
startTime: 85,
endTime: 95,
}),
it("Shift is overlaping endTime of segment", (done) => {
postSegmentShift({
videoID: "vsegshift01",
userID: privateVipUserID,
startTime: 85,
endTime: 95,
})
.then(async res => {
assert.strictEqual(res.status, 200);
@@ -214,15 +202,12 @@ describe("segmentShift", function () {
.catch(err => done(err));
});
it("Shift is overlaping segment", function (done: Done) {
fetch(endpoint, {
...postJSON,
body: JSON.stringify({
videoID: "vsegshift01",
userID: privateVipUserID,
startTime: 35,
endTime: 55,
}),
it("Shift is overlaping segment", (done) => {
postSegmentShift({
videoID: "vsegshift01",
userID: privateVipUserID,
startTime: 35,
endTime: 55,
})
.then(async res => {
assert.strictEqual(res.status, 200);

View File

@@ -1,9 +1,7 @@
import fetch from "node-fetch";
import { Done } from "../utils/utils";
import { getbaseURL } from "../utils/getBaseURL";
import { db, privateDB } from "../../src/databases/databases";
import { getHash } from "../../src/utils/getHash";
import assert from "assert";
import { client } from "../utils/httpClient";
const adminPrivateUserID = "testUserId";
const user00PrivateUserID = "setUsername_00";
@@ -52,7 +50,7 @@ function wellFormatUserName(userName: string) {
return userName.replace(/[\u0000-\u001F\u007F-\u009F]/g, "");
}
async function testUserNameChangelog(userID: string, newUserName: string, oldUserName: string, byAdmin: boolean, done: Done) {
async function testUserNameChangelog(userID: string, newUserName: string, oldUserName: string, byAdmin: boolean, done: Mocha.Done) {
const log = await getLastLogUserNameChange(userID);
assert.strictEqual(newUserName, log.newUserName);
assert.strictEqual(oldUserName, log.oldUserName);
@@ -60,8 +58,27 @@ async function testUserNameChangelog(userID: string, newUserName: string, oldUse
return done();
}
const endpoint = "/api/setUsername";
const postSetUserName = (userID: string, username: string) => client({
method: "POST",
url: endpoint,
params: {
userID,
username,
}
});
const postSetUserNameAdmin = (userID: string, username: string, adminUserID: string) => client({
method: "POST",
url: endpoint,
params: {
userID,
username,
adminUserID,
}
});
describe("setUsername", () => {
const endpoint = `${getbaseURL()}/api/setUsername`;
before(async () => {
await addUsername(getHash(user01PrivateUserID), username01, 0);
await addUsername(getHash(user02PrivateUserID), username02, 0);
@@ -72,157 +89,147 @@ describe("setUsername", () => {
await addUsername(getHash(user07PrivateUserID), username07, 1);
});
it("Should be able to set username that has never been set", (done: Done) => {
fetch(`${endpoint}?userID=${user00PrivateUserID}&username=${username00}`, {
method: "POST",
})
it("Should be able to set username that has never been set", (done) => {
postSetUserName(user00PrivateUserID, username00)
.then(async res => {
console.log(res.data);
const usernameInfo = await getUsernameInfo(getHash(user00PrivateUserID));
assert.strictEqual(res.status, 200);
assert.strictEqual(usernameInfo.userName, username00);
assert.notStrictEqual(usernameInfo.locked, 1, "username should not be locked");
done();
})
.catch(() => done(`couldn't call endpoint`));
.catch((err) => done(err));
});
it("Should return 200", (done: Done) => {
fetch(`${endpoint}?userID=${user01PrivateUserID}&username=Changed%20Username`, {
method: "POST",
})
it("Should return 200", (done) => {
const username = "Changed%20Username";
postSetUserName(user01PrivateUserID, username)
.then(async res => {
assert.strictEqual(res.status, 200);
testUserNameChangelog(user01PrivateUserID, decodeURIComponent("Changed%20Username"), username01, false, done);
testUserNameChangelog(user01PrivateUserID, username, username01, false, done);
})
.catch(() => done(`couldn't call endpoint`));
.catch((err) => done(err));
});
it('Should return 400 for missing param "userID"', (done: Done) => {
fetch(`${endpoint}?username=MyUsername`, {
it('Should return 400 for missing param "userID"', (done) => {
client({
method: "POST",
url: endpoint,
data: {
userName: "MyUsername"
}
})
.then(res => {
assert.strictEqual(res.status, 400);
done();
})
.catch(() => done(`couldn't call endpoint`));
.catch((err) => done(err));
});
it('Should return 400 for missing param "username"', (done: Done) => {
fetch(`${endpoint}?userID=test`, {
it('Should return 400 for missing param "username"', (done) => {
client({
method: "POST",
url: endpoint,
data: {
userID: "test"
}
})
.then(res => {
assert.strictEqual(res.status, 400);
done();
})
.catch(() => done(`couldn't call endpoint`));
.catch((err) => done(err));
});
it('Should return 400 for "username" longer then 64 characters', (done: Done) => {
it('Should return 400 for "username" longer then 64 characters', (done) => {
const username65 = "0000000000000000000000000000000000000000000000000000000000000000X";
fetch(`${endpoint}?userID=test&username=${encodeURIComponent(username65)}`, {
method: "POST",
})
postSetUserName("test", username65)
.then(res => {
assert.strictEqual(res.status, 400);
done();
})
.catch(() => done(`couldn't call endpoint`));
.catch((err) => done(err));
});
it('Should not change username if it contains "discord"', (done: Done) => {
it('Should not change username if it contains "discord"', (done) => {
const newUsername = "discord.me";
fetch(`${endpoint}?userID=${user02PrivateUserID}&username=${encodeURIComponent(newUsername)}`, {
method: "POST",
})
postSetUserName(user02PrivateUserID, newUsername)
.then(async res => {
assert.strictEqual(res.status, 200);
const userNameInfo = await getUsernameInfo(getHash(user02PrivateUserID));
assert.notStrictEqual(userNameInfo.userName, newUsername);
done();
})
.catch(() => done(`couldn't call endpoint`));
.catch((err) => done(err));
});
it("Should be able to change username", (done: Done) => {
it("Should be able to change username", (done) => {
const newUsername = "newUsername";
fetch(`${endpoint}?userID=${user03PrivateUserID}&username=${encodeURIComponent(newUsername)}`, {
method: "POST",
})
postSetUserName(user03PrivateUserID, newUsername)
.then(async () => {
const usernameInfo = await getUsernameInfo(getHash(user03PrivateUserID));
assert.strictEqual(usernameInfo.userName, newUsername, "Username should change");
assert.notStrictEqual(usernameInfo.locked, 1, "Username should not be locked");
testUserNameChangelog(user03PrivateUserID, newUsername, username03, false, done);
})
.catch(() => done(`couldn't call endpoint`));
.catch((err) => done(err));
});
it("Should not be able to change locked username", (done: Done) => {
it("Should not be able to change locked username", (done) => {
const newUsername = "newUsername";
fetch(`${endpoint}?userID=${user04PrivateUserID}&username=${encodeURIComponent(newUsername)}`, {
method: "POST",
})
postSetUserName(user04PrivateUserID, newUsername)
.then(async () => {
const usernameInfo = await getUsernameInfo(getHash(user04PrivateUserID));
assert.notStrictEqual(usernameInfo.userName, newUsername, "Username should not be changed");
assert.strictEqual(usernameInfo.locked, 1, "username should be locked");
done();
})
.catch((err) => done(`couldn't call endpoint: ${err}`));
.catch((err) => done(err));
});
it("Should filter out unicode control characters", (done: Done) => {
it("Should filter out unicode control characters", (done) => {
const newUsername = "This\nUsername+has\tInvalid+Characters";
fetch(`${endpoint}?userID=${user05PrivateUserID}&username=${encodeURIComponent(newUsername)}`, {
method: "POST",
})
postSetUserName(user05PrivateUserID, newUsername)
.then(async () => {
const usernameInfo = await getUsernameInfo(getHash(user05PrivateUserID));
assert.notStrictEqual(usernameInfo.userName, newUsername, "Username should not contain control characters");
testUserNameChangelog(user05PrivateUserID, wellFormatUserName(newUsername), username05, false, done);
})
.catch(() => done(`couldn't call endpoint`));
.catch((err) => done(err));
});
it("Incorrect adminUserID should return 403", (done: Done) => {
it("Incorrect adminUserID should return 403", (done) => {
const newUsername = "New Username";
fetch(`${endpoint}?adminUserID=invalidAdminID&userID=${getHash(user06PrivateUserID)}&username=${encodeURIComponent(newUsername)}`, {
method: "POST",
})
.then(async res => {
postSetUserNameAdmin(getHash(user06PrivateUserID), newUsername,"invalidAdminID")
.then(res => {
assert.strictEqual(res.status, 403);
done();
})
.catch(() => done(`couldn't call endpoint`));
.catch((err) => done(err));
});
it("Admin should be able to change username", (done: Done) => {
it("Admin should be able to change username", (done) => {
const newUsername = "New Username";
fetch(`${endpoint}?adminUserID=${adminPrivateUserID}&userID=${getHash(user06PrivateUserID)}&username=${encodeURIComponent(newUsername)}`, {
method: "POST",
})
postSetUserNameAdmin(getHash(user06PrivateUserID), newUsername, adminPrivateUserID)
.then(async () => {
const usernameInfo = await getUsernameInfo(getHash(user06PrivateUserID));
assert.strictEqual(usernameInfo.userName, newUsername, "username should be changed");
assert.strictEqual(usernameInfo.locked, 1, "Username should be locked");
testUserNameChangelog(user06PrivateUserID, newUsername, username06, true, done);
})
.catch(() => done(`couldn't call endpoint`));
.catch((err) => done(err));
});
it("Admin should be able to change locked username", (done: Done) => {
it("Admin should be able to change locked username", (done) => {
const newUsername = "New Username";
fetch(`${endpoint}?adminUserID=${adminPrivateUserID}&userID=${getHash(user07PrivateUserID)}&username=${encodeURIComponent(newUsername)}`, {
method: "POST",
})
postSetUserNameAdmin(getHash(user07PrivateUserID), newUsername, adminPrivateUserID)
.then(async () => {
const usernameInfo = await getUsernameInfo(getHash(user06PrivateUserID));
assert.strictEqual(usernameInfo.userName, newUsername, "Username should be changed");
assert.strictEqual(usernameInfo.locked, 1, "Username should be locked");
testUserNameChangelog(user07PrivateUserID, newUsername, username07, true, done);
})
.catch(() => done(`couldn't call endpoint`));
.catch((err) => done(err));
});
});

View File

@@ -1,17 +1,15 @@
import fetch from "node-fetch";
import { db } from "../../src/databases/databases";
import { Done } from "../utils/utils";
import { getbaseURL } from "../utils/getBaseURL";
import { getHash } from "../../src/utils/getHash";
import assert from "assert";
import { Category } from "../../src/types/segments.model";
import { client } from "../utils/httpClient";
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 endpoint = "/api/shadowBanUser";
const VIPuserID = "shadow-ban-vip";
before(async () => {
@@ -36,10 +34,15 @@ describe("shadowBanUser", () => {
await db.prepare("run", `INSERT INTO "vipUsers" ("userID") VALUES(?)`, [getHash(VIPuserID)]);
});
it("Should be able to ban user and hide submissions", (done: Done) => {
it("Should be able to ban user and hide submissions", (done) => {
const userID = "shadowBanned";
fetch(`${endpoint}?userID=${userID}&adminUserID=${VIPuserID}`, {
method: "POST"
client({
method: "POST",
url: endpoint,
params: {
userID,
adminUserID: VIPuserID,
}
})
.then(async res => {
assert.strictEqual(res.status, 200);
@@ -52,10 +55,17 @@ describe("shadowBanUser", () => {
.catch(err => done(err));
});
it("Should be able to unban user without unhiding submissions", (done: Done) => {
it("Should be able to unban user without unhiding submissions", (done) => {
const userID = "shadowBanned";
fetch(`${endpoint}?userID=${userID}&adminUserID=${VIPuserID}&enabled=false&unHideOldSubmissions=false`, {
method: "POST"
client({
method: "POST",
url: endpoint,
params: {
userID,
adminUserID: VIPuserID,
enabled: false,
unHideOldSubmissions: false,
}
})
.then(async res => {
assert.strictEqual(res.status, 200);
@@ -68,10 +78,16 @@ describe("shadowBanUser", () => {
.catch(err => done(err));
});
it("Should be able to ban user and hide submissions from only some categories", (done: Done) => {
it("Should be able to ban user and hide submissions from only some categories", (done) => {
const userID = "shadowBanned2";
fetch(`${endpoint}?userID=${userID}&adminUserID=${VIPuserID}&categories=["sponsor"]`, {
method: "POST"
client({
method: "POST",
url: endpoint,
params: {
userID,
adminUserID: VIPuserID,
categories: `["sponsor"]`
}
})
.then(async res => {
assert.strictEqual(res.status, 200);
@@ -85,10 +101,16 @@ describe("shadowBanUser", () => {
.catch(err => done(err));
});
it("Should be able to unban user and unhide submissions", (done: Done) => {
it("Should be able to unban user and unhide submissions", (done) => {
const userID = "shadowBanned2";
fetch(`${endpoint}?userID=${userID}&adminUserID=${VIPuserID}&enabled=false`, {
method: "POST"
client({
method: "POST",
url: endpoint,
params: {
userID,
adminUserID: VIPuserID,
enabled: false,
}
})
.then(async res => {
assert.strictEqual(res.status, 200);
@@ -101,10 +123,17 @@ describe("shadowBanUser", () => {
.catch(err => done(err));
});
it("Should be able to unban user and unhide some submissions", (done: Done) => {
it("Should be able to unban user and unhide some submissions", (done) => {
const userID = "shadowBanned3";
fetch(`${endpoint}?userID=${userID}&adminUserID=${VIPuserID}&enabled=false&categories=["sponsor"]`, {
method: "POST"
client({
method: "POST",
url: endpoint,
params: {
userID,
adminUserID: VIPuserID,
enabled: false,
categories: `["sponsor"]`
}
})
.then(async res => {
assert.strictEqual(res.status, 200);
@@ -118,10 +147,18 @@ describe("shadowBanUser", () => {
.catch(err => done(err));
});
it("Should get 409 when re-shadowbanning user", (done: Done) => {
it("Should get 409 when re-shadowbanning user", (done) => {
const userID = "shadowBanned4";
fetch(`${endpoint}?userID=${userID}&adminUserID=${VIPuserID}&enabled=true&categories=["sponsor"]&unHideOldSubmissions=false`, {
method: "POST"
client({
method: "POST",
url: endpoint,
params: {
userID,
adminUserID: VIPuserID,
enabled: true,
categories: `["sponsor"]`,
unHideOldSubmissions: false
}
})
.then(async res => {
assert.strictEqual(res.status, 409);
@@ -135,10 +172,18 @@ describe("shadowBanUser", () => {
.catch(err => done(err));
});
it("Should be able to re-shadowban user to hide old submissions", (done: Done) => {
it("Should be able to re-shadowban user to hide old submissions", (done) => {
const userID = "shadowBanned4";
fetch(`${endpoint}?userID=${userID}&adminUserID=${VIPuserID}&enabled=true&categories=["sponsor"]&unHideOldSubmissions=true`, {
method: "POST"
client({
method: "POST",
url: endpoint,
params: {
userID,
adminUserID: VIPuserID,
enabled: true,
categories: `["sponsor"]`,
unHideOldSubmissions: true
}
})
.then(async res => {
assert.strictEqual(res.status, 200);

View File

@@ -1,13 +1,20 @@
import fetch from "node-fetch";
import { postJSON } from "../utils/utils";
import { getbaseURL } from "../utils/getBaseURL";
import { getHash } from "../../src/utils/getHash";
import { db } from "../../src/databases/databases";
import { client } from "../utils/httpClient";
import assert from "assert";
describe("unBan", () => {
const endpoint = `${getbaseURL()}/api/shadowBanUser`;
const endpoint = "/api/shadowBanUser";
const VIPuser = "VIPUser-unBan";
const postUnBan = (userID: string, adminUserID: string, enabled: boolean) => client({
url: endpoint,
method: "POST",
params: {
userID,
adminUserID,
enabled
}
});
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(?)';
@@ -30,9 +37,7 @@ describe("unBan", () => {
it("Should be able to unban a user and re-enable shadow banned segments", (done) => {
const userID = "testMan-unBan";
fetch(`${endpoint}?userID=${userID}&adminUserID=${VIPuser}&enabled=false`, {
...postJSON
})
postUnBan(userID, VIPuser, false)
.then(async res => {
assert.strictEqual(res.status, 200);
const result = await videoIDUnBanCheck("unBan-videoID-0", userID, 1);
@@ -44,9 +49,7 @@ describe("unBan", () => {
it("Should be able to unban a user and re-enable shadow banned segments without lockCategories entrys", (done) => {
const userID = "testWoman-unBan";
fetch(`${endpoint}?userID=${userID}&adminUserID=${VIPuser}&enabled=false`, {
...postJSON
})
postUnBan(userID, VIPuser, false)
.then(async res => {
assert.strictEqual(res.status, 200);
const result = await videoIDUnBanCheck("unBan-videoID-1", userID, 1);
@@ -58,9 +61,7 @@ describe("unBan", () => {
it("Should be able to unban a user and re-enable shadow banned segments with a mix of lockCategories entrys", (done) => {
const userID = "testEntity-unBan";
fetch(`${endpoint}?userID=${userID}&adminUserID=${VIPuser}&enabled=false`, {
...postJSON
})
postUnBan(userID, VIPuser, false)
.then(async res => {
assert.strictEqual(res.status, 200);
const result = await db.prepare("all", 'SELECT * FROM "sponsorTimes" WHERE "userID" = ? AND "shadowHidden" = ?', [userID, 1]);

View File

@@ -1,17 +1,17 @@
import fetch from "node-fetch";
import { config } from "../../src/config";
import { db } from "../../src/databases/databases";
import { Done } from "../utils/utils";
import { getbaseURL } from "../utils/getBaseURL";
import { getHash } from "../../src/utils/getHash";
import { ImportMock } from "ts-mock-imports";
import * as YouTubeAPIModule from "../../src/utils/youtubeApi";
import { YouTubeApiMock } from "../youtubeMock";
import assert from "assert";
import { client } from "../utils/httpClient";
const mockManager = ImportMock.mockStaticClass(YouTubeAPIModule, "YouTubeAPI");
const sinonStub = mockManager.mock("listVideos");
sinonStub.callsFake(YouTubeApiMock.listVideos);
const vipUser = "VIPUser";
const randomID2 = "randomID2";
describe("voteOnSponsorTime", () => {
before(async () => {
@@ -35,7 +35,7 @@ describe("voteOnSponsorTime", () => {
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-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]);
@@ -59,19 +59,38 @@ describe("voteOnSponsorTime", () => {
await db.prepare("run", insertWarningQuery, [warnUser02Hash, (now - (warningExpireTime + 2000)), warnVip01Hash, 1]);
await db.prepare("run", 'INSERT INTO "vipUsers" ("userID") VALUES (?)', [getHash("VIPUser")]);
await db.prepare("run", 'INSERT INTO "vipUsers" ("userID") VALUES (?)', [getHash(vipUser)]);
await db.prepare("run", 'INSERT INTO "shadowBannedUsers" ("userID") VALUES (?)', [getHash("randomID4")]);
await db.prepare("run", 'INSERT INTO "lockCategories" ("videoID", "userID", "category") VALUES (?, ?, ?)', ["no-sponsor-segments-video", "someUser", "sponsor"]);
});
// constants
const endpoint = `${getbaseURL()}/api/voteOnSponsorTime`;
const endpoint = "/api/voteOnSponsorTime";
const postVote = (userID: string, UUID: string, type: number) => client({
method: "POST",
url: endpoint,
params: {
userID,
UUID,
type
}
});
const postVoteCategory = (userID: string, UUID: string, category: string) => client({
method: "POST",
url: endpoint,
params: {
userID,
UUID,
category
}
});
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) => {
it("Should be able to upvote a segment", (done) => {
const UUID = "vote-uuid-0";
fetch(`${endpoint}?userID=randomID&UUID=${UUID}&type=1`)
postVote("randomID", UUID, 1)
.then(async res => {
assert.strictEqual(res.status, 200);
const row = await getSegmentVotes(UUID);
@@ -81,9 +100,9 @@ describe("voteOnSponsorTime", () => {
.catch(err => done(err));
});
it("Should be able to downvote a segment", (done: Done) => {
it("Should be able to downvote a segment", (done) => {
const UUID = "vote-uuid-2";
fetch(`${endpoint}?userID=randomID2&UUID=${UUID}&type=0`)
postVote(randomID2, UUID, 0)
.then(async res => {
assert.strictEqual(res.status, 200);
const row = await getSegmentVotes(UUID);
@@ -93,9 +112,9 @@ describe("voteOnSponsorTime", () => {
.catch(err => done(err));
});
it("Should not be able to downvote the same segment when voting from a different user on the same IP", (done: Done) => {
it("Should not be able to downvote the same segment when voting from a different user on the same IP", (done) => {
const UUID = "vote-uuid-2";
fetch(`${endpoint}?userID=randomID3&UUID=${UUID}&type=0`)
postVote("randomID3", UUID, 0)
.then(async res => {
assert.strictEqual(res.status, 200);
const row = await getSegmentVotes(UUID);
@@ -105,75 +124,81 @@ describe("voteOnSponsorTime", () => {
.catch(err => done(err));
});
it("Should not be able to downvote a segment if the user is shadow banned", (done: Done) => {
fetch(`${endpoint}?userID=randomID4&UUID=vote-uuid-1.6&type=0`)
it("Should not be able to downvote a segment if the user is shadow banned", (done) => {
const UUID = "vote-uuid-1.6";
postVote("randomID4", UUID, 0)
.then(async res => {
assert.strictEqual(res.status, 200);
const row = await getSegmentVotes("vote-uuid-1.6");
const row = await getSegmentVotes(UUID);
assert.strictEqual(row.votes, 10);
done();
})
.catch(err => done(err));
});
it("Should not be able to upvote a segment if the user hasn't submitted yet", (done: Done) => {
fetch(`${endpoint}?userID=hasNotSubmittedID&UUID=vote-uuid-1&type=1`)
it("Should not be able to upvote a segment if the user hasn't submitted yet", (done) => {
const UUID = "vote-uuid-1";
postVote("hasNotSubmittedID", UUID, 1)
.then(async res => {
assert.strictEqual(res.status, 200);
const row = await getSegmentVotes("vote-uuid-1");
const row = await getSegmentVotes(UUID);
assert.strictEqual(row.votes, 2);
done();
})
.catch(err => done(err));
});
it("Should not be able to downvote a segment if the user hasn't submitted yet", (done: Done) => {
fetch(`${endpoint}?userID=hasNotSubmittedID&UUID=vote-uuid-1.5&type=0`)
it("Should not be able to downvote a segment if the user hasn't submitted yet", (done) => {
const UUID = "vote-uuid-1.5";
postVote("hasNotSubmittedID", UUID, 0)
.then(async res => {
assert.strictEqual(res.status, 200);
const row = await getSegmentVotes("vote-uuid-1.5");
const row = await getSegmentVotes(UUID);
assert.strictEqual(row.votes, 10);
done();
})
.catch(err => done(err));
});
it("VIP should be able to completely downvote a segment", (done: Done) => {
fetch(`${endpoint}?userID=VIPUser&UUID=vote-uuid-3&type=0`)
it("VIP should be able to completely downvote a segment", (done) => {
const UUID = "vote-uuid-3";
postVote(vipUser, UUID, 0)
.then(async res => {
assert.strictEqual(res.status, 200);
const row = await getSegmentVotes("vote-uuid-3");
const row = await getSegmentVotes(UUID);
assert.ok(row.votes <= -2);
done();
})
.catch(err => done(err));
});
it("should be able to completely downvote your own segment", (done: Done) => {
fetch(`${endpoint}?userID=own-submission-id&UUID=own-submission-uuid&type=0`)
it("should be able to completely downvote your own segment", (done) => {
const UUID = "own-submission-uuid";
postVote("own-submission-id", UUID, 0)
.then(async res => {
assert.strictEqual(res.status, 200);
const row = await getSegmentVotes("own-submission-uuid");
const row = await getSegmentVotes(UUID);
assert.ok(row.votes <= -2);
done();
})
.catch(err => done(err));
});
it("should not be able to completely downvote somebody elses segment", (done: Done) => {
fetch(`${endpoint}?userID=randomID2&UUID=not-own-submission-uuid&type=0`)
it("should not be able to completely downvote somebody elses segment", (done) => {
const UUID = "not-own-submission-uuid";
postVote(randomID2, UUID, 0)
.then(async res => {
assert.strictEqual(res.status, 200);
const row = await getSegmentVotes("not-own-submission-uuid");
const row = await getSegmentVotes(UUID);
assert.strictEqual(row.votes, 499);
done();
})
.catch(err => done(err));
});
it("Should be able to vote for a category and it should add your vote to the database", (done: Done) => {
it("Should be able to vote for a category and it should add your vote to the database", (done) => {
const UUID = "vote-uuid-4";
fetch(`${endpoint}?userID=randomID2&UUID=${UUID}&category=intro`)
postVoteCategory(randomID2, UUID, "intro")
.then(async res => {
assert.strictEqual(res.status, 200);
const row = await getSegmentCategory(UUID);
@@ -189,9 +214,9 @@ describe("voteOnSponsorTime", () => {
.catch(err => done(err));
});
it("Should not able to change to an invalid category", (done: Done) => {
it("Should not able to change to an invalid category", (done) => {
const UUID = "incorrect-category";
fetch(`${endpoint}?userID=randomID2&UUID=${UUID}&category=fakecategory`)
postVoteCategory(randomID2, UUID, "fakecategory")
.then(async res => {
assert.strictEqual(res.status, 400);
const row = await getSegmentCategory(UUID);
@@ -201,9 +226,9 @@ describe("voteOnSponsorTime", () => {
.catch(err => done(err));
});
it("Should not able to change to highlight category", (done: Done) => {
it("Should not able to change to highlight category", (done) => {
const UUID = "incorrect-category";
fetch(`${endpoint}?userID=randomID2&UUID=${UUID}&category=highlight`)
postVoteCategory(randomID2, UUID, "highlight")
.then(async res => {
assert.strictEqual(res.status, 400);
const row = await getSegmentCategory(UUID);
@@ -213,39 +238,36 @@ describe("voteOnSponsorTime", () => {
.catch(err => done(err));
});
it("Should be able to change your vote for a category and it should add your vote to the database", (done: Done) => {
it("Should be able to change your vote for a category and it should add your vote to the database", (done) => {
const UUID = "vote-uuid-4";
fetch(`${endpoint}?userID=randomID2&UUID=${UUID}&category=outro`)
postVoteCategory(randomID2, UUID, "outro")
.then(async res => {
if (res.status === 200) {
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;
for (const row of categoryRows) {
if (row?.category === "intro") introVotes += row?.votes;
if (row?.category === "outro") outroVotes += row?.votes;
if (row?.category === "sponsor") sponsorVotes += row?.votes;
}
assert.strictEqual(submissionRow.category, "sponsor");
assert.strictEqual(categoryRows.length, 3);
assert.strictEqual(introVotes, 0);
assert.strictEqual(outroVotes, 1);
assert.strictEqual(sponsorVotes, 1);
done();
} else {
done(`Status code was ${res.status}`);
assert.strictEqual(res.status, 200, "Status code should be 200");
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;
for (const row of categoryRows) {
if (row?.category === "intro") introVotes += row?.votes;
if (row?.category === "outro") outroVotes += row?.votes;
if (row?.category === "sponsor") sponsorVotes += row?.votes;
}
assert.strictEqual(submissionRow.category, "sponsor");
assert.strictEqual(categoryRows.length, 3);
assert.strictEqual(introVotes, 0);
assert.strictEqual(outroVotes, 1);
assert.strictEqual(sponsorVotes, 1);
done();
})
.catch(err => done(err));
});
it("Should not be able to change your vote to an invalid category", (done: Done) => {
it("Should not be able to change your vote to an invalid category", (done) => {
const UUID = "incorrect-category-change";
const vote = (inputCat: string, assertCat: string, callback: Done) => {
fetch(`${endpoint}?userID=randomID2&UUID=${UUID}&category=${inputCat}`)
const vote = (inputCat: string, assertCat: string, callback: Mocha.Done) => {
postVoteCategory(randomID2, UUID, inputCat)
.then(async () => {
const row = await getSegmentCategory(UUID);
assert.strictEqual(row.category, assertCat);
@@ -259,9 +281,9 @@ describe("voteOnSponsorTime", () => {
});
it("VIP should be able to vote for a category and it should immediately change", (done: Done) => {
it("VIP should be able to vote for a category and it should immediately change", (done) => {
const UUID = "vote-uuid-5";
fetch(`${endpoint}?userID=VIPUser&UUID=${UUID}&category=outro`)
postVoteCategory(vipUser, UUID, "outro")
.then(async res => {
assert.strictEqual(res.status, 200);
const row = await getSegmentCategory(UUID);
@@ -273,9 +295,9 @@ describe("voteOnSponsorTime", () => {
.catch(err => done(err));
});
it("Submitter should be able to vote for a category and it should immediately change", (done: Done) => {
it("Submitter should be able to vote for a category and it should immediately change", (done) => {
const UUID = "vote-uuid-5_1";
fetch(`${endpoint}?userID=testman&UUID=${UUID}&category=outro`)
postVoteCategory("testman", UUID, "outro")
.then(async res => {
assert.strictEqual(res.status, 200);
const row = await getSegmentCategory("vote-uuid-5");
@@ -285,9 +307,9 @@ describe("voteOnSponsorTime", () => {
.catch(err => done(err));
});
it("Should not be able to category-vote on an invalid UUID submission", (done: Done) => {
it("Should not be able to category-vote on an invalid UUID submission", (done) => {
const UUID = "invalid-uuid";
fetch(`${endpoint}?userID=randomID3&UUID=${UUID}&category=intro`)
postVoteCategory("randomID3", UUID, "intro")
.then(async res => {
assert.strictEqual(res.status, 400);
done();
@@ -295,9 +317,9 @@ describe("voteOnSponsorTime", () => {
.catch(err => done(err));
});
it('Non-VIP should not be able to upvote "dead" submission', (done: Done) => {
it('Non-VIP should not be able to upvote "dead" submission', (done) => {
const UUID = "vote-uuid-5";
fetch(`${endpoint}?userID=randomID2&UUID=${UUID}&type=1`)
postVote(randomID2, UUID, 1)
.then(async res => {
assert.strictEqual(res.status, 403);
const row = await getSegmentVotes(UUID);
@@ -307,9 +329,9 @@ describe("voteOnSponsorTime", () => {
.catch(err => done(err));
});
it('Non-VIP should not be able to downvote "dead" submission', (done: Done) => {
it('Non-VIP should not be able to downvote "dead" submission', (done) => {
const UUID = "vote-uuid-5";
fetch(`${endpoint}?userID=randomID2&UUID=${UUID}&type=0`)
postVote(randomID2, UUID, 0)
.then(async res => {
assert.strictEqual(res.status, 200);
const row = await getSegmentVotes(UUID);
@@ -319,9 +341,9 @@ describe("voteOnSponsorTime", () => {
.catch(err => done(err));
});
it('VIP should be able to upvote "dead" submission', (done: Done) => {
it('VIP should be able to upvote "dead" submission', (done) => {
const UUID = "vote-uuid-5";
fetch(`${endpoint}?userID=VIPUser&UUID=${UUID}&type=1`)
postVote(vipUser, UUID, 1)
.then(async res => {
assert.strictEqual(res.status, 200);
const row = await getSegmentVotes(UUID);
@@ -331,9 +353,9 @@ describe("voteOnSponsorTime", () => {
.catch(err => done(err));
});
it("Should not be able to upvote a segment (Too many warning)", (done: Done) => {
it("Should not be able to upvote a segment (Too many warning)", (done) => {
const UUID = "warnvote-uuid-0";
fetch(`${endpoint}?userID=warn-voteuser01&UUID=${UUID}&type=1`)
postVote("warn-voteuser01", UUID, 1)
.then(async res => {
assert.strictEqual(res.status, 403);
done();
@@ -341,9 +363,9 @@ describe("voteOnSponsorTime", () => {
.catch(err => done(err));
});
it("Non-VIP should not be able to downvote on a segment with no-segments category", (done: Done) => {
it("Non-VIP should not be able to downvote on a segment with no-segments category", (done) => {
const UUID = "no-sponsor-segments-uuid-0";
fetch(`${endpoint}?userID=randomID&UUID=${UUID}&type=0`)
postVote("randomID", UUID, 0)
.then(async res => {
assert.strictEqual(res.status, 200);
const row = await getSegmentVotes(UUID);
@@ -353,9 +375,9 @@ describe("voteOnSponsorTime", () => {
.catch(err => done(err));
});
it("Non-VIP should be able to upvote on a segment with no-segments category", (done: Done) => {
it("Non-VIP should be able to upvote on a segment with no-segments category", (done) => {
const UUID = "no-sponsor-segments-uuid-0";
fetch(`${endpoint}?userID=randomID&UUID=${UUID}&type=1`)
postVote("randomID", UUID, 1)
.then(async res => {
assert.strictEqual(res.status, 200);
const row = await getSegmentVotes(UUID);
@@ -365,9 +387,9 @@ describe("voteOnSponsorTime", () => {
.catch(err => done(err));
});
it("Non-VIP should not be able to category vote on a segment with no-segments category", (done: Done) => {
it("Non-VIP should not be able to category vote on a segment with no-segments category", (done) => {
const UUID = "no-sponsor-segments-uuid-0";
fetch(`${endpoint}?userID=randomID&UUID=${UUID}&category=outro`)
postVoteCategory("randomID", UUID, "outro")
.then(async res => {
assert.strictEqual(res.status, 200);
const row = await getSegmentCategory(UUID);
@@ -377,9 +399,9 @@ describe("voteOnSponsorTime", () => {
.catch(err => done(err));
});
it("VIP upvote should lock segment", (done: Done) => {
it("VIP upvote should lock segment", (done) => {
const UUID = "segment-locking-uuid-1";
fetch(`${endpoint}?userID=VIPUser&UUID=${UUID}&type=1`)
postVote(vipUser, UUID, 1)
.then(async res => {
assert.strictEqual(res.status, 200);
const row = await db.prepare("get", `SELECT "locked" FROM "sponsorTimes" WHERE "UUID" = ?`, [UUID]);
@@ -389,9 +411,9 @@ describe("voteOnSponsorTime", () => {
.catch(err => done(err));
});
it("VIP downvote should unlock segment", (done: Done) => {
it("VIP downvote should unlock segment", (done) => {
const UUID = "segment-locking-uuid-1";
fetch(`${endpoint}?userID=VIPUser&UUID=${UUID}&type=0`)
postVote(vipUser, UUID, 0)
.then(async res => {
assert.strictEqual(res.status, 200);
const row = await db.prepare("get", `SELECT "locked" FROM "sponsorTimes" WHERE "UUID" = ?`, [UUID]);
@@ -401,9 +423,9 @@ describe("voteOnSponsorTime", () => {
.catch(err => done(err));
});
it("VIP upvote should unhide segment", (done: Done) => {
it("VIP upvote should unhide segment", (done) => {
const UUID = "segment-hidden-uuid-1";
fetch(`${endpoint}?userID=VIPUser&UUID=${UUID}&type=1`)
postVote(vipUser, UUID, 1)
.then(async res => {
assert.strictEqual(res.status, 200);
const row = await db.prepare("get", `SELECT "hidden" FROM "sponsorTimes" WHERE "UUID" = ?`, [UUID]);
@@ -413,9 +435,9 @@ describe("voteOnSponsorTime", () => {
.catch(err => done(err));
});
it("Should be able to undo-vote a segment", (done: Done) => {
it("Should be able to undo-vote a segment", (done) => {
const UUID = "vote-uuid-2";
fetch(`${endpoint}?userID=randomID2&UUID=${UUID}&type=20`)
postVote(randomID2, UUID, 20)
.then(async res => {
assert.strictEqual(res.status, 200);
const row = await getSegmentVotes(UUID);
@@ -425,9 +447,9 @@ describe("voteOnSponsorTime", () => {
.catch(err => done(err));
});
it("Should not be able to vote with type 10", (done: Done) => {
it("Should not be able to vote with type 10", (done) => {
const UUID = "segment-locking-uuid-1";
fetch(`${endpoint}?userID=VIPUser&UUID=${UUID}&type=10`)
postVote(vipUser, UUID, 10)
.then(res => {
assert.strictEqual(res.status, 400);
done();
@@ -435,9 +457,9 @@ describe("voteOnSponsorTime", () => {
.catch(err => done(err));
});
it("Should not be able to vote with type 11", (done: Done) => {
it("Should not be able to vote with type 11", (done) => {
const UUID = "segment-locking-uuid-1";
fetch(`${endpoint}?userID=VIPUser&UUID=${UUID}&type=11`)
postVote(vipUser, UUID, 11)
.then(res => {
assert.strictEqual(res.status, 400);
done();