fix eslint for tests

This commit is contained in:
Michael C
2021-07-12 02:43:46 -04:00
parent c0b1d201ad
commit 8b3ffe5d0d
30 changed files with 3453 additions and 3475 deletions

View File

@@ -1,10 +1,10 @@
import {db, privateDB} from '../../src/databases/databases';
import {db, privateDB} from "../../src/databases/databases";
describe('dbUpgrade', () => {
it('Should update the database version when starting the application', async () => {
const dbVersion = (await db.prepare('get', 'SELECT key, value FROM config where key = ?', ['version'])).value;
const privateVersion = (await privateDB.prepare('get', 'SELECT key, value FROM config where key = ?', ['version'])).value;
describe("dbUpgrade", () => {
it("Should update the database version when starting the application", async () => {
const dbVersion = (await db.prepare("get", "SELECT key, value FROM config where key = ?", ["version"])).value;
const privateVersion = (await privateDB.prepare("get", "SELECT key, value FROM config where key = ?", ["version"])).value;
if (dbVersion >= 1 && privateVersion >= 1) return;
else return 'Versions are not at least 1. db is ' + dbVersion + ', private is ' + privateVersion;
else return `Versions are not at least 1. db is ${dbVersion}, private is ${privateVersion}`;
});
});

View File

@@ -1,62 +1,62 @@
import assert from 'assert';
import assert from "assert";
import { db } from '../../src/databases/databases';
import { getHash } from '../../src/utils/getHash';
import { archiveDownvoteSegment } from '../../src/cronjob/downvoteSegmentArchiveJob';
import { DBSegment } from '../../src/types/segments.model';
import { db } from "../../src/databases/databases";
import { getHash } from "../../src/utils/getHash";
import { archiveDownvoteSegment } from "../../src/cronjob/downvoteSegmentArchiveJob";
import { DBSegment } from "../../src/types/segments.model";
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)],
['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)],
['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)],
['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)],
['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)],
["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)],
["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)],
["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)],
["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)],
["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)],
['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)],
['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)],
["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)],
["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)],
['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)],
['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)],
["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)],
["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)],
['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)],
['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)],
["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)],
["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)],
['onlyHiddenSegments', 20, 34, 100000, 0, 'onlyHiddenSegments', 'testman', new Date('December 17, 2021').getTime(), 50, 'sponsor', 'skip', 'ytb', 190, 1, 0, getHash('onlyHiddenSegments', 1)],
["onlyHiddenSegments", 20, 34, 100000, 0, "onlyHiddenSegments", "testman", new Date("December 17, 2021").getTime(), 50, "sponsor", "skip", "ytb", 190, 1, 0, getHash("onlyHiddenSegments", 1)],
['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)],
['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)],
['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)],
['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)]
["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)],
["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)],
["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)],
["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)]
];
describe('downvoteSegmentArchiveJob', () => {
describe("downvoteSegmentArchiveJob", () => {
beforeEach(async () => {
const query = 'INSERT INTO "sponsorTimes" ("videoID", "startTime", "endTime", "votes", "locked", "UUID", "userID", "timeSubmitted", views, category, "actionType", "service", "videoDuration", "hidden", "shadowHidden", "hashedVideoID") VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)';
for (let i = 0; i < records.length; i += 1) {
await db.prepare('run', query, records[i]);
await db.prepare("run", query, records[i]);
}
return;
});
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;
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;
assert.ok(version >= 21, "version should be greater or equal to 21");
});
afterEach(async () => {
await db.prepare('run', 'DELETE FROM "sponsorTimes"');
await db.prepare('run', 'DELETE FROM "archivedSponsorTimes"');
await db.prepare("run", 'DELETE FROM "sponsorTimes"');
await db.prepare("run", 'DELETE FROM "archivedSponsorTimes"');
});
const getArchivedSegment = (): Promise<DBSegment[]> => {
return db.prepare('all', 'SELECT * FROM "archivedSponsorTimes"');
return db.prepare("all", 'SELECT * FROM "archivedSponsorTimes"');
};
const getSegmentsInMainTable = (dayLimit: number, voteLimit: number, now: number): Promise<DBSegment[]> => {
return db.prepare(
'all',
"all",
'SELECT * FROM "sponsorTimes" WHERE "votes" < ? AND (? - "timeSubmitted") > ?',
[
voteLimit,
@@ -68,17 +68,17 @@ describe('downvoteSegmentArchiveJob', () => {
const countSegmentInMainTable = (): Promise<number> => {
return db.prepare(
'get',
"get",
'SELECT COUNT(*) as count FROM "sponsorTimes"'
).then(res => res.count);
};
it('Should archive all records match', async () => {
it("Should archive all records match", async () => {
const dayLimit = 20;
const voteLimit = 0;
const time = new Date('December 17, 2022').getTime();
const time = new Date("December 17, 2022").getTime();
const res = await archiveDownvoteSegment(dayLimit, voteLimit, time);
assert.strictEqual(res, 0, 'Expection in archiveDownvoteSegment');
assert.strictEqual(res, 0, "Expection in archiveDownvoteSegment");
// check segments in archived table
const archivedSegment = await getArchivedSegment();
@@ -89,15 +89,15 @@ describe('downvoteSegmentArchiveJob', () => {
assert.strictEqual(segments.length, 0, `Incorrect segment in main table: ${segments.length} instead of 0`);
// check number segments remain in main table
assert.strictEqual(await countSegmentInMainTable(), records.length - archivedSegment.length ,'Incorrect segment remain in main table');
assert.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 voteLimit = -1;
const time = new Date('December 17, 2022').getTime();
const time = new Date("December 17, 2022").getTime();
const res = await archiveDownvoteSegment(dayLimit, voteLimit, time);
assert.strictEqual(res, 0, '');
assert.strictEqual(res, 0, "");
// check segments in archived table
const archivedSegment = await getArchivedSegment();
@@ -108,15 +108,15 @@ describe('downvoteSegmentArchiveJob', () => {
assert.strictEqual(segments.length, 0, `Incorrect segment in main table: ${segments.length} instead of 0`);
// check number segments remain in main table
assert.strictEqual(await countSegmentInMainTable(), records.length - archivedSegment.length ,'Incorrect segment remain in main table');
assert.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 voteLimit = -2;
const time = new Date('December 17, 2021').getTime();
const time = new Date("December 17, 2021").getTime();
const res = await archiveDownvoteSegment(dayLimit, voteLimit, time);
assert.strictEqual(res, 0, '');
assert.strictEqual(res, 0, "");
// check segments in archived table
const archivedSegment = await getArchivedSegment();
@@ -129,15 +129,15 @@ describe('downvoteSegmentArchiveJob', () => {
assert.strictEqual(segments.length, 0, `Incorrect segment in main table: ${segments.length} instead of 0`);
// check number segments remain in main table
assert.strictEqual(await countSegmentInMainTable(), records.length - archivedSegment.length ,'Incorrect segment remain in main table');
assert.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 voteLimit = -2;
const time = new Date('December 17, 2022').getTime();
const time = new Date("December 17, 2022").getTime();
const res = await archiveDownvoteSegment(dayLimit, voteLimit, time);
assert.strictEqual(res, 0, '');
assert.strictEqual(res, 0, "");
// check segments in archived table
const archivedSegment = await getArchivedSegment();
@@ -148,15 +148,15 @@ describe('downvoteSegmentArchiveJob', () => {
assert.strictEqual(segments.length, 0, `Incorrect segment in main table: ${segments.length} instead of 0`);
// check number segments remain in main table
assert.strictEqual(await countSegmentInMainTable(), records.length - archivedSegment.length ,'Incorrect segment remain in main table');
assert.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 voteLimit = -2;
const time = new Date('December 17, 2021').getTime();
const time = new Date("December 17, 2021").getTime();
const res = await archiveDownvoteSegment(dayLimit, voteLimit, time);
assert.strictEqual(res, 0, '');
assert.strictEqual(res, 0, "");
// check segments in archived table
const archivedSegment = await getArchivedSegment();
@@ -167,6 +167,6 @@ describe('downvoteSegmentArchiveJob', () => {
assert.strictEqual(segments.length, 0, `Incorrect segment in main table: ${segments.length} instead of 0`);
// check number segments remain in main table
assert.strictEqual(await countSegmentInMainTable(), records.length - archivedSegment.length ,'Incorrect segment remain in main table');
assert.strictEqual(await countSegmentInMainTable(), records.length - archivedSegment.length ,"Incorrect segment remain in main table");
});
});

View File

@@ -1,33 +1,33 @@
import {getHash} from '../../src/utils/getHash';
import assert from 'assert';
import {getHash} from "../../src/utils/getHash";
import assert from "assert";
describe('getHash', () => {
it('Should not output the input string', () => {
describe("getHash", () => {
it("Should not output the input string", () => {
assert(getHash("test") !== "test");
assert(getHash("test", -1) !== "test");
assert(getHash("test", 0) !== "test");
assert(getHash("test", null) !== "test");
});
it('Should return a hashed value', () => {
it("Should return a hashed value", () => {
assert.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");
});
it('Should take a variable number of passes', () => {
it("Should take a variable number of passes", () => {
assert.strictEqual(getHash("test", 1), "9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08");
assert.strictEqual(getHash("test", 2), "7b3d979ca8330a94fa7e9e1b466d8b99e0bcdea1ec90596c0dcc8d7ef6b4300c");
assert.strictEqual(getHash("test", 3), "5b24f7aa99f1e1da5698a4f91ae0f4b45651a1b625c61ed669dd25ff5b937972");
});
it('Should default to 5000 passes', () => {
it("Should default to 5000 passes", () => {
assert.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), "");
});
});

View File

@@ -1,16 +1,16 @@
import fetch from 'node-fetch';
import {getbaseURL, Done} from '../utils';
import {db} from '../../src/databases/databases';
import {getHash} from '../../src/utils/getHash';
import assert from 'assert';
import fetch from "node-fetch";
import {getbaseURL, Done} from "../utils";
import {db} from "../../src/databases/databases";
import {getHash} from "../../src/utils/getHash";
import assert from "assert";
describe('getIsUserVIP', () => {
describe("getIsUserVIP", () => {
before((done: Done) => {
db.prepare("run", 'INSERT INTO "vipUsers" ("userID") VALUES (?)', [getHash("supertestman")]).then(done);
});
it('Should be able to get a 200', (done: Done) => {
fetch(getbaseURL() + "/api/isUserVIP?userID=supertestman")
it("Should be able to get a 200", (done: Done) => {
fetch(`${getbaseURL()}/api/isUserVIP?userID=supertestman`)
.then(res => {
assert.strictEqual(res.status, 200, "response should be 200");
done();
@@ -19,8 +19,8 @@ describe('getIsUserVIP', () => {
});
it('Should get a 400 if no userID', (done: Done) => {
fetch(getbaseURL() + "/api/isUserVIP")
it("Should get a 400 if no userID", (done: Done) => {
fetch(`${getbaseURL()}/api/isUserVIP`)
.then(res => {
assert.strictEqual(res.status, 400, "response should be 400");
done();
@@ -28,28 +28,24 @@ describe('getIsUserVIP', () => {
.catch(err => done(err));
});
it('Should say a VIP is a VIP', (done: Done) => {
fetch(getbaseURL() + "/api/isUserVIP?userID=supertestman")
it("Should say a VIP is a VIP", (done: Done) => {
fetch(`${getbaseURL()}/api/isUserVIP?userID=supertestman`)
.then(async res => {
if (res.status !== 200) done("non 200: " + res.status);
else {
assert.strictEqual(res.status, 200);
const data = await res.json();
assert.strictEqual(data.vip, true);
done();
}
})
.catch(err => done(err));
});
it('Should say a normal user is not a VIP', (done: Done) => {
fetch(getbaseURL() + "/api/isUserVIP?userID=regulartestman")
it("Should say a normal user is not a VIP", (done: Done) => {
fetch(`${getbaseURL()}/api/isUserVIP?userID=regulartestman`)
.then(async res => {
if (res.status !== 200) done("non 200: " + res.status);
else {
assert.strictEqual(res.status, 200);
const data = await res.json();
assert.strictEqual(data.vip, false);
done();
}
})
.catch(err => done(err));
});

View File

@@ -1,32 +1,32 @@
import fetch from 'node-fetch';
import {Done, getbaseURL} from '../utils';
import {getHash} from '../../src/utils/getHash';
import {db} from '../../src/databases/databases';
import assert from 'assert';
import fetch from "node-fetch";
import {Done, getbaseURL} from "../utils";
import {getHash} from "../../src/utils/getHash";
import {db} from "../../src/databases/databases";
import assert from "assert";
describe('getLockCategories', () => {
describe("getLockCategories", () => {
before(async () => {
const insertVipUserQuery = 'INSERT INTO "vipUsers" ("userID") VALUES (?)';
await db.prepare("run", insertVipUserQuery, [getHash("VIPUser-getLockCategories")]);
const insertLockCategoryQuery = 'INSERT INTO "lockCategories" ("userID", "videoID", "category") VALUES (?, ?, ?)';
await db.prepare("run", insertLockCategoryQuery, [getHash("VIPUser-getLockCategories"), 'getLock-1', 'sponsor']);
await db.prepare("run", insertLockCategoryQuery, [getHash("VIPUser-getLockCategories"), 'getLock-1', 'interaction']);
await db.prepare("run", insertLockCategoryQuery, [getHash("VIPUser-getLockCategories"), "getLock-1", "sponsor"]);
await db.prepare("run", insertLockCategoryQuery, [getHash("VIPUser-getLockCategories"), "getLock-1", "interaction"]);
await db.prepare("run", insertLockCategoryQuery, [getHash("VIPUser-getLockCategories"), 'getLock-2', 'preview']);
await db.prepare("run", insertLockCategoryQuery, [getHash("VIPUser-getLockCategories"), "getLock-2", "preview"]);
await db.prepare("run", insertLockCategoryQuery, [getHash("VIPUser-getLockCategories"), 'getLock-3', 'nonmusic']);
await db.prepare("run", insertLockCategoryQuery, [getHash("VIPUser-getLockCategories"), "getLock-3", "nonmusic"]);
});
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;
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;
if (version > 1) return;
else return 'Version isn\'t greater than 1. Version is ' + version;
else return `Version isn't greater than 1. Version is ${version}`;
});
it('Should be able to get multiple locks', (done: Done) => {
fetch(getbaseURL() + '/api/lockCategories?videoID=getLock-1')
it("Should be able to get multiple locks", (done: Done) => {
fetch(`${getbaseURL()}/api/lockCategories?videoID=getLock-1`)
.then(async res => {
assert.strictEqual(res.status, 200);
const data = await res.json();
@@ -42,8 +42,8 @@ describe('getLockCategories', () => {
.catch(err => done(err));
});
it('Should be able to get single locks', (done: Done) => {
fetch(getbaseURL() + '/api/lockCategories?videoID=getLock-2')
it("Should be able to get single locks", (done: Done) => {
fetch(`${getbaseURL()}/api/lockCategories?videoID=getLock-2`)
.then(async res => {
assert.strictEqual(res.status, 200);
const data = await res.json();
@@ -58,8 +58,8 @@ describe('getLockCategories', () => {
.catch(err => done(err));
});
it('should return 404 if no lock exists', (done: Done) => {
fetch(getbaseURL() + '/api/lockCategories?videoID=getLock-0')
it("should return 404 if no lock exists", (done: Done) => {
fetch(`${getbaseURL()}/api/lockCategories?videoID=getLock-0`)
.then(res => {
assert.strictEqual(res.status, 404);
done();
@@ -67,8 +67,8 @@ describe('getLockCategories', () => {
.catch(err => done(err));
});
it('should return 400 if no videoID specified', (done: Done) => {
fetch(getbaseURL() + '/api/lockCategories')
it("should return 400 if no videoID specified", (done: Done) => {
fetch(`${getbaseURL()}/api/lockCategories`)
.then(res => {
assert.strictEqual(res.status, 400);
done();

View File

@@ -1,36 +1,36 @@
import fetch from 'node-fetch';
import {Done, getbaseURL} from '../utils';
import {getHash} from '../../src/utils/getHash';
import {db} from '../../src/databases/databases';
import assert from 'assert';
import fetch from "node-fetch";
import {Done, getbaseURL} from "../utils";
import {getHash} from "../../src/utils/getHash";
import {db} from "../../src/databases/databases";
import assert from "assert";
describe('getLockCategoriesByHash', () => {
describe("getLockCategoriesByHash", () => {
before(async () => {
const insertVipUserQuery = 'INSERT INTO "vipUsers" ("userID") VALUES (?)';
await db.prepare("run", insertVipUserQuery, [getHash("VIPUser-getLockCategories")]);
const insertLockCategoryQuery = 'INSERT INTO "lockCategories" ("userID", "videoID", "category", "hashedVideoID") VALUES (?, ?, ?, ?)';
await db.prepare("run", insertLockCategoryQuery, [getHash("VIPUser-getLockCategories"), 'getLockHash-1', 'sponsor', '67a654898fda3a5541774aea345796c7709982bb6018cb08d22a18eeddccc1d0']);
await db.prepare("run", insertLockCategoryQuery, [getHash("VIPUser-getLockCategories"), 'getLockHash-1', 'interaction', '67a654898fda3a5541774aea345796c7709982bb6018cb08d22a18eeddccc1d0']);
await db.prepare("run", insertLockCategoryQuery, [getHash("VIPUser-getLockCategories"), "getLockHash-1", "sponsor", "67a654898fda3a5541774aea345796c7709982bb6018cb08d22a18eeddccc1d0"]);
await db.prepare("run", insertLockCategoryQuery, [getHash("VIPUser-getLockCategories"), "getLockHash-1", "interaction", "67a654898fda3a5541774aea345796c7709982bb6018cb08d22a18eeddccc1d0"]);
await db.prepare("run", insertLockCategoryQuery, [getHash("VIPUser-getLockCategories"), 'getLockHash-2', 'preview', 'dff09120437b4bd594dffae5f3cde3cfc5f6099fb01d0ef4051919b2908d9a50']);
await db.prepare("run", insertLockCategoryQuery, [getHash("VIPUser-getLockCategories"), "getLockHash-2", "preview", "dff09120437b4bd594dffae5f3cde3cfc5f6099fb01d0ef4051919b2908d9a50"]);
await db.prepare("run", insertLockCategoryQuery, [getHash("VIPUser-getLockCategories"), 'getLockHash-3', 'nonmusic', 'bf1b122fd5630e0df8626d00c4a95c58954ad715e5595b0f75a19ac131e28928']);
await db.prepare("run", insertLockCategoryQuery, [getHash("VIPUser-getLockCategories"), "getLockHash-3", "nonmusic", "bf1b122fd5630e0df8626d00c4a95c58954ad715e5595b0f75a19ac131e28928"]);
await db.prepare("run", insertLockCategoryQuery, [getHash("VIPUser-getLockCategories"), 'fakehash-1', 'outro', 'b05a20424f24a53dac1b059fb78d861ba9723645026be2174c93a94f9106bb35']);
await db.prepare("run", insertLockCategoryQuery, [getHash("VIPUser-getLockCategories"), 'fakehash-2', 'intro', 'b05acd1cd6ec7dffe5ffea64ada91ae7469d6db2ce21c7e30ad7fa62075d450']);
await db.prepare("run", insertLockCategoryQuery, [getHash("VIPUser-getLockCategories"), 'fakehash-2', 'preview', 'b05acd1cd6ec7dffe5ffea64ada91ae7469d6db2ce21c7e30ad7fa62075d450']);
await db.prepare("run", insertLockCategoryQuery, [getHash("VIPUser-getLockCategories"), "fakehash-1", "outro", "b05a20424f24a53dac1b059fb78d861ba9723645026be2174c93a94f9106bb35"]);
await db.prepare("run", insertLockCategoryQuery, [getHash("VIPUser-getLockCategories"), "fakehash-2", "intro", "b05acd1cd6ec7dffe5ffea64ada91ae7469d6db2ce21c7e30ad7fa62075d450"]);
await db.prepare("run", insertLockCategoryQuery, [getHash("VIPUser-getLockCategories"), "fakehash-2", "preview", "b05acd1cd6ec7dffe5ffea64ada91ae7469d6db2ce21c7e30ad7fa62075d450"]);
});
it('Database should be greater or equal to version 18', async () => {
const version = (await db.prepare('get', 'SELECT key, value FROM config where key = ?', ['version'])).value;
it("Database should be greater or equal to version 18", async () => {
const version = (await db.prepare("get", "SELECT key, value FROM config where key = ?", ["version"])).value;
if (version >= 18) return;
else return 'Version isn\'t greater than 18. Version is ' + version;
else return `Version isn't greater than 18. Version is ${version}`;
});
it('Should be able to get multiple locks in one object', (done: Done) => {
fetch(getbaseURL() + '/api/lockCategories/67a65')
it("Should be able to get multiple locks in one object", (done: Done) => {
fetch(`${getbaseURL()}/api/lockCategories/67a65`)
.then(async res => {
assert.strictEqual(res.status, 200);
const data = await res.json();
@@ -48,8 +48,8 @@ describe('getLockCategoriesByHash', () => {
.catch(err => done(err));
});
it('Should be able to get single lock', (done: Done) => {
fetch(getbaseURL() + '/api/lockCategories/dff09')
it("Should be able to get single lock", (done: Done) => {
fetch(`${getbaseURL()}/api/lockCategories/dff09`)
.then(async res => {
assert.strictEqual(res.status, 200);
const data = await res.json();
@@ -66,8 +66,8 @@ describe('getLockCategoriesByHash', () => {
.catch(err => done(err));
});
it('Should be able to get by half full hash', (done: Done) => {
fetch(getbaseURL() + '/api/lockCategories/bf1b122fd5630e0df8626d00c4a95c58')
it("Should be able to get by half full hash", (done: Done) => {
fetch(`${getbaseURL()}/api/lockCategories/bf1b122fd5630e0df8626d00c4a95c58`)
.then(async res => {
assert.strictEqual(res.status, 200);
const data = await res.json();
@@ -84,8 +84,8 @@ describe('getLockCategoriesByHash', () => {
.catch(err => done(err));
});
it('Should be able to get multiple by similar hash with multiple categories', (done: Done) => {
fetch(getbaseURL() + '/api/lockCategories/b05a')
it("Should be able to get multiple by similar hash with multiple categories", (done: Done) => {
fetch(`${getbaseURL()}/api/lockCategories/b05a`)
.then(async res => {
assert.strictEqual(res.status, 200);
const data = await res.json();
@@ -109,8 +109,8 @@ describe('getLockCategoriesByHash', () => {
.catch(err => done(err));
});
it('should return 404 once hash prefix varies', (done: Done) => {
fetch(getbaseURL() + '/api/lockCategories/b05aa')
it("should return 404 once hash prefix varies", (done: Done) => {
fetch(`${getbaseURL()}/api/lockCategories/b05aa`)
.then(res => {
assert.strictEqual(res.status, 404);
done();
@@ -118,8 +118,8 @@ describe('getLockCategoriesByHash', () => {
.catch(err => done(err));
});
it('should return 404 if no lock exists', (done: Done) => {
fetch(getbaseURL() + '/api/lockCategories/aaaaaa')
it("should return 404 if no lock exists", (done: Done) => {
fetch(`${getbaseURL()}/api/lockCategories/aaaaaa`)
.then(res => {
assert.strictEqual(res.status, 404);
done();
@@ -127,8 +127,8 @@ describe('getLockCategoriesByHash', () => {
.catch(err => done(err));
});
it('should return 400 if no videoID specified', (done: Done) => {
fetch(getbaseURL() + '/api/lockCategories/')
it("should return 400 if no videoID specified", (done: Done) => {
fetch(`${getbaseURL()}/api/lockCategories/`)
.then(res => {
assert.strictEqual(res.status, 400);
done();
@@ -136,8 +136,8 @@ describe('getLockCategoriesByHash', () => {
.catch(err => done(err));
});
it('should return 400 if full hash sent', (done: Done) => {
fetch(getbaseURL() + '/api/lockCategories/b05a20424f24a53dac1b059fb78d861ba9723645026be2174c93a94f9106bb35')
it("should return 400 if full hash sent", (done: Done) => {
fetch(`${getbaseURL()}/api/lockCategories/b05a20424f24a53dac1b059fb78d861ba9723645026be2174c93a94f9106bb35`)
.then(res => {
assert.strictEqual(res.status, 400);
done();

View File

@@ -1,19 +1,19 @@
import fetch from 'node-fetch';
import {Done, getbaseURL} from '../utils';
import {db} from '../../src/databases/databases';
import {getHash} from '../../src/utils/getHash';
import assert from 'assert';
import fetch from "node-fetch";
import {Done, getbaseURL} from "../utils";
import {db} from "../../src/databases/databases";
import {getHash} from "../../src/utils/getHash";
import assert from "assert";
describe('getSavedTimeForUser', () => {
describe("getSavedTimeForUser", () => {
before(async () => {
const startOfQuery = 'INSERT INTO "sponsorTimes" ("videoID", "startTime", "endTime", "votes", "UUID", "userID", "timeSubmitted", views, category, "shadowHidden", "hashedVideoID") VALUES';
await db.prepare("run", startOfQuery + "(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
['getSavedTimeForUser', 1, 11, 2, 'abc1239999', getHash("testman"), 0, 50, 'sponsor', 0, getHash('getSavedTimeForUser', 0)]);
await db.prepare("run", `${startOfQuery}(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`,
["getSavedTimeForUser", 1, 11, 2, "abc1239999", getHash("testman"), 0, 50, "sponsor", 0, getHash("getSavedTimeForUser", 0)]);
return;
});
it('Should be able to get a 200', (done: Done) => {
fetch(getbaseURL() + "/api/getSavedTimeForUser?userID=testman")
it("Should be able to get a 200", (done: Done) => {
fetch(`${getbaseURL()}/api/getSavedTimeForUser?userID=testman`)
.then(async res => {
const data = await res.json();
// (end-start)*minute * views

View File

@@ -1,48 +1,48 @@
import fetch from 'node-fetch';
import {db} from '../../src/databases/databases';
import {Done, getbaseURL} from '../utils';
import {getHash} from '../../src/utils/getHash';
import assert from 'assert';
import fetch from "node-fetch";
import {db} from "../../src/databases/databases";
import {Done, getbaseURL} from "../utils";
import {getHash} from "../../src/utils/getHash";
import assert from "assert";
const ENOENTID = "0".repeat(64);
const upvotedID = "a"+"0".repeat(63);
const downvotedID = "b"+"0".repeat(63);
const lockedupID = "c"+"0".repeat(63);
const infvotesID = "d"+"0".repeat(63);
const shadowhiddenID = "e"+"0".repeat(63);
const lockeddownID = "f"+"0".repeat(63);
const hiddenID = "1"+"0".repeat(63);
const fillerID1 = "11"+"0".repeat(62);
const fillerID2 = "12"+"0".repeat(62);
const fillerID3 = "13"+"0".repeat(62);
const fillerID4 = "14"+"0".repeat(62);
const fillerID5 = "15"+"0".repeat(62);
const oldID = `${'0'.repeat(8)}-${'0000-'.repeat(3)}${'0'.repeat(12)}`;
const upvotedID = `a${"0".repeat(63)}`;
const downvotedID = `b${"0".repeat(63)}`;
const lockedupID = `c${"0".repeat(63)}`;
const infvotesID = `d${"0".repeat(63)}`;
const shadowhiddenID = `e${"0".repeat(63)}`;
const lockeddownID = `f${"0".repeat(63)}`;
const hiddenID = `1${"0".repeat(63)}`;
const fillerID1 = `11${"0".repeat(62)}`;
const fillerID2 = `12${"0".repeat(62)}`;
const fillerID3 = `13${"0".repeat(62)}`;
const fillerID4 = `14${"0".repeat(62)}`;
const fillerID5 = `15${"0".repeat(62)}`;
const oldID = `${"0".repeat(8)}-${"0000-".repeat(3)}${"0".repeat(12)}`;
describe('getSegmentInfo', () => {
describe("getSegmentInfo", () => {
before(async () => {
const insertQuery = `INSERT INTO
"sponsorTimes"("videoID", "startTime", "endTime", "votes", "locked",
"UUID", "userID", "timeSubmitted", "views", "category", "service",
"videoDuration", "hidden", "shadowHidden", "hashedVideoID")
VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`;
await db.prepare("run", insertQuery, ['upvoted', 1, 10, 2, 0, upvotedID, 'testman', 0, 50, 'sponsor', 'YouTube', 100, 0, 0, getHash('upvoted', 1)]);
await db.prepare("run", insertQuery, ['downvoted', 1, 10, -2, 0, downvotedID, 'testman', 0, 50, 'sponsor', 'YouTube', 120, 0, 0, getHash('downvoted', 1)]);
await db.prepare("run", insertQuery, ['locked-up', 1, 10, 2, 1, lockedupID, 'testman', 0, 50, 'sponsor', 'YouTube', 101, 0, 0, getHash('locked-up', 1)]);
await db.prepare("run", insertQuery, ['infvotes', 1, 10, 100000, 0, infvotesID, 'testman', 0, 50, 'sponsor', 'YouTube', 101, 0, 0, getHash('infvotes', 1)]);
await db.prepare("run", insertQuery, ['hidden', 1, 10, 2, 0, hiddenID, 'testman', 0, 50, 'sponsor', 'YouTube', 140, 1, 0, getHash('hidden', 1)]);
await db.prepare("run", insertQuery, ['shadowhidden', 1, 10, 2, 0, shadowhiddenID, 'testman', 0, 50, 'sponsor', 'YouTube', 140, 0, 1, getHash('shadowhidden', 1)]);
await db.prepare("run", insertQuery, ['locked-down', 1, 10, -2, 1, lockeddownID, 'testman', 0, 50, 'sponsor', 'YouTube', 200, 0, 0, getHash('locked-down', 1)]);
await db.prepare("run", insertQuery, ['oldID', 1, 10, 1, 0, oldID, 'testman', 0, 50, 'sponsor', 'YouTube', 300, 0, 0, getHash('oldID', 1)]);
await db.prepare("run", insertQuery, ['filler', 1, 2, 1, 0, fillerID1, 'testman', 0, 50, 'sponsor', 'YouTube', 300, 0, 0, getHash('filler', 1)]);
await db.prepare("run", insertQuery, ['filler', 2, 3, 1, 0, fillerID2, 'testman', 0, 50, 'sponsor', 'YouTube', 300, 0, 0, getHash('filler', 1)]);
await db.prepare("run", insertQuery, ['filler', 3, 4, 1, 0, fillerID3, 'testman', 0, 50, 'sponsor', 'YouTube', 300, 0, 0, getHash('filler', 1)]);
await db.prepare("run", insertQuery, ['filler', 4, 5, 1, 0, fillerID4, 'testman', 0, 50, 'sponsor', 'YouTube', 300, 0, 0, getHash('filler', 1)]);
await db.prepare("run", insertQuery, ['filler', 5, 6, 1, 0, fillerID5, 'testman', 0, 50, 'sponsor', 'YouTube', 300, 0, 0, getHash('filler', 1)]);
await db.prepare("run", insertQuery, ["upvoted", 1, 10, 2, 0, upvotedID, "testman", 0, 50, "sponsor", "YouTube", 100, 0, 0, getHash("upvoted", 1)]);
await db.prepare("run", insertQuery, ["downvoted", 1, 10, -2, 0, downvotedID, "testman", 0, 50, "sponsor", "YouTube", 120, 0, 0, getHash("downvoted", 1)]);
await db.prepare("run", insertQuery, ["locked-up", 1, 10, 2, 1, lockedupID, "testman", 0, 50, "sponsor", "YouTube", 101, 0, 0, getHash("locked-up", 1)]);
await db.prepare("run", insertQuery, ["infvotes", 1, 10, 100000, 0, infvotesID, "testman", 0, 50, "sponsor", "YouTube", 101, 0, 0, getHash("infvotes", 1)]);
await db.prepare("run", insertQuery, ["hidden", 1, 10, 2, 0, hiddenID, "testman", 0, 50, "sponsor", "YouTube", 140, 1, 0, getHash("hidden", 1)]);
await db.prepare("run", insertQuery, ["shadowhidden", 1, 10, 2, 0, shadowhiddenID, "testman", 0, 50, "sponsor", "YouTube", 140, 0, 1, getHash("shadowhidden", 1)]);
await db.prepare("run", insertQuery, ["locked-down", 1, 10, -2, 1, lockeddownID, "testman", 0, 50, "sponsor", "YouTube", 200, 0, 0, getHash("locked-down", 1)]);
await db.prepare("run", insertQuery, ["oldID", 1, 10, 1, 0, oldID, "testman", 0, 50, "sponsor", "YouTube", 300, 0, 0, getHash("oldID", 1)]);
await db.prepare("run", insertQuery, ["filler", 1, 2, 1, 0, fillerID1, "testman", 0, 50, "sponsor", "YouTube", 300, 0, 0, getHash("filler", 1)]);
await db.prepare("run", insertQuery, ["filler", 2, 3, 1, 0, fillerID2, "testman", 0, 50, "sponsor", "YouTube", 300, 0, 0, getHash("filler", 1)]);
await db.prepare("run", insertQuery, ["filler", 3, 4, 1, 0, fillerID3, "testman", 0, 50, "sponsor", "YouTube", 300, 0, 0, getHash("filler", 1)]);
await db.prepare("run", insertQuery, ["filler", 4, 5, 1, 0, fillerID4, "testman", 0, 50, "sponsor", "YouTube", 300, 0, 0, getHash("filler", 1)]);
await db.prepare("run", insertQuery, ["filler", 5, 6, 1, 0, fillerID5, "testman", 0, 50, "sponsor", "YouTube", 300, 0, 0, getHash("filler", 1)]);
});
it('Should be able to retreive upvoted segment', (done: Done) => {
fetch(getbaseURL() + `/api/segmentInfo?UUID=${upvotedID}`)
it("Should be able to retreive upvoted segment", (done: Done) => {
fetch(`${getbaseURL()}/api/segmentInfo?UUID=${upvotedID}`)
.then(async res => {
assert.strictEqual(res.status, 200);
const data = await res.json();
@@ -53,8 +53,8 @@ describe('getSegmentInfo', () => {
.catch(err => done(err));
});
it('Should be able to retreive downvoted segment', (done: Done) => {
fetch(getbaseURL() + `/api/segmentInfo?UUID=${downvotedID}`)
it("Should be able to retreive downvoted segment", (done: Done) => {
fetch(`${getbaseURL()}/api/segmentInfo?UUID=${downvotedID}`)
.then(async res => {
assert.strictEqual(res.status, 200);
const data = await res.json();
@@ -65,8 +65,8 @@ describe('getSegmentInfo', () => {
.catch(err => done(err));
});
it('Should be able to retreive locked up segment', (done: Done) => {
fetch(getbaseURL() + `/api/segmentInfo?UUID=${lockedupID}`)
it("Should be able to retreive locked up segment", (done: Done) => {
fetch(`${getbaseURL()}/api/segmentInfo?UUID=${lockedupID}`)
.then(async res => {
assert.strictEqual(res.status, 200);
const data = await res.json();
@@ -78,8 +78,8 @@ describe('getSegmentInfo', () => {
.catch(err => done(err));
});
it('Should be able to retreive infinite vote segment', (done: Done) => {
fetch(getbaseURL() + `/api/segmentInfo?UUID=${infvotesID}`)
it("Should be able to retreive infinite vote segment", (done: Done) => {
fetch(`${getbaseURL()}/api/segmentInfo?UUID=${infvotesID}`)
.then(async res => {
assert.strictEqual(res.status, 200);
const data = await res.json();
@@ -90,8 +90,8 @@ describe('getSegmentInfo', () => {
.catch(err => done(err));
});
it('Should be able to retreive shadowhidden segment', (done: Done) => {
fetch(getbaseURL() + `/api/segmentInfo?UUID=${shadowhiddenID}`)
it("Should be able to retreive shadowhidden segment", (done: Done) => {
fetch(`${getbaseURL()}/api/segmentInfo?UUID=${shadowhiddenID}`)
.then(async res => {
assert.strictEqual(res.status, 200);
const data = await res.json();
@@ -102,8 +102,8 @@ describe('getSegmentInfo', () => {
.catch(err => done(err));
});
it('Should be able to retreive locked down segment', (done: Done) => {
fetch(getbaseURL() + `/api/segmentInfo?UUID=${lockeddownID}`)
it("Should be able to retreive locked down segment", (done: Done) => {
fetch(`${getbaseURL()}/api/segmentInfo?UUID=${lockeddownID}`)
.then(async res => {
assert.strictEqual(res.status, 200);
const data = await res.json();
@@ -115,8 +115,8 @@ describe('getSegmentInfo', () => {
.catch(err => done(err));
});
it('Should be able to retreive hidden segment', (done: Done) => {
fetch(getbaseURL() + `/api/segmentInfo?UUID=${hiddenID}`)
it("Should be able to retreive hidden segment", (done: Done) => {
fetch(`${getbaseURL() }/api/segmentInfo?UUID=${hiddenID}`)
.then(async res => {
assert.strictEqual(res.status, 200);
const data = await res.json();
@@ -127,8 +127,8 @@ describe('getSegmentInfo', () => {
.catch(err => done(err));
});
it('Should be able to retreive segment with old ID', (done: Done) => {
fetch(getbaseURL() + `/api/segmentInfo?UUID=${oldID}`)
it("Should be able to retreive segment with old ID", (done: Done) => {
fetch(`${getbaseURL()}/api/segmentInfo?UUID=${oldID}`)
.then(async res => {
assert.strictEqual(res.status, 200);
const data = await res.json();
@@ -139,8 +139,8 @@ describe('getSegmentInfo', () => {
.catch(err => done(err));
});
it('Should be able to retreive single segment in array', (done: Done) => {
fetch(getbaseURL() + `/api/segmentInfo?UUIDs=["${upvotedID}"]`)
it("Should be able to retreive single segment in array", (done: Done) => {
fetch(`${getbaseURL()}/api/segmentInfo?UUIDs=["${upvotedID}"]`)
.then(async res => {
assert.strictEqual(res.status, 200);
const data = await res.json();
@@ -152,8 +152,8 @@ describe('getSegmentInfo', () => {
.catch(err => done(err));
});
it('Should be able to retreive multiple segments in array', (done: Done) => {
fetch(getbaseURL() + `/api/segmentInfo?UUIDs=["${upvotedID}", "${downvotedID}"]`)
it("Should be able to retreive multiple segments in array", (done: Done) => {
fetch(`${getbaseURL()}/api/segmentInfo?UUIDs=["${upvotedID}", "${downvotedID}"]`)
.then(async res => {
assert.strictEqual(res.status, 200);
const data = await res.json();
@@ -167,8 +167,8 @@ describe('getSegmentInfo', () => {
.catch(err => done(err));
});
it('Should be possible to send unexpected query parameters', (done: Done) => {
fetch(getbaseURL() + `/api/segmentInfo?UUID=${upvotedID}&fakeparam=hello&category=sponsor`)
it("Should be possible to send unexpected query parameters", (done: Done) => {
fetch(`${getbaseURL()}/api/segmentInfo?UUID=${upvotedID}&fakeparam=hello&category=sponsor`)
.then(async res => {
assert.strictEqual(res.status, 200);
const data = await res.json();
@@ -179,8 +179,8 @@ describe('getSegmentInfo', () => {
.catch(err => done(err));
});
it('Should return 400 if array passed to UUID', (done: Done) => {
fetch(getbaseURL() + `/api/segmentInfo?UUID=["${upvotedID}", "${downvotedID}"]`)
it("Should return 400 if array passed to UUID", (done: Done) => {
fetch(`${getbaseURL()}/api/segmentInfo?UUID=["${upvotedID}", "${downvotedID}"]`)
.then(res => {
assert.strictEqual(res.status, 400);
done();
@@ -188,8 +188,8 @@ describe('getSegmentInfo', () => {
.catch(err => done(err));
});
it('Should return 400 if bad array passed to UUIDs', (done: Done) => {
fetch(getbaseURL() + "/api/segmentInfo?UUIDs=[not-quoted,not-quoted]")
it("Should return 400 if bad array passed to UUIDs", (done: Done) => {
fetch(`${getbaseURL()}/api/segmentInfo?UUIDs=[not-quoted,not-quoted]`)
.then(res => {
assert.strictEqual(res.status, 400);
done();
@@ -197,8 +197,8 @@ describe('getSegmentInfo', () => {
.catch(err => done(err));
});
it('Should return 400 if bad UUID passed', (done: Done) => {
fetch(getbaseURL() + "/api/segmentInfo?UUID=notarealuuid")
it("Should return 400 if bad UUID passed", (done: Done) => {
fetch(`${getbaseURL()}/api/segmentInfo?UUID=notarealuuid`)
.then(res => {
assert.strictEqual(res.status, 400);
done();
@@ -206,8 +206,8 @@ describe('getSegmentInfo', () => {
.catch(err => done(err));
});
it('Should return 400 if bad UUIDs passed in array', (done: Done) => {
fetch(getbaseURL() + `/api/segmentInfo?UUIDs=["notarealuuid", "anotherfakeuuid"]`)
it("Should return 400 if bad UUIDs passed in array", (done: Done) => {
fetch(`${getbaseURL()}/api/segmentInfo?UUIDs=["notarealuuid", "anotherfakeuuid"]`)
.then(res => {
assert.strictEqual(res.status, 400);
done();
@@ -215,8 +215,8 @@ describe('getSegmentInfo', () => {
.catch(err => done(err));
});
it('Should return good UUID when mixed with bad UUIDs', (done: Done) => {
fetch(getbaseURL() + `/api/segmentInfo?UUIDs=["${upvotedID}", "anotherfakeuuid"]`)
it("Should return good UUID when mixed with bad UUIDs", (done: Done) => {
fetch(`${getbaseURL()}/api/segmentInfo?UUIDs=["${upvotedID}", "anotherfakeuuid"]`)
.then(async res => {
assert.strictEqual(res.status, 200);
const data = await res.json();
@@ -228,10 +228,10 @@ describe('getSegmentInfo', () => {
.catch(err => done(err));
});
it('Should cut off array at 10', function(done: Done) {
it("Should cut off array at 10", function(done: Done) {
this.timeout(10000);
const filledIDArray = `["${upvotedID}", "${downvotedID}", "${lockedupID}", "${shadowhiddenID}", "${lockeddownID}", "${hiddenID}", "${fillerID1}", "${fillerID2}", "${fillerID3}", "${fillerID4}", "${fillerID5}"]`;
fetch(getbaseURL() + `/api/segmentInfo?UUIDs=${filledIDArray}`)
fetch(`${getbaseURL()}/api/segmentInfo?UUIDs=${filledIDArray}`)
.then(async res => {
assert.strictEqual(res.status, 200);
const data = await res.json();
@@ -245,8 +245,8 @@ describe('getSegmentInfo', () => {
.catch(err => done(err));
});
it('Should not duplicate reponses', (done: Done) => {
fetch(getbaseURL() + `/api/segmentInfo?UUIDs=["${upvotedID}", "${upvotedID}", "${upvotedID}", "${upvotedID}", "${upvotedID}", "${upvotedID}", "${upvotedID}", "${upvotedID}", "${upvotedID}", "${upvotedID}", "${downvotedID}"]`)
it("Should not duplicate reponses", (done: Done) => {
fetch(`${getbaseURL()}/api/segmentInfo?UUIDs=["${upvotedID}", "${upvotedID}", "${upvotedID}", "${upvotedID}", "${upvotedID}", "${upvotedID}", "${upvotedID}", "${upvotedID}", "${upvotedID}", "${upvotedID}", "${downvotedID}"]`)
.then(async res => {
assert.strictEqual(res.status, 200);
const data = await res.json();
@@ -260,17 +260,17 @@ describe('getSegmentInfo', () => {
.catch(err => done(err));
});
it('Should return 400 if UUID not found', (done: Done) => {
fetch(getbaseURL() + `/api/segmentInfo?UUID=${ENOENTID}`)
it("Should return 400 if UUID not found", (done: Done) => {
fetch(`${getbaseURL()}/api/segmentInfo?UUID=${ENOENTID}`)
.then(res => {
if (res.status !== 400) done("non 400 respone code: " + res.status);
if (res.status !== 400) done(`non 400 respone code: ${res.status}`);
else done(); // pass
})
.catch(err => done(err));
});
it('Should be able to retreive multiple segments with multiple parameters', (done: Done) => {
fetch(getbaseURL() + `/api/segmentInfo?UUID=${upvotedID}&UUID=${downvotedID}`)
it("Should be able to retreive multiple segments with multiple parameters", (done: Done) => {
fetch(`${getbaseURL()}/api/segmentInfo?UUID=${upvotedID}&UUID=${downvotedID}`)
.then(async res => {
assert.strictEqual(res.status, 200);
const data = await res.json();
@@ -284,8 +284,8 @@ describe('getSegmentInfo', () => {
.catch(err => done(err));
});
it('Should not parse repeated UUID if UUIDs present', (done: Done) => {
fetch(getbaseURL() + `/api/segmentInfo?UUID=${downvotedID}&UUID=${lockedupID}&UUIDs=["${upvotedID}"]`)
it("Should not parse repeated UUID if UUIDs present", (done: Done) => {
fetch(`${getbaseURL()}/api/segmentInfo?UUID=${downvotedID}&UUID=${lockedupID}&UUIDs=["${upvotedID}"]`)
.then(async res => {
assert.strictEqual(res.status, 200);
const data = await res.json();

View File

@@ -1,34 +1,34 @@
import fetch from 'node-fetch';
import {db} from '../../src/databases/databases';
import {Done, getbaseURL} from '../utils';
import {getHash} from '../../src/utils/getHash';
import assert from 'assert';
import fetch from "node-fetch";
import {db} from "../../src/databases/databases";
import {Done, getbaseURL} from "../utils";
import {getHash} from "../../src/utils/getHash";
import assert from "assert";
describe('getSkipSegments', () => {
describe("getSkipSegments", () => {
before(async () => {
const query = 'INSERT INTO "sponsorTimes" ("videoID", "startTime", "endTime", "votes", "locked", "UUID", "userID", "timeSubmitted", views, category, "actionType", "service", "videoDuration", "hidden", "shadowHidden", "hashedVideoID") 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, ['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, ['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, ['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, ['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, ['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, ['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, ['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, ['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, ['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, ['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, ['onlyHiddenSegments', 20, 34, 100000, 0, 'onlyHiddenSegments', 'testman', 0, 50, 'sponsor', 'skip', 'YouTube', 190, 1, 0, getHash('onlyHiddenSegments', 1)]);
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-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-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-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, ["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, ["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, ["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, ["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, ["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, ["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, ["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, ["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, ["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, ["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, ["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, ["onlyHiddenSegments", 20, 34, 100000, 0, "onlyHiddenSegments", "testman", 0, 50, "sponsor", "skip", "YouTube", 190, 1, 0, getHash("onlyHiddenSegments", 1)]);
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-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-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-raw", 80, 90, 2, 0, "requiredSegmentVid-raw-4", "testman", 0, 50, "sponsor", "skip", "YouTube", 0, 0, 0, getHash("requiredSegmentVid-raw", 1)]);
return;
});
it('Should be able to get a time by category 1', (done: Done) => {
fetch(getbaseURL() + "/api/skipSegments?videoID=testtesttest&category=sponsor")
it("Should be able to get a time by category 1", (done: Done) => {
fetch(`${getbaseURL()}/api/skipSegments?videoID=testtesttest&category=sponsor`)
.then(async res => {
assert.strictEqual(res.status, 200);
const data = await res.json();
@@ -43,8 +43,8 @@ describe('getSkipSegments', () => {
.catch(err => done(err));
});
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")
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`)
.then(async res => {
assert.strictEqual(res.status, 200);
const data = await res.json();
@@ -59,8 +59,8 @@ describe('getSkipSegments', () => {
.catch(err => done(err));
});
it('Should be able to get a time by category and multiple action types', (done: Done) => {
fetch(getbaseURL() + "/api/skipSegments?videoID=testtesttest&category=sponsor&actionType=mute&actionType=skip")
it("Should be able to get a time by category and multiple action types", (done: Done) => {
fetch(`${getbaseURL()}/api/skipSegments?videoID=testtesttest&category=sponsor&actionType=mute&actionType=skip`)
.then(async res => {
assert.strictEqual(res.status, 200);
const data = await res.json();
@@ -76,8 +76,8 @@ describe('getSkipSegments', () => {
.catch(err => done(err));
});
it('Should be able to get a time by category and multiple action types (JSON array)', (done: Done) => {
fetch(getbaseURL() + '/api/skipSegments?videoID=testtesttest&category=sponsor&actionTypes=["mute","skip"]')
it("Should be able to get a time by category and multiple action types (JSON array)", (done: Done) => {
fetch(`${getbaseURL()}/api/skipSegments?videoID=testtesttest&category=sponsor&actionTypes=["mute","skip"]`)
.then(async res => {
assert.strictEqual(res.status, 200);
const data = await res.json();
@@ -93,8 +93,8 @@ describe('getSkipSegments', () => {
.catch(err => done(err));
});
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")
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`)
.then(async res => {
assert.strictEqual(res.status, 200);
const data = await res.json();
@@ -109,8 +109,8 @@ describe('getSkipSegments', () => {
.catch(err => done(err));
});
it('Should be able to get a time by category 2', (done: Done) => {
fetch(getbaseURL() + "/api/skipSegments?videoID=testtesttest&category=intro")
it("Should be able to get a time by category 2", (done: Done) => {
fetch(`${getbaseURL()}/api/skipSegments?videoID=testtesttest&category=intro`)
.then(async res => {
assert.strictEqual(res.status, 200);
const data = await res.json();
@@ -124,8 +124,8 @@ describe('getSkipSegments', () => {
.catch(err => done(err));
});
it('Should be able to get a time by categories array', (done: Done) => {
fetch(getbaseURL() + "/api/skipSegments?videoID=testtesttest&categories=[\"sponsor\"]")
it("Should be able to get a time by categories array", (done: Done) => {
fetch(`${getbaseURL()}/api/skipSegments?videoID=testtesttest&categories=["sponsor"]`)
.then(async res => {
assert.strictEqual(res.status, 200);
const data = await res.json();
@@ -140,8 +140,8 @@ describe('getSkipSegments', () => {
.catch(err => done(err));
});
it('Should be able to get a time by categories array 2', (done: Done) => {
fetch(getbaseURL() + "/api/skipSegments?videoID=testtesttest&categories=[\"intro\"]")
it("Should be able to get a time by categories array 2", (done: Done) => {
fetch(`${getbaseURL()}/api/skipSegments?videoID=testtesttest&categories=["intro"]`)
.then(async res => {
assert.strictEqual(res.status, 200);
const data = await res.json();
@@ -156,8 +156,8 @@ describe('getSkipSegments', () => {
.catch(err => done(err));
});
it('Should return 404 if all submissions are hidden', (done: Done) => {
fetch(getbaseURL() + "/api/skipSegments?videoID=onlyHiddenSegments")
it("Should return 404 if all submissions are hidden", (done: Done) => {
fetch(`${getbaseURL()}/api/skipSegments?videoID=onlyHiddenSegments`)
.then(res => {
assert.strictEqual(res.status, 404);
done();
@@ -165,8 +165,8 @@ describe('getSkipSegments', () => {
.catch(err => done(err));
});
it('Should be able to get multiple times by category', (done: Done) => {
fetch(getbaseURL() + "/api/skipSegments?videoID=multiple&categories=[\"intro\"]")
it("Should be able to get multiple times by category", (done: Done) => {
fetch(`${getbaseURL()}/api/skipSegments?videoID=multiple&categories=["intro"]`)
.then(async res => {
assert.strictEqual(res.status, 200);
const data = await res.json();
@@ -184,8 +184,8 @@ describe('getSkipSegments', () => {
.catch(err => done(err));
});
it('Should be able to get multiple times by multiple categories', (done: Done) => {
fetch(getbaseURL() + "/api/skipSegments?videoID=testtesttest&categories=[\"sponsor\", \"intro\"]")
it("Should be able to get multiple times by multiple categories", (done: Done) => {
fetch(`${getbaseURL()}/api/skipSegments?videoID=testtesttest&categories=["sponsor", "intro"]`)
.then(async res => {
assert.strictEqual(res.status, 200);
const data = await res.json();
@@ -203,8 +203,8 @@ describe('getSkipSegments', () => {
.catch(err => done(err));
});
it('Should be possible to send unexpected query parameters', (done: Done) => {
fetch(getbaseURL() + "/api/skipSegments?videoID=testtesttest&fakeparam=hello&category=sponsor")
it("Should be possible to send unexpected query parameters", (done: Done) => {
fetch(`${getbaseURL()}/api/skipSegments?videoID=testtesttest&fakeparam=hello&category=sponsor`)
.then(async res => {
assert.strictEqual(res.status, 200);
const data = await res.json();
@@ -218,8 +218,8 @@ describe('getSkipSegments', () => {
.catch(err => done(err));
});
it('Low voted submissions should be hidden', (done: Done) => {
fetch(getbaseURL() + "/api/skipSegments?videoID=test3&category=sponsor")
it("Low voted submissions should be hidden", (done: Done) => {
fetch(`${getbaseURL()}/api/skipSegments?videoID=test3&category=sponsor`)
.then(async res => {
assert.strictEqual(res.status, 200);
const data = await res.json();
@@ -233,8 +233,8 @@ describe('getSkipSegments', () => {
.catch(err => done(err));
});
it('Should return 404 if no segment found', (done: Done) => {
fetch(getbaseURL() + "/api/skipSegments?videoID=notarealvideo")
it("Should return 404 if no segment found", (done: Done) => {
fetch(`${getbaseURL()}/api/skipSegments?videoID=notarealvideo`)
.then(res => {
assert.strictEqual(res.status, 404);
done();
@@ -242,8 +242,8 @@ describe('getSkipSegments', () => {
.catch(err => done(err));
});
it('Should return 400 if bad categories argument', (done: Done) => {
fetch(getbaseURL() + "/api/skipSegments?videoID=testtesttest&categories=[not-quoted,not-quoted]")
it("Should return 400 if bad categories argument", (done: Done) => {
fetch(`${getbaseURL()}/api/skipSegments?videoID=testtesttest&categories=[not-quoted,not-quoted]`)
.then(res => {
assert.strictEqual(res.status, 400);
done();
@@ -251,8 +251,8 @@ describe('getSkipSegments', () => {
.catch(err => done(err));
});
it('Should be able send a comma in a query param', (done: Done) => {
fetch(getbaseURL() + "/api/skipSegments?videoID=testtesttest,test&category=sponsor")
it("Should be able send a comma in a query param", (done: Done) => {
fetch(`${getbaseURL()}/api/skipSegments?videoID=testtesttest,test&category=sponsor`)
.then(async res => {
assert.strictEqual(res.status, 200);
const data = await res.json();
@@ -266,8 +266,8 @@ describe('getSkipSegments', () => {
.catch(err => done(err));
});
it('Should always get locked segment', (done: Done) => {
fetch(getbaseURL() + "/api/skipSegments?videoID=locked&category=intro")
it("Should always get locked segment", (done: Done) => {
fetch(`${getbaseURL()}/api/skipSegments?videoID=locked&category=intro`)
.then(async res => {
assert.strictEqual(res.status, 200);
const data = await res.json();
@@ -281,8 +281,8 @@ describe('getSkipSegments', () => {
.catch(err => done(err));
});
it('Should be able to get multiple categories with repeating parameters', (done: Done) => {
fetch(getbaseURL() + "/api/skipSegments?videoID=testtesttest&category=sponsor&category=intro")
it("Should be able to get multiple categories with repeating parameters", (done: Done) => {
fetch(`${getbaseURL()}/api/skipSegments?videoID=testtesttest&category=sponsor&category=intro`)
.then(async res => {
assert.strictEqual(res.status, 200);
const data = await res.json();
@@ -300,8 +300,8 @@ describe('getSkipSegments', () => {
.catch(err => done(err));
});
it('Should be able to get, categories param overriding repeating category', (done: Done) => {
fetch(getbaseURL() + "/api/skipSegments?videoID=testtesttest&categories=[\"sponsor\"]&category=intro")
it("Should be able to get, categories param overriding repeating category", (done: Done) => {
fetch(`${getbaseURL()}/api/skipSegments?videoID=testtesttest&categories=["sponsor"]&category=intro`)
.then(async res => {
assert.strictEqual(res.status, 200);
const data = await res.json();
@@ -315,8 +315,8 @@ describe('getSkipSegments', () => {
.catch(err => done(err));
});
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"]')
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"]`)
.then(async res => {
assert.strictEqual(res.status, 200);
const data = await res.json();
@@ -328,14 +328,14 @@ describe('getSkipSegments', () => {
.catch(err => done(err));
});
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')
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`)
.then(async res => {
assert.strictEqual(res.status, 200);
const data = await res.json();
assert.strictEqual(data.length, 2);
assert.strictEqual(data[0].UUID, 'requiredSegmentVid-raw-2');
assert.strictEqual(data[1].UUID, 'requiredSegmentVid-raw-3');
assert.strictEqual(data[0].UUID, "requiredSegmentVid-raw-2");
assert.strictEqual(data[1].UUID, "requiredSegmentVid-raw-3");
done();
})
.catch(err => done(err));

View File

@@ -1,36 +1,36 @@
import fetch from 'node-fetch';
import {db} from '../../src/databases/databases';
import {Done, getbaseURL} from '../utils';
import {getHash} from '../../src/utils/getHash';
import {ImportMock,} from 'ts-mock-imports';
import * as YouTubeAPIModule from '../../src/utils/youtubeApi';
import {YouTubeApiMock} from '../youtubeMock';
import assert from 'assert';
import fetch from "node-fetch";
import {db} from "../../src/databases/databases";
import {Done, getbaseURL} from "../utils";
import {getHash} from "../../src/utils/getHash";
import {ImportMock,} from "ts-mock-imports";
import * as YouTubeAPIModule from "../../src/utils/youtubeApi";
import {YouTubeApiMock} from "../youtubeMock";
import assert from "assert";
const mockManager = ImportMock.mockStaticClass(YouTubeAPIModule, 'YouTubeAPI');
const sinonStub = mockManager.mock('listVideos');
const mockManager = ImportMock.mockStaticClass(YouTubeAPIModule, "YouTubeAPI");
const sinonStub = mockManager.mock("listVideos");
sinonStub.callsFake(YouTubeApiMock.listVideos);
describe('getSegmentsByHash', () => {
describe("getSegmentsByHash", () => {
before(async () => {
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-0-0-1', 'testman', 0, 50, 'sponsor', 'skip', 'PeerTube', 0, 0, 'fdaff4dee1043451faa7398324fb63d8618ebcd11bddfe0491c488db12c6c910']);
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', 40, 50, 2, 'getSegmentsByHash-0-2', 'testman', 0, 50, 'sponsor', 'mute', 'YouTube', 0, 0, 'fdaff4dee1043451faa7398324fb63d8618ebcd11bddfe0491c488db12c6c910']);
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, ['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, 'highlight', 'skip', 'YouTube', 0, 0, getHash('highlightVid', 1)]);
await db.prepare("run", query, ['highlightVid', 70, 70, 2, 'highlightVid-2', 'testman', 0, 50, '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-2', '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, 'd51822c3f681e07aef15a8855f52ad12db9eb9cf059e65b16b64c43359557f61']);
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, ["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-0-0-1", "testman", 0, 50, "sponsor", "skip", "PeerTube", 0, 0, "fdaff4dee1043451faa7398324fb63d8618ebcd11bddfe0491c488db12c6c910"]);
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", 40, 50, 2, "getSegmentsByHash-0-2", "testman", 0, 50, "sponsor", "mute", "YouTube", 0, 0, "fdaff4dee1043451faa7398324fb63d8618ebcd11bddfe0491c488db12c6c910"]);
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, ["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, "highlight", "skip", "YouTube", 0, 0, getHash("highlightVid", 1)]);
await db.prepare("run", query, ["highlightVid", 70, 70, 2, "highlightVid-2", "testman", 0, 50, "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-2", "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, "d51822c3f681e07aef15a8855f52ad12db9eb9cf059e65b16b64c43359557f61"]);
await db.prepare("run", query, ["requiredSegmentVid", 80, 90, 2, "requiredSegmentVid-4", "testman", 0, 50, "sponsor", "skip", "YouTube", 0, 0, "d51822c3f681e07aef15a8855f52ad12db9eb9cf059e65b16b64c43359557f61"]);
});
it('Should be able to get a 200', (done: Done) => {
fetch(getbaseURL() + '/api/skipSegments/3272f?categories=["sponsor", "intro"]')
it("Should be able to get a 200", (done: Done) => {
fetch(`${getbaseURL()}/api/skipSegments/3272f?categories=["sponsor", "intro"]`)
.then(res => {
assert.strictEqual(res.status, 200);
done();
@@ -38,11 +38,11 @@ describe('getSegmentsByHash', () => {
.catch(err => done(err));
});
it('Should return 404 if no segments are found even if a video for the given hash is known', (done: Done) => {
fetch(getbaseURL() + '/api/skipSegments/3272f?categories=["shilling"]')
it("Should return 404 if no segments are found even if a video for the given hash is known", (done: Done) => {
fetch(`${getbaseURL()}/api/skipSegments/3272f?categories=["shilling"]`)
.then(async res => {
assert.strictEqual(res.status, 404);
const expected = '[]';
const expected = "[]";
const body = await res.text();
assert.strictEqual(body, expected);
done();
@@ -50,12 +50,12 @@ describe('getSegmentsByHash', () => {
.catch(err => done(err));
});
it('Should be able to get an empty array if no videos', (done: Done) => {
fetch(getbaseURL() + '/api/skipSegments/11111?categories=["shilling"]')
it("Should be able to get an empty array if no videos", (done: Done) => {
fetch(`${getbaseURL()}/api/skipSegments/11111?categories=["shilling"]`)
.then(async res => {
assert.strictEqual(res.status, 404);
const body = await res.text();
const expected = '[]';
const expected = "[]";
assert.strictEqual(JSON.parse(body).length, 0);
assert.strictEqual(body, expected);
done();
@@ -63,21 +63,21 @@ describe('getSegmentsByHash', () => {
.catch(err => done(err));
});
it('Should be able to get an empty array if only hidden videos', (done: Done) => {
fetch(getbaseURL() + '/api/skipSegments/f3a1?categories=["sponsor"]')
it("Should be able to get an empty array if only hidden videos", (done: Done) => {
fetch(`${getbaseURL()}/api/skipSegments/f3a1?categories=["sponsor"]`)
.then(async res => {
if (res.status !== 404) done("non 404 status code, was " + res.status);
if (res.status !== 404) done(`non 404 status code, was ${res.status}`);
else {
const body = await res.text();
if (JSON.parse(body).length === 0 && body === '[]') done(); // pass
if (JSON.parse(body).length === 0 && body === "[]") done(); // pass
else done("non empty array returned");
}
})
.catch(err => done(err));
});
it('Should return 400 prefix too short', (done: Done) => {
fetch(getbaseURL() + '/api/skipSegments/11?categories=["shilling"]')
it("Should return 400 prefix too short", (done: Done) => {
fetch(`${getbaseURL()}/api/skipSegments/11?categories=["shilling"]`)
.then(res => {
assert.strictEqual(res.status, 400);
done();
@@ -85,10 +85,10 @@ describe('getSegmentsByHash', () => {
.catch(err => done(err));
});
it('Should return 400 prefix too long', (done: Done) => {
const prefix = '1'.repeat(50);
it("Should return 400 prefix too long", (done: Done) => {
const prefix = "1".repeat(50);
assert.ok(prefix.length > 33, "failed to generate long enough string");
fetch(getbaseURL() + '/api/skipSegments/' + prefix + '?categories=["shilling"]')
fetch(`${getbaseURL()}/api/skipSegments/${ prefix }?categories=["shilling"]`)
.then(res => {
assert.strictEqual(res.status, 400);
done();
@@ -96,9 +96,9 @@ describe('getSegmentsByHash', () => {
.catch(err => done(err));
});
it('Should return 404 prefix in range', (done: Done) => {
const prefix = '1'.repeat(5);
fetch(getbaseURL() + '/api/skipSegments/'+prefix+'?categories=["shilling"]')
it("Should return 404 prefix in range", (done: Done) => {
const prefix = "1".repeat(5);
fetch(`${getbaseURL()}/api/skipSegments/${prefix}?categories=["shilling"]`)
.then(res => {
assert.strictEqual(res.status, 404);
done();
@@ -106,8 +106,8 @@ describe('getSegmentsByHash', () => {
.catch(err => done(err));
});
it('Should return 404 for no hash', (done: Done) => {
fetch(getbaseURL() + '/api/skipSegments/?categories=["shilling"]')
it("Should return 404 for no hash", (done: Done) => {
fetch(`${getbaseURL()}/api/skipSegments/?categories=["shilling"]`)
.then(res => {
assert.strictEqual(res.status, 404);
done();
@@ -115,8 +115,8 @@ describe('getSegmentsByHash', () => {
.catch(err => done(err));
});
it('Should return 400 for bad format categories', (done: Done) => {
fetch(getbaseURL() + '/api/skipSegments/fdaf?categories=shilling')
it("Should return 400 for bad format categories", (done: Done) => {
fetch(`${getbaseURL()}/api/skipSegments/fdaf?categories=shilling`)
.then(res => {
assert.strictEqual(res.status, 400);
done();
@@ -124,8 +124,8 @@ describe('getSegmentsByHash', () => {
.catch(err => done(err));
});
it('Should be able to get multiple videos', (done: Done) => {
fetch(getbaseURL() + '/api/skipSegments/fdaf?categories=["sponsor","intro"]')
it("Should be able to get multiple videos", (done: Done) => {
fetch(`${getbaseURL()}/api/skipSegments/fdaf?categories=["sponsor","intro"]`)
.then(async res => {
assert.strictEqual(res.status, 200);
const data = await res.json();
@@ -137,87 +137,87 @@ describe('getSegmentsByHash', () => {
.catch(err => done(err));
});
it('Should be able to get 200 for no categories (default sponsor)', (done: Done) => {
fetch(getbaseURL() + '/api/skipSegments/fdaf')
it("Should be able to get 200 for no categories (default sponsor)", (done: Done) => {
fetch(`${getbaseURL()}/api/skipSegments/fdaf`)
.then(async res => {
assert.strictEqual(res.status, 200);
const data = await res.json();
assert.strictEqual(data.length, 2);
assert.strictEqual(data[0].segments.length, 1);
assert.strictEqual(data[1].segments.length, 1);
assert.strictEqual(data[0].segments[0].category, 'sponsor');
assert.strictEqual(data[0].segments[0].UUID, 'getSegmentsByHash-0-0');
assert.strictEqual(data[1].segments[0].category, 'sponsor');
assert.strictEqual(data[0].segments[0].category, "sponsor");
assert.strictEqual(data[0].segments[0].UUID, "getSegmentsByHash-0-0");
assert.strictEqual(data[1].segments[0].category, "sponsor");
done();
})
.catch(err => done(err));
});
it('Should be able to get 200 for no categories (default sponsor) with action type', (done: Done) => {
fetch(getbaseURL() + '/api/skipSegments/fdaf?actionType=skip')
it("Should be able to get 200 for no categories (default sponsor) with action type", (done: Done) => {
fetch(`${getbaseURL()}/api/skipSegments/fdaf?actionType=skip`)
.then(async res => {
assert.strictEqual(res.status, 200);
const data = await res.json();
assert.strictEqual(data.length, 2);
assert.strictEqual(data[0].segments.length, 1);
assert.strictEqual(data[1].segments.length, 1);
assert.strictEqual(data[0].segments[0].category, 'sponsor');
assert.strictEqual(data[0].segments[0].UUID, 'getSegmentsByHash-0-0');
assert.strictEqual(data[1].segments[0].category, 'sponsor');
assert.strictEqual(data[0].segments[0].category, "sponsor");
assert.strictEqual(data[0].segments[0].UUID, "getSegmentsByHash-0-0");
assert.strictEqual(data[1].segments[0].category, "sponsor");
done();
})
.catch(err => done(err));
});
it('Should be able to get 200 for no categories (default sponsor) with multiple action types', (done: Done) => {
fetch(getbaseURL() + '/api/skipSegments/fdaf?actionType=skip&actionType=mute')
it("Should be able to get 200 for no categories (default sponsor) with multiple action types", (done: Done) => {
fetch(`${getbaseURL()}/api/skipSegments/fdaf?actionType=skip&actionType=mute`)
.then(async res => {
assert.strictEqual(res.status, 200);
const data = await res.json();
assert.strictEqual(data.length, 2);
assert.strictEqual(data[0].segments.length, 2);
assert.strictEqual(data[1].segments.length, 1);
assert.strictEqual(data[0].segments[0].category, 'sponsor');
assert.strictEqual(data[0].segments[0].UUID, 'getSegmentsByHash-0-0');
assert.strictEqual(data[0].segments[1].UUID, 'getSegmentsByHash-0-2');
assert.strictEqual(data[1].segments[0].category, 'sponsor');
assert.strictEqual(data[0].segments[0].category, "sponsor");
assert.strictEqual(data[0].segments[0].UUID, "getSegmentsByHash-0-0");
assert.strictEqual(data[0].segments[1].UUID, "getSegmentsByHash-0-2");
assert.strictEqual(data[1].segments[0].category, "sponsor");
done();
})
.catch(err => done(err));
});
it('Should be able to get 200 for no categories (default sponsor) with multiple action types (JSON array)', (done: Done) => {
fetch(getbaseURL() + '/api/skipSegments/fdaf?actionTypes=["skip","mute"]')
it("Should be able to get 200 for no categories (default sponsor) with multiple action types (JSON array)", (done: Done) => {
fetch(`${getbaseURL()}/api/skipSegments/fdaf?actionTypes=["skip","mute"]`)
.then(async res => {
assert.strictEqual(res.status, 200);
const data = await res.json();
assert.strictEqual(data.length, 2);
assert.strictEqual(data[0].segments.length, 2);
assert.strictEqual(data[1].segments.length, 1);
assert.strictEqual(data[0].segments[0].category, 'sponsor');
assert.strictEqual(data[0].segments[0].UUID, 'getSegmentsByHash-0-0');
assert.strictEqual(data[0].segments[1].UUID, 'getSegmentsByHash-0-2');
assert.strictEqual(data[1].segments[0].category, 'sponsor');
assert.strictEqual(data[0].segments[0].category, "sponsor");
assert.strictEqual(data[0].segments[0].UUID, "getSegmentsByHash-0-0");
assert.strictEqual(data[0].segments[1].UUID, "getSegmentsByHash-0-2");
assert.strictEqual(data[1].segments[0].category, "sponsor");
done();
})
.catch(err => done(err));
});
it('Should be able to get 200 for no categories (default sponsor) for a non YouTube service', (done: Done) => {
fetch(getbaseURL() + '/api/skipSegments/fdaf?service=PeerTube')
it("Should be able to get 200 for no categories (default sponsor) for a non YouTube service", (done: Done) => {
fetch(`${getbaseURL()}/api/skipSegments/fdaf?service=PeerTube`)
.then(async res => {
assert.strictEqual(res.status, 200);
const data = await res.json();
assert.strictEqual(data.length, 1);
assert.strictEqual(data[0].segments.length, 1);
assert.strictEqual(data[0].segments[0].UUID, 'getSegmentsByHash-0-0-1');
assert.strictEqual(data[0].segments[0].UUID, "getSegmentsByHash-0-0-1");
done();
})
.catch(err => done(err));
});
it('Should only return one segment when fetching highlight segments', (done: Done) => {
fetch(getbaseURL() + '/api/skipSegments/c962?category=highlight')
it("Should only return one segment when fetching highlight segments", (done: Done) => {
fetch(`${getbaseURL()}/api/skipSegments/c962?category=highlight`)
.then(async res => {
assert.strictEqual(res.status, 200);
const data = await res.json();
@@ -228,12 +228,12 @@ describe('getSegmentsByHash', () => {
.catch(err => done(err));
});
it('Should be able to post a segment and get it using endpoint', (done: Done) => {
const testID = 'abc123goodVideo';
fetch(getbaseURL() + "/api/postVideoSponsorTimes", {
method: 'POST',
it("Should be able to post a segment and get it using endpoint", (done: Done) => {
const testID = "abc123goodVideo";
fetch(`${getbaseURL()}/api/postVideoSponsorTimes`, {
method: "POST",
headers: {
'Content-Type': 'application/json',
"Content-Type": "application/json",
},
body: JSON.stringify({
userID: "test-qwertyuiopasdfghjklzxcvbnm",
@@ -245,22 +245,22 @@ describe('getSegmentsByHash', () => {
}),
})
.then(async () => {
fetch(getbaseURL() + '/api/skipSegments/' + getHash(testID, 1).substring(0, 3))
fetch(`${getbaseURL()}/api/skipSegments/${getHash(testID, 1).substring(0, 3)}`)
.then(async res => {
assert.strictEqual(res.status, 200);
const data = await res.json();
assert.strictEqual(data.length, 1);
assert.strictEqual(data[0].segments.length, 1);
assert.strictEqual(data[0].segments[0].category, 'sponsor');
assert.strictEqual(data[0].segments[0].category, "sponsor");
done();
})
.catch(err => done('(get) ' + err));
.catch(err => done(`(get) ${err}`));
})
.catch(err => done('(post) ' + err));
.catch(err => done(`(post) ${err}`));
});
it('Should be able to get multiple categories with repeating parameters', (done: Done) => {
fetch(getbaseURL() + "/api/skipSegments/fdaff4?&category=sponsor&category=intro")
it("Should be able to get multiple categories with repeating parameters", (done: Done) => {
fetch(`${getbaseURL()}/api/skipSegments/fdaff4?&category=sponsor&category=intro`)
.then(async res => {
assert.strictEqual(res.status, 200);
const data = await res.json();
@@ -278,32 +278,31 @@ describe('getSegmentsByHash', () => {
.catch(err => done(err));
});
it('Should be able to get specific segments with requiredSegments', (done: Done) => {
fetch(getbaseURL() + '/api/skipSegments/d518?requiredSegments=["requiredSegmentVid-2","requiredSegmentVid-3"]')
it("Should be able to get specific segments with requiredSegments", (done: Done) => {
fetch(`${getbaseURL()}/api/skipSegments/d518?requiredSegments=["requiredSegmentVid-2","requiredSegmentVid-3"]`)
.then(async res => {
assert.strictEqual(res.status, 200);
const data = await res.json();
assert.strictEqual(data.length, 1);
assert.strictEqual(data[0].segments.length, 2);
assert.strictEqual(data[0].segments[0].UUID, 'requiredSegmentVid-2');
assert.strictEqual(data[0].segments[0].UUID, 'requiredSegmentVid-2');
assert.strictEqual(data[0].segments[0].UUID, "requiredSegmentVid-2");
assert.strictEqual(data[0].segments[0].UUID, "requiredSegmentVid-2");
done();
})
.catch(err => done(err));
});
it('Should be able to get specific segments with repeating requiredSegment', (done: Done) => {
fetch(getbaseURL() + '/api/skipSegments/d518?requiredSegment=requiredSegmentVid-2&requiredSegment=requiredSegmentVid-3')
it("Should be able to get specific segments with repeating requiredSegment", (done: Done) => {
fetch(`${getbaseURL()}/api/skipSegments/d518?requiredSegment=requiredSegmentVid-2&requiredSegment=requiredSegmentVid-3`)
.then(async res => {
assert.strictEqual(res.status, 200);
const data = await res.json();
assert.strictEqual(data.length, 1);
assert.strictEqual(data[0].segments.length, 2);
assert.strictEqual(data[0].segments[0].UUID, 'requiredSegmentVid-2');
assert.strictEqual(data[0].segments[1].UUID, 'requiredSegmentVid-3');
assert.strictEqual(data[0].segments[0].UUID, "requiredSegmentVid-2");
assert.strictEqual(data[0].segments[1].UUID, "requiredSegmentVid-3");
done();
})
.catch(err => done(err));
});
});

View File

@@ -1,10 +1,10 @@
import {getSubmissionUUID} from '../../src/utils/getSubmissionUUID';
import assert from 'assert';
import { ActionType, VideoID } from '../../src/types/segments.model';
import { UserID } from '../../src/types/user.model';
import {getSubmissionUUID} from "../../src/utils/getSubmissionUUID";
import assert from "assert";
import { ActionType, VideoID } from "../../src/types/segments.model";
import { UserID } from "../../src/types/user.model";
describe('getSubmissionUUID', () => {
it('Should return the hashed value', () => {
assert.strictEqual(getSubmissionUUID('video001' as VideoID, 'skip' as ActionType, 'testuser001' as UserID, 13.33337, 42.000001), '3572aa64e0a2d6352c3de14ca45f8a83d193c32635669a7ae0b40c9eb36395872');
describe("getSubmissionUUID", () => {
it("Should return the hashed value", () => {
assert.strictEqual(getSubmissionUUID("video001" as VideoID, "skip" as ActionType, "testuser001" as UserID, 13.33337, 42.000001), "3572aa64e0a2d6352c3de14ca45f8a83d193c32635669a7ae0b40c9eb36395872");
});
});

View File

@@ -1,28 +1,28 @@
import fetch from 'node-fetch';
import {Done, getbaseURL} from '../utils';
import {db} from '../../src/databases/databases';
import {getHash} from '../../src/utils/getHash';
import assert from 'assert';
import fetch from "node-fetch";
import {Done, getbaseURL} from "../utils";
import {db} from "../../src/databases/databases";
import {getHash} from "../../src/utils/getHash";
import assert from "assert";
describe('getUserID', () => {
describe("getUserID", () => {
before(async () => {
const insertUserNameQuery = 'INSERT INTO "userNames" ("userID", "userName") VALUES(?, ?)';
await db.prepare("run", insertUserNameQuery, [getHash("getuserid_user_01"), 'fuzzy user 01']);
await db.prepare("run", insertUserNameQuery, [getHash("getuserid_user_02"), 'fuzzy user 02']);
await db.prepare("run", insertUserNameQuery, [getHash("getuserid_user_03"), 'specific user 03']);
await db.prepare("run", insertUserNameQuery, [getHash("getuserid_user_04"), 'repeating']);
await db.prepare("run", insertUserNameQuery, [getHash("getuserid_user_05"), 'repeating']);
await db.prepare("run", insertUserNameQuery, [getHash("getuserid_user_01"), "fuzzy user 01"]);
await db.prepare("run", insertUserNameQuery, [getHash("getuserid_user_02"), "fuzzy user 02"]);
await db.prepare("run", insertUserNameQuery, [getHash("getuserid_user_03"), "specific user 03"]);
await db.prepare("run", insertUserNameQuery, [getHash("getuserid_user_04"), "repeating"]);
await db.prepare("run", insertUserNameQuery, [getHash("getuserid_user_05"), "repeating"]);
await db.prepare("run", insertUserNameQuery, [getHash("getuserid_user_06"), getHash("getuserid_user_06")]);
await db.prepare("run", insertUserNameQuery, [getHash("getuserid_user_07"), '0redos0']);
await db.prepare("run", insertUserNameQuery, [getHash("getuserid_user_08"), '%redos%']);
await db.prepare("run", insertUserNameQuery, [getHash("getuserid_user_09"), '_redos_']);
await db.prepare("run", insertUserNameQuery, [getHash("getuserid_user_10"), 'redos\\%']);
await db.prepare("run", insertUserNameQuery, [getHash("getuserid_user_11"), '\\\\\\']);
await db.prepare("run", insertUserNameQuery, [getHash("getuserid_user_12"), 'a']);
await db.prepare("run", insertUserNameQuery, [getHash("getuserid_user_07"), "0redos0"]);
await db.prepare("run", insertUserNameQuery, [getHash("getuserid_user_08"), "%redos%"]);
await db.prepare("run", insertUserNameQuery, [getHash("getuserid_user_09"), "_redos_"]);
await db.prepare("run", insertUserNameQuery, [getHash("getuserid_user_10"), "redos\\%"]);
await db.prepare("run", insertUserNameQuery, [getHash("getuserid_user_11"), "\\\\\\"]);
await db.prepare("run", insertUserNameQuery, [getHash("getuserid_user_12"), "a"]);
});
it('Should be able to get a 200', (done: Done) => {
fetch(getbaseURL() + '/api/userID?username=fuzzy+user+01')
it("Should be able to get a 200", (done: Done) => {
fetch(`${getbaseURL()}/api/userID?username=fuzzy+user+01`)
.then(async res => {
assert.strictEqual(res.status, 200);
done();
@@ -30,8 +30,8 @@ describe('getUserID', () => {
.catch(err => done(err));
});
it('Should be able to get a 400 (No username parameter)', (done: Done) => {
fetch(getbaseURL() + '/api/userID')
it("Should be able to get a 400 (No username parameter)", (done: Done) => {
fetch(`${getbaseURL()}/api/userID`)
.then(res => {
assert.strictEqual(res.status, 400);
done();
@@ -39,8 +39,8 @@ describe('getUserID', () => {
.catch(err => done(err));
});
it('Should be able to get a 200 (username is public id)', (done: Done) => {
fetch(getbaseURL() + '/api/userID?username='+getHash("getuserid_user_06"))
it("Should be able to get a 200 (username is public id)", (done: Done) => {
fetch(`${getbaseURL()}/api/userID?username=${getHash("getuserid_user_06")}`)
.then(async res => {
assert.strictEqual(res.status, 200);
done();
@@ -48,8 +48,8 @@ describe('getUserID', () => {
.catch(err => done(err));
});
it('Should be able to get a 400 (username longer than 64 chars)', (done: Done) => {
fetch(getbaseURL() + '/api/userID?username='+getHash("getuserid_user_06")+'0')
it("Should be able to get a 400 (username longer than 64 chars)", (done: Done) => {
fetch(`${getbaseURL()}/api/userID?username=${getHash("getuserid_user_06")}0`)
.then(res => {
assert.strictEqual(res.status, 400);
done();
@@ -57,8 +57,8 @@ describe('getUserID', () => {
.catch(err => done(err));
});
it('Should be able to get single username', (done: Done) => {
fetch(getbaseURL() + '/api/userID?username=fuzzy+user+01')
it("Should be able to get single username", (done: Done) => {
fetch(`${getbaseURL()}/api/userID?username=fuzzy+user+01`)
.then(async res => {
assert.strictEqual(res.status, 200);
const expected = [{
@@ -72,8 +72,8 @@ describe('getUserID', () => {
.catch(err => done(err));
});
it('Should be able to get multiple fuzzy user info from start', (done: Done) => {
fetch(getbaseURL() + '/api/userID?username=fuzzy+user')
it("Should be able to get multiple fuzzy user info from start", (done: Done) => {
fetch(`${getbaseURL()}/api/userID?username=fuzzy+user`)
.then(async res => {
assert.strictEqual(res.status, 200);
const expected = [{
@@ -90,8 +90,8 @@ describe('getUserID', () => {
.catch(err => done(err));
});
it('Should be able to get multiple fuzzy user info from middle', (done: Done) => {
fetch(getbaseURL() + '/api/userID?username=user')
it("Should be able to get multiple fuzzy user info from middle", (done: Done) => {
fetch(`${getbaseURL()}/api/userID?username=user`)
.then(async res => {
assert.strictEqual(res.status, 200);
const expected = [{
@@ -111,9 +111,9 @@ describe('getUserID', () => {
.catch(err => done(err));
});
it('Should be able to get with public ID', (done: Done) => {
it("Should be able to get with public ID", (done: Done) => {
const userID = getHash("getuserid_user_06");
fetch(getbaseURL() + '/api/userID?username='+userID)
fetch(`${getbaseURL()}/api/userID?username=${userID}`)
.then(async res => {
assert.strictEqual(res.status, 200);
const expected = [{
@@ -127,9 +127,9 @@ describe('getUserID', () => {
.catch(err => done(err));
});
it('Should be able to get with fuzzy public ID', (done: Done) => {
it("Should be able to get with fuzzy public ID", (done: Done) => {
const userID = getHash("getuserid_user_06");
fetch(getbaseURL() + '/api/userID?username='+userID.substr(10,60))
fetch(`${getbaseURL()}/api/userID?username=${userID.substr(10,60)}`)
.then(async res => {
assert.strictEqual(res.status, 200);
const expected = [{
@@ -143,8 +143,8 @@ describe('getUserID', () => {
.catch(err => done(err));
});
it('Should be able to get repeating username', (done: Done) => {
fetch(getbaseURL() + '/api/userID?username=repeating')
it("Should be able to get repeating username", (done: Done) => {
fetch(`${getbaseURL()}/api/userID?username=repeating`)
.then(async res => {
assert.strictEqual(res.status, 200);
const expected = [{
@@ -161,8 +161,8 @@ describe('getUserID', () => {
.catch(err => done(err));
});
it('Should be able to get repeating fuzzy username', (done: Done) => {
fetch(getbaseURL() + '/api/userID?username=peat')
it("Should be able to get repeating fuzzy username", (done: Done) => {
fetch(`${getbaseURL()}/api/userID?username=peat`)
.then(async res => {
assert.strictEqual(res.status, 200);
const expected = [{
@@ -179,8 +179,8 @@ describe('getUserID', () => {
.catch(err => done(err));
});
it('should avoid ReDOS with _', (done: Done) => {
fetch(getbaseURL() + '/api/userID?username=_redos_')
it("should avoid ReDOS with _", (done: Done) => {
fetch(`${getbaseURL()}/api/userID?username=_redos_`)
.then(async res => {
assert.strictEqual(res.status, 200);
const expected = [{
@@ -194,8 +194,8 @@ describe('getUserID', () => {
.catch(err => done(err));
});
it('should avoid ReDOS with %', (done: Done) => {
fetch(getbaseURL() + '/api/userID?username=%redos%')
it("should avoid ReDOS with %", (done: Done) => {
fetch(`${getbaseURL()}/api/userID?username=%redos%`)
.then(async res => {
assert.strictEqual(res.status, 200);
const expected = [{
@@ -209,8 +209,8 @@ describe('getUserID', () => {
.catch(err => done(err));
});
it('should return 404 if escaped backslashes present', (done: Done) => {
fetch(getbaseURL() + '/api/userID?username=%redos\\\\_')
it("should return 404 if escaped backslashes present", (done: Done) => {
fetch(`${getbaseURL()}/api/userID?username=%redos\\\\_`)
.then(res => {
assert.strictEqual(res.status, 404);
done();
@@ -218,8 +218,8 @@ describe('getUserID', () => {
.catch(err => done(err));
});
it('should return 404 if backslashes present', (done: Done) => {
fetch(getbaseURL() + '/api/userID?username=\\%redos\\_')
it("should return 404 if backslashes present", (done: Done) => {
fetch(`${getbaseURL()}/api/userID?username=\\%redos\\_`)
.then(res => {
assert.strictEqual(res.status, 404);
done();
@@ -227,8 +227,8 @@ describe('getUserID', () => {
.catch(err => done(err));
});
it('should return user if just backslashes', (done: Done) => {
fetch(getbaseURL() + '/api/userID?username=\\\\\\')
it("should return user if just backslashes", (done: Done) => {
fetch(`${getbaseURL()}/api/userID?username=\\\\\\`)
.then(async res => {
assert.strictEqual(res.status, 200);
const expected = [{
@@ -242,8 +242,8 @@ describe('getUserID', () => {
.catch(err => done(err));
});
it('should not allow usernames more than 64 characters', (done: Done) => {
fetch(getbaseURL() + '/api/userID?username='+'0'.repeat(65))
it("should not allow usernames more than 64 characters", (done: Done) => {
fetch(`${getbaseURL()}/api/userID?username=${"0".repeat(65)}`)
.then(res => {
assert.strictEqual(res.status, 400);
done();
@@ -251,8 +251,8 @@ describe('getUserID', () => {
.catch(err => done(err));
});
it('should not allow usernames less than 3 characters', (done: Done) => {
fetch(getbaseURL() + '/api/userID?username=aa')
it("should not allow usernames less than 3 characters", (done: Done) => {
fetch(`${getbaseURL()}/api/userID?username=aa`)
.then(res => {
assert.strictEqual(res.status, 400);
done();
@@ -260,8 +260,8 @@ describe('getUserID', () => {
.catch(err => done(err));
});
it('should allow exact match', (done: Done) => {
fetch(getbaseURL() + '/api/userID?username=a&exact=true')
it("should allow exact match", (done: Done) => {
fetch(`${getbaseURL()}/api/userID?username=a&exact=true`)
.then(async res => {
assert.strictEqual(res.status, 200);
const expected = [{
@@ -275,8 +275,8 @@ describe('getUserID', () => {
.catch(err => done(err));
});
it('Should be able to get repeating username with exact username', (done: Done) => {
fetch(getbaseURL() + '/api/userID?username=repeating&exact=true')
it("Should be able to get repeating username with exact username", (done: Done) => {
fetch(`${getbaseURL()}/api/userID?username=repeating&exact=true`)
.then(async res => {
assert.strictEqual(res.status, 200);
const expected = [{
@@ -293,8 +293,8 @@ describe('getUserID', () => {
.catch(err => done(err));
});
it('Should not get exact unless explicitly set to true', (done: Done) => {
fetch(getbaseURL() + '/api/userID?username=user&exact=1')
it("Should not get exact unless explicitly set to true", (done: Done) => {
fetch(`${getbaseURL()}/api/userID?username=user&exact=1`)
.then(async res => {
assert.strictEqual(res.status, 200);
const expected = [{

View File

@@ -1,32 +1,32 @@
import fetch from 'node-fetch';
import {Done, getbaseURL} from '../utils';
import {db} from '../../src/databases/databases';
import {getHash} from '../../src/utils/getHash';
import assert from 'assert';
import fetch from "node-fetch";
import {Done, getbaseURL} from "../utils";
import {db} from "../../src/databases/databases";
import {getHash} from "../../src/utils/getHash";
import assert from "assert";
describe('getUserInfo', () => {
describe("getUserInfo", () => {
before(async () => {
const insertUserNameQuery = 'INSERT INTO "userNames" ("userID", "userName") VALUES(?, ?)';
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(?, ?, ?, ?, ?, ?, ?, ?, ?, ?)';
await db.prepare("run", sponsorTimesQuery, ['xxxyyyzzz', 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, ['yyyxxxzzz', 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, ['xzzzxxyyy', 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, ['xxxyyyzzz', 1, 11, 2, 'uuid000007', getHash("getuserinfo_user_02"), 7, 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, ["xxxyyyzzz", 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, ["yyyxxxzzz", 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, ["xzzzxxyyy", 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, ["xxxyyyzzz", 1, 11, 2, "uuid000007", getHash("getuserinfo_user_02"), 7, 10, "sponsor", 1]);
await db.prepare("run", sponsorTimesQuery, ["xxxyyyzzz", 1, 11, 2, "uuid000008", getHash("getuserinfo_user_02"), 8, 10, "sponsor", 1]);
const insertWarningQuery = 'INSERT INTO warnings ("userID", "issueTime", "issuerUserID", "enabled") VALUES (?, ?, ?, ?)';
await db.prepare("run", insertWarningQuery, [getHash('getuserinfo_warning_0'), 10, 'getuserinfo_vip', 1]);
await db.prepare("run", insertWarningQuery, [getHash('getuserinfo_warning_1'), 10, 'getuserinfo_vip', 1]);
await db.prepare("run", insertWarningQuery, [getHash('getuserinfo_warning_1'), 10, 'getuserinfo_vip', 1]);
await db.prepare("run", insertWarningQuery, [getHash("getuserinfo_warning_0"), 10, "getuserinfo_vip", 1]);
await db.prepare("run", insertWarningQuery, [getHash("getuserinfo_warning_1"), 10, "getuserinfo_vip", 1]);
await db.prepare("run", insertWarningQuery, [getHash("getuserinfo_warning_1"), 10, "getuserinfo_vip", 1]);
});
it('Should be able to get a 200', (done: Done) => {
fetch(getbaseURL() + '/api/userInfo?userID=getuserinfo_user_01')
it("Should be able to get a 200", (done: Done) => {
fetch(`${getbaseURL()}/api/userInfo?userID=getuserinfo_user_01`)
.then(res => {
assert.strictEqual(res.status, 200);
done();
@@ -34,8 +34,8 @@ describe('getUserInfo', () => {
.catch(err => done(err));
});
it('Should be able to get a 400 (No userID parameter)', (done: Done) => {
fetch(getbaseURL() + '/api/userInfo')
it("Should be able to get a 400 (No userID parameter)", (done: Done) => {
fetch(`${getbaseURL()}/api/userInfo`)
.then(res => {
assert.strictEqual(res.status, 400);
done();
@@ -43,12 +43,12 @@ describe('getUserInfo', () => {
.catch(err => done(err));
});
it('Should be able to get user info', (done: Done) => {
fetch(getbaseURL() + '/api/userInfo?userID=getuserinfo_user_01')
it("Should be able to get user info", (done: Done) => {
fetch(`${getbaseURL()}/api/userInfo?userID=getuserinfo_user_01`)
.then(async res => {
assert.strictEqual(res.status, 200);
const expected = {
userName: 'Username user 01',
userName: "Username user 01",
userID: "66e7c974039ffb870a500a33eca3a3989861018909b938c313cf1a8a366800b8",
minutesSaved: 5,
viewCount: 30,
@@ -67,8 +67,8 @@ describe('getUserInfo', () => {
.catch(err => done(err));
});
it('Should get warning data', (done: Done) => {
fetch(getbaseURL() + '/api/userInfo?userID=getuserinfo_warning_0')
it("Should get warning data", (done: Done) => {
fetch(`${getbaseURL()}/api/userInfo?userID=getuserinfo_warning_0`)
.then(async res => {
assert.strictEqual(res.status, 200);
const data = await res.json();
@@ -78,8 +78,8 @@ describe('getUserInfo', () => {
.catch(err => done(err));
});
it('Should get warning data with public ID', (done: Done) => {
fetch(getbaseURL() + '/api/userInfo?publicUserID=' + getHash("getuserinfo_warning_0"))
it("Should get warning data with public ID", (done: Done) => {
fetch(`${getbaseURL()}/api/userInfo?publicUserID=${ getHash("getuserinfo_warning_0")}`)
.then(async res => {
assert.strictEqual(res.status, 200);
const data = await res.json();
@@ -89,8 +89,8 @@ describe('getUserInfo', () => {
.catch(err => done(err));
});
it('Should get multiple warnings', (done: Done) => {
fetch(getbaseURL() + '/api/userInfo?userID=getuserinfo_warning_1')
it("Should get multiple warnings", (done: Done) => {
fetch(`${getbaseURL()}/api/userInfo?userID=getuserinfo_warning_1`)
.then(async res => {
assert.strictEqual(res.status, 200);
const data = await res.json();
@@ -100,8 +100,8 @@ describe('getUserInfo', () => {
.catch(err => done(err));
});
it('Should not get warnings if none', (done: Done) => {
fetch(getbaseURL() + '/api/userInfo?userID=getuserinfo_warning_2')
it("Should not get warnings if none", (done: Done) => {
fetch(`${getbaseURL()}/api/userInfo?userID=getuserinfo_warning_2`)
.then(async res => {
assert.strictEqual(res.status, 200);
const data = await res.json();
@@ -111,19 +111,19 @@ describe('getUserInfo', () => {
.catch(err => done(err));
});
it('Should done(userID for userName (No userName set)', (done: Done) => {
fetch(getbaseURL() + '/api/userInfo?userID=getuserinfo_user_02')
it("Should done(userID for userName (No userName set)", (done: Done) => {
fetch(`${getbaseURL()}/api/userInfo?userID=getuserinfo_user_02`)
.then(async res => {
assert.strictEqual(res.status, 200);
const data = await res.json();
assert.strictEqual(data.userName, 'c2a28fd225e88f74945794ae85aef96001d4a1aaa1022c656f0dd48ac0a3ea0f');
assert.strictEqual(data.userName, "c2a28fd225e88f74945794ae85aef96001d4a1aaa1022c656f0dd48ac0a3ea0f");
done();
})
.catch(err => done(err));
});
it('Should return null segment if none', (done: Done) => {
fetch(getbaseURL() + '/api/userInfo?userID=getuserinfo_null')
it("Should return null segment if none", (done: Done) => {
fetch(`${getbaseURL()}/api/userInfo?userID=getuserinfo_null`)
.then(async res => {
assert.strictEqual(res.status, 200);
const data = await res.json();
@@ -133,8 +133,8 @@ describe('getUserInfo', () => {
.catch(err => done(err));
});
it('Should return zeroes if userid does not exist', (done: Done) => {
fetch(getbaseURL() + '/api/userInfo?userID=getuserinfo_null')
it("Should return zeroes if userid does not exist", (done: Done) => {
fetch(`${getbaseURL()}/api/userInfo?userID=getuserinfo_null`)
.then(async res => {
const data = await res.json();
for (const value in data) {

View File

@@ -1,9 +1,9 @@
import fetch from 'node-fetch';
import {Done, getbaseURL} from '../utils';
import {getHash} from '../../src/utils/getHash';
import {db} from '../../src/databases/databases';
import assert from 'assert';
import {LockCategory} from '../../src/types/segments.model';
import fetch from "node-fetch";
import {Done, getbaseURL} from "../utils";
import {getHash} from "../../src/utils/getHash";
import {db} from "../../src/databases/databases";
import assert from "assert";
import {LockCategory} from "../../src/types/segments.model";
const deepStringEqual = (a: string[], b: string[]): boolean => {
if (a.length !== b.length) return false;
@@ -11,53 +11,53 @@ const deepStringEqual = (a: string[], b: string[]): boolean => {
return true;
};
describe('lockCategoriesRecords', () => {
describe("lockCategoriesRecords", () => {
before(async () => {
const insertVipUserQuery = 'INSERT INTO "vipUsers" ("userID") VALUES (?)';
await db.prepare("run", insertVipUserQuery, [getHash("VIPUser-lockCategories")]);
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("VIPUser-lockCategories"), 'no-segments-video-id', 'intro', 'reason-1']);
await db.prepare("run", insertLockCategoryQuery, [getHash("VIPUser-lockCategories"), "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("VIPUser-lockCategories"), '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("VIPUser-lockCategories"), 'lockCategoryVideo', 'sponsor', 'reason-3']);
await db.prepare("run", insertLockCategoryQuery, [getHash("VIPUser-lockCategories"), "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("VIPUser-lockCategories"), "lockCategoryVideo", "sponsor", "reason-3"]);
await db.prepare("run", insertLockCategoryQuery, [getHash("VIPUser-lockCategories"), 'delete-record', 'sponsor', 'reason-4']);
await db.prepare("run", insertLockCategoryQuery, [getHash("VIPUser-lockCategories"), "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("VIPUser-lockCategories"), 'delete-record-1', 'intro', 'reason-5']);
await db.prepare("run", insertLockCategoryQuery, [getHash("VIPUser-lockCategories"), "delete-record-1", "sponsor", "reason-5"]);
await db.prepare("run", insertLockCategoryQuery, [getHash("VIPUser-lockCategories"), "delete-record-1", "intro", "reason-5"]);
});
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;
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;
assert.ok(version > 1);
});
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 = {
videoID: 'no-segments-video-id',
userID: 'VIPUser-lockCategories',
videoID: "no-segments-video-id",
userID: "VIPUser-lockCategories",
categories: [
'outro',
'shilling',
'shilling',
'shil ling',
'',
'intro',
"outro",
"shilling",
"shilling",
"shil ling",
"",
"intro",
],
};
const expected = {
submitted: [
'outro',
'shilling',
"outro",
"shilling",
],
};
fetch(getbaseURL() + "/api/lockCategories", {
method: 'POST',
fetch(`${getbaseURL()}/api/lockCategories`, {
method: "POST",
headers: {
'Content-Type': 'application/json',
"Content-Type": "application/json",
},
body: JSON.stringify(json)
})
@@ -70,36 +70,36 @@ describe('lockCategoriesRecords', () => {
.catch(err => done(err));
});
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 = {
videoID: 'no-segments-video-id-1',
userID: 'VIPUser-lockCategories',
videoID: "no-segments-video-id-1",
userID: "VIPUser-lockCategories",
categories: [
'outro',
'shilling',
'shilling',
'shil ling',
'',
'intro',
"outro",
"shilling",
"shilling",
"shil ling",
"",
"intro",
],
};
fetch(getbaseURL() + "/api/lockCategories", {
method: 'POST',
fetch(`${getbaseURL()}/api/lockCategories`, {
method: "POST",
headers: {
'Content-Type': 'application/json',
"Content-Type": "application/json",
},
body: JSON.stringify(json)
})
.then(async res => {
assert.strictEqual(res.status, 200);
const result = await db.prepare('all', 'SELECT * FROM "lockCategories" WHERE "videoID" = ?', ['no-segments-video-id-1']) as LockCategory[];
const result = await db.prepare("all", 'SELECT * FROM "lockCategories" WHERE "videoID" = ?', ["no-segments-video-id-1"]) as LockCategory[];
assert.strictEqual(result.length, 4);
const oldRecordNotChangeReason = result.filter(item =>
item.reason === 'reason-2' && ['sponsor', 'intro'].includes(item.category)
item.reason === "reason-2" && ["sponsor", "intro"].includes(item.category)
);
const newRecordWithEmptyReason = result.filter(item =>
item.reason === '' && ['outro', 'shilling'].includes(item.category)
item.reason === "" && ["outro", "shilling"].includes(item.category)
);
assert.strictEqual(newRecordWithEmptyReason.length, 2);
@@ -109,33 +109,33 @@ describe('lockCategoriesRecords', () => {
.catch(err => done(err));
});
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 = {
videoID: 'no-segments-video-id',
userID: 'VIPUser-lockCategories',
videoID: "no-segments-video-id",
userID: "VIPUser-lockCategories",
categories: [
'outro',
'shilling',
'shilling',
'shil ling',
'',
'intro',
"outro",
"shilling",
"shilling",
"shil ling",
"",
"intro",
],
reason: 'new reason'
reason: "new reason"
};
const expected = {
submitted: [
'outro',
'shilling',
'intro'
"outro",
"shilling",
"intro"
],
};
fetch(getbaseURL() + "/api/lockCategories", {
method: 'POST',
fetch(`${getbaseURL()}/api/lockCategories`, {
method: "POST",
headers: {
'Content-Type': 'application/json',
"Content-Type": "application/json",
},
body: JSON.stringify(json)
})
@@ -148,43 +148,43 @@ describe('lockCategoriesRecords', () => {
.catch(err => done(err));
});
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 = {
videoID: 'no-segments-video-id-1',
userID: 'VIPUser-lockCategories',
videoID: "no-segments-video-id-1",
userID: "VIPUser-lockCategories",
categories: [
'outro',
'shilling',
'shilling',
'shil ling',
'',
'intro',
"outro",
"shilling",
"shilling",
"shil ling",
"",
"intro",
],
reason: 'new reason'
reason: "new reason"
};
const expectedWithNewReason = [
'outro',
'shilling',
'intro'
"outro",
"shilling",
"intro"
];
fetch(getbaseURL() + "/api/lockCategories", {
method: 'POST',
fetch(`${getbaseURL()}/api/lockCategories`, {
method: "POST",
headers: {
'Content-Type': 'application/json',
"Content-Type": "application/json",
},
body: JSON.stringify(json)
})
.then(async res => {
assert.strictEqual(res.status, 200);
const result = await db.prepare('all', 'SELECT * FROM "lockCategories" WHERE "videoID" = ?', ['no-segments-video-id-1']) as LockCategory[];
const result = await db.prepare("all", 'SELECT * FROM "lockCategories" WHERE "videoID" = ?', ["no-segments-video-id-1"]) as LockCategory[];
assert.strictEqual(result.length, 4);
const newRecordWithNewReason = result.filter(item =>
expectedWithNewReason.includes(item.category) && item.reason === 'new reason'
expectedWithNewReason.includes(item.category) && item.reason === "new reason"
);
const oldRecordNotChangeReason = result.filter(item =>
item.reason === 'reason-2'
item.reason === "reason-2"
);
assert.strictEqual(newRecordWithNewReason.length, 3);
@@ -194,84 +194,84 @@ describe('lockCategoriesRecords', () => {
.catch(err => done(err));
});
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 = {
videoID: 'underscore',
userID: 'VIPUser-lockCategories',
videoID: "underscore",
userID: "VIPUser-lockCategories",
categories: [
'word_word',
"word_word",
],
};
fetch(getbaseURL() + "/api/lockCategories", {
method: 'POST',
fetch(`${getbaseURL()}/api/lockCategories`, {
method: "POST",
headers: {
'Content-Type': 'application/json',
"Content-Type": "application/json",
},
body: JSON.stringify(json),
})
.then(async res => {
assert.strictEqual(res.status, 200);
const result = await db.prepare('all', 'SELECT * FROM "lockCategories" WHERE "videoID" = ?', ['underscore']);
const result = await db.prepare("all", 'SELECT * FROM "lockCategories" WHERE "videoID" = ?', ["underscore"]);
assert.strictEqual(result.length, 1);
done();
})
.catch(err => done(err));
});
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 = {
videoID: 'bothCases',
userID: 'VIPUser-lockCategories',
videoID: "bothCases",
userID: "VIPUser-lockCategories",
categories: [
'wordWord',
"wordWord",
],
};
fetch(getbaseURL() + "/api/lockCategories", {
method: 'POST',
fetch(`${getbaseURL()}/api/lockCategories`, {
method: "POST",
headers: {
'Content-Type': 'application/json',
"Content-Type": "application/json",
},
body: JSON.stringify(json),
})
.then(async res => {
assert.strictEqual(res.status, 200);
const result = await db.prepare('all', 'SELECT * FROM "lockCategories" WHERE "videoID" = ?', ['bothCases']);
const result = await db.prepare("all", 'SELECT * FROM "lockCategories" WHERE "videoID" = ?', ["bothCases"]);
assert.strictEqual(result.length, 1);
done();
})
.catch(err => done(err));
});
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 = {
videoID: 'specialChar',
userID: 'VIPUser-lockCategories',
videoID: "specialChar",
userID: "VIPUser-lockCategories",
categories: [
'word&word',
"word&word",
],
};
fetch(getbaseURL() + "/api/lockCategories", {
method: 'POST',
fetch(`${getbaseURL()}/api/lockCategories`, {
method: "POST",
headers: {
'Content-Type': 'application/json',
"Content-Type": "application/json",
},
body: JSON.stringify(json),
})
.then(async res => {
assert.strictEqual(res.status, 200);
const result = await db.prepare('all', 'SELECT * FROM "lockCategories" WHERE "videoID" = ?', ['specialChar']);
const result = await db.prepare("all", 'SELECT * FROM "lockCategories" WHERE "videoID" = ?', ["specialChar"]);
assert.strictEqual(result.length, 0);
done();
})
.catch(err => done(err));
});
it('Should return 400 for missing params', (done: Done) => {
fetch(getbaseURL() + "/api/lockCategories", {
method: 'POST',
it("Should return 400 for missing params", (done: Done) => {
fetch(`${getbaseURL()}/api/lockCategories`, {
method: "POST",
headers: {
'Content-Type': 'application/json',
"Content-Type": "application/json",
},
body: JSON.stringify({}),
})
@@ -282,16 +282,16 @@ describe('lockCategoriesRecords', () => {
.catch(err => done(err));
});
it('Should return 400 for no categories', (done: Done) => {
it("Should return 400 for no categories", (done: Done) => {
const json: any = {
videoID: 'test',
userID: 'test',
videoID: "test",
userID: "test",
categories: [],
};
fetch(getbaseURL() + "/api/lockCategories", {
method: 'POST',
fetch(`${getbaseURL()}/api/lockCategories`, {
method: "POST",
headers: {
'Content-Type': 'application/json',
"Content-Type": "application/json",
},
body: JSON.stringify(json),
})
@@ -302,17 +302,17 @@ describe('lockCategoriesRecords', () => {
.catch(err => done(err));
});
it('Should return 400 for no userID', (done: Done) => {
it("Should return 400 for no userID", (done: Done) => {
const json: any = {
videoID: 'test',
videoID: "test",
userID: null,
categories: ['sponsor'],
categories: ["sponsor"],
};
fetch(getbaseURL() + "/api/lockCategories", {
method: 'POST',
fetch(`${getbaseURL()}/api/lockCategories`, {
method: "POST",
headers: {
'Content-Type': 'application/json',
"Content-Type": "application/json",
},
body: JSON.stringify(json),
})
@@ -323,17 +323,17 @@ describe('lockCategoriesRecords', () => {
.catch(err => done(err));
});
it('Should return 400 for no videoID', (done: Done) => {
it("Should return 400 for no videoID", (done: Done) => {
const json: any = {
videoID: null,
userID: 'test',
categories: ['sponsor'],
userID: "test",
categories: ["sponsor"],
};
fetch(getbaseURL() + "/api/lockCategories", {
method: 'POST',
fetch(`${getbaseURL()}/api/lockCategories`, {
method: "POST",
headers: {
'Content-Type': 'application/json',
"Content-Type": "application/json",
},
body: JSON.stringify(json),
})
@@ -344,17 +344,17 @@ describe('lockCategoriesRecords', () => {
.catch(err => done(err));
});
it('Should return 400 object categories', (done: Done) => {
it("Should return 400 object categories", (done: Done) => {
const json = {
videoID: 'test',
userID: 'test',
videoID: "test",
userID: "test",
categories: {},
};
fetch(getbaseURL() + "/api/lockCategories", {
method: 'POST',
fetch(`${getbaseURL()}/api/lockCategories`, {
method: "POST",
headers: {
'Content-Type': 'application/json',
"Content-Type": "application/json",
},
body: JSON.stringify(json),
})
@@ -365,17 +365,17 @@ describe('lockCategoriesRecords', () => {
.catch(err => done(err));
});
it('Should return 400 bad format categories', (done: Done) => {
it("Should return 400 bad format categories", (done: Done) => {
const json = {
videoID: 'test',
userID: 'test',
categories: 'sponsor',
videoID: "test",
userID: "test",
categories: "sponsor",
};
fetch(getbaseURL() + "/api/lockCategories", {
method: 'POST',
fetch(`${getbaseURL()}/api/lockCategories`, {
method: "POST",
headers: {
'Content-Type': 'application/json',
"Content-Type": "application/json",
},
body: JSON.stringify(json),
})
@@ -386,19 +386,19 @@ describe('lockCategoriesRecords', () => {
.catch(err => done(err));
});
it('Should return 403 if user is not VIP', (done: Done) => {
it("Should return 403 if user is not VIP", (done: Done) => {
const json = {
videoID: 'test',
userID: 'test',
videoID: "test",
userID: "test",
categories: [
'sponsor',
"sponsor",
],
};
fetch(getbaseURL() + "/api/lockCategories", {
method: 'POST',
fetch(`${getbaseURL()}/api/lockCategories`, {
method: "POST",
headers: {
'Content-Type': 'application/json',
"Content-Type": "application/json",
},
body: JSON.stringify(json),
})
@@ -409,50 +409,50 @@ describe('lockCategoriesRecords', () => {
.catch(err => done(err));
});
it('Should be able to delete a lockCategories record', (done: Done) => {
it("Should be able to delete a lockCategories record", (done: Done) => {
const json = {
videoID: 'delete-record',
userID: 'VIPUser-lockCategories',
videoID: "delete-record",
userID: "VIPUser-lockCategories",
categories: [
'sponsor',
"sponsor",
],
};
fetch(getbaseURL() + "/api/lockCategories", {
method: 'DELETE',
fetch(`${getbaseURL()}/api/lockCategories`, {
method: "DELETE",
headers: {
'Content-Type': 'application/json',
"Content-Type": "application/json",
},
body: JSON.stringify(json),
})
.then(async res => {
assert.strictEqual(res.status, 200);
const result = await db.prepare('all', 'SELECT * FROM "lockCategories" WHERE "videoID" = ?', ['delete-record']);
const result = await db.prepare("all", 'SELECT * FROM "lockCategories" WHERE "videoID" = ?', ["delete-record"]);
assert.strictEqual(result.length, 0);
done();
})
.catch(err => done(err));
});
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 = {
videoID: 'delete-record-1',
userID: 'VIPUser-lockCategories',
videoID: "delete-record-1",
userID: "VIPUser-lockCategories",
categories: [
'sponsor',
"sponsor",
],
};
fetch(getbaseURL() + "/api/lockCategories", {
method: 'DELETE',
fetch(`${getbaseURL()}/api/lockCategories`, {
method: "DELETE",
headers: {
'Content-Type': 'application/json',
"Content-Type": "application/json",
},
body: JSON.stringify(json),
})
.then(async res => {
assert.strictEqual(res.status, 200);
const result = await db.prepare('all', 'SELECT * FROM "lockCategories" WHERE "videoID" = ?', ['delete-record-1']);
const result = await db.prepare("all", 'SELECT * FROM "lockCategories" WHERE "videoID" = ?', ["delete-record-1"]);
assert.strictEqual(result.length, 1);
done();
})
@@ -465,11 +465,11 @@ describe('lockCategoriesRecords', () => {
* To test the submission code properly see ./test/cases/postSkipSegments.js
*/
it('Should not be able to submit a segment to a video with a lock-category record (single submission)', (done: Done) => {
fetch(getbaseURL() + "/api/postVideoSponsorTimes", {
method: 'POST',
it("Should not be able to submit a segment to a video with a lock-category record (single submission)", (done: Done) => {
fetch(`${getbaseURL()}/api/postVideoSponsorTimes`, {
method: "POST",
headers: {
'Content-Type': 'application/json',
"Content-Type": "application/json",
},
body: JSON.stringify({
userID: "testman42-qwertyuiopasdfghjklzxcvbnm",
@@ -487,11 +487,11 @@ describe('lockCategoriesRecords', () => {
.catch(err => done(err));
});
it('Should not be able to submit segments to a video where any of the submissions with a no-segment record', (done: Done) => {
fetch(getbaseURL() + "/api/postVideoSponsorTimes", {
method: 'POST',
it("Should not be able to submit segments to a video where any of the submissions with a no-segment record", (done: Done) => {
fetch(`${getbaseURL()}/api/postVideoSponsorTimes`, {
method: "POST",
headers: {
'Content-Type': 'application/json',
"Content-Type": "application/json",
},
body: JSON.stringify({
userID: "testman42-qwertyuiopasdfghjklzxcvbnm",
@@ -513,11 +513,11 @@ describe('lockCategoriesRecords', () => {
});
it('Should be able to submit a segment to a video with a different no-segment record', (done: Done) => {
fetch(getbaseURL() + "/api/postVideoSponsorTimes", {
method: 'POST',
it("Should be able to submit a segment to a video with a different no-segment record", (done: Done) => {
fetch(`${getbaseURL()}/api/postVideoSponsorTimes`, {
method: "POST",
headers: {
'Content-Type': 'application/json',
"Content-Type": "application/json",
},
body: JSON.stringify({
userID: "testman42-qwertyuiopasdfghjklzxcvbnm",
@@ -535,11 +535,11 @@ describe('lockCategoriesRecords', () => {
.catch(err => done(err));
});
it('Should be able to submit a segment to a video with no no-segment records', (done: Done) => {
fetch(getbaseURL() + "/api/postVideoSponsorTimes", {
method: 'POST',
it("Should be able to submit a segment to a video with no no-segment records", (done: Done) => {
fetch(`${getbaseURL()}/api/postVideoSponsorTimes`, {
method: "POST",
headers: {
'Content-Type': 'application/json',
"Content-Type": "application/json",
},
body: JSON.stringify({
userID: "testman42-qwertyuiopasdfghjklzxcvbnm",
@@ -557,17 +557,17 @@ describe('lockCategoriesRecords', () => {
.catch(err => done(err));
});
it('should be able to get existing category lock', (done: Done) => {
it("should be able to get existing category lock", (done: Done) => {
const expected = {
categories: [
'sponsor',
'intro',
'outro',
'shilling'
"sponsor",
"intro",
"outro",
"shilling"
],
};
fetch(getbaseURL() + "/api/lockCategories?videoID=" + "no-segments-video-id")
fetch(`${getbaseURL()}/api/lockCategories?videoID=` + `no-segments-video-id`)
.then(async res => {
assert.strictEqual(res.status, 200);
const data = await res.json();

View File

@@ -1,18 +1,18 @@
import fetch from 'node-fetch';
import {db} from '../../src/databases/databases';
import {Done, getbaseURL} from '../utils';
import {getHash} from '../../src/utils/getHash';
import assert from 'assert';
import fetch from "node-fetch";
import {db} from "../../src/databases/databases";
import {Done, getbaseURL} from "../utils";
import {getHash} from "../../src/utils/getHash";
import assert from "assert";
describe('getVideoSponsorTime (Old get method)', () => {
describe("getVideoSponsorTime (Old get method)", () => {
before(async () => {
const insertSponsorTimes = 'INSERT INTO "sponsorTimes" ("videoID", "startTime", "endTime", "votes", "UUID", "userID", "timeSubmitted", views, category, "shadowHidden", "hashedVideoID") 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, ['old-testtesttest,test', 1, 11, 2, 'uuid-1', 'testman', 0, 50, 'sponsor', 0, getHash('old-testtesttest,test', 1)]);
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, ["old-testtesttest,test", 1, 11, 2, "uuid-1", "testman", 0, 50, "sponsor", 0, getHash("old-testtesttest,test", 1)]);
});
it('Should be able to get a time', (done: Done) => {
fetch(getbaseURL() + "/api/getVideoSponsorTimes?videoID=old-testtesttest")
it("Should be able to get a time", (done: Done) => {
fetch(`${getbaseURL()}/api/getVideoSponsorTimes?videoID=old-testtesttest`)
.then(res => {
assert.strictEqual(res.status, 200);
done();
@@ -20,8 +20,8 @@ describe('getVideoSponsorTime (Old get method)', () => {
.catch(err => done(err));
});
it('Should return 404 if no segment found', (done: Done) => {
fetch(getbaseURL() + "/api/getVideoSponsorTimes?videoID=notarealvideo")
it("Should return 404 if no segment found", (done: Done) => {
fetch(`${getbaseURL()}/api/getVideoSponsorTimes?videoID=notarealvideo`)
.then(res => {
assert.strictEqual(res.status, 404);
done();
@@ -30,8 +30,8 @@ describe('getVideoSponsorTime (Old get method)', () => {
});
it('Should be possible to send unexpected query parameters', (done: Done) => {
fetch(getbaseURL() + "/api/getVideoSponsorTimes?videoID=old-testtesttest&fakeparam=hello")
it("Should be possible to send unexpected query parameters", (done: Done) => {
fetch(`${getbaseURL()}/api/getVideoSponsorTimes?videoID=old-testtesttest&fakeparam=hello`)
.then(res => {
assert.strictEqual(res.status, 200);
done();
@@ -39,8 +39,8 @@ describe('getVideoSponsorTime (Old get method)', () => {
.catch(() => done("couldn't callendpoint"));
});
it('Should be able send a comma in a query param', (done: Done) => {
fetch(getbaseURL() + "/api/getVideoSponsorTimes?videoID=old-testtesttest,test")
it("Should be able send a comma in a query param", (done: Done) => {
fetch(`${getbaseURL()}/api/getVideoSponsorTimes?videoID=old-testtesttest,test`)
.then(async res => {
assert.strictEqual(res.status, 200);
const data = await res.json();
@@ -50,14 +50,14 @@ describe('getVideoSponsorTime (Old get method)', () => {
.catch(err => done(err));
});
it('Should be able to get the correct time', (done: Done) => {
fetch(getbaseURL() + "/api/getVideoSponsorTimes?videoID=old-testtesttest")
it("Should be able to get the correct time", (done: Done) => {
fetch(`${getbaseURL()}/api/getVideoSponsorTimes?videoID=old-testtesttest`)
.then(async res => {
assert.strictEqual(res.status, 200);
const data = await res.json();
assert.strictEqual(data.sponsorTimes[0][0], 1);
assert.strictEqual(data.sponsorTimes[0][1], 11);
assert.strictEqual(data.UUIDs[0], 'uuid-0');
assert.strictEqual(data.UUIDs[0], "uuid-0");
done();
})
.catch(err => done(err));

View File

@@ -1,15 +1,15 @@
import fetch from 'node-fetch';
import {Done, getbaseURL} from '../utils';
import {db} from '../../src/databases/databases';
import assert from 'assert';
import fetch from "node-fetch";
import {Done, getbaseURL} from "../utils";
import {db} from "../../src/databases/databases";
import assert from "assert";
describe('postVideoSponsorTime (Old submission method)', () => {
it('Should be able to submit a time (GET)', (done: Done) => {
fetch(getbaseURL()
+ "/api/postVideoSponsorTimes?videoID=dQw4w9WgXcQ&startTime=1&endTime=10&userID=testtesttesttesttesttesttesttesttest")
describe("postVideoSponsorTime (Old submission method)", () => {
it("Should be able to submit a time (GET)", (done: Done) => {
fetch(`${getbaseURL()
}/api/postVideoSponsorTimes?videoID=dQw4w9WgXcQ&startTime=1&endTime=10&userID=testtesttesttesttesttesttesttesttest`)
.then(async res => {
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" = ?`, ["dQw4w9WgXcQ"]);
assert.strictEqual(row.startTime, 1);
assert.strictEqual(row.endTime, 10);
assert.strictEqual(row.category, "sponsor");
@@ -18,17 +18,17 @@ describe('postVideoSponsorTime (Old submission method)', () => {
.catch(err => done(err));
});
it('Should be able to submit a time (POST)', (done: Done) => {
fetch(getbaseURL()
+ "/api/postVideoSponsorTimes?videoID=dQw4w9WgXcE&startTime=1&endTime=11&userID=testtesttesttesttesttesttesttesttest", {
method: 'POST',
it("Should be able to submit a time (POST)", (done: Done) => {
fetch(`${getbaseURL()
}/api/postVideoSponsorTimes?videoID=dQw4w9WgXcE&startTime=1&endTime=11&userID=testtesttesttesttesttesttesttesttest`, {
method: "POST",
headers: {
'Content-Type': 'application/json',
"Content-Type": "application/json",
},
})
.then(async res => {
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" = ?`, ["dQw4w9WgXcE"]);
assert.strictEqual(row.startTime, 1);
assert.strictEqual(row.endTime, 11);
assert.strictEqual(row.category, "sponsor");
@@ -37,9 +37,9 @@ describe('postVideoSponsorTime (Old submission method)', () => {
.catch(err => done(err));
});
it('Should return 400 for missing params', (done: Done) => {
fetch(getbaseURL()
+ "/api/postVideoSponsorTimes?startTime=1&endTime=10&userID=testtesttesttesttesttesttesttesttest")
it("Should return 400 for missing params", (done: Done) => {
fetch(`${getbaseURL()
}/api/postVideoSponsorTimes?startTime=1&endTime=10&userID=testtesttesttesttesttesttesttesttest`)
.then(async res => {
assert.strictEqual(res.status, 400);
done();

View File

@@ -1,20 +1,20 @@
import fetch from 'node-fetch';
import {Done, getbaseURL} from '../utils';
import {db} from '../../src/databases/databases';
import {getHash} from '../../src/utils/getHash';
import assert from 'assert';
import fetch from "node-fetch";
import {Done, getbaseURL} from "../utils";
import {db} from "../../src/databases/databases";
import {getHash} from "../../src/utils/getHash";
import assert from "assert";
describe('postClearCache', () => {
describe("postClearCache", () => {
before(async () => {
await db.prepare("run", `INSERT INTO "vipUsers" ("userID") VALUES ('` + getHash("clearing-vip") + "')");
await db.prepare("run", `INSERT INTO "vipUsers" ("userID") VALUES ('${getHash("clearing-vip")}')`);
const startOfQuery = 'INSERT INTO "sponsorTimes" ("videoID", "startTime", "endTime", "votes", "UUID", "userID", "timeSubmitted", views, category, "shadowHidden", "hashedVideoID") 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, '" + getHash("clear-test", 1) + "')`);
});
it('Should be able to clear cache for existing video', (done: Done) => {
fetch(getbaseURL()
+ "/api/clearCache?userID=clearing-vip&videoID=clear-test", {
method: 'POST'
it("Should be able to clear cache for existing video", (done: Done) => {
fetch(`${getbaseURL()
}/api/clearCache?userID=clearing-vip&videoID=clear-test`, {
method: "POST"
})
.then(res => {
assert.strictEqual(res.status, 200);
@@ -23,10 +23,10 @@ describe('postClearCache', () => {
.catch(err => done(err));
});
it('Should be able to clear cache for nonexistent video', (done: Done) => {
fetch(getbaseURL()
+ "/api/clearCache?userID=clearing-vip&videoID=dne-video", {
method: 'POST'
it("Should be able to clear cache for nonexistent video", (done: Done) => {
fetch(`${getbaseURL()
}/api/clearCache?userID=clearing-vip&videoID=dne-video`, {
method: "POST"
})
.then(res => {
assert.strictEqual(res.status, 200);
@@ -35,10 +35,10 @@ describe('postClearCache', () => {
.catch(err => done(err));
});
it('Should get 403 as non-vip', (done: Done) => {
fetch(getbaseURL()
+ "/api/clearCache?userID=regular-user&videoID=clear-tes", {
method: 'POST'
it("Should get 403 as non-vip", (done: Done) => {
fetch(`${getbaseURL()
}/api/clearCache?userID=regular-user&videoID=clear-tes`, {
method: "POST"
})
.then(async res => {
assert.strictEqual(res.status, 403);
@@ -47,10 +47,10 @@ describe('postClearCache', () => {
.catch(err => done(err));
});
it('Should give 400 with missing videoID', (done: Done) => {
fetch(getbaseURL()
+ "/api/clearCache?userID=clearing-vip", {
method: 'POST'
it("Should give 400 with missing videoID", (done: Done) => {
fetch(`${getbaseURL()
}/api/clearCache?userID=clearing-vip`, {
method: "POST"
})
.then(async res => {
assert.strictEqual(res.status, 400);
@@ -59,10 +59,10 @@ describe('postClearCache', () => {
.catch(err => done(err));
});
it('Should give 400 with missing userID', (done: Done) => {
fetch(getbaseURL()
+ "/api/clearCache?userID=clearing-vip", {
method: 'POST'
it("Should give 400 with missing userID", (done: Done) => {
fetch(`${getbaseURL()
}/api/clearCache?userID=clearing-vip`, {
method: "POST"
})
.then(async res => {
assert.strictEqual(res.status, 400);

View File

@@ -1,9 +1,9 @@
import fetch from 'node-fetch';
import {Done, getbaseURL} from '../utils';
import {db} from '../../src/databases/databases';
import {getHash} from '../../src/utils/getHash';
import {IDatabase} from '../../src/databases/IDatabase';
import assert from 'assert';
import fetch from "node-fetch";
import {Done, getbaseURL} from "../utils";
import {db} from "../../src/databases/databases";
import {getHash} from "../../src/utils/getHash";
import {IDatabase} from "../../src/databases/IDatabase";
import assert from "assert";
async function dbSponsorTimesAdd(db: IDatabase, videoID: string, startTime: number, endTime: number, UUID: string, category: string) {
const votes = 0,
@@ -21,7 +21,7 @@ async function dbSponsorTimesAdd(db: IDatabase, videoID: string, startTime: numb
}
async function dbSponsorTimesCompareExpect(db: IDatabase, videoId: string, expectdHidden: number) {
const seg = await db.prepare('get', `SELECT "hidden", "UUID" FROM "sponsorTimes" WHERE "videoID" = ?`, [videoId]);
const seg = await db.prepare("get", `SELECT "hidden", "UUID" FROM "sponsorTimes" WHERE "videoID" = ?`, [videoId]);
for (let i = 0, len = seg.length; i < len; i++) {
if (seg.hidden !== expectdHidden) {
return `${seg.UUID} hidden expected to be ${expectdHidden} but found ${seg.hidden}`;
@@ -30,31 +30,31 @@ async function dbSponsorTimesCompareExpect(db: IDatabase, videoId: string, expec
return;
}
describe('postPurgeAllSegments', function () {
const privateVipUserID = 'VIPUser-purgeAll';
const route = '/api/purgeAllSegments';
describe("postPurgeAllSegments", function () {
const privateVipUserID = "VIPUser-purgeAll";
const route = "/api/purgeAllSegments";
const vipUserID = getHash(privateVipUserID);
const baseURL = getbaseURL();
before(async function () {
// startTime and endTime get set in beforeEach for consistency
await dbSponsorTimesAdd(db, 'vsegpurge01', 0, 1, 'vsegpurgetest01uuid01', 'intro');
await dbSponsorTimesAdd(db, 'vsegpurge01', 0, 2, 'vsegpurgetest01uuid02', 'sponsor');
await dbSponsorTimesAdd(db, 'vsegpurge01', 0, 3, 'vsegpurgetest01uuid03', 'interaction');
await dbSponsorTimesAdd(db, 'vsegpurge01', 0, 4, 'vsegpurgetest01uuid04', 'outro');
await dbSponsorTimesAdd(db, 'vseg-not-purged01', 0, 5, 'vsegpurgetest01uuid05', 'outro');
await dbSponsorTimesAdd(db, "vsegpurge01", 0, 1, "vsegpurgetest01uuid01", "intro");
await dbSponsorTimesAdd(db, "vsegpurge01", 0, 2, "vsegpurgetest01uuid02", "sponsor");
await dbSponsorTimesAdd(db, "vsegpurge01", 0, 3, "vsegpurgetest01uuid03", "interaction");
await dbSponsorTimesAdd(db, "vsegpurge01", 0, 4, "vsegpurgetest01uuid04", "outro");
await dbSponsorTimesAdd(db, "vseg-not-purged01", 0, 5, "vsegpurgetest01uuid05", "outro");
await db.prepare("run", `INSERT INTO "vipUsers" ("userID") VALUES (?)`, [vipUserID]);
});
it('Reject non-VIP user', function (done: Done) {
it("Reject non-VIP user", function (done: Done) {
fetch(`${baseURL}${route}`, {
method: 'POST',
method: "POST",
headers: {
'Content-Type': 'application/json',
"Content-Type": "application/json",
},
body: JSON.stringify({
videoID: 'vsegpurge01',
userID: 'segshift_randomuser001',
videoID: "vsegpurge01",
userID: "segshift_randomuser001",
}),
})
.then(async res => {
@@ -64,20 +64,20 @@ describe('postPurgeAllSegments', function () {
.catch(err => done(err));
});
it('Purge all segments success', function (done: Done) {
it("Purge all segments success", function (done: Done) {
fetch(`${baseURL}${route}`, {
method: 'POST',
method: "POST",
headers: {
'Content-Type': 'application/json',
"Content-Type": "application/json",
},
body: JSON.stringify({
videoID: 'vsegpurge01',
videoID: "vsegpurge01",
userID: privateVipUserID,
}),
})
.then(async res => {
assert.strictEqual(res.status, 200);
done(await dbSponsorTimesCompareExpect(db, 'vsegpurge01', 1) || await dbSponsorTimesCompareExpect(db, 'vseg-not-purged01', 0));
done(await dbSponsorTimesCompareExpect(db, "vsegpurge01", 1) || await dbSponsorTimesCompareExpect(db, "vseg-not-purged01", 0));
})
.catch(err => done(err));
});

View File

@@ -1,23 +1,23 @@
import fetch from 'node-fetch';
import {config} from '../../src/config';
import {getHash} from '../../src/utils/getHash';
import {Done, getbaseURL} from '../utils';
import {db} from '../../src/databases/databases';
import {ImportMock} from 'ts-mock-imports';
import * as YouTubeAPIModule from '../../src/utils/youtubeApi';
import {YouTubeApiMock} from '../youtubeMock';
import assert from 'assert';
import fetch from "node-fetch";
import {config} from "../../src/config";
import {getHash} from "../../src/utils/getHash";
import {Done, getbaseURL} from "../utils";
import {db} from "../../src/databases/databases";
import {ImportMock} from "ts-mock-imports";
import * as YouTubeAPIModule from "../../src/utils/youtubeApi";
import {YouTubeApiMock} from "../youtubeMock";
import assert from "assert";
const mockManager = ImportMock.mockStaticClass(YouTubeAPIModule, 'YouTubeAPI');
const sinonStub = mockManager.mock('listVideos');
const mockManager = ImportMock.mockStaticClass(YouTubeAPIModule, "YouTubeAPI");
const sinonStub = mockManager.mock("listVideos");
sinonStub.callsFake(YouTubeApiMock.listVideos);
describe('postSkipSegments', () => {
describe("postSkipSegments", () => {
before(() => {
const insertSponsorTimeQuery = 'INSERT INTO "sponsorTimes" ("videoID", "startTime", "endTime", "votes", "UUID", "userID", "timeSubmitted", views, category, "shadowHidden", "hashedVideoID") VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)';
db.prepare("run", insertSponsorTimeQuery, ['80percent_video', 0, 1000, 0, '80percent-uuid-0', getHash("testtesttesttesttesttesttesttesttest"), 0, 0, 'interaction', 0, '80percent_video']);
db.prepare("run", insertSponsorTimeQuery, ['80percent_video', 1001, 1005, 0, '80percent-uuid-1', getHash("testtesttesttesttesttesttesttesttest"), 0, 0, 'interaction', 0, '80percent_video']);
db.prepare("run", insertSponsorTimeQuery, ['80percent_video', 0, 5000, -2, '80percent-uuid-2', getHash("testtesttesttesttesttesttesttesttest"), 0, 0, 'interaction', 0, '80percent_video']);
db.prepare("run", insertSponsorTimeQuery, ["80percent_video", 0, 1000, 0, "80percent-uuid-0", getHash("testtesttesttesttesttesttesttesttest"), 0, 0, "interaction", 0, "80percent_video"]);
db.prepare("run", insertSponsorTimeQuery, ["80percent_video", 1001, 1005, 0, "80percent-uuid-1", getHash("testtesttesttesttesttesttesttesttest"), 0, 0, "interaction", 0, "80percent_video"]);
db.prepare("run", insertSponsorTimeQuery, ["80percent_video", 0, 5000, -2, "80percent-uuid-2", getHash("testtesttesttesttesttesttesttesttest"), 0, 0, "interaction", 0, "80percent_video"]);
const now = Date.now();
const warnVip01Hash = getHash("warn-vip01-qwertyuiopasdfghjklzxcvbnm");
@@ -25,10 +25,10 @@ describe('postSkipSegments', () => {
const warnUser02Hash = getHash("warn-user02-qwertyuiopasdfghjklzxcvbnm");
const warnUser03Hash = getHash("warn-user03-qwertyuiopasdfghjklzxcvbnm");
const warnUser04Hash = getHash("warn-user04-qwertyuiopasdfghjklzxcvbnm");
const reason01 = 'Reason01';
const reason02 = '';
const reason03 = 'Reason03';
const reason04 = '';
const reason01 = "Reason01";
const reason02 = "";
const reason03 = "Reason03";
const reason04 = "";
const MILLISECONDS_IN_HOUR = 3600000;
const warningExpireTime = MILLISECONDS_IN_HOUR * config.hoursAfterWarningExpires;
@@ -54,17 +54,17 @@ describe('postSkipSegments', () => {
db.prepare("run", insertVipUserQuery, [getHash("VIPUserSubmissionVIPUserSubmissionVIPUserSubmission")]);
});
it('Should be able to submit a single time (Params method)', (done: Done) => {
fetch(getbaseURL()
+ "/api/postVideoSponsorTimes?videoID=dQw4w9WgXcR&startTime=2&endTime=10&userID=testtesttesttesttesttesttesttesttest&category=sponsor", {
method: 'POST',
it("Should be able to submit a single time (Params method)", (done: Done) => {
fetch(`${getbaseURL()
}/api/postVideoSponsorTimes?videoID=dQw4w9WgXcR&startTime=2&endTime=10&userID=testtesttesttesttesttesttesttesttest&category=sponsor`, {
method: "POST",
headers: {
'Content-Type': 'application/json',
"Content-Type": "application/json",
},
})
.then(async res => {
assert.strictEqual(res.status, 200);
const row = await db.prepare('get', `SELECT "startTime", "endTime", "category" FROM "sponsorTimes" WHERE "videoID" = ?`, ["dQw4w9WgXcR"]);
const row = await db.prepare("get", `SELECT "startTime", "endTime", "category" FROM "sponsorTimes" WHERE "videoID" = ?`, ["dQw4w9WgXcR"]);
assert.strictEqual(row.startTime, 2);
assert.strictEqual(row.endTime, 10);
assert.strictEqual(row.category, "sponsor");
@@ -73,12 +73,11 @@ describe('postSkipSegments', () => {
.catch(err => done(err));
});
it('Should be able to submit a single time (JSON method)', (done: Done) => {
fetch(getbaseURL()
+ "/api/postVideoSponsorTimes", {
method: 'POST',
it("Should be able to submit a single time (JSON method)", (done: Done) => {
fetch(`${getbaseURL()}/api/postVideoSponsorTimes`, {
method: "POST",
headers: {
'Content-Type': 'application/json',
"Content-Type": "application/json",
},
body: JSON.stringify({
userID: "testtesttesttesttesttesttesttesttest",
@@ -91,7 +90,7 @@ describe('postSkipSegments', () => {
})
.then(async res => {
assert.strictEqual(res.status, 200);
const row = await db.prepare('get', `SELECT "startTime", "endTime", "locked", "category" FROM "sponsorTimes" WHERE "videoID" = ?`, ["dQw4w9WgXcF"]);
const row = await db.prepare("get", `SELECT "startTime", "endTime", "locked", "category" FROM "sponsorTimes" WHERE "videoID" = ?`, ["dQw4w9WgXcF"]);
assert.strictEqual(row.startTime, 0);
assert.strictEqual(row.endTime, 10);
assert.strictEqual(row.locked, 0);
@@ -101,12 +100,11 @@ describe('postSkipSegments', () => {
.catch(err => done(err));
});
it('Should be able to submit a single time with an action type (JSON method)', (done: Done) => {
fetch(getbaseURL()
+ "/api/postVideoSponsorTimes", {
method: 'POST',
it("Should be able to submit a single time with an action type (JSON method)", (done: Done) => {
fetch(`${getbaseURL()}/api/postVideoSponsorTimes`, {
method: "POST",
headers: {
'Content-Type': 'application/json',
"Content-Type": "application/json",
},
body: JSON.stringify({
userID: "testtesttesttesttesttesttesttesttest",
@@ -120,7 +118,7 @@ describe('postSkipSegments', () => {
})
.then(async res => {
assert.strictEqual(res.status, 200);
const row = await db.prepare('get', `SELECT "startTime", "endTime", "locked", "category", "actionType" FROM "sponsorTimes" WHERE "videoID" = ?`, ["dQw4w9WgXcV"]);
const row = await db.prepare("get", `SELECT "startTime", "endTime", "locked", "category", "actionType" FROM "sponsorTimes" WHERE "videoID" = ?`, ["dQw4w9WgXcV"]);
assert.strictEqual(row.startTime, 0);
assert.strictEqual(row.endTime, 10);
assert.strictEqual(row.locked, 0);
@@ -131,12 +129,11 @@ describe('postSkipSegments', () => {
.catch(err => done(err));
});
it('Should be able to submit a single time with a duration from the YouTube API (JSON method)', (done: Done) => {
fetch(getbaseURL()
+ "/api/postVideoSponsorTimes", {
method: 'POST',
it("Should be able to submit a single time with a duration from the YouTube API (JSON method)", (done: Done) => {
fetch(`${getbaseURL()}/api/postVideoSponsorTimes`, {
method: "POST",
headers: {
'Content-Type': 'application/json',
"Content-Type": "application/json",
},
body: JSON.stringify({
userID: "testtesttesttesttesttesttesttesttest",
@@ -150,7 +147,7 @@ describe('postSkipSegments', () => {
})
.then(async res => {
assert.strictEqual(res.status, 200);
const row = await db.prepare('get', `SELECT "startTime", "endTime", "locked", "category", "videoDuration" FROM "sponsorTimes" WHERE "videoID" = ?`, ["dQw4w9WgXZX"]);
const row = await db.prepare("get", `SELECT "startTime", "endTime", "locked", "category", "videoDuration" FROM "sponsorTimes" WHERE "videoID" = ?`, ["dQw4w9WgXZX"]);
assert.strictEqual(row.startTime, 0);
assert.strictEqual(row.endTime, 10);
assert.strictEqual(row.locked, 0);
@@ -161,12 +158,11 @@ describe('postSkipSegments', () => {
.catch(err => done(err));
});
it('Should be able to submit a single time with a precise duration close to the one from the YouTube API (JSON method)', (done: Done) => {
fetch(getbaseURL()
+ "/api/postVideoSponsorTimes", {
method: 'POST',
it("Should be able to submit a single time with a precise duration close to the one from the YouTube API (JSON method)", (done: Done) => {
fetch(`${getbaseURL()}/api/postVideoSponsorTimes`, {
method: "POST",
headers: {
'Content-Type': 'application/json',
"Content-Type": "application/json",
},
body: JSON.stringify({
userID: "testtesttesttesttesttesttesttesttest",
@@ -180,7 +176,7 @@ describe('postSkipSegments', () => {
})
.then(async res => {
assert.strictEqual(res.status, 200);
const row = await db.prepare('get', `SELECT "startTime", "endTime", "locked", "category", "videoDuration" FROM "sponsorTimes" WHERE "videoID" = ?`, ["dQw4w9WgXZH"]);
const row = await db.prepare("get", `SELECT "startTime", "endTime", "locked", "category", "videoDuration" FROM "sponsorTimes" WHERE "videoID" = ?`, ["dQw4w9WgXZH"]);
assert.strictEqual(row.startTime, 1);
assert.strictEqual(row.endTime, 10);
assert.strictEqual(row.locked, 0);
@@ -191,12 +187,11 @@ describe('postSkipSegments', () => {
.catch(err => done(err));
});
it('Should be able to submit a single time with a duration in the body (JSON method)', (done: Done) => {
fetch(getbaseURL()
+ "/api/postVideoSponsorTimes", {
method: 'POST',
it("Should be able to submit a single time with a duration in the body (JSON method)", (done: Done) => {
fetch(`${getbaseURL()}/api/postVideoSponsorTimes`, {
method: "POST",
headers: {
'Content-Type': 'application/json',
"Content-Type": "application/json",
},
body: JSON.stringify({
userID: "testtesttesttesttesttesttesttesttest",
@@ -210,7 +205,7 @@ describe('postSkipSegments', () => {
})
.then(async res => {
assert.strictEqual(res.status, 200);
const row = await db.prepare('get', `SELECT "startTime", "endTime", "locked", "category", "videoDuration" FROM "sponsorTimes" WHERE "videoID" = ?`, ["noDuration"]);
const row = await db.prepare("get", `SELECT "startTime", "endTime", "locked", "category", "videoDuration" FROM "sponsorTimes" WHERE "videoID" = ?`, ["noDuration"]);
assert.strictEqual(row.startTime, 0);
assert.strictEqual(row.endTime, 10);
assert.strictEqual(row.locked, 0);
@@ -221,16 +216,15 @@ describe('postSkipSegments', () => {
.catch(err => done(err));
});
it('Should be able to submit with a new duration, and hide old submissions and remove segment locks', async () => {
it("Should be able to submit with a new duration, and hide old submissions and remove segment locks", async () => {
await db.prepare("run", `INSERT INTO "lockCategories" ("userID", "videoID", "category")
VALUES(?, ?, ?)`, [getHash("VIPUser-lockCategories"), 'noDuration', 'sponsor']);
VALUES(?, ?, ?)`, [getHash("VIPUser-lockCategories"), "noDuration", "sponsor"]);
try {
const res = await fetch(getbaseURL()
+ "/api/postVideoSponsorTimes", {
method: 'POST',
const res = await fetch(`${getbaseURL()}/api/postVideoSponsorTimes`, {
method: "POST",
headers: {
'Content-Type': 'application/json',
"Content-Type": "application/json",
},
body: JSON.stringify({
userID: "testtesttesttesttesttesttesttesttest",
@@ -243,11 +237,11 @@ describe('postSkipSegments', () => {
}),
});
assert.strictEqual(res.status, 200);
const lockCategoriesRow = await db.prepare('get', `SELECT * from "lockCategories" WHERE videoID = ?`, ["noDuration"]);
const videoRows = await db.prepare('all', `SELECT "startTime", "endTime", "locked", "category", "videoDuration"
const lockCategoriesRow = await db.prepare("get", `SELECT * from "lockCategories" WHERE videoID = ?`, ["noDuration"]);
const videoRows = await db.prepare("all", `SELECT "startTime", "endTime", "locked", "category", "videoDuration"
FROM "sponsorTimes" WHERE "videoID" = ? AND hidden = 0`, ["noDuration"]);
const videoRow = videoRows[0];
const hiddenVideoRows = await db.prepare('all', `SELECT "startTime", "endTime", "locked", "category", "videoDuration"
const hiddenVideoRows = await db.prepare("all", `SELECT "startTime", "endTime", "locked", "category", "videoDuration"
FROM "sponsorTimes" WHERE "videoID" = ? AND hidden = 1`, ["noDuration"]);
assert.ok(!lockCategoriesRow);
assert.strictEqual(videoRows.length, 1);
@@ -262,10 +256,10 @@ describe('postSkipSegments', () => {
}
});
it('Should still not be allowed if youtube thinks duration is 0', (done: Done) => {
fetch(getbaseURL()
+ "/api/postVideoSponsorTimes?videoID=noDuration&startTime=30&endTime=10000&userID=testtesttesttesttesttesttesttesttesting", {
method: 'POST',
it("Should still not be allowed if youtube thinks duration is 0", (done: Done) => {
fetch(`${getbaseURL()
}/api/postVideoSponsorTimes?videoID=noDuration&startTime=30&endTime=10000&userID=testtesttesttesttesttesttesttesttesting`, {
method: "POST",
})
.then(async res => {
assert.strictEqual(res.status, 403);
@@ -274,12 +268,11 @@ describe('postSkipSegments', () => {
.catch(err => done(err));
});
it('Should be able to submit a single time under a different service (JSON method)', (done: Done) => {
fetch(getbaseURL()
+ "/api/postVideoSponsorTimes", {
method: 'POST',
it("Should be able to submit a single time under a different service (JSON method)", (done: Done) => {
fetch(`${getbaseURL()}/api/postVideoSponsorTimes`, {
method: "POST",
headers: {
'Content-Type': 'application/json',
"Content-Type": "application/json",
},
body: JSON.stringify({
userID: "testtesttesttesttesttesttesttesttest",
@@ -293,7 +286,7 @@ describe('postSkipSegments', () => {
})
.then(async res => {
assert.strictEqual(res.status, 200);
const row = await db.prepare('get', `SELECT "startTime", "endTime", "locked", "category", "service" FROM "sponsorTimes" WHERE "videoID" = ?`, ["dQw4w9WgXcG"]);
const row = await db.prepare("get", `SELECT "startTime", "endTime", "locked", "category", "service" FROM "sponsorTimes" WHERE "videoID" = ?`, ["dQw4w9WgXcG"]);
assert.strictEqual(row.startTime, 0);
assert.strictEqual(row.endTime, 10);
assert.strictEqual(row.locked, 0);
@@ -304,12 +297,11 @@ describe('postSkipSegments', () => {
.catch(err => done(err));
});
it('VIP submission should start locked', (done: Done) => {
fetch(getbaseURL()
+ "/api/postVideoSponsorTimes", {
method: 'POST',
it("VIP submission should start locked", (done: Done) => {
fetch(`${getbaseURL()}/api/postVideoSponsorTimes`, {
method: "POST",
headers: {
'Content-Type': 'application/json',
"Content-Type": "application/json",
},
body: JSON.stringify({
userID: "VIPUserSubmissionVIPUserSubmissionVIPUserSubmission",
@@ -322,7 +314,7 @@ describe('postSkipSegments', () => {
})
.then(async res => {
assert.strictEqual(res.status, 200);
const row = await db.prepare('get', `SELECT "startTime", "endTime", "locked", "category" FROM "sponsorTimes" WHERE "videoID" = ?`, ["vipuserIDSubmission"]);
const row = await db.prepare("get", `SELECT "startTime", "endTime", "locked", "category" FROM "sponsorTimes" WHERE "videoID" = ?`, ["vipuserIDSubmission"]);
assert.strictEqual(row.startTime, 0);
assert.strictEqual(row.endTime, 10);
assert.strictEqual(row.locked, 1);
@@ -332,12 +324,11 @@ describe('postSkipSegments', () => {
.catch(err => done(err));
});
it('Should be able to submit multiple times (JSON method)', (done: Done) => {
fetch(getbaseURL()
+ "/api/postVideoSponsorTimes", {
method: 'POST',
it("Should be able to submit multiple times (JSON method)", (done: Done) => {
fetch(`${getbaseURL()}/api/postVideoSponsorTimes`, {
method: "POST",
headers: {
'Content-Type': 'application/json',
"Content-Type": "application/json",
},
body: JSON.stringify({
userID: "testtesttesttesttesttesttesttesttest",
@@ -353,7 +344,7 @@ describe('postSkipSegments', () => {
})
.then(async res => {
assert.strictEqual(res.status, 200);
const rows = await db.prepare('all', `SELECT "startTime", "endTime", "category" FROM "sponsorTimes" WHERE "videoID" = ?`, ["dQw4w9WgXcT"]);
const rows = await db.prepare("all", `SELECT "startTime", "endTime", "category" FROM "sponsorTimes" WHERE "videoID" = ?`, ["dQw4w9WgXcT"]);
const expected = [{
startTime: 3,
endTime: 10,
@@ -369,12 +360,11 @@ describe('postSkipSegments', () => {
.catch(err => done(err));
}).timeout(5000);
it('Should allow multiple times if total is under 80% of video(JSON method)', (done: Done) => {
fetch(getbaseURL()
+ "/api/postVideoSponsorTimes", {
method: 'POST',
it("Should allow multiple times if total is under 80% of video(JSON method)", (done: Done) => {
fetch(`${getbaseURL()}/api/postVideoSponsorTimes`, {
method: "POST",
headers: {
'Content-Type': 'application/json',
"Content-Type": "application/json",
},
body: JSON.stringify({
userID: "testtesttesttesttesttesttesttesttest",
@@ -396,7 +386,7 @@ describe('postSkipSegments', () => {
})
.then(async res => {
assert.strictEqual(res.status, 200);
const rows = await db.prepare('all', `SELECT "startTime", "endTime", "category" FROM "sponsorTimes" WHERE "videoID" = ? and "votes" > -1`, ["L_jWHffIx5E"]);
const rows = await db.prepare("all", `SELECT "startTime", "endTime", "category" FROM "sponsorTimes" WHERE "videoID" = ? and "votes" > -1`, ["L_jWHffIx5E"]);
const expected = [{
startTime: 3,
endTime: 3000,
@@ -420,12 +410,11 @@ describe('postSkipSegments', () => {
.catch(err => done(err));
}).timeout(5000);
it('Should reject multiple times if total is over 80% of video (JSON method)', (done: Done) => {
fetch(getbaseURL()
+ "/api/postVideoSponsorTimes", {
method: 'POST',
it("Should reject multiple times if total is over 80% of video (JSON method)", (done: Done) => {
fetch(`${getbaseURL()}/api/postVideoSponsorTimes`, {
method: "POST",
headers: {
'Content-Type': 'application/json',
"Content-Type": "application/json",
},
body: JSON.stringify({
userID: "testtesttesttesttesttesttesttesttest",
@@ -447,19 +436,18 @@ describe('postSkipSegments', () => {
})
.then(async res => {
assert.strictEqual(res.status, 403);
const rows = await db.prepare('all', `SELECT "startTime", "endTime", "category" FROM "sponsorTimes" WHERE "videoID" = ? and "votes" > -1`, ["n9rIGdXnSJc"]);
const rows = await db.prepare("all", `SELECT "startTime", "endTime", "category" FROM "sponsorTimes" WHERE "videoID" = ? and "votes" > -1`, ["n9rIGdXnSJc"]);
assert.deepStrictEqual(rows, []);
done();
})
.catch(err => done(err));
}).timeout(5000);
it('Should reject multiple times if total is over 80% of video including previosuly submitted times(JSON method)', (done: Done) => {
fetch(getbaseURL()
+ "/api/postVideoSponsorTimes", {
method: 'POST',
it("Should reject multiple times if total is over 80% of video including previosuly submitted times(JSON method)", (done: Done) => {
fetch(`${getbaseURL()}/api/postVideoSponsorTimes`, {
method: "POST",
headers: {
'Content-Type': 'application/json',
"Content-Type": "application/json",
},
body: JSON.stringify({
userID: "testtesttesttesttesttesttesttesttest",
@@ -491,17 +479,17 @@ describe('postSkipSegments', () => {
startTime: 4050,
endTime: 4750
}];
const rows = await db.prepare('all', `SELECT "startTime", "endTime", "category" FROM "sponsorTimes" WHERE "videoID" = ? and "votes" > -1`, ["80percent_video"]);
const rows = await db.prepare("all", `SELECT "startTime", "endTime", "category" FROM "sponsorTimes" WHERE "videoID" = ? and "votes" > -1`, ["80percent_video"]);
assert.notDeepStrictEqual(rows, expected);
done();
})
.catch(err => done(err));
}).timeout(5000);
it('Should be accepted if a non-sponsor is less than 1 second', (done: Done) => {
fetch(getbaseURL()
+ "/api/skipSegments?videoID=qqwerty&startTime=30&endTime=30.5&userID=testtesttesttesttesttesttesttesttesting&category=intro", {
method: 'POST',
it("Should be accepted if a non-sponsor is less than 1 second", (done: Done) => {
fetch(`${getbaseURL()
}/api/skipSegments?videoID=qqwerty&startTime=30&endTime=30.5&userID=testtesttesttesttesttesttesttesttesting&category=intro`, {
method: "POST",
})
.then(res => {
assert.strictEqual(res.status, 200);
@@ -510,10 +498,10 @@ describe('postSkipSegments', () => {
.catch(err => done(err));
});
it('Should be rejected if segment starts and ends at the same time', (done: Done) => {
fetch(getbaseURL()
+ "/api/skipSegments?videoID=qqwerty&startTime=90&endTime=90&userID=testtesttesttesttesttesttesttesttesting&category=intro", {
method: 'POST',
it("Should be rejected if segment starts and ends at the same time", (done: Done) => {
fetch(`${getbaseURL()
}/api/skipSegments?videoID=qqwerty&startTime=90&endTime=90&userID=testtesttesttesttesttesttesttesttesting&category=intro`, {
method: "POST",
})
.then(res => {
assert.strictEqual(res.status, 400);
@@ -522,10 +510,10 @@ describe('postSkipSegments', () => {
.catch(err => done(err));
});
it('Should be accepted if highlight segment starts and ends at the same time', (done: Done) => {
fetch(getbaseURL()
+ "/api/skipSegments?videoID=qqwerty&startTime=30&endTime=30&userID=testtesttesttesttesttesttesttesttesting&category=highlight", {
method: 'POST',
it("Should be accepted if highlight segment starts and ends at the same time", (done: Done) => {
fetch(`${getbaseURL()
}/api/skipSegments?videoID=qqwerty&startTime=30&endTime=30&userID=testtesttesttesttesttesttesttesttesting&category=highlight`, {
method: "POST",
})
.then(res => {
assert.strictEqual(res.status, 200);
@@ -534,10 +522,10 @@ describe('postSkipSegments', () => {
.catch(err => done(err));
});
it('Should be rejected if highlight segment doesn\'t start and end at the same time', (done: Done) => {
fetch(getbaseURL()
+ "/api/skipSegments?videoID=qqwerty&startTime=30&endTime=30.5&userID=testtesttesttesttesttesttesttesttesting&category=highlight", {
method: 'POST',
it("Should be rejected if highlight segment doesn't start and end at the same time", (done: Done) => {
fetch(`${getbaseURL()
}/api/skipSegments?videoID=qqwerty&startTime=30&endTime=30.5&userID=testtesttesttesttesttesttesttesttesting&category=highlight`, {
method: "POST",
})
.then(res => {
assert.strictEqual(res.status, 400);
@@ -546,10 +534,10 @@ describe('postSkipSegments', () => {
.catch(err => done(err));
});
it('Should be rejected if a sponsor is less than 1 second', (done: Done) => {
fetch(getbaseURL()
+ "/api/skipSegments?videoID=qqwerty&startTime=30&endTime=30.5&userID=testtesttesttesttesttesttesttesttesting", {
method: 'POST',
it("Should be rejected if a sponsor is less than 1 second", (done: Done) => {
fetch(`${getbaseURL()
}/api/skipSegments?videoID=qqwerty&startTime=30&endTime=30.5&userID=testtesttesttesttesttesttesttesttesting`, {
method: "POST",
})
.then(res => {
assert.strictEqual(res.status, 400);
@@ -558,9 +546,9 @@ describe('postSkipSegments', () => {
.catch(err => done(err));
});
it('Should be rejected if over 80% of the video', (done: Done) => {
fetch(getbaseURL()
+ "/api/postVideoSponsorTimes?videoID=qqwerty&startTime=30&endTime=1000000&userID=testtesttesttesttesttesttesttesttesting")
it("Should be rejected if over 80% of the video", (done: Done) => {
fetch(`${getbaseURL()
}/api/postVideoSponsorTimes?videoID=qqwerty&startTime=30&endTime=1000000&userID=testtesttesttesttesttesttesttesttesting`)
.then(res => {
assert.strictEqual(res.status, 403);
done();
@@ -569,8 +557,8 @@ describe('postSkipSegments', () => {
});
it("Should be rejected if NB's predicted probability is <70%.", (done: Done) => {
fetch(getbaseURL()
+ "/api/postVideoSponsorTimes?videoID=LevkAjUE6d4&startTime=40&endTime=60&userID=testtesttesttesttesttesttesttesttesting")
fetch(`${getbaseURL()
}/api/postVideoSponsorTimes?videoID=LevkAjUE6d4&startTime=40&endTime=60&userID=testtesttesttesttesttesttesttesttesting`)
.then(res => {
assert.strictEqual(res.status, 200);
done();
@@ -578,12 +566,11 @@ describe('postSkipSegments', () => {
.catch(err => done(err));
});
it('Should be rejected with custom message if user has to many active warnings', (done: Done) => {
fetch(getbaseURL()
+ "/api/postVideoSponsorTimes", {
method: 'POST',
it("Should be rejected with custom message if user has to many active warnings", (done: Done) => {
fetch(`${getbaseURL()}/api/postVideoSponsorTimes`, {
method: "POST",
headers: {
'Content-Type': 'application/json',
"Content-Type": "application/json",
},
body: JSON.stringify({
userID: "warn-user01-qwertyuiopasdfghjklzxcvbnm",
@@ -597,18 +584,17 @@ describe('postSkipSegments', () => {
.then(async res => {
assert.strictEqual(res.status, 403);
const errorMessage = await res.text();
assert.strictEqual(errorMessage, 'Reason01');
assert.strictEqual(errorMessage, "Reason01");
done();
})
.catch(err => done(err));
});
it('Should be accepted if user has some active warnings', (done: Done) => {
fetch(getbaseURL()
+ "/api/postVideoSponsorTimes", {
method: 'POST',
it("Should be accepted if user has some active warnings", (done: Done) => {
fetch(`${getbaseURL()}/api/postVideoSponsorTimes`, {
method: "POST",
headers: {
'Content-Type': 'application/json',
"Content-Type": "application/json",
},
body: JSON.stringify({
userID: "warn-user02-qwertyuiopasdfghjklzxcvbnm",
@@ -624,18 +610,17 @@ describe('postSkipSegments', () => {
done(); // success
} else {
const body = await res.text();
done("Status code was " + res.status + " " + body);
done(`Status code was ${ res.status } ${ body}`);
}
})
.catch(err => done(err));
});
it('Should be accepted if user has some warnings removed', (done: Done) => {
fetch(getbaseURL()
+ "/api/postVideoSponsorTimes", {
method: 'POST',
it("Should be accepted if user has some warnings removed", (done: Done) => {
fetch(`${getbaseURL()}/api/postVideoSponsorTimes`, {
method: "POST",
headers: {
'Content-Type': 'application/json',
"Content-Type": "application/json",
},
body: JSON.stringify({
userID: "warn-user03-qwertyuiopasdfghjklzxcvbnm",
@@ -651,16 +636,16 @@ describe('postSkipSegments', () => {
done(); // success
} else {
const body = await res.text();
done("Status code was " + res.status + " " + body);
done(`Status code was ${ res.status } ${ body}`);
}
})
.catch(err => done(err));
});
it('Should return 400 for missing params (Params method)', (done: Done) => {
fetch(getbaseURL()
+ "/api/postVideoSponsorTimes?startTime=9&endTime=10&userID=testtesttesttesttesttesttesttesttest", {
method: 'POST',
it("Should return 400 for missing params (Params method)", (done: Done) => {
fetch(`${getbaseURL()
}/api/postVideoSponsorTimes?startTime=9&endTime=10&userID=testtesttesttesttesttesttesttesttest`, {
method: "POST",
})
.then(async res => {
if (res.status === 400) done();
@@ -669,12 +654,11 @@ describe('postSkipSegments', () => {
.catch(err => done(err));
});
it('Should be rejected with default message if user has to many active warnings', (done: Done) => {
fetch(getbaseURL()
+ "/api/postVideoSponsorTimes", {
method: 'POST',
it("Should be rejected with default message if user has to many active warnings", (done: Done) => {
fetch(`${getbaseURL()}/api/postVideoSponsorTimes`, {
method: "POST",
headers: {
'Content-Type': 'application/json',
"Content-Type": "application/json",
},
body: JSON.stringify({
userID: "warn-user01-qwertyuiopasdfghjklzxcvbnm",
@@ -688,18 +672,17 @@ describe('postSkipSegments', () => {
.then(async res => {
assert.strictEqual(res.status, 403);
const errorMessage = await res.text();
assert.notStrictEqual(errorMessage, '');
assert.notStrictEqual(errorMessage, "");
done();
})
.catch(err => done(err));
});
it('Should return 400 for missing params (JSON method) 1', (done: Done) => {
fetch(getbaseURL()
+ "/api/postVideoSponsorTimes", {
method: 'POST',
it("Should return 400 for missing params (JSON method) 1", (done: Done) => {
fetch(`${getbaseURL()}/api/postVideoSponsorTimes`, {
method: "POST",
headers: {
'Content-Type': 'application/json',
"Content-Type": "application/json",
},
body: JSON.stringify({
userID: "testtesttesttesttesttesttesttesttest",
@@ -718,12 +701,11 @@ describe('postSkipSegments', () => {
})
.catch(err => done(err));
});
it('Should return 400 for missing params (JSON method) 2', (done: Done) => {
fetch(getbaseURL()
+ "/api/postVideoSponsorTimes", {
method: 'POST',
it("Should return 400 for missing params (JSON method) 2", (done: Done) => {
fetch(`${getbaseURL()}/api/postVideoSponsorTimes`, {
method: "POST",
headers: {
'Content-Type': 'application/json',
"Content-Type": "application/json",
},
body: JSON.stringify({
userID: "testtesttesttesttesttesttesttesttest",
@@ -736,12 +718,11 @@ describe('postSkipSegments', () => {
})
.catch(err => done(err));
});
it('Should return 400 for missing params (JSON method) 3', (done: Done) => {
fetch(getbaseURL()
+ "/api/postVideoSponsorTimes", {
method: 'POST',
it("Should return 400 for missing params (JSON method) 3", (done: Done) => {
fetch(`${getbaseURL()}/api/postVideoSponsorTimes`, {
method: "POST",
headers: {
'Content-Type': 'application/json',
"Content-Type": "application/json",
},
body: JSON.stringify({
userID: "testtesttesttesttesttesttesttesttest",
@@ -761,12 +742,11 @@ describe('postSkipSegments', () => {
})
.catch(err => done(err));
});
it('Should return 400 for missing params (JSON method) 4', (done: Done) => {
fetch(getbaseURL()
+ "/api/postVideoSponsorTimes", {
method: 'POST',
it("Should return 400 for missing params (JSON method) 4", (done: Done) => {
fetch(`${getbaseURL()}/api/postVideoSponsorTimes`, {
method: "POST",
headers: {
'Content-Type': 'application/json',
"Content-Type": "application/json",
},
body: JSON.stringify({
userID: "testtesttesttesttesttesttesttesttest",
@@ -785,12 +765,11 @@ describe('postSkipSegments', () => {
})
.catch(err => done(err));
});
it('Should return 400 for missing params (JSON method) 5', (done: Done) => {
fetch(getbaseURL()
+ "/api/postVideoSponsorTimes", {
method: 'POST',
it("Should return 400 for missing params (JSON method) 5", (done: Done) => {
fetch(`${getbaseURL()}/api/postVideoSponsorTimes`, {
method: "POST",
headers: {
'Content-Type': 'application/json',
"Content-Type": "application/json",
},
body: JSON.stringify({
userID: "testtesttesttesttesttesttesttesttest",

View File

@@ -1,31 +1,30 @@
import fetch from 'node-fetch';
import {Done, getbaseURL} from '../utils';
import {db} from '../../src/databases/databases';
import {getHash} from '../../src/utils/getHash';
import assert from 'assert';
import fetch from "node-fetch";
import {Done, getbaseURL} from "../utils";
import {db} from "../../src/databases/databases";
import {getHash} from "../../src/utils/getHash";
import assert from "assert";
describe('postWarning', () => {
describe("postWarning", () => {
before(async () => {
await db.prepare("run", `INSERT INTO "vipUsers" ("userID") VALUES (?)`, [getHash("warning-vip")]);
});
it('Should be able to create warning if vip (exp 200)', (done: Done) => {
it("Should be able to create warning if vip (exp 200)", (done: Done) => {
const json = {
issuerUserID: 'warning-vip',
userID: 'warning-0',
reason: 'warning-reason-0'
issuerUserID: "warning-vip",
userID: "warning-0",
reason: "warning-reason-0"
};
fetch(getbaseURL()
+ "/api/warnUser", {
method: 'POST',
fetch(`${getbaseURL()}/api/warnUser`, {
method: "POST",
headers: {
'Content-Type': 'application/json',
"Content-Type": "application/json",
},
body: JSON.stringify(json),
})
.then(async res => {
assert.strictEqual(res.status, 200);
const row = await db.prepare('get', `SELECT "userID", "issueTime", "issuerUserID", enabled, "reason" FROM warnings WHERE "userID" = ?`, [json.userID]);
const row = await db.prepare("get", `SELECT "userID", "issueTime", "issuerUserID", enabled, "reason" FROM warnings WHERE "userID" = ?`, [json.userID]);
assert.strictEqual(row.enabled, 1);
assert.strictEqual(row.issuerUserID, getHash(json.issuerUserID));
assert.strictEqual(row.reason, json.reason);
@@ -34,23 +33,22 @@ describe('postWarning', () => {
.catch(err => done(err));
});
it('Should be not be able to create a duplicate warning if vip', (done: Done) => {
it("Should be not be able to create a duplicate warning if vip", (done: Done) => {
const json = {
issuerUserID: 'warning-vip',
userID: 'warning-0',
issuerUserID: "warning-vip",
userID: "warning-0",
};
fetch(getbaseURL()
+ "/api/warnUser", {
method: 'POST',
fetch(`${getbaseURL()}/api/warnUser`, {
method: "POST",
headers: {
'Content-Type': 'application/json',
"Content-Type": "application/json",
},
body: JSON.stringify(json),
})
.then(async res => {
assert.strictEqual(res.status, 409);
const row = await db.prepare('get', `SELECT "userID", "issueTime", "issuerUserID", enabled FROM warnings WHERE "userID" = ?`, [json.userID]);
const row = await db.prepare("get", `SELECT "userID", "issueTime", "issuerUserID", enabled FROM warnings WHERE "userID" = ?`, [json.userID]);
assert.strictEqual(row.enabled, 1);
assert.strictEqual(row.issuerUserID, getHash(json.issuerUserID));
done();
@@ -58,41 +56,39 @@ describe('postWarning', () => {
.catch(err => done(err));
});
it('Should be able to remove warning if vip', (done: Done) => {
it("Should be able to remove warning if vip", (done: Done) => {
const json = {
issuerUserID: 'warning-vip',
userID: 'warning-0',
issuerUserID: "warning-vip",
userID: "warning-0",
enabled: false
};
fetch(getbaseURL()
+ "/api/warnUser", {
method: 'POST',
fetch(`${getbaseURL()}/api/warnUser`, {
method: "POST",
headers: {
'Content-Type': 'application/json',
"Content-Type": "application/json",
},
body: JSON.stringify(json),
})
.then(async res => {
assert.strictEqual(res.status, 200);
const row = await db.prepare('get', `SELECT "userID", "issueTime", "issuerUserID", enabled FROM warnings WHERE "userID" = ?`, [json.userID]);
const row = await db.prepare("get", `SELECT "userID", "issueTime", "issuerUserID", enabled FROM warnings WHERE "userID" = ?`, [json.userID]);
assert.strictEqual(row.enabled, 0);
done();
})
.catch(err => done(err));
});
it('Should not be able to create warning if not vip (exp 403)', (done: Done) => {
it("Should not be able to create warning if not vip (exp 403)", (done: Done) => {
const json = {
issuerUserID: 'warning-not-vip',
userID: 'warning-1',
issuerUserID: "warning-not-vip",
userID: "warning-1",
};
fetch(getbaseURL()
+ "/api/warnUser", {
method: 'POST',
fetch(`${getbaseURL()}/api/warnUser`, {
method: "POST",
headers: {
'Content-Type': 'application/json',
"Content-Type": "application/json",
},
body: JSON.stringify(json),
})

View File

@@ -1,8 +1,8 @@
import assert from 'assert';
import { db } from '../../src/databases/databases';
import { UserID } from '../../src/types/user.model';
import { getHash } from '../../src/utils/getHash';
import { getReputation } from '../../src/utils/reputation';
import assert from "assert";
import { db } from "../../src/databases/databases";
import { UserID } from "../../src/types/user.model";
import { getHash } from "../../src/utils/getHash";
import { getReputation } from "../../src/utils/reputation";
const userIDLowSubmissions = "reputation-lowsubmissions" as UserID;
const userIDHighDownvotes = "reputation-highdownvotes" as UserID;
@@ -13,80 +13,80 @@ const userIDHighRepBeforeManualVote = "reputation-oldhighrep" as UserID;
const userIDHighRep = "reputation-highrep" as UserID;
const userIDHighRepAndLocked = "reputation-highlockedrep" as UserID;
describe('reputation', () => {
describe("reputation", () => {
before(async function() {
this.timeout(5000); // this preparation takes longer then usual
const videoID = "reputation-videoID";
const sponsorTimesInsertQuery = 'INSERT INTO "sponsorTimes" ("videoID", "startTime", "endTime", "votes", "locked", "UUID", "userID", "timeSubmitted", "views", "category", "service", "videoDuration", "hidden", "shadowHidden", "hashedVideoID") VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)';
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 2, 0, 'reputation-0-uuid-0', getHash(userIDLowSubmissions), 1606240000000, 50, 'sponsor', 'YouTube', 100, 0, 0, getHash(videoID, 1)]);
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 2, 0, 'reputation-0-uuid-1', getHash(userIDLowSubmissions), 1606240000000, 50, 'sponsor', 'YouTube', 100, 0, 0, getHash(videoID, 1)]);
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 100, 0, 'reputation-0-uuid-2', getHash(userIDLowSubmissions), 1606240000000, 50, 'sponsor', 'YouTube', 100, 0, 0, getHash(videoID, 1)]);
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 2, 0, "reputation-0-uuid-0", getHash(userIDLowSubmissions), 1606240000000, 50, "sponsor", "YouTube", 100, 0, 0, getHash(videoID, 1)]);
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 2, 0, "reputation-0-uuid-1", getHash(userIDLowSubmissions), 1606240000000, 50, "sponsor", "YouTube", 100, 0, 0, getHash(videoID, 1)]);
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 100, 0, "reputation-0-uuid-2", getHash(userIDLowSubmissions), 1606240000000, 50, "sponsor", "YouTube", 100, 0, 0, getHash(videoID, 1)]);
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 2, 0, 'reputation-1-uuid-0', getHash(userIDHighDownvotes), 1606240000000, 50, 'sponsor', 'YouTube', 100, 0, 0, getHash(videoID, 1)]);
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, -2, 0, 'reputation-1-uuid-1', getHash(userIDHighDownvotes), 1606240000000, 50, 'sponsor', 'YouTube', 100, 0, 0, getHash(videoID, 1)]);
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, -2, 0, 'reputation-1-uuid-2', getHash(userIDHighDownvotes), 1606240000000, 50, 'sponsor', 'YouTube', 100, 0, 0, getHash(videoID, 1)]);
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, -2, 0, 'reputation-1-uuid-3', getHash(userIDHighDownvotes), 1606240000000, 50, 'sponsor', 'YouTube', 100, 0, 0, getHash(videoID, 1)]);
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, -2, 0, 'reputation-1-uuid-4', getHash(userIDHighDownvotes), 1606240000000, 50, 'sponsor', 'YouTube', 100, 0, 0, getHash(videoID, 1)]);
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, -1, 0, 'reputation-1-uuid-5', getHash(userIDHighDownvotes), 1606240000000, 50, 'sponsor', 'YouTube', 100, 0, 0, getHash(videoID, 1)]);
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 0, 0, 'reputation-1-uuid-6', getHash(userIDHighDownvotes), 1606240000000, 50, 'sponsor', 'YouTube', 100, 0, 0, getHash(videoID, 1)]);
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 0, 0, 'reputation-1-uuid-7', getHash(userIDHighDownvotes), 1606240000000, 50, 'sponsor', 'YouTube', 100, 0, 0, getHash(videoID, 1)]);
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 2, 0, "reputation-1-uuid-0", getHash(userIDHighDownvotes), 1606240000000, 50, "sponsor", "YouTube", 100, 0, 0, getHash(videoID, 1)]);
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, -2, 0, "reputation-1-uuid-1", getHash(userIDHighDownvotes), 1606240000000, 50, "sponsor", "YouTube", 100, 0, 0, getHash(videoID, 1)]);
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, -2, 0, "reputation-1-uuid-2", getHash(userIDHighDownvotes), 1606240000000, 50, "sponsor", "YouTube", 100, 0, 0, getHash(videoID, 1)]);
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, -2, 0, "reputation-1-uuid-3", getHash(userIDHighDownvotes), 1606240000000, 50, "sponsor", "YouTube", 100, 0, 0, getHash(videoID, 1)]);
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, -2, 0, "reputation-1-uuid-4", getHash(userIDHighDownvotes), 1606240000000, 50, "sponsor", "YouTube", 100, 0, 0, getHash(videoID, 1)]);
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, -1, 0, "reputation-1-uuid-5", getHash(userIDHighDownvotes), 1606240000000, 50, "sponsor", "YouTube", 100, 0, 0, getHash(videoID, 1)]);
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 0, 0, "reputation-1-uuid-6", getHash(userIDHighDownvotes), 1606240000000, 50, "sponsor", "YouTube", 100, 0, 0, getHash(videoID, 1)]);
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 0, 0, "reputation-1-uuid-7", getHash(userIDHighDownvotes), 1606240000000, 50, "sponsor", "YouTube", 100, 0, 0, getHash(videoID, 1)]);
// First video is considered a normal downvote, second is considered a self-downvote (ie. they didn't resubmit to fix their downvote)
await db.prepare("run", sponsorTimesInsertQuery, [videoID+'A', 1, 11, 2, 0, 'reputation-1-1-uuid-0', getHash(userIDHighNonSelfDownvotes), 1606240000000, 50, 'sponsor', 'YouTube', 100, 0, 0, getHash(videoID, 1)]);
await db.prepare("run", sponsorTimesInsertQuery, [`${videoID}A`, 1, 11, 2, 0, "reputation-1-1-uuid-0", getHash(userIDHighNonSelfDownvotes), 1606240000000, 50, "sponsor", "YouTube", 100, 0, 0, getHash(videoID, 1)]);
// Different category, same video
await db.prepare("run", sponsorTimesInsertQuery, [videoID+'A', 1, 11, -2, 0, 'reputation-1-1-uuid-1', getHash(userIDHighNonSelfDownvotes), 1606240000000, 50, 'intro', 'YouTube', 100, 0, 0, getHash(videoID, 1)]);
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 0, 0, 'reputation-1-1-uuid-2', getHash(userIDHighNonSelfDownvotes), 1606240000000, 50, 'sponsor', 'YouTube', 100, 0, 0, getHash(videoID, 1)]);
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 0, 0, 'reputation-1-1-uuid-3', getHash(userIDHighNonSelfDownvotes), 1606240000000, 50, 'sponsor', 'YouTube', 100, 0, 0, getHash(videoID, 1)]);
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 0, 0, 'reputation-1-1-uuid-4', getHash(userIDHighNonSelfDownvotes), 1606240000000, 50, 'sponsor', 'YouTube', 100, 0, 0, getHash(videoID, 1)]);
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, -1, 0, 'reputation-1-1-uuid-5', getHash(userIDHighNonSelfDownvotes), 1606240000000, 50, 'sponsor', 'YouTube', 100, 0, 0, getHash(videoID, 1)]);
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 0, 0, 'reputation-1-1-uuid-6', getHash(userIDHighNonSelfDownvotes), 1606240000000, 50, 'sponsor', 'YouTube', 100, 0, 0, getHash(videoID, 1)]);
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 0, 0, 'reputation-1-1-uuid-7', getHash(userIDHighNonSelfDownvotes), 1606240000000, 50, 'sponsor', 'YouTube', 100, 0, 0, getHash(videoID, 1)]);
await db.prepare("run", sponsorTimesInsertQuery, [`${videoID}A`, 1, 11, -2, 0, "reputation-1-1-uuid-1", getHash(userIDHighNonSelfDownvotes), 1606240000000, 50, "intro", "YouTube", 100, 0, 0, getHash(videoID, 1)]);
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 0, 0, "reputation-1-1-uuid-2", getHash(userIDHighNonSelfDownvotes), 1606240000000, 50, "sponsor", "YouTube", 100, 0, 0, getHash(videoID, 1)]);
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 0, 0, "reputation-1-1-uuid-3", getHash(userIDHighNonSelfDownvotes), 1606240000000, 50, "sponsor", "YouTube", 100, 0, 0, getHash(videoID, 1)]);
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 0, 0, "reputation-1-1-uuid-4", getHash(userIDHighNonSelfDownvotes), 1606240000000, 50, "sponsor", "YouTube", 100, 0, 0, getHash(videoID, 1)]);
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, -1, 0, "reputation-1-1-uuid-5", getHash(userIDHighNonSelfDownvotes), 1606240000000, 50, "sponsor", "YouTube", 100, 0, 0, getHash(videoID, 1)]);
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 0, 0, "reputation-1-1-uuid-6", getHash(userIDHighNonSelfDownvotes), 1606240000000, 50, "sponsor", "YouTube", 100, 0, 0, getHash(videoID, 1)]);
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 0, 0, "reputation-1-1-uuid-7", getHash(userIDHighNonSelfDownvotes), 1606240000000, 50, "sponsor", "YouTube", 100, 0, 0, getHash(videoID, 1)]);
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 2, 0, 'reputation-2-uuid-0', getHash(userIDNewSubmissions), Date.now(), 50, 'sponsor', 'YouTube', 100, 0, 0, getHash(videoID, 1)]);
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 2, 0, 'reputation-2-uuid-1', getHash(userIDNewSubmissions), Date.now(), 50, 'sponsor', 'YouTube', 100, 0, 0, getHash(videoID, 1)]);
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 2, 0, 'reputation-2-uuid-2', getHash(userIDNewSubmissions), Date.now(), 50, 'sponsor', 'YouTube', 100, 0, 0, getHash(videoID, 1)]);
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 2, 0, 'reputation-2-uuid-3', getHash(userIDNewSubmissions), Date.now(), 50, 'sponsor', 'YouTube', 100, 0, 0, getHash(videoID, 1)]);
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 2, 0, 'reputation-2-uuid-4', getHash(userIDNewSubmissions), Date.now(), 50, 'sponsor', 'YouTube', 100, 0, 0, getHash(videoID, 1)]);
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, -1, 0, 'reputation-2-uuid-5', getHash(userIDNewSubmissions), 1606240000000, 50, 'sponsor', 'YouTube', 100, 0, 0, getHash(videoID, 1)]);
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 0, 0, 'reputation-2-uuid-6', getHash(userIDNewSubmissions), 1606240000000, 50, 'sponsor', 'YouTube', 100, 0, 0, getHash(videoID, 1)]);
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 0, 0, 'reputation-2-uuid-7', getHash(userIDNewSubmissions), 1606240000000, 50, 'sponsor', 'YouTube', 100, 0, 0, getHash(videoID, 1)]);
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 2, 0, "reputation-2-uuid-0", getHash(userIDNewSubmissions), Date.now(), 50, "sponsor", "YouTube", 100, 0, 0, getHash(videoID, 1)]);
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 2, 0, "reputation-2-uuid-1", getHash(userIDNewSubmissions), Date.now(), 50, "sponsor", "YouTube", 100, 0, 0, getHash(videoID, 1)]);
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 2, 0, "reputation-2-uuid-2", getHash(userIDNewSubmissions), Date.now(), 50, "sponsor", "YouTube", 100, 0, 0, getHash(videoID, 1)]);
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 2, 0, "reputation-2-uuid-3", getHash(userIDNewSubmissions), Date.now(), 50, "sponsor", "YouTube", 100, 0, 0, getHash(videoID, 1)]);
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 2, 0, "reputation-2-uuid-4", getHash(userIDNewSubmissions), Date.now(), 50, "sponsor", "YouTube", 100, 0, 0, getHash(videoID, 1)]);
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, -1, 0, "reputation-2-uuid-5", getHash(userIDNewSubmissions), 1606240000000, 50, "sponsor", "YouTube", 100, 0, 0, getHash(videoID, 1)]);
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 0, 0, "reputation-2-uuid-6", getHash(userIDNewSubmissions), 1606240000000, 50, "sponsor", "YouTube", 100, 0, 0, getHash(videoID, 1)]);
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 0, 0, "reputation-2-uuid-7", getHash(userIDNewSubmissions), 1606240000000, 50, "sponsor", "YouTube", 100, 0, 0, getHash(videoID, 1)]);
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 2, 0, 'reputation-3-uuid-0', getHash(userIDLowSum), 1606240000000, 50, 'sponsor', 'YouTube', 100, 0, 0, getHash(videoID, 1)]);
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 1, 0, 'reputation-3-uuid-1', getHash(userIDLowSum), 1606240000000, 50, 'sponsor', 'YouTube', 100, 0, 0, getHash(videoID, 1)]);
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 0, 0, 'reputation-3-uuid-2', getHash(userIDLowSum), 1606240000000, 50, 'sponsor', 'YouTube', 100, 0, 0, getHash(videoID, 1)]);
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 0, 0, 'reputation-3-uuid-3', getHash(userIDLowSum), 1606240000000, 50, 'sponsor', 'YouTube', 100, 0, 0, getHash(videoID, 1)]);
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 1, 0, 'reputation-3-uuid-4', getHash(userIDLowSum), 1606240000000, 50, 'sponsor', 'YouTube', 100, 0, 0, getHash(videoID, 1)]);
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, -1, 0, 'reputation-3-uuid-5', getHash(userIDLowSum), 1606240000000, 50, 'sponsor', 'YouTube', 100, 0, 0, getHash(videoID, 1)]);
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 0, 0, 'reputation-3-uuid-6', getHash(userIDLowSum), 1606240000000, 50, 'sponsor', 'YouTube', 100, 0, 0, getHash(videoID, 1)]);
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 0, 0, 'reputation-3-uuid-7', getHash(userIDLowSum), 1606240000000, 50, 'sponsor', 'YouTube', 100, 0, 0, getHash(videoID, 1)]);
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 2, 0, "reputation-3-uuid-0", getHash(userIDLowSum), 1606240000000, 50, "sponsor", "YouTube", 100, 0, 0, getHash(videoID, 1)]);
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 1, 0, "reputation-3-uuid-1", getHash(userIDLowSum), 1606240000000, 50, "sponsor", "YouTube", 100, 0, 0, getHash(videoID, 1)]);
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 0, 0, "reputation-3-uuid-2", getHash(userIDLowSum), 1606240000000, 50, "sponsor", "YouTube", 100, 0, 0, getHash(videoID, 1)]);
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 0, 0, "reputation-3-uuid-3", getHash(userIDLowSum), 1606240000000, 50, "sponsor", "YouTube", 100, 0, 0, getHash(videoID, 1)]);
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 1, 0, "reputation-3-uuid-4", getHash(userIDLowSum), 1606240000000, 50, "sponsor", "YouTube", 100, 0, 0, getHash(videoID, 1)]);
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, -1, 0, "reputation-3-uuid-5", getHash(userIDLowSum), 1606240000000, 50, "sponsor", "YouTube", 100, 0, 0, getHash(videoID, 1)]);
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 0, 0, "reputation-3-uuid-6", getHash(userIDLowSum), 1606240000000, 50, "sponsor", "YouTube", 100, 0, 0, getHash(videoID, 1)]);
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 0, 0, "reputation-3-uuid-7", getHash(userIDLowSum), 1606240000000, 50, "sponsor", "YouTube", 100, 0, 0, getHash(videoID, 1)]);
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 2, 0, 'reputation-4-uuid-0', getHash(userIDHighRepBeforeManualVote), 0, 50, 'sponsor', 'YouTube', 100, 0, 0, getHash(videoID, 1)]);
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 2, 0, 'reputation-4-uuid-1', getHash(userIDHighRepBeforeManualVote), 0, 50, 'sponsor', 'YouTube', 100, 0, 0, getHash(videoID, 1)]);
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 2, 0, 'reputation-4-uuid-2', getHash(userIDHighRepBeforeManualVote), 0, 50, 'sponsor', 'YouTube', 100, 0, 0, getHash(videoID, 1)]);
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 2, 0, 'reputation-4-uuid-3', getHash(userIDHighRepBeforeManualVote), 0, 50, 'sponsor', 'YouTube', 100, 0, 0, getHash(videoID, 1)]);
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 2, 0, 'reputation-4-uuid-4', getHash(userIDHighRepBeforeManualVote), 0, 50, 'sponsor', 'YouTube', 100, 0, 0, getHash(videoID, 1)]);
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, -1, 0, 'reputation-4-uuid-5', getHash(userIDHighRepBeforeManualVote), 0, 50, 'sponsor', 'YouTube', 100, 0, 0, getHash(videoID, 1)]);
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 0, 0, 'reputation-4-uuid-6', getHash(userIDHighRepBeforeManualVote), 0, 50, 'sponsor', 'YouTube', 100, 0, 0, getHash(videoID, 1)]);
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 0, 0, 'reputation-4-uuid-7', getHash(userIDHighRepBeforeManualVote), 0, 50, 'sponsor', 'YouTube', 100, 0, 0, getHash(videoID, 1)]);
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 2, 0, "reputation-4-uuid-0", getHash(userIDHighRepBeforeManualVote), 0, 50, "sponsor", "YouTube", 100, 0, 0, getHash(videoID, 1)]);
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 2, 0, "reputation-4-uuid-1", getHash(userIDHighRepBeforeManualVote), 0, 50, "sponsor", "YouTube", 100, 0, 0, getHash(videoID, 1)]);
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 2, 0, "reputation-4-uuid-2", getHash(userIDHighRepBeforeManualVote), 0, 50, "sponsor", "YouTube", 100, 0, 0, getHash(videoID, 1)]);
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 2, 0, "reputation-4-uuid-3", getHash(userIDHighRepBeforeManualVote), 0, 50, "sponsor", "YouTube", 100, 0, 0, getHash(videoID, 1)]);
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 2, 0, "reputation-4-uuid-4", getHash(userIDHighRepBeforeManualVote), 0, 50, "sponsor", "YouTube", 100, 0, 0, getHash(videoID, 1)]);
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, -1, 0, "reputation-4-uuid-5", getHash(userIDHighRepBeforeManualVote), 0, 50, "sponsor", "YouTube", 100, 0, 0, getHash(videoID, 1)]);
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 0, 0, "reputation-4-uuid-6", getHash(userIDHighRepBeforeManualVote), 0, 50, "sponsor", "YouTube", 100, 0, 0, getHash(videoID, 1)]);
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 0, 0, "reputation-4-uuid-7", getHash(userIDHighRepBeforeManualVote), 0, 50, "sponsor", "YouTube", 100, 0, 0, getHash(videoID, 1)]);
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 2, 0, 'reputation-5-uuid-0', getHash(userIDHighRep), 1606240000000, 50, 'sponsor', 'YouTube', 100, 0, 0, getHash(videoID, 1)]);
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 2, 0, 'reputation-5-uuid-1', getHash(userIDHighRep), 1606240000000, 50, 'sponsor', 'YouTube', 100, 0, 0, getHash(videoID, 1)]);
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 2, 0, 'reputation-5-uuid-2', getHash(userIDHighRep), 1606240000000, 50, 'sponsor', 'YouTube', 100, 0, 0, getHash(videoID, 1)]);
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 2, 0, 'reputation-5-uuid-3', getHash(userIDHighRep), 1606240000000, 50, 'sponsor', 'YouTube', 100, 0, 0, getHash(videoID, 1)]);
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 2, 0, 'reputation-5-uuid-4', getHash(userIDHighRep), 1606240000000, 50, 'sponsor', 'YouTube', 100, 0, 0, getHash(videoID, 1)]);
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, -1, 0, 'reputation-5-uuid-5', getHash(userIDHighRep), 1606240000000, 50, 'sponsor', 'YouTube', 100, 0, 0, getHash(videoID, 1)]);
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 0, 0, 'reputation-5-uuid-6', getHash(userIDHighRep), 1606240000000, 50, 'sponsor', 'YouTube', 100, 0, 0, getHash(videoID, 1)]);
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 0, 0, 'reputation-5-uuid-7', getHash(userIDHighRep), 1606240000000, 50, 'sponsor', 'YouTube', 100, 0, 0, getHash(videoID, 1)]);
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 2, 0, "reputation-5-uuid-0", getHash(userIDHighRep), 1606240000000, 50, "sponsor", "YouTube", 100, 0, 0, getHash(videoID, 1)]);
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 2, 0, "reputation-5-uuid-1", getHash(userIDHighRep), 1606240000000, 50, "sponsor", "YouTube", 100, 0, 0, getHash(videoID, 1)]);
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 2, 0, "reputation-5-uuid-2", getHash(userIDHighRep), 1606240000000, 50, "sponsor", "YouTube", 100, 0, 0, getHash(videoID, 1)]);
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 2, 0, "reputation-5-uuid-3", getHash(userIDHighRep), 1606240000000, 50, "sponsor", "YouTube", 100, 0, 0, getHash(videoID, 1)]);
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 2, 0, "reputation-5-uuid-4", getHash(userIDHighRep), 1606240000000, 50, "sponsor", "YouTube", 100, 0, 0, getHash(videoID, 1)]);
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, -1, 0, "reputation-5-uuid-5", getHash(userIDHighRep), 1606240000000, 50, "sponsor", "YouTube", 100, 0, 0, getHash(videoID, 1)]);
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 0, 0, "reputation-5-uuid-6", getHash(userIDHighRep), 1606240000000, 50, "sponsor", "YouTube", 100, 0, 0, getHash(videoID, 1)]);
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 0, 0, "reputation-5-uuid-7", getHash(userIDHighRep), 1606240000000, 50, "sponsor", "YouTube", 100, 0, 0, getHash(videoID, 1)]);
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 2, 1, 'reputation-6-uuid-0', getHash(userIDHighRepAndLocked), 1606240000000, 50, 'sponsor', 'YouTube', 100, 0, 0, getHash(videoID, 1)]);
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 2, 1, 'reputation-6-uuid-1', getHash(userIDHighRepAndLocked), 1606240000000, 50, 'sponsor', 'YouTube', 100, 0, 0, getHash(videoID, 1)]);
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 2, 1, 'reputation-6-uuid-2', getHash(userIDHighRepAndLocked), 1606240000000, 50, 'sponsor', 'YouTube', 100, 0, 0, getHash(videoID, 1)]);
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 2, 1, 'reputation-6-uuid-3', getHash(userIDHighRepAndLocked), 1606240000000, 50, 'sponsor', 'YouTube', 100, 0, 0, getHash(videoID, 1)]);
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 2, 0, 'reputation-6-uuid-4', getHash(userIDHighRepAndLocked), 1606240000000, 50, 'sponsor', 'YouTube', 100, 0, 0, getHash(videoID, 1)]);
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, -1, 0, 'reputation-6-uuid-5', getHash(userIDHighRepAndLocked), 1606240000000, 50, 'sponsor', 'YouTube', 100, 0, 0, getHash(videoID, 1)]);
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 0, 0, 'reputation-6-uuid-6', getHash(userIDHighRepAndLocked), 1606240000000, 50, 'sponsor', 'YouTube', 100, 0, 0, getHash(videoID, 1)]);
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 0, 0, 'reputation-6-uuid-7', getHash(userIDHighRepAndLocked), 1606240000000, 50, 'sponsor', 'YouTube', 100, 0, 0, getHash(videoID, 1)]);
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 2, 1, "reputation-6-uuid-0", getHash(userIDHighRepAndLocked), 1606240000000, 50, "sponsor", "YouTube", 100, 0, 0, getHash(videoID, 1)]);
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 2, 1, "reputation-6-uuid-1", getHash(userIDHighRepAndLocked), 1606240000000, 50, "sponsor", "YouTube", 100, 0, 0, getHash(videoID, 1)]);
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 2, 1, "reputation-6-uuid-2", getHash(userIDHighRepAndLocked), 1606240000000, 50, "sponsor", "YouTube", 100, 0, 0, getHash(videoID, 1)]);
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 2, 1, "reputation-6-uuid-3", getHash(userIDHighRepAndLocked), 1606240000000, 50, "sponsor", "YouTube", 100, 0, 0, getHash(videoID, 1)]);
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 2, 0, "reputation-6-uuid-4", getHash(userIDHighRepAndLocked), 1606240000000, 50, "sponsor", "YouTube", 100, 0, 0, getHash(videoID, 1)]);
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, -1, 0, "reputation-6-uuid-5", getHash(userIDHighRepAndLocked), 1606240000000, 50, "sponsor", "YouTube", 100, 0, 0, getHash(videoID, 1)]);
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 0, 0, "reputation-6-uuid-6", getHash(userIDHighRepAndLocked), 1606240000000, 50, "sponsor", "YouTube", 100, 0, 0, getHash(videoID, 1)]);
await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 0, 0, "reputation-6-uuid-7", getHash(userIDHighRepAndLocked), 1606240000000, 50, "sponsor", "YouTube", 100, 0, 0, getHash(videoID, 1)]);
});
it("user in grace period", async () => {

View File

@@ -1,9 +1,9 @@
import fetch from 'node-fetch';
import {Done, getbaseURL} from '../utils';
import {db} from '../../src/databases/databases';
import {getHash} from '../../src/utils/getHash';
import {IDatabase} from '../../src/databases/IDatabase';
import assert from 'assert';
import fetch from "node-fetch";
import {Done, getbaseURL} from "../utils";
import {db} from "../../src/databases/databases";
import {getHash} from "../../src/utils/getHash";
import {IDatabase} from "../../src/databases/IDatabase";
import assert from "assert";
async function dbSponsorTimesAdd(db: IDatabase, videoID: string, startTime: number, endTime: number, UUID: string, category: string) {
const votes = 0,
@@ -20,14 +20,14 @@ async function dbSponsorTimesAdd(db: IDatabase, videoID: string, startTime: numb
}
async function dbSponsorTimesSetByUUID(db: IDatabase, UUID: string, startTime: number, endTime: number) {
await db.prepare('run', `UPDATE "sponsorTimes" SET "startTime" = ?, "endTime" = ? WHERE "UUID" = ?`, [startTime, endTime, UUID]);
await db.prepare("run", `UPDATE "sponsorTimes" SET "startTime" = ?, "endTime" = ? WHERE "UUID" = ?`, [startTime, endTime, UUID]);
}
async function dbSponsorTimesCompareExpect(db: IDatabase, expect: any): Promise<void> {
for (let i = 0, len = expect.length; i < len; i++) {
const expectSeg = expect[i];
const seg = await db.prepare('get', `SELECT "startTime", "endTime" FROM "sponsorTimes" WHERE "UUID" = ?`, [expectSeg.UUID]);
if ('removed' in expect) {
const seg = await db.prepare("get", `SELECT "startTime", "endTime" FROM "sponsorTimes" WHERE "UUID" = ?`, [expectSeg.UUID]);
if ("removed" in expect) {
assert.ok(expect.removed);
assert.strictEqual(seg.votes, -2);
assert.deepStrictEqual(seg, expectSeg);
@@ -37,37 +37,37 @@ async function dbSponsorTimesCompareExpect(db: IDatabase, expect: any): Promise<
}
}
describe('segmentShift', function () {
const privateVipUserID = 'VIPUser-segmentShift';
describe("segmentShift", function () {
const privateVipUserID = "VIPUser-segmentShift";
const vipUserID = getHash(privateVipUserID);
const baseURL = getbaseURL();
before(async function () {
// startTime and endTime get set in beforeEach for consistency
await dbSponsorTimesAdd(db, 'vsegshift01', 0, 0, 'vsegshifttest01uuid01', 'intro');
await dbSponsorTimesAdd(db, 'vsegshift01', 0, 0, 'vsegshifttest01uuid02', 'sponsor');
await dbSponsorTimesAdd(db, 'vsegshift01', 0, 0, 'vsegshifttest01uuid03', 'interaction');
await dbSponsorTimesAdd(db, 'vsegshift01', 0, 0, 'vsegshifttest01uuid04', 'outro');
await dbSponsorTimesAdd(db, "vsegshift01", 0, 0, "vsegshifttest01uuid01", "intro");
await dbSponsorTimesAdd(db, "vsegshift01", 0, 0, "vsegshifttest01uuid02", "sponsor");
await dbSponsorTimesAdd(db, "vsegshift01", 0, 0, "vsegshifttest01uuid03", "interaction");
await dbSponsorTimesAdd(db, "vsegshift01", 0, 0, "vsegshifttest01uuid04", "outro");
await db.prepare("run", `INSERT INTO "vipUsers" ("userID") VALUES (?)`, [vipUserID]);
});
beforeEach(async function () {
// resetting startTime and endTime to reuse them
await dbSponsorTimesSetByUUID(db, 'vsegshifttest01uuid01', 0, 10);
await dbSponsorTimesSetByUUID(db, 'vsegshifttest01uuid02', 60, 90);
await dbSponsorTimesSetByUUID(db, 'vsegshifttest01uuid03', 40, 45);
await dbSponsorTimesSetByUUID(db, 'vsegshifttest01uuid04', 120, 140);
await dbSponsorTimesSetByUUID(db, "vsegshifttest01uuid01", 0, 10);
await dbSponsorTimesSetByUUID(db, "vsegshifttest01uuid02", 60, 90);
await dbSponsorTimesSetByUUID(db, "vsegshifttest01uuid03", 40, 45);
await dbSponsorTimesSetByUUID(db, "vsegshifttest01uuid04", 120, 140);
});
it('Reject none VIP user', function (done: Done) {
it("Reject none VIP user", function (done: Done) {
fetch(`${baseURL}/api/segmentShift`, {
method: 'POST',
method: "POST",
headers: {
'Content-Type': 'application/json',
"Content-Type": "application/json",
},
body: JSON.stringify({
videoID: 'vsegshift01',
userID: 'segshift_randomuser001',
videoID: "vsegshift01",
userID: "segshift_randomuser001",
startTime: 20,
endTime: 30,
}),
@@ -79,14 +79,14 @@ describe('segmentShift', function () {
.catch(err => done(err));
});
it('Shift is outside segments', function (done: Done) {
it("Shift is outside segments", function (done: Done) {
fetch(`${baseURL}/api/segmentShift`, {
method: 'POST',
method: "POST",
headers: {
'Content-Type': 'application/json',
"Content-Type": "application/json",
},
body: JSON.stringify({
videoID: 'vsegshift01',
videoID: "vsegshift01",
userID: privateVipUserID,
startTime: 20,
endTime: 30,
@@ -96,22 +96,22 @@ describe('segmentShift', function () {
assert.strictEqual(res.status, 200);
const expect = [
{
UUID: 'vsegshifttest01uuid01',
UUID: "vsegshifttest01uuid01",
startTime: 0,
endTime: 10,
},
{
UUID: 'vsegshifttest01uuid02',
UUID: "vsegshifttest01uuid02",
startTime: 50,
endTime: 80,
},
{
UUID: 'vsegshifttest01uuid03',
UUID: "vsegshifttest01uuid03",
startTime: 30,
endTime: 35,
},
{
UUID: 'vsegshifttest01uuid04',
UUID: "vsegshifttest01uuid04",
startTime: 110,
endTime: 130,
},
@@ -121,14 +121,14 @@ describe('segmentShift', function () {
.catch(err => done(err));
});
it('Shift is inside segment', function (done: Done) {
it("Shift is inside segment", function (done: Done) {
fetch(`${baseURL}/api/segmentShift`, {
method: 'POST',
method: "POST",
headers: {
'Content-Type': 'application/json',
"Content-Type": "application/json",
},
body: JSON.stringify({
videoID: 'vsegshift01',
videoID: "vsegshift01",
userID: privateVipUserID,
startTime: 65,
endTime: 75,
@@ -138,22 +138,22 @@ describe('segmentShift', function () {
assert.strictEqual(res.status, 200);
const expect = [
{
UUID: 'vsegshifttest01uuid01',
UUID: "vsegshifttest01uuid01",
startTime: 0,
endTime: 10,
},
{
UUID: 'vsegshifttest01uuid02',
UUID: "vsegshifttest01uuid02",
startTime: 60,
endTime: 80,
},
{
UUID: 'vsegshifttest01uuid03',
UUID: "vsegshifttest01uuid03",
startTime: 40,
endTime: 45,
},
{
UUID: 'vsegshifttest01uuid04',
UUID: "vsegshifttest01uuid04",
startTime: 110,
endTime: 130,
},
@@ -163,14 +163,14 @@ describe('segmentShift', function () {
.catch(err => done(err));
});
it('Shift is overlaping startTime of segment', function (done: Done) {
it("Shift is overlaping startTime of segment", function (done: Done) {
fetch(`${baseURL}/api/segmentShift`, {
method: 'POST',
method: "POST",
headers: {
'Content-Type': 'application/json',
"Content-Type": "application/json",
},
body: JSON.stringify({
videoID: 'vsegshift01',
videoID: "vsegshift01",
userID: privateVipUserID,
startTime: 32,
endTime: 42,
@@ -180,22 +180,22 @@ describe('segmentShift', function () {
assert.strictEqual(res.status, 200);
const expect = [
{
UUID: 'vsegshifttest01uuid01',
UUID: "vsegshifttest01uuid01",
startTime: 0,
endTime: 10,
},
{
UUID: 'vsegshifttest01uuid02',
UUID: "vsegshifttest01uuid02",
startTime: 50,
endTime: 80,
},
{
UUID: 'vsegshifttest01uuid03',
UUID: "vsegshifttest01uuid03",
startTime: 32,
endTime: 35,
},
{
UUID: 'vsegshifttest01uuid04',
UUID: "vsegshifttest01uuid04",
startTime: 110,
endTime: 130,
},
@@ -205,14 +205,14 @@ describe('segmentShift', function () {
.catch(err => done(err));
});
it('Shift is overlaping endTime of segment', function (done: Done) {
it("Shift is overlaping endTime of segment", function (done: Done) {
fetch(`${baseURL}/api/segmentShift`, {
method: 'POST',
method: "POST",
headers: {
'Content-Type': 'application/json',
"Content-Type": "application/json",
},
body: JSON.stringify({
videoID: 'vsegshift01',
videoID: "vsegshift01",
userID: privateVipUserID,
startTime: 85,
endTime: 95,
@@ -222,22 +222,22 @@ describe('segmentShift', function () {
assert.strictEqual(res.status, 200);
const expect = [
{
UUID: 'vsegshifttest01uuid01',
UUID: "vsegshifttest01uuid01",
startTime: 0,
endTime: 10,
},
{
UUID: 'vsegshifttest01uuid02',
UUID: "vsegshifttest01uuid02",
startTime: 60,
endTime: 85,
},
{
UUID: 'vsegshifttest01uuid03',
UUID: "vsegshifttest01uuid03",
startTime: 40,
endTime: 45,
},
{
UUID: 'vsegshifttest01uuid04',
UUID: "vsegshifttest01uuid04",
startTime: 110,
endTime: 130,
},
@@ -247,14 +247,14 @@ describe('segmentShift', function () {
.catch(err => done(err));
});
it('Shift is overlaping segment', function (done: Done) {
it("Shift is overlaping segment", function (done: Done) {
fetch(`${baseURL}/api/segmentShift`, {
method: 'POST',
method: "POST",
headers: {
'Content-Type': 'application/json',
"Content-Type": "application/json",
},
body: JSON.stringify({
videoID: 'vsegshift01',
videoID: "vsegshift01",
userID: privateVipUserID,
startTime: 35,
endTime: 55,
@@ -264,23 +264,23 @@ describe('segmentShift', function () {
assert.strictEqual(res.status, 200);
const expect = [
{
UUID: 'vsegshifttest01uuid01',
UUID: "vsegshifttest01uuid01",
startTime: 0,
endTime: 10,
},
{
UUID: 'vsegshifttest01uuid02',
UUID: "vsegshifttest01uuid02",
startTime: 40,
endTime: 70,
},
{
UUID: 'vsegshifttest01uuid03',
UUID: "vsegshifttest01uuid03",
startTime: 40,
endTime: 45,
removed: true,
},
{
UUID: 'vsegshifttest01uuid04',
UUID: "vsegshifttest01uuid04",
startTime: 100,
endTime: 120,
},

View File

@@ -1,54 +1,54 @@
import fetch from 'node-fetch';
import { Done, getbaseURL } from '../utils';
import { db, privateDB } from '../../src/databases/databases';
import { getHash } from '../../src/utils/getHash';
import assert from 'assert';
import fetch from "node-fetch";
import { Done, getbaseURL } from "../utils";
import { db, privateDB } from "../../src/databases/databases";
import { getHash } from "../../src/utils/getHash";
import assert from "assert";
const adminPrivateUserID = 'testUserId';
const user00PrivateUserID = 'setUsername_00';
const username00 = 'Username 00';
const user01PrivateUserID = 'setUsername_01';
const username01 = 'Username 01';
const user02PrivateUserID = 'setUsername_02';
const username02 = 'Username 02';
const user03PrivateUserID = 'setUsername_03';
const username03 = 'Username 03';
const user04PrivateUserID = 'setUsername_04';
const username04 = 'Username 04';
const user05PrivateUserID = 'setUsername_05';
const username05 = 'Username 05';
const user06PrivateUserID = 'setUsername_06';
const username06 = 'Username 06';
const user07PrivateUserID = 'setUsername_07';
const username07 = 'Username 07';
const adminPrivateUserID = "testUserId";
const user00PrivateUserID = "setUsername_00";
const username00 = "Username 00";
const user01PrivateUserID = "setUsername_01";
const username01 = "Username 01";
const user02PrivateUserID = "setUsername_02";
const username02 = "Username 02";
const user03PrivateUserID = "setUsername_03";
const username03 = "Username 03";
const user04PrivateUserID = "setUsername_04";
const username04 = "Username 04";
const user05PrivateUserID = "setUsername_05";
const username05 = "Username 05";
const user06PrivateUserID = "setUsername_06";
const username06 = "Username 06";
const user07PrivateUserID = "setUsername_07";
const username07 = "Username 07";
async function addUsername(userID: string, userName: string, locked = 0) {
await db.prepare('run', 'INSERT INTO "userNames" ("userID", "userName", "locked") VALUES(?, ?, ?)', [userID, userName, locked]);
await db.prepare("run", 'INSERT INTO "userNames" ("userID", "userName", "locked") VALUES(?, ?, ?)', [userID, userName, locked]);
await addLogUserNameChange(userID, userName);
}
async function getUsernameInfo(userID: string): Promise<{ userName: string, locked: string }> {
const row = await db.prepare('get', 'SELECT "userName", "locked" FROM "userNames" WHERE "userID" = ?', [userID]);
const row = await db.prepare("get", 'SELECT "userName", "locked" FROM "userNames" WHERE "userID" = ?', [userID]);
if (!row) {
return null;
}
return row;
}
async function addLogUserNameChange(userID: string, newUserName: string, oldUserName = '') {
privateDB.prepare('run',
async function addLogUserNameChange(userID: string, newUserName: string, oldUserName = "") {
privateDB.prepare("run",
`INSERT INTO "userNameLogs"("userID", "newUserName", "oldUserName", "updatedAt", "updatedByAdmin") VALUES(?, ?, ?, ?, ?)`,
[getHash(userID), newUserName, oldUserName, new Date().getTime(), + true]
);
}
async function getLastLogUserNameChange(userID: string) {
return privateDB.prepare('get', `SELECT * FROM "userNameLogs" WHERE "userID" = ? ORDER BY "updatedAt" DESC LIMIT 1`, [getHash(userID)]);
return privateDB.prepare("get", `SELECT * FROM "userNameLogs" WHERE "userID" = ? ORDER BY "updatedAt" DESC LIMIT 1`, [getHash(userID)]);
}
function wellFormatUserName(userName: string) {
// eslint-disable-next-line no-control-regex
return userName.replace(/[\u0000-\u001F\u007F-\u009F]/g, '');
return userName.replace(/[\u0000-\u001F\u007F-\u009F]/g, "");
}
async function testUserNameChangelog(userID: string, newUserName: string, oldUserName: string, byAdmin: boolean, done: Done) {
@@ -59,7 +59,7 @@ async function testUserNameChangelog(userID: string, newUserName: string, oldUse
return done();
}
describe('setUsername', () => {
describe("setUsername", () => {
before(async () => {
await addUsername(getHash(user01PrivateUserID), username01, 0);
await addUsername(getHash(user02PrivateUserID), username02, 0);
@@ -70,9 +70,9 @@ describe('setUsername', () => {
await addUsername(getHash(user07PrivateUserID), username07, 1);
});
it('Should be able to set username that has never been set', (done: Done) => {
it("Should be able to set username that has never been set", (done: Done) => {
fetch(`${getbaseURL()}/api/setUsername?userID=${user00PrivateUserID}&username=${username00}`, {
method: 'POST',
method: "POST",
})
.then(async res => {
const usernameInfo = await getUsernameInfo(getHash(user00PrivateUserID));
@@ -84,20 +84,20 @@ describe('setUsername', () => {
.catch(() => done(`couldn't call endpoint`));
});
it('Should return 200', (done: Done) => {
it("Should return 200", (done: Done) => {
fetch(`${getbaseURL()}/api/setUsername?userID=${user01PrivateUserID}&username=Changed%20Username`, {
method: 'POST',
method: "POST",
})
.then(async res => {
assert.strictEqual(res.status, 200);
testUserNameChangelog(user01PrivateUserID, decodeURIComponent('Changed%20Username'), username01, false, done);
testUserNameChangelog(user01PrivateUserID, decodeURIComponent("Changed%20Username"), username01, false, done);
})
.catch(() => done(`couldn't call endpoint`));
});
it('Should return 400 for missing param "userID"', (done: Done) => {
fetch(`${getbaseURL()}/api/setUsername?username=MyUsername`, {
method: 'POST',
method: "POST",
})
.then(res => {
assert.strictEqual(res.status, 400);
@@ -108,7 +108,7 @@ describe('setUsername', () => {
it('Should return 400 for missing param "username"', (done: Done) => {
fetch(`${getbaseURL()}/api/setUsername?userID=test`, {
method: 'POST',
method: "POST",
})
.then(res => {
assert.strictEqual(res.status, 400);
@@ -118,9 +118,9 @@ describe('setUsername', () => {
});
it('Should return 400 for "username" longer then 64 characters', (done: Done) => {
const username65 = '0000000000000000000000000000000000000000000000000000000000000000X';
const username65 = "0000000000000000000000000000000000000000000000000000000000000000X";
fetch(`${getbaseURL()}/api/setUsername?userID=test&username=${encodeURIComponent(username65)}`, {
method: 'POST',
method: "POST",
})
.then(res => {
assert.strictEqual(res.status, 400);
@@ -130,9 +130,9 @@ describe('setUsername', () => {
});
it('Should not change username if it contains "discord"', (done: Done) => {
const newUsername = 'discord.me';
const newUsername = "discord.me";
fetch(`${getbaseURL()}/api/setUsername?userID=${user02PrivateUserID}&username=${encodeURIComponent(newUsername)}`, {
method: 'POST',
method: "POST",
})
.then(async res => {
assert.strictEqual(res.status, 200);
@@ -143,10 +143,10 @@ describe('setUsername', () => {
.catch(() => done(`couldn't call endpoint`));
});
it('Should be able to change username', (done: Done) => {
const newUsername = 'newUsername';
it("Should be able to change username", (done: Done) => {
const newUsername = "newUsername";
fetch(`${getbaseURL()}/api/setUsername?userID=${user03PrivateUserID}&username=${encodeURIComponent(newUsername)}`, {
method: 'POST',
method: "POST",
})
.then(async () => {
const usernameInfo = await getUsernameInfo(getHash(user03PrivateUserID));
@@ -157,10 +157,10 @@ describe('setUsername', () => {
.catch(() => done(`couldn't call endpoint`));
});
it('Should not be able to change locked username', (done: Done) => {
const newUsername = 'newUsername';
it("Should not be able to change locked username", (done: Done) => {
const newUsername = "newUsername";
fetch(`${getbaseURL()}/api/setUsername?userID=${user04PrivateUserID}&username=${encodeURIComponent(newUsername)}`, {
method: 'POST',
method: "POST",
})
.then(async () => {
const usernameInfo = await getUsernameInfo(getHash(user04PrivateUserID));
@@ -171,10 +171,10 @@ describe('setUsername', () => {
.catch(() => done(`couldn't call endpoint`));
});
it('Should filter out unicode control characters', (done: Done) => {
const newUsername = 'This\nUsername+has\tInvalid+Characters';
it("Should filter out unicode control characters", (done: Done) => {
const newUsername = "This\nUsername+has\tInvalid+Characters";
fetch(`${getbaseURL()}/api/setUsername?userID=${user05PrivateUserID}&username=${encodeURIComponent(newUsername)}`, {
method: 'POST',
method: "POST",
})
.then(async () => {
const usernameInfo = await getUsernameInfo(getHash(user05PrivateUserID));
@@ -184,10 +184,10 @@ describe('setUsername', () => {
.catch(() => done(`couldn't call endpoint`));
});
it('Incorrect adminUserID should return 403', (done: Done) => {
const newUsername = 'New Username';
it("Incorrect adminUserID should return 403", (done: Done) => {
const newUsername = "New Username";
fetch(`${getbaseURL()}/api/setUsername?adminUserID=invalidAdminID&userID=${getHash(user06PrivateUserID)}&username=${encodeURIComponent(newUsername)}`, {
method: 'POST',
method: "POST",
})
.then(async res => {
assert.strictEqual(res.status, 403);
@@ -196,10 +196,10 @@ describe('setUsername', () => {
.catch(() => done(`couldn't call endpoint`));
});
it('Admin should be able to change username', (done: Done) => {
const newUsername = 'New Username';
it("Admin should be able to change username", (done: Done) => {
const newUsername = "New Username";
fetch(`${getbaseURL()}/api/setUsername?adminUserID=${adminPrivateUserID}&userID=${getHash(user06PrivateUserID)}&username=${encodeURIComponent(newUsername)}`, {
method: 'POST',
method: "POST",
})
.then(async () => {
const usernameInfo = await getUsernameInfo(getHash(user06PrivateUserID));
@@ -210,10 +210,10 @@ describe('setUsername', () => {
.catch(() => done(`couldn't call endpoint`));
});
it('Admin should be able to change locked username', (done: Done) => {
const newUsername = 'New Username';
it("Admin should be able to change locked username", (done: Done) => {
const newUsername = "New Username";
fetch(`${getbaseURL()}/api/setUsername?adminUserID=${adminPrivateUserID}&userID=${getHash(user07PrivateUserID)}&username=${encodeURIComponent(newUsername)}`, {
method: 'POST',
method: "POST",
})
.then(async () => {
const usernameInfo = await getUsernameInfo(getHash(user06PrivateUserID));

View File

@@ -1,37 +1,38 @@
import fetch from 'node-fetch';
import {db} from '../../src/databases/databases';
import {Done, getbaseURL} from '../utils';
import {getHash} from '../../src/utils/getHash';
import assert from 'assert';
import fetch from "node-fetch";
import {db} from "../../src/databases/databases";
import {Done, getbaseURL} from "../utils";
import {getHash} from "../../src/utils/getHash";
import assert from "assert";
describe('shadowBanUser', () => {
describe("shadowBanUser", () => {
before(async () => {
const insertQuery = `INSERT INTO "sponsorTimes" ("videoID", "startTime", "endTime", "votes", "locked", "UUID", "userID", "timeSubmitted", "views", "category", "service", "videoDuration", "hidden", "shadowHidden", "hashedVideoID") VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`;
await db.prepare("run", insertQuery, ['testtesttest', 1, 11, 2, 0, 'shadow-1-uuid-0', 'shadowBanned', 0, 50, 'sponsor', 'YouTube', 100, 0, 0, getHash('testtesttest', 1)]);
await db.prepare("run", insertQuery, ['testtesttest2', 1, 11, 2, 0, 'shadow-1-uuid-0-1', 'shadowBanned', 0, 50, 'sponsor', 'PeerTube', 120, 0, 0, getHash('testtesttest2', 1)]);
await db.prepare("run", insertQuery, ['testtesttest', 20, 33, 2, 0, 'shadow-1-uuid-2', 'shadowBanned', 0, 50, 'intro', 'YouTube', 101, 0, 0, getHash('testtesttest', 1)]);
await db.prepare("run", insertQuery, ["testtesttest", 1, 11, 2, 0, "shadow-1-uuid-0", "shadowBanned", 0, 50, "sponsor", "YouTube", 100, 0, 0, getHash("testtesttest", 1)]);
await db.prepare("run", insertQuery, ["testtesttest2", 1, 11, 2, 0, "shadow-1-uuid-0-1", "shadowBanned", 0, 50, "sponsor", "PeerTube", 120, 0, 0, getHash("testtesttest2", 1)]);
await db.prepare("run", insertQuery, ["testtesttest", 20, 33, 2, 0, "shadow-1-uuid-2", "shadowBanned", 0, 50, "intro", "YouTube", 101, 0, 0, getHash("testtesttest", 1)]);
await db.prepare("run", insertQuery, ['testtesttest', 1, 11, 2, 0, 'shadow-2-uuid-0', 'shadowBanned2', 0, 50, 'sponsor', 'YouTube', 100, 0, 0, getHash('testtesttest', 1)]);
await db.prepare("run", insertQuery, ['testtesttest2', 1, 11, 2, 0, 'shadow-2-uuid-0-1', 'shadowBanned2', 0, 50, 'sponsor', 'PeerTube', 120, 0, 0, getHash('testtesttest2', 1)]);
await db.prepare("run", insertQuery, ['testtesttest', 20, 33, 2, 0, 'shadow-2-uuid-2', 'shadowBanned2', 0, 50, 'intro', 'YouTube', 101, 0, 0, getHash('testtesttest', 1)]);
await db.prepare("run", insertQuery, ["testtesttest", 1, 11, 2, 0, "shadow-2-uuid-0", "shadowBanned2", 0, 50, "sponsor", "YouTube", 100, 0, 0, getHash("testtesttest", 1)]);
await db.prepare("run", insertQuery, ["testtesttest2", 1, 11, 2, 0, "shadow-2-uuid-0-1", "shadowBanned2", 0, 50, "sponsor", "PeerTube", 120, 0, 0, getHash("testtesttest2", 1)]);
await db.prepare("run", insertQuery, ["testtesttest", 20, 33, 2, 0, "shadow-2-uuid-2", "shadowBanned2", 0, 50, "intro", "YouTube", 101, 0, 0, getHash("testtesttest", 1)]);
await db.prepare("run", insertQuery, ['testtesttest', 1, 11, 2, 0, 'shadow-3-uuid-0', 'shadowBanned3', 0, 50, 'sponsor', 'YouTube', 100, 0, 1, getHash('testtesttest', 1)]);
await db.prepare("run", insertQuery, ['testtesttest2', 1, 11, 2, 0, 'shadow-3-uuid-0-1', 'shadowBanned3', 0, 50, 'sponsor', 'PeerTube', 120, 0, 1, getHash('testtesttest2', 1)]);
await db.prepare("run", insertQuery, ['testtesttest', 20, 33, 2, 0, 'shadow-3-uuid-2', 'shadowBanned3', 0, 50, 'intro', 'YouTube', 101, 0, 1, getHash('testtesttest', 1)]);
await db.prepare("run", `INSERT INTO "shadowBannedUsers" ("userID") VALUES(?)`, ['shadowBanned3']);
await db.prepare("run", insertQuery, ["testtesttest", 1, 11, 2, 0, "shadow-3-uuid-0", "shadowBanned3", 0, 50, "sponsor", "YouTube", 100, 0, 1, getHash("testtesttest", 1)]);
await db.prepare("run", insertQuery, ["testtesttest2", 1, 11, 2, 0, "shadow-3-uuid-0-1", "shadowBanned3", 0, 50, "sponsor", "PeerTube", 120, 0, 1, getHash("testtesttest2", 1)]);
await db.prepare("run", insertQuery, ["testtesttest", 20, 33, 2, 0, "shadow-3-uuid-2", "shadowBanned3", 0, 50, "intro", "YouTube", 101, 0, 1, getHash("testtesttest", 1)]);
await db.prepare("run", `INSERT INTO "shadowBannedUsers" ("userID") VALUES(?)`, ["shadowBanned3"]);
await db.prepare("run", `INSERT INTO "vipUsers" ("userID") VALUES(?)`, [getHash("shadow-ban-vip")]);
});
it('Should be able to ban user and hide submissions', (done: Done) => {
fetch(getbaseURL() + "/api/shadowBanUser?userID=shadowBanned&adminUserID=shadow-ban-vip", {
method: 'POST'
it("Should be able to ban user and hide submissions", (done: Done) => {
fetch(`${getbaseURL()
}/api/shadowBanUser?userID=shadowBanned&adminUserID=shadow-ban-vip`, {
method: "POST"
})
.then(async res => {
assert.strictEqual(res.status, 200);
const videoRow = await db.prepare('all', `SELECT "shadowHidden" FROM "sponsorTimes" WHERE "userID" = ? AND "shadowHidden" = ?`, ["shadowBanned", 1]);
const shadowRow = await db.prepare('get', `SELECT * FROM "shadowBannedUsers" WHERE "userID" = ?`, ["shadowBanned"]);
const videoRow = await db.prepare("all", `SELECT "shadowHidden" FROM "sponsorTimes" WHERE "userID" = ? AND "shadowHidden" = ?`, ["shadowBanned", 1]);
const shadowRow = await db.prepare("get", `SELECT * FROM "shadowBannedUsers" WHERE "userID" = ?`, ["shadowBanned"]);
assert.ok(shadowRow);
assert.strictEqual(videoRow.length, 3);
done();
@@ -39,14 +40,15 @@ describe('shadowBanUser', () => {
.catch(err => done(err));
});
it('Should be able to unban user without unhiding submissions', (done: Done) => {
fetch(getbaseURL() + "/api/shadowBanUser?userID=shadowBanned&adminUserID=shadow-ban-vip&enabled=false&unHideOldSubmissions=false", {
method: 'POST'
it("Should be able to unban user without unhiding submissions", (done: Done) => {
fetch(`${getbaseURL()
}/api/shadowBanUser?userID=shadowBanned&adminUserID=shadow-ban-vip&enabled=false&unHideOldSubmissions=false`, {
method: "POST"
})
.then(async res => {
assert.strictEqual(res.status, 200);
const videoRow = await db.prepare('all', `SELECT "shadowHidden" FROM "sponsorTimes" WHERE "userID" = ? AND "shadowHidden" = ?`, ["shadowBanned", 1]);
const shadowRow = await db.prepare('get', `SELECT * FROM "shadowBannedUsers" WHERE "userID" = ?`, ["shadowBanned"]);
const videoRow = await db.prepare("all", `SELECT "shadowHidden" FROM "sponsorTimes" WHERE "userID" = ? AND "shadowHidden" = ?`, ["shadowBanned", 1]);
const shadowRow = await db.prepare("get", `SELECT * FROM "shadowBannedUsers" WHERE "userID" = ?`, ["shadowBanned"]);
assert.ok(!shadowRow);
assert.strictEqual(videoRow.length, 3);
done();
@@ -54,14 +56,15 @@ describe('shadowBanUser', () => {
.catch(err => done(err));
});
it('Should be able to ban user and hide submissions from only some categories', (done: Done) => {
fetch(getbaseURL() + '/api/shadowBanUser?userID=shadowBanned2&adminUserID=shadow-ban-vip&categories=["sponsor"]', {
method: 'POST'
it("Should be able to ban user and hide submissions from only some categories", (done: Done) => {
fetch(`${getbaseURL()
}/api/shadowBanUser?userID=shadowBanned2&adminUserID=shadow-ban-vip&categories=["sponsor"]`, {
method: "POST"
})
.then(async res => {
assert.strictEqual(res.status, 200);
const videoRow: {category: string, shadowHidden: number}[] = (await db.prepare('all', `SELECT "shadowHidden", "category" FROM "sponsorTimes" WHERE "userID" = ? AND "shadowHidden" = ?`, ["shadowBanned2", 1]));
const shadowRow = await db.prepare('get', `SELECT * FROM "shadowBannedUsers" WHERE "userID" = ?`, ["shadowBanned2"]);
const videoRow: {category: string, shadowHidden: number}[] = (await db.prepare("all", `SELECT "shadowHidden", "category" FROM "sponsorTimes" WHERE "userID" = ? AND "shadowHidden" = ?`, ["shadowBanned2", 1]));
const shadowRow = await db.prepare("get", `SELECT * FROM "shadowBannedUsers" WHERE "userID" = ?`, ["shadowBanned2"]);
assert.ok(shadowRow);
assert.strictEqual(videoRow.length, 2);
assert.strictEqual(videoRow.filter((elem) => elem.category === "sponsor").length, 2);
@@ -70,14 +73,15 @@ describe('shadowBanUser', () => {
.catch(err => done(err));
});
it('Should be able to unban user and unhide submissions', (done: Done) => {
fetch(getbaseURL() + "/api/shadowBanUser?userID=shadowBanned2&adminUserID=shadow-ban-vip&enabled=false", {
method: 'POST'
it("Should be able to unban user and unhide submissions", (done: Done) => {
fetch(`${getbaseURL()
}/api/shadowBanUser?userID=shadowBanned2&adminUserID=shadow-ban-vip&enabled=false`, {
method: "POST"
})
.then(async res => {
assert.strictEqual(res.status, 200);
const videoRow = await db.prepare('all', `SELECT "shadowHidden" FROM "sponsorTimes" WHERE "userID" = ? AND "shadowHidden" = ?`, ["shadowBanned2", 1]);
const shadowRow = await db.prepare('get', `SELECT * FROM "shadowBannedUsers" WHERE "userID" = ?`, ["shadowBanned2"]);
const videoRow = await db.prepare("all", `SELECT "shadowHidden" FROM "sponsorTimes" WHERE "userID" = ? AND "shadowHidden" = ?`, ["shadowBanned2", 1]);
const shadowRow = await db.prepare("get", `SELECT * FROM "shadowBannedUsers" WHERE "userID" = ?`, ["shadowBanned2"]);
assert.ok(!shadowRow);
assert.strictEqual(videoRow?.length, 0);
done();
@@ -85,14 +89,15 @@ describe('shadowBanUser', () => {
.catch(err => done(err));
});
it('Should be able to unban user and unhide some submissions', (done: Done) => {
fetch(getbaseURL() + `/api/shadowBanUser?userID=shadowBanned3&adminUserID=shadow-ban-vip&enabled=false&categories=["sponsor"]`, {
method: 'POST'
it("Should be able to unban user and unhide some submissions", (done: Done) => {
fetch(`${getbaseURL()
}/api/shadowBanUser?userID=shadowBanned3&adminUserID=shadow-ban-vip&enabled=false&categories=["sponsor"]`, {
method: "POST"
})
.then(async res => {
assert.strictEqual(res.status, 200);
const videoRow = await db.prepare('all', `SELECT "shadowHidden", "category" FROM "sponsorTimes" WHERE "userID" = ? AND "shadowHidden" = ?`, ["shadowBanned3", 1]);
const shadowRow = await db.prepare('get', `SELECT * FROM "shadowBannedUsers" WHERE "userID" = ?`, ["shadowBanned3"]);
const videoRow = await db.prepare("all", `SELECT "shadowHidden", "category" FROM "sponsorTimes" WHERE "userID" = ? AND "shadowHidden" = ?`, ["shadowBanned3", 1]);
const shadowRow = await db.prepare("get", `SELECT * FROM "shadowBannedUsers" WHERE "userID" = ?`, ["shadowBanned3"]);
assert.ok(!shadowRow);
assert.strictEqual(videoRow.length, 1);
assert.strictEqual(videoRow[0].category, "intro");

View File

@@ -1,71 +1,74 @@
import fetch from 'node-fetch';
import * as utils from '../utils';
import { getHash } from '../../src/utils/getHash';
import { db } from '../../src/databases/databases';
import assert from 'assert';
import fetch from "node-fetch";
import * as utils from "../utils";
import { getHash } from "../../src/utils/getHash";
import { db } from "../../src/databases/databases";
import assert from "assert";
describe('unBan', () => {
describe("unBan", () => {
before(async () => {
const insertShadowBannedUserQuery = 'INSERT INTO "shadowBannedUsers" VALUES(?)';
await db.prepare("run", insertShadowBannedUserQuery, ['testMan-unBan']);
await db.prepare("run", insertShadowBannedUserQuery, ['testWoman-unBan']);
await db.prepare("run", insertShadowBannedUserQuery, ['testEntity-unBan']);
await db.prepare("run", insertShadowBannedUserQuery, ["testMan-unBan"]);
await db.prepare("run", insertShadowBannedUserQuery, ["testWoman-unBan"]);
await db.prepare("run", insertShadowBannedUserQuery, ["testEntity-unBan"]);
const insertVipUserQuery = 'INSERT INTO "vipUsers" ("userID") VALUES (?)';
await db.prepare("run", insertVipUserQuery, [getHash("VIPUser-unBan")]);
const insertLockCategoryQuery = 'INSERT INTO "lockCategories" ("userID", "videoID", "category") VALUES(?, ?, ?)';
await db.prepare("run", insertLockCategoryQuery, [getHash("VIPUser-unBan"), 'unBan-videoID-1', 'sponsor']);
await db.prepare("run", insertLockCategoryQuery, [getHash("VIPUser-unBan"), "unBan-videoID-1", "sponsor"]);
const insertSponsorTimeQuery = 'INSERT INTO "sponsorTimes" ("videoID", "startTime", "endTime", "votes", "UUID", "userID", "timeSubmitted", views, category, "shadowHidden", "hashedVideoID") VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)';
await db.prepare("run", insertSponsorTimeQuery, ['unBan-videoID-0', 1, 11, 2, 'unBan-uuid-0', 'testMan-unBan', 0, 50, 'sponsor', 1, getHash('unBan-videoID-0', 1)]);
await db.prepare("run", insertSponsorTimeQuery, ['unBan-videoID-1', 1, 11, 2, 'unBan-uuid-1', 'testWoman-unBan', 0, 50, 'sponsor', 1, getHash('unBan-videoID-1', 1)]);
await db.prepare("run", insertSponsorTimeQuery, ['unBan-videoID-1', 1, 11, 2, 'unBan-uuid-2', 'testEntity-unBan', 0, 60, 'sponsor', 1, getHash('unBan-videoID-1', 1)]);
await db.prepare("run", insertSponsorTimeQuery, ['unBan-videoID-2', 1, 11, 2, 'unBan-uuid-3', 'testEntity-unBan', 0, 60, 'sponsor', 1, getHash('unBan-videoID-2', 1)]);
await db.prepare("run", insertSponsorTimeQuery, ["unBan-videoID-0", 1, 11, 2, "unBan-uuid-0", "testMan-unBan", 0, 50, "sponsor", 1, getHash("unBan-videoID-0", 1)]);
await db.prepare("run", insertSponsorTimeQuery, ["unBan-videoID-1", 1, 11, 2, "unBan-uuid-1", "testWoman-unBan", 0, 50, "sponsor", 1, getHash("unBan-videoID-1", 1)]);
await db.prepare("run", insertSponsorTimeQuery, ["unBan-videoID-1", 1, 11, 2, "unBan-uuid-2", "testEntity-unBan", 0, 60, "sponsor", 1, getHash("unBan-videoID-1", 1)]);
await db.prepare("run", insertSponsorTimeQuery, ["unBan-videoID-2", 1, 11, 2, "unBan-uuid-3", "testEntity-unBan", 0, 60, "sponsor", 1, getHash("unBan-videoID-2", 1)]);
});
it('Should be able to unban a user and re-enable shadow banned segments', (done) => {
fetch(utils.getbaseURL() + "/api/shadowBanUser?userID=testMan-unBan&adminUserID=VIPUser-unBan&enabled=false", {
method: 'POST',
it("Should be able to unban a user and re-enable shadow banned segments", (done) => {
fetch(`${utils.getbaseURL()
}/api/shadowBanUser?userID=testMan-unBan&adminUserID=VIPUser-unBan&enabled=false`, {
method: "POST",
headers: {
'Content-Type': 'application/json',
"Content-Type": "application/json",
},
})
.then(async res => {
assert.strictEqual(res.status, 200);
const result = await db.prepare('all', 'SELECT * FROM "sponsorTimes" WHERE "videoID" = ? AND "userID" = ? AND "shadowHidden" = ?', ['unBan-videoID-0', 'testMan-unBan', 1]);
const result = await db.prepare("all", 'SELECT * FROM "sponsorTimes" WHERE "videoID" = ? AND "userID" = ? AND "shadowHidden" = ?', ["unBan-videoID-0", "testMan-unBan", 1]);
assert.strictEqual(result.length, 0);
done();
})
.catch(err => done(err));
});
it('Should be able to unban a user and re-enable shadow banned segments without lockCategories entrys', (done) => {
fetch(utils.getbaseURL() + "/api/shadowBanUser?userID=testWoman-unBan&adminUserID=VIPUser-unBan&enabled=false", {
method: 'POST',
it("Should be able to unban a user and re-enable shadow banned segments without lockCategories entrys", (done) => {
fetch(`${utils.getbaseURL()
}/api/shadowBanUser?userID=testWoman-unBan&adminUserID=VIPUser-unBan&enabled=false`, {
method: "POST",
headers: {
'Content-Type': 'application/json',
"Content-Type": "application/json",
},
})
.then(async res => {
assert.strictEqual(res.status, 200);
const result = await db.prepare('all', 'SELECT * FROM "sponsorTimes" WHERE "videoID" = ? AND "userID" = ? AND "shadowHidden" = ?', ['unBan-videoID-1', 'testWoman-unBan', 1]);
const result = await db.prepare("all", 'SELECT * FROM "sponsorTimes" WHERE "videoID" = ? AND "userID" = ? AND "shadowHidden" = ?', ["unBan-videoID-1", "testWoman-unBan", 1]);
assert.strictEqual(result.length, 1);
done();
})
.catch(err => done(err));
});
it('Should be able to unban a user and re-enable shadow banned segments with a mix of lockCategories entrys', (done) => {
fetch(utils.getbaseURL() + "/api/shadowBanUser?userID=testEntity-unBan&adminUserID=VIPUser-unBan&enabled=false", {
method: 'POST',
it("Should be able to unban a user and re-enable shadow banned segments with a mix of lockCategories entrys", (done) => {
fetch(`${utils.getbaseURL()
}/api/shadowBanUser?userID=testEntity-unBan&adminUserID=VIPUser-unBan&enabled=false`, {
method: "POST",
headers: {
'Content-Type': 'application/json',
"Content-Type": "application/json",
},
})
.then(async res => {
assert.strictEqual(res.status, 200);
const result = await db.prepare('all', 'SELECT * FROM "sponsorTimes" WHERE "userID" = ? AND "shadowHidden" = ?', ['testEntity-unBan', 1]);
const result = await db.prepare("all", 'SELECT * FROM "sponsorTimes" WHERE "userID" = ? AND "shadowHidden" = ?', ["testEntity-unBan", 1]);
assert.strictEqual(result.length, 1);
done();
})

View File

@@ -1,18 +1,18 @@
import fetch from 'node-fetch';
import {config} from '../../src/config';
import {db} from '../../src/databases/databases';
import {Done, getbaseURL} from '../utils';
import {getHash} from '../../src/utils/getHash';
import {ImportMock} from 'ts-mock-imports';
import * as YouTubeAPIModule from '../../src/utils/youtubeApi';
import {YouTubeApiMock} from '../youtubeMock';
import assert from 'assert';
import fetch from "node-fetch";
import {config} from "../../src/config";
import {db} from "../../src/databases/databases";
import {Done, getbaseURL} from "../utils";
import {getHash} from "../../src/utils/getHash";
import {ImportMock} from "ts-mock-imports";
import * as YouTubeAPIModule from "../../src/utils/youtubeApi";
import {YouTubeApiMock} from "../youtubeMock";
import assert from "assert";
const mockManager = ImportMock.mockStaticClass(YouTubeAPIModule, 'YouTubeAPI');
const sinonStub = mockManager.mock('listVideos');
const mockManager = ImportMock.mockStaticClass(YouTubeAPIModule, "YouTubeAPI");
const sinonStub = mockManager.mock("listVideos");
sinonStub.callsFake(YouTubeApiMock.listVideos);
describe('voteOnSponsorTime', () => {
describe("voteOnSponsorTime", () => {
before(async () => {
const now = Date.now();
const warnVip01Hash = getHash("warn-vip01");
@@ -22,29 +22,29 @@ describe('voteOnSponsorTime', () => {
const warningExpireTime = MILLISECONDS_IN_HOUR * config.hoursAfterWarningExpires;
const insertSponsorTimeQuery = 'INSERT INTO "sponsorTimes" ("videoID", "startTime", "endTime", "votes", "UUID", "userID", "timeSubmitted", "views", "category", "shadowHidden", "hidden", "hashedVideoID") VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)';
await db.prepare("run", insertSponsorTimeQuery, ['vote-testtesttest', 1, 11, 2, 'vote-uuid-0', 'testman', 0, 50, 'sponsor', 0, 0, getHash('vote-testtesttest', 1)]);
await db.prepare("run", insertSponsorTimeQuery, ['vote-testtesttest2', 1, 11, 2, 'vote-uuid-1', 'testman', 0, 50, 'sponsor', 0, 0, getHash('vote-testtesttest2', 1)]);
await db.prepare("run", insertSponsorTimeQuery, ['vote-testtesttest2', 1, 11, 10, 'vote-uuid-1.5', 'testman', 0, 50, 'outro', 0, 0, getHash('vote-testtesttest2', 1)]);
await db.prepare("run", insertSponsorTimeQuery, ['vote-testtesttest2', 1, 11, 10, 'vote-uuid-1.6', 'testman', 0, 50, 'interaction', 0, 0, getHash('vote-testtesttest2', 1)]);
await db.prepare("run", insertSponsorTimeQuery, ['vote-testtesttest3', 20, 33, 10, 'vote-uuid-2', 'testman', 0, 50, 'intro', 0, 0, getHash('vote-testtesttest3', 1)]);
await db.prepare("run", insertSponsorTimeQuery, ['vote-testtesttest,test', 1, 11, 100, 'vote-uuid-3', 'testman', 0, 50, 'sponsor', 0, 0, getHash('vote-testtesttest,test', 1)]);
await db.prepare("run", insertSponsorTimeQuery, ['vote-test3', 1, 11, 2, 'vote-uuid-4', 'testman', 0, 50, 'sponsor', 0, 0, getHash('vote-test3', 1)]);
await db.prepare("run", insertSponsorTimeQuery, ['vote-test3', 7, 22, -3, 'vote-uuid-5', 'testman', 0, 50, 'intro', 0, 0, getHash('vote-test3', 1)]);
await db.prepare("run", insertSponsorTimeQuery, ['vote-test3', 7, 22, -3, 'vote-uuid-5_1', 'testman', 0, 50, 'intro', 0, 0, getHash('vote-test3', 1)]);
await db.prepare("run", insertSponsorTimeQuery, ['vote-multiple', 1, 11, 2, 'vote-uuid-6', 'testman', 0, 50, 'intro', 0, 0, getHash('vote-multiple', 1)]);
await db.prepare("run", insertSponsorTimeQuery, ['vote-multiple', 20, 33, 2, 'vote-uuid-7', 'testman', 0, 50, 'intro', 0, 0, getHash('vote-multiple', 1)]);
await db.prepare("run", insertSponsorTimeQuery, ['voter-submitter', 1, 11, 2, 'vote-uuid-8', getHash("randomID"), 0, 50, 'sponsor', 0, 0, getHash('voter-submitter', 1)]);
await db.prepare("run", insertSponsorTimeQuery, ['voter-submitter2', 1, 11, 2, 'vote-uuid-9', getHash("randomID2"), 0, 50, 'sponsor', 0, 0, getHash('voter-submitter2', 1)]);
await db.prepare("run", insertSponsorTimeQuery, ['voter-submitter2', 1, 11, 2, 'vote-uuid-10', getHash("randomID3"), 0, 50, 'sponsor', 0, 0, getHash('voter-submitter2', 1)]);
await db.prepare("run", insertSponsorTimeQuery, ['voter-submitter2', 1, 11, 2, 'vote-uuid-11', getHash("randomID4"), 0, 50, 'sponsor', 0, 0, getHash('voter-submitter2', 1)]);
await db.prepare("run", insertSponsorTimeQuery, ['own-submission-video', 1, 11, 500, 'own-submission-uuid', getHash('own-submission-id'), 0, 50, 'sponsor', 0, 0, getHash('own-submission-video', 1)]);
await db.prepare("run", insertSponsorTimeQuery, ['not-own-submission-video', 1, 11, 500, 'not-own-submission-uuid', getHash('somebody-else-id'), 0, 50, 'sponsor', 0, 0, getHash('not-own-submission-video', 1)]);
await db.prepare("run", insertSponsorTimeQuery, ['incorrect-category', 1, 11, 500, 'incorrect-category', getHash('somebody-else-id'), 0, 50, 'sponsor', 0, 0, getHash('incorrect-category', 1)]);
await db.prepare("run", insertSponsorTimeQuery, ['incorrect-category-change', 1, 11, 500, 'incorrect-category-change', getHash('somebody-else-id'), 0, 50, 'sponsor', 0, 0, getHash('incorrect-category-change', 1)]);
await db.prepare("run", insertSponsorTimeQuery, ['vote-testtesttest', 1, 11, 2, 'warnvote-uuid-0', 'testman', 0, 50, 'sponsor', 0, 0, getHash('vote-testtesttest', 1)]);
await db.prepare("run", insertSponsorTimeQuery, ['no-sponsor-segments-video', 1, 11, 2, 'no-sponsor-segments-uuid-0', 'no-sponsor-segments', 0, 50, 'sponsor', 0, 0, getHash('no-sponsor-segments-video', 1)]);
await db.prepare("run", insertSponsorTimeQuery, ['no-sponsor-segments-video', 1, 11, 2, 'no-sponsor-segments-uuid-1', 'no-sponsor-segments', 0, 50, 'intro', 0, 0, getHash('no-sponsor-segments-video', 1)]);
await db.prepare("run", insertSponsorTimeQuery, ['segment-locking-video', 1, 11, 2, 'segment-locking-uuid-1', 'segment-locking-user', 0, 50, 'intro', 0, 0, getHash('segment-locking-video', 1)]);
await db.prepare("run", insertSponsorTimeQuery, ["vote-testtesttest", 1, 11, 2, "vote-uuid-0", "testman", 0, 50, "sponsor", 0, 0, getHash("vote-testtesttest", 1)]);
await db.prepare("run", insertSponsorTimeQuery, ["vote-testtesttest2", 1, 11, 2, "vote-uuid-1", "testman", 0, 50, "sponsor", 0, 0, getHash("vote-testtesttest2", 1)]);
await db.prepare("run", insertSponsorTimeQuery, ["vote-testtesttest2", 1, 11, 10, "vote-uuid-1.5", "testman", 0, 50, "outro", 0, 0, getHash("vote-testtesttest2", 1)]);
await db.prepare("run", insertSponsorTimeQuery, ["vote-testtesttest2", 1, 11, 10, "vote-uuid-1.6", "testman", 0, 50, "interaction", 0, 0, getHash("vote-testtesttest2", 1)]);
await db.prepare("run", insertSponsorTimeQuery, ["vote-testtesttest3", 20, 33, 10, "vote-uuid-2", "testman", 0, 50, "intro", 0, 0, getHash("vote-testtesttest3", 1)]);
await db.prepare("run", insertSponsorTimeQuery, ["vote-testtesttest,test", 1, 11, 100, "vote-uuid-3", "testman", 0, 50, "sponsor", 0, 0, getHash("vote-testtesttest,test", 1)]);
await db.prepare("run", insertSponsorTimeQuery, ["vote-test3", 1, 11, 2, "vote-uuid-4", "testman", 0, 50, "sponsor", 0, 0, getHash("vote-test3", 1)]);
await db.prepare("run", insertSponsorTimeQuery, ["vote-test3", 7, 22, -3, "vote-uuid-5", "testman", 0, 50, "intro", 0, 0, getHash("vote-test3", 1)]);
await db.prepare("run", insertSponsorTimeQuery, ["vote-test3", 7, 22, -3, "vote-uuid-5_1", "testman", 0, 50, "intro", 0, 0, getHash("vote-test3", 1)]);
await db.prepare("run", insertSponsorTimeQuery, ["vote-multiple", 1, 11, 2, "vote-uuid-6", "testman", 0, 50, "intro", 0, 0, getHash("vote-multiple", 1)]);
await db.prepare("run", insertSponsorTimeQuery, ["vote-multiple", 20, 33, 2, "vote-uuid-7", "testman", 0, 50, "intro", 0, 0, getHash("vote-multiple", 1)]);
await db.prepare("run", insertSponsorTimeQuery, ["voter-submitter", 1, 11, 2, "vote-uuid-8", getHash("randomID"), 0, 50, "sponsor", 0, 0, getHash("voter-submitter", 1)]);
await db.prepare("run", insertSponsorTimeQuery, ["voter-submitter2", 1, 11, 2, "vote-uuid-9", getHash("randomID2"), 0, 50, "sponsor", 0, 0, getHash("voter-submitter2", 1)]);
await db.prepare("run", insertSponsorTimeQuery, ["voter-submitter2", 1, 11, 2, "vote-uuid-10", getHash("randomID3"), 0, 50, "sponsor", 0, 0, getHash("voter-submitter2", 1)]);
await db.prepare("run", insertSponsorTimeQuery, ["voter-submitter2", 1, 11, 2, "vote-uuid-11", getHash("randomID4"), 0, 50, "sponsor", 0, 0, getHash("voter-submitter2", 1)]);
await db.prepare("run", insertSponsorTimeQuery, ["own-submission-video", 1, 11, 500, "own-submission-uuid", getHash("own-submission-id"), 0, 50, "sponsor", 0, 0, getHash("own-submission-video", 1)]);
await db.prepare("run", insertSponsorTimeQuery, ["not-own-submission-video", 1, 11, 500, "not-own-submission-uuid", getHash("somebody-else-id"), 0, 50, "sponsor", 0, 0, getHash("not-own-submission-video", 1)]);
await db.prepare("run", insertSponsorTimeQuery, ["incorrect-category", 1, 11, 500, "incorrect-category", getHash("somebody-else-id"), 0, 50, "sponsor", 0, 0, getHash("incorrect-category", 1)]);
await db.prepare("run", insertSponsorTimeQuery, ["incorrect-category-change", 1, 11, 500, "incorrect-category-change", getHash("somebody-else-id"), 0, 50, "sponsor", 0, 0, getHash("incorrect-category-change", 1)]);
await db.prepare("run", insertSponsorTimeQuery, ["vote-testtesttest", 1, 11, 2, "warnvote-uuid-0", "testman", 0, 50, "sponsor", 0, 0, getHash("vote-testtesttest", 1)]);
await db.prepare("run", insertSponsorTimeQuery, ["no-sponsor-segments-video", 1, 11, 2, "no-sponsor-segments-uuid-0", "no-sponsor-segments", 0, 50, "sponsor", 0, 0, getHash("no-sponsor-segments-video", 1)]);
await db.prepare("run", insertSponsorTimeQuery, ["no-sponsor-segments-video", 1, 11, 2, "no-sponsor-segments-uuid-1", "no-sponsor-segments", 0, 50, "intro", 0, 0, getHash("no-sponsor-segments-video", 1)]);
await db.prepare("run", insertSponsorTimeQuery, ["segment-locking-video", 1, 11, 2, "segment-locking-uuid-1", "segment-locking-user", 0, 50, "intro", 0, 0, getHash("segment-locking-video", 1)]);
const insertWarningQuery = 'INSERT INTO "warnings" ("userID", "issueTime", "issuerUserID", "enabled") VALUES(?, ?, ?, ?)';
await db.prepare("run", insertWarningQuery, [warnUser01Hash, now, warnVip01Hash, 1]);
@@ -60,39 +60,39 @@ describe('voteOnSponsorTime', () => {
await db.prepare("run", 'INSERT INTO "vipUsers" ("userID") VALUES (?)', [getHash("VIPUser")]);
await db.prepare("run", 'INSERT INTO "shadowBannedUsers" ("userID") VALUES (?)', [getHash("randomID4")]);
await db.prepare("run", 'INSERT INTO "lockCategories" ("videoID", "userID", "category") VALUES (?, ?, ?)', ['no-sponsor-segments-video', 'someUser', 'sponsor']);
await db.prepare("run", 'INSERT INTO "lockCategories" ("videoID", "userID", "category") VALUES (?, ?, ?)', ["no-sponsor-segments-video", "someUser", "sponsor"]);
});
it('Should be able to upvote a segment', (done: Done) => {
fetch(getbaseURL()
+ "/api/voteOnSponsorTime?userID=randomID&UUID=vote-uuid-0&type=1")
it("Should be able to upvote a segment", (done: Done) => {
fetch(`${getbaseURL()
}/api/voteOnSponsorTime?userID=randomID&UUID=vote-uuid-0&type=1`)
.then(async res => {
assert.strictEqual(res.status, 200);
const row = await db.prepare('get', `SELECT "votes" FROM "sponsorTimes" WHERE "UUID" = ?`, ["vote-uuid-0"]);
const row = await db.prepare("get", `SELECT "votes" FROM "sponsorTimes" WHERE "UUID" = ?`, ["vote-uuid-0"]);
assert.strictEqual(row.votes, 3);
done();
})
.catch(err => done(err));
});
it('Should be able to downvote a segment', (done: Done) => {
fetch(getbaseURL()
+ "/api/voteOnSponsorTime?userID=randomID2&UUID=vote-uuid-2&type=0")
it("Should be able to downvote a segment", (done: Done) => {
fetch(`${getbaseURL()
}/api/voteOnSponsorTime?userID=randomID2&UUID=vote-uuid-2&type=0`)
.then(async res => {
assert.strictEqual(res.status, 200);
const row = await db.prepare('get', `SELECT "votes" FROM "sponsorTimes" WHERE "UUID" = ?`, ["vote-uuid-2"]);
const row = await db.prepare("get", `SELECT "votes" FROM "sponsorTimes" WHERE "UUID" = ?`, ["vote-uuid-2"]);
assert.ok(row.votes < 10);
done();
})
.catch(err => done(err));
});
it('Should not be able to downvote the same segment when voting from a different user on the same IP', (done: Done) => {
fetch(getbaseURL()
+ "/api/voteOnSponsorTime?userID=randomID3&UUID=vote-uuid-2&type=0")
it("Should not be able to downvote the same segment when voting from a different user on the same IP", (done: Done) => {
fetch(`${getbaseURL()
}/api/voteOnSponsorTime?userID=randomID3&UUID=vote-uuid-2&type=0`)
.then(async res => {
assert.strictEqual(res.status, 200);
const row = await db.prepare('get', `SELECT "votes" FROM "sponsorTimes" WHERE "UUID" = ?`, ["vote-uuid-2"]);
const row = await db.prepare("get", `SELECT "votes" FROM "sponsorTimes" WHERE "UUID" = ?`, ["vote-uuid-2"]);
assert.strictEqual(row.votes, 9);
done();
})
@@ -100,11 +100,11 @@ describe('voteOnSponsorTime', () => {
});
it("Should not be able to downvote a segment if the user is shadow banned", (done: Done) => {
fetch(getbaseURL()
+ "/api/voteOnSponsorTime?userID=randomID4&UUID=vote-uuid-1.6&type=0")
fetch(`${getbaseURL()
}/api/voteOnSponsorTime?userID=randomID4&UUID=vote-uuid-1.6&type=0`)
.then(async res => {
assert.strictEqual(res.status, 200);
const row = await db.prepare('get', `SELECT "votes" FROM "sponsorTimes" WHERE "UUID" = ?`, ["vote-uuid-1.6"]);
const row = await db.prepare("get", `SELECT "votes" FROM "sponsorTimes" WHERE "UUID" = ?`, ["vote-uuid-1.6"]);
assert.strictEqual(row.votes, 10);
done();
})
@@ -112,11 +112,11 @@ describe('voteOnSponsorTime', () => {
});
it("Should not be able to upvote a segment if the user hasn't submitted yet", (done: Done) => {
fetch(getbaseURL()
+ "/api/voteOnSponsorTime?userID=hasNotSubmittedID&UUID=vote-uuid-1&type=1")
fetch(`${getbaseURL()
}/api/voteOnSponsorTime?userID=hasNotSubmittedID&UUID=vote-uuid-1&type=1`)
.then(async res => {
assert.strictEqual(res.status, 200);
const row = await db.prepare('get', `SELECT "votes" FROM "sponsorTimes" WHERE "UUID" = ?`, ["vote-uuid-1"]);
const row = await db.prepare("get", `SELECT "votes" FROM "sponsorTimes" WHERE "UUID" = ?`, ["vote-uuid-1"]);
assert.strictEqual(row.votes, 2);
done();
})
@@ -124,60 +124,60 @@ describe('voteOnSponsorTime', () => {
});
it("Should not be able to downvote a segment if the user hasn't submitted yet", (done: Done) => {
fetch(getbaseURL()
+ "/api/voteOnSponsorTime?userID=hasNotSubmittedID&UUID=vote-uuid-1.5&type=0")
fetch(`${getbaseURL()
}/api/voteOnSponsorTime?userID=hasNotSubmittedID&UUID=vote-uuid-1.5&type=0`)
.then(async res => {
assert.strictEqual(res.status, 200);
const row = await db.prepare('get', `SELECT "votes" FROM "sponsorTimes" WHERE "UUID" = ?`, ["vote-uuid-1.5"]);
const row = await db.prepare("get", `SELECT "votes" FROM "sponsorTimes" WHERE "UUID" = ?`, ["vote-uuid-1.5"]);
assert.strictEqual(row.votes, 10);
done();
})
.catch(err => done(err));
});
it('VIP should be able to completely downvote a segment', (done: Done) => {
fetch(getbaseURL()
+ "/api/voteOnSponsorTime?userID=VIPUser&UUID=vote-uuid-3&type=0")
it("VIP should be able to completely downvote a segment", (done: Done) => {
fetch(`${getbaseURL()
}/api/voteOnSponsorTime?userID=VIPUser&UUID=vote-uuid-3&type=0`)
.then(async res => {
assert.strictEqual(res.status, 200);
const row = await db.prepare('get', `SELECT "votes" FROM "sponsorTimes" WHERE "UUID" = ?`, ["vote-uuid-3"]);
const row = await db.prepare("get", `SELECT "votes" FROM "sponsorTimes" WHERE "UUID" = ?`, ["vote-uuid-3"]);
assert.ok(row.votes <= -2);
done();
})
.catch(err => done(err));
});
it('should be able to completely downvote your own segment', (done: Done) => {
fetch(getbaseURL()
+ "/api/voteOnSponsorTime?userID=own-submission-id&UUID=own-submission-uuid&type=0")
it("should be able to completely downvote your own segment", (done: Done) => {
fetch(`${getbaseURL()
}/api/voteOnSponsorTime?userID=own-submission-id&UUID=own-submission-uuid&type=0`)
.then(async res => {
assert.strictEqual(res.status, 200);
const row = await db.prepare('get', `SELECT "votes" FROM "sponsorTimes" WHERE "UUID" = ?`, ["own-submission-uuid"]);
const row = await db.prepare("get", `SELECT "votes" FROM "sponsorTimes" WHERE "UUID" = ?`, ["own-submission-uuid"]);
assert.ok(row.votes <= -2);
done();
})
.catch(err => done(err));
});
it('should not be able to completely downvote somebody elses segment', (done: Done) => {
fetch(getbaseURL()
+ "/api/voteOnSponsorTime?userID=randomID2&UUID=not-own-submission-uuid&type=0")
it("should not be able to completely downvote somebody elses segment", (done: Done) => {
fetch(`${getbaseURL()
}/api/voteOnSponsorTime?userID=randomID2&UUID=not-own-submission-uuid&type=0`)
.then(async res => {
assert.strictEqual(res.status, 200);
const row = await db.prepare('get', `SELECT "votes" FROM "sponsorTimes" WHERE "UUID" = ?`, ["not-own-submission-uuid"]);
const row = await db.prepare("get", `SELECT "votes" FROM "sponsorTimes" WHERE "UUID" = ?`, ["not-own-submission-uuid"]);
assert.strictEqual(row.votes, 499);
done();
})
.catch(err => done(err));
});
it('Should be able to vote for a category and it should add your vote to the database', (done: Done) => {
fetch(getbaseURL()
+ "/api/voteOnSponsorTime?userID=randomID2&UUID=vote-uuid-4&category=intro")
it("Should be able to vote for a category and it should add your vote to the database", (done: Done) => {
fetch(`${getbaseURL()
}/api/voteOnSponsorTime?userID=randomID2&UUID=vote-uuid-4&category=intro`)
.then(async res => {
assert.strictEqual(res.status, 200);
const row = await db.prepare('get', `SELECT "category" FROM "sponsorTimes" WHERE "UUID" = ?`, ["vote-uuid-4"]);
const categoryRows = await db.prepare('all', `SELECT votes, category FROM "categoryVotes" WHERE "UUID" = ?`, ["vote-uuid-4"]);
const row = await db.prepare("get", `SELECT "category" FROM "sponsorTimes" WHERE "UUID" = ?`, ["vote-uuid-4"]);
const categoryRows = await db.prepare("all", `SELECT votes, category FROM "categoryVotes" WHERE "UUID" = ?`, ["vote-uuid-4"]);
assert.strictEqual(row.category, "sponsor");
assert.strictEqual(categoryRows.length, 2);
assert.strictEqual(categoryRows[0].votes, 1);
@@ -189,37 +189,37 @@ describe('voteOnSponsorTime', () => {
.catch(err => done(err));
});
it('Should not able to change to an invalid category', (done: Done) => {
fetch(getbaseURL()
+ "/api/voteOnSponsorTime?userID=randomID2&UUID=incorrect-category&category=fakecategory")
it("Should not able to change to an invalid category", (done: Done) => {
fetch(`${getbaseURL()
}/api/voteOnSponsorTime?userID=randomID2&UUID=incorrect-category&category=fakecategory`)
.then(async res => {
assert.strictEqual(res.status, 400);
const row = await db.prepare('get', `SELECT "category" FROM "sponsorTimes" WHERE "UUID" = ?`, ["incorrect-category"]);
const row = await db.prepare("get", `SELECT "category" FROM "sponsorTimes" WHERE "UUID" = ?`, ["incorrect-category"]);
assert.strictEqual(row.category, "sponsor");
done();
})
.catch(err => done(err));
});
it('Should not able to change to highlight category', (done: Done) => {
fetch(getbaseURL()
+ "/api/voteOnSponsorTime?userID=randomID2&UUID=incorrect-category&category=highlight")
it("Should not able to change to highlight category", (done: Done) => {
fetch(`${getbaseURL()
}/api/voteOnSponsorTime?userID=randomID2&UUID=incorrect-category&category=highlight`)
.then(async res => {
assert.strictEqual(res.status, 400);
const row = await db.prepare('get', `SELECT "category" FROM "sponsorTimes" WHERE "UUID" = ?`, ["incorrect-category"]);
const row = await db.prepare("get", `SELECT "category" FROM "sponsorTimes" WHERE "UUID" = ?`, ["incorrect-category"]);
assert.strictEqual(row.category, "sponsor");
done();
})
.catch(err => done(err));
});
it('Should be able to change your vote for a category and it should add your vote to the database', (done: Done) => {
fetch(getbaseURL()
+ "/api/voteOnSponsorTime?userID=randomID2&UUID=vote-uuid-4&category=outro")
it("Should be able to change your vote for a category and it should add your vote to the database", (done: Done) => {
fetch(`${getbaseURL()
}/api/voteOnSponsorTime?userID=randomID2&UUID=vote-uuid-4&category=outro`)
.then(async res => {
if (res.status === 200) {
const submissionRow = await db.prepare('get', `SELECT "category" FROM "sponsorTimes" WHERE "UUID" = ?`, ["vote-uuid-4"]);
const categoryRows = await db.prepare('all', `SELECT votes, category FROM "categoryVotes" WHERE "UUID" = ?`, ["vote-uuid-4"]);
const submissionRow = await db.prepare("get", `SELECT "category" FROM "sponsorTimes" WHERE "UUID" = ?`, ["vote-uuid-4"]);
const categoryRows = await db.prepare("all", `SELECT votes, category FROM "categoryVotes" WHERE "UUID" = ?`, ["vote-uuid-4"]);
let introVotes = 0;
let outroVotes = 0;
let sponsorVotes = 0;
@@ -235,19 +235,19 @@ describe('voteOnSponsorTime', () => {
assert.strictEqual(sponsorVotes, 1);
done();
} else {
done("Status code was " + res.status);
done(`Status code was ${ res.status}`);
}
})
.catch(err => done(err));
});
it('Should not be able to change your vote to an invalid category', (done: Done) => {
it("Should not be able to change your vote to an invalid category", (done: Done) => {
const vote = (inputCat: string, assertCat: string, callback: Done) => {
fetch(getbaseURL()
+ "/api/voteOnSponsorTime?userID=randomID2&UUID=incorrect-category-change&category=" + inputCat)
fetch(`${getbaseURL()
}/api/voteOnSponsorTime?userID=randomID2&UUID=incorrect-category-change&category=${ inputCat}`)
.then(async () => {
const row = await db.prepare('get', `SELECT "category" FROM "sponsorTimes" WHERE "UUID" = ?`, ["incorrect-category-change"]);
const row = await db.prepare("get", `SELECT "category" FROM "sponsorTimes" WHERE "UUID" = ?`, ["incorrect-category-change"]);
assert.strictEqual(row.category, assertCat);
callback();
})
@@ -259,13 +259,13 @@ describe('voteOnSponsorTime', () => {
});
it('VIP should be able to vote for a category and it should immediately change', (done: Done) => {
fetch(getbaseURL()
+ "/api/voteOnSponsorTime?userID=VIPUser&UUID=vote-uuid-5&category=outro")
it("VIP should be able to vote for a category and it should immediately change", (done: Done) => {
fetch(`${getbaseURL()
}/api/voteOnSponsorTime?userID=VIPUser&UUID=vote-uuid-5&category=outro`)
.then(async res => {
assert.strictEqual(res.status, 200);
const row = await db.prepare('get', `SELECT "category" FROM "sponsorTimes" WHERE "UUID" = ?`, ["vote-uuid-5"]);
const row2 = await db.prepare('get', `SELECT votes FROM "categoryVotes" WHERE "UUID" = ? and category = ?`, ["vote-uuid-5", "outro"]);
const row = await db.prepare("get", `SELECT "category" FROM "sponsorTimes" WHERE "UUID" = ?`, ["vote-uuid-5"]);
const row2 = await db.prepare("get", `SELECT votes FROM "categoryVotes" WHERE "UUID" = ? and category = ?`, ["vote-uuid-5", "outro"]);
assert.strictEqual(row.category, "outro");
assert.strictEqual(row2.votes, 500);
done();
@@ -273,21 +273,21 @@ describe('voteOnSponsorTime', () => {
.catch(err => done(err));
});
it('Submitter should be able to vote for a category and it should immediately change', (done: Done) => {
fetch(getbaseURL()
+ "/api/voteOnSponsorTime?userID=testman&UUID=vote-uuid-5_1&category=outro")
it("Submitter should be able to vote for a category and it should immediately change", (done: Done) => {
fetch(`${getbaseURL()
}/api/voteOnSponsorTime?userID=testman&UUID=vote-uuid-5_1&category=outro`)
.then(async res => {
assert.strictEqual(res.status, 200);
const row = await db.prepare('get', `SELECT "category" FROM "sponsorTimes" WHERE "UUID" = ?`, ["vote-uuid-5"]);
const row = await db.prepare("get", `SELECT "category" FROM "sponsorTimes" WHERE "UUID" = ?`, ["vote-uuid-5"]);
assert.strictEqual(row.category, "outro");
done();
})
.catch(err => done(err));
});
it('Should not be able to category-vote on an invalid UUID submission', (done: Done) => {
fetch(getbaseURL()
+ "/api/voteOnSponsorTime?userID=randomID3&UUID=invalid-uuid&category=intro")
it("Should not be able to category-vote on an invalid UUID submission", (done: Done) => {
fetch(`${getbaseURL()
}/api/voteOnSponsorTime?userID=randomID3&UUID=invalid-uuid&category=intro`)
.then(async res => {
assert.strictEqual(res.status, 400);
done();
@@ -296,11 +296,11 @@ describe('voteOnSponsorTime', () => {
});
it('Non-VIP should not be able to upvote "dead" submission', (done: Done) => {
fetch(getbaseURL()
+ "/api/voteOnSponsorTime?userID=randomID2&UUID=vote-uuid-5&type=1")
fetch(`${getbaseURL()
}/api/voteOnSponsorTime?userID=randomID2&UUID=vote-uuid-5&type=1`)
.then(async res => {
assert.strictEqual(res.status, 403);
const row = await db.prepare('get', `SELECT "votes" FROM "sponsorTimes" WHERE "UUID" = ?`, ["vote-uuid-5"]);
const row = await db.prepare("get", `SELECT "votes" FROM "sponsorTimes" WHERE "UUID" = ?`, ["vote-uuid-5"]);
assert.strictEqual(row.votes, -3);
done();
})
@@ -308,11 +308,11 @@ describe('voteOnSponsorTime', () => {
});
it('Non-VIP should not be able to downvote "dead" submission', (done: Done) => {
fetch(getbaseURL()
+ "/api/voteOnSponsorTime?userID=randomID2&UUID=vote-uuid-5&type=0")
fetch(`${getbaseURL()
}/api/voteOnSponsorTime?userID=randomID2&UUID=vote-uuid-5&type=0`)
.then(async res => {
assert.strictEqual(res.status, 200);
const row = await db.prepare('get', `SELECT "votes" FROM "sponsorTimes" WHERE "UUID" = ?`, ["vote-uuid-5"]);
const row = await db.prepare("get", `SELECT "votes" FROM "sponsorTimes" WHERE "UUID" = ?`, ["vote-uuid-5"]);
assert.strictEqual(row.votes, -3);
done();
})
@@ -320,20 +320,20 @@ describe('voteOnSponsorTime', () => {
});
it('VIP should be able to upvote "dead" submission', (done: Done) => {
fetch(getbaseURL()
+ "/api/voteOnSponsorTime?userID=VIPUser&UUID=vote-uuid-5&type=1")
fetch(`${getbaseURL()
}/api/voteOnSponsorTime?userID=VIPUser&UUID=vote-uuid-5&type=1`)
.then(async res => {
assert.strictEqual(res.status, 200);
const row = await db.prepare('get', `SELECT "votes" FROM "sponsorTimes" WHERE "UUID" = ?`, ["vote-uuid-5"]);
const row = await db.prepare("get", `SELECT "votes" FROM "sponsorTimes" WHERE "UUID" = ?`, ["vote-uuid-5"]);
assert.ok(row.votes > -3);
done();
})
.catch(err => done(err));
});
it('Should not be able to upvote a segment (Too many warning)', (done: Done) => {
fetch(getbaseURL()
+ "/api/voteOnSponsorTime?userID=warn-voteuser01&UUID=warnvote-uuid-0&type=1")
it("Should not be able to upvote a segment (Too many warning)", (done: Done) => {
fetch(`${getbaseURL()
}/api/voteOnSponsorTime?userID=warn-voteuser01&UUID=warnvote-uuid-0&type=1`)
.then(async res => {
assert.strictEqual(res.status, 403);
done();
@@ -341,92 +341,92 @@ describe('voteOnSponsorTime', () => {
.catch(err => done(err));
});
it('Non-VIP should not be able to downvote on a segment with no-segments category', (done: Done) => {
fetch(getbaseURL()
+ "/api/voteOnSponsorTime?userID=randomID&UUID=no-sponsor-segments-uuid-0&type=0")
it("Non-VIP should not be able to downvote on a segment with no-segments category", (done: Done) => {
fetch(`${getbaseURL()
}/api/voteOnSponsorTime?userID=randomID&UUID=no-sponsor-segments-uuid-0&type=0`)
.then(async res => {
assert.strictEqual(res.status, 200);
const row = await db.prepare('get', `SELECT "votes" FROM "sponsorTimes" WHERE "UUID" = ?`, ["no-sponsor-segments-uuid-0"]);
const row = await db.prepare("get", `SELECT "votes" FROM "sponsorTimes" WHERE "UUID" = ?`, ["no-sponsor-segments-uuid-0"]);
assert.strictEqual(row.votes, 2);
done();
})
.catch(err => done(err));
});
it('Non-VIP should be able to upvote on a segment with no-segments category', (done: Done) => {
fetch(getbaseURL()
+ "/api/voteOnSponsorTime?userID=randomID&UUID=no-sponsor-segments-uuid-0&type=1")
it("Non-VIP should be able to upvote on a segment with no-segments category", (done: Done) => {
fetch(`${getbaseURL()
}/api/voteOnSponsorTime?userID=randomID&UUID=no-sponsor-segments-uuid-0&type=1`)
.then(async res => {
assert.strictEqual(res.status, 200);
const row = await db.prepare('get', `SELECT "votes" FROM "sponsorTimes" WHERE "UUID" = ?`, ["no-sponsor-segments-uuid-0"]);
const row = await db.prepare("get", `SELECT "votes" FROM "sponsorTimes" WHERE "UUID" = ?`, ["no-sponsor-segments-uuid-0"]);
assert.strictEqual(row.votes, 3);
done();
})
.catch(err => done(err));
});
it('Non-VIP should not be able to category vote on a segment with no-segments category', (done: Done) => {
fetch(getbaseURL()
+ "/api/voteOnSponsorTime?userID=randomID&UUID=no-sponsor-segments-uuid-0&category=outro")
it("Non-VIP should not be able to category vote on a segment with no-segments category", (done: Done) => {
fetch(`${getbaseURL()
}/api/voteOnSponsorTime?userID=randomID&UUID=no-sponsor-segments-uuid-0&category=outro`)
.then(async res => {
assert.strictEqual(res.status, 200);
const row = await db.prepare('get', `SELECT "category" FROM "sponsorTimes" WHERE "UUID" = ?`, ["no-sponsor-segments-uuid-0"]);
const row = await db.prepare("get", `SELECT "category" FROM "sponsorTimes" WHERE "UUID" = ?`, ["no-sponsor-segments-uuid-0"]);
assert.strictEqual(row.category, "sponsor");
done();
})
.catch(err => done(err));
});
it('VIP upvote should lock segment', (done: Done) => {
fetch(getbaseURL()
+ "/api/voteOnSponsorTime?userID=VIPUser&UUID=segment-locking-uuid-1&type=1")
it("VIP upvote should lock segment", (done: Done) => {
fetch(`${getbaseURL()
}/api/voteOnSponsorTime?userID=VIPUser&UUID=segment-locking-uuid-1&type=1`)
.then(async res => {
assert.strictEqual(res.status, 200);
const row = await db.prepare('get', `SELECT "locked" FROM "sponsorTimes" WHERE "UUID" = ?`, ["segment-locking-uuid-1"]);
const row = await db.prepare("get", `SELECT "locked" FROM "sponsorTimes" WHERE "UUID" = ?`, ["segment-locking-uuid-1"]);
assert.ok(row.locked);
done();
})
.catch(err => done(err));
});
it('VIP downvote should unlock segment', (done: Done) => {
fetch(getbaseURL()
+ "/api/voteOnSponsorTime?userID=VIPUser&UUID=segment-locking-uuid-1&type=0")
it("VIP downvote should unlock segment", (done: Done) => {
fetch(`${getbaseURL()
}/api/voteOnSponsorTime?userID=VIPUser&UUID=segment-locking-uuid-1&type=0`)
.then(async res => {
assert.strictEqual(res.status, 200);
const row = await db.prepare('get', `SELECT "locked" FROM "sponsorTimes" WHERE "UUID" = ?`, ["segment-locking-uuid-1"]);
const row = await db.prepare("get", `SELECT "locked" FROM "sponsorTimes" WHERE "UUID" = ?`, ["segment-locking-uuid-1"]);
assert.ok(!row.locked);
done();
})
.catch(err => done(err));
});
it('VIP upvote should unhide segment', (done: Done) => {
fetch(getbaseURL()
+ "/api/voteOnSponsorTime?userID=VIPUser&UUID=segment-hidden-uuid-1&type=1")
it("VIP upvote should unhide segment", (done: Done) => {
fetch(`${getbaseURL()
}/api/voteOnSponsorTime?userID=VIPUser&UUID=segment-hidden-uuid-1&type=1`)
.then(async res => {
assert.strictEqual(res.status, 200);
const row = await db.prepare('get', `SELECT "hidden" FROM "sponsorTimes" WHERE "UUID" = ?`, ["segment-hidden-uuid-1"]);
const row = await db.prepare("get", `SELECT "hidden" FROM "sponsorTimes" WHERE "UUID" = ?`, ["segment-hidden-uuid-1"]);
assert.ok(!row?.hidden);
done();
})
.catch(err => done(err));
});
it('Should be able to undo-vote a segment', (done: Done) => {
fetch(getbaseURL()
+ "/api/voteOnSponsorTime?userID=randomID2&UUID=vote-uuid-2&type=20")
it("Should be able to undo-vote a segment", (done: Done) => {
fetch(`${getbaseURL()
}/api/voteOnSponsorTime?userID=randomID2&UUID=vote-uuid-2&type=20`)
.then(async res => {
assert.strictEqual(res.status, 200);
const row = await db.prepare('get', `SELECT "votes" FROM "sponsorTimes" WHERE "UUID" = ?`, ["vote-uuid-2"]);
const row = await db.prepare("get", `SELECT "votes" FROM "sponsorTimes" WHERE "UUID" = ?`, ["vote-uuid-2"]);
assert.strictEqual(row.votes, 10);
done();
})
.catch(err => done(err));
});
it('Should not be able to vote with type 10', (done: Done) => {
fetch(getbaseURL() + "/api/voteOnSponsorTime?userID=VIPUser&UUID=segment-locking-uuid-1&type=10")
it("Should not be able to vote with type 10", (done: Done) => {
fetch(`${getbaseURL() }/api/voteOnSponsorTime?userID=VIPUser&UUID=segment-locking-uuid-1&type=10`)
.then(res => {
assert.strictEqual(res.status, 400);
done();
@@ -434,8 +434,8 @@ describe('voteOnSponsorTime', () => {
.catch(err => done(err));
});
it('Should not be able to vote with type 11', (done: Done) => {
fetch(getbaseURL() + "/api/voteOnSponsorTime?userID=VIPUser&UUID=segment-locking-uuid-1&type=11")
it("Should not be able to vote with type 11", (done: Done) => {
fetch(`${getbaseURL() }/api/voteOnSponsorTime?userID=VIPUser&UUID=segment-locking-uuid-1&type=11`)
.then(res => {
assert.strictEqual(res.status, 400);
done();

View File

@@ -1,27 +1,27 @@
import express from 'express';
import {config} from '../src/config';
import { Server } from 'http';
import express from "express";
import {config} from "../src/config";
import { Server } from "http";
const app = express();
app.post('/ReportChannelWebhook', (req, res) => {
app.post("/ReportChannelWebhook", (req, res) => {
res.sendStatus(200);
});
app.post('/FirstTimeSubmissionsWebhook', (req, res) => {
app.post("/FirstTimeSubmissionsWebhook", (req, res) => {
res.sendStatus(200);
});
app.post('/CompletelyIncorrectReportWebhook', (req, res) => {
app.post("/CompletelyIncorrectReportWebhook", (req, res) => {
res.sendStatus(200);
});
// Testing NeuralBlock
app.post('/NeuralBlockRejectWebhook', (req, res) => {
app.post("/NeuralBlockRejectWebhook", (req, res) => {
res.sendStatus(200);
});
app.get('/NeuralBlock/api/checkSponsorSegments', (req, res) => {
app.get("/NeuralBlock/api/checkSponsorSegments", (req, res) => {
if (req.query.vid === "LevkAjUE6d4") {
res.json({
probabilities: [0.69],
@@ -32,7 +32,7 @@ app.get('/NeuralBlock/api/checkSponsorSegments', (req, res) => {
});
//getSponsorSegments is no longer being used for automod
app.get('/NeuralBlock/api/getSponsorSegments', (req, res) => {
app.get("/NeuralBlock/api/getSponsorSegments", (req, res) => {
if (req.query.vid === "LevkAjUE6d4") {
res.json({
sponsorSegments: [[0.47, 7.549], [264.023, 317.293]],
@@ -43,7 +43,7 @@ app.get('/NeuralBlock/api/getSponsorSegments', (req, res) => {
});
// Testing webhooks
app.post('/CustomWebhook', (req, res) => {
app.post("/CustomWebhook", (req, res) => {
res.sendStatus(200);
});

View File

@@ -1,17 +1,17 @@
import Mocha from 'mocha';
import fs from 'fs';
import path from 'path';
import {config} from '../src/config';
import {createServer} from '../src/app';
import {createMockServer} from './mocks';
import {Logger} from '../src/utils/logger';
import {initDb} from '../src/databases/databases';
import {ImportMock} from 'ts-mock-imports';
import * as rateLimitMiddlewareModule from '../src/middleware/requestRateLimit';
import rateLimit from 'express-rate-limit';
import Mocha from "mocha";
import fs from "fs";
import path from "path";
import {config} from "../src/config";
import {createServer} from "../src/app";
import {createMockServer} from "./mocks";
import {Logger} from "../src/utils/logger";
import {initDb} from "../src/databases/databases";
import {ImportMock} from "ts-mock-imports";
import * as rateLimitMiddlewareModule from "../src/middleware/requestRateLimit";
import rateLimit from "express-rate-limit";
async function init() {
ImportMock.mockFunction(rateLimitMiddlewareModule, 'rateLimitMiddleware', rateLimit({
ImportMock.mockFunction(rateLimitMiddlewareModule, "rateLimitMiddleware", rateLimit({
skip: () => true
}));
@@ -21,21 +21,21 @@ async function init() {
await initDb();
const dbMode = config.mysql ? 'mysql'
: config.postgres ? 'postgres'
: 'sqlite';
Logger.info('Database Mode: ' + dbMode);
const dbMode = config.mysql ? "mysql"
: config.postgres ? "postgres"
: "sqlite";
Logger.info(`Database Mode: ${dbMode}`);
// Instantiate a Mocha instance.
const mocha = new Mocha();
const testDir = './test/cases';
const testDir = "./test/cases";
// Add each .ts file to the mocha instance
fs.readdirSync(testDir)
.filter((file) =>
// Only keep the .ts files
file.substr(-3) === '.ts'
file.substr(-3) === ".ts"
)
.forEach(function(file) {
mocha.addFile(

View File

@@ -1,7 +1,7 @@
import {config} from '../src/config';
import {config} from "../src/config";
export function getbaseURL(): string {
return "http://localhost:" + config.port;
return `http://localhost:${config.port}`;
}
/**