postSkipSegments

This commit is contained in:
Michael C
2021-09-16 20:44:12 -04:00
parent 6e55f9d979
commit 870ade6fa9
2 changed files with 236 additions and 264 deletions

View File

@@ -1,7 +1,7 @@
import fetch from "node-fetch"; import fetch from "node-fetch";
import {config} from "../../src/config"; import {config} from "../../src/config";
import {getHash} from "../../src/utils/getHash"; import {getHash} from "../../src/utils/getHash";
import {Done, getbaseURL, partialDeepEquals} from "../utils"; import {Done, getbaseURL, partialDeepEquals, postJSON} from "../utils";
import {db} from "../../src/databases/databases"; import {db} from "../../src/databases/databases";
import {ImportMock} from "ts-mock-imports"; import {ImportMock} from "ts-mock-imports";
import * as YouTubeAPIModule from "../../src/utils/youtubeApi"; import * as YouTubeAPIModule from "../../src/utils/youtubeApi";
@@ -12,19 +12,40 @@ const mockManager = ImportMock.mockStaticClass(YouTubeAPIModule, "YouTubeAPI");
const sinonStub = mockManager.mock("listVideos"); const sinonStub = mockManager.mock("listVideos");
sinonStub.callsFake(YouTubeApiMock.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", () => { describe("postSkipSegments", () => {
before(() => { before(() => {
const insertSponsorTimeQuery = 'INSERT INTO "sponsorTimes" ("videoID", "startTime", "endTime", "votes", "UUID", "userID", "timeSubmitted", views, category, "shadowHidden", "hashedVideoID") VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)'; 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", getHash("testtesttesttesttesttesttesttesttest"), 0, 0, "interaction", 0, "80percent_video"]); db.prepare("run", insertSponsorTimeQuery, ["80percent_video", 0, 1000, 0, "80percent-uuid-0", submitUserOneHash, 0, 0, "interaction", 0, "80percent_video"]);
db.prepare("run", insertSponsorTimeQuery, ["80percent_video", 1001, 1005, 0, "80percent-uuid-1", getHash("testtesttesttesttesttesttesttesttest"), 0, 0, "interaction", 0, "80percent_video"]); db.prepare("run", insertSponsorTimeQuery, ["80percent_video", 1001, 1005, 0, "80percent-uuid-1", submitUserOneHash, 0, 0, "interaction", 0, "80percent_video"]);
db.prepare("run", insertSponsorTimeQuery, ["80percent_video", 0, 5000, -2, "80percent-uuid-2", getHash("testtesttesttesttesttesttesttesttest"), 0, 0, "interaction", 0, "80percent_video"]); db.prepare("run", insertSponsorTimeQuery, ["80percent_video", 0, 5000, -2, "80percent-uuid-2", submitUserOneHash, 0, 0, "interaction", 0, "80percent_video"]);
const now = Date.now(); const now = Date.now();
const warnVip01Hash = getHash("warn-vip01-qwertyuiopasdfghjklzxcvbnm"); const warnVip01Hash = getHash("warn-vip01-qwertyuiopasdfghjklzxcvbnm");
const warnUser01Hash = getHash("warn-user01-qwertyuiopasdfghjklzxcvbnm");
const warnUser02Hash = getHash("warn-user02-qwertyuiopasdfghjklzxcvbnm");
const warnUser03Hash = getHash("warn-user03-qwertyuiopasdfghjklzxcvbnm");
const warnUser04Hash = getHash("warn-user04-qwertyuiopasdfghjklzxcvbnm");
const reason01 = "Reason01"; const reason01 = "Reason01";
const reason02 = ""; const reason02 = "";
const reason03 = "Reason03"; const reason03 = "Reason03";
@@ -32,39 +53,40 @@ describe("postSkipSegments", () => {
const MILLISECONDS_IN_HOUR = 3600000; const MILLISECONDS_IN_HOUR = 3600000;
const warningExpireTime = MILLISECONDS_IN_HOUR * config.hoursAfterWarningExpires; const warningExpireTime = MILLISECONDS_IN_HOUR * config.hoursAfterWarningExpires;
const insertWarningQuery = 'INSERT INTO warnings ("userID", "issueTime", "issuerUserID", "enabled", "reason") VALUES(?, ?, ?, ?, ?)'; const insertWarningQuery = 'INSERT INTO warnings ("userID", "issuerUserID", "enabled", "reason", issueTime) VALUES(?, ?, ?, ?, ?)';
db.prepare("run", insertWarningQuery, [warnUser01Hash, now, warnVip01Hash, 1, reason01]); // User 1
db.prepare("run", insertWarningQuery, [warnUser01Hash, (now - 1000), warnVip01Hash, 1, reason01]); db.prepare("run", insertWarningQuery, [warnUser01Hash, warnVip01Hash, 1, reason01, now]);
db.prepare("run", insertWarningQuery, [warnUser01Hash, (now - 2000), warnVip01Hash, 1, reason01]); db.prepare("run", insertWarningQuery, [warnUser01Hash, warnVip01Hash, 1, reason01, (now - 1000)]);
db.prepare("run", insertWarningQuery, [warnUser01Hash, (now - 3601000), warnVip01Hash, 1, reason01]); db.prepare("run", insertWarningQuery, [warnUser01Hash, warnVip01Hash, 1, reason01, (now - 2000)]);
db.prepare("run", insertWarningQuery, [warnUser02Hash, now, warnVip01Hash, 1, reason02]); db.prepare("run", insertWarningQuery, [warnUser01Hash, warnVip01Hash, 1, reason01, (now - 3601000)]);
db.prepare("run", insertWarningQuery, [warnUser02Hash, now, warnVip01Hash, 1, reason02]); // User 2
db.prepare("run", insertWarningQuery, [warnUser02Hash, (now - (warningExpireTime + 1000)), warnVip01Hash, 1, reason02]); db.prepare("run", insertWarningQuery, [warnUser02Hash, warnVip01Hash, 1, reason02, now]);
db.prepare("run", insertWarningQuery, [warnUser02Hash, (now - (warningExpireTime + 2000)), warnVip01Hash, 1, reason02]); db.prepare("run", insertWarningQuery, [warnUser02Hash, warnVip01Hash, 1, reason02, now]);
db.prepare("run", insertWarningQuery, [warnUser03Hash, now, warnVip01Hash, 0, reason03]); db.prepare("run", insertWarningQuery, [warnUser02Hash, warnVip01Hash, 1, reason02, (now - (warningExpireTime + 1000))]);
db.prepare("run", insertWarningQuery, [warnUser03Hash, (now - 1000), warnVip01Hash, 0, reason03]); db.prepare("run", insertWarningQuery, [warnUser02Hash, warnVip01Hash, 1, reason02, (now - (warningExpireTime + 2000))]);
db.prepare("run", insertWarningQuery, [warnUser03Hash, (now - 2000), warnVip01Hash, 1, reason03]); // User 3
db.prepare("run", insertWarningQuery, [warnUser03Hash, (now - 3601000), warnVip01Hash, 1, reason03]); db.prepare("run", insertWarningQuery, [warnUser03Hash, warnVip01Hash, 0, reason03, now]);
db.prepare("run", insertWarningQuery, [warnUser04Hash, now, warnVip01Hash, 0, reason04]); db.prepare("run", insertWarningQuery, [warnUser03Hash, warnVip01Hash, 0, reason03, (now - 1000)]);
db.prepare("run", insertWarningQuery, [warnUser04Hash, (now - 1000), warnVip01Hash, 0, reason04]); db.prepare("run", insertWarningQuery, [warnUser03Hash, warnVip01Hash, 1, reason03, (now - 2000)]);
db.prepare("run", insertWarningQuery, [warnUser04Hash, (now - 2000), warnVip01Hash, 1, reason04]); db.prepare("run", insertWarningQuery, [warnUser03Hash, warnVip01Hash, 1, reason03, (now - 3601000)]);
db.prepare("run", insertWarningQuery, [warnUser04Hash, (now - 3601000), warnVip01Hash, 1, reason04]); // User 4
db.prepare("run", insertWarningQuery, [warnUser04Hash, warnVip01Hash, 0, reason04, now]);
db.prepare("run", insertWarningQuery, [warnUser04Hash, warnVip01Hash, 0, reason04, (now - 1000)]);
db.prepare("run", insertWarningQuery, [warnUser04Hash, warnVip01Hash, 1, reason04, (now - 2000)]);
db.prepare("run", insertWarningQuery, [warnUser04Hash, warnVip01Hash, 1, reason04, (now - 3601000)]);
const insertVipUserQuery = 'INSERT INTO "vipUsers" ("userID") VALUES (?)'; const insertVipUserQuery = 'INSERT INTO "vipUsers" ("userID") VALUES (?)';
db.prepare("run", insertVipUserQuery, [getHash("VIPUserSubmissionVIPUserSubmissionVIPUserSubmission")]); db.prepare("run", insertVipUserQuery, [getHash(submitVIPuser)]);
}); });
it("Should be able to submit a single time (Params method)", (done: Done) => { it("Should be able to submit a single time (Params method)", (done: Done) => {
fetch(`${getbaseURL() const videoID = "dQw4w9WgXcR";
}/api/postVideoSponsorTimes?videoID=dQw4w9WgXcR&startTime=2&endTime=10&userID=testtesttesttesttesttesttesttesttest&category=sponsor`, { fetch(`${endpoint}?videoID=${videoID}&startTime=2&endTime=10&userID=${submitUserOne}&category=sponsor`, {
method: "POST", method: "POST"
headers: {
"Content-Type": "application/json",
},
}) })
.then(async res => { .then(async res => {
assert.strictEqual(res.status, 200); assert.strictEqual(res.status, 200);
const row = await db.prepare("get", `SELECT "startTime", "endTime", "category" FROM "sponsorTimes" WHERE "videoID" = ?`, ["dQw4w9WgXcR"]); const row = await queryDatabase(videoID);
const expected = { const expected = {
startTime: 2, startTime: 2,
endTime: 10, endTime: 10,
@@ -77,14 +99,12 @@ describe("postSkipSegments", () => {
}); });
it("Should be able to submit a single time (JSON method)", (done: Done) => { it("Should be able to submit a single time (JSON method)", (done: Done) => {
fetch(`${getbaseURL()}/api/postVideoSponsorTimes`, { const videoID = "dQw4w9WgXcF";
method: "POST", fetch(endpoint, {
headers: { ...postJSON,
"Content-Type": "application/json",
},
body: JSON.stringify({ body: JSON.stringify({
userID: "testtesttesttesttesttesttesttesttest", userID: submitUserOne,
videoID: "dQw4w9WgXcF", videoID,
segments: [{ segments: [{
segment: [0, 10], segment: [0, 10],
category: "sponsor", category: "sponsor",
@@ -93,7 +113,7 @@ describe("postSkipSegments", () => {
}) })
.then(async res => { .then(async res => {
assert.strictEqual(res.status, 200); assert.strictEqual(res.status, 200);
const row = await db.prepare("get", `SELECT "startTime", "endTime", "locked", "category" FROM "sponsorTimes" WHERE "videoID" = ?`, ["dQw4w9WgXcF"]); const row = await queryDatabase(videoID);
const expected = { const expected = {
startTime: 0, startTime: 0,
endTime: 10, endTime: 10,
@@ -107,14 +127,12 @@ describe("postSkipSegments", () => {
}); });
it("Should be able to submit a single time with an action type (JSON method)", (done: Done) => { it("Should be able to submit a single time with an action type (JSON method)", (done: Done) => {
fetch(`${getbaseURL()}/api/postVideoSponsorTimes`, { const videoID = "dQw4w9WgXcV";
method: "POST", fetch(endpoint, {
headers: { ...postJSON,
"Content-Type": "application/json",
},
body: JSON.stringify({ body: JSON.stringify({
userID: "testtesttesttesttesttesttesttesttest", userID: submitUserOne,
videoID: "dQw4w9WgXcV", videoID,
segments: [{ segments: [{
segment: [0, 10], segment: [0, 10],
category: "sponsor", category: "sponsor",
@@ -124,7 +142,7 @@ describe("postSkipSegments", () => {
}) })
.then(async res => { .then(async res => {
assert.strictEqual(res.status, 200); assert.strictEqual(res.status, 200);
const row = await db.prepare("get", `SELECT "startTime", "endTime", "locked", "category", "actionType" FROM "sponsorTimes" WHERE "videoID" = ?`, ["dQw4w9WgXcV"]); const row = await queryDatabaseActionType(videoID);
const expected = { const expected = {
startTime: 0, startTime: 0,
endTime: 10, endTime: 10,
@@ -138,14 +156,12 @@ describe("postSkipSegments", () => {
}); });
it("Should not be able to submit an intro with mute action type (JSON method)", (done: Done) => { it("Should not be able to submit an intro with mute action type (JSON method)", (done: Done) => {
fetch(`${getbaseURL()}/api/postVideoSponsorTimes`, { const videoID = "dQw4w9WgXpQ";
method: "POST", fetch(endpoint, {
headers: { ...postJSON,
"Content-Type": "application/json",
},
body: JSON.stringify({ body: JSON.stringify({
userID: "testtesttesttesttesttesttesttesttest", userID: submitUserOne,
videoID: "dQw4w9WgXpQ", videoID,
segments: [{ segments: [{
segment: [0, 10], segment: [0, 10],
category: "intro", category: "intro",
@@ -155,7 +171,7 @@ describe("postSkipSegments", () => {
}) })
.then(async res => { .then(async res => {
assert.strictEqual(res.status, 400); assert.strictEqual(res.status, 400);
const row = await db.prepare("get", `SELECT "startTime", "endTime", "locked", "category", "actionType" FROM "sponsorTimes" WHERE "videoID" = ?`, ["dQw4w9WgXpQ"]); const row = await queryDatabaseActionType(videoID);
assert.strictEqual(row, undefined); assert.strictEqual(row, undefined);
done(); done();
}) })
@@ -163,14 +179,12 @@ describe("postSkipSegments", () => {
}); });
it("Should be able to submit a single time with a duration from the YouTube API (JSON method)", (done: Done) => { it("Should be able to submit a single time with a duration from the YouTube API (JSON method)", (done: Done) => {
fetch(`${getbaseURL()}/api/postVideoSponsorTimes`, { const videoID = "dQw4w9WgXZX";
method: "POST", fetch(endpoint, {
headers: { ...postJSON,
"Content-Type": "application/json",
},
body: JSON.stringify({ body: JSON.stringify({
userID: "testtesttesttesttesttesttesttesttest", userID: submitUserOne,
videoID: "dQw4w9WgXZX", videoID,
videoDuration: 100, videoDuration: 100,
segments: [{ segments: [{
segment: [0, 10], segment: [0, 10],
@@ -180,7 +194,7 @@ describe("postSkipSegments", () => {
}) })
.then(async res => { .then(async res => {
assert.strictEqual(res.status, 200); assert.strictEqual(res.status, 200);
const row = await db.prepare("get", `SELECT "startTime", "endTime", "locked", "category", "videoDuration" FROM "sponsorTimes" WHERE "videoID" = ?`, ["dQw4w9WgXZX"]); const row = await queryDatabaseDuration(videoID);
const expected = { const expected = {
startTime: 0, startTime: 0,
endTime: 10, endTime: 10,
@@ -194,14 +208,12 @@ describe("postSkipSegments", () => {
}); });
it("Should be able to submit a single time with a precise duration close to the one from the YouTube API (JSON method)", (done: Done) => { it("Should be able to submit a single time with a precise duration close to the one from the YouTube API (JSON method)", (done: Done) => {
fetch(`${getbaseURL()}/api/postVideoSponsorTimes`, { const videoID = "dQw4w9WgXZH";
method: "POST", fetch(endpoint, {
headers: { ...postJSON,
"Content-Type": "application/json",
},
body: JSON.stringify({ body: JSON.stringify({
userID: "testtesttesttesttesttesttesttesttest", userID: submitUserOne,
videoID: "dQw4w9WgXZH", videoID,
videoDuration: 4980.20, videoDuration: 4980.20,
segments: [{ segments: [{
segment: [1, 10], segment: [1, 10],
@@ -211,7 +223,7 @@ describe("postSkipSegments", () => {
}) })
.then(async res => { .then(async res => {
assert.strictEqual(res.status, 200); assert.strictEqual(res.status, 200);
const row = await db.prepare("get", `SELECT "startTime", "endTime", "locked", "category", "videoDuration" FROM "sponsorTimes" WHERE "videoID" = ?`, ["dQw4w9WgXZH"]); const row = await queryDatabaseDuration(videoID);
const expected = { const expected = {
startTime: 1, startTime: 1,
endTime: 10, endTime: 10,
@@ -226,14 +238,12 @@ describe("postSkipSegments", () => {
}); });
it("Should be able to submit a single time with a duration in the body (JSON method)", (done: Done) => { it("Should be able to submit a single time with a duration in the body (JSON method)", (done: Done) => {
fetch(`${getbaseURL()}/api/postVideoSponsorTimes`, { const videoID = "noDuration";
method: "POST", fetch(endpoint, {
headers: { ...postJSON,
"Content-Type": "application/json",
},
body: JSON.stringify({ body: JSON.stringify({
userID: "testtesttesttesttesttesttesttesttest", userID: submitUserOne,
videoID: "noDuration", videoID,
videoDuration: 100, videoDuration: 100,
segments: [{ segments: [{
segment: [0, 10], segment: [0, 10],
@@ -243,7 +253,7 @@ describe("postSkipSegments", () => {
}) })
.then(async res => { .then(async res => {
assert.strictEqual(res.status, 200); assert.strictEqual(res.status, 200);
const row = await db.prepare("get", `SELECT "startTime", "endTime", "locked", "category", "videoDuration" FROM "sponsorTimes" WHERE "videoID" = ?`, ["noDuration"]); const row = await queryDatabaseDuration(videoID);
const expected = { const expected = {
startTime: 0, startTime: 0,
endTime: 10, endTime: 10,
@@ -258,18 +268,16 @@ describe("postSkipSegments", () => {
}); });
it("Should be able to submit with a new duration, and hide old submissions and remove segment locks", async () => { it("Should be able to submit with a new duration, and hide old submissions and remove segment locks", async () => {
const videoID = "noDuration";
await db.prepare("run", `INSERT INTO "lockCategories" ("userID", "videoID", "category") await db.prepare("run", `INSERT INTO "lockCategories" ("userID", "videoID", "category")
VALUES(?, ?, ?)`, [getHash("VIPUser-lockCategories"), "noDuration", "sponsor"]); VALUES(?, ?, ?)`, [getHash("VIPUser-lockCategories"), videoID, "sponsor"]);
try { try {
const res = await fetch(`${getbaseURL()}/api/postVideoSponsorTimes`, { const res = await fetch(endpoint, {
method: "POST", ...postJSON,
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({ body: JSON.stringify({
userID: "testtesttesttesttesttesttesttesttest", userID: submitUserOne,
videoID: "noDuration", videoID,
videoDuration: 100, videoDuration: 100,
segments: [{ segments: [{
segment: [1, 10], segment: [1, 10],
@@ -278,11 +286,11 @@ describe("postSkipSegments", () => {
}), }),
}); });
assert.strictEqual(res.status, 200); assert.strictEqual(res.status, 200);
const lockCategoriesRow = await db.prepare("get", `SELECT * from "lockCategories" WHERE videoID = ?`, ["noDuration"]); const lockCategoriesRow = await db.prepare("get", `SELECT * from "lockCategories" WHERE videoID = ?`, [videoID]);
const videoRows = await db.prepare("all", `SELECT "startTime", "endTime", "locked", "category", "videoDuration" const videoRows = await db.prepare("all", `SELECT "startTime", "endTime", "locked", "category", "videoDuration"
FROM "sponsorTimes" WHERE "videoID" = ? AND hidden = 0`, ["noDuration"]); FROM "sponsorTimes" WHERE "videoID" = ? AND hidden = 0`, [videoID]);
const hiddenVideoRows = await db.prepare("all", `SELECT "startTime", "endTime", "locked", "category", "videoDuration" const hiddenVideoRows = await db.prepare("all", `SELECT "startTime", "endTime", "locked", "category", "videoDuration"
FROM "sponsorTimes" WHERE "videoID" = ? AND hidden = 1`, ["noDuration"]); FROM "sponsorTimes" WHERE "videoID" = ? AND hidden = 1`, [videoID]);
assert.ok(!lockCategoriesRow); assert.ok(!lockCategoriesRow);
const expected = { const expected = {
startTime: 1, startTime: 1,
@@ -300,8 +308,8 @@ describe("postSkipSegments", () => {
}); });
it("Should still not be allowed if youtube thinks duration is 0", (done: Done) => { it("Should still not be allowed if youtube thinks duration is 0", (done: Done) => {
fetch(`${getbaseURL() const videoID= "noDuration";
}/api/postVideoSponsorTimes?videoID=noDuration&startTime=30&endTime=10000&userID=testtesttesttesttesttesttesttesttesting`, { fetch(`${endpoint}?videoID=${videoID}&startTime=30&endTime=10000&userID=${submitUserThree}&category=sponsor`, {
method: "POST", method: "POST",
}) })
.then(async res => { .then(async res => {
@@ -312,14 +320,12 @@ describe("postSkipSegments", () => {
}); });
it("Should be able to submit a single time under a different service (JSON method)", (done: Done) => { it("Should be able to submit a single time under a different service (JSON method)", (done: Done) => {
fetch(`${getbaseURL()}/api/postVideoSponsorTimes`, { const videoID = "dQw4w9WgXcG";
method: "POST", fetch(endpoint, {
headers: { ...postJSON,
"Content-Type": "application/json",
},
body: JSON.stringify({ body: JSON.stringify({
userID: "testtesttesttesttesttesttesttesttest", userID: submitUserOne,
videoID: "dQw4w9WgXcG", videoID,
service: "PeerTube", service: "PeerTube",
segments: [{ segments: [{
segment: [0, 10], segment: [0, 10],
@@ -329,7 +335,7 @@ describe("postSkipSegments", () => {
}) })
.then(async res => { .then(async res => {
assert.strictEqual(res.status, 200); assert.strictEqual(res.status, 200);
const row = await db.prepare("get", `SELECT "startTime", "endTime", "locked", "category", "service" FROM "sponsorTimes" WHERE "videoID" = ?`, ["dQw4w9WgXcG"]); const row = await db.prepare("get", `SELECT "startTime", "endTime", "locked", "category", "service" FROM "sponsorTimes" WHERE "videoID" = ?`, [videoID]);
const expected = { const expected = {
startTime: 0, startTime: 0,
endTime: 10, endTime: 10,
@@ -344,14 +350,12 @@ describe("postSkipSegments", () => {
}); });
it("VIP submission should start locked", (done: Done) => { it("VIP submission should start locked", (done: Done) => {
fetch(`${getbaseURL()}/api/postVideoSponsorTimes`, { const videoID = "vipuserIDSubmission";
method: "POST", fetch(endpoint, {
headers: { ...postJSON,
"Content-Type": "application/json",
},
body: JSON.stringify({ body: JSON.stringify({
userID: "VIPUserSubmissionVIPUserSubmissionVIPUserSubmission", userID: submitVIPuser,
videoID: "vipuserIDSubmission", videoID,
segments: [{ segments: [{
segment: [0, 10], segment: [0, 10],
category: "sponsor", category: "sponsor",
@@ -360,7 +364,7 @@ describe("postSkipSegments", () => {
}) })
.then(async res => { .then(async res => {
assert.strictEqual(res.status, 200); assert.strictEqual(res.status, 200);
const row = await db.prepare("get", `SELECT "startTime", "endTime", "locked", "category" FROM "sponsorTimes" WHERE "videoID" = ?`, ["vipuserIDSubmission"]); const row = await queryDatabase(videoID);
const expected = { const expected = {
startTime: 0, startTime: 0,
endTime: 10, endTime: 10,
@@ -374,14 +378,12 @@ describe("postSkipSegments", () => {
}); });
it("Should be able to submit multiple times (JSON method)", (done: Done) => { it("Should be able to submit multiple times (JSON method)", (done: Done) => {
fetch(`${getbaseURL()}/api/postVideoSponsorTimes`, { const videoID = "dQw4w9WgXcT";
method: "POST", fetch(endpoint, {
headers: { ...postJSON,
"Content-Type": "application/json",
},
body: JSON.stringify({ body: JSON.stringify({
userID: "testtesttesttesttesttesttesttesttest", userID: submitUserOne,
videoID: "dQw4w9WgXcT", videoID,
segments: [{ segments: [{
segment: [3, 10], segment: [3, 10],
category: "sponsor", category: "sponsor",
@@ -393,7 +395,7 @@ describe("postSkipSegments", () => {
}) })
.then(async res => { .then(async res => {
assert.strictEqual(res.status, 200); assert.strictEqual(res.status, 200);
const rows = await db.prepare("all", `SELECT "startTime", "endTime", "category" FROM "sponsorTimes" WHERE "videoID" = ?`, ["dQw4w9WgXcT"]); const rows = await db.prepare("all", `SELECT "startTime", "endTime", "category" FROM "sponsorTimes" WHERE "videoID" = ?`, [videoID]);
const expected = [{ const expected = [{
startTime: 3, startTime: 3,
endTime: 10, endTime: 10,
@@ -410,14 +412,12 @@ describe("postSkipSegments", () => {
}).timeout(5000); }).timeout(5000);
it("Should allow multiple times if total is under 80% of video(JSON method)", (done: Done) => { it("Should allow multiple times if total is under 80% of video(JSON method)", (done: Done) => {
fetch(`${getbaseURL()}/api/postVideoSponsorTimes`, { const videoID = "L_jWHffIx5E";
method: "POST", fetch(endpoint, {
headers: { ...postJSON,
"Content-Type": "application/json",
},
body: JSON.stringify({ body: JSON.stringify({
userID: "testtesttesttesttesttesttesttesttest", userID: submitUserOne,
videoID: "L_jWHffIx5E", videoID,
segments: [{ segments: [{
segment: [3, 3000], segment: [3, 3000],
category: "sponsor", category: "sponsor",
@@ -435,7 +435,7 @@ describe("postSkipSegments", () => {
}) })
.then(async res => { .then(async res => {
assert.strictEqual(res.status, 200); assert.strictEqual(res.status, 200);
const rows = await db.prepare("all", `SELECT "startTime", "endTime", "category" FROM "sponsorTimes" WHERE "videoID" = ? and "votes" > -1`, ["L_jWHffIx5E"]); const rows = await db.prepare("all", `SELECT "startTime", "endTime", "category" FROM "sponsorTimes" WHERE "videoID" = ? and "votes" > -1`, [videoID]);
const expected = [{ const expected = [{
startTime: 3, startTime: 3,
endTime: 3000, endTime: 3000,
@@ -460,14 +460,12 @@ describe("postSkipSegments", () => {
}).timeout(5000); }).timeout(5000);
it("Should reject multiple times if total is over 80% of video (JSON method)", (done: Done) => { it("Should reject multiple times if total is over 80% of video (JSON method)", (done: Done) => {
fetch(`${getbaseURL()}/api/postVideoSponsorTimes`, { const videoID = "n9rIGdXnSJc";
method: "POST", fetch(endpoint, {
headers: { ...postJSON,
"Content-Type": "application/json",
},
body: JSON.stringify({ body: JSON.stringify({
userID: "testtesttesttesttesttesttesttesttest", userID: submitUserOne,
videoID: "n9rIGdXnSJc", videoID,
segments: [{ segments: [{
segment: [0, 2000], segment: [0, 2000],
category: "interaction", category: "interaction",
@@ -485,7 +483,7 @@ describe("postSkipSegments", () => {
}) })
.then(async res => { .then(async res => {
assert.strictEqual(res.status, 403); assert.strictEqual(res.status, 403);
const rows = await db.prepare("all", `SELECT "startTime", "endTime", "category" FROM "sponsorTimes" WHERE "videoID" = ? and "votes" > -1`, ["n9rIGdXnSJc"]); const rows = await db.prepare("all", `SELECT "startTime", "endTime", "category" FROM "sponsorTimes" WHERE "videoID" = ? and "votes" > -1`, [videoID]);
assert.deepStrictEqual(rows, []); assert.deepStrictEqual(rows, []);
done(); done();
}) })
@@ -493,14 +491,12 @@ describe("postSkipSegments", () => {
}).timeout(5000); }).timeout(5000);
it("Should reject multiple times if total is over 80% of video including previosuly submitted times(JSON method)", (done: Done) => { it("Should reject multiple times if total is over 80% of video including previosuly submitted times(JSON method)", (done: Done) => {
fetch(`${getbaseURL()}/api/postVideoSponsorTimes`, { const videoID = "80percent_video";
method: "POST", fetch(endpoint, {
headers: { ...postJSON,
"Content-Type": "application/json",
},
body: JSON.stringify({ body: JSON.stringify({
userID: "testtesttesttesttesttesttesttesttest", userID: submitUserOne,
videoID: "80percent_video", videoID,
segments: [{ segments: [{
segment: [2000, 4000], segment: [2000, 4000],
category: "sponsor", category: "sponsor",
@@ -528,7 +524,7 @@ describe("postSkipSegments", () => {
startTime: 4050, startTime: 4050,
endTime: 4750 endTime: 4750
}]; }];
const rows = await db.prepare("all", `SELECT "startTime", "endTime", "category" FROM "sponsorTimes" WHERE "videoID" = ? and "votes" > -1`, ["80percent_video"]); const rows = await queryDatabase(videoID);
assert.notDeepStrictEqual(rows, expected); assert.notDeepStrictEqual(rows, expected);
done(); done();
}) })
@@ -536,8 +532,8 @@ describe("postSkipSegments", () => {
}).timeout(5000); }).timeout(5000);
it("Should be accepted if a non-sponsor is less than 1 second", (done: Done) => { it("Should be accepted if a non-sponsor is less than 1 second", (done: Done) => {
fetch(`${getbaseURL() const videoID = "qqwerty";
}/api/skipSegments?videoID=qqwerty&startTime=30&endTime=30.5&userID=testtesttesttesttesttesttesttesttesting&category=intro`, { fetch(`${endpoint}?videoID=${videoID}&startTime=30&endTime=30.5&userID=${submitUserTwo}&category=intro`, {
method: "POST", method: "POST",
}) })
.then(res => { .then(res => {
@@ -548,8 +544,8 @@ describe("postSkipSegments", () => {
}); });
it("Should be rejected if segment starts and ends at the same time", (done: Done) => { it("Should be rejected if segment starts and ends at the same time", (done: Done) => {
fetch(`${getbaseURL() const videoID = "qqwerty";
}/api/skipSegments?videoID=qqwerty&startTime=90&endTime=90&userID=testtesttesttesttesttesttesttesttesting&category=intro`, { fetch(`${endpoint}?videoID=${videoID}&startTime=90&endTime=90&userID=${submitUserTwo}&category=intro`, {
method: "POST", method: "POST",
}) })
.then(res => { .then(res => {
@@ -560,8 +556,8 @@ describe("postSkipSegments", () => {
}); });
it("Should be accepted if highlight segment starts and ends at the same time", (done: Done) => { it("Should be accepted if highlight segment starts and ends at the same time", (done: Done) => {
fetch(`${getbaseURL() const videoID = "qqwerty";
}/api/skipSegments?videoID=qqwerty&startTime=30&endTime=30&userID=testtesttesttesttesttesttesttesttesting&category=poi_highlight`, { fetch(`${endpoint}?videoID=${videoID}&startTime=30&endTime=30&userID=${submitUserTwo}&category=poi_highlight`, {
method: "POST", method: "POST",
}) })
.then(res => { .then(res => {
@@ -572,8 +568,8 @@ describe("postSkipSegments", () => {
}); });
it("Should be rejected if highlight segment doesn't start and end at the same time", (done: Done) => { it("Should be rejected if highlight segment doesn't start and end at the same time", (done: Done) => {
fetch(`${getbaseURL() const videoID = "qqwerty";
}/api/skipSegments?videoID=qqwerty&startTime=30&endTime=30.5&userID=testtesttesttesttesttesttesttesttesting&category=poi_highlight`, { fetch(`${endpoint}?videoID=${videoID}&startTime=30&endTime=30.5&userID=${submitUserTwo}&category=poi_highlight`, {
method: "POST", method: "POST",
}) })
.then(res => { .then(res => {
@@ -584,8 +580,8 @@ describe("postSkipSegments", () => {
}); });
it("Should be rejected if a sponsor is less than 1 second", (done: Done) => { it("Should be rejected if a sponsor is less than 1 second", (done: Done) => {
fetch(`${getbaseURL() const videoID = "qqwerty";
}/api/skipSegments?videoID=qqwerty&startTime=30&endTime=30.5&userID=testtesttesttesttesttesttesttesttesting`, { fetch(`${endpoint}?videoID=${videoID}&startTime=30&endTime=30.5&userID=${submitUserTwo}`, {
method: "POST", method: "POST",
}) })
.then(res => { .then(res => {
@@ -596,34 +592,37 @@ describe("postSkipSegments", () => {
}); });
it("Should be rejected if over 80% of the video", (done: Done) => { it("Should be rejected if over 80% of the video", (done: Done) => {
fetch(`${getbaseURL() const videoID = "qqwerty";
}/api/postVideoSponsorTimes?videoID=qqwerty&startTime=30&endTime=1000000&userID=testtesttesttesttesttesttesttesttesting`) fetch(`${endpoint}?videoID=${videoID}&startTime=30&endTime=1000000&userID=${submitUserTwo}&category=sponsor`, {
.then(res => { method: "POST",
})
.then( async res => {
assert.strictEqual(res.status, 403); assert.strictEqual(res.status, 403);
console.log(res.text());
done(); done();
}) })
.catch(err => done(err)); .catch(err => done(err));
}); });
it("Should be rejected if NB's predicted probability is <70%.", (done: Done) => { it("Should be rejected if NB's predicted probability is <70%.", (done: Done) => {
fetch(`${getbaseURL() const videoID = "LevkAjUE6d4";
}/api/postVideoSponsorTimes?videoID=LevkAjUE6d4&startTime=40&endTime=60&userID=testtesttesttesttesttesttesttesttesting`) fetch(`${endpoint}?videoID=${videoID}&startTime=40&endTime=60&userID=${submitUserTwo}&category=sponsor`, {
.then(res => { method: "POST",
})
.then(async res => {
assert.strictEqual(res.status, 200); assert.strictEqual(res.status, 200);
console.log(res.text());
done(); done();
}) })
.catch(err => done(err)); .catch(err => done(err));
}); });
it("Should be rejected with custom message if user has to many active warnings", (done: Done) => { it("Should be rejected with custom message if user has to many active warnings", (done: Done) => {
fetch(`${getbaseURL()}/api/postVideoSponsorTimes`, { fetch(endpoint, {
method: "POST", ...postJSON,
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({ body: JSON.stringify({
userID: "warn-user01-qwertyuiopasdfghjklzxcvbnm", userID: warnUser01,
videoID: "dQw4w9WgXcF", videoID: warnVideoID,
segments: [{ segments: [{
segment: [0, 10], segment: [0, 10],
category: "sponsor", category: "sponsor",
@@ -634,11 +633,10 @@ describe("postSkipSegments", () => {
assert.strictEqual(res.status, 403); assert.strictEqual(res.status, 403);
const errorMessage = await res.text(); const errorMessage = await res.text();
const reason = "Reason01"; const reason = "Reason01";
const userID = "09dee632bfbb1acc9fda3169cc14b46e459b45cee4f4449be305590e612b5eb7";
const expected = "Submission rejected due to a warning from a moderator. This means that we noticed you were making some common mistakes" const expected = "Submission rejected due to a warning from a moderator. This means that we noticed you were making some common mistakes"
+ " that are not malicious, and we just want to clarify the rules. " + " that are not malicious, and we just want to clarify the rules. "
+ "Could you please send a message in discord.gg/SponsorBlock or matrix.to/#/#sponsor:ajay.app so we can further help you? " + "Could you please send a message in discord.gg/SponsorBlock or matrix.to/#/#sponsor:ajay.app so we can further help you? "
+ `Your userID is ${userID}.\n\nWarning reason: '${reason}'`; + `Your userID is ${warnUser01Hash}.\n\nWarning reason: '${reason}'`;
assert.strictEqual(errorMessage, expected); assert.strictEqual(errorMessage, expected);
done(); done();
@@ -647,14 +645,11 @@ describe("postSkipSegments", () => {
}); });
it("Should be accepted if user has some active warnings", (done: Done) => { it("Should be accepted if user has some active warnings", (done: Done) => {
fetch(`${getbaseURL()}/api/postVideoSponsorTimes`, { fetch(endpoint, {
method: "POST", ...postJSON,
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({ body: JSON.stringify({
userID: "warn-user02-qwertyuiopasdfghjklzxcvbnm", userID: warnUser02,
videoID: "dQw4w9WgXcF", videoID: warnVideoID,
segments: [{ segments: [{
segment: [50, 60], segment: [50, 60],
category: "sponsor", category: "sponsor",
@@ -673,14 +668,11 @@ describe("postSkipSegments", () => {
}); });
it("Should be accepted if user has some warnings removed", (done: Done) => { it("Should be accepted if user has some warnings removed", (done: Done) => {
fetch(`${getbaseURL()}/api/postVideoSponsorTimes`, { fetch(endpoint, {
method: "POST", ...postJSON,
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({ body: JSON.stringify({
userID: "warn-user03-qwertyuiopasdfghjklzxcvbnm", userID: warnUser03,
videoID: "dQw4w9WgXcF", videoID: warnVideoID,
segments: [{ segments: [{
segment: [53, 60], segment: [53, 60],
category: "sponsor", category: "sponsor",
@@ -699,8 +691,7 @@ describe("postSkipSegments", () => {
}); });
it("Should return 400 for missing params (Params method)", (done: Done) => { it("Should return 400 for missing params (Params method)", (done: Done) => {
fetch(`${getbaseURL() fetch(`${endpoint}?startTime=9&endTime=10&userID=${submitUserOne}`, {
}/api/postVideoSponsorTimes?startTime=9&endTime=10&userID=testtesttesttesttesttesttesttesttest`, {
method: "POST", method: "POST",
}) })
.then(async res => { .then(async res => {
@@ -711,14 +702,11 @@ describe("postSkipSegments", () => {
}); });
it("Should be rejected with default message if user has to many active warnings", (done: Done) => { it("Should be rejected with default message if user has to many active warnings", (done: Done) => {
fetch(`${getbaseURL()}/api/postVideoSponsorTimes`, { fetch(endpoint, {
method: "POST", ...postJSON,
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({ body: JSON.stringify({
userID: "warn-user01-qwertyuiopasdfghjklzxcvbnm", userID: warnUser01,
videoID: "dQw4w9WgXcF", videoID: warnVideoID,
segments: [{ segments: [{
segment: [0, 10], segment: [0, 10],
category: "sponsor", category: "sponsor",
@@ -735,13 +723,10 @@ describe("postSkipSegments", () => {
}); });
it("Should return 400 for missing params (JSON method) 1", (done: Done) => { it("Should return 400 for missing params (JSON method) 1", (done: Done) => {
fetch(`${getbaseURL()}/api/postVideoSponsorTimes`, { fetch(endpoint, {
method: "POST", ...postJSON,
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({ body: JSON.stringify({
userID: "testtesttesttesttesttesttesttesttest", userID: submitUserOne,
segments: [{ segments: [{
segment: [9, 10], segment: [9, 10],
category: "sponsor", category: "sponsor",
@@ -758,14 +743,11 @@ describe("postSkipSegments", () => {
.catch(err => done(err)); .catch(err => done(err));
}); });
it("Should return 400 for missing params (JSON method) 2", (done: Done) => { it("Should return 400 for missing params (JSON method) 2", (done: Done) => {
fetch(`${getbaseURL()}/api/postVideoSponsorTimes`, { fetch(endpoint, {
method: "POST", ...postJSON,
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({ body: JSON.stringify({
userID: "testtesttesttesttesttesttesttesttest", userID: submitUserOne,
videoID: "dQw4w9WgXcQ", videoID: badInputVideoID,
}), }),
}) })
.then(res => { .then(res => {
@@ -775,14 +757,11 @@ describe("postSkipSegments", () => {
.catch(err => done(err)); .catch(err => done(err));
}); });
it("Should return 400 for missing params (JSON method) 3", (done: Done) => { it("Should return 400 for missing params (JSON method) 3", (done: Done) => {
fetch(`${getbaseURL()}/api/postVideoSponsorTimes`, { fetch(endpoint, {
method: "POST", ...postJSON,
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({ body: JSON.stringify({
userID: "testtesttesttesttesttesttesttesttest", userID: submitUserOne,
videoID: "dQw4w9WgXcQ", videoID: badInputVideoID,
segments: [{ segments: [{
segment: [0], segment: [0],
category: "sponsor", category: "sponsor",
@@ -799,14 +778,11 @@ describe("postSkipSegments", () => {
.catch(err => done(err)); .catch(err => done(err));
}); });
it("Should return 400 for missing params (JSON method) 4", (done: Done) => { it("Should return 400 for missing params (JSON method) 4", (done: Done) => {
fetch(`${getbaseURL()}/api/postVideoSponsorTimes`, { fetch(endpoint, {
method: "POST", ...postJSON,
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({ body: JSON.stringify({
userID: "testtesttesttesttesttesttesttesttest", userID: submitUserOne,
videoID: "dQw4w9WgXcQ", videoID: badInputVideoID,
segments: [{ segments: [{
segment: [9, 10], segment: [9, 10],
}, { }, {
@@ -822,14 +798,11 @@ describe("postSkipSegments", () => {
.catch(err => done(err)); .catch(err => done(err));
}); });
it("Should return 400 for missing params (JSON method) 5", (done: Done) => { it("Should return 400 for missing params (JSON method) 5", (done: Done) => {
fetch(`${getbaseURL()}/api/postVideoSponsorTimes`, { fetch(endpoint, {
method: "POST", ...postJSON,
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({ body: JSON.stringify({
userID: "testtesttesttesttesttesttesttesttest", userID: submitUserOne,
videoID: "dQw4w9WgXcQ", videoID: badInputVideoID,
}), }),
}) })
.then(res => { .then(res => {
@@ -840,18 +813,16 @@ describe("postSkipSegments", () => {
}); });
it("Should return 403 and custom reason for submiting in lockedCategory", async () => { it("Should return 403 and custom reason for submiting in lockedCategory", async () => {
const videoID = "lockedVideo";
await db.prepare("run", `INSERT INTO "lockCategories" ("userID", "videoID", "category", "reason") await db.prepare("run", `INSERT INTO "lockCategories" ("userID", "videoID", "category", "reason")
VALUES(?, ?, ?, ?)`, [getHash("VIPUser-lockCategories"), "lockedVideo", "sponsor", "Custom Reason"]); VALUES(?, ?, ?, ?)`, [getHash("VIPUser-lockCategories"), videoID, "sponsor", "Custom Reason"]);
try { try {
const res = await fetch(`${getbaseURL()}/api/postVideoSponsorTimes`, { const res = await fetch(endpoint, {
method: "POST", ...postJSON,
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({ body: JSON.stringify({
userID: "testtesttesttesttesttesttesttesttest", userID: submitUserOne,
videoID: "lockedVideo", videoID,
segments: [{ segments: [{
segment: [1, 10], segment: [1, 10],
category: "sponsor", category: "sponsor",
@@ -868,18 +839,16 @@ describe("postSkipSegments", () => {
}); });
it("Should return 403 for submiting in lockedCategory", async () => { it("Should return 403 for submiting in lockedCategory", async () => {
const videoID = "lockedVideo1";
await db.prepare("run", `INSERT INTO "lockCategories" ("userID", "videoID", "category", "reason") await db.prepare("run", `INSERT INTO "lockCategories" ("userID", "videoID", "category", "reason")
VALUES(?, ?, ?, ?)`, [getHash("VIPUser-lockCategories"), "lockedVideo1", "intro", ""]); VALUES(?, ?, ?, ?)`, [getHash("VIPUser-lockCategories"), videoID, "intro", ""]);
try { try {
const res = await fetch(`${getbaseURL()}/api/postVideoSponsorTimes`, { const res = await fetch(endpoint, {
method: "POST", ...postJSON,
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({ body: JSON.stringify({
userID: "testtesttesttesttesttesttesttesttest", userID: submitUserOne,
videoID: "lockedVideo1", videoID,
segments: [{ segments: [{
segment: [1, 10], segment: [1, 10],
category: "intro", category: "intro",
@@ -896,14 +865,14 @@ describe("postSkipSegments", () => {
}).timeout(5000); }).timeout(5000);
it("Should be able to submit with custom user-agent 1", (done: Done) => { it("Should be able to submit with custom user-agent 1", (done: Done) => {
fetch(`${getbaseURL()}/api/postVideoSponsorTimes`, { fetch(endpoint, {
method: "POST", method: "POST",
headers: { headers: {
"Content-Type": "application/json", "Content-Type": "application/json",
"User-Agent": "com.google.android.youtube/5.0" "User-Agent": "com.google.android.youtube/5.0"
}, },
body: JSON.stringify({ body: JSON.stringify({
userID: "testtesttesttesttesttesttesttesttest", userID: submitUserOne,
videoID: "userAgent-1", videoID: "userAgent-1",
segments: [{ segments: [{
segment: [0, 10], segment: [0, 10],
@@ -926,14 +895,14 @@ describe("postSkipSegments", () => {
}); });
it("Should be able to submit with empty user-agent", (done: Done) => { it("Should be able to submit with empty user-agent", (done: Done) => {
fetch(`${getbaseURL()}/api/postVideoSponsorTimes`, { fetch(endpoint, {
method: "POST", method: "POST",
headers: { headers: {
"Content-Type": "application/json", "Content-Type": "application/json",
"User-Agent": "" "User-Agent": ""
}, },
body: JSON.stringify({ body: JSON.stringify({
userID: "testtesttesttesttesttesttesttesttest", userID: submitUserOne,
videoID: "userAgent-3", videoID: "userAgent-3",
segments: [{ segments: [{
segment: [0, 10], segment: [0, 10],
@@ -956,13 +925,13 @@ describe("postSkipSegments", () => {
}); });
it("Should be able to submit with custom userAgent in body", (done: Done) => { it("Should be able to submit with custom userAgent in body", (done: Done) => {
fetch(`${getbaseURL()}/api/postVideoSponsorTimes`, { fetch(endpoint, {
method: "POST", method: "POST",
headers: { headers: {
"Content-Type": "application/json" "Content-Type": "application/json"
}, },
body: JSON.stringify({ body: JSON.stringify({
userID: "testtesttesttesttesttesttesttesttest", userID: submitUserOne,
videoID: "userAgent-4", videoID: "userAgent-4",
segments: [{ segments: [{
segment: [0, 10], segment: [0, 10],
@@ -986,14 +955,12 @@ describe("postSkipSegments", () => {
}); });
it("Should be able to submit with commas in timestamps", (done: Done) => { it("Should be able to submit with commas in timestamps", (done: Done) => {
fetch(`${getbaseURL()}/api/postVideoSponsorTimes`, { const videoID = "commas-1";
method: "POST", fetch(endpoint, {
headers: { ...postJSON,
"Content-Type": "application/json"
},
body: JSON.stringify({ body: JSON.stringify({
userID: "testtesttesttesttesttesttesttesttest", userID: submitUserOne,
videoID: "commas-1", videoID,
segments: [{ segments: [{
segment: ["0,2", "10,392"], segment: ["0,2", "10,392"],
category: "sponsor", category: "sponsor",
@@ -1002,7 +969,7 @@ describe("postSkipSegments", () => {
}) })
.then(async res => { .then(async res => {
assert.strictEqual(res.status, 200); assert.strictEqual(res.status, 200);
const row = await db.prepare("get", `SELECT "startTime", "endTime", "locked", "category" FROM "sponsorTimes" WHERE "videoID" = ?`, ["commas-1"]); const row = await queryDatabase(videoID);
const expected = { const expected = {
startTime: 0.2, startTime: 0.2,
endTime: 10.392 endTime: 10.392
@@ -1014,8 +981,8 @@ describe("postSkipSegments", () => {
}); });
it("Should be rejected if a POI is at less than 1 second", (done: Done) => { it("Should be rejected if a POI is at less than 1 second", (done: Done) => {
fetch(`${getbaseURL() const videoID = "qqwerty";
}/api/skipSegments?videoID=qqwerty&startTime=0.5&endTime=0.5&category=poi_highlight&userID=testtesttesttesttesttesttesttesttesting`, { fetch(`${endpoint}?videoID=${videoID}&startTime=0.5&endTime=0.5&category=poi_highlight&userID=${submitUserTwo}`, {
method: "POST", method: "POST",
}) })
.then(res => { .then(res => {
@@ -1026,14 +993,12 @@ describe("postSkipSegments", () => {
}); });
it("Should not be able to submit with colons in timestamps", (done: Done) => { it("Should not be able to submit with colons in timestamps", (done: Done) => {
fetch(`${getbaseURL()}/api/postVideoSponsorTimes`, { const videoID = "colon-1";
method: "POST", fetch(endpoint, {
headers: { ...postJSON,
"Content-Type": "application/json"
},
body: JSON.stringify({ body: JSON.stringify({
userID: "testtesttesttesttesttesttesttesttest", userID: submitUserOne,
videoID: "colon-1", videoID,
segments: [{ segments: [{
segment: ["0:2.000", "3:10.392"], segment: ["0:2.000", "3:10.392"],
category: "sponsor", category: "sponsor",

View File

@@ -38,3 +38,10 @@ function printActualExpected(actual: Record<string, any>, expected: Record<strin
Logger.error(`Actual: ${JSON.stringify(actual)}`); Logger.error(`Actual: ${JSON.stringify(actual)}`);
Logger.error(`Expected: ${JSON.stringify(expected)}`); Logger.error(`Expected: ${JSON.stringify(expected)}`);
} }
export const postJSON = {
method: "POST",
headers: {
"Content-Type": "application/json",
},
};