mirror of
https://github.com/ajayyy/SponsorBlockServer.git
synced 2025-12-06 19:47:00 +03:00
everything up to purgeAllSegments
This commit is contained in:
@@ -1,40 +1,43 @@
|
|||||||
import assert from "assert";
|
import {strictEqual, ok} from "assert";
|
||||||
|
|
||||||
import { db } from "../../src/databases/databases";
|
import { db } from "../../src/databases/databases";
|
||||||
import { getHash } from "../../src/utils/getHash";
|
|
||||||
import { archiveDownvoteSegment } from "../../src/cronjob/downvoteSegmentArchiveJob";
|
import { archiveDownvoteSegment } from "../../src/cronjob/downvoteSegmentArchiveJob";
|
||||||
import { DBSegment } from "../../src/types/segments.model";
|
import { DBSegment } from "../../src/types/segments.model";
|
||||||
|
|
||||||
|
const oct2021 = new Date("October 1, 2021").getTime();
|
||||||
|
const nov2021 = new Date("November 1, 2021").getTime();
|
||||||
|
const dec2021 = new Date("December 17, 2021").getTime();
|
||||||
|
const dec2022 = new Date("December 17, 2022").getTime();
|
||||||
|
|
||||||
const records = [
|
const records = [
|
||||||
["testtesttest", 1, 11, 2, 0, "1-uuid-0", "testman", new Date("December 17, 2021").getTime(), 50, "sponsor", "skip", "ytb", 100, 0, 0, getHash("testtesttest", 1)],
|
["dsajVideo0", 0, 0, 2, 0, "dsaj00", "dsajUser", dec2021, 0, 0, 0],
|
||||||
["testtesttest2", 1, 11, 2, 0, "1-uuid-0-1", "testman", new Date("December 17, 2021").getTime(), 50, "sponsor", "skip", "ytb", 120, 0, 0, getHash("testtesttest2", 1)],
|
["dsajVideo0", 0, 0, 2, 0, "dsaj01", "dsajUser", dec2021, 0, 0, 0],
|
||||||
["testtesttest", 12, 14, 2, 0, "1-uuid-0-2", "testman", new Date("December 17, 2021").getTime(), 50, "sponsor", "mute", "ytb", 100, 0, 0, getHash("testtesttest", 1)],
|
["dsajVideo0", 0, 0, 2, 0, "dsaj02", "dsajUser", dec2021, 0, 0, 0],
|
||||||
["testtesttest", 20, 33, 2, 0, "1-uuid-2", "testman", new Date("December 17, 2021").getTime(), 50, "intro", "skip", "ytb", 101, 0, 0, getHash("testtesttest", 1)],
|
["dsajVideo0", 0, 0, 2, 0, "dsaj03", "dsajUser", dec2021, 0, 0, 0],
|
||||||
["testtesttest,test", 1, 11, 2, 0, "1-uuid-1", "testman", new Date("December 17, 2021").getTime(), 50, "sponsor", "skip", "ytb", 140, 0, 0, getHash("testtesttest,test", 1)],
|
["dsajVideo0", 0, 0, 2, 0, "dsaj04", "dsajUser", dec2021, 0, 0, 0,],
|
||||||
|
|
||||||
["test3", 1, 11, 2, 0, "1-uuid-4", "testman", new Date("December 17, 2021").getTime(), 50, "sponsor", "skip", "ytb", 200, 0, 0, getHash("test3", 1)],
|
["dsajVideo1", 0, 0, 2, 0, "dsaj10", "dsajUser", dec2021, 0, 0, 0],
|
||||||
["test3", 7, 22, -3, 0, "1-uuid-5", "testman", new Date("December 17, 2021").getTime(), 50, "sponsor", "skip", "ytb", 300, 0, 0, getHash("test3", 1)],
|
["dsajVideo1", 0, 0, -3, 0, "dsaj11", "dsajUser", dec2021, 0, 0, 0],
|
||||||
|
|
||||||
["multiple", 1, 11, 2, 0, "1-uuid-6", "testman", new Date("December 17, 2021").getTime(), 50, "intro", "skip", "ytb", 400, 0, 0, getHash("multiple", 1)],
|
["dsajVideo2", 0, 0, 2, 0, "dsaj20", "dsajUser", dec2021, 0, 0, 0],
|
||||||
["multiple", 20, 33, -4, 0, "1-uuid-7", "testman", new Date("October 1, 2021").getTime(), 50, "intro", "skip", "ytb", 500, 0, 0, getHash("multiple", 1)],
|
["dsajVideo2", 0, 0, -4, 0, "dsaj21", "dsajUser", oct2021, 0, 0, 0],
|
||||||
|
|
||||||
["locked", 20, 33, 2, 1, "1-uuid-locked-8", "testman", new Date("December 17, 2021").getTime(), 50, "intro", "skip", "ytb", 230, 0, 0, getHash("locked", 1)],
|
["dsajVideo3", 0, 0, 2, 1, "dsaj30", "dsajUser", dec2021, 0, 0, 0],
|
||||||
["locked", 20, 34, 100000, 0, "1-uuid-9", "testman", new Date("December 17, 2021").getTime(), 50, "intro", "skip", "ytb", 190, 0, 0, getHash("locked", 1)],
|
["dsajVideo3", 0, 0, 100000, 0, "dsaj31", "dsajUser", dec2021, 0, 0, 0],
|
||||||
|
|
||||||
["onlyHiddenSegments", 20, 34, 100000, 0, "onlyHiddenSegments", "testman", new Date("December 17, 2021").getTime(), 50, "sponsor", "skip", "ytb", 190, 1, 0, getHash("onlyHiddenSegments", 1)],
|
["dsajVideo4", 0, 0, 100000, 0, "dsaj40", "dsajUser", dec2021, 0, 1, 0],
|
||||||
|
|
||||||
["requiredSegmentVid-raw", 60, 70, 2, 0, "requiredSegmentVid-raw-1", "testman", new Date("December 17, 2021").getTime(), 50, "sponsor", "skip", "ytb", 0, 0, 0, getHash("requiredSegmentVid-raw", 1)],
|
["dsajVideo5", 0, 0, 2, 0, "dsaj50", "dsajUser", dec2021, 0, 0, 0],
|
||||||
["requiredSegmentVid-raw", 60, 70, -1, 0, "requiredSegmentVid-raw-2", "testman", new Date("December 17, 2021").getTime(), 50, "sponsor", "skip", "ytb", 0, 0, 0, getHash("requiredSegmentVid-raw", 1)],
|
["dsajVideo5", 0, 0, -1, 0, "dsaj51", "dsajUser", dec2021, 0, 0, 0],
|
||||||
["requiredSegmentVid-raw", 80, 90, -2, 0, "requiredSegmentVid-raw-3", "testman", new Date("November 17, 2021").getTime(), 50, "sponsor", "skip", "ytb", 0, 0, 0, getHash("requiredSegmentVid-raw", 1)],
|
["dsajVideo5", 0, 0, -2, 0, "dsaj52", "dsajUser", nov2021, 0, 0, 0],
|
||||||
["requiredSegmentVid-raw", 80, 90, 2, 0, "requiredSegmentVid-raw-4", "testman", new Date("December 17, 2021").getTime(), 50, "sponsor", "skip", "ytb", 0, 0, 0, getHash("requiredSegmentVid-raw", 1)]
|
["dsajVideo5", 0, 0, 2, 0, "dsaj53", "dsajUser", dec2021, 0, 0, 0]
|
||||||
];
|
];
|
||||||
|
|
||||||
describe("downvoteSegmentArchiveJob", () => {
|
describe("downvoteSegmentArchiveJob", () => {
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
const query = 'INSERT INTO "sponsorTimes" ("videoID", "startTime", "endTime", "votes", "locked", "UUID", "userID", "timeSubmitted", views, category, "actionType", "service", "videoDuration", "hidden", "shadowHidden", "hashedVideoID") VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)';
|
const query = 'INSERT INTO "sponsorTimes" ("videoID", "startTime", "endTime", "votes", "locked", "UUID", "userID", "timeSubmitted", "views", "hidden", "shadowHidden") VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)';
|
||||||
|
|
||||||
for (let i = 0; i < records.length; i += 1) {
|
for (const record of records) {
|
||||||
await db.prepare("run", query, records[i]);
|
await db.prepare("run", query, record);
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
@@ -42,7 +45,7 @@ describe("downvoteSegmentArchiveJob", () => {
|
|||||||
|
|
||||||
it("Should update the database version when starting the application", async () => {
|
it("Should update the database version when starting the application", async () => {
|
||||||
const version = (await db.prepare("get", "SELECT key, value FROM config where key = ?", ["version"])).value;
|
const version = (await db.prepare("get", "SELECT key, value FROM config where key = ?", ["version"])).value;
|
||||||
assert.ok(version >= 21, "version should be greater or equal to 21");
|
ok(version >= 21, "version should be greater or equal to 21");
|
||||||
});
|
});
|
||||||
|
|
||||||
afterEach(async () => {
|
afterEach(async () => {
|
||||||
@@ -50,12 +53,10 @@ describe("downvoteSegmentArchiveJob", () => {
|
|||||||
await db.prepare("run", 'DELETE FROM "archivedSponsorTimes"');
|
await db.prepare("run", 'DELETE FROM "archivedSponsorTimes"');
|
||||||
});
|
});
|
||||||
|
|
||||||
const getArchivedSegment = (): Promise<DBSegment[]> => {
|
const getArchivedSegment = (): Promise<DBSegment[]> => db.prepare("all", 'SELECT * FROM "archivedSponsorTimes"');
|
||||||
return db.prepare("all", 'SELECT * FROM "archivedSponsorTimes"');
|
|
||||||
};
|
|
||||||
|
|
||||||
const getSegmentsInMainTable = (dayLimit: number, voteLimit: number, now: number): Promise<DBSegment[]> => {
|
const getSegmentsInMainTable = (dayLimit: number, voteLimit: number, now: number): Promise<DBSegment[]> =>
|
||||||
return db.prepare(
|
db.prepare(
|
||||||
"all",
|
"all",
|
||||||
'SELECT * FROM "sponsorTimes" WHERE "votes" < ? AND (? - "timeSubmitted") > ?',
|
'SELECT * FROM "sponsorTimes" WHERE "votes" < ? AND (? - "timeSubmitted") > ?',
|
||||||
[
|
[
|
||||||
@@ -64,109 +65,107 @@ describe("downvoteSegmentArchiveJob", () => {
|
|||||||
dayLimit * 86400000,
|
dayLimit * 86400000,
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
};
|
|
||||||
|
|
||||||
const countSegmentInMainTable = (): Promise<number> => {
|
const countSegmentInMainTable = (): Promise<number> =>
|
||||||
return db.prepare(
|
db.prepare(
|
||||||
"get",
|
"get",
|
||||||
'SELECT COUNT(*) as count FROM "sponsorTimes"'
|
'SELECT COUNT(*) as count FROM "sponsorTimes"'
|
||||||
).then(res => res.count);
|
).then(res => res.count);
|
||||||
};
|
|
||||||
|
|
||||||
it("Should archive all records match", async () => {
|
it("Should archive all records match", async () => {
|
||||||
const dayLimit = 20;
|
const dayLimit = 20;
|
||||||
const voteLimit = 0;
|
const voteLimit = 0;
|
||||||
const time = new Date("December 17, 2022").getTime();
|
const time = dec2022;
|
||||||
const res = await archiveDownvoteSegment(dayLimit, voteLimit, time);
|
const res = await archiveDownvoteSegment(dayLimit, voteLimit, time);
|
||||||
assert.strictEqual(res, 0, "Expection in archiveDownvoteSegment");
|
strictEqual(res, 0, "Expection in archiveDownvoteSegment");
|
||||||
|
|
||||||
// check segments in archived table
|
// check segments in archived table
|
||||||
const archivedSegment = await getArchivedSegment();
|
const archivedSegment = await getArchivedSegment();
|
||||||
assert.strictEqual(archivedSegment.length, 4, `Incorrect segment in archiveTable: ${archivedSegment.length} instead of 4`);
|
strictEqual(archivedSegment.length, 4, `Incorrect segment in archiveTable: ${archivedSegment.length} instead of 4`);
|
||||||
|
|
||||||
// check segments not in main table
|
// check segments not in main table
|
||||||
const segments = await getSegmentsInMainTable(dayLimit, voteLimit, time);
|
const segments = await getSegmentsInMainTable(dayLimit, voteLimit, time);
|
||||||
assert.strictEqual(segments.length, 0, `Incorrect segment in main table: ${segments.length} instead of 0`);
|
strictEqual(segments.length, 0, `Incorrect segment in main table: ${segments.length} instead of 0`);
|
||||||
|
|
||||||
// check number segments remain in main table
|
// check number segments remain in main table
|
||||||
assert.strictEqual(await countSegmentInMainTable(), records.length - archivedSegment.length ,"Incorrect segment remain in main table");
|
strictEqual(await countSegmentInMainTable(), records.length - archivedSegment.length ,"Incorrect segment remain in main table");
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should archive records with vote < -1 match", async () => {
|
it("Should archive records with vote < -1 match", async () => {
|
||||||
const dayLimit = 20;
|
const dayLimit = 20;
|
||||||
const voteLimit = -1;
|
const voteLimit = -1;
|
||||||
const time = new Date("December 17, 2022").getTime();
|
const time = dec2022;
|
||||||
const res = await archiveDownvoteSegment(dayLimit, voteLimit, time);
|
const res = await archiveDownvoteSegment(dayLimit, voteLimit, time);
|
||||||
assert.strictEqual(res, 0, "");
|
strictEqual(res, 0, "");
|
||||||
|
|
||||||
// check segments in archived table
|
// check segments in archived table
|
||||||
const archivedSegment = await getArchivedSegment();
|
const archivedSegment = await getArchivedSegment();
|
||||||
assert.strictEqual(archivedSegment.length, 3, `Incorrect segment in archiveTable: ${archivedSegment.length} instead of 3`);
|
strictEqual(archivedSegment.length, 3, `Incorrect segment in archiveTable: ${archivedSegment.length} instead of 3`);
|
||||||
|
|
||||||
// check segments not in main table
|
// check segments not in main table
|
||||||
const segments = await getSegmentsInMainTable(dayLimit, voteLimit, time);
|
const segments = await getSegmentsInMainTable(dayLimit, voteLimit, time);
|
||||||
assert.strictEqual(segments.length, 0, `Incorrect segment in main table: ${segments.length} instead of 0`);
|
strictEqual(segments.length, 0, `Incorrect segment in main table: ${segments.length} instead of 0`);
|
||||||
|
|
||||||
// check number segments remain in main table
|
// check number segments remain in main table
|
||||||
assert.strictEqual(await countSegmentInMainTable(), records.length - archivedSegment.length ,"Incorrect segment remain in main table");
|
strictEqual(await countSegmentInMainTable(), records.length - archivedSegment.length ,"Incorrect segment remain in main table");
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should archive records with vote < -2 and day < 30 match", async () => {
|
it("Should archive records with vote < -2 and day < 30 match", async () => {
|
||||||
const dayLimit = 30;
|
const dayLimit = 30;
|
||||||
const voteLimit = -2;
|
const voteLimit = -2;
|
||||||
const time = new Date("December 17, 2021").getTime();
|
const time = dec2021;
|
||||||
const res = await archiveDownvoteSegment(dayLimit, voteLimit, time);
|
const res = await archiveDownvoteSegment(dayLimit, voteLimit, time);
|
||||||
assert.strictEqual(res, 0, "");
|
strictEqual(res, 0, "");
|
||||||
|
|
||||||
// check segments in archived table
|
// check segments in archived table
|
||||||
const archivedSegment = await getArchivedSegment();
|
const archivedSegment = await getArchivedSegment();
|
||||||
assert.strictEqual(archivedSegment.length, 1, `Incorrect segment in archiveTable: ${archivedSegment.length} instead of 1`);
|
strictEqual(archivedSegment.length, 1, `Incorrect segment in archiveTable: ${archivedSegment.length} instead of 1`);
|
||||||
|
|
||||||
assert.strictEqual(archivedSegment[0].votes, -4, `Incorrect segment vote in archiveTable: ${archivedSegment[0].votes} instead of -4`);
|
strictEqual(archivedSegment[0].votes, -4, `Incorrect segment vote in archiveTable: ${archivedSegment[0].votes} instead of -4`);
|
||||||
|
|
||||||
// check segments not in main table
|
// check segments not in main table
|
||||||
const segments = await getSegmentsInMainTable(dayLimit, voteLimit, time);
|
const segments = await getSegmentsInMainTable(dayLimit, voteLimit, time);
|
||||||
assert.strictEqual(segments.length, 0, `Incorrect segment in main table: ${segments.length} instead of 0`);
|
strictEqual(segments.length, 0, `Incorrect segment in main table: ${segments.length} instead of 0`);
|
||||||
|
|
||||||
// check number segments remain in main table
|
// check number segments remain in main table
|
||||||
assert.strictEqual(await countSegmentInMainTable(), records.length - archivedSegment.length ,"Incorrect segment remain in main table");
|
strictEqual(await countSegmentInMainTable(), records.length - archivedSegment.length ,"Incorrect segment remain in main table");
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should archive records with vote < -2 and day < 300 match", async () => {
|
it("Should archive records with vote < -2 and day < 300 match", async () => {
|
||||||
const dayLimit = 300;
|
const dayLimit = 300;
|
||||||
const voteLimit = -2;
|
const voteLimit = -2;
|
||||||
const time = new Date("December 17, 2022").getTime();
|
const time = dec2022;
|
||||||
const res = await archiveDownvoteSegment(dayLimit, voteLimit, time);
|
const res = await archiveDownvoteSegment(dayLimit, voteLimit, time);
|
||||||
assert.strictEqual(res, 0, "");
|
strictEqual(res, 0, "");
|
||||||
|
|
||||||
// check segments in archived table
|
// check segments in archived table
|
||||||
const archivedSegment = await getArchivedSegment();
|
const archivedSegment = await getArchivedSegment();
|
||||||
assert.strictEqual(archivedSegment.length, 2, `Incorrect segment in archiveTable: ${archivedSegment.length} instead of 2`);
|
strictEqual(archivedSegment.length, 2, `Incorrect segment in archiveTable: ${archivedSegment.length} instead of 2`);
|
||||||
|
|
||||||
// check segments not in main table
|
// check segments not in main table
|
||||||
const segments = await getSegmentsInMainTable(dayLimit, voteLimit, time);
|
const segments = await getSegmentsInMainTable(dayLimit, voteLimit, time);
|
||||||
assert.strictEqual(segments.length, 0, `Incorrect segment in main table: ${segments.length} instead of 0`);
|
strictEqual(segments.length, 0, `Incorrect segment in main table: ${segments.length} instead of 0`);
|
||||||
|
|
||||||
// check number segments remain in main table
|
// check number segments remain in main table
|
||||||
assert.strictEqual(await countSegmentInMainTable(), records.length - archivedSegment.length ,"Incorrect segment remain in main table");
|
strictEqual(await countSegmentInMainTable(), records.length - archivedSegment.length ,"Incorrect segment remain in main table");
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should not archive any", async () => {
|
it("Should not archive any", async () => {
|
||||||
const dayLimit = 300;
|
const dayLimit = 300;
|
||||||
const voteLimit = -2;
|
const voteLimit = -2;
|
||||||
const time = new Date("December 17, 2021").getTime();
|
const time = dec2021;
|
||||||
const res = await archiveDownvoteSegment(dayLimit, voteLimit, time);
|
const res = await archiveDownvoteSegment(dayLimit, voteLimit, time);
|
||||||
assert.strictEqual(res, 0, "");
|
strictEqual(res, 0, "");
|
||||||
|
|
||||||
// check segments in archived table
|
// check segments in archived table
|
||||||
const archivedSegment = await getArchivedSegment();
|
const archivedSegment = await getArchivedSegment();
|
||||||
assert.strictEqual(archivedSegment.length, 0, `Incorrect segment in archiveTable: ${archivedSegment.length} instead of 0`);
|
strictEqual(archivedSegment.length, 0, `Incorrect segment in archiveTable: ${archivedSegment.length} instead of 0`);
|
||||||
|
|
||||||
// check segments not in main table
|
// check segments not in main table
|
||||||
const segments = await getSegmentsInMainTable(dayLimit, voteLimit, time);
|
const segments = await getSegmentsInMainTable(dayLimit, voteLimit, time);
|
||||||
assert.strictEqual(segments.length, 0, `Incorrect segment in main table: ${segments.length} instead of 0`);
|
strictEqual(segments.length, 0, `Incorrect segment in main table: ${segments.length} instead of 0`);
|
||||||
|
|
||||||
// check number segments remain in main table
|
// check number segments remain in main table
|
||||||
assert.strictEqual(await countSegmentInMainTable(), records.length - archivedSegment.length ,"Incorrect segment remain in main table");
|
strictEqual(await countSegmentInMainTable(), records.length - archivedSegment.length ,"Incorrect segment remain in main table");
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,33 +1,33 @@
|
|||||||
import {getHash} from "../../src/utils/getHash";
|
import {getHash} from "../../src/utils/getHash";
|
||||||
import assert from "assert";
|
import {notStrictEqual, strictEqual} from "assert";
|
||||||
|
|
||||||
describe("getHash", () => {
|
describe("getHash", () => {
|
||||||
it("Should not output the input string", () => {
|
it("Should not output the input string", () => {
|
||||||
assert(getHash("test") !== "test");
|
notStrictEqual(getHash("test"), "test");
|
||||||
assert(getHash("test", -1) !== "test");
|
notStrictEqual(getHash("test", -1), "test");
|
||||||
assert(getHash("test", 0) !== "test");
|
notStrictEqual(getHash("test", 0), "test");
|
||||||
assert(getHash("test", null) !== "test");
|
notStrictEqual(getHash("test", null), "test");
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should return a hashed value", () => {
|
it("Should return a hashed value", () => {
|
||||||
assert.strictEqual(getHash("test"), "2f327ef967ade1ebf4319163f7debbda9cc17bb0c8c834b00b30ca1cf1c256ee");
|
strictEqual(getHash("test"), "2f327ef967ade1ebf4319163f7debbda9cc17bb0c8c834b00b30ca1cf1c256ee");
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should be able to output the same has the DB upgrade script will output", () => {
|
it("Should be able to output the same has the DB upgrade script will output", () => {
|
||||||
assert.strictEqual(getHash("vid", 1), "1ff838dc6ca9680d88455341118157d59a055fe6d0e3870f9c002847bebe4663");
|
strictEqual(getHash("vid", 1), "1ff838dc6ca9680d88455341118157d59a055fe6d0e3870f9c002847bebe4663");
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should take a variable number of passes", () => {
|
it("Should take a variable number of passes", () => {
|
||||||
assert.strictEqual(getHash("test", 1), "9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08");
|
strictEqual(getHash("test", 1), "9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08");
|
||||||
assert.strictEqual(getHash("test", 2), "7b3d979ca8330a94fa7e9e1b466d8b99e0bcdea1ec90596c0dcc8d7ef6b4300c");
|
strictEqual(getHash("test", 2), "7b3d979ca8330a94fa7e9e1b466d8b99e0bcdea1ec90596c0dcc8d7ef6b4300c");
|
||||||
assert.strictEqual(getHash("test", 3), "5b24f7aa99f1e1da5698a4f91ae0f4b45651a1b625c61ed669dd25ff5b937972");
|
strictEqual(getHash("test", 3), "5b24f7aa99f1e1da5698a4f91ae0f4b45651a1b625c61ed669dd25ff5b937972");
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should default to 5000 passes", () => {
|
it("Should default to 5000 passes", () => {
|
||||||
assert.strictEqual(getHash("test"), getHash("test", 5000));
|
strictEqual(getHash("test"), getHash("test", 5000));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should not take a negative number of passes", () => {
|
it("Should not take a negative number of passes", () => {
|
||||||
assert.strictEqual(getHash("test", -1), "");
|
strictEqual(getHash("test", -1), "");
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -6,11 +6,11 @@ import assert from "assert";
|
|||||||
|
|
||||||
describe("getIsUserVIP", () => {
|
describe("getIsUserVIP", () => {
|
||||||
before((done: Done) => {
|
before((done: Done) => {
|
||||||
db.prepare("run", 'INSERT INTO "vipUsers" ("userID") VALUES (?)', [getHash("supertestman")]).then(done);
|
db.prepare("run", 'INSERT INTO "vipUsers" ("userID") VALUES (?)', [getHash("isUserVIPVIP")]).then(done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should be able to get a 200", (done: Done) => {
|
it("Should be able to get a 200", (done: Done) => {
|
||||||
fetch(`${getbaseURL()}/api/isUserVIP?userID=supertestman`)
|
fetch(`${getbaseURL()}/api/isUserVIP?userID=isUserVIPVIP`)
|
||||||
.then(res => {
|
.then(res => {
|
||||||
assert.strictEqual(res.status, 200, "response should be 200");
|
assert.strictEqual(res.status, 200, "response should be 200");
|
||||||
done();
|
done();
|
||||||
@@ -29,7 +29,7 @@ describe("getIsUserVIP", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("Should say a VIP is a VIP", (done: Done) => {
|
it("Should say a VIP is a VIP", (done: Done) => {
|
||||||
fetch(`${getbaseURL()}/api/isUserVIP?userID=supertestman`)
|
fetch(`${getbaseURL()}/api/isUserVIP?userID=isUserVIPVIP`)
|
||||||
.then(async res => {
|
.then(async res => {
|
||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
const data = await res.json();
|
const data = await res.json();
|
||||||
@@ -40,7 +40,7 @@ describe("getIsUserVIP", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("Should say a normal user is not a VIP", (done: Done) => {
|
it("Should say a normal user is not a VIP", (done: Done) => {
|
||||||
fetch(`${getbaseURL()}/api/isUserVIP?userID=regulartestman`)
|
fetch(`${getbaseURL()}/api/isUserVIP?userID=isUserVIPNormal`)
|
||||||
.then(async res => {
|
.then(async res => {
|
||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
const data = await res.json();
|
const data = await res.json();
|
||||||
|
|||||||
@@ -8,25 +8,24 @@ import assert from "assert";
|
|||||||
describe("getLockCategories", () => {
|
describe("getLockCategories", () => {
|
||||||
before(async () => {
|
before(async () => {
|
||||||
const insertVipUserQuery = 'INSERT INTO "vipUsers" ("userID") VALUES (?)';
|
const insertVipUserQuery = 'INSERT INTO "vipUsers" ("userID") VALUES (?)';
|
||||||
await db.prepare("run", insertVipUserQuery, [getHash("VIPUser-getLockCategories")]);
|
await db.prepare("run", insertVipUserQuery, [getHash("getLockCategoriesVIP")]);
|
||||||
|
|
||||||
const insertLockCategoryQuery = 'INSERT INTO "lockCategories" ("userID", "videoID", "category", "reason") VALUES (?, ?, ?, ?)';
|
const insertLockCategoryQuery = 'INSERT INTO "lockCategories" ("userID", "videoID", "category", "reason") VALUES (?, ?, ?, ?)';
|
||||||
await db.prepare("run", insertLockCategoryQuery, [getHash("VIPUser-getLockCategories"), "getLock-1", "sponsor", "1-short"]);
|
await db.prepare("run", insertLockCategoryQuery, [getHash("getLockCategoriesVIP"), "getLock1", "sponsor", "1-short"]);
|
||||||
await db.prepare("run", insertLockCategoryQuery, [getHash("VIPUser-getLockCategories"), "getLock-1", "interaction", "1-longer-reason"]);
|
await db.prepare("run", insertLockCategoryQuery, [getHash("getLockCategoriesVIP"), "getLock1", "interaction", "1-longer-reason"]);
|
||||||
|
|
||||||
await db.prepare("run", insertLockCategoryQuery, [getHash("VIPUser-getLockCategories"), "getLock-2", "preview", "2-reason"]);
|
await db.prepare("run", insertLockCategoryQuery, [getHash("getLockCategoriesVIP"), "getLock2", "preview", "2-reason"]);
|
||||||
|
|
||||||
await db.prepare("run", insertLockCategoryQuery, [getHash("VIPUser-getLockCategories"), "getLock-3", "nonmusic", "3-reason"]);
|
await db.prepare("run", insertLockCategoryQuery, [getHash("getLockCategoriesVIP"), "getLock3", "nonmusic", "3-reason"]);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should update the database version when starting the application", async () => {
|
it("Should update the database version when starting the application", async () => {
|
||||||
const version = (await db.prepare("get", "SELECT key, value FROM config where key = ?", ["version"])).value;
|
const version = (await db.prepare("get", "SELECT key, value FROM config where key = ?", ["version"])).value;
|
||||||
if (version > 20) return;
|
assert.ok(version > 20, `Version isn't greater than 20. Version is ${version}`);
|
||||||
else return `Version isn't greater than 20. Version is ${version}`;
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should be able to get multiple locks", (done: Done) => {
|
it("Should be able to get multiple locks", (done: Done) => {
|
||||||
fetch(`${getbaseURL()}/api/lockCategories?videoID=getLock-1`)
|
fetch(`${getbaseURL()}/api/lockCategories?videoID=getLock1`)
|
||||||
.then(async res => {
|
.then(async res => {
|
||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
const data = await res.json();
|
const data = await res.json();
|
||||||
@@ -44,7 +43,7 @@ describe("getLockCategories", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("Should be able to get single locks", (done: Done) => {
|
it("Should be able to get single locks", (done: Done) => {
|
||||||
fetch(`${getbaseURL()}/api/lockCategories?videoID=getLock-2`)
|
fetch(`${getbaseURL()}/api/lockCategories?videoID=getLock2`)
|
||||||
.then(async res => {
|
.then(async res => {
|
||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
const data = await res.json();
|
const data = await res.json();
|
||||||
@@ -61,7 +60,7 @@ describe("getLockCategories", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("should return 404 if no lock exists", (done: Done) => {
|
it("should return 404 if no lock exists", (done: Done) => {
|
||||||
fetch(`${getbaseURL()}/api/lockCategories?videoID=getLock-0`)
|
fetch(`${getbaseURL()}/api/lockCategories?videoID=getLockNull`)
|
||||||
.then(res => {
|
.then(res => {
|
||||||
assert.strictEqual(res.status, 404);
|
assert.strictEqual(res.status, 404);
|
||||||
done();
|
done();
|
||||||
|
|||||||
@@ -4,22 +4,24 @@ import {getHash} from "../../src/utils/getHash";
|
|||||||
import {db} from "../../src/databases/databases";
|
import {db} from "../../src/databases/databases";
|
||||||
import assert from "assert";
|
import assert from "assert";
|
||||||
|
|
||||||
|
const fakeHash = "b05a20424f24a53dac1b059fb78d861ba9723645026be2174c93a94f9106bb35";
|
||||||
|
|
||||||
describe("getLockCategoriesByHash", () => {
|
describe("getLockCategoriesByHash", () => {
|
||||||
before(async () => {
|
before(async () => {
|
||||||
const insertVipUserQuery = 'INSERT INTO "vipUsers" ("userID") VALUES (?)';
|
const insertVipUserQuery = 'INSERT INTO "vipUsers" ("userID") VALUES (?)';
|
||||||
await db.prepare("run", insertVipUserQuery, [getHash("VIPUser-getLockCategories")]);
|
await db.prepare("run", insertVipUserQuery, [getHash("getLockCategoriesHashVIP")]);
|
||||||
|
|
||||||
const insertLockCategoryQuery = 'INSERT INTO "lockCategories" ("userID", "videoID", "category", "reason", "hashedVideoID") VALUES (?, ?, ?, ?, ?)';
|
const insertLockCategoryQuery = 'INSERT INTO "lockCategories" ("userID", "videoID", "category", "reason", "hashedVideoID") VALUES (?, ?, ?, ?, ?)';
|
||||||
await db.prepare("run", insertLockCategoryQuery, [getHash("VIPUser-getLockCategories"), "getLockHash-1", "sponsor", "1-reason-short", "67a654898fda3a5541774aea345796c7709982bb6018cb08d22a18eeddccc1d0"]);
|
await db.prepare("run", insertLockCategoryQuery, [getHash("getLockCategoriesHashVIP"), "getLockHash1", "sponsor", "1-reason-short", getHash("getLockHash1", 1)]);
|
||||||
await db.prepare("run", insertLockCategoryQuery, [getHash("VIPUser-getLockCategories"), "getLockHash-1", "interaction", "1-reason-longer", "67a654898fda3a5541774aea345796c7709982bb6018cb08d22a18eeddccc1d0"]);
|
await db.prepare("run", insertLockCategoryQuery, [getHash("getLockCategoriesHashVIP"), "getLockHash1", "interaction", "1-reason-longer", getHash("getLockHash1", 1)]);
|
||||||
|
|
||||||
await db.prepare("run", insertLockCategoryQuery, [getHash("VIPUser-getLockCategories"), "getLockHash-2", "preview", "2-reason", "dff09120437b4bd594dffae5f3cde3cfc5f6099fb01d0ef4051919b2908d9a50"]);
|
await db.prepare("run", insertLockCategoryQuery, [getHash("getLockCategoriesHashVIP"), "getLockHash2", "preview", "2-reason", getHash("getLockHash2", 1)]);
|
||||||
|
|
||||||
await db.prepare("run", insertLockCategoryQuery, [getHash("VIPUser-getLockCategories"), "getLockHash-3", "nonmusic", "3-reason", "bf1b122fd5630e0df8626d00c4a95c58954ad715e5595b0f75a19ac131e28928"]);
|
await db.prepare("run", insertLockCategoryQuery, [getHash("getLockCategoriesHashVIP"), "getLockHash3", "nonmusic", "3-reason", getHash("getLockHash3", 1)]);
|
||||||
|
|
||||||
await db.prepare("run", insertLockCategoryQuery, [getHash("VIPUser-getLockCategories"), "fakehash-1", "outro", "fake1-reason", "b05a20424f24a53dac1b059fb78d861ba9723645026be2174c93a94f9106bb35"]);
|
await db.prepare("run", insertLockCategoryQuery, [getHash("getLockCategoriesHashVIP"), "fakehash-1", "outro", "fake1-reason", fakeHash]);
|
||||||
await db.prepare("run", insertLockCategoryQuery, [getHash("VIPUser-getLockCategories"), "fakehash-2", "intro", "fake2-longer-reason", "b05acd1cd6ec7dffe5ffea64ada91ae7469d6db2ce21c7e30ad7fa62075d450"]);
|
await db.prepare("run", insertLockCategoryQuery, [getHash("getLockCategoriesHashVIP"), "fakehash-2", "intro", "fake2-longer-reason", fakeHash]);
|
||||||
await db.prepare("run", insertLockCategoryQuery, [getHash("VIPUser-getLockCategories"), "fakehash-2", "preview", "fake2-short", "b05acd1cd6ec7dffe5ffea64ada91ae7469d6db2ce21c7e30ad7fa62075d450"]);
|
await db.prepare("run", insertLockCategoryQuery, [getHash("getLockCategoriesHashVIP"), "fakehash-2", "preview", "fake2-short", fakeHash]);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Database should be greater or equal to version 20", async () => {
|
it("Database should be greater or equal to version 20", async () => {
|
||||||
@@ -30,13 +32,15 @@ describe("getLockCategoriesByHash", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("Should be able to get multiple locks in one object", (done: Done) => {
|
it("Should be able to get multiple locks in one object", (done: Done) => {
|
||||||
fetch(`${getbaseURL()}/api/lockCategories/67a65`)
|
const videoID = "getLockHash1";
|
||||||
|
const hash = getHash(videoID, 1);
|
||||||
|
fetch(`${getbaseURL()}/api/lockCategories/${hash.substring(0,4)}`)
|
||||||
.then(async res => {
|
.then(async res => {
|
||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
const data = await res.json();
|
const data = await res.json();
|
||||||
const expected = [{
|
const expected = [{
|
||||||
videoID: "getLockHash-1",
|
videoID,
|
||||||
hash: getHash("getLockHash-1", 1),
|
hash,
|
||||||
categories: [
|
categories: [
|
||||||
"sponsor",
|
"sponsor",
|
||||||
"interaction"
|
"interaction"
|
||||||
@@ -50,13 +54,15 @@ describe("getLockCategoriesByHash", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("Should be able to get single lock", (done: Done) => {
|
it("Should be able to get single lock", (done: Done) => {
|
||||||
fetch(`${getbaseURL()}/api/lockCategories/dff09`)
|
const videoID = "getLockHash2";
|
||||||
|
const hash = getHash(videoID, 1);
|
||||||
|
fetch(`${getbaseURL()}/api/lockCategories/${hash.substring(0,6)}`)
|
||||||
.then(async res => {
|
.then(async res => {
|
||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
const data = await res.json();
|
const data = await res.json();
|
||||||
const expected = [{
|
const expected = [{
|
||||||
videoID: "getLockHash-2",
|
videoID,
|
||||||
hash: getHash("getLockHash-2", 1),
|
hash,
|
||||||
categories: [
|
categories: [
|
||||||
"preview"
|
"preview"
|
||||||
],
|
],
|
||||||
@@ -69,13 +75,15 @@ describe("getLockCategoriesByHash", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("Should be able to get by half full hash", (done: Done) => {
|
it("Should be able to get by half full hash", (done: Done) => {
|
||||||
fetch(`${getbaseURL()}/api/lockCategories/bf1b122fd5630e0df8626d00c4a95c58`)
|
const videoID = "getLockHash3";
|
||||||
|
const hash = getHash(videoID, 1);
|
||||||
|
fetch(`${getbaseURL()}/api/lockCategories/${hash.substring(0,32)}`)
|
||||||
.then(async res => {
|
.then(async res => {
|
||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
const data = await res.json();
|
const data = await res.json();
|
||||||
const expected = [{
|
const expected = [{
|
||||||
videoID: "getLockHash-3",
|
videoID,
|
||||||
hash: getHash("getLockHash-3", 1),
|
hash,
|
||||||
categories: [
|
categories: [
|
||||||
"nonmusic"
|
"nonmusic"
|
||||||
],
|
],
|
||||||
@@ -88,20 +96,20 @@ describe("getLockCategoriesByHash", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("Should be able to get multiple by similar hash with multiple categories", (done: Done) => {
|
it("Should be able to get multiple by similar hash with multiple categories", (done: Done) => {
|
||||||
fetch(`${getbaseURL()}/api/lockCategories/b05a`)
|
fetch(`${getbaseURL()}/api/lockCategories/${fakeHash.substring(0,5)}`)
|
||||||
.then(async res => {
|
.then(async res => {
|
||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
const data = await res.json();
|
const data = await res.json();
|
||||||
const expected = [{
|
const expected = [{
|
||||||
videoID: "fakehash-1",
|
videoID: "fakehash-1",
|
||||||
hash: "b05a20424f24a53dac1b059fb78d861ba9723645026be2174c93a94f9106bb35",
|
hash: fakeHash,
|
||||||
categories: [
|
categories: [
|
||||||
"outro"
|
"outro"
|
||||||
],
|
],
|
||||||
reason: "fake1-reason"
|
reason: "fake1-reason"
|
||||||
}, {
|
}, {
|
||||||
videoID: "fakehash-2",
|
videoID: "fakehash-2",
|
||||||
hash: "b05acd1cd6ec7dffe5ffea64ada91ae7469d6db2ce21c7e30ad7fa62075d450",
|
hash: fakeHash,
|
||||||
categories: [
|
categories: [
|
||||||
"intro",
|
"intro",
|
||||||
"preview"
|
"preview"
|
||||||
@@ -142,7 +150,7 @@ describe("getLockCategoriesByHash", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("should return 400 if full hash sent", (done: Done) => {
|
it("should return 400 if full hash sent", (done: Done) => {
|
||||||
fetch(`${getbaseURL()}/api/lockCategories/b05a20424f24a53dac1b059fb78d861ba9723645026be2174c93a94f9106bb35`)
|
fetch(`${getbaseURL()}/api/lockCategories/${fakeHash}`)
|
||||||
.then(res => {
|
.then(res => {
|
||||||
assert.strictEqual(res.status, 400);
|
assert.strictEqual(res.status, 400);
|
||||||
done();
|
done();
|
||||||
|
|||||||
@@ -2,18 +2,18 @@ import fetch from "node-fetch";
|
|||||||
import {Done, getbaseURL} from "../utils";
|
import {Done, getbaseURL} from "../utils";
|
||||||
import {db} from "../../src/databases/databases";
|
import {db} from "../../src/databases/databases";
|
||||||
import {getHash} from "../../src/utils/getHash";
|
import {getHash} from "../../src/utils/getHash";
|
||||||
import assert from "assert";
|
import {deepStrictEqual} from "assert";
|
||||||
|
|
||||||
describe("getSavedTimeForUser", () => {
|
describe("getSavedTimeForUser", () => {
|
||||||
before(async () => {
|
before(async () => {
|
||||||
const startOfQuery = 'INSERT INTO "sponsorTimes" ("videoID", "startTime", "endTime", "votes", "UUID", "userID", "timeSubmitted", views, category, "shadowHidden", "hashedVideoID") VALUES';
|
const startOfQuery = 'INSERT INTO "sponsorTimes" ("videoID", "startTime", "endTime", "votes", "UUID", "userID", "timeSubmitted", "views", "shadowHidden") VALUES';
|
||||||
await db.prepare("run", `${startOfQuery}(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`,
|
await db.prepare("run", `${startOfQuery}(?, ?, ?, ?, ?, ?, ?, ?, ?)`,
|
||||||
["getSavedTimeForUser", 1, 11, 2, "abc1239999", getHash("testman"), 0, 50, "sponsor", 0, getHash("getSavedTimeForUser", 0)]);
|
["getSavedTimeForUser", 1, 11, 2, "gstfu0", getHash("getSavedTimeForUserUser"), 0, 50, 0]);
|
||||||
return;
|
return;
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should be able to get a 200", (done: Done) => {
|
it("Should be able to get a 200", (done: Done) => {
|
||||||
fetch(`${getbaseURL()}/api/getSavedTimeForUser?userID=testman`)
|
fetch(`${getbaseURL()}/api/getSavedTimeForUser?userID=getSavedTimeForUserUser`)
|
||||||
.then(async res => {
|
.then(async res => {
|
||||||
const data = await res.json();
|
const data = await res.json();
|
||||||
// (end-start)*minute * views
|
// (end-start)*minute * views
|
||||||
@@ -21,7 +21,7 @@ describe("getSavedTimeForUser", () => {
|
|||||||
const expected = {
|
const expected = {
|
||||||
timeSaved: savedMinutes
|
timeSaved: savedMinutes
|
||||||
};
|
};
|
||||||
assert.deepStrictEqual(data, expected);
|
deepStrictEqual(data, expected);
|
||||||
done();
|
done();
|
||||||
})
|
})
|
||||||
.catch((err) => done(err));
|
.catch((err) => done(err));
|
||||||
|
|||||||
@@ -6,29 +6,29 @@ import assert from "assert";
|
|||||||
describe("getSearchSegments", () => {
|
describe("getSearchSegments", () => {
|
||||||
before(async () => {
|
before(async () => {
|
||||||
const query = 'INSERT INTO "sponsorTimes" ("videoID", "startTime", "endTime", "votes", "views", "locked", "hidden", "shadowHidden", "timeSubmitted", "UUID", "userID", "category", "actionType") VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)';
|
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", "testman", "sponsor", "skip"]);
|
await db.prepare("run", query, ["searchTest0", 0, 1, 2, 0, 0, 0, 0, 1, "search-normal", "searchTestUser", "sponsor", "skip"]);
|
||||||
await db.prepare("run", query, ["searchTest0", 0, 2, -2, 0, 0, 0, 0, 2, "search-downvote", "testman", "selfpromo", "skip",]);
|
await db.prepare("run", query, ["searchTest0", 0, 2, -2, 0, 0, 0, 0, 2, "search-downvote", "searchTestUser", "selfpromo", "skip",]);
|
||||||
await db.prepare("run", query, ["searchTest0", 0, 3, 1, 0, 1, 0, 0, 3, "search-locked", "testman", "interaction", "skip"]);
|
await db.prepare("run", query, ["searchTest0", 0, 3, 1, 0, 1, 0, 0, 3, "search-locked", "searchTestUser", "interaction", "skip"]);
|
||||||
await db.prepare("run", query, ["searchTest0", 0, 4, 1, 0, 0, 1, 0, 4, "search-hidden", "testman", "sponsor", "skip"]);
|
await db.prepare("run", query, ["searchTest0", 0, 4, 1, 0, 0, 1, 0, 4, "search-hidden", "searchTestUser", "sponsor", "skip"]);
|
||||||
await db.prepare("run", query, ["searchTest0", 0, 5, 1, 0, 0, 0, 1, 5, "search-shadowhidden", "testman", "sponsor", "skip"]);
|
await db.prepare("run", query, ["searchTest0", 0, 5, 1, 0, 0, 0, 1, 5, "search-shadowhidden", "searchTestUser", "sponsor", "skip"]);
|
||||||
await db.prepare("run", query, ["searchTest1", 1, 2, 1, 5, 0, 0, 0, 6, "search-lowview", "testman", "sponsor", "skip"]);
|
await db.prepare("run", query, ["searchTest1", 1, 2, 1, 5, 0, 0, 0, 6, "search-lowview", "searchTestUser", "sponsor", "skip"]);
|
||||||
await db.prepare("run", query, ["searchTest1", 1, 3, 1, 50, 0, 0, 0, 7, "search-highview", "testman", "sponsor", "skip"]);
|
await db.prepare("run", query, ["searchTest1", 1, 3, 1, 50, 0, 0, 0, 7, "search-highview", "searchTestUser", "sponsor", "skip"]);
|
||||||
await db.prepare("run", query, ["searchTest2", 1, 4, -1, 0, 0, 0, 0, 8, "search-lowvote", "testman", "sponsor", "skip"]);
|
await db.prepare("run", query, ["searchTest2", 1, 4, -1, 0, 0, 0, 0, 8, "search-lowvote", "searchTestUser", "sponsor", "skip"]);
|
||||||
await db.prepare("run", query, ["searchTest2", 2, 3, 0, 0, 0, 0, 0, 9, "search-zerovote", "testman", "sponsor", "skip"]);
|
await db.prepare("run", query, ["searchTest2", 2, 3, 0, 0, 0, 0, 0, 9, "search-zerovote", "searchTestUser", "sponsor", "skip"]);
|
||||||
await db.prepare("run", query, ["searchTest2", 2, 4, 50, 0, 0, 0, 0, 10, "search-highvote", "testman", "sponsor", "skip"]);
|
await db.prepare("run", query, ["searchTest2", 2, 4, 50, 0, 0, 0, 0, 10, "search-highvote", "searchTestUser", "sponsor", "skip"]);
|
||||||
// page
|
// page
|
||||||
await db.prepare("run", query, ["searchTest4", 3, 4, 1, 0, 0, 0, 0, 10, "search-page1-1", "testman", "sponsor", "skip"]);
|
await db.prepare("run", query, ["searchTest4", 3, 4, 1, 0, 0, 0, 0, 10, "search-page1-1", "searchTestUser", "sponsor", "skip"]);
|
||||||
await db.prepare("run", query, ["searchTest4", 3, 5, 1, 0, 0, 0, 0, 11, "search-page1-2", "testman", "sponsor", "skip"]);
|
await db.prepare("run", query, ["searchTest4", 3, 5, 1, 0, 0, 0, 0, 11, "search-page1-2", "searchTestUser", "sponsor", "skip"]);
|
||||||
await db.prepare("run", query, ["searchTest4", 3, 6, 1, 0, 0, 0, 0, 12, "search-page1-3", "testman", "sponsor", "skip"]);
|
await db.prepare("run", query, ["searchTest4", 3, 6, 1, 0, 0, 0, 0, 12, "search-page1-3", "searchTestUser", "sponsor", "skip"]);
|
||||||
await db.prepare("run", query, ["searchTest4", 3, 7, 1, 0, 0, 0, 0, 13, "search-page1-4", "testman", "sponsor", "skip"]);
|
await db.prepare("run", query, ["searchTest4", 3, 7, 1, 0, 0, 0, 0, 13, "search-page1-4", "searchTestUser", "sponsor", "skip"]);
|
||||||
await db.prepare("run", query, ["searchTest4", 3, 8, 1, 0, 0, 0, 0, 14, "search-page1-5", "testman", "sponsor", "skip"]);
|
await db.prepare("run", query, ["searchTest4", 3, 8, 1, 0, 0, 0, 0, 14, "search-page1-5", "searchTestUser", "sponsor", "skip"]);
|
||||||
await db.prepare("run", query, ["searchTest4", 3, 9, 1, 0, 0, 0, 0, 15, "search-page1-6", "testman", "sponsor", "skip"]);
|
await db.prepare("run", query, ["searchTest4", 3, 9, 1, 0, 0, 0, 0, 15, "search-page1-6", "searchTestUser", "sponsor", "skip"]);
|
||||||
await db.prepare("run", query, ["searchTest4", 3, 10, 1, 0, 0, 0, 0, 16, "search-page1-7", "testman", "sponsor", "skip"]);
|
await db.prepare("run", query, ["searchTest4", 3, 10, 1, 0, 0, 0, 0, 16, "search-page1-7", "searchTestUser", "sponsor", "skip"]);
|
||||||
await db.prepare("run", query, ["searchTest4", 3, 11, 1, 0, 0, 0, 0, 17, "search-page1-8", "testman", "sponsor", "skip"]);
|
await db.prepare("run", query, ["searchTest4", 3, 11, 1, 0, 0, 0, 0, 17, "search-page1-8", "searchTestUser", "sponsor", "skip"]);
|
||||||
await db.prepare("run", query, ["searchTest4", 3, 12, 1, 0, 0, 0, 0, 18, "search-page1-9", "testman", "sponsor", "skip"]);
|
await db.prepare("run", query, ["searchTest4", 3, 12, 1, 0, 0, 0, 0, 18, "search-page1-9", "searchTestUser", "sponsor", "skip"]);
|
||||||
await db.prepare("run", query, ["searchTest4", 3, 13, 1, 0, 0, 0, 0, 19, "search-page1-10", "testman", "sponsor", "skip"]);
|
await db.prepare("run", query, ["searchTest4", 3, 13, 1, 0, 0, 0, 0, 19, "search-page1-10", "searchTestUser", "sponsor", "skip"]);
|
||||||
await db.prepare("run", query, ["searchTest4", 3, 14, 1, 0, 0, 0, 0, 20, "search-page2-1", "testman", "sponsor", "skip"]);
|
await db.prepare("run", query, ["searchTest4", 3, 14, 1, 0, 0, 0, 0, 20, "search-page2-1", "searchTestUser", "sponsor", "skip"]);
|
||||||
await db.prepare("run", query, ["searchTest4", 3, 15, 1, 0, 0, 0, 0, 21, "search-page2-2", "testman", "sponsor", "skip"]);
|
await db.prepare("run", query, ["searchTest4", 3, 15, 1, 0, 0, 0, 0, 21, "search-page2-2", "searchTestUser", "sponsor", "skip"]);
|
||||||
return;
|
return;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
import fetch from "node-fetch";
|
import fetch from "node-fetch";
|
||||||
import {db} from "../../src/databases/databases";
|
import {db} from "../../src/databases/databases";
|
||||||
import {Done, getbaseURL, partialDeepEquals} from "../utils";
|
import {Done, getbaseURL, partialDeepEquals} from "../utils";
|
||||||
import {getHash} from "../../src/utils/getHash";
|
|
||||||
import assert from "assert";
|
import assert from "assert";
|
||||||
|
|
||||||
const ENOENTID = "0".repeat(64);
|
const ENOENTID = "0".repeat(64);
|
||||||
@@ -30,22 +29,21 @@ describe("getSegmentInfo", () => {
|
|||||||
before(async () => {
|
before(async () => {
|
||||||
const insertQuery = `INSERT INTO
|
const insertQuery = `INSERT INTO
|
||||||
"sponsorTimes"("videoID", "startTime", "endTime", "votes", "locked",
|
"sponsorTimes"("videoID", "startTime", "endTime", "votes", "locked",
|
||||||
"UUID", "userID", "timeSubmitted", "views", "category", "service",
|
"UUID", "userID", "timeSubmitted", "views", "hidden", "shadowHidden", "userAgent")
|
||||||
"videoDuration", "hidden", "shadowHidden", "hashedVideoID", "userAgent")
|
VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`;
|
||||||
VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`;
|
await db.prepare("run", insertQuery, ["segmentInfoUpvoted", 1, 10, 2, 0, upvotedID, "segmentInfoUser", 0, 50, 0, 0, userAgents.vanced]);
|
||||||
await db.prepare("run", insertQuery, ["upvoted", 1, 10, 2, 0, upvotedID, "testman", 0, 50, "sponsor", "YouTube", 100, 0, 0, getHash("upvoted", 1), userAgents.vanced]);
|
await db.prepare("run", insertQuery, ["segmentInfoDownvoted", 1, 10, -2, 0, downvotedID, "segmentInfoUser", 0, 50, 0, 0, userAgents.meabot]);
|
||||||
await db.prepare("run", insertQuery, ["downvoted", 1, 10, -2, 0, downvotedID, "testman", 0, 50, "sponsor", "YouTube", 120, 0, 0, getHash("downvoted", 1), userAgents.meabot]);
|
await db.prepare("run", insertQuery, ["segmentInfoLockedup", 1, 10, 2, 1, lockedupID, "segmentInfoUser", 0, 50, 0, 0, userAgents.mpv]);
|
||||||
await db.prepare("run", insertQuery, ["locked-up", 1, 10, 2, 1, lockedupID, "testman", 0, 50, "sponsor", "YouTube", 101, 0, 0, getHash("locked-up", 1), userAgents.mpv]);
|
await db.prepare("run", insertQuery, ["segmentInfoInfvotes", 1, 10, 100000, 0, infvotesID, "segmentInfoUser", 0, 50, 0, 0, userAgents.nodesb]);
|
||||||
await db.prepare("run", insertQuery, ["infvotes", 1, 10, 100000, 0, infvotesID, "testman", 0, 50, "sponsor", "YouTube", 101, 0, 0, getHash("infvotes", 1), userAgents.nodesb]);
|
await db.prepare("run", insertQuery, ["segmentInfoHidden", 1, 10, 2, 0, hiddenID, "segmentInfoUser", 0, 50, 1, 0, userAgents.blank]);
|
||||||
await db.prepare("run", insertQuery, ["hidden", 1, 10, 2, 0, hiddenID, "testman", 0, 50, "sponsor", "YouTube", 140, 1, 0, getHash("hidden", 1), userAgents.blank]);
|
await db.prepare("run", insertQuery, ["segmentInfoShadowhidden", 1, 10, 2, 0, shadowhiddenID, "segmentInfoUser", 0, 50, 0, 1, userAgents.blank]);
|
||||||
await db.prepare("run", insertQuery, ["shadowhidden", 1, 10, 2, 0, shadowhiddenID, "testman", 0, 50, "sponsor", "YouTube", 140, 0, 1, getHash("shadowhidden", 1), userAgents.blank]);
|
await db.prepare("run", insertQuery, ["segmentInfoLockedown", 1, 10, -2, 1, lockeddownID, "segmentInfoUser", 0, 50, 0, 0, userAgents.blank]);
|
||||||
await db.prepare("run", insertQuery, ["locked-down", 1, 10, -2, 1, lockeddownID, "testman", 0, 50, "sponsor", "YouTube", 200, 0, 0, getHash("locked-down", 1), userAgents.blank]);
|
await db.prepare("run", insertQuery, ["segmentInfoOldID", 1, 10, 1, 0, oldID, "segmentInfoUser", 0, 50, 0, 0, userAgents.blank]);
|
||||||
await db.prepare("run", insertQuery, ["oldID", 1, 10, 1, 0, oldID, "testman", 0, 50, "sponsor", "YouTube", 300, 0, 0, getHash("oldID", 1), userAgents.blank]);
|
await db.prepare("run", insertQuery, ["segmentInfoUpvoted", 1, 2, 1, 0, fillerID1, "segmentInfoUser", 0, 50, 0, 0, userAgents.blank]);
|
||||||
await db.prepare("run", insertQuery, ["filler", 1, 2, 1, 0, fillerID1, "testman", 0, 50, "sponsor", "YouTube", 300, 0, 0, getHash("filler", 1), userAgents.blank]);
|
await db.prepare("run", insertQuery, ["segmentInfoFiller", 2, 3, 1, 0, fillerID2, "segmentInfoUser", 0, 50, 0, 0, userAgents.blank]);
|
||||||
await db.prepare("run", insertQuery, ["filler", 2, 3, 1, 0, fillerID2, "testman", 0, 50, "sponsor", "YouTube", 300, 0, 0, getHash("filler", 1), userAgents.blank]);
|
await db.prepare("run", insertQuery, ["segmentInfoFiller", 3, 4, 1, 0, fillerID3, "segmentInfoUser", 0, 50, 0, 0, userAgents.blank]);
|
||||||
await db.prepare("run", insertQuery, ["filler", 3, 4, 1, 0, fillerID3, "testman", 0, 50, "sponsor", "YouTube", 300, 0, 0, getHash("filler", 1), userAgents.blank]);
|
await db.prepare("run", insertQuery, ["segmentInfoFiller", 4, 5, 1, 0, fillerID4, "segmentInfoUser", 0, 50, 0, 0, userAgents.blank]);
|
||||||
await db.prepare("run", insertQuery, ["filler", 4, 5, 1, 0, fillerID4, "testman", 0, 50, "sponsor", "YouTube", 300, 0, 0, getHash("filler", 1), userAgents.blank]);
|
await db.prepare("run", insertQuery, ["segmentInfoFiller", 5, 6, 1, 0, fillerID5, "segmentInfoUser", 0, 50, 0, 0, userAgents.blank]);
|
||||||
await db.prepare("run", insertQuery, ["filler", 5, 6, 1, 0, fillerID5, "testman", 0, 50, "sponsor", "YouTube", 300, 0, 0, getHash("filler", 1), userAgents.blank]);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should be able to retreive upvoted segment", (done: Done) => {
|
it("Should be able to retreive upvoted segment", (done: Done) => {
|
||||||
@@ -54,7 +52,7 @@ describe("getSegmentInfo", () => {
|
|||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
const data = await res.json();
|
const data = await res.json();
|
||||||
const expected = [{
|
const expected = [{
|
||||||
videoID: "upvoted",
|
videoID: "segmentInfoUpvoted",
|
||||||
votes: 2,
|
votes: 2,
|
||||||
userAgent: userAgents.vanced,
|
userAgent: userAgents.vanced,
|
||||||
}];
|
}];
|
||||||
@@ -70,7 +68,7 @@ describe("getSegmentInfo", () => {
|
|||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
const data = await res.json();
|
const data = await res.json();
|
||||||
const expected = [{
|
const expected = [{
|
||||||
videoID: "downvoted",
|
videoID: "segmentInfoDownvoted",
|
||||||
votes: -2,
|
votes: -2,
|
||||||
userAgent: userAgents.meabot,
|
userAgent: userAgents.meabot,
|
||||||
}];
|
}];
|
||||||
@@ -86,7 +84,7 @@ describe("getSegmentInfo", () => {
|
|||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
const data = await res.json();
|
const data = await res.json();
|
||||||
const expected = [{
|
const expected = [{
|
||||||
videoID: "locked-up",
|
videoID: "segmentInfoLockedup",
|
||||||
locked: 1,
|
locked: 1,
|
||||||
votes: 2,
|
votes: 2,
|
||||||
userAgent: userAgents.mpv,
|
userAgent: userAgents.mpv,
|
||||||
@@ -103,7 +101,7 @@ describe("getSegmentInfo", () => {
|
|||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
const data = await res.json();
|
const data = await res.json();
|
||||||
const expected = [{
|
const expected = [{
|
||||||
videoID: "infvotes",
|
videoID: "segmentInfoInfvotes",
|
||||||
votes: 100000,
|
votes: 100000,
|
||||||
userAgent: userAgents.nodesb,
|
userAgent: userAgents.nodesb,
|
||||||
}];
|
}];
|
||||||
@@ -119,7 +117,7 @@ describe("getSegmentInfo", () => {
|
|||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
const data = await res.json();
|
const data = await res.json();
|
||||||
const expected = [{
|
const expected = [{
|
||||||
videoID: "shadowhidden",
|
videoID: "segmentInfoShadowhidden",
|
||||||
shadowHidden: 1,
|
shadowHidden: 1,
|
||||||
userAgent: userAgents.blank,
|
userAgent: userAgents.blank,
|
||||||
}];
|
}];
|
||||||
@@ -135,7 +133,7 @@ describe("getSegmentInfo", () => {
|
|||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
const data = await res.json();
|
const data = await res.json();
|
||||||
const expected = [{
|
const expected = [{
|
||||||
videoID: "locked-down",
|
videoID: "segmentInfoLockedown",
|
||||||
locked: 1,
|
locked: 1,
|
||||||
votes: -2,
|
votes: -2,
|
||||||
}];
|
}];
|
||||||
@@ -151,7 +149,7 @@ describe("getSegmentInfo", () => {
|
|||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
const data = await res.json();
|
const data = await res.json();
|
||||||
const expected = [{
|
const expected = [{
|
||||||
videoID: "hidden",
|
videoID: "segmentInfoHidden",
|
||||||
hidden: 1,
|
hidden: 1,
|
||||||
}];
|
}];
|
||||||
assert.ok(partialDeepEquals(data, expected));
|
assert.ok(partialDeepEquals(data, expected));
|
||||||
@@ -166,7 +164,7 @@ describe("getSegmentInfo", () => {
|
|||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
const data = await res.json();
|
const data = await res.json();
|
||||||
const expected = [{
|
const expected = [{
|
||||||
videoID: "oldID",
|
videoID: "segmentInfoOldID",
|
||||||
votes: 1,
|
votes: 1,
|
||||||
}];
|
}];
|
||||||
assert.ok(partialDeepEquals(data, expected));
|
assert.ok(partialDeepEquals(data, expected));
|
||||||
@@ -181,7 +179,7 @@ describe("getSegmentInfo", () => {
|
|||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
const data = await res.json();
|
const data = await res.json();
|
||||||
const expected = [{
|
const expected = [{
|
||||||
videoID: "upvoted",
|
videoID: "segmentInfoUpvoted",
|
||||||
votes: 2,
|
votes: 2,
|
||||||
}];
|
}];
|
||||||
assert.strictEqual(data.length, 1);
|
assert.strictEqual(data.length, 1);
|
||||||
@@ -197,10 +195,10 @@ describe("getSegmentInfo", () => {
|
|||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
const data = await res.json();
|
const data = await res.json();
|
||||||
const expected = [{
|
const expected = [{
|
||||||
videoID: "upvoted",
|
videoID: "segmentInfoUpvoted",
|
||||||
votes: 2,
|
votes: 2,
|
||||||
}, {
|
}, {
|
||||||
videoID: "downvoted",
|
videoID: "segmentInfoDownvoted",
|
||||||
votes: -2,
|
votes: -2,
|
||||||
}];
|
}];
|
||||||
assert.ok(partialDeepEquals(data, expected));
|
assert.ok(partialDeepEquals(data, expected));
|
||||||
@@ -216,7 +214,7 @@ describe("getSegmentInfo", () => {
|
|||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
const data = await res.json();
|
const data = await res.json();
|
||||||
const expected = [{
|
const expected = [{
|
||||||
videoID: "upvoted",
|
videoID: "segmentInfoUpvoted",
|
||||||
votes: 2,
|
votes: 2,
|
||||||
}];
|
}];
|
||||||
assert.ok(partialDeepEquals(data, expected));
|
assert.ok(partialDeepEquals(data, expected));
|
||||||
@@ -267,7 +265,7 @@ describe("getSegmentInfo", () => {
|
|||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
const data = await res.json();
|
const data = await res.json();
|
||||||
const expected = [{
|
const expected = [{
|
||||||
videoID: "upvoted",
|
videoID: "segmentInfoUpvoted",
|
||||||
votes: 2,
|
votes: 2,
|
||||||
}];
|
}];
|
||||||
assert.ok(partialDeepEquals(data, expected));
|
assert.ok(partialDeepEquals(data, expected));
|
||||||
@@ -285,9 +283,9 @@ describe("getSegmentInfo", () => {
|
|||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
const data = await res.json();
|
const data = await res.json();
|
||||||
assert.strictEqual(data.length, 10);
|
assert.strictEqual(data.length, 10);
|
||||||
assert.strictEqual(data[0].videoID, "upvoted");
|
assert.strictEqual(data[0].videoID, "segmentInfoUpvoted");
|
||||||
assert.strictEqual(data[0].votes, 2);
|
assert.strictEqual(data[0].votes, 2);
|
||||||
assert.strictEqual(data[9].videoID, "filler");
|
assert.strictEqual(data[9].videoID, "segmentInfoFiller");
|
||||||
assert.strictEqual(data[9].UUID, fillerID4);
|
assert.strictEqual(data[9].UUID, fillerID4);
|
||||||
done();
|
done();
|
||||||
})
|
})
|
||||||
@@ -308,7 +306,7 @@ describe("getSegmentInfo", () => {
|
|||||||
it("Should return 400 if UUID not found", (done: Done) => {
|
it("Should return 400 if UUID not found", (done: Done) => {
|
||||||
fetch(`${getbaseURL()}/api/segmentInfo?UUID=${ENOENTID}`)
|
fetch(`${getbaseURL()}/api/segmentInfo?UUID=${ENOENTID}`)
|
||||||
.then(res => {
|
.then(res => {
|
||||||
if (res.status !== 400) done(`non 400 respone code: ${res.status}`);
|
if (res.status !== 400) done(`non 400 response code: ${res.status}`);
|
||||||
else done(); // pass
|
else done(); // pass
|
||||||
})
|
})
|
||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
@@ -320,10 +318,10 @@ describe("getSegmentInfo", () => {
|
|||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
const data = await res.json();
|
const data = await res.json();
|
||||||
const expected = [{
|
const expected = [{
|
||||||
videoID: "upvoted",
|
videoID: "segmentInfoUpvoted",
|
||||||
votes: 2,
|
votes: 2,
|
||||||
}, {
|
}, {
|
||||||
videoID: "downvoted",
|
videoID: "segmentInfoDownvoted",
|
||||||
votes: -2,
|
votes: -2,
|
||||||
}];
|
}];
|
||||||
assert.ok(partialDeepEquals(data, expected));
|
assert.ok(partialDeepEquals(data, expected));
|
||||||
@@ -339,7 +337,7 @@ describe("getSegmentInfo", () => {
|
|||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
const data = await res.json();
|
const data = await res.json();
|
||||||
const expected = [{
|
const expected = [{
|
||||||
videoID: "upvoted",
|
videoID: "segmentInfoUpvoted",
|
||||||
votes: 2
|
votes: 2
|
||||||
}];
|
}];
|
||||||
assert.ok(partialDeepEquals(data, expected));
|
assert.ok(partialDeepEquals(data, expected));
|
||||||
|
|||||||
@@ -1,34 +1,33 @@
|
|||||||
import fetch from "node-fetch";
|
import fetch from "node-fetch";
|
||||||
import {db} from "../../src/databases/databases";
|
import {db} from "../../src/databases/databases";
|
||||||
import {Done, getbaseURL, partialDeepEquals} from "../utils";
|
import {Done, getbaseURL, partialDeepEquals} from "../utils";
|
||||||
import {getHash} from "../../src/utils/getHash";
|
|
||||||
import assert from "assert";
|
import assert from "assert";
|
||||||
|
|
||||||
describe("getSkipSegments", () => {
|
describe("getSkipSegments", () => {
|
||||||
before(async () => {
|
before(async () => {
|
||||||
const query = 'INSERT INTO "sponsorTimes" ("videoID", "startTime", "endTime", "votes", "locked", "UUID", "userID", "timeSubmitted", views, category, "actionType", "service", "videoDuration", "hidden", "shadowHidden", "hashedVideoID") VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)';
|
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, ["testtesttest", 1, 11, 2, 0, "1-uuid-0", "testman", 0, 50, "sponsor", "skip", "YouTube", 100, 0, 0, getHash("testtesttest", 1)]);
|
await db.prepare("run", query, ["getSkipSegmentID0", 1, 11, 2, 0, "uuid01", "testman", 0, 50, "sponsor", "skip", "YouTube", 100, 0, 0]);
|
||||||
await db.prepare("run", query, ["testtesttest2", 1, 11, 2, 0, "1-uuid-0-1", "testman", 0, 50, "sponsor", "skip", "PeerTube", 120, 0, 0, getHash("testtesttest2", 1)]);
|
await db.prepare("run", query, ["getSkipSegmentID0", 12, 14, 2, 0, "uuid02", "testman", 0, 50, "sponsor", "mute", "YouTube", 100, 0, 0]);
|
||||||
await db.prepare("run", query, ["testtesttest", 12, 14, 2, 0, "1-uuid-0-2", "testman", 0, 50, "sponsor", "mute", "YouTube", 100, 0, 0, getHash("testtesttest", 1)]);
|
await db.prepare("run", query, ["getSkipSegmentID0", 20, 33, 2, 0, "uuid03", "testman", 0, 50, "intro", "skip", "YouTube", 101, 0, 0]);
|
||||||
await db.prepare("run", query, ["testtesttest", 20, 33, 2, 0, "1-uuid-2", "testman", 0, 50, "intro", "skip", "YouTube", 101, 0, 0, getHash("testtesttest", 1)]);
|
await db.prepare("run", query, ["getSkipSegmentID1", 1, 11, 2, 0, "uuid10", "testman", 0, 50, "sponsor", "skip", "PeerTube", 120, 0, 0]);
|
||||||
await db.prepare("run", query, ["testtesttest,test", 1, 11, 2, 0, "1-uuid-1", "testman", 0, 50, "sponsor", "skip", "YouTube", 140, 0, 0, getHash("testtesttest,test", 1)]);
|
await db.prepare("run", query, ["getSkipSegmentID2", 1, 11, 2, 0, "uuid20", "testman", 0, 50, "sponsor", "skip", "YouTube", 140, 0, 0]);
|
||||||
await db.prepare("run", query, ["test3", 1, 11, 2, 0, "1-uuid-4", "testman", 0, 50, "sponsor", "skip", "YouTube", 200, 0, 0, getHash("test3", 1)]);
|
await db.prepare("run", query, ["getSkipSegmentID3", 1, 11, 2, 0, "uuid30", "testman", 0, 50, "sponsor", "skip", "YouTube", 200, 0, 0]);
|
||||||
await db.prepare("run", query, ["test3", 7, 22, -3, 0, "1-uuid-5", "testman", 0, 50, "sponsor", "skip", "YouTube", 300, 0, 0, getHash("test3", 1)]);
|
await db.prepare("run", query, ["getSkipSegmentID3", 7, 22, -3, 0, "uuid31", "testman", 0, 50, "sponsor", "skip", "YouTube", 300, 0, 0]);
|
||||||
await db.prepare("run", query, ["multiple", 1, 11, 2, 0, "1-uuid-6", "testman", 0, 50, "intro", "skip", "YouTube", 400, 0, 0, getHash("multiple", 1)]);
|
await db.prepare("run", query, ["getSkipSegmentMultiple", 1, 11, 2, 0, "uuid40", "testman", 0, 50, "intro", "skip", "YouTube", 400, 0, 0]);
|
||||||
await db.prepare("run", query, ["multiple", 20, 33, 2, 0, "1-uuid-7", "testman", 0, 50, "intro", "skip", "YouTube", 500, 0, 0, getHash("multiple", 1)]);
|
await db.prepare("run", query, ["getSkipSegmentMultiple", 20, 33, 2, 0, "uuid41", "testman", 0, 50, "intro", "skip", "YouTube", 500, 0, 0]);
|
||||||
await db.prepare("run", query, ["locked", 20, 33, 2, 1, "1-uuid-locked-8", "testman", 0, 50, "intro", "skip", "YouTube", 230, 0, 0, getHash("locked", 1)]);
|
await db.prepare("run", query, ["getSkipSegmentLocked", 20, 33, 2, 1, "uuid50", "testman", 0, 50, "intro", "skip", "YouTube", 230, 0, 0]);
|
||||||
await db.prepare("run", query, ["locked", 20, 34, 100000, 0, "1-uuid-9", "testman", 0, 50, "intro", "skip", "YouTube", 190, 0, 0, getHash("locked", 1)]);
|
await db.prepare("run", query, ["getSkipSegmentLocked", 20, 34, 100000, 0, "uuid51", "testman", 0, 50, "intro", "skip", "YouTube", 190, 0, 0]);
|
||||||
await db.prepare("run", query, ["onlyHiddenSegments", 20, 34, 100000, 0, "onlyHiddenSegments", "testman", 0, 50, "sponsor", "skip", "YouTube", 190, 1, 0, getHash("onlyHiddenSegments", 1)]);
|
await db.prepare("run", query, ["getSkipSegmentID6", 20, 34, 100000, 0, "uuid60", "testman", 0, 50, "sponsor", "skip", "YouTube", 190, 1, 0]);
|
||||||
await db.prepare("run", query, ["requiredSegmentVid-raw", 60, 70, 2, 0, "requiredSegmentVid-raw-1", "testman", 0, 50, "sponsor", "skip", "YouTube", 0, 0, 0, getHash("requiredSegmentVid-raw", 1)]);
|
await db.prepare("run", query, ["requiredSegmentVid", 60, 70, 2, 0, "requiredSegmentVid1", "testman", 0, 50, "sponsor", "skip", "YouTube", 0, 0, 0]);
|
||||||
await db.prepare("run", query, ["requiredSegmentVid-raw", 60, 70, -2, 0, "requiredSegmentVid-raw-2", "testman", 0, 50, "sponsor", "skip", "YouTube", 0, 0, 0, getHash("requiredSegmentVid-raw", 1)]);
|
await db.prepare("run", query, ["requiredSegmentVid", 60, 70, -2, 0, "requiredSegmentVid2", "testman", 0, 50, "sponsor", "skip", "YouTube", 0, 0, 0]);
|
||||||
await db.prepare("run", query, ["requiredSegmentVid-raw", 80, 90, -2, 0, "requiredSegmentVid-raw-3", "testman", 0, 50, "sponsor", "skip", "YouTube", 0, 0, 0, getHash("requiredSegmentVid-raw", 1)]);
|
await db.prepare("run", query, ["requiredSegmentVid", 80, 90, -2, 0, "requiredSegmentVid3", "testman", 0, 50, "sponsor", "skip", "YouTube", 0, 0, 0]);
|
||||||
await db.prepare("run", query, ["requiredSegmentVid-raw", 80, 90, 2, 0, "requiredSegmentVid-raw-4", "testman", 0, 50, "sponsor", "skip", "YouTube", 0, 0, 0, getHash("requiredSegmentVid-raw", 1)]);
|
await db.prepare("run", query, ["requiredSegmentVid", 80, 90, 2, 0, "requiredSegmentVid4", "testman", 0, 50, "sponsor", "skip", "YouTube", 0, 0, 0]);
|
||||||
return;
|
return;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
it("Should be able to get a time by category 1", (done: Done) => {
|
it("Should be able to get a time by category 1", (done: Done) => {
|
||||||
fetch(`${getbaseURL()}/api/skipSegments?videoID=testtesttest&category=sponsor`)
|
fetch(`${getbaseURL()}/api/skipSegments?videoID=getSkipSegmentID0&category=sponsor`)
|
||||||
.then(async res => {
|
.then(async res => {
|
||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
const data = await res.json();
|
const data = await res.json();
|
||||||
@@ -36,7 +35,7 @@ describe("getSkipSegments", () => {
|
|||||||
assert.strictEqual(data[0].segment[0], 1);
|
assert.strictEqual(data[0].segment[0], 1);
|
||||||
assert.strictEqual(data[0].segment[1], 11);
|
assert.strictEqual(data[0].segment[1], 11);
|
||||||
assert.strictEqual(data[0].category, "sponsor");
|
assert.strictEqual(data[0].category, "sponsor");
|
||||||
assert.strictEqual(data[0].UUID, "1-uuid-0");
|
assert.strictEqual(data[0].UUID, "uuid01");
|
||||||
assert.strictEqual(data[0].videoDuration, 100);
|
assert.strictEqual(data[0].videoDuration, 100);
|
||||||
done();
|
done();
|
||||||
})
|
})
|
||||||
@@ -44,14 +43,14 @@ describe("getSkipSegments", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("Should be able to get a time by category and action type", (done: Done) => {
|
it("Should be able to get a time by category and action type", (done: Done) => {
|
||||||
fetch(`${getbaseURL()}/api/skipSegments?videoID=testtesttest&category=sponsor&actionType=mute`)
|
fetch(`${getbaseURL()}/api/skipSegments?videoID=getSkipSegmentID0&category=sponsor&actionType=mute`)
|
||||||
.then(async res => {
|
.then(async res => {
|
||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
const data = await res.json();
|
const data = await res.json();
|
||||||
const expected = [{
|
const expected = [{
|
||||||
segment: [12, 14],
|
segment: [12, 14],
|
||||||
category: "sponsor",
|
category: "sponsor",
|
||||||
UUID: "1-uuid-0-2",
|
UUID: "uuid02",
|
||||||
videoDuration: 100
|
videoDuration: 100
|
||||||
}];
|
}];
|
||||||
assert.ok(partialDeepEquals(data, expected));
|
assert.ok(partialDeepEquals(data, expected));
|
||||||
@@ -61,18 +60,18 @@ describe("getSkipSegments", () => {
|
|||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should be able to get a time by category and multiple action types", (done: Done) => {
|
it("Should be able to get a time by category and getSkipSegmentMultiple action types", (done: Done) => {
|
||||||
fetch(`${getbaseURL()}/api/skipSegments?videoID=testtesttest&category=sponsor&actionType=mute&actionType=skip`)
|
fetch(`${getbaseURL()}/api/skipSegments?videoID=getSkipSegmentID0&category=sponsor&actionType=mute&actionType=skip`)
|
||||||
.then(async res => {
|
.then(async res => {
|
||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
const data = await res.json();
|
const data = await res.json();
|
||||||
const expected = [{
|
const expected = [{
|
||||||
segment: [1, 11],
|
segment: [1, 11],
|
||||||
category: "sponsor",
|
category: "sponsor",
|
||||||
UUID: "1-uuid-0",
|
UUID: "uuid01",
|
||||||
videoDuration: 100
|
videoDuration: 100
|
||||||
}, {
|
}, {
|
||||||
UUID: "1-uuid-0-2"
|
UUID: "uuid02"
|
||||||
}];
|
}];
|
||||||
assert.strictEqual(data.length, 2);
|
assert.strictEqual(data.length, 2);
|
||||||
assert.ok(partialDeepEquals(data, expected));
|
assert.ok(partialDeepEquals(data, expected));
|
||||||
@@ -81,18 +80,18 @@ describe("getSkipSegments", () => {
|
|||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should be able to get a time by category and multiple action types (JSON array)", (done: Done) => {
|
it("Should be able to get a time by category and getSkipSegmentMultiple action types (JSON array)", (done: Done) => {
|
||||||
fetch(`${getbaseURL()}/api/skipSegments?videoID=testtesttest&category=sponsor&actionTypes=["mute","skip"]`)
|
fetch(`${getbaseURL()}/api/skipSegments?videoID=getSkipSegmentID0&category=sponsor&actionTypes=["mute","skip"]`)
|
||||||
.then(async res => {
|
.then(async res => {
|
||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
const data = await res.json();
|
const data = await res.json();
|
||||||
const expected = [{
|
const expected = [{
|
||||||
segment: [1, 11],
|
segment: [1, 11],
|
||||||
category: "sponsor",
|
category: "sponsor",
|
||||||
UUID: "1-uuid-0",
|
UUID: "uuid01",
|
||||||
videoDuration: 100
|
videoDuration: 100
|
||||||
}, {
|
}, {
|
||||||
UUID: "1-uuid-0-2"
|
UUID: "uuid02"
|
||||||
}];
|
}];
|
||||||
assert.ok(partialDeepEquals(data, expected));
|
assert.ok(partialDeepEquals(data, expected));
|
||||||
done();
|
done();
|
||||||
@@ -101,14 +100,14 @@ describe("getSkipSegments", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("Should be able to get a time by category for a different service 1", (done: Done) => {
|
it("Should be able to get a time by category for a different service 1", (done: Done) => {
|
||||||
fetch(`${getbaseURL()}/api/skipSegments?videoID=testtesttest2&category=sponsor&service=PeerTube`)
|
fetch(`${getbaseURL()}/api/skipSegments?videoID=getSkipSegmentID1&category=sponsor&service=PeerTube`)
|
||||||
.then(async res => {
|
.then(async res => {
|
||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
const data = await res.json();
|
const data = await res.json();
|
||||||
const expected = [{
|
const expected = [{
|
||||||
segment: [1, 11],
|
segment: [1, 11],
|
||||||
category: "sponsor",
|
category: "sponsor",
|
||||||
UUID: "1-uuid-0-1",
|
UUID: "uuid10",
|
||||||
videoDuration: 120
|
videoDuration: 120
|
||||||
}];
|
}];
|
||||||
assert.ok(partialDeepEquals(data, expected));
|
assert.ok(partialDeepEquals(data, expected));
|
||||||
@@ -119,14 +118,14 @@ describe("getSkipSegments", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("Should be able to get a time by category 2", (done: Done) => {
|
it("Should be able to get a time by category 2", (done: Done) => {
|
||||||
fetch(`${getbaseURL()}/api/skipSegments?videoID=testtesttest&category=intro`)
|
fetch(`${getbaseURL()}/api/skipSegments?videoID=getSkipSegmentID0&category=intro`)
|
||||||
.then(async res => {
|
.then(async res => {
|
||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
const data = await res.json();
|
const data = await res.json();
|
||||||
const expected = [{
|
const expected = [{
|
||||||
segment: [20, 33],
|
segment: [20, 33],
|
||||||
category: "intro",
|
category: "intro",
|
||||||
UUID: "1-uuid-2"
|
UUID: "uuid03"
|
||||||
}];
|
}];
|
||||||
assert.ok(partialDeepEquals(data, expected));
|
assert.ok(partialDeepEquals(data, expected));
|
||||||
assert.strictEqual(data.length, 1);
|
assert.strictEqual(data.length, 1);
|
||||||
@@ -136,14 +135,14 @@ describe("getSkipSegments", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("Should be able to get a time by categories array", (done: Done) => {
|
it("Should be able to get a time by categories array", (done: Done) => {
|
||||||
fetch(`${getbaseURL()}/api/skipSegments?videoID=testtesttest&categories=["sponsor"]`)
|
fetch(`${getbaseURL()}/api/skipSegments?videoID=getSkipSegmentID0&categories=["sponsor"]`)
|
||||||
.then(async res => {
|
.then(async res => {
|
||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
const data = await res.json();
|
const data = await res.json();
|
||||||
const expected = [{
|
const expected = [{
|
||||||
segment: [1, 11],
|
segment: [1, 11],
|
||||||
category: "sponsor",
|
category: "sponsor",
|
||||||
UUID: "1-uuid-0",
|
UUID: "uuid01",
|
||||||
videoDuration: 100
|
videoDuration: 100
|
||||||
}];
|
}];
|
||||||
assert.ok(partialDeepEquals(data, expected));
|
assert.ok(partialDeepEquals(data, expected));
|
||||||
@@ -154,14 +153,14 @@ describe("getSkipSegments", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("Should be able to get a time by categories array 2", (done: Done) => {
|
it("Should be able to get a time by categories array 2", (done: Done) => {
|
||||||
fetch(`${getbaseURL()}/api/skipSegments?videoID=testtesttest&categories=["intro"]`)
|
fetch(`${getbaseURL()}/api/skipSegments?videoID=getSkipSegmentID0&categories=["intro"]`)
|
||||||
.then(async res => {
|
.then(async res => {
|
||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
const data = await res.json();
|
const data = await res.json();
|
||||||
const expected = [{
|
const expected = [{
|
||||||
segment: [20, 33],
|
segment: [20, 33],
|
||||||
category: "intro",
|
category: "intro",
|
||||||
UUID: "1-uuid-2",
|
UUID: "uuid03",
|
||||||
videoDuration: 101
|
videoDuration: 101
|
||||||
}];
|
}];
|
||||||
assert.ok(partialDeepEquals(data, expected));
|
assert.ok(partialDeepEquals(data, expected));
|
||||||
@@ -172,7 +171,7 @@ describe("getSkipSegments", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("Should return 404 if all submissions are hidden", (done: Done) => {
|
it("Should return 404 if all submissions are hidden", (done: Done) => {
|
||||||
fetch(`${getbaseURL()}/api/skipSegments?videoID=onlyHiddenSegments`)
|
fetch(`${getbaseURL()}/api/skipSegments?videoID=getSkipSegmentID6`)
|
||||||
.then(res => {
|
.then(res => {
|
||||||
assert.strictEqual(res.status, 404);
|
assert.strictEqual(res.status, 404);
|
||||||
done();
|
done();
|
||||||
@@ -180,40 +179,40 @@ describe("getSkipSegments", () => {
|
|||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should be able to get multiple times by category", (done: Done) => {
|
it("Should be able to get getSkipSegmentMultiple times by category", (done: Done) => {
|
||||||
fetch(`${getbaseURL()}/api/skipSegments?videoID=multiple&categories=["intro"]`)
|
fetch(`${getbaseURL()}/api/skipSegments?videoID=getSkipSegmentMultiple&categories=["intro"]`)
|
||||||
.then(async res => {
|
.then(async res => {
|
||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
const data = await res.json();
|
const data = await res.json();
|
||||||
assert.strictEqual(data.length, 2);
|
|
||||||
const expected = [{
|
const expected = [{
|
||||||
segment: [1, 11],
|
segment: [1, 11],
|
||||||
category: "intro",
|
category: "intro",
|
||||||
UUID: "1-uuid-6",
|
UUID: "uuid40",
|
||||||
}, {
|
}, {
|
||||||
segment: [20, 33],
|
segment: [20, 33],
|
||||||
category: "intro",
|
category: "intro",
|
||||||
UUID: "1-uuid-7",
|
UUID: "uuid41",
|
||||||
}];
|
}];
|
||||||
assert.ok(partialDeepEquals(data, expected));
|
assert.ok(partialDeepEquals(data, expected));
|
||||||
|
assert.strictEqual(data.length, 2);
|
||||||
done();
|
done();
|
||||||
})
|
})
|
||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should be able to get multiple times by multiple categories", (done: Done) => {
|
it("Should be able to get getSkipSegmentMultiple times by getSkipSegmentMultiple categories", (done: Done) => {
|
||||||
fetch(`${getbaseURL()}/api/skipSegments?videoID=testtesttest&categories=["sponsor", "intro"]`)
|
fetch(`${getbaseURL()}/api/skipSegments?videoID=getSkipSegmentID0&categories=["sponsor", "intro"]`)
|
||||||
.then(async res => {
|
.then(async res => {
|
||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
const data = await res.json();
|
const data = await res.json();
|
||||||
const expected = [{
|
const expected = [{
|
||||||
segment: [1, 11],
|
segment: [1, 11],
|
||||||
category: "sponsor",
|
category: "sponsor",
|
||||||
UUID: "1-uuid-0",
|
UUID: "uuid01",
|
||||||
}, {
|
}, {
|
||||||
segment: [20, 33],
|
segment: [20, 33],
|
||||||
category: "intro",
|
category: "intro",
|
||||||
UUID: "1-uuid-2",
|
UUID: "uuid03",
|
||||||
}];
|
}];
|
||||||
assert.ok(partialDeepEquals(data, expected));
|
assert.ok(partialDeepEquals(data, expected));
|
||||||
assert.strictEqual(data.length, 2);
|
assert.strictEqual(data.length, 2);
|
||||||
@@ -223,7 +222,7 @@ describe("getSkipSegments", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("Should be possible to send unexpected query parameters", (done: Done) => {
|
it("Should be possible to send unexpected query parameters", (done: Done) => {
|
||||||
fetch(`${getbaseURL()}/api/skipSegments?videoID=testtesttest&fakeparam=hello&category=sponsor`)
|
fetch(`${getbaseURL()}/api/skipSegments?videoID=getSkipSegmentID0&fakeparam=hello&category=sponsor`)
|
||||||
.then(async res => {
|
.then(async res => {
|
||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
const data = await res.json();
|
const data = await res.json();
|
||||||
@@ -231,7 +230,7 @@ describe("getSkipSegments", () => {
|
|||||||
const expected = [{
|
const expected = [{
|
||||||
segment: [1, 11],
|
segment: [1, 11],
|
||||||
category: "sponsor",
|
category: "sponsor",
|
||||||
UUID: "1-uuid-0",
|
UUID: "uuid01",
|
||||||
}];
|
}];
|
||||||
assert.ok(partialDeepEquals(data, expected));
|
assert.ok(partialDeepEquals(data, expected));
|
||||||
done();
|
done();
|
||||||
@@ -240,7 +239,7 @@ describe("getSkipSegments", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("Low voted submissions should be hidden", (done: Done) => {
|
it("Low voted submissions should be hidden", (done: Done) => {
|
||||||
fetch(`${getbaseURL()}/api/skipSegments?videoID=test3&category=sponsor`)
|
fetch(`${getbaseURL()}/api/skipSegments?videoID=getSkipSegmentID3&category=sponsor`)
|
||||||
.then(async res => {
|
.then(async res => {
|
||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
const data = await res.json();
|
const data = await res.json();
|
||||||
@@ -248,7 +247,7 @@ describe("getSkipSegments", () => {
|
|||||||
const expected = [{
|
const expected = [{
|
||||||
segment: [1, 11],
|
segment: [1, 11],
|
||||||
category: "sponsor",
|
category: "sponsor",
|
||||||
UUID: "1-uuid-4",
|
UUID: "uuid30",
|
||||||
}];
|
}];
|
||||||
assert.ok(partialDeepEquals(data, expected));
|
assert.ok(partialDeepEquals(data, expected));
|
||||||
done();
|
done();
|
||||||
@@ -266,7 +265,7 @@ describe("getSkipSegments", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("Should return 400 if bad categories argument", (done: Done) => {
|
it("Should return 400 if bad categories argument", (done: Done) => {
|
||||||
fetch(`${getbaseURL()}/api/skipSegments?videoID=testtesttest&categories=[not-quoted,not-quoted]`)
|
fetch(`${getbaseURL()}/api/skipSegments?videoID=getSkipSegmentID0&categories=[not-quoted,not-quoted]`)
|
||||||
.then(res => {
|
.then(res => {
|
||||||
assert.strictEqual(res.status, 400);
|
assert.strictEqual(res.status, 400);
|
||||||
done();
|
done();
|
||||||
@@ -275,7 +274,7 @@ describe("getSkipSegments", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("Should be able send a comma in a query param", (done: Done) => {
|
it("Should be able send a comma in a query param", (done: Done) => {
|
||||||
fetch(`${getbaseURL()}/api/skipSegments?videoID=testtesttest,test&category=sponsor`)
|
fetch(`${getbaseURL()}/api/skipSegments?videoID=getSkipSegmentID2&category=sponsor`)
|
||||||
.then(async res => {
|
.then(async res => {
|
||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
const data = await res.json();
|
const data = await res.json();
|
||||||
@@ -283,7 +282,7 @@ describe("getSkipSegments", () => {
|
|||||||
const expected = [{
|
const expected = [{
|
||||||
segment: [1, 11],
|
segment: [1, 11],
|
||||||
category: "sponsor",
|
category: "sponsor",
|
||||||
UUID: "1-uuid-1",
|
UUID: "uuid20",
|
||||||
}];
|
}];
|
||||||
assert.ok(partialDeepEquals(data, expected));
|
assert.ok(partialDeepEquals(data, expected));
|
||||||
done();
|
done();
|
||||||
@@ -291,8 +290,8 @@ describe("getSkipSegments", () => {
|
|||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should always get locked segment", (done: Done) => {
|
it("Should always get getSkipSegmentLocked segment", (done: Done) => {
|
||||||
fetch(`${getbaseURL()}/api/skipSegments?videoID=locked&category=intro`)
|
fetch(`${getbaseURL()}/api/skipSegments?videoID=getSkipSegmentLocked&category=intro`)
|
||||||
.then(async res => {
|
.then(async res => {
|
||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
const data = await res.json();
|
const data = await res.json();
|
||||||
@@ -300,7 +299,7 @@ describe("getSkipSegments", () => {
|
|||||||
const expected = [{
|
const expected = [{
|
||||||
segment: [20, 33],
|
segment: [20, 33],
|
||||||
category: "intro",
|
category: "intro",
|
||||||
UUID: "1-uuid-locked-8",
|
UUID: "uuid50",
|
||||||
}];
|
}];
|
||||||
assert.ok(partialDeepEquals(data, expected));
|
assert.ok(partialDeepEquals(data, expected));
|
||||||
done();
|
done();
|
||||||
@@ -308,8 +307,8 @@ describe("getSkipSegments", () => {
|
|||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should be able to get multiple categories with repeating parameters", (done: Done) => {
|
it("Should be able to get getSkipSegmentMultiple categories with repeating parameters", (done: Done) => {
|
||||||
fetch(`${getbaseURL()}/api/skipSegments?videoID=testtesttest&category=sponsor&category=intro`)
|
fetch(`${getbaseURL()}/api/skipSegments?videoID=getSkipSegmentID0&category=sponsor&category=intro`)
|
||||||
.then(async res => {
|
.then(async res => {
|
||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
const data = await res.json();
|
const data = await res.json();
|
||||||
@@ -317,11 +316,11 @@ describe("getSkipSegments", () => {
|
|||||||
const expected = [{
|
const expected = [{
|
||||||
segment: [1, 11],
|
segment: [1, 11],
|
||||||
category: "sponsor",
|
category: "sponsor",
|
||||||
UUID: "1-uuid-0",
|
UUID: "uuid01",
|
||||||
}, {
|
}, {
|
||||||
segment: [20, 33],
|
segment: [20, 33],
|
||||||
category: "intro",
|
category: "intro",
|
||||||
UUID: "1-uuid-2",
|
UUID: "uuid03",
|
||||||
}];
|
}];
|
||||||
assert.ok(partialDeepEquals(data, expected));
|
assert.ok(partialDeepEquals(data, expected));
|
||||||
done();
|
done();
|
||||||
@@ -330,7 +329,7 @@ describe("getSkipSegments", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("Should be able to get, categories param overriding repeating category", (done: Done) => {
|
it("Should be able to get, categories param overriding repeating category", (done: Done) => {
|
||||||
fetch(`${getbaseURL()}/api/skipSegments?videoID=testtesttest&categories=["sponsor"]&category=intro`)
|
fetch(`${getbaseURL()}/api/skipSegments?videoID=getSkipSegmentID0&categories=["sponsor"]&category=intro`)
|
||||||
.then(async res => {
|
.then(async res => {
|
||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
const data = await res.json();
|
const data = await res.json();
|
||||||
@@ -338,7 +337,7 @@ describe("getSkipSegments", () => {
|
|||||||
const expected = [{
|
const expected = [{
|
||||||
segment: [1, 11],
|
segment: [1, 11],
|
||||||
category: "sponsor",
|
category: "sponsor",
|
||||||
UUID: "1-uuid-0",
|
UUID: "uuid01",
|
||||||
}];
|
}];
|
||||||
assert.ok(partialDeepEquals(data, expected));
|
assert.ok(partialDeepEquals(data, expected));
|
||||||
done();
|
done();
|
||||||
@@ -347,15 +346,15 @@ describe("getSkipSegments", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("Should be able to get specific segments with requiredSegments", (done: Done) => {
|
it("Should be able to get specific segments with requiredSegments", (done: Done) => {
|
||||||
fetch(`${getbaseURL()}/api/skipSegments?videoID=requiredSegmentVid-raw&requiredSegments=["requiredSegmentVid-raw-2","requiredSegmentVid-raw-3"]`)
|
fetch(`${getbaseURL()}/api/skipSegments?videoID=requiredSegmentVid&requiredSegments=["requiredSegmentVid2","requiredSegmentVid3"]`)
|
||||||
.then(async res => {
|
.then(async res => {
|
||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
const data = await res.json();
|
const data = await res.json();
|
||||||
assert.strictEqual(data.length, 2);
|
assert.strictEqual(data.length, 2);
|
||||||
const expected = [{
|
const expected = [{
|
||||||
UUID: "requiredSegmentVid-raw-2",
|
UUID: "requiredSegmentVid2",
|
||||||
}, {
|
}, {
|
||||||
UUID: "requiredSegmentVid-raw-3",
|
UUID: "requiredSegmentVid3",
|
||||||
}];
|
}];
|
||||||
assert.ok(partialDeepEquals(data, expected));
|
assert.ok(partialDeepEquals(data, expected));
|
||||||
done();
|
done();
|
||||||
@@ -364,15 +363,15 @@ describe("getSkipSegments", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("Should be able to get specific segments with repeating requiredSegment", (done: Done) => {
|
it("Should be able to get specific segments with repeating requiredSegment", (done: Done) => {
|
||||||
fetch(`${getbaseURL()}/api/skipSegments?videoID=requiredSegmentVid-raw&requiredSegment=requiredSegmentVid-raw-2&requiredSegment=requiredSegmentVid-raw-3`)
|
fetch(`${getbaseURL()}/api/skipSegments?videoID=requiredSegmentVid&requiredSegment=requiredSegmentVid2&requiredSegment=requiredSegmentVid3`)
|
||||||
.then(async res => {
|
.then(async res => {
|
||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
const data = await res.json();
|
const data = await res.json();
|
||||||
assert.strictEqual(data.length, 2);
|
assert.strictEqual(data.length, 2);
|
||||||
const expected = [{
|
const expected = [{
|
||||||
UUID: "requiredSegmentVid-raw-2",
|
UUID: "requiredSegmentVid2",
|
||||||
}, {
|
}, {
|
||||||
UUID: "requiredSegmentVid-raw-3",
|
UUID: "requiredSegmentVid3",
|
||||||
}];
|
}];
|
||||||
assert.ok(partialDeepEquals(data, expected));
|
assert.ok(partialDeepEquals(data, expected));
|
||||||
done();
|
done();
|
||||||
|
|||||||
@@ -12,21 +12,23 @@ const sinonStub = mockManager.mock("listVideos");
|
|||||||
sinonStub.callsFake(YouTubeApiMock.listVideos);
|
sinonStub.callsFake(YouTubeApiMock.listVideos);
|
||||||
|
|
||||||
describe("getSkipSegmentsByHash", () => {
|
describe("getSkipSegmentsByHash", () => {
|
||||||
|
const getSegmentsByHash0Hash = "fdaff4dee1043451faa7398324fb63d8618ebcd11bddfe0491c488db12c6c910";
|
||||||
|
const requiredSegmentVidHash = "d51822c3f681e07aef15a8855f52ad12db9eb9cf059e65b16b64c43359557f61";
|
||||||
before(async () => {
|
before(async () => {
|
||||||
const query = 'INSERT INTO "sponsorTimes" ("videoID", "startTime", "endTime", "votes", "UUID", "userID", "timeSubmitted", views, category, "actionType", "service", "hidden", "shadowHidden", "hashedVideoID") VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)';
|
const query = 'INSERT INTO "sponsorTimes" ("videoID", "startTime", "endTime", "votes", "UUID", "userID", "timeSubmitted", views, category, "actionType", "service", "hidden", "shadowHidden", "hashedVideoID") VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)';
|
||||||
await db.prepare("run", query, ["getSegmentsByHash-0", 1, 10, 2, "getSegmentsByHash-0-0", "testman", 0, 50, "sponsor", "skip", "YouTube", 0, 0, "fdaff4dee1043451faa7398324fb63d8618ebcd11bddfe0491c488db12c6c910"]);
|
await db.prepare("run", query, ["getSegmentsByHash-0", 1, 10, 2, "getSegmentsByHash-01", "testman", 0, 50, "sponsor", "skip", "YouTube", 0, 0, getSegmentsByHash0Hash]);
|
||||||
await db.prepare("run", query, ["getSegmentsByHash-0", 1, 10, 2, "getSegmentsByHash-0-0-1", "testman", 0, 50, "sponsor", "skip", "PeerTube", 0, 0, "fdaff4dee1043451faa7398324fb63d8618ebcd11bddfe0491c488db12c6c910"]);
|
await db.prepare("run", query, ["getSegmentsByHash-0", 1, 10, 2, "getSegmentsByHash-02", "testman", 0, 50, "sponsor", "skip", "PeerTube", 0, 0, getSegmentsByHash0Hash]);
|
||||||
await db.prepare("run", query, ["getSegmentsByHash-0", 20, 30, 2, "getSegmentsByHash-0-1", "testman", 100, 150, "intro", "skip", "YouTube", 0, 0, "fdaff4dee1043451faa7398324fb63d8618ebcd11bddfe0491c488db12c6c910"]);
|
await db.prepare("run", query, ["getSegmentsByHash-0", 20, 30, 2, "getSegmentsByHash-03", "testman", 100, 150, "intro", "skip", "YouTube", 0, 0, getSegmentsByHash0Hash]);
|
||||||
await db.prepare("run", query, ["getSegmentsByHash-0", 40, 50, 2, "getSegmentsByHash-0-2", "testman", 0, 50, "sponsor", "mute", "YouTube", 0, 0, "fdaff4dee1043451faa7398324fb63d8618ebcd11bddfe0491c488db12c6c910"]);
|
await db.prepare("run", query, ["getSegmentsByHash-0", 40, 50, 2, "getSegmentsByHash-04", "testman", 0, 50, "sponsor", "mute", "YouTube", 0, 0, getSegmentsByHash0Hash]);
|
||||||
await db.prepare("run", query, ["getSegmentsByHash-noMatchHash", 40, 50, 2, "getSegmentsByHash-noMatchHash", "testman", 0, 50, "sponsor", "skip", "YouTube", 0, 0, "fdaffnoMatchHash"]);
|
await db.prepare("run", query, ["getSegmentsByHash-noMatchHash", 40, 50, 2, "getSegmentsByHash-noMatchHash", "testman", 0, 50, "sponsor", "skip", "YouTube", 0, 0, "fdaffnoMatchHash"]);
|
||||||
await db.prepare("run", query, ["getSegmentsByHash-1", 60, 70, 2, "getSegmentsByHash-1", "testman", 0, 50, "sponsor", "skip", "YouTube", 0, 0, "3272fa85ee0927f6073ef6f07ad5f3146047c1abba794cfa364d65ab9921692b"]);
|
await db.prepare("run", query, ["getSegmentsByHash-1", 60, 70, 2, "getSegmentsByHash-1", "testman", 0, 50, "sponsor", "skip", "YouTube", 0, 0, "3272fa85ee0927f6073ef6f07ad5f3146047c1abba794cfa364d65ab9921692b"]);
|
||||||
await db.prepare("run", query, ["onlyHidden", 60, 70, 2, "onlyHidden", "testman", 0, 50, "sponsor", "skip", "YouTube", 1, 0, "f3a199e1af001d716cdc6599360e2b062c2d2b3fa2885f6d9d2fd741166cbbd3"]);
|
await db.prepare("run", query, ["onlyHidden", 60, 70, 2, "onlyHidden", "testman", 0, 50, "sponsor", "skip", "YouTube", 1, 0, "f3a199e1af001d716cdc6599360e2b062c2d2b3fa2885f6d9d2fd741166cbbd3"]);
|
||||||
await db.prepare("run", query, ["highlightVid", 60, 60, 2, "highlightVid-1", "testman", 0, 50, "poi_highlight", "skip", "YouTube", 0, 0, getHash("highlightVid", 1)]);
|
await db.prepare("run", query, ["highlightVid", 60, 60, 2, "highlightVid-1", "testman", 0, 50, "poi_highlight", "skip", "YouTube", 0, 0, getHash("highlightVid", 1)]);
|
||||||
await db.prepare("run", query, ["highlightVid", 70, 70, 2, "highlightVid-2", "testman", 0, 50, "poi_highlight", "skip", "YouTube", 0, 0, getHash("highlightVid", 1)]);
|
await db.prepare("run", query, ["highlightVid", 70, 70, 2, "highlightVid-2", "testman", 0, 50, "poi_highlight", "skip", "YouTube", 0, 0, getHash("highlightVid", 1)]);
|
||||||
await db.prepare("run", query, ["requiredSegmentVid", 60, 70, 2, "requiredSegmentVid-1", "testman", 0, 50, "sponsor", "skip", "YouTube", 0, 0, "d51822c3f681e07aef15a8855f52ad12db9eb9cf059e65b16b64c43359557f61"]);
|
await db.prepare("run", query, ["requiredSegmentVid", 60, 70, 2, "requiredSegmentVid-1", "testman", 0, 50, "sponsor", "skip", "YouTube", 0, 0, requiredSegmentVidHash]);
|
||||||
await db.prepare("run", query, ["requiredSegmentVid", 60, 70, -2, "requiredSegmentVid-2", "testman", 0, 50, "sponsor", "skip", "YouTube", 0, 0, "d51822c3f681e07aef15a8855f52ad12db9eb9cf059e65b16b64c43359557f61"]);
|
await db.prepare("run", query, ["requiredSegmentVid", 60, 70, -2, "requiredSegmentVid-2", "testman", 0, 50, "sponsor", "skip", "YouTube", 0, 0, requiredSegmentVidHash]);
|
||||||
await db.prepare("run", query, ["requiredSegmentVid", 80, 90, -2, "requiredSegmentVid-3", "testman", 0, 50, "sponsor", "skip", "YouTube", 0, 0, "d51822c3f681e07aef15a8855f52ad12db9eb9cf059e65b16b64c43359557f61"]);
|
await db.prepare("run", query, ["requiredSegmentVid", 80, 90, -2, "requiredSegmentVid-3", "testman", 0, 50, "sponsor", "skip", "YouTube", 0, 0, requiredSegmentVidHash]);
|
||||||
await db.prepare("run", query, ["requiredSegmentVid", 80, 90, 2, "requiredSegmentVid-4", "testman", 0, 50, "sponsor", "skip", "YouTube", 0, 0, "d51822c3f681e07aef15a8855f52ad12db9eb9cf059e65b16b64c43359557f61"]);
|
await db.prepare("run", query, ["requiredSegmentVid", 80, 90, 2, "requiredSegmentVid-4", "testman", 0, 50, "sponsor", "skip", "YouTube", 0, 0, requiredSegmentVidHash]);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should be able to get a 200", (done: Done) => {
|
it("Should be able to get a 200", (done: Done) => {
|
||||||
@@ -146,7 +148,7 @@ describe("getSkipSegmentsByHash", () => {
|
|||||||
const expected = [{
|
const expected = [{
|
||||||
segments: [{
|
segments: [{
|
||||||
category: "sponsor",
|
category: "sponsor",
|
||||||
UUID: "getSegmentsByHash-0-0",
|
UUID: "getSegmentsByHash-01",
|
||||||
}]
|
}]
|
||||||
}, {
|
}, {
|
||||||
segments: [{
|
segments: [{
|
||||||
@@ -172,7 +174,7 @@ describe("getSkipSegmentsByHash", () => {
|
|||||||
const expected = [{
|
const expected = [{
|
||||||
segments: [{
|
segments: [{
|
||||||
category: "sponsor",
|
category: "sponsor",
|
||||||
UUID: "getSegmentsByHash-0-0",
|
UUID: "getSegmentsByHash-01",
|
||||||
}]
|
}]
|
||||||
}, {
|
}, {
|
||||||
segments: [{
|
segments: [{
|
||||||
@@ -196,9 +198,9 @@ describe("getSkipSegmentsByHash", () => {
|
|||||||
const expected = [{
|
const expected = [{
|
||||||
segments: [{
|
segments: [{
|
||||||
category: "sponsor",
|
category: "sponsor",
|
||||||
UUID: "getSegmentsByHash-0-0",
|
UUID: "getSegmentsByHash-01",
|
||||||
}, {
|
}, {
|
||||||
UUID: "getSegmentsByHash-0-2",
|
UUID: "getSegmentsByHash-04",
|
||||||
}]
|
}]
|
||||||
}, {
|
}, {
|
||||||
segments: [{
|
segments: [{
|
||||||
@@ -220,9 +222,9 @@ describe("getSkipSegmentsByHash", () => {
|
|||||||
const expected = [{
|
const expected = [{
|
||||||
segments: [{
|
segments: [{
|
||||||
category: "sponsor",
|
category: "sponsor",
|
||||||
UUID: "getSegmentsByHash-0-0",
|
UUID: "getSegmentsByHash-01",
|
||||||
}, {
|
}, {
|
||||||
UUID: "getSegmentsByHash-0-2",
|
UUID: "getSegmentsByHash-04",
|
||||||
}]
|
}]
|
||||||
}, {
|
}, {
|
||||||
segments: [{
|
segments: [{
|
||||||
@@ -243,7 +245,7 @@ describe("getSkipSegmentsByHash", () => {
|
|||||||
assert.strictEqual(data.length, 1);
|
assert.strictEqual(data.length, 1);
|
||||||
const expected = [{
|
const expected = [{
|
||||||
segments: [{
|
segments: [{
|
||||||
UUID: "getSegmentsByHash-0-0-1"
|
UUID: "getSegmentsByHash-02"
|
||||||
}]
|
}]
|
||||||
}];
|
}];
|
||||||
assert.ok(partialDeepEquals(data, expected));
|
assert.ok(partialDeepEquals(data, expected));
|
||||||
@@ -311,11 +313,11 @@ describe("getSkipSegmentsByHash", () => {
|
|||||||
segments: [{
|
segments: [{
|
||||||
segment: [1, 10],
|
segment: [1, 10],
|
||||||
category: "sponsor",
|
category: "sponsor",
|
||||||
UUID: "getSegmentsByHash-0-0",
|
UUID: "getSegmentsByHash-01",
|
||||||
}, {
|
}, {
|
||||||
segment: [20, 30],
|
segment: [20, 30],
|
||||||
category: "intro",
|
category: "intro",
|
||||||
UUID: "getSegmentsByHash-0-1",
|
UUID: "getSegmentsByHash-03",
|
||||||
}]
|
}]
|
||||||
}];
|
}];
|
||||||
assert.ok(partialDeepEquals(data, expected));
|
assert.ok(partialDeepEquals(data, expected));
|
||||||
|
|||||||
@@ -10,15 +10,16 @@ describe("getUserInfo", () => {
|
|||||||
await db.prepare("run", insertUserNameQuery, [getHash("getuserinfo_user_01"), "Username user 01"]);
|
await db.prepare("run", insertUserNameQuery, [getHash("getuserinfo_user_01"), "Username user 01"]);
|
||||||
|
|
||||||
const sponsorTimesQuery = 'INSERT INTO "sponsorTimes" ("videoID", "startTime", "endTime", "votes", "UUID", "userID", "timeSubmitted", views, category, "shadowHidden") VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?)';
|
const sponsorTimesQuery = 'INSERT INTO "sponsorTimes" ("videoID", "startTime", "endTime", "votes", "UUID", "userID", "timeSubmitted", views, category, "shadowHidden") VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?)';
|
||||||
await db.prepare("run", sponsorTimesQuery, ["xxxyyyzzz", 1, 11, 2, "uuid000001", getHash("getuserinfo_user_01"), 1, 10, "sponsor", 0]);
|
await db.prepare("run", sponsorTimesQuery, ["getUserInfo0", 1, 11, 2, "uuid000001", getHash("getuserinfo_user_01"), 1, 10, "sponsor", 0]);
|
||||||
await db.prepare("run", sponsorTimesQuery, ["xxxyyyzzz", 1, 11, 2, "uuid000002", getHash("getuserinfo_user_01"), 2, 10, "sponsor", 0]);
|
await db.prepare("run", sponsorTimesQuery, ["getUserInfo0", 1, 11, 2, "uuid000002", getHash("getuserinfo_user_01"), 2, 10, "sponsor", 0]);
|
||||||
await db.prepare("run", sponsorTimesQuery, ["yyyxxxzzz", 1, 11, -1, "uuid000003", getHash("getuserinfo_user_01"), 3, 10, "sponsor", 0]);
|
await db.prepare("run", sponsorTimesQuery, ["getUserInfo1", 1, 11, -1, "uuid000003", getHash("getuserinfo_user_01"), 3, 10, "sponsor", 0]);
|
||||||
await db.prepare("run", sponsorTimesQuery, ["yyyxxxzzz", 1, 11, -2, "uuid000004", getHash("getuserinfo_user_01"), 4, 10, "sponsor", 1]);
|
await db.prepare("run", sponsorTimesQuery, ["getUserInfo1", 1, 11, -2, "uuid000004", getHash("getuserinfo_user_01"), 4, 10, "sponsor", 1]);
|
||||||
await db.prepare("run", sponsorTimesQuery, ["xzzzxxyyy", 1, 11, -5, "uuid000005", getHash("getuserinfo_user_01"), 5, 10, "sponsor", 1]);
|
await db.prepare("run", sponsorTimesQuery, ["getUserInfo2", 1, 11, -5, "uuid000005", getHash("getuserinfo_user_01"), 5, 10, "sponsor", 1]);
|
||||||
await db.prepare("run", sponsorTimesQuery, ["zzzxxxyyy", 1, 11, 2, "uuid000006", getHash("getuserinfo_user_02"), 6, 10, "sponsor", 0]);
|
await db.prepare("run", sponsorTimesQuery, ["getUserInfo0", 1, 11, 2, "uuid000007", getHash("getuserinfo_user_02"), 7, 10, "sponsor", 1]);
|
||||||
await db.prepare("run", sponsorTimesQuery, ["xxxyyyzzz", 1, 11, 2, "uuid000007", getHash("getuserinfo_user_02"), 7, 10, "sponsor", 1]);
|
await db.prepare("run", sponsorTimesQuery, ["getUserInfo0", 1, 11, 2, "uuid000008", getHash("getuserinfo_user_02"), 8, 10, "sponsor", 1]);
|
||||||
await db.prepare("run", sponsorTimesQuery, ["xxxyyyzzz", 1, 11, 2, "uuid000008", getHash("getuserinfo_user_02"), 8, 10, "sponsor", 1]);
|
await db.prepare("run", sponsorTimesQuery, ["getUserInfo0", 0, 36000, 2,"uuid000009", getHash("getuserinfo_user_03"), 8, 10, "sponsor", 0]);
|
||||||
await db.prepare("run", sponsorTimesQuery, ["xxxyyyzzz", 0, 36000, 2, "uuid000009", getHash("getuserinfo_user_03"), 8, 2, "sponsor", 0]);
|
await db.prepare("run", sponsorTimesQuery, ["getUserInfo3", 1, 11, 2, "uuid000006", getHash("getuserinfo_user_02"), 6, 10, "sponsor", 0]);
|
||||||
|
|
||||||
|
|
||||||
const insertWarningQuery = 'INSERT INTO warnings ("userID", "issueTime", "issuerUserID", "enabled", "reason") VALUES (?, ?, ?, ?, ?)';
|
const insertWarningQuery = 'INSERT INTO warnings ("userID", "issueTime", "issuerUserID", "enabled", "reason") VALUES (?, ?, ?, ?, ?)';
|
||||||
await db.prepare("run", insertWarningQuery, [getHash("getuserinfo_warning_0"), 10, "getuserinfo_vip", 1, "warning0-0"]);
|
await db.prepare("run", insertWarningQuery, [getHash("getuserinfo_warning_0"), 10, "getuserinfo_vip", 1, "warning0-0"]);
|
||||||
@@ -303,8 +304,8 @@ describe("getUserInfo", () => {
|
|||||||
const expected = {
|
const expected = {
|
||||||
userName: "807e0a5d0a62c9c4365fae3d403e4618a3226f231314a898fa1555a0e55eab9e",
|
userName: "807e0a5d0a62c9c4365fae3d403e4618a3226f231314a898fa1555a0e55eab9e",
|
||||||
userID: "807e0a5d0a62c9c4365fae3d403e4618a3226f231314a898fa1555a0e55eab9e",
|
userID: "807e0a5d0a62c9c4365fae3d403e4618a3226f231314a898fa1555a0e55eab9e",
|
||||||
minutesSaved: 20,
|
minutesSaved: 100,
|
||||||
viewCount: 2,
|
viewCount: 10,
|
||||||
ignoredViewCount: 0,
|
ignoredViewCount: 0,
|
||||||
segmentCount: 1,
|
segmentCount: 1,
|
||||||
ignoredSegmentCount: 0,
|
ignoredSegmentCount: 0,
|
||||||
|
|||||||
@@ -16,20 +16,20 @@ const stringDeepEquals = (a: string[] ,b: string[]): boolean => {
|
|||||||
describe("lockCategoriesRecords", () => {
|
describe("lockCategoriesRecords", () => {
|
||||||
before(async () => {
|
before(async () => {
|
||||||
const insertVipUserQuery = 'INSERT INTO "vipUsers" ("userID") VALUES (?)';
|
const insertVipUserQuery = 'INSERT INTO "vipUsers" ("userID") VALUES (?)';
|
||||||
await db.prepare("run", insertVipUserQuery, [getHash("VIPUser-lockCategories")]);
|
await db.prepare("run", insertVipUserQuery, [getHash("lockCategoriesRecordsVIPUser")]);
|
||||||
|
|
||||||
const insertLockCategoryQuery = 'INSERT INTO "lockCategories" ("userID", "videoID", "category", "reason") VALUES (?, ?, ?, ?)';
|
const insertLockCategoryQuery = 'INSERT INTO "lockCategories" ("userID", "videoID", "category", "reason") VALUES (?, ?, ?, ?)';
|
||||||
await db.prepare("run", insertLockCategoryQuery, [getHash("VIPUser-lockCategories"), "no-segments-video-id", "sponsor", "reason-1"]);
|
await db.prepare("run", insertLockCategoryQuery, [getHash("lockCategoriesRecordsVIPUser"), "no-segments-video-id", "sponsor", "reason-1"]);
|
||||||
await db.prepare("run", insertLockCategoryQuery, [getHash("VIPUser-lockCategories"), "no-segments-video-id", "intro", "reason-1"]);
|
await db.prepare("run", insertLockCategoryQuery, [getHash("lockCategoriesRecordsVIPUser"), "no-segments-video-id", "intro", "reason-1"]);
|
||||||
|
|
||||||
await db.prepare("run", insertLockCategoryQuery, [getHash("VIPUser-lockCategories"), "no-segments-video-id-1", "sponsor", "reason-2"]);
|
await db.prepare("run", insertLockCategoryQuery, [getHash("lockCategoriesRecordsVIPUser"), "no-segments-video-id-1", "sponsor", "reason-2"]);
|
||||||
await db.prepare("run", insertLockCategoryQuery, [getHash("VIPUser-lockCategories"), "no-segments-video-id-1", "intro", "reason-2"]);
|
await db.prepare("run", insertLockCategoryQuery, [getHash("lockCategoriesRecordsVIPUser"), "no-segments-video-id-1", "intro", "reason-2"]);
|
||||||
await db.prepare("run", insertLockCategoryQuery, [getHash("VIPUser-lockCategories"), "lockCategoryVideo", "sponsor", "reason-3"]);
|
await db.prepare("run", insertLockCategoryQuery, [getHash("lockCategoriesRecordsVIPUser"), "lockCategoryVideo", "sponsor", "reason-3"]);
|
||||||
|
|
||||||
await db.prepare("run", insertLockCategoryQuery, [getHash("VIPUser-lockCategories"), "delete-record", "sponsor", "reason-4"]);
|
await db.prepare("run", insertLockCategoryQuery, [getHash("lockCategoriesRecordsVIPUser"), "delete-record", "sponsor", "reason-4"]);
|
||||||
|
|
||||||
await db.prepare("run", insertLockCategoryQuery, [getHash("VIPUser-lockCategories"), "delete-record-1", "sponsor", "reason-5"]);
|
await db.prepare("run", insertLockCategoryQuery, [getHash("lockCategoriesRecordsVIPUser"), "delete-record-1", "sponsor", "reason-5"]);
|
||||||
await db.prepare("run", insertLockCategoryQuery, [getHash("VIPUser-lockCategories"), "delete-record-1", "intro", "reason-5"]);
|
await db.prepare("run", insertLockCategoryQuery, [getHash("lockCategoriesRecordsVIPUser"), "delete-record-1", "intro", "reason-5"]);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should update the database version when starting the application", async () => {
|
it("Should update the database version when starting the application", async () => {
|
||||||
@@ -40,7 +40,7 @@ describe("lockCategoriesRecords", () => {
|
|||||||
it("Should be able to submit categories not in video (http response)", (done: Done) => {
|
it("Should be able to submit categories not in video (http response)", (done: Done) => {
|
||||||
const json = {
|
const json = {
|
||||||
videoID: "no-segments-video-id",
|
videoID: "no-segments-video-id",
|
||||||
userID: "VIPUser-lockCategories",
|
userID: "lockCategoriesRecordsVIPUser",
|
||||||
categories: [
|
categories: [
|
||||||
"outro",
|
"outro",
|
||||||
"shilling",
|
"shilling",
|
||||||
@@ -75,7 +75,7 @@ describe("lockCategoriesRecords", () => {
|
|||||||
it("Should be able to submit categories not in video (sql check)", (done: Done) => {
|
it("Should be able to submit categories not in video (sql check)", (done: Done) => {
|
||||||
const json = {
|
const json = {
|
||||||
videoID: "no-segments-video-id-1",
|
videoID: "no-segments-video-id-1",
|
||||||
userID: "VIPUser-lockCategories",
|
userID: "lockCategoriesRecordsVIPUser",
|
||||||
categories: [
|
categories: [
|
||||||
"outro",
|
"outro",
|
||||||
"shilling",
|
"shilling",
|
||||||
@@ -114,7 +114,7 @@ describe("lockCategoriesRecords", () => {
|
|||||||
it("Should be able to submit categories not in video with reason (http response)", (done: Done) => {
|
it("Should be able to submit categories not in video with reason (http response)", (done: Done) => {
|
||||||
const json = {
|
const json = {
|
||||||
videoID: "no-segments-video-id",
|
videoID: "no-segments-video-id",
|
||||||
userID: "VIPUser-lockCategories",
|
userID: "lockCategoriesRecordsVIPUser",
|
||||||
categories: [
|
categories: [
|
||||||
"outro",
|
"outro",
|
||||||
"shilling",
|
"shilling",
|
||||||
@@ -153,7 +153,7 @@ describe("lockCategoriesRecords", () => {
|
|||||||
it("Should be able to submit categories not in video with reason (sql check)", (done: Done) => {
|
it("Should be able to submit categories not in video with reason (sql check)", (done: Done) => {
|
||||||
const json = {
|
const json = {
|
||||||
videoID: "no-segments-video-id-1",
|
videoID: "no-segments-video-id-1",
|
||||||
userID: "VIPUser-lockCategories",
|
userID: "lockCategoriesRecordsVIPUser",
|
||||||
categories: [
|
categories: [
|
||||||
"outro",
|
"outro",
|
||||||
"shilling",
|
"shilling",
|
||||||
@@ -199,7 +199,7 @@ describe("lockCategoriesRecords", () => {
|
|||||||
it("Should be able to submit categories with _ in the category", (done: Done) => {
|
it("Should be able to submit categories with _ in the category", (done: Done) => {
|
||||||
const json = {
|
const json = {
|
||||||
videoID: "underscore",
|
videoID: "underscore",
|
||||||
userID: "VIPUser-lockCategories",
|
userID: "lockCategoriesRecordsVIPUser",
|
||||||
categories: [
|
categories: [
|
||||||
"word_word",
|
"word_word",
|
||||||
],
|
],
|
||||||
@@ -223,7 +223,7 @@ describe("lockCategoriesRecords", () => {
|
|||||||
it("Should be able to submit categories with upper and lower case in the category", (done: Done) => {
|
it("Should be able to submit categories with upper and lower case in the category", (done: Done) => {
|
||||||
const json = {
|
const json = {
|
||||||
videoID: "bothCases",
|
videoID: "bothCases",
|
||||||
userID: "VIPUser-lockCategories",
|
userID: "lockCategoriesRecordsVIPUser",
|
||||||
categories: [
|
categories: [
|
||||||
"wordWord",
|
"wordWord",
|
||||||
],
|
],
|
||||||
@@ -247,7 +247,7 @@ describe("lockCategoriesRecords", () => {
|
|||||||
it("Should not be able to submit categories with $ in the category", (done: Done) => {
|
it("Should not be able to submit categories with $ in the category", (done: Done) => {
|
||||||
const json = {
|
const json = {
|
||||||
videoID: "specialChar",
|
videoID: "specialChar",
|
||||||
userID: "VIPUser-lockCategories",
|
userID: "lockCategoriesRecordsVIPUser",
|
||||||
categories: [
|
categories: [
|
||||||
"word&word",
|
"word&word",
|
||||||
],
|
],
|
||||||
@@ -414,7 +414,7 @@ describe("lockCategoriesRecords", () => {
|
|||||||
it("Should be able to delete a lockCategories record", (done: Done) => {
|
it("Should be able to delete a lockCategories record", (done: Done) => {
|
||||||
const json = {
|
const json = {
|
||||||
videoID: "delete-record",
|
videoID: "delete-record",
|
||||||
userID: "VIPUser-lockCategories",
|
userID: "lockCategoriesRecordsVIPUser",
|
||||||
categories: [
|
categories: [
|
||||||
"sponsor",
|
"sponsor",
|
||||||
],
|
],
|
||||||
@@ -439,7 +439,7 @@ describe("lockCategoriesRecords", () => {
|
|||||||
it("Should be able to delete one lockCategories record without removing another", (done: Done) => {
|
it("Should be able to delete one lockCategories record without removing another", (done: Done) => {
|
||||||
const json = {
|
const json = {
|
||||||
videoID: "delete-record-1",
|
videoID: "delete-record-1",
|
||||||
userID: "VIPUser-lockCategories",
|
userID: "lockCategoriesRecordsVIPUser",
|
||||||
categories: [
|
categories: [
|
||||||
"sponsor",
|
"sponsor",
|
||||||
],
|
],
|
||||||
|
|||||||
@@ -1,18 +1,17 @@
|
|||||||
import fetch from "node-fetch";
|
import fetch from "node-fetch";
|
||||||
import {db} from "../../src/databases/databases";
|
import {db} from "../../src/databases/databases";
|
||||||
import {Done, getbaseURL, partialDeepEquals} from "../utils";
|
import {Done, getbaseURL, partialDeepEquals} from "../utils";
|
||||||
import {getHash} from "../../src/utils/getHash";
|
|
||||||
import assert from "assert";
|
import assert from "assert";
|
||||||
|
|
||||||
describe("getVideoSponsorTime (Old get method)", () => {
|
describe("getVideoSponsorTime (Old get method)", () => {
|
||||||
before(async () => {
|
before(async () => {
|
||||||
const insertSponsorTimes = 'INSERT INTO "sponsorTimes" ("videoID", "startTime", "endTime", "votes", "UUID", "userID", "timeSubmitted", views, category, "shadowHidden", "hashedVideoID") VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)';
|
const insertSponsorTimes = 'INSERT INTO "sponsorTimes" ("videoID", "startTime", "endTime", "votes", "UUID", "userID", "timeSubmitted", views, category, "shadowHidden") VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?)';
|
||||||
await db.prepare("run", insertSponsorTimes, ["old-testtesttest", 1, 11, 2, "uuid-0", "testman", 0, 50, "sponsor", 0, getHash("old-testtesttest", 1)]);
|
await db.prepare("run", insertSponsorTimes, ["oldGetSponsorTime0", 1, 11, 2, "oldGetSponsorTime00", "oldGetSponsorTimeUser", 0, 50, "sponsor", 0]);
|
||||||
await db.prepare("run", insertSponsorTimes, ["old-testtesttest,test", 1, 11, 2, "uuid-1", "testman", 0, 50, "sponsor", 0, getHash("old-testtesttest,test", 1)]);
|
await db.prepare("run", insertSponsorTimes, ["oldGetSponsorTime1,test", 1, 11, 2, "oldGetSponsorTime01", "oldGetSponsorTimeUser", 0, 50, "sponsor", 0]);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should be able to get a time", (done: Done) => {
|
it("Should be able to get a time", (done: Done) => {
|
||||||
fetch(`${getbaseURL()}/api/getVideoSponsorTimes?videoID=old-testtesttest`)
|
fetch(`${getbaseURL()}/api/getVideoSponsorTimes?videoID=oldGetSponsorTime0`)
|
||||||
.then(res => {
|
.then(res => {
|
||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
done();
|
done();
|
||||||
@@ -31,7 +30,7 @@ describe("getVideoSponsorTime (Old get method)", () => {
|
|||||||
|
|
||||||
|
|
||||||
it("Should be possible to send unexpected query parameters", (done: Done) => {
|
it("Should be possible to send unexpected query parameters", (done: Done) => {
|
||||||
fetch(`${getbaseURL()}/api/getVideoSponsorTimes?videoID=old-testtesttest&fakeparam=hello`)
|
fetch(`${getbaseURL()}/api/getVideoSponsorTimes?videoID=oldGetSponsorTime0&fakeparam=hello`)
|
||||||
.then(res => {
|
.then(res => {
|
||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
done();
|
done();
|
||||||
@@ -40,12 +39,12 @@ describe("getVideoSponsorTime (Old get method)", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("Should be able send a comma in a query param", (done: Done) => {
|
it("Should be able send a comma in a query param", (done: Done) => {
|
||||||
fetch(`${getbaseURL()}/api/getVideoSponsorTimes?videoID=old-testtesttest,test`)
|
fetch(`${getbaseURL()}/api/getVideoSponsorTimes?videoID=oldGetSponsorTime1,test`)
|
||||||
.then(async res => {
|
.then(async res => {
|
||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
const data = await res.json();
|
const data = await res.json();
|
||||||
const expected = {
|
const expected = {
|
||||||
UUIDs: ["uuid-1"],
|
UUIDs: ["oldGetSponsorTime01"],
|
||||||
};
|
};
|
||||||
assert.ok(partialDeepEquals(data, expected));
|
assert.ok(partialDeepEquals(data, expected));
|
||||||
done();
|
done();
|
||||||
@@ -54,13 +53,13 @@ describe("getVideoSponsorTime (Old get method)", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("Should be able to get the correct time", (done: Done) => {
|
it("Should be able to get the correct time", (done: Done) => {
|
||||||
fetch(`${getbaseURL()}/api/getVideoSponsorTimes?videoID=old-testtesttest`)
|
fetch(`${getbaseURL()}/api/getVideoSponsorTimes?videoID=oldGetSponsorTime0`)
|
||||||
.then(async res => {
|
.then(async res => {
|
||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
const data = await res.json();
|
const data = await res.json();
|
||||||
const expected = {
|
const expected = {
|
||||||
sponsorTimes: [[1, 11]],
|
sponsorTimes: [[1, 11]],
|
||||||
UUIDs: ["uuid-0"]
|
UUIDs: ["oldGetSponsorTime00"]
|
||||||
};
|
};
|
||||||
assert.ok(partialDeepEquals(data, expected));
|
assert.ok(partialDeepEquals(data, expected));
|
||||||
done();
|
done();
|
||||||
|
|||||||
@@ -3,13 +3,17 @@ import {Done, getbaseURL, partialDeepEquals} from "../utils";
|
|||||||
import {db} from "../../src/databases/databases";
|
import {db} from "../../src/databases/databases";
|
||||||
import assert from "assert";
|
import assert from "assert";
|
||||||
|
|
||||||
|
const videoID1 = "dQw4w9WgXcQ";
|
||||||
|
const videoID2 = "dQw4w9WgXcE";
|
||||||
|
const userID = "testtesttesttesttesttesttesttesttest";
|
||||||
|
|
||||||
describe("postVideoSponsorTime (Old submission method)", () => {
|
describe("postVideoSponsorTime (Old submission method)", () => {
|
||||||
it("Should be able to submit a time (GET)", (done: Done) => {
|
it("Should be able to submit a time (GET)", (done: Done) => {
|
||||||
fetch(`${getbaseURL()
|
fetch(`${getbaseURL()
|
||||||
}/api/postVideoSponsorTimes?videoID=dQw4w9WgXcQ&startTime=1&endTime=10&userID=testtesttesttesttesttesttesttesttest`)
|
}/api/postVideoSponsorTimes?videoID=${videoID1}&startTime=1&endTime=10&userID=${userID}`)
|
||||||
.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" = ?`, ["dQw4w9WgXcQ"]);
|
const row = await db.prepare("get", `SELECT "startTime", "endTime", "category" FROM "sponsorTimes" WHERE "videoID" = ?`, [videoID1]);
|
||||||
const expected = {
|
const expected = {
|
||||||
startTime: 1,
|
startTime: 1,
|
||||||
endTime: 10,
|
endTime: 10,
|
||||||
@@ -23,7 +27,7 @@ describe("postVideoSponsorTime (Old submission method)", () => {
|
|||||||
|
|
||||||
it("Should be able to submit a time (POST)", (done: Done) => {
|
it("Should be able to submit a time (POST)", (done: Done) => {
|
||||||
fetch(`${getbaseURL()
|
fetch(`${getbaseURL()
|
||||||
}/api/postVideoSponsorTimes?videoID=dQw4w9WgXcE&startTime=1&endTime=11&userID=testtesttesttesttesttesttesttesttest`, {
|
}/api/postVideoSponsorTimes?videoID=${videoID2}&startTime=1&endTime=11&userID=${userID}`, {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
@@ -31,7 +35,7 @@ describe("postVideoSponsorTime (Old submission method)", () => {
|
|||||||
})
|
})
|
||||||
.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" = ?`, ["dQw4w9WgXcE"]);
|
const row = await db.prepare("get", `SELECT "startTime", "endTime", "category" FROM "sponsorTimes" WHERE "videoID" = ?`, [videoID2]);
|
||||||
const expected = {
|
const expected = {
|
||||||
startTime: 1,
|
startTime: 1,
|
||||||
endTime: 11,
|
endTime: 11,
|
||||||
@@ -45,7 +49,7 @@ describe("postVideoSponsorTime (Old submission method)", () => {
|
|||||||
|
|
||||||
it("Should return 400 for missing params", (done: Done) => {
|
it("Should return 400 for missing params", (done: Done) => {
|
||||||
fetch(`${getbaseURL()
|
fetch(`${getbaseURL()
|
||||||
}/api/postVideoSponsorTimes?startTime=1&endTime=10&userID=testtesttesttesttesttesttesttesttest`)
|
}/api/postVideoSponsorTimes?startTime=1&endTime=10&userID=${userID}`)
|
||||||
.then(async res => {
|
.then(async res => {
|
||||||
assert.strictEqual(res.status, 400);
|
assert.strictEqual(res.status, 400);
|
||||||
done();
|
done();
|
||||||
|
|||||||
@@ -4,16 +4,19 @@ import {db} from "../../src/databases/databases";
|
|||||||
import {getHash} from "../../src/utils/getHash";
|
import {getHash} from "../../src/utils/getHash";
|
||||||
import assert from "assert";
|
import assert from "assert";
|
||||||
|
|
||||||
|
const VIPUser = "clearCacheVIP";
|
||||||
|
const regularUser = "regular-user";
|
||||||
|
|
||||||
describe("postClearCache", () => {
|
describe("postClearCache", () => {
|
||||||
before(async () => {
|
before(async () => {
|
||||||
await db.prepare("run", `INSERT INTO "vipUsers" ("userID") VALUES ('${getHash("clearing-vip")}')`);
|
await db.prepare("run", `INSERT INTO "vipUsers" ("userID") VALUES ('${getHash(VIPUser)}')`);
|
||||||
const startOfQuery = 'INSERT INTO "sponsorTimes" ("videoID", "startTime", "endTime", "votes", "UUID", "userID", "timeSubmitted", views, category, "shadowHidden", "hashedVideoID") VALUES';
|
const startOfQuery = 'INSERT INTO "sponsorTimes" ("videoID", "startTime", "endTime", "votes", "UUID", "userID", "timeSubmitted", "views", "category", "shadowHidden") VALUES';
|
||||||
await db.prepare("run", `${startOfQuery}('clear-test', 0, 1, 2, 'clear-uuid', 'testman', 0, 50, 'sponsor', 0, '" + getHash("clear-test", 1) + "')`);
|
await db.prepare("run", `${startOfQuery}('clear-test', 0, 1, 2, 'clear-uuid', 'testman', 0, 50, 'sponsor', 0)`);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should be able to clear cache for existing video", (done: Done) => {
|
it("Should be able to clear cache for existing video", (done: Done) => {
|
||||||
fetch(`${getbaseURL()
|
fetch(`${getbaseURL()
|
||||||
}/api/clearCache?userID=clearing-vip&videoID=clear-test`, {
|
}/api/clearCache?userID=${VIPUser}&videoID=clear-test`, {
|
||||||
method: "POST"
|
method: "POST"
|
||||||
})
|
})
|
||||||
.then(res => {
|
.then(res => {
|
||||||
@@ -25,7 +28,7 @@ describe("postClearCache", () => {
|
|||||||
|
|
||||||
it("Should be able to clear cache for nonexistent video", (done: Done) => {
|
it("Should be able to clear cache for nonexistent video", (done: Done) => {
|
||||||
fetch(`${getbaseURL()
|
fetch(`${getbaseURL()
|
||||||
}/api/clearCache?userID=clearing-vip&videoID=dne-video`, {
|
}/api/clearCache?userID=${VIPUser}&videoID=dne-video`, {
|
||||||
method: "POST"
|
method: "POST"
|
||||||
})
|
})
|
||||||
.then(res => {
|
.then(res => {
|
||||||
@@ -37,7 +40,7 @@ describe("postClearCache", () => {
|
|||||||
|
|
||||||
it("Should get 403 as non-vip", (done: Done) => {
|
it("Should get 403 as non-vip", (done: Done) => {
|
||||||
fetch(`${getbaseURL()
|
fetch(`${getbaseURL()
|
||||||
}/api/clearCache?userID=regular-user&videoID=clear-tes`, {
|
}/api/clearCache?userID=${regularUser}&videoID=clear-tes`, {
|
||||||
method: "POST"
|
method: "POST"
|
||||||
})
|
})
|
||||||
.then(async res => {
|
.then(async res => {
|
||||||
@@ -49,7 +52,7 @@ describe("postClearCache", () => {
|
|||||||
|
|
||||||
it("Should give 400 with missing videoID", (done: Done) => {
|
it("Should give 400 with missing videoID", (done: Done) => {
|
||||||
fetch(`${getbaseURL()
|
fetch(`${getbaseURL()
|
||||||
}/api/clearCache?userID=clearing-vip`, {
|
}/api/clearCache?userID=${VIPUser}`, {
|
||||||
method: "POST"
|
method: "POST"
|
||||||
})
|
})
|
||||||
.then(async res => {
|
.then(async res => {
|
||||||
@@ -61,7 +64,7 @@ describe("postClearCache", () => {
|
|||||||
|
|
||||||
it("Should give 400 with missing userID", (done: Done) => {
|
it("Should give 400 with missing userID", (done: Done) => {
|
||||||
fetch(`${getbaseURL()
|
fetch(`${getbaseURL()
|
||||||
}/api/clearCache?userID=clearing-vip`, {
|
}/api/clearCache?userID=${VIPUser}`, {
|
||||||
method: "POST"
|
method: "POST"
|
||||||
})
|
})
|
||||||
.then(async res => {
|
.then(async res => {
|
||||||
|
|||||||
Reference in New Issue
Block a user