finished other tests

This commit is contained in:
Michael C 2021-09-16 23:59:19 -04:00
parent e7d55d1e1b
commit 9e9fcd47c0
No known key found for this signature in database
GPG key ID: FFB04FB3B878B7B4
13 changed files with 263 additions and 293 deletions

View file

@ -5,12 +5,13 @@ import {getHash} from "../../src/utils/getHash";
import assert from "assert";
describe("getIsUserVIP", () => {
before((done: Done) => {
db.prepare("run", 'INSERT INTO "vipUsers" ("userID") VALUES (?)', [getHash("isUserVIPVIP")]).then(done);
const endpoint = `${getbaseURL()}/api/isUserVIP`;
before(() => {
db.prepare("run", 'INSERT INTO "vipUsers" ("userID") VALUES (?)', [getHash("isUserVIPVIP")]);
});
it("Should be able to get a 200", (done: Done) => {
fetch(`${getbaseURL()}/api/isUserVIP?userID=isUserVIPVIP`)
fetch(`${endpoint}?userID=isUserVIPVIP`)
.then(res => {
assert.strictEqual(res.status, 200, "response should be 200");
done();
@ -20,7 +21,7 @@ describe("getIsUserVIP", () => {
it("Should get a 400 if no userID", (done: Done) => {
fetch(`${getbaseURL()}/api/isUserVIP`)
fetch(endpoint)
.then(res => {
assert.strictEqual(res.status, 400, "response should be 400");
done();
@ -29,7 +30,7 @@ describe("getIsUserVIP", () => {
});
it("Should say a VIP is a VIP", (done: Done) => {
fetch(`${getbaseURL()}/api/isUserVIP?userID=isUserVIPVIP`)
fetch(`${endpoint}?userID=isUserVIPVIP`)
.then(async res => {
assert.strictEqual(res.status, 200);
const data = await res.json();
@ -40,7 +41,7 @@ describe("getIsUserVIP", () => {
});
it("Should say a normal user is not a VIP", (done: Done) => {
fetch(`${getbaseURL()}/api/isUserVIP?userID=isUserVIPNormal`)
fetch(`${endpoint}?userID=isUserVIPNormal`)
.then(async res => {
assert.strictEqual(res.status, 200);
const data = await res.json();

View file

@ -6,6 +6,7 @@ import assert from "assert";
describe("getLockCategories", () => {
const endpoint = `${getbaseURL()}/api/lockCategories`;
before(async () => {
const insertVipUserQuery = 'INSERT INTO "vipUsers" ("userID") VALUES (?)';
await db.prepare("run", insertVipUserQuery, [getHash("getLockCategoriesVIP")]);
@ -25,7 +26,7 @@ describe("getLockCategories", () => {
});
it("Should be able to get multiple locks", (done: Done) => {
fetch(`${getbaseURL()}/api/lockCategories?videoID=getLock1`)
fetch(`${endpoint}?videoID=getLock1`)
.then(async res => {
assert.strictEqual(res.status, 200);
const data = await res.json();
@ -43,7 +44,7 @@ describe("getLockCategories", () => {
});
it("Should be able to get single locks", (done: Done) => {
fetch(`${getbaseURL()}/api/lockCategories?videoID=getLock2`)
fetch(`${endpoint}?videoID=getLock2`)
.then(async res => {
assert.strictEqual(res.status, 200);
const data = await res.json();
@ -60,7 +61,7 @@ describe("getLockCategories", () => {
});
it("should return 404 if no lock exists", (done: Done) => {
fetch(`${getbaseURL()}/api/lockCategories?videoID=getLockNull`)
fetch(`${endpoint}?videoID=getLockNull`)
.then(res => {
assert.strictEqual(res.status, 404);
done();
@ -69,7 +70,7 @@ describe("getLockCategories", () => {
});
it("should return 400 if no videoID specified", (done: Done) => {
fetch(`${getbaseURL()}/api/lockCategories`)
fetch(endpoint)
.then(res => {
assert.strictEqual(res.status, 400);
done();

View file

@ -7,6 +7,7 @@ import assert from "assert";
const fakeHash = "b05a20424f24a53dac1b059fb78d861ba9723645026be2174c93a94f9106bb35";
describe("getLockCategoriesByHash", () => {
const endpoint = `${getbaseURL()}/api/lockCategories`;
before(async () => {
const insertVipUserQuery = 'INSERT INTO "vipUsers" ("userID") VALUES (?)';
await db.prepare("run", insertVipUserQuery, [getHash("getLockCategoriesHashVIP")]);
@ -34,7 +35,7 @@ describe("getLockCategoriesByHash", () => {
it("Should be able to get multiple locks in one object", (done: Done) => {
const videoID = "getLockHash1";
const hash = getHash(videoID, 1);
fetch(`${getbaseURL()}/api/lockCategories/${hash.substring(0,4)}`)
fetch(`${endpoint}/${hash.substring(0,4)}`)
.then(async res => {
assert.strictEqual(res.status, 200);
const data = await res.json();
@ -56,7 +57,7 @@ describe("getLockCategoriesByHash", () => {
it("Should be able to get single lock", (done: Done) => {
const videoID = "getLockHash2";
const hash = getHash(videoID, 1);
fetch(`${getbaseURL()}/api/lockCategories/${hash.substring(0,6)}`)
fetch(`${endpoint}/${hash.substring(0,6)}`)
.then(async res => {
assert.strictEqual(res.status, 200);
const data = await res.json();
@ -77,7 +78,7 @@ describe("getLockCategoriesByHash", () => {
it("Should be able to get by half full hash", (done: Done) => {
const videoID = "getLockHash3";
const hash = getHash(videoID, 1);
fetch(`${getbaseURL()}/api/lockCategories/${hash.substring(0,32)}`)
fetch(`${endpoint}/${hash.substring(0,32)}`)
.then(async res => {
assert.strictEqual(res.status, 200);
const data = await res.json();
@ -96,7 +97,7 @@ describe("getLockCategoriesByHash", () => {
});
it("Should be able to get multiple by similar hash with multiple categories", (done: Done) => {
fetch(`${getbaseURL()}/api/lockCategories/${fakeHash.substring(0,5)}`)
fetch(`${endpoint}/${fakeHash.substring(0,5)}`)
.then(async res => {
assert.strictEqual(res.status, 200);
const data = await res.json();
@ -123,7 +124,7 @@ describe("getLockCategoriesByHash", () => {
});
it("should return 404 once hash prefix varies", (done: Done) => {
fetch(`${getbaseURL()}/api/lockCategories/b05aa`)
fetch(`${endpoint}/b05aa`)
.then(res => {
assert.strictEqual(res.status, 404);
done();
@ -132,7 +133,7 @@ describe("getLockCategoriesByHash", () => {
});
it("should return 404 if no lock exists", (done: Done) => {
fetch(`${getbaseURL()}/api/lockCategories/aaaaaa`)
fetch(`${endpoint}/aaaaaa`)
.then(res => {
assert.strictEqual(res.status, 404);
done();
@ -141,7 +142,7 @@ describe("getLockCategoriesByHash", () => {
});
it("should return 400 if no videoID specified", (done: Done) => {
fetch(`${getbaseURL()}/api/lockCategories/`)
fetch(`${endpoint}/`)
.then(res => {
assert.strictEqual(res.status, 400);
done();
@ -150,7 +151,7 @@ describe("getLockCategoriesByHash", () => {
});
it("should return 400 if full hash sent", (done: Done) => {
fetch(`${getbaseURL()}/api/lockCategories/${fakeHash}`)
fetch(`${endpoint}/${fakeHash}`)
.then(res => {
assert.strictEqual(res.status, 400);
done();
@ -159,7 +160,7 @@ describe("getLockCategoriesByHash", () => {
});
it("should return 400 if hash too short", (done: Done) => {
fetch(`${getbaseURL()}/api/lockCategories/00`)
fetch(`${endpoint}/00`)
.then(res => {
assert.strictEqual(res.status, 400);
done();
@ -168,7 +169,7 @@ describe("getLockCategoriesByHash", () => {
});
it("should return 400 if no hash specified", (done: Done) => {
fetch(`${getbaseURL()}/api/lockCategories/`)
fetch(endpoint)
.then(res => {
assert.strictEqual(res.status, 400);
done();

View file

@ -5,6 +5,7 @@ import {getHash} from "../../src/utils/getHash";
import {deepStrictEqual} from "assert";
describe("getSavedTimeForUser", () => {
const endpoint = `${getbaseURL()}/api/getSavedTimeForUser`;
before(async () => {
const startOfQuery = 'INSERT INTO "sponsorTimes" ("videoID", "startTime", "endTime", "votes", "UUID", "userID", "timeSubmitted", "views", "shadowHidden") VALUES';
await db.prepare("run", `${startOfQuery}(?, ?, ?, ?, ?, ?, ?, ?, ?)`,
@ -13,7 +14,7 @@ describe("getSavedTimeForUser", () => {
});
it("Should be able to get a 200", (done: Done) => {
fetch(`${getbaseURL()}/api/getSavedTimeForUser?userID=getSavedTimeForUserUser`)
fetch(`${endpoint}?userID=getSavedTimeForUserUser`)
.then(async res => {
const data = await res.json();
// (end-start)*minute * views

View file

@ -4,6 +4,7 @@ import {Done, getbaseURL} from "../utils";
import assert from "assert";
describe("getSearchSegments", () => {
const endpoint = `${getbaseURL()}/api/searchSegments`;
before(async () => {
const query = 'INSERT INTO "sponsorTimes" ("videoID", "startTime", "endTime", "votes", "views", "locked", "hidden", "shadowHidden", "timeSubmitted", "UUID", "userID", "category", "actionType") VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)';
await db.prepare("run", query, ["searchTest0", 0, 1, 2, 0, 0, 0, 0, 1, "search-normal", "searchTestUser", "sponsor", "skip"]);
@ -33,7 +34,7 @@ describe("getSearchSegments", () => {
});
it("Should be able to show all segments under searchTest0", (done: Done) => {
fetch(`${getbaseURL()}/api/searchSegments?videoID=searchTest0`)
fetch(`${endpoint}?videoID=searchTest0`)
.then(async res => {
assert.strictEqual(res.status, 200);
const data = await res.json();
@ -51,7 +52,7 @@ describe("getSearchSegments", () => {
});
it("Should be able to filter by category", (done: Done) => {
fetch(`${getbaseURL()}/api/searchSegments?videoID=searchTest0&category=selfpromo`)
fetch(`${endpoint}?videoID=searchTest0&category=selfpromo`)
.then(async res => {
assert.strictEqual(res.status, 200);
const data = await res.json();
@ -65,7 +66,7 @@ describe("getSearchSegments", () => {
});
it("Should be able to filter by category", (done: Done) => {
fetch(`${getbaseURL()}/api/searchSegments?videoID=searchTest0&category=selfpromo`)
fetch(`${endpoint}?videoID=searchTest0&category=selfpromo`)
.then(async res => {
assert.strictEqual(res.status, 200);
const data = await res.json();
@ -79,7 +80,7 @@ describe("getSearchSegments", () => {
});
it("Should be able to filter by lock status", (done: Done) => {
fetch(`${getbaseURL()}/api/searchSegments?videoID=searchTest0&locked=false`)
fetch(`${endpoint}?videoID=searchTest0&locked=false`)
.then(async res => {
assert.strictEqual(res.status, 200);
const data = await res.json();
@ -96,7 +97,7 @@ describe("getSearchSegments", () => {
});
it("Should be able to filter by hide status", (done: Done) => {
fetch(`${getbaseURL()}/api/searchSegments?videoID=searchTest0&hidden=false`)
fetch(`${endpoint}?videoID=searchTest0&hidden=false`)
.then(async res => {
assert.strictEqual(res.status, 200);
const data = await res.json();
@ -113,7 +114,7 @@ describe("getSearchSegments", () => {
});
it("Should be able to filter by ignored status", (done: Done) => {
fetch(`${getbaseURL()}/api/searchSegments?videoID=searchTest0&ignored=false`)
fetch(`${endpoint}?videoID=searchTest0&ignored=false`)
.then(async res => {
assert.strictEqual(res.status, 200);
const data = await res.json();
@ -129,7 +130,7 @@ describe("getSearchSegments", () => {
});
it("Should be able to filter segments by min views", (done: Done) => {
fetch(`${getbaseURL()}/api/searchSegments?videoID=searchTest1&minViews=6`)
fetch(`${endpoint}?videoID=searchTest1&minViews=6`)
.then(async res => {
assert.strictEqual(res.status, 200);
const data = await res.json();
@ -143,7 +144,7 @@ describe("getSearchSegments", () => {
});
it("Should be able to filter segments by max views", (done: Done) => {
fetch(`${getbaseURL()}/api/searchSegments?videoID=searchTest1&maxViews=10`)
fetch(`${endpoint}?videoID=searchTest1&maxViews=10`)
.then(async res => {
assert.strictEqual(res.status, 200);
const data = await res.json();
@ -157,7 +158,7 @@ describe("getSearchSegments", () => {
});
it("Should be able to filter segments by min and max views", (done: Done) => {
fetch(`${getbaseURL()}/api/searchSegments?videoID=searchTest1&maxViews=10&minViews=1`)
fetch(`${endpoint}?videoID=searchTest1&maxViews=10&minViews=1`)
.then(async res => {
assert.strictEqual(res.status, 200);
const data = await res.json();
@ -171,7 +172,7 @@ describe("getSearchSegments", () => {
});
it("Should be able to filter segments by min votes", (done: Done) => {
fetch(`${getbaseURL()}/api/searchSegments?videoID=searchTest2&minVotes=0`)
fetch(`${endpoint}?videoID=searchTest2&minVotes=0`)
.then(async res => {
assert.strictEqual(res.status, 200);
const data = await res.json();
@ -186,7 +187,7 @@ describe("getSearchSegments", () => {
});
it("Should be able to filter segments by max votes", (done: Done) => {
fetch(`${getbaseURL()}/api/searchSegments?videoID=searchTest2&maxVotes=10`)
fetch(`${endpoint}?videoID=searchTest2&maxVotes=10`)
.then(async res => {
assert.strictEqual(res.status, 200);
const data = await res.json();
@ -201,7 +202,7 @@ describe("getSearchSegments", () => {
});
it("Should be able to filter segments by both min and max votes", (done: Done) => {
fetch(`${getbaseURL()}/api/searchSegments?videoID=searchTest2&maxVotes=10&minVotes=0`)
fetch(`${endpoint}?videoID=searchTest2&maxVotes=10&minVotes=0`)
.then(async res => {
assert.strictEqual(res.status, 200);
const data = await res.json();
@ -215,7 +216,7 @@ describe("getSearchSegments", () => {
});
it("Should be able to get first page of results", (done: Done) => {
fetch(`${getbaseURL()}/api/searchSegments?videoID=searchTest4`)
fetch(`${endpoint}?videoID=searchTest4`)
.then(async res => {
assert.strictEqual(res.status, 200);
const data = await res.json();
@ -238,7 +239,7 @@ describe("getSearchSegments", () => {
});
it("Should be able to get second page of results", (done: Done) => {
fetch(`${getbaseURL()}/api/searchSegments?videoID=searchTest4&page=1`)
fetch(`${endpoint}?videoID=searchTest4&page=1`)
.then(async res => {
assert.strictEqual(res.status, 200);
const data = await res.json();

View file

@ -26,6 +26,7 @@ const userAgents = {
};
describe("getSegmentInfo", () => {
const endpoint = `${getbaseURL()}/api/segmentInfo`;
before(async () => {
const insertQuery = `INSERT INTO
"sponsorTimes"("videoID", "startTime", "endTime", "votes", "locked",
@ -47,7 +48,7 @@ describe("getSegmentInfo", () => {
});
it("Should be able to retreive upvoted segment", (done: Done) => {
fetch(`${getbaseURL()}/api/segmentInfo?UUID=${upvotedID}`)
fetch(`${endpoint}?UUID=${upvotedID}`)
.then(async res => {
assert.strictEqual(res.status, 200);
const data = await res.json();
@ -63,7 +64,7 @@ describe("getSegmentInfo", () => {
});
it("Should be able to retreive downvoted segment", (done: Done) => {
fetch(`${getbaseURL()}/api/segmentInfo?UUID=${downvotedID}`)
fetch(`${endpoint}?UUID=${downvotedID}`)
.then(async res => {
assert.strictEqual(res.status, 200);
const data = await res.json();
@ -79,7 +80,7 @@ describe("getSegmentInfo", () => {
});
it("Should be able to retreive locked up segment", (done: Done) => {
fetch(`${getbaseURL()}/api/segmentInfo?UUID=${lockedupID}`)
fetch(`${endpoint}?UUID=${lockedupID}`)
.then(async res => {
assert.strictEqual(res.status, 200);
const data = await res.json();
@ -96,7 +97,7 @@ describe("getSegmentInfo", () => {
});
it("Should be able to retreive infinite vote segment", (done: Done) => {
fetch(`${getbaseURL()}/api/segmentInfo?UUID=${infvotesID}`)
fetch(`${endpoint}?UUID=${infvotesID}`)
.then(async res => {
assert.strictEqual(res.status, 200);
const data = await res.json();
@ -112,7 +113,7 @@ describe("getSegmentInfo", () => {
});
it("Should be able to retreive shadowhidden segment", (done: Done) => {
fetch(`${getbaseURL()}/api/segmentInfo?UUID=${shadowhiddenID}`)
fetch(`${endpoint}?UUID=${shadowhiddenID}`)
.then(async res => {
assert.strictEqual(res.status, 200);
const data = await res.json();
@ -128,7 +129,7 @@ describe("getSegmentInfo", () => {
});
it("Should be able to retreive locked down segment", (done: Done) => {
fetch(`${getbaseURL()}/api/segmentInfo?UUID=${lockeddownID}`)
fetch(`${endpoint}?UUID=${lockeddownID}`)
.then(async res => {
assert.strictEqual(res.status, 200);
const data = await res.json();
@ -144,7 +145,7 @@ describe("getSegmentInfo", () => {
});
it("Should be able to retreive hidden segment", (done: Done) => {
fetch(`${getbaseURL()}/api/segmentInfo?UUID=${hiddenID}`)
fetch(`${endpoint}?UUID=${hiddenID}`)
.then(async res => {
assert.strictEqual(res.status, 200);
const data = await res.json();
@ -159,7 +160,7 @@ describe("getSegmentInfo", () => {
});
it("Should be able to retreive segment with old ID", (done: Done) => {
fetch(`${getbaseURL()}/api/segmentInfo?UUID=${oldID}`)
fetch(`${endpoint}?UUID=${oldID}`)
.then(async res => {
assert.strictEqual(res.status, 200);
const data = await res.json();
@ -174,7 +175,7 @@ describe("getSegmentInfo", () => {
});
it("Should be able to retreive single segment in array", (done: Done) => {
fetch(`${getbaseURL()}/api/segmentInfo?UUIDs=["${upvotedID}"]`)
fetch(`${endpoint}?UUIDs=["${upvotedID}"]`)
.then(async res => {
assert.strictEqual(res.status, 200);
const data = await res.json();
@ -190,7 +191,7 @@ describe("getSegmentInfo", () => {
});
it("Should be able to retreive multiple segments in array", (done: Done) => {
fetch(`${getbaseURL()}/api/segmentInfo?UUIDs=["${upvotedID}", "${downvotedID}"]`)
fetch(`${endpoint}?UUIDs=["${upvotedID}", "${downvotedID}"]`)
.then(async res => {
assert.strictEqual(res.status, 200);
const data = await res.json();
@ -209,7 +210,7 @@ describe("getSegmentInfo", () => {
});
it("Should be possible to send unexpected query parameters", (done: Done) => {
fetch(`${getbaseURL()}/api/segmentInfo?UUID=${upvotedID}&fakeparam=hello&category=sponsor`)
fetch(`${endpoint}?UUID=${upvotedID}&fakeparam=hello&category=sponsor`)
.then(async res => {
assert.strictEqual(res.status, 200);
const data = await res.json();
@ -224,7 +225,7 @@ describe("getSegmentInfo", () => {
});
it("Should return 400 if array passed to UUID", (done: Done) => {
fetch(`${getbaseURL()}/api/segmentInfo?UUID=["${upvotedID}", "${downvotedID}"]`)
fetch(`${endpoint}?UUID=["${upvotedID}", "${downvotedID}"]`)
.then(res => {
assert.strictEqual(res.status, 400);
done();
@ -233,7 +234,7 @@ describe("getSegmentInfo", () => {
});
it("Should return 400 if bad array passed to UUIDs", (done: Done) => {
fetch(`${getbaseURL()}/api/segmentInfo?UUIDs=[not-quoted,not-quoted]`)
fetch(`${endpoint}?UUIDs=[not-quoted,not-quoted]`)
.then(res => {
assert.strictEqual(res.status, 400);
done();
@ -242,7 +243,7 @@ describe("getSegmentInfo", () => {
});
it("Should return 400 if bad UUID passed", (done: Done) => {
fetch(`${getbaseURL()}/api/segmentInfo?UUID=notarealuuid`)
fetch(`${endpoint}?UUID=notarealuuid`)
.then(res => {
assert.strictEqual(res.status, 400);
done();
@ -251,7 +252,7 @@ describe("getSegmentInfo", () => {
});
it("Should return 400 if bad UUIDs passed in array", (done: Done) => {
fetch(`${getbaseURL()}/api/segmentInfo?UUIDs=["notarealuuid", "anotherfakeuuid"]`)
fetch(`${endpoint}?UUIDs=["notarealuuid", "anotherfakeuuid"]`)
.then(res => {
assert.strictEqual(res.status, 400);
done();
@ -260,7 +261,7 @@ describe("getSegmentInfo", () => {
});
it("Should return good UUID when mixed with bad UUIDs", (done: Done) => {
fetch(`${getbaseURL()}/api/segmentInfo?UUIDs=["${upvotedID}", "anotherfakeuuid"]`)
fetch(`${endpoint}?UUIDs=["${upvotedID}", "anotherfakeuuid"]`)
.then(async res => {
assert.strictEqual(res.status, 200);
const data = await res.json();
@ -278,7 +279,7 @@ describe("getSegmentInfo", () => {
it("Should cut off array at 10", function(done: Done) {
this.timeout(10000);
const filledIDArray = `["${upvotedID}", "${downvotedID}", "${lockedupID}", "${shadowhiddenID}", "${lockeddownID}", "${hiddenID}", "${fillerID1}", "${fillerID2}", "${fillerID3}", "${fillerID4}", "${fillerID5}"]`;
fetch(`${getbaseURL()}/api/segmentInfo?UUIDs=${filledIDArray}`)
fetch(`${endpoint}?UUIDs=${filledIDArray}`)
.then(async res => {
assert.strictEqual(res.status, 200);
const data = await res.json();
@ -293,7 +294,7 @@ describe("getSegmentInfo", () => {
});
it("Should not duplicate reponses", (done: Done) => {
fetch(`${getbaseURL()}/api/segmentInfo?UUIDs=["${upvotedID}", "${upvotedID}", "${upvotedID}", "${upvotedID}", "${upvotedID}", "${upvotedID}", "${upvotedID}", "${upvotedID}", "${upvotedID}", "${upvotedID}", "${downvotedID}"]`)
fetch(`${endpoint}?UUIDs=["${upvotedID}", "${upvotedID}", "${upvotedID}", "${upvotedID}", "${upvotedID}", "${upvotedID}", "${upvotedID}", "${upvotedID}", "${upvotedID}", "${upvotedID}", "${downvotedID}"]`)
.then(async res => {
assert.strictEqual(res.status, 200);
const data = await res.json();
@ -304,7 +305,7 @@ describe("getSegmentInfo", () => {
});
it("Should return 400 if UUID not found", (done: Done) => {
fetch(`${getbaseURL()}/api/segmentInfo?UUID=${ENOENTID}`)
fetch(`${endpoint}?UUID=${ENOENTID}`)
.then(res => {
if (res.status !== 400) done(`non 400 response code: ${res.status}`);
else done(); // pass
@ -313,7 +314,7 @@ describe("getSegmentInfo", () => {
});
it("Should be able to retreive multiple segments with multiple parameters", (done: Done) => {
fetch(`${getbaseURL()}/api/segmentInfo?UUID=${upvotedID}&UUID=${downvotedID}`)
fetch(`${endpoint}?UUID=${upvotedID}&UUID=${downvotedID}`)
.then(async res => {
assert.strictEqual(res.status, 200);
const data = await res.json();
@ -332,7 +333,7 @@ describe("getSegmentInfo", () => {
});
it("Should not parse repeated UUID if UUIDs present", (done: Done) => {
fetch(`${getbaseURL()}/api/segmentInfo?UUID=${downvotedID}&UUID=${lockedupID}&UUIDs=["${upvotedID}"]`)
fetch(`${endpoint}?UUID=${downvotedID}&UUID=${lockedupID}&UUIDs=["${upvotedID}"]`)
.then(async res => {
assert.strictEqual(res.status, 200);
const data = await res.json();

View file

@ -4,6 +4,7 @@ import {Done, getbaseURL, partialDeepEquals} from "../utils";
import assert from "assert";
describe("getSkipSegments", () => {
const endpoint = `${getbaseURL()}/api/skipSegments`;
before(async () => {
const query = 'INSERT INTO "sponsorTimes" ("videoID", "startTime", "endTime", "votes", "locked", "UUID", "userID", "timeSubmitted", "views", "category", "actionType", "service", "videoDuration", "hidden", "shadowHidden") VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)';
await db.prepare("run", query, ["getSkipSegmentID0", 1, 11, 2, 0, "uuid01", "testman", 0, 50, "sponsor", "skip", "YouTube", 100, 0, 0]);
@ -27,7 +28,7 @@ describe("getSkipSegments", () => {
it("Should be able to get a time by category 1", (done: Done) => {
fetch(`${getbaseURL()}/api/skipSegments?videoID=getSkipSegmentID0&category=sponsor`)
fetch(`${endpoint}?videoID=getSkipSegmentID0&category=sponsor`)
.then(async res => {
assert.strictEqual(res.status, 200);
const data = await res.json();
@ -43,7 +44,7 @@ describe("getSkipSegments", () => {
});
it("Should be able to get a time by category and action type", (done: Done) => {
fetch(`${getbaseURL()}/api/skipSegments?videoID=getSkipSegmentID0&category=sponsor&actionType=mute`)
fetch(`${endpoint}?videoID=getSkipSegmentID0&category=sponsor&actionType=mute`)
.then(async res => {
assert.strictEqual(res.status, 200);
const data = await res.json();
@ -61,7 +62,7 @@ describe("getSkipSegments", () => {
});
it("Should be able to get a time by category and getSkipSegmentMultiple action types", (done: Done) => {
fetch(`${getbaseURL()}/api/skipSegments?videoID=getSkipSegmentID0&category=sponsor&actionType=mute&actionType=skip`)
fetch(`${endpoint}?videoID=getSkipSegmentID0&category=sponsor&actionType=mute&actionType=skip`)
.then(async res => {
assert.strictEqual(res.status, 200);
const data = await res.json();
@ -81,7 +82,7 @@ describe("getSkipSegments", () => {
});
it("Should be able to get a time by category and getSkipSegmentMultiple action types (JSON array)", (done: Done) => {
fetch(`${getbaseURL()}/api/skipSegments?videoID=getSkipSegmentID0&category=sponsor&actionTypes=["mute","skip"]`)
fetch(`${endpoint}?videoID=getSkipSegmentID0&category=sponsor&actionTypes=["mute","skip"]`)
.then(async res => {
assert.strictEqual(res.status, 200);
const data = await res.json();
@ -100,7 +101,7 @@ describe("getSkipSegments", () => {
});
it("Should be able to get a time by category for a different service 1", (done: Done) => {
fetch(`${getbaseURL()}/api/skipSegments?videoID=getSkipSegmentID1&category=sponsor&service=PeerTube`)
fetch(`${endpoint}?videoID=getSkipSegmentID1&category=sponsor&service=PeerTube`)
.then(async res => {
assert.strictEqual(res.status, 200);
const data = await res.json();
@ -118,7 +119,7 @@ describe("getSkipSegments", () => {
});
it("Should be able to get a time by category 2", (done: Done) => {
fetch(`${getbaseURL()}/api/skipSegments?videoID=getSkipSegmentID0&category=intro`)
fetch(`${endpoint}?videoID=getSkipSegmentID0&category=intro`)
.then(async res => {
assert.strictEqual(res.status, 200);
const data = await res.json();
@ -135,7 +136,7 @@ describe("getSkipSegments", () => {
});
it("Should be able to get a time by categories array", (done: Done) => {
fetch(`${getbaseURL()}/api/skipSegments?videoID=getSkipSegmentID0&categories=["sponsor"]`)
fetch(`${endpoint}?videoID=getSkipSegmentID0&categories=["sponsor"]`)
.then(async res => {
assert.strictEqual(res.status, 200);
const data = await res.json();
@ -153,7 +154,7 @@ describe("getSkipSegments", () => {
});
it("Should be able to get a time by categories array 2", (done: Done) => {
fetch(`${getbaseURL()}/api/skipSegments?videoID=getSkipSegmentID0&categories=["intro"]`)
fetch(`${endpoint}?videoID=getSkipSegmentID0&categories=["intro"]`)
.then(async res => {
assert.strictEqual(res.status, 200);
const data = await res.json();
@ -171,7 +172,7 @@ describe("getSkipSegments", () => {
});
it("Should return 404 if all submissions are hidden", (done: Done) => {
fetch(`${getbaseURL()}/api/skipSegments?videoID=getSkipSegmentID6`)
fetch(`${endpoint}?videoID=getSkipSegmentID6`)
.then(res => {
assert.strictEqual(res.status, 404);
done();
@ -180,7 +181,7 @@ describe("getSkipSegments", () => {
});
it("Should be able to get getSkipSegmentMultiple times by category", (done: Done) => {
fetch(`${getbaseURL()}/api/skipSegments?videoID=getSkipSegmentMultiple&categories=["intro"]`)
fetch(`${endpoint}?videoID=getSkipSegmentMultiple&categories=["intro"]`)
.then(async res => {
assert.strictEqual(res.status, 200);
const data = await res.json();
@ -201,7 +202,7 @@ describe("getSkipSegments", () => {
});
it("Should be able to get getSkipSegmentMultiple times by getSkipSegmentMultiple categories", (done: Done) => {
fetch(`${getbaseURL()}/api/skipSegments?videoID=getSkipSegmentID0&categories=["sponsor", "intro"]`)
fetch(`${endpoint}?videoID=getSkipSegmentID0&categories=["sponsor", "intro"]`)
.then(async res => {
assert.strictEqual(res.status, 200);
const data = await res.json();
@ -222,7 +223,7 @@ describe("getSkipSegments", () => {
});
it("Should be possible to send unexpected query parameters", (done: Done) => {
fetch(`${getbaseURL()}/api/skipSegments?videoID=getSkipSegmentID0&fakeparam=hello&category=sponsor`)
fetch(`${endpoint}?videoID=getSkipSegmentID0&fakeparam=hello&category=sponsor`)
.then(async res => {
assert.strictEqual(res.status, 200);
const data = await res.json();
@ -239,7 +240,7 @@ describe("getSkipSegments", () => {
});
it("Low voted submissions should be hidden", (done: Done) => {
fetch(`${getbaseURL()}/api/skipSegments?videoID=getSkipSegmentID3&category=sponsor`)
fetch(`${endpoint}?videoID=getSkipSegmentID3&category=sponsor`)
.then(async res => {
assert.strictEqual(res.status, 200);
const data = await res.json();
@ -256,7 +257,7 @@ describe("getSkipSegments", () => {
});
it("Should return 404 if no segment found", (done: Done) => {
fetch(`${getbaseURL()}/api/skipSegments?videoID=notarealvideo`)
fetch(`${endpoint}?videoID=notarealvideo`)
.then(res => {
assert.strictEqual(res.status, 404);
done();
@ -265,7 +266,7 @@ describe("getSkipSegments", () => {
});
it("Should return 400 if bad categories argument", (done: Done) => {
fetch(`${getbaseURL()}/api/skipSegments?videoID=getSkipSegmentID0&categories=[not-quoted,not-quoted]`)
fetch(`${endpoint}?videoID=getSkipSegmentID0&categories=[not-quoted,not-quoted]`)
.then(res => {
assert.strictEqual(res.status, 400);
done();
@ -274,7 +275,7 @@ describe("getSkipSegments", () => {
});
it("Should be able send a comma in a query param", (done: Done) => {
fetch(`${getbaseURL()}/api/skipSegments?videoID=getSkipSegmentID2&category=sponsor`)
fetch(`${endpoint}?videoID=getSkipSegmentID2&category=sponsor`)
.then(async res => {
assert.strictEqual(res.status, 200);
const data = await res.json();
@ -291,7 +292,7 @@ describe("getSkipSegments", () => {
});
it("Should always get getSkipSegmentLocked segment", (done: Done) => {
fetch(`${getbaseURL()}/api/skipSegments?videoID=getSkipSegmentLocked&category=intro`)
fetch(`${endpoint}?videoID=getSkipSegmentLocked&category=intro`)
.then(async res => {
assert.strictEqual(res.status, 200);
const data = await res.json();
@ -308,7 +309,7 @@ describe("getSkipSegments", () => {
});
it("Should be able to get getSkipSegmentMultiple categories with repeating parameters", (done: Done) => {
fetch(`${getbaseURL()}/api/skipSegments?videoID=getSkipSegmentID0&category=sponsor&category=intro`)
fetch(`${endpoint}?videoID=getSkipSegmentID0&category=sponsor&category=intro`)
.then(async res => {
assert.strictEqual(res.status, 200);
const data = await res.json();
@ -329,7 +330,7 @@ describe("getSkipSegments", () => {
});
it("Should be able to get, categories param overriding repeating category", (done: Done) => {
fetch(`${getbaseURL()}/api/skipSegments?videoID=getSkipSegmentID0&categories=["sponsor"]&category=intro`)
fetch(`${endpoint}?videoID=getSkipSegmentID0&categories=["sponsor"]&category=intro`)
.then(async res => {
assert.strictEqual(res.status, 200);
const data = await res.json();
@ -346,15 +347,17 @@ describe("getSkipSegments", () => {
});
it("Should be able to get specific segments with requiredSegments", (done: Done) => {
fetch(`${getbaseURL()}/api/skipSegments?videoID=requiredSegmentVid&requiredSegments=["requiredSegmentVid2","requiredSegmentVid3"]`)
const required2 = "requiredSegmentVid2";
const required3 = "requiredSegmentVid3";
fetch(`${endpoint}?videoID=requiredSegmentVid&requiredSegments=["${required2}","${required3}"]`)
.then(async res => {
assert.strictEqual(res.status, 200);
const data = await res.json();
assert.strictEqual(data.length, 2);
const expected = [{
UUID: "requiredSegmentVid2",
UUID: required2,
}, {
UUID: "requiredSegmentVid3",
UUID: required3,
}];
assert.ok(partialDeepEquals(data, expected));
done();
@ -363,15 +366,17 @@ describe("getSkipSegments", () => {
});
it("Should be able to get specific segments with repeating requiredSegment", (done: Done) => {
fetch(`${getbaseURL()}/api/skipSegments?videoID=requiredSegmentVid&requiredSegment=requiredSegmentVid2&requiredSegment=requiredSegmentVid3`)
const required2 = "requiredSegmentVid2";
const required3 = "requiredSegmentVid3";
fetch(`${endpoint}?videoID=requiredSegmentVid&requiredSegment=${required2}&requiredSegment=${required3}`)
.then(async res => {
assert.strictEqual(res.status, 200);
const data = await res.json();
assert.strictEqual(data.length, 2);
const expected = [{
UUID: "requiredSegmentVid2",
UUID: required2,
}, {
UUID: "requiredSegmentVid3",
UUID: required3,
}];
assert.ok(partialDeepEquals(data, expected));
done();
@ -380,7 +385,7 @@ describe("getSkipSegments", () => {
});
it("Should get 400 if no videoID passed in", (done: Done) => {
fetch(`${getbaseURL()}/api/skipSegments`)
fetch(`${endpoint}`)
.then(async res => {
assert.strictEqual(res.status, 400);
done();

View file

@ -1,6 +1,6 @@
import fetch from "node-fetch";
import {db} from "../../src/databases/databases";
import {Done, getbaseURL, partialDeepEquals} from "../utils";
import {Done, getbaseURL, partialDeepEquals, postJSON} from "../utils";
import {getHash} from "../../src/utils/getHash";
import {ImportMock,} from "ts-mock-imports";
import * as YouTubeAPIModule from "../../src/utils/youtubeApi";
@ -12,6 +12,7 @@ const sinonStub = mockManager.mock("listVideos");
sinonStub.callsFake(YouTubeApiMock.listVideos);
describe("getSkipSegmentsByHash", () => {
const endpoint = `${getbaseURL()}/api/skipSegments`;
const getSegmentsByHash0Hash = "fdaff4dee1043451faa7398324fb63d8618ebcd11bddfe0491c488db12c6c910";
const requiredSegmentVidHash = "d51822c3f681e07aef15a8855f52ad12db9eb9cf059e65b16b64c43359557f61";
before(async () => {
@ -32,7 +33,7 @@ describe("getSkipSegmentsByHash", () => {
});
it("Should be able to get a 200", (done: Done) => {
fetch(`${getbaseURL()}/api/skipSegments/3272f?categories=["sponsor", "intro"]`)
fetch(`${endpoint}/3272f?categories=["sponsor", "intro"]`)
.then(res => {
assert.strictEqual(res.status, 200);
done();
@ -41,7 +42,7 @@ describe("getSkipSegmentsByHash", () => {
});
it("Should return 404 if no segments are found even if a video for the given hash is known", (done: Done) => {
fetch(`${getbaseURL()}/api/skipSegments/3272f?categories=["shilling"]`)
fetch(`${endpoint}/3272f?categories=["shilling"]`)
.then(async res => {
assert.strictEqual(res.status, 404);
const expected = "[]";
@ -53,7 +54,7 @@ describe("getSkipSegmentsByHash", () => {
});
it("Should be able to get an empty array if no videos", (done: Done) => {
fetch(`${getbaseURL()}/api/skipSegments/11111?categories=["shilling"]`)
fetch(`${endpoint}/11111?categories=["shilling"]`)
.then(async res => {
assert.strictEqual(res.status, 404);
const body = await res.text();
@ -66,7 +67,7 @@ describe("getSkipSegmentsByHash", () => {
});
it("Should be able to get an empty array if only hidden videos", (done: Done) => {
fetch(`${getbaseURL()}/api/skipSegments/f3a1?categories=["sponsor"]`)
fetch(`${endpoint}/f3a1?categories=["sponsor"]`)
.then(async res => {
if (res.status !== 404) done(`non 404 status code, was ${res.status}`);
else {
@ -79,7 +80,7 @@ describe("getSkipSegmentsByHash", () => {
});
it("Should return 400 prefix too short", (done: Done) => {
fetch(`${getbaseURL()}/api/skipSegments/11?categories=["shilling"]`)
fetch(`${endpoint}/11?categories=["shilling"]`)
.then(res => {
assert.strictEqual(res.status, 400);
done();
@ -90,7 +91,7 @@ describe("getSkipSegmentsByHash", () => {
it("Should return 400 prefix too long", (done: Done) => {
const prefix = "1".repeat(50);
assert.ok(prefix.length > 33, "failed to generate long enough string");
fetch(`${getbaseURL()}/api/skipSegments/${prefix}?categories=["shilling"]`)
fetch(`${endpoint}/${prefix}?categories=["shilling"]`)
.then(res => {
assert.strictEqual(res.status, 400);
done();
@ -100,7 +101,7 @@ describe("getSkipSegmentsByHash", () => {
it("Should return 404 prefix in range", (done: Done) => {
const prefix = "1".repeat(5);
fetch(`${getbaseURL()}/api/skipSegments/${prefix}?categories=["shilling"]`)
fetch(`${endpoint}/${prefix}?categories=["shilling"]`)
.then(res => {
assert.strictEqual(res.status, 404);
done();
@ -109,7 +110,7 @@ describe("getSkipSegmentsByHash", () => {
});
it("Should return 400 for no hash", (done: Done) => {
fetch(`${getbaseURL()}/api/skipSegments/?categories=["shilling"]`)
fetch(`${endpoint}/?categories=["shilling"]`)
.then(res => {
assert.strictEqual(res.status, 400);
done();
@ -118,7 +119,7 @@ describe("getSkipSegmentsByHash", () => {
});
it("Should return 400 for bad format categories", (done: Done) => {
fetch(`${getbaseURL()}/api/skipSegments/fdaf?categories=shilling`)
fetch(`${endpoint}/fdaf?categories=shilling`)
.then(res => {
assert.strictEqual(res.status, 400);
done();
@ -127,7 +128,7 @@ describe("getSkipSegmentsByHash", () => {
});
it("Should be able to get multiple videos", (done: Done) => {
fetch(`${getbaseURL()}/api/skipSegments/fdaf?categories=["sponsor","intro"]`)
fetch(`${endpoint}/fdaf?categories=["sponsor","intro"]`)
.then(async res => {
assert.strictEqual(res.status, 200);
const data = await res.json();
@ -140,7 +141,7 @@ describe("getSkipSegmentsByHash", () => {
});
it("Should be able to get 200 for no categories (default sponsor)", (done: Done) => {
fetch(`${getbaseURL()}/api/skipSegments/fdaf`)
fetch(`${endpoint}/fdaf`)
.then(async res => {
assert.strictEqual(res.status, 200);
const data = await res.json();
@ -164,7 +165,7 @@ describe("getSkipSegmentsByHash", () => {
});
it("Should be able to get 200 for no categories (default sponsor) with action type", (done: Done) => {
fetch(`${getbaseURL()}/api/skipSegments/fdaf?actionType=skip`)
fetch(`${endpoint}/fdaf?actionType=skip`)
.then(async res => {
assert.strictEqual(res.status, 200);
const data = await res.json();
@ -188,7 +189,7 @@ describe("getSkipSegmentsByHash", () => {
});
it("Should be able to get 200 for no categories (default sponsor) with multiple action types", (done: Done) => {
fetch(`${getbaseURL()}/api/skipSegments/fdaf?actionType=skip&actionType=mute`)
fetch(`${endpoint}/fdaf?actionType=skip&actionType=mute`)
.then(async res => {
assert.strictEqual(res.status, 200);
const data = await res.json();
@ -214,7 +215,7 @@ describe("getSkipSegmentsByHash", () => {
});
it("Should be able to get 200 for no categories (default sponsor) with multiple action types (JSON array)", (done: Done) => {
fetch(`${getbaseURL()}/api/skipSegments/fdaf?actionTypes=["skip","mute"]`)
fetch(`${endpoint}/fdaf?actionTypes=["skip","mute"]`)
.then(async res => {
assert.strictEqual(res.status, 200);
const data = await res.json();
@ -238,7 +239,7 @@ describe("getSkipSegmentsByHash", () => {
});
it("Should be able to get 200 for no categories (default sponsor) for a non YouTube service", (done: Done) => {
fetch(`${getbaseURL()}/api/skipSegments/fdaf?service=PeerTube`)
fetch(`${endpoint}/fdaf?service=PeerTube`)
.then(async res => {
assert.strictEqual(res.status, 200);
const data = await res.json();
@ -256,7 +257,7 @@ describe("getSkipSegmentsByHash", () => {
});
it("Should only return one segment when fetching highlight segments", (done: Done) => {
fetch(`${getbaseURL()}/api/skipSegments/c962?category=poi_highlight`)
fetch(`${endpoint}/c962?category=poi_highlight`)
.then(async res => {
assert.strictEqual(res.status, 200);
const data = await res.json();
@ -270,10 +271,7 @@ describe("getSkipSegmentsByHash", () => {
it("Should be able to post a segment and get it using endpoint", (done: Done) => {
const testID = "abc123goodVideo";
fetch(`${getbaseURL()}/api/postVideoSponsorTimes`, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
...postJSON,
body: JSON.stringify({
userID: "test-qwertyuiopasdfghjklzxcvbnm",
videoID: testID,
@ -284,7 +282,7 @@ describe("getSkipSegmentsByHash", () => {
}),
})
.then(async () => {
fetch(`${getbaseURL()}/api/skipSegments/${getHash(testID, 1).substring(0, 3)}`)
fetch(`${endpoint}/${getHash(testID, 1).substring(0, 3)}`)
.then(async res => {
assert.strictEqual(res.status, 200);
const data = await res.json();
@ -304,7 +302,7 @@ describe("getSkipSegmentsByHash", () => {
});
it("Should be able to get multiple categories with repeating parameters", (done: Done) => {
fetch(`${getbaseURL()}/api/skipSegments/fdaff4?&category=sponsor&category=intro`)
fetch(`${endpoint}/fdaff4?&category=sponsor&category=intro`)
.then(async res => {
assert.strictEqual(res.status, 200);
const data = await res.json();
@ -327,7 +325,7 @@ describe("getSkipSegmentsByHash", () => {
});
it("Should be able to get specific segments with requiredSegments", (done: Done) => {
fetch(`${getbaseURL()}/api/skipSegments/d518?requiredSegments=["requiredSegmentVid-2","requiredSegmentVid-3"]`)
fetch(`${endpoint}/d518?requiredSegments=["requiredSegmentVid-2","requiredSegmentVid-3"]`)
.then(async res => {
assert.strictEqual(res.status, 200);
const data = await res.json();
@ -347,7 +345,7 @@ describe("getSkipSegmentsByHash", () => {
});
it("Should be able to get specific segments with repeating requiredSegment", (done: Done) => {
fetch(`${getbaseURL()}/api/skipSegments/d518?requiredSegment=requiredSegmentVid-2&requiredSegment=requiredSegmentVid-3`)
fetch(`${endpoint}/d518?requiredSegment=requiredSegmentVid-2&requiredSegment=requiredSegmentVid-3`)
.then(async res => {
assert.strictEqual(res.status, 200);
const data = await res.json();

View file

@ -6,12 +6,13 @@ import {db} from "../../src/databases/databases";
let dbVersion: number;
describe("getStatus", () => {
const endpoint = `${getbaseURL()}/api/status`;
before(async () => {
dbVersion = (await db.prepare("get", "SELECT key, value FROM config where key = ?", ["version"])).value;
});
it("Should be able to get status", (done: Done) => {
fetch(`${getbaseURL()}/api/status`)
fetch(endpoint)
.then(async res => {
assert.strictEqual(res.status, 200);
const data = await res.json();
@ -26,7 +27,7 @@ describe("getStatus", () => {
});
it("Should be able to get uptime only", (done: Done) => {
fetch(`${getbaseURL()}/api/status/uptime`)
fetch(`${endpoint}/uptime`)
.then(async res => {
assert.strictEqual(res.status, 200);
const data = await res.text();
@ -37,7 +38,7 @@ describe("getStatus", () => {
});
it("Should be able to get commit only", (done: Done) => {
fetch(`${getbaseURL()}/api/status/commit`)
fetch(`${endpoint}/commit`)
.then(async res => {
assert.strictEqual(res.status, 200);
const data = await res.text();
@ -48,7 +49,7 @@ describe("getStatus", () => {
});
it("Should be able to get db only", (done: Done) => {
fetch(`${getbaseURL()}/api/status/db`)
fetch(`${endpoint}/db`)
.then(async res => {
assert.strictEqual(res.status, 200);
const data = await res.text();
@ -59,7 +60,7 @@ describe("getStatus", () => {
});
it("Should be able to get startTime only", (done: Done) => {
fetch(`${getbaseURL()}/api/status/startTime`)
fetch(`${endpoint}/startTime`)
.then(async res => {
assert.strictEqual(res.status, 200);
const data = await res.text();
@ -71,7 +72,7 @@ describe("getStatus", () => {
});
it("Should be able to get processTime only", (done: Done) => {
fetch(`${getbaseURL()}/api/status/processTime`)
fetch(`${endpoint}/processTime`)
.then(async res => {
assert.strictEqual(res.status, 200);
const data = await res.text();

View file

@ -5,6 +5,7 @@ import {getHash} from "../../src/utils/getHash";
import assert from "assert";
describe("getUserID", () => {
const endpoint = `${getbaseURL()}/api/userID`;
before(async () => {
const insertUserNameQuery = 'INSERT INTO "userNames" ("userID", "userName") VALUES(?, ?)';
await db.prepare("run", insertUserNameQuery, [getHash("getuserid_user_01"), "fuzzy user 01"]);
@ -22,7 +23,7 @@ describe("getUserID", () => {
});
it("Should be able to get a 200", (done: Done) => {
fetch(`${getbaseURL()}/api/userID?username=fuzzy+user+01`)
fetch(`${endpoint}?username=fuzzy+user+01`)
.then(async res => {
assert.strictEqual(res.status, 200);
done();
@ -31,7 +32,7 @@ describe("getUserID", () => {
});
it("Should be able to get a 400 (No username parameter)", (done: Done) => {
fetch(`${getbaseURL()}/api/userID`)
fetch(endpoint)
.then(res => {
assert.strictEqual(res.status, 400);
done();
@ -40,7 +41,7 @@ describe("getUserID", () => {
});
it("Should be able to get a 200 (username is public id)", (done: Done) => {
fetch(`${getbaseURL()}/api/userID?username=${getHash("getuserid_user_06")}`)
fetch(`${endpoint}?username=${getHash("getuserid_user_06")}`)
.then(async res => {
assert.strictEqual(res.status, 200);
done();
@ -49,7 +50,7 @@ describe("getUserID", () => {
});
it("Should be able to get a 400 (username longer than 64 chars)", (done: Done) => {
fetch(`${getbaseURL()}/api/userID?username=${getHash("getuserid_user_06")}0`)
fetch(`${endpoint}?username=${getHash("getuserid_user_06")}0`)
.then(res => {
assert.strictEqual(res.status, 400);
done();
@ -58,7 +59,7 @@ describe("getUserID", () => {
});
it("Should be able to get single username", (done: Done) => {
fetch(`${getbaseURL()}/api/userID?username=fuzzy+user+01`)
fetch(`${endpoint}?username=fuzzy+user+01`)
.then(async res => {
assert.strictEqual(res.status, 200);
const expected = [{
@ -73,7 +74,7 @@ describe("getUserID", () => {
});
it("Should be able to get multiple fuzzy user info from start", (done: Done) => {
fetch(`${getbaseURL()}/api/userID?username=fuzzy+user`)
fetch(`${endpoint}?username=fuzzy+user`)
.then(async res => {
assert.strictEqual(res.status, 200);
const expected = [{
@ -91,7 +92,7 @@ describe("getUserID", () => {
});
it("Should be able to get multiple fuzzy user info from middle", (done: Done) => {
fetch(`${getbaseURL()}/api/userID?username=user`)
fetch(`${endpoint}?username=user`)
.then(async res => {
assert.strictEqual(res.status, 200);
const expected = [{
@ -113,7 +114,7 @@ describe("getUserID", () => {
it("Should be able to get with public ID", (done: Done) => {
const userID = getHash("getuserid_user_06");
fetch(`${getbaseURL()}/api/userID?username=${userID}`)
fetch(`${endpoint}?username=${userID}`)
.then(async res => {
assert.strictEqual(res.status, 200);
const expected = [{
@ -129,7 +130,7 @@ describe("getUserID", () => {
it("Should be able to get with fuzzy public ID", (done: Done) => {
const userID = getHash("getuserid_user_06");
fetch(`${getbaseURL()}/api/userID?username=${userID.substr(10,60)}`)
fetch(`${endpoint}?username=${userID.substr(10,60)}`)
.then(async res => {
assert.strictEqual(res.status, 200);
const expected = [{
@ -144,7 +145,7 @@ describe("getUserID", () => {
});
it("Should be able to get repeating username", (done: Done) => {
fetch(`${getbaseURL()}/api/userID?username=repeating`)
fetch(`${endpoint}?username=repeating`)
.then(async res => {
assert.strictEqual(res.status, 200);
const expected = [{
@ -162,7 +163,7 @@ describe("getUserID", () => {
});
it("Should be able to get repeating fuzzy username", (done: Done) => {
fetch(`${getbaseURL()}/api/userID?username=peat`)
fetch(`${endpoint}?username=peat`)
.then(async res => {
assert.strictEqual(res.status, 200);
const expected = [{
@ -180,7 +181,7 @@ describe("getUserID", () => {
});
it("should avoid ReDOS with _", (done: Done) => {
fetch(`${getbaseURL()}/api/userID?username=_redos_`)
fetch(`${endpoint}?username=_redos_`)
.then(async res => {
assert.strictEqual(res.status, 200);
const expected = [{
@ -195,7 +196,7 @@ describe("getUserID", () => {
});
it("should avoid ReDOS with %", (done: Done) => {
fetch(`${getbaseURL()}/api/userID?username=%redos%`)
fetch(`${endpoint}?username=%redos%`)
.then(async res => {
assert.strictEqual(res.status, 200);
const expected = [{
@ -210,7 +211,7 @@ describe("getUserID", () => {
});
it("should return 404 if escaped backslashes present", (done: Done) => {
fetch(`${getbaseURL()}/api/userID?username=%redos\\\\_`)
fetch(`${endpoint}?username=%redos\\\\_`)
.then(res => {
assert.strictEqual(res.status, 404);
done();
@ -219,7 +220,7 @@ describe("getUserID", () => {
});
it("should return 404 if backslashes present", (done: Done) => {
fetch(`${getbaseURL()}/api/userID?username=\\%redos\\_`)
fetch(`${endpoint}?username=\\%redos\\_`)
.then(res => {
assert.strictEqual(res.status, 404);
done();
@ -228,7 +229,7 @@ describe("getUserID", () => {
});
it("should return user if just backslashes", (done: Done) => {
fetch(`${getbaseURL()}/api/userID?username=\\\\\\`)
fetch(`${endpoint}?username=\\\\\\`)
.then(async res => {
assert.strictEqual(res.status, 200);
const expected = [{
@ -243,7 +244,7 @@ describe("getUserID", () => {
});
it("should not allow usernames more than 64 characters", (done: Done) => {
fetch(`${getbaseURL()}/api/userID?username=${"0".repeat(65)}`)
fetch(`${endpoint}?username=${"0".repeat(65)}`)
.then(res => {
assert.strictEqual(res.status, 400);
done();
@ -252,7 +253,7 @@ describe("getUserID", () => {
});
it("should not allow usernames less than 3 characters", (done: Done) => {
fetch(`${getbaseURL()}/api/userID?username=aa`)
fetch(`${endpoint}?username=aa`)
.then(res => {
assert.strictEqual(res.status, 400);
done();
@ -261,7 +262,7 @@ describe("getUserID", () => {
});
it("should allow exact match", (done: Done) => {
fetch(`${getbaseURL()}/api/userID?username=a&exact=true`)
fetch(`${endpoint}?username=a&exact=true`)
.then(async res => {
assert.strictEqual(res.status, 200);
const expected = [{
@ -276,7 +277,7 @@ describe("getUserID", () => {
});
it("Should be able to get repeating username with exact username", (done: Done) => {
fetch(`${getbaseURL()}/api/userID?username=repeating&exact=true`)
fetch(`${endpoint}?username=repeating&exact=true`)
.then(async res => {
assert.strictEqual(res.status, 200);
const expected = [{
@ -294,7 +295,7 @@ describe("getUserID", () => {
});
it("Should not get exact unless explicitly set to true", (done: Done) => {
fetch(`${getbaseURL()}/api/userID?username=user&exact=1`)
fetch(`${endpoint}?username=user&exact=1`)
.then(async res => {
assert.strictEqual(res.status, 200);
const expected = [{
@ -315,7 +316,7 @@ describe("getUserID", () => {
});
it("should return 400 if no username parameter specified", (done: Done) => {
fetch(`${getbaseURL()}/api/userID`)
fetch(endpoint)
.then(res => {
assert.strictEqual(res.status, 400);
done();

View file

@ -5,6 +5,7 @@ import {getHash} from "../../src/utils/getHash";
import assert from "assert";
describe("getUserInfo", () => {
const endpoint = `${getbaseURL()}/api/userInfo`;
before(async () => {
const insertUserNameQuery = 'INSERT INTO "userNames" ("userID", "userName") VALUES(?, ?)';
await db.prepare("run", insertUserNameQuery, [getHash("getuserinfo_user_01"), "Username user 01"]);
@ -34,7 +35,7 @@ describe("getUserInfo", () => {
});
it("Should be able to get a 200", (done: Done) => {
fetch(`${getbaseURL()}/api/userInfo?userID=getuserinfo_user_01`)
fetch(`${endpoint}?userID=getuserinfo_user_01`)
.then(res => {
assert.strictEqual(res.status, 200);
done();
@ -43,7 +44,7 @@ describe("getUserInfo", () => {
});
it("Should be able to get a 400 (No userID parameter)", (done: Done) => {
fetch(`${getbaseURL()}/api/userInfo`)
fetch(endpoint)
.then(res => {
assert.strictEqual(res.status, 400);
done();
@ -52,7 +53,7 @@ describe("getUserInfo", () => {
});
it("Should be able to get user info", (done: Done) => {
fetch(`${getbaseURL()}/api/userInfo?userID=getuserinfo_user_01`)
fetch(`${endpoint}?userID=getuserinfo_user_01`)
.then(async res => {
assert.strictEqual(res.status, 200);
const expected = {
@ -77,7 +78,7 @@ describe("getUserInfo", () => {
});
it("Should get warning data", (done: Done) => {
fetch(`${getbaseURL()}/api/userInfo?userID=getuserinfo_warning_0&value=warnings`)
fetch(`${endpoint}?userID=getuserinfo_warning_0&value=warnings`)
.then(async res => {
assert.strictEqual(res.status, 200);
const data = await res.json();
@ -91,7 +92,7 @@ describe("getUserInfo", () => {
});
it("Should get warning data with public ID", (done: Done) => {
fetch(`${getbaseURL()}/api/userInfo?publicUserID=${getHash("getuserinfo_warning_0")}&values=["warnings"]`)
fetch(`${endpoint}?publicUserID=${getHash("getuserinfo_warning_0")}&values=["warnings"]`)
.then(async res => {
assert.strictEqual(res.status, 200);
const data = await res.json();
@ -105,7 +106,7 @@ describe("getUserInfo", () => {
});
it("Should get multiple warnings", (done: Done) => {
fetch(`${getbaseURL()}/api/userInfo?userID=getuserinfo_warning_1&value=warnings`)
fetch(`${endpoint}?userID=getuserinfo_warning_1&value=warnings`)
.then(async res => {
assert.strictEqual(res.status, 200);
const data = await res.json();
@ -119,7 +120,7 @@ describe("getUserInfo", () => {
});
it("Should not get warnings if none", (done: Done) => {
fetch(`${getbaseURL()}/api/userInfo?userID=getuserinfo_warning_2&value=warnings`)
fetch(`${endpoint}?userID=getuserinfo_warning_2&value=warnings`)
.then(async res => {
assert.strictEqual(res.status, 200);
const data = await res.json();
@ -133,7 +134,7 @@ describe("getUserInfo", () => {
});
it("Should done(userID for userName (No userName set)", (done: Done) => {
fetch(`${getbaseURL()}/api/userInfo?userID=getuserinfo_user_02&value=userName`)
fetch(`${endpoint}?userID=getuserinfo_user_02&value=userName`)
.then(async res => {
assert.strictEqual(res.status, 200);
const data = await res.json();
@ -147,7 +148,7 @@ describe("getUserInfo", () => {
});
it("Should return null segment if none", (done: Done) => {
fetch(`${getbaseURL()}/api/userInfo?userID=getuserinfo_null&value=lastSegmentID`)
fetch(`${endpoint}?userID=getuserinfo_null&value=lastSegmentID`)
.then(async res => {
assert.strictEqual(res.status, 200);
const data = await res.json();
@ -158,7 +159,7 @@ describe("getUserInfo", () => {
});
it("Should return zeroes if userid does not exist", (done: Done) => {
fetch(`${getbaseURL()}/api/userInfo?userID=getuserinfo_null&value=lastSegmentID`)
fetch(`${endpoint}?userID=getuserinfo_null&value=lastSegmentID`)
.then(async res => {
const data = await res.json();
for (const value in data) {
@ -172,7 +173,7 @@ describe("getUserInfo", () => {
});
it("Should get warning reason from from single enabled warning", (done: Done) => {
fetch(`${getbaseURL()}/api/userInfo?userID=getuserinfo_warning_0&values=["warningReason"]`)
fetch(`${endpoint}?userID=getuserinfo_warning_0&values=["warningReason"]`)
.then(async res => {
assert.strictEqual(res.status, 200);
const data = await res.json();
@ -186,7 +187,7 @@ describe("getUserInfo", () => {
});
it("Should get most recent warning from two enabled warnings", (done: Done) => {
fetch(`${getbaseURL()}/api/userInfo?userID=getuserinfo_warning_1&value=warningReason`)
fetch(`${endpoint}?userID=getuserinfo_warning_1&value=warningReason`)
.then(async res => {
assert.strictEqual(res.status, 200);
const data = await res.json();
@ -200,7 +201,7 @@ describe("getUserInfo", () => {
});
it("Should not get disabled warning", (done: Done) => {
fetch(`${getbaseURL()}/api/userInfo?userID=getuserinfo_warning_2&values=["warnings","warningReason"]`)
fetch(`${endpoint}?userID=getuserinfo_warning_2&values=["warnings","warningReason"]`)
.then(async res => {
assert.strictEqual(res.status, 200);
const data = await res.json();
@ -215,7 +216,7 @@ describe("getUserInfo", () => {
});
it("Should not get newer disabled warning", (done: Done) => {
fetch(`${getbaseURL()}/api/userInfo?userID=getuserinfo_warning_3&value=warnings&value=warningReason`)
fetch(`${endpoint}?userID=getuserinfo_warning_3&value=warnings&value=warningReason`)
.then(async res => {
assert.strictEqual(res.status, 200);
const data = await res.json();
@ -230,7 +231,7 @@ describe("getUserInfo", () => {
});
it("Should get 400 if bad values specified", (done: Done) => {
fetch(`${getbaseURL()}/api/userInfo?userID=getuserinfo_warning_3&value=invalid-value`)
fetch(`${endpoint}?userID=getuserinfo_warning_3&value=invalid-value`)
.then(async res => {
assert.strictEqual(res.status, 400);
done(); // pass
@ -239,7 +240,7 @@ describe("getUserInfo", () => {
});
it("Should get ban data for banned user (only appears when specifically requested)", (done: Done) => {
fetch(`${getbaseURL()}/api/userInfo?userID=getuserinfo_ban_01&value=banned`)
fetch(`${endpoint}?userID=getuserinfo_ban_01&value=banned`)
.then(async res => {
assert.strictEqual(res.status, 200);
const data = await res.json();
@ -253,7 +254,7 @@ describe("getUserInfo", () => {
});
it("Should get ban data for unbanned user (only appears when specifically requested)", (done: Done) => {
fetch(`${getbaseURL()}/api/userInfo?userID=getuserinfo_notban_01&value=banned`)
fetch(`${endpoint}?userID=getuserinfo_notban_01&value=banned`)
.then(async res => {
assert.strictEqual(res.status, 200);
const data = await res.json();
@ -267,7 +268,7 @@ describe("getUserInfo", () => {
});
it("Should throw 400 on bad json in values", (done: Done) => {
fetch(`${getbaseURL()}/api/userInfo?userID=x&values=[userID]`)
fetch(`${endpoint}?userID=x&values=[userID]`)
.then(async res => {
assert.strictEqual(res.status, 400);
done(); // pass
@ -276,7 +277,7 @@ describe("getUserInfo", () => {
});
it("Should return 200 on userID not found", (done: Done) => {
fetch(`${getbaseURL()}/api/userInfo?userID=notused-userid`)
fetch(`${endpoint}?userID=notused-userid`)
.then(async res => {
assert.strictEqual(res.status, 200);
const data = await res.json();
@ -298,7 +299,7 @@ describe("getUserInfo", () => {
});
it("Should only count long segments as 10 minutes", (done: Done) => {
fetch(`${getbaseURL()}/api/userInfo?userID=getuserinfo_user_03`)
fetch(`${endpoint}?userID=getuserinfo_user_03`)
.then(async res => {
assert.strictEqual(res.status, 200);
const expected = {

View file

@ -1,5 +1,5 @@
import fetch from "node-fetch";
import {Done, getbaseURL} from "../utils";
import {Done, getbaseURL, postJSON} from "../utils";
import {getHash} from "../../src/utils/getHash";
import {db} from "../../src/databases/databases";
import assert from "assert";
@ -13,23 +13,29 @@ const stringDeepEquals = (a: string[] ,b: string[]): boolean => {
return result;
};
const endpoint = `${getbaseURL()}/api/lockCategories`;
const submitEndpoint = `${getbaseURL()}/api/skipSegments`;
const checkLockCategories = (videoID: string): Promise<LockCategory[]> => db.prepare("all", 'SELECT * FROM "lockCategories" WHERE "videoID" = ?', [videoID]);
const lockVIPUser = "lockCategoriesRecordsVIPUser";
const lockVIPUserHash = getHash(lockVIPUser);
describe("lockCategoriesRecords", () => {
before(async () => {
const insertVipUserQuery = 'INSERT INTO "vipUsers" ("userID") VALUES (?)';
await db.prepare("run", insertVipUserQuery, [getHash("lockCategoriesRecordsVIPUser")]);
await db.prepare("run", insertVipUserQuery, [lockVIPUserHash]);
const insertLockCategoryQuery = 'INSERT INTO "lockCategories" ("userID", "videoID", "category", "reason") VALUES (?, ?, ?, ?)';
await db.prepare("run", insertLockCategoryQuery, [getHash("lockCategoriesRecordsVIPUser"), "no-segments-video-id", "sponsor", "reason-1"]);
await db.prepare("run", insertLockCategoryQuery, [getHash("lockCategoriesRecordsVIPUser"), "no-segments-video-id", "intro", "reason-1"]);
await db.prepare("run", insertLockCategoryQuery, [lockVIPUserHash, "no-segments-video-id", "sponsor", "reason-1"]);
await db.prepare("run", insertLockCategoryQuery, [lockVIPUserHash, "no-segments-video-id", "intro", "reason-1"]);
await db.prepare("run", insertLockCategoryQuery, [getHash("lockCategoriesRecordsVIPUser"), "no-segments-video-id-1", "sponsor", "reason-2"]);
await db.prepare("run", insertLockCategoryQuery, [getHash("lockCategoriesRecordsVIPUser"), "no-segments-video-id-1", "intro", "reason-2"]);
await db.prepare("run", insertLockCategoryQuery, [getHash("lockCategoriesRecordsVIPUser"), "lockCategoryVideo", "sponsor", "reason-3"]);
await db.prepare("run", insertLockCategoryQuery, [lockVIPUserHash, "no-segments-video-id-1", "sponsor", "reason-2"]);
await db.prepare("run", insertLockCategoryQuery, [lockVIPUserHash, "no-segments-video-id-1", "intro", "reason-2"]);
await db.prepare("run", insertLockCategoryQuery, [lockVIPUserHash, "lockCategoryVideo", "sponsor", "reason-3"]);
await db.prepare("run", insertLockCategoryQuery, [getHash("lockCategoriesRecordsVIPUser"), "delete-record", "sponsor", "reason-4"]);
await db.prepare("run", insertLockCategoryQuery, [lockVIPUserHash, "delete-record", "sponsor", "reason-4"]);
await db.prepare("run", insertLockCategoryQuery, [getHash("lockCategoriesRecordsVIPUser"), "delete-record-1", "sponsor", "reason-5"]);
await db.prepare("run", insertLockCategoryQuery, [getHash("lockCategoriesRecordsVIPUser"), "delete-record-1", "intro", "reason-5"]);
await db.prepare("run", insertLockCategoryQuery, [lockVIPUserHash, "delete-record-1", "sponsor", "reason-5"]);
await db.prepare("run", insertLockCategoryQuery, [lockVIPUserHash, "delete-record-1", "intro", "reason-5"]);
});
it("Should update the database version when starting the application", async () => {
@ -56,11 +62,8 @@ describe("lockCategoriesRecords", () => {
"shilling",
],
};
fetch(`${getbaseURL()}/api/lockCategories`, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
fetch(endpoint, {
...postJSON,
body: JSON.stringify(json)
})
.then(async res => {
@ -73,9 +76,10 @@ describe("lockCategoriesRecords", () => {
});
it("Should be able to submit categories not in video (sql check)", (done: Done) => {
const videoID = "no-segments-video-id-1";
const json = {
videoID: "no-segments-video-id-1",
userID: "lockCategoriesRecordsVIPUser",
videoID,
userID: lockVIPUser,
categories: [
"outro",
"shilling",
@ -85,25 +89,20 @@ describe("lockCategoriesRecords", () => {
"intro",
],
};
fetch(`${getbaseURL()}/api/lockCategories`, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
fetch(endpoint, {
...postJSON,
body: JSON.stringify(json)
})
.then(async res => {
assert.strictEqual(res.status, 200);
const result = await db.prepare("all", 'SELECT * FROM "lockCategories" WHERE "videoID" = ?', ["no-segments-video-id-1"]) as LockCategory[];
const result = await checkLockCategories(videoID);
assert.strictEqual(result.length, 4);
const oldRecordNotChangeReason = result.filter(item =>
item.reason === "reason-2" && ["sponsor", "intro"].includes(item.category)
);
const newRecordWithEmptyReason = result.filter(item =>
item.reason === "" && ["outro", "shilling"].includes(item.category)
);
assert.strictEqual(newRecordWithEmptyReason.length, 2);
assert.strictEqual(oldRecordNotChangeReason.length, 2);
done();
@ -112,9 +111,10 @@ describe("lockCategoriesRecords", () => {
});
it("Should be able to submit categories not in video with reason (http response)", (done: Done) => {
const videoID = "no-segments-video-id";
const json = {
videoID: "no-segments-video-id",
userID: "lockCategoriesRecordsVIPUser",
videoID,
userID: lockVIPUser,
categories: [
"outro",
"shilling",
@ -134,11 +134,8 @@ describe("lockCategoriesRecords", () => {
],
};
fetch(`${getbaseURL()}/api/lockCategories`, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
fetch(endpoint, {
...postJSON,
body: JSON.stringify(json)
})
.then(async res => {
@ -151,9 +148,10 @@ describe("lockCategoriesRecords", () => {
});
it("Should be able to submit categories not in video with reason (sql check)", (done: Done) => {
const videoID = "no-segments-video-id-1";
const json = {
videoID: "no-segments-video-id-1",
userID: "lockCategoriesRecordsVIPUser",
videoID,
userID: lockVIPUser,
categories: [
"outro",
"shilling",
@ -171,16 +169,13 @@ describe("lockCategoriesRecords", () => {
"intro"
];
fetch(`${getbaseURL()}/api/lockCategories`, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
fetch(endpoint, {
...postJSON,
body: JSON.stringify(json)
})
.then(async res => {
assert.strictEqual(res.status, 200);
const result = await db.prepare("all", 'SELECT * FROM "lockCategories" WHERE "videoID" = ?', ["no-segments-video-id-1"]) as LockCategory[];
const result = await checkLockCategories(videoID);
assert.strictEqual(result.length, 4);
const newRecordWithNewReason = result.filter(item =>
expectedWithNewReason.includes(item.category) && item.reason === "new reason"
@ -199,21 +194,18 @@ describe("lockCategoriesRecords", () => {
it("Should be able to submit categories with _ in the category", (done: Done) => {
const json = {
videoID: "underscore",
userID: "lockCategoriesRecordsVIPUser",
userID: lockVIPUser,
categories: [
"word_word",
],
};
fetch(`${getbaseURL()}/api/lockCategories`, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
fetch(endpoint, {
...postJSON,
body: JSON.stringify(json),
})
.then(async res => {
assert.strictEqual(res.status, 200);
const result = await db.prepare("all", 'SELECT * FROM "lockCategories" WHERE "videoID" = ?', ["underscore"]);
const result = await checkLockCategories("underscore");
assert.strictEqual(result.length, 1);
done();
})
@ -223,21 +215,18 @@ describe("lockCategoriesRecords", () => {
it("Should be able to submit categories with upper and lower case in the category", (done: Done) => {
const json = {
videoID: "bothCases",
userID: "lockCategoriesRecordsVIPUser",
userID: lockVIPUser,
categories: [
"wordWord",
],
};
fetch(`${getbaseURL()}/api/lockCategories`, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
fetch(endpoint, {
...postJSON,
body: JSON.stringify(json),
})
.then(async res => {
assert.strictEqual(res.status, 200);
const result = await db.prepare("all", 'SELECT * FROM "lockCategories" WHERE "videoID" = ?', ["bothCases"]);
const result = await checkLockCategories("bothCases");
assert.strictEqual(result.length, 1);
done();
})
@ -245,24 +234,22 @@ describe("lockCategoriesRecords", () => {
});
it("Should not be able to submit categories with $ in the category", (done: Done) => {
const videoID = "specialChar";
const json = {
videoID: "specialChar",
userID: "lockCategoriesRecordsVIPUser",
videoID,
userID: lockVIPUser,
categories: [
"word&word",
],
};
fetch(`${getbaseURL()}/api/lockCategories`, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
fetch(endpoint, {
...postJSON,
body: JSON.stringify(json),
})
.then(async res => {
assert.strictEqual(res.status, 200);
const result = await db.prepare("all", 'SELECT * FROM "lockCategories" WHERE "videoID" = ?', ["specialChar"]);
const result = await checkLockCategories(videoID);
assert.strictEqual(result.length, 0);
done();
})
@ -270,11 +257,8 @@ describe("lockCategoriesRecords", () => {
});
it("Should return 400 for missing params", (done: Done) => {
fetch(`${getbaseURL()}/api/lockCategories`, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
fetch(endpoint, {
...postJSON,
body: JSON.stringify({}),
})
.then(res => {
@ -290,11 +274,8 @@ describe("lockCategoriesRecords", () => {
userID: "test",
categories: [],
};
fetch(`${getbaseURL()}/api/lockCategories`, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
fetch(endpoint, {
...postJSON,
body: JSON.stringify(json),
})
.then(res => {
@ -311,11 +292,8 @@ describe("lockCategoriesRecords", () => {
categories: ["sponsor"],
};
fetch(`${getbaseURL()}/api/lockCategories`, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
fetch(endpoint, {
...postJSON,
body: JSON.stringify(json),
})
.then(res => {
@ -332,11 +310,8 @@ describe("lockCategoriesRecords", () => {
categories: ["sponsor"],
};
fetch(`${getbaseURL()}/api/lockCategories`, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
fetch(endpoint, {
...postJSON,
body: JSON.stringify(json),
})
.then(res => {
@ -353,11 +328,8 @@ describe("lockCategoriesRecords", () => {
categories: {},
};
fetch(`${getbaseURL()}/api/lockCategories`, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
fetch(endpoint, {
...postJSON,
body: JSON.stringify(json),
})
.then(res => {
@ -374,11 +346,8 @@ describe("lockCategoriesRecords", () => {
categories: "sponsor",
};
fetch(`${getbaseURL()}/api/lockCategories`, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
fetch(endpoint, {
...postJSON,
body: JSON.stringify(json),
})
.then(res => {
@ -397,11 +366,8 @@ describe("lockCategoriesRecords", () => {
],
};
fetch(`${getbaseURL()}/api/lockCategories`, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
fetch(endpoint, {
...postJSON,
body: JSON.stringify(json),
})
.then(res => {
@ -412,15 +378,16 @@ describe("lockCategoriesRecords", () => {
});
it("Should be able to delete a lockCategories record", (done: Done) => {
const videoID = "delete-record";
const json = {
videoID: "delete-record",
userID: "lockCategoriesRecordsVIPUser",
videoID,
userID: lockVIPUser,
categories: [
"sponsor",
],
};
fetch(`${getbaseURL()}/api/lockCategories`, {
fetch(endpoint, {
method: "DELETE",
headers: {
"Content-Type": "application/json",
@ -429,7 +396,7 @@ describe("lockCategoriesRecords", () => {
})
.then(async res => {
assert.strictEqual(res.status, 200);
const result = await db.prepare("all", 'SELECT * FROM "lockCategories" WHERE "videoID" = ?', ["delete-record"]);
const result = await checkLockCategories(videoID);
assert.strictEqual(result.length, 0);
done();
})
@ -437,15 +404,16 @@ describe("lockCategoriesRecords", () => {
});
it("Should be able to delete one lockCategories record without removing another", (done: Done) => {
const videoID = "delete-record-1";
const json = {
videoID: "delete-record-1",
userID: "lockCategoriesRecordsVIPUser",
videoID,
userID: lockVIPUser,
categories: [
"sponsor",
],
};
fetch(`${getbaseURL()}/api/lockCategories`, {
fetch(endpoint, {
method: "DELETE",
headers: {
"Content-Type": "application/json",
@ -454,7 +422,7 @@ describe("lockCategoriesRecords", () => {
})
.then(async res => {
assert.strictEqual(res.status, 200);
const result = await db.prepare("all", 'SELECT * FROM "lockCategories" WHERE "videoID" = ?', ["delete-record-1"]);
const result = await checkLockCategories(videoID);
assert.strictEqual(result.length, 1);
done();
})
@ -466,16 +434,14 @@ describe("lockCategoriesRecords", () => {
* Submission tests in this file do not check database records, only status codes.
* To test the submission code properly see ./test/cases/postSkipSegments.js
*/
const lockedVideoID = "lockCategoryVideo";
const testSubmitUser = "testman42-qwertyuiopasdfghjklzxcvbnm";
it("Should not be able to submit a segment to a video with a lock-category record (single submission)", (done: Done) => {
fetch(`${getbaseURL()}/api/postVideoSponsorTimes`, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
fetch(submitEndpoint, {
...postJSON,
body: JSON.stringify({
userID: "testman42-qwertyuiopasdfghjklzxcvbnm",
videoID: "lockCategoryVideo",
userID: testSubmitUser,
videoID: lockedVideoID,
segments: [{
segment: [20, 40],
category: "sponsor",
@ -490,14 +456,11 @@ describe("lockCategoriesRecords", () => {
});
it("Should not be able to submit segments to a video where any of the submissions with a no-segment record", (done: Done) => {
fetch(`${getbaseURL()}/api/postVideoSponsorTimes`, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
fetch(submitEndpoint, {
...postJSON,
body: JSON.stringify({
userID: "testman42-qwertyuiopasdfghjklzxcvbnm",
videoID: "lockCategoryVideo",
userID: testSubmitUser,
videoID: lockedVideoID,
segments: [{
segment: [20, 40],
category: "sponsor",
@ -516,14 +479,11 @@ describe("lockCategoriesRecords", () => {
it("Should be able to submit a segment to a video with a different no-segment record", (done: Done) => {
fetch(`${getbaseURL()}/api/postVideoSponsorTimes`, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
fetch(submitEndpoint, {
...postJSON,
body: JSON.stringify({
userID: "testman42-qwertyuiopasdfghjklzxcvbnm",
videoID: "lockCategoryVideo",
userID: testSubmitUser,
videoID: lockedVideoID,
segments: [{
segment: [20, 40],
category: "intro",
@ -538,13 +498,10 @@ describe("lockCategoriesRecords", () => {
});
it("Should be able to submit a segment to a video with no no-segment records", (done: Done) => {
fetch(`${getbaseURL()}/api/postVideoSponsorTimes`, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
fetch(submitEndpoint, {
...postJSON,
body: JSON.stringify({
userID: "testman42-qwertyuiopasdfghjklzxcvbnm",
userID: testSubmitUser,
videoID: "normalVideo",
segments: [{
segment: [20, 40],
@ -568,8 +525,7 @@ describe("lockCategoriesRecords", () => {
"shilling"
],
};
fetch(`${getbaseURL()}/api/lockCategories?videoID=` + `no-segments-video-id`)
fetch(`${endpoint}?videoID=no-segments-video-id`)
.then(async res => {
assert.strictEqual(res.status, 200);
const data = await res.json();

View file

@ -3,6 +3,8 @@ import {db} from "../../src/databases/databases";
import {Done, getbaseURL, partialDeepEquals} from "../utils";
import assert from "assert";
const endpoint = `${getbaseURL()}/api/getVideoSponsorTimes`;
describe("getVideoSponsorTime (Old get method)", () => {
before(async () => {
const insertSponsorTimes = 'INSERT INTO "sponsorTimes" ("videoID", "startTime", "endTime", "votes", "UUID", "userID", "timeSubmitted", views, category, "shadowHidden") VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?)';
@ -11,7 +13,7 @@ describe("getVideoSponsorTime (Old get method)", () => {
});
it("Should be able to get a time", (done: Done) => {
fetch(`${getbaseURL()}/api/getVideoSponsorTimes?videoID=oldGetSponsorTime0`)
fetch(`${endpoint}?videoID=oldGetSponsorTime0`)
.then(res => {
assert.strictEqual(res.status, 200);
done();
@ -20,7 +22,7 @@ describe("getVideoSponsorTime (Old get method)", () => {
});
it("Should return 404 if no segment found", (done: Done) => {
fetch(`${getbaseURL()}/api/getVideoSponsorTimes?videoID=notarealvideo`)
fetch(`${endpoint}?videoID=notarealvideo`)
.then(res => {
assert.strictEqual(res.status, 404);
done();