diff --git a/src/databases/IDatabase.ts b/src/databases/IDatabase.ts index 4bac1e3..6001cdd 100644 --- a/src/databases/IDatabase.ts +++ b/src/databases/IDatabase.ts @@ -1,7 +1,7 @@ export interface IDatabase { init(): void; - prepare(type: QueryType, query: string, params: any[]): Promise; + prepare(type: QueryType, query: string, params?: any[]): Promise; } export type QueryType = 'get' | 'all' | 'run'; diff --git a/src/databases/Mysql.ts b/src/databases/Mysql.ts index 4d9c675..9ec78c7 100644 --- a/src/databases/Mysql.ts +++ b/src/databases/Mysql.ts @@ -13,7 +13,7 @@ export class Mysql implements IDatabase { this.connection = new MysqlInterface(this.config); } - prepare(type: QueryType, query: string, params: any[]) { + prepare(type: QueryType, query: string, params?: any[]) { Logger.debug(`prepare (mysql): type: ${type}, query: ${query}, params: ${params}`); const queryResult = this.connection.query(query, params); diff --git a/src/databases/Postgres.ts b/src/databases/Postgres.ts index 2b6685a..3f63707 100644 --- a/src/databases/Postgres.ts +++ b/src/databases/Postgres.ts @@ -11,7 +11,7 @@ export class Mysql implements IDatabase { this.pool = new Pool(); } - async prepare(type: QueryType, query: string, params: any[]) { + async prepare(type: QueryType, query: string, params?: any[]) { Logger.debug(`prepare (postgres): type: ${type}, query: ${query}, params: ${params}`); const queryResult = await this.pool.query(query, params); diff --git a/src/databases/Sqlite.ts b/src/databases/Sqlite.ts index 5cf0104..ec3055d 100644 --- a/src/databases/Sqlite.ts +++ b/src/databases/Sqlite.ts @@ -12,18 +12,30 @@ export class Sqlite implements IDatabase { { } - async prepare(type: QueryType, query: string, params: any[]) { + async prepare(type: QueryType, query: string, params?: any[]) { const preparedQuery = this.db.prepare(query); switch (type) { case 'get': { - return preparedQuery.get(...params); + if (params) { + return preparedQuery.get(...params); + } else { + return preparedQuery.get(); + } } case 'all': { - return preparedQuery.all(...params); + if (params) { + return preparedQuery.all(...params); + } else { + return preparedQuery.all(); + } } case 'run': { - preparedQuery.run(...params); + if (params) { + preparedQuery.run(...params); + } else { + preparedQuery.run(); + } break; } } diff --git a/src/routes/getSkipSegmentsByHash.ts b/src/routes/getSkipSegmentsByHash.ts index 399400b..7313af0 100644 --- a/src/routes/getSkipSegmentsByHash.ts +++ b/src/routes/getSkipSegmentsByHash.ts @@ -29,7 +29,7 @@ export async function getSkipSegmentsByHash(req: Request, res: Response) { categories = categories.filter((item: any) => typeof item === "string"); // Get all video id's that match hash prefix - const segments = getSegmentsByHash(req, hashPrefix, categories); + const segments = await getSegmentsByHash(req, hashPrefix, categories); if (!segments) return res.status(404).json([]); diff --git a/test/cases/dbUpgrade.ts b/test/cases/dbUpgrade.ts index 8762b5d..12bfe92 100644 --- a/test/cases/dbUpgrade.ts +++ b/test/cases/dbUpgrade.ts @@ -2,10 +2,10 @@ import {db, privateDB} from '../../src/databases/databases'; import {Done} from '../utils'; describe('dbUpgrade', () => { - it('Should update the database version when starting the application', async (done: Done) => { + it('Should update the database version when starting the application', async () => { let dbVersion = (await db.prepare('get', 'SELECT key, value FROM config where key = ?', ['version'])).value; let privateVersion = (await privateDB.prepare('get', 'SELECT key, value FROM config where key = ?', ['version'])).value; - if (dbVersion >= 1 && privateVersion >= 1) done(); - else done('Versions are not at least 1. db is ' + dbVersion + ', private is ' + privateVersion); + if (dbVersion >= 1 && privateVersion >= 1) return; + else return 'Versions are not at least 1. db is ' + dbVersion + ', private is ' + privateVersion; }); }); diff --git a/test/cases/getIsUserVIP.ts b/test/cases/getIsUserVIP.ts index 4f923e0..7610e4a 100644 --- a/test/cases/getIsUserVIP.ts +++ b/test/cases/getIsUserVIP.ts @@ -4,8 +4,8 @@ import {db} from '../../src/databases/databases'; import {getHash} from '../../src/utils/getHash'; describe('getIsUserVIP', () => { - before(() => { - db.exec("INSERT INTO vipUsers (userID) VALUES ('" + getHash("supertestman") + "')"); + 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) => { diff --git a/test/cases/getSavedTimeForUser.ts b/test/cases/getSavedTimeForUser.ts index 4c96687..795f41b 100644 --- a/test/cases/getSavedTimeForUser.ts +++ b/test/cases/getSavedTimeForUser.ts @@ -4,9 +4,11 @@ import {db} from '../../src/databases/databases'; import {getHash} from '../../src/utils/getHash'; describe('getSavedTimeForUser', () => { - before(() => { + before(async () => { let startOfQuery = "INSERT INTO sponsorTimes (videoID, startTime, endTime, votes, UUID, userID, timeSubmitted, views, category, shadowHidden, hashedVideoID) VALUES"; - db.exec(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) => { diff --git a/test/cases/getSegmentsByHash.ts b/test/cases/getSegmentsByHash.ts index 1d0975f..1f5597f 100644 --- a/test/cases/getSegmentsByHash.ts +++ b/test/cases/getSegmentsByHash.ts @@ -11,13 +11,12 @@ const sinonStub = mockManager.mock('listVideos'); sinonStub.callsFake(YouTubeApiMock.listVideos); describe('getSegmentsByHash', () => { - before(() => { + before(async () => { let startOfQuery = "INSERT INTO sponsorTimes (videoID, startTime, endTime, votes, UUID, userID, timeSubmitted, views, category, shadowHidden, hashedVideoID) VALUES"; - db.exec(startOfQuery + "('getSegmentsByHash-0', 1, 10, 2, 'getSegmentsByHash-0-0', 'testman', 0, 50, 'sponsor', 0, '" + getHash('getSegmentsByHash-0', 1) + "')"); // hash = fdaff4dee1043451faa7398324fb63d8618ebcd11bddfe0491c488db12c6c910 - db.exec(startOfQuery + "('getSegmentsByHash-0', 20, 30, 2, 'getSegmentsByHash-0-1', 'testman', 100, 150, 'intro', 0, '" + getHash('getSegmentsByHash-0', 1) + "')"); // hash = fdaff4dee1043451faa7398324fb63d8618ebcd11bddfe0491c488db12c6c910 - db.exec(startOfQuery + "('getSegmentsByHash-noMatchHash', 40, 50, 2, 'getSegmentsByHash-noMatchHash', 'testman', 0, 50, 'sponsor', 0, 'fdaffnoMatchHash')"); // hash = fdaff4dee1043451faa7398324fb63d8618ebcd11bddfe0491c488db12c6c910 - db.exec(startOfQuery + "('getSegmentsByHash-1', 60, 70, 2, 'getSegmentsByHash-1', 'testman', 0, 50, 'sponsor', 0, '" + getHash('getSegmentsByHash-1', 1) + "')"); // hash = 3272fa85ee0927f6073ef6f07ad5f3146047c1abba794cfa364d65ab9921692b - + await db.prepare("run", startOfQuery + "('getSegmentsByHash-0', 1, 10, 2, 'getSegmentsByHash-0-0', 'testman', 0, 50, 'sponsor', 0, '" + getHash('getSegmentsByHash-0', 1) + "')"); // hash = fdaff4dee1043451faa7398324fb63d8618ebcd11bddfe0491c488db12c6c910 + await db.prepare("run", startOfQuery + "('getSegmentsByHash-0', 20, 30, 2, 'getSegmentsByHash-0-1', 'testman', 100, 150, 'intro', 0, '" + getHash('getSegmentsByHash-0', 1) + "')"); // hash = fdaff4dee1043451faa7398324fb63d8618ebcd11bddfe0491c488db12c6c910 + await db.prepare("run", startOfQuery + "('getSegmentsByHash-noMatchHash', 40, 50, 2, 'getSegmentsByHash-noMatchHash', 'testman', 0, 50, 'sponsor', 0, 'fdaffnoMatchHash')"); // hash = fdaff4dee1043451faa7398324fb63d8618ebcd11bddfe0491c488db12c6c910 + await db.prepare("run", startOfQuery + "('getSegmentsByHash-1', 60, 70, 2, 'getSegmentsByHash-1', 'testman', 0, 50, 'sponsor', 0, '" + getHash('getSegmentsByHash-1', 1) + "')"); // hash = 3272fa85ee0927f6073ef6f07ad5f3146047c1abba794cfa364d65ab9921692b }); it('Should be able to get a 200', (done: Done) => { diff --git a/test/cases/getSkipSegments.ts b/test/cases/getSkipSegments.ts index a68fdce..ae562e5 100644 --- a/test/cases/getSkipSegments.ts +++ b/test/cases/getSkipSegments.ts @@ -4,92 +4,94 @@ import {Done, getbaseURL} from '../utils'; import {getHash} from '../../src/utils/getHash'; describe('getSkipSegments', () => { - before(() => { + before(async () => { let startOfQuery = "INSERT INTO sponsorTimes (videoID, startTime, endTime, votes, locked, UUID, userID, timeSubmitted, views, category, shadowHidden, hashedVideoID) VALUES"; - db.exec(startOfQuery + "('testtesttest', 1, 11, 2, 0, '1-uuid-0', 'testman', 0, 50, 'sponsor', 0, '" + getHash('testtesttest', 1) + "')"); - db.exec(startOfQuery + "('testtesttest', 20, 33, 2, 0, '1-uuid-2', 'testman', 0, 50, 'intro', 0, '" + getHash('testtesttest', 1) + "')"); - db.exec(startOfQuery + "('testtesttest,test', 1, 11, 2, 0, '1-uuid-1', 'testman', 0, 50, 'sponsor', 0, '" + getHash('testtesttest,test', 1) + "')"); - db.exec(startOfQuery + "('test3', 1, 11, 2, 0, '1-uuid-4', 'testman', 0, 50, 'sponsor', 0, '" + getHash('test3', 1) + "')"); - db.exec(startOfQuery + "('test3', 7, 22, -3, 0, '1-uuid-5', 'testman', 0, 50, 'sponsor', 0, '" + getHash('test3', 1) + "')"); - db.exec(startOfQuery + "('multiple', 1, 11, 2, 0, '1-uuid-6', 'testman', 0, 50, 'intro', 0, '" + getHash('multiple', 1) + "')"); - db.exec(startOfQuery + "('multiple', 20, 33, 2, 0, '1-uuid-7', 'testman', 0, 50, 'intro', 0, '" + getHash('multiple', 1) + "')"); - db.exec(startOfQuery + "('locked', 20, 33, 2, 1, '1-uuid-locked-8', 'testman', 0, 50, 'intro', 0, '" + getHash('locked', 1) + "')"); - db.exec(startOfQuery + "('locked', 20, 34, 100000, 0, '1-uuid-9', 'testman', 0, 50, 'intro', 0, '" + getHash('locked', 1) + "')"); + await db.prepare("run", startOfQuery + "('testtesttest', 1, 11, 2, 0, '1-uuid-0', 'testman', 0, 50, 'sponsor', 0, '" + getHash('testtesttest', 1) + "')"); + await db.prepare("run", startOfQuery + "('testtesttest', 20, 33, 2, 0, '1-uuid-2', 'testman', 0, 50, 'intro', 0, '" + getHash('testtesttest', 1) + "')"); + await db.prepare("run", startOfQuery + "('testtesttest,test', 1, 11, 2, 0, '1-uuid-1', 'testman', 0, 50, 'sponsor', 0, '" + getHash('testtesttest,test', 1) + "')"); + await db.prepare("run", startOfQuery + "('test3', 1, 11, 2, 0, '1-uuid-4', 'testman', 0, 50, 'sponsor', 0, '" + getHash('test3', 1) + "')"); + await db.prepare("run", startOfQuery + "('test3', 7, 22, -3, 0, '1-uuid-5', 'testman', 0, 50, 'sponsor', 0, '" + getHash('test3', 1) + "')"); + await db.prepare("run", startOfQuery + "('multiple', 1, 11, 2, 0, '1-uuid-6', 'testman', 0, 50, 'intro', 0, '" + getHash('multiple', 1) + "')"); + await db.prepare("run", startOfQuery + "('multiple', 20, 33, 2, 0, '1-uuid-7', 'testman', 0, 50, 'intro', 0, '" + getHash('multiple', 1) + "')"); + await db.prepare("run", startOfQuery + "('locked', 20, 33, 2, 1, '1-uuid-locked-8', 'testman', 0, 50, 'intro', 0, '" + getHash('locked', 1) + "')"); + await db.prepare("run", startOfQuery + "('locked', 20, 34, 100000, 0, '1-uuid-9', 'testman', 0, 50, 'intro', 0, '" + getHash('locked', 1) + "')"); + + return; }); - it('Should be able to get a time by category 1', (done: Done) => { + it('Should be able to get a time by category 1', () => { fetch(getbaseURL() + "/api/skipSegments?videoID=testtesttest&category=sponsor") .then(async res => { - if (res.status !== 200) done("Status code was: " + res.status); + if (res.status !== 200) return ("Status code was: " + res.status); else { const data = await res.json(); if (data.length === 1 && data[0].segment[0] === 1 && data[0].segment[1] === 11 && data[0].category === "sponsor" && data[0].UUID === "1-uuid-0") { - done(); + return; } else { - done("Received incorrect body: " + (await res.text())); + return ("Received incorrect body: " + (await res.text())); } } }) - .catch(err => done("Couldn't call endpoint")); + .catch(err => "Couldn't call endpoint"); }); - it('Should be able to get a time by category 2', (done: Done) => { + it('Should be able to get a time by category 2', () => { fetch(getbaseURL() + "/api/skipSegments?videoID=testtesttest&category=intro") .then(async res => { - if (res.status !== 200) done("Status code was: " + res.status); + if (res.status !== 200) return ("Status code was: " + res.status); else { const data = await res.json(); if (data.length === 1 && data[0].segment[0] === 20 && data[0].segment[1] === 33 && data[0].category === "intro" && data[0].UUID === "1-uuid-2") { - done(); + return; } else { - done("Received incorrect body: " + (await res.text())); + return ("Received incorrect body: " + (await res.text())); } } }) - .catch(err => done("Couldn't call endpoint")); + .catch(err => ("Couldn't call endpoint")); }); - it('Should be able to get a time by categories array', (done: Done) => { + it('Should be able to get a time by categories array', () => { fetch(getbaseURL() + "/api/skipSegments?videoID=testtesttest&categories=[\"sponsor\"]") .then(async res => { - if (res.status !== 200) done("Status code was: " + res.status); + if (res.status !== 200) return ("Status code was: " + res.status); else { const data = await res.json(); if (data.length === 1 && data[0].segment[0] === 1 && data[0].segment[1] === 11 && data[0].category === "sponsor" && data[0].UUID === "1-uuid-0") { - done(); + return; } else { - done("Received incorrect body: " + (await res.text())); + return ("Received incorrect body: " + (await res.text())); } } }) - .catch(err => done("Couldn't call endpoint")); + .catch(err => ("Couldn't call endpoint")); }); - it('Should be able to get a time by categories array 2', (done: Done) => { + it('Should be able to get a time by categories array 2', () => { fetch(getbaseURL() + "/api/skipSegments?videoID=testtesttest&categories=[\"intro\"]") .then(async res => { - if (res.status !== 200) done("Status code was: " + res.status); + if (res.status !== 200) return ("Status code was: " + res.status); else { const data = await res.json(); if (data.length === 1 && data[0].segment[0] === 20 && data[0].segment[1] === 33 && data[0].category === "intro" && data[0].UUID === "1-uuid-2") { - done(); + return; } else { - done("Received incorrect body: " + (await res.text())); + return ("Received incorrect body: " + (await res.text())); } } }) - .catch(err => done("Couldn't call endpoint")); + .catch(err => ("Couldn't call endpoint")); }); - it('Should be able to get multiple times by category', (done: Done) => { + it('Should be able to get multiple times by category', () => { fetch(getbaseURL() + "/api/skipSegments?videoID=multiple&categories=[\"intro\"]") .then(async res => { - if (res.status !== 200) done("Status code was: " + res.status); + if (res.status !== 200) return ("Status code was: " + res.status); else { const body = await res.text(); const data = JSON.parse(body); @@ -105,20 +107,20 @@ describe('getSkipSegments', () => { } } - if (success) done(); - else done("Received incorrect body: " + body); + if (success) return; + else return ("Received incorrect body: " + body); } else { - done("Received incorrect body: " + body); + return ("Received incorrect body: " + body); } } }) - .catch(err => done("Couldn't call endpoint\n\n" + err)); + .catch(err => ("Couldn't call endpoint\n\n" + err)); }); - it('Should be able to get multiple times by multiple categories', (done: Done) => { + it('Should be able to get multiple times by multiple categories', () => { fetch(getbaseURL() + "/api/skipSegments?videoID=testtesttest&categories=[\"sponsor\", \"intro\"]") .then(async res => { - if (res.status !== 200) done("Status code was: " + res.status); + if (res.status !== 200) return ("Status code was: " + res.status); else { const body = await res.text(); const data = JSON.parse(body); @@ -135,95 +137,95 @@ describe('getSkipSegments', () => { } } - if (success) done(); - else done("Received incorrect body: " + body); + if (success) return; + else return ("Received incorrect body: " + body); } else { - done("Received incorrect body: " + body); + return ("Received incorrect body: " + body); } } }) - .catch(err => done("Couldn't call endpoint")); + .catch(err => ("Couldn't call endpoint")); }); - it('Should be possible to send unexpected query parameters', (done: Done) => { + it('Should be possible to send unexpected query parameters', () => { fetch(getbaseURL() + "/api/skipSegments?videoID=testtesttest&fakeparam=hello&category=sponsor") .then(async res => { - if (res.status !== 200) done("Status code was: " + res.status); + if (res.status !== 200) return ("Status code was: " + res.status); else { const body = await res.text(); const data = JSON.parse(body); if (data.length === 1 && data[0].segment[0] === 1 && data[0].segment[1] === 11 && data[0].category === "sponsor" && data[0].UUID === "1-uuid-0") { - done(); + return; } else { - done("Received incorrect body: " + body); + return ("Received incorrect body: " + body); } } }) - .catch(err => done("Couldn't call endpoint")); + .catch(err => ("Couldn't call endpoint")); }); - it('Low voted submissions should be hidden', (done: Done) => { + it('Low voted submissions should be hidden', () => { fetch(getbaseURL() + "/api/skipSegments?videoID=test3&category=sponsor") .then(async res => { - if (res.status !== 200) done("Status code was: " + res.status); + if (res.status !== 200) return ("Status code was: " + res.status); else { const body = await res.text(); const data = JSON.parse(body); if (data.length === 1 && data[0].segment[0] === 1 && data[0].segment[1] === 11 && data[0].category === "sponsor" && data[0].UUID === "1-uuid-4") { - done(); + return; } else { - done("Received incorrect body: " + body); + return ("Received incorrect body: " + body); } } }) - .catch(err => done("Couldn't call endpoint")); + .catch(err => ("Couldn't call endpoint")); }); - it('Should return 404 if no segment found', (done: Done) => { + it('Should return 404 if no segment found', () => { fetch(getbaseURL() + "/api/skipSegments?videoID=notarealvideo") .then(res => { - if (res.status !== 404) done("non 404 respone code: " + res.status); - else done(); // pass + if (res.status !== 404) return ("non 404 respone code: " + res.status); + else return; // pass }) - .catch(err => done("couldn't call endpoint")); + .catch(err => ("couldn't call endpoint")); }); - it('Should be able send a comma in a query param', (done: Done) => { + it('Should be able send a comma in a query param', () => { fetch(getbaseURL() + "/api/skipSegments?videoID=testtesttest,test&category=sponsor") .then(async res => { - if (res.status !== 200) done("Status code was: " + res.status); + if (res.status !== 200) return ("Status code was: " + res.status); else { const body = await res.text(); const data = JSON.parse(body); if (data.length === 1 && data[0].segment[0] === 1 && data[0].segment[1] === 11 && data[0].category === "sponsor" && data[0].UUID === "1-uuid-1") { - done(); + return; } else { - done("Received incorrect body: " + body); + return ("Received incorrect body: " + body); } } }) - .catch(err => done("Couldn't call endpoint")); + .catch(err => ("Couldn't call endpoint")); }); - it('Should always get locked segment', (done: Done) => { + it('Should always get locked segment', () => { fetch(getbaseURL() + "/api/skipSegments?videoID=locked&category=intro") .then(async res => { - if (res.status !== 200) done("Status code was: " + res.status); + if (res.status !== 200) return ("Status code was: " + res.status); else { const data = await res.json(); if (data.length === 1 && data[0].segment[0] === 20 && data[0].segment[1] === 33 && data[0].category === "intro" && data[0].UUID === "1-uuid-locked-8") { - done(); + return; } else { - done("Received incorrect body: " + (await res.text())); + return ("Received incorrect body: " + (await res.text())); } } }) - .catch(err => done("Couldn't call endpoint")); + .catch(err => ("Couldn't call endpoint")); }); }); diff --git a/test/cases/getUserInfo.ts b/test/cases/getUserInfo.ts index 673364f..318f28b 100644 --- a/test/cases/getUserInfo.ts +++ b/test/cases/getUserInfo.ts @@ -4,30 +4,30 @@ import {db} from '../../src/databases/databases'; import {getHash} from '../../src/utils/getHash'; describe('getUserInfo', () => { - before(() => { + before(async () => { let startOfUserNamesQuery = "INSERT INTO userNames (userID, userName) VALUES"; - db.exec(startOfUserNamesQuery + "('" + getHash("getuserinfo_user_01") + "', 'Username user 01')"); + await db.prepare("run", startOfUserNamesQuery + "('" + getHash("getuserinfo_user_01") + "', 'Username user 01')"); let startOfSponsorTimesQuery = "INSERT INTO sponsorTimes (videoID, startTime, endTime, votes, UUID, userID, timeSubmitted, views, category, shadowHidden) VALUES"; - db.exec(startOfSponsorTimesQuery + "('xxxyyyzzz', 1, 11, 2, 'uuid000001', '" + getHash("getuserinfo_user_01") + "', 0, 10, 'sponsor', 0)"); - db.exec(startOfSponsorTimesQuery + "('xxxyyyzzz', 1, 11, 2, 'uuid000002', '" + getHash("getuserinfo_user_01") + "', 0, 10, 'sponsor', 0)"); - db.exec(startOfSponsorTimesQuery + "('yyyxxxzzz', 1, 11, -1, 'uuid000003', '" + getHash("getuserinfo_user_01") + "', 0, 10, 'sponsor', 0)"); - db.exec(startOfSponsorTimesQuery + "('yyyxxxzzz', 1, 11, -2, 'uuid000004', '" + getHash("getuserinfo_user_01") + "', 0, 10, 'sponsor', 1)"); - db.exec(startOfSponsorTimesQuery + "('xzzzxxyyy', 1, 11, -5, 'uuid000005', '" + getHash("getuserinfo_user_01") + "', 0, 10, 'sponsor', 1)"); - db.exec(startOfSponsorTimesQuery + "('zzzxxxyyy', 1, 11, 2, 'uuid000006', '" + getHash("getuserinfo_user_02") + "', 0, 10, 'sponsor', 0)"); - db.exec(startOfSponsorTimesQuery + "('xxxyyyzzz', 1, 11, 2, 'uuid000007', '" + getHash("getuserinfo_user_02") + "', 0, 10, 'sponsor', 1)"); - db.exec(startOfSponsorTimesQuery + "('xxxyyyzzz', 1, 11, 2, 'uuid000008', '" + getHash("getuserinfo_user_02") + "', 0, 10, 'sponsor', 1)"); + await db.prepare("run", startOfSponsorTimesQuery + "('xxxyyyzzz', 1, 11, 2, 'uuid000001', '" + getHash("getuserinfo_user_01") + "', 0, 10, 'sponsor', 0)"); + await db.prepare("run", startOfSponsorTimesQuery + "('xxxyyyzzz', 1, 11, 2, 'uuid000002', '" + getHash("getuserinfo_user_01") + "', 0, 10, 'sponsor', 0)"); + await db.prepare("run", startOfSponsorTimesQuery + "('yyyxxxzzz', 1, 11, -1, 'uuid000003', '" + getHash("getuserinfo_user_01") + "', 0, 10, 'sponsor', 0)"); + await db.prepare("run", startOfSponsorTimesQuery + "('yyyxxxzzz', 1, 11, -2, 'uuid000004', '" + getHash("getuserinfo_user_01") + "', 0, 10, 'sponsor', 1)"); + await db.prepare("run", startOfSponsorTimesQuery + "('xzzzxxyyy', 1, 11, -5, 'uuid000005', '" + getHash("getuserinfo_user_01") + "', 0, 10, 'sponsor', 1)"); + await db.prepare("run", startOfSponsorTimesQuery + "('zzzxxxyyy', 1, 11, 2, 'uuid000006', '" + getHash("getuserinfo_user_02") + "', 0, 10, 'sponsor', 0)"); + await db.prepare("run", startOfSponsorTimesQuery + "('xxxyyyzzz', 1, 11, 2, 'uuid000007', '" + getHash("getuserinfo_user_02") + "', 0, 10, 'sponsor', 1)"); + await db.prepare("run", startOfSponsorTimesQuery + "('xxxyyyzzz', 1, 11, 2, 'uuid000008', '" + getHash("getuserinfo_user_02") + "', 0, 10, 'sponsor', 1)"); - - db.exec("INSERT INTO warnings (userID, issueTime, issuerUserID, enabled) VALUES ('" + getHash('getuserinfo_warning_0') + "', 10, 'getuserinfo_vip', 1)"); - db.exec("INSERT INTO warnings (userID, issueTime, issuerUserID, enabled) VALUES ('" + getHash('getuserinfo_warning_1') + "', 10, 'getuserinfo_vip', 1)"); - db.exec("INSERT INTO warnings (userID, issueTime, issuerUserID, enabled) VALUES ('" + getHash('getuserinfo_warning_1') + "', 10, 'getuserinfo_vip', 1)"); + + await db.prepare("run", "INSERT INTO warnings (userID, issueTime, issuerUserID, enabled) VALUES ('" + getHash('getuserinfo_warning_0') + "', 10, 'getuserinfo_vip', 1)"); + await db.prepare("run", "INSERT INTO warnings (userID, issueTime, issuerUserID, enabled) VALUES ('" + getHash('getuserinfo_warning_1') + "', 10, 'getuserinfo_vip', 1)"); + await db.prepare("run", "INSERT INTO warnings (userID, issueTime, issuerUserID, enabled) VALUES ('" + getHash('getuserinfo_warning_1') + "', 10, 'getuserinfo_vip', 1)"); }); it('Should be able to get a 200', (done: Done) => { fetch(getbaseURL() + '/api/getUserInfo?userID=getuserinfo_user_01') .then(res => { if (res.status !== 200) done('non 200 (' + res.status + ')'); - else done(); // pass + else done(); // pass }) .catch(err => done('couldn\'t call endpoint')); }); @@ -41,7 +41,7 @@ describe('getUserInfo', () => { .catch(err => done('couldn\'t call endpoint')); }); - it('Should return info', (done: Done) => { + it('Should done(info', (done: Done) => { fetch(getbaseURL() + '/api/getUserInfo?userID=getuserinfo_user_01') .then(async res => { if (res.status !== 200) { @@ -61,7 +61,7 @@ describe('getUserInfo', () => { } } }) - .catch(err => done("couldn't call endpoint")); + .catch(err => ("couldn't call endpoint")); }); it('Should get warning data', (done: Done) => { @@ -75,7 +75,7 @@ describe('getUserInfo', () => { else done(); // pass } }) - .catch(err => done("couldn't call endpoint")); + .catch(err => ("couldn't call endpoint")); }); it('Should get multiple warnings', (done: Done) => { @@ -89,7 +89,7 @@ describe('getUserInfo', () => { else done(); // pass } }) - .catch(err => done("couldn't call endpoint")); + .catch(err => ("couldn't call endpoint")); }); it('Should not get warnings if noe', (done: Done) => { @@ -103,10 +103,10 @@ describe('getUserInfo', () => { else done(); // pass } }) - .catch(err => done("couldn't call endpoint")); + .catch(err => ("couldn't call endpoint")); }); - it('Should return userID for userName (No userName set)', (done: Done) => { + it('Should done(userID for userName (No userName set)', (done: Done) => { fetch(getbaseURL() + '/api/getUserInfo?userID=getuserinfo_user_02') .then(async res => { if (res.status !== 200) { @@ -114,11 +114,11 @@ describe('getUserInfo', () => { } else { const data = await res.json(); if (data.userName !== 'c2a28fd225e88f74945794ae85aef96001d4a1aaa1022c656f0dd48ac0a3ea0f') { - return done('Did not return userID for userName'); + done('Did not done(userID for userName'); } done(); // pass } }) - .catch(err => done('couldn\'t call endpoint')); + .catch(err => ('couldn\'t call endpoint')); }); }); diff --git a/test/cases/noSegmentRecords.ts b/test/cases/noSegmentRecords.ts index 172227f..a789b5d 100644 --- a/test/cases/noSegmentRecords.ts +++ b/test/cases/noSegmentRecords.ts @@ -5,26 +5,26 @@ import {db} from '../../src/databases/databases'; describe('noSegmentRecords', () => { - before(() => { - db.exec("INSERT INTO vipUsers (userID) VALUES ('" + getHash("VIPUser-noSegments") + "')"); - - db.exec("INSERT INTO noSegments (userID, videoID, category) VALUES ('" + getHash("VIPUser-noSegments") + "', 'no-segments-video-id', 'sponsor')"); - db.exec("INSERT INTO noSegments (userID, videoID, category) VALUES ('" + getHash("VIPUser-noSegments") + "', 'no-segments-video-id', 'intro')"); - - db.exec("INSERT INTO noSegments (userID, videoID, category) VALUES ('" + getHash("VIPUser-noSegments") + "', 'no-segments-video-id-1', 'sponsor')"); - db.exec("INSERT INTO noSegments (userID, videoID, category) VALUES ('" + getHash("VIPUser-noSegments") + "', 'no-segments-video-id-1', 'intro')"); - db.exec("INSERT INTO noSegments (userID, videoID, category) VALUES ('" + getHash("VIPUser-noSegments") + "', 'noSubmitVideo', 'sponsor')"); - - db.exec("INSERT INTO noSegments (userID, videoID, category) VALUES ('" + getHash("VIPUser-noSegments") + "', 'delete-record', 'sponsor')"); - - db.exec("INSERT INTO noSegments (userID, videoID, category) VALUES ('" + getHash("VIPUser-noSegments") + "', 'delete-record-1', 'sponsor')"); - db.exec("INSERT INTO noSegments (userID, videoID, category) VALUES ('" + getHash("VIPUser-noSegments") + "', 'delete-record-1', 'intro')"); + before(async () => { + await db.prepare("run", "INSERT INTO vipUsers (userID) VALUES ('" + getHash("VIPUser-noSegments") + "')"); + + await db.prepare("run", "INSERT INTO noSegments (userID, videoID, category) VALUES ('" + getHash("VIPUser-noSegments") + "', 'no-segments-video-id', 'sponsor')"); + await db.prepare("run", "INSERT INTO noSegments (userID, videoID, category) VALUES ('" + getHash("VIPUser-noSegments") + "', 'no-segments-video-id', 'intro')"); + + await db.prepare("run", "INSERT INTO noSegments (userID, videoID, category) VALUES ('" + getHash("VIPUser-noSegments") + "', 'no-segments-video-id-1', 'sponsor')"); + await db.prepare("run", "INSERT INTO noSegments (userID, videoID, category) VALUES ('" + getHash("VIPUser-noSegments") + "', 'no-segments-video-id-1', 'intro')"); + await db.prepare("run", "INSERT INTO noSegments (userID, videoID, category) VALUES ('" + getHash("VIPUser-noSegments") + "', 'noSubmitVideo', 'sponsor')"); + + await db.prepare("run", "INSERT INTO noSegments (userID, videoID, category) VALUES ('" + getHash("VIPUser-noSegments") + "', 'delete-record', 'sponsor')"); + + await db.prepare("run", "INSERT INTO noSegments (userID, videoID, category) VALUES ('" + getHash("VIPUser-noSegments") + "', 'delete-record-1', 'sponsor')"); + await db.prepare("run", "INSERT INTO noSegments (userID, videoID, category) VALUES ('" + getHash("VIPUser-noSegments") + "', 'delete-record-1', 'intro')"); }); - it('Should update the database version when starting the application', (done: Done) => { - let version = await db.prepare('get', 'SELECT key, value FROM config where key = ?', ['version']).value; - if (version > 1) done(); - else done('Version isn\'t greater than 1. Version is ' + version); + it('Should update the database version when starting the application', async () => { + let 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; }); it('Should be able to submit categories not in video (http response)', (done: Done) => { @@ -221,7 +221,7 @@ describe('noSegmentRecords', () => { }, body: JSON.stringify({}), }) - .then(res => { + .then(async res => { if (res.status === 400) { done(); } else { @@ -245,7 +245,7 @@ describe('noSegmentRecords', () => { }, body: JSON.stringify(json), }) - .then(res => { + .then(async res => { if (res.status === 400) { done(); } else { @@ -269,7 +269,7 @@ describe('noSegmentRecords', () => { }, body: JSON.stringify(json), }) - .then(res => { + .then(async res => { if (res.status === 400) { done(); } else { @@ -293,7 +293,7 @@ describe('noSegmentRecords', () => { }, body: JSON.stringify(json), }) - .then(res => { + .then(async res => { if (res.status === 400) { done(); } else { @@ -317,7 +317,7 @@ describe('noSegmentRecords', () => { }, body: JSON.stringify(json), }) - .then(res => { + .then(async res => { if (res.status === 400) { done(); } else { @@ -341,7 +341,7 @@ describe('noSegmentRecords', () => { }, body: JSON.stringify(json), }) - .then(res => { + .then(async res => { if (res.status === 400) { done(); } else { @@ -367,7 +367,7 @@ describe('noSegmentRecords', () => { }, body: JSON.stringify(json), }) - .then(res => { + .then(async res => { if (res.status === 403) { done(); } else { @@ -393,7 +393,7 @@ describe('noSegmentRecords', () => { }, body: JSON.stringify(json), }) - .then(res => { + .then(async res => { if (res.status === 200) { let result = await db.prepare('all', 'SELECT * FROM noSegments WHERE videoID = ?', ['delete-record']); if (result.length === 0) { @@ -424,7 +424,7 @@ describe('noSegmentRecords', () => { }, body: JSON.stringify(json), }) - .then(res => { + .then(async res => { if (res.status === 200) { let result = await db.prepare('all', 'SELECT * FROM noSegments WHERE videoID = ?', ['delete-record-1']); if (result.length === 1) { @@ -460,7 +460,7 @@ describe('noSegmentRecords', () => { }], }), }) - .then(res => { + .then(async res => { if (res.status === 403) { done(); } else { @@ -488,7 +488,7 @@ describe('noSegmentRecords', () => { }], },), }) - .then(res => { + .then(async res => { if (res.status === 403) { done(); } else { @@ -514,7 +514,7 @@ describe('noSegmentRecords', () => { }], }), }) - .then(res => { + .then(async res => { if (res.status === 200) { done(); } else { @@ -539,7 +539,7 @@ describe('noSegmentRecords', () => { }], }), }) - .then(res => { + .then(async res => { if (res.status === 200) { done(); } else { diff --git a/test/cases/oldGetSponsorTime.ts b/test/cases/oldGetSponsorTime.ts index 68482a0..067ea7d 100644 --- a/test/cases/oldGetSponsorTime.ts +++ b/test/cases/oldGetSponsorTime.ts @@ -19,8 +19,8 @@ import {getHash} from '../../src/utils/getHash'; describe('getVideoSponsorTime (Old get method)', () => { before(() => { let startOfQuery = "INSERT INTO sponsorTimes (videoID, startTime, endTime, votes, UUID, userID, timeSubmitted, views, category, shadowHidden, hashedVideoID) VALUES"; - db.exec(startOfQuery + "('old-testtesttest', 1, 11, 2, 'uuid-0', 'testman', 0, 50, 'sponsor', 0, '" + getHash('old-testtesttest', 1) + "')"); - db.exec(startOfQuery + "('old-testtesttest,test', 1, 11, 2, 'uuid-1', 'testman', 0, 50, 'sponsor', 0, '" + getHash('old-testtesttest,test', 1) + "')"); + db.prepare("run", startOfQuery + "('old-testtesttest', 1, 11, 2, 'uuid-0', 'testman', 0, 50, 'sponsor', 0, '" + getHash('old-testtesttest', 1) + "')"); + db.prepare("run", startOfQuery + "('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) => { diff --git a/test/cases/oldSubmitSponsorTimes.ts b/test/cases/oldSubmitSponsorTimes.ts index 616dec7..96c4292 100644 --- a/test/cases/oldSubmitSponsorTimes.ts +++ b/test/cases/oldSubmitSponsorTimes.ts @@ -7,7 +7,7 @@ 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=test") - .then(res => { + .then(async res => { if (res.status === 200) { let row = await db.prepare('get', "SELECT startTime, endTime, category FROM sponsorTimes WHERE videoID = ?", ["dQw4w9WgXcQ"]); if (row.startTime === 1 && row.endTime === 10 && row.category === "sponsor") { @@ -30,7 +30,7 @@ describe('postVideoSponsorTime (Old submission method)', () => { 'Content-Type': 'application/json', }, }) - .then(res => { + .then(async res => { if (res.status === 200) { let row = await db.prepare('get', "SELECT startTime, endTime, category FROM sponsorTimes WHERE videoID = ?", ["dQw4w9WgXcE"]); if (row.startTime === 1 && row.endTime === 11 && row.category === "sponsor") { @@ -48,7 +48,7 @@ describe('postVideoSponsorTime (Old submission method)', () => { it('Should return 400 for missing params', (done: Done) => { fetch(getbaseURL() + "/api/postVideoSponsorTimes?startTime=1&endTime=10&userID=test") - .then(res => { + .then(async res => { if (res.status === 400) done(); else done("Status code was: " + res.status); }) diff --git a/test/cases/postSkipSegments.ts b/test/cases/postSkipSegments.ts index 9f1058a..faebba7 100644 --- a/test/cases/postSkipSegments.ts +++ b/test/cases/postSkipSegments.ts @@ -15,9 +15,9 @@ describe('postSkipSegments', () => { before(() => { let startOfQuery = "INSERT INTO sponsorTimes (videoID, startTime, endTime, votes, UUID, userID, timeSubmitted, views, category, shadowHidden, hashedVideoID) VALUES"; - db.exec(startOfQuery + "('80percent_video', 0, 1000, 0, '80percent-uuid-0', '" + getHash("test") + "', 0, 0, 'interaction', 0, '80percent_video')"); - db.exec(startOfQuery + "('80percent_video', 1001, 1005, 0, '80percent-uuid-1', '" + getHash("test") + "', 0, 0, 'interaction', 0, '80percent_video')"); - db.exec(startOfQuery + "('80percent_video', 0, 5000, -2, '80percent-uuid-2', '" + getHash("test") + "', 0, 0, 'interaction', 0, '80percent_video')"); + db.prepare("run", startOfQuery + "('80percent_video', 0, 1000, 0, '80percent-uuid-0', '" + getHash("test") + "', 0, 0, 'interaction', 0, '80percent_video')"); + db.prepare("run", startOfQuery + "('80percent_video', 1001, 1005, 0, '80percent-uuid-1', '" + getHash("test") + "', 0, 0, 'interaction', 0, '80percent_video')"); + db.prepare("run", startOfQuery + "('80percent_video', 0, 5000, -2, '80percent-uuid-2', '" + getHash("test") + "', 0, 0, 'interaction', 0, '80percent_video')"); const now = Date.now(); const warnVip01Hash = getHash("warn-vip01"); @@ -27,20 +27,20 @@ describe('postSkipSegments', () => { const MILLISECONDS_IN_HOUR = 3600000; const warningExpireTime = MILLISECONDS_IN_HOUR * config.hoursAfterWarningExpires; const startOfWarningQuery = 'INSERT INTO warnings (userID, issueTime, issuerUserID, enabled) VALUES'; - db.exec(startOfWarningQuery + "('" + warnUser01Hash + "', '" + now + "', '" + warnVip01Hash + "', 1)"); - db.exec(startOfWarningQuery + "('" + warnUser01Hash + "', '" + (now - 1000) + "', '" + warnVip01Hash + "', 1)"); - db.exec(startOfWarningQuery + "('" + warnUser01Hash + "', '" + (now - 2000) + "', '" + warnVip01Hash + "', 1)"); - db.exec(startOfWarningQuery + "('" + warnUser01Hash + "', '" + (now - 3601000) + "', '" + warnVip01Hash + "', 1)"); - db.exec(startOfWarningQuery + "('" + warnUser02Hash + "', '" + now + "', '" + warnVip01Hash + "', 1)"); - db.exec(startOfWarningQuery + "('" + warnUser02Hash + "', '" + now + "', '" + warnVip01Hash + "', 1)"); - db.exec(startOfWarningQuery + "('" + warnUser02Hash + "', '" + (now - (warningExpireTime + 1000)) + "', '" + warnVip01Hash + "', 1)"); - db.exec(startOfWarningQuery + "('" + warnUser02Hash + "', '" + (now - (warningExpireTime + 2000)) + "', '" + warnVip01Hash + "', 1)"); - db.exec(startOfWarningQuery + "('" + warnUser03Hash + "', '" + now + "', '" + warnVip01Hash + "', 0)"); - db.exec(startOfWarningQuery + "('" + warnUser03Hash + "', '" + (now - 1000) + "', '" + warnVip01Hash + "', 0)"); - db.exec(startOfWarningQuery + "('" + warnUser03Hash + "', '" + (now - 2000) + "', '" + warnVip01Hash + "', 1)"); - db.exec(startOfWarningQuery + "('" + warnUser03Hash + "', '" + (now - 3601000) + "', '" + warnVip01Hash + "', 1)"); + db.prepare("run", startOfWarningQuery + "('" + warnUser01Hash + "', '" + now + "', '" + warnVip01Hash + "', 1)"); + db.prepare("run", startOfWarningQuery + "('" + warnUser01Hash + "', '" + (now - 1000) + "', '" + warnVip01Hash + "', 1)"); + db.prepare("run", startOfWarningQuery + "('" + warnUser01Hash + "', '" + (now - 2000) + "', '" + warnVip01Hash + "', 1)"); + db.prepare("run", startOfWarningQuery + "('" + warnUser01Hash + "', '" + (now - 3601000) + "', '" + warnVip01Hash + "', 1)"); + db.prepare("run", startOfWarningQuery + "('" + warnUser02Hash + "', '" + now + "', '" + warnVip01Hash + "', 1)"); + db.prepare("run", startOfWarningQuery + "('" + warnUser02Hash + "', '" + now + "', '" + warnVip01Hash + "', 1)"); + db.prepare("run", startOfWarningQuery + "('" + warnUser02Hash + "', '" + (now - (warningExpireTime + 1000)) + "', '" + warnVip01Hash + "', 1)"); + db.prepare("run", startOfWarningQuery + "('" + warnUser02Hash + "', '" + (now - (warningExpireTime + 2000)) + "', '" + warnVip01Hash + "', 1)"); + db.prepare("run", startOfWarningQuery + "('" + warnUser03Hash + "', '" + now + "', '" + warnVip01Hash + "', 0)"); + db.prepare("run", startOfWarningQuery + "('" + warnUser03Hash + "', '" + (now - 1000) + "', '" + warnVip01Hash + "', 0)"); + db.prepare("run", startOfWarningQuery + "('" + warnUser03Hash + "', '" + (now - 2000) + "', '" + warnVip01Hash + "', 1)"); + db.prepare("run", startOfWarningQuery + "('" + warnUser03Hash + "', '" + (now - 3601000) + "', '" + warnVip01Hash + "', 1)"); - db.exec("INSERT INTO vipUsers (userID) VALUES ('" + getHash("VIPUserSubmission") + "')"); + db.prepare("run", "INSERT INTO vipUsers (userID) VALUES ('" + getHash("VIPUserSubmission") + "')"); }); it('Should be able to submit a single time (Params method)', (done: Done) => { @@ -51,7 +51,7 @@ describe('postSkipSegments', () => { 'Content-Type': 'application/json', }, }) - .then(res => { + .then(async res => { if (res.status === 200) { const row = await db.prepare('get', "SELECT startTime, endTime, category FROM sponsorTimes WHERE videoID = ?", ["dQw4w9WgXcR"]); if (row.startTime === 2 && row.endTime === 10 && row.category === "sponsor") { @@ -82,7 +82,7 @@ describe('postSkipSegments', () => { }], }), }) - .then(res => { + .then(async res => { if (res.status === 200) { const row = await db.prepare('get', "SELECT startTime, endTime, locked, category FROM sponsorTimes WHERE videoID = ?", ["dQw4w9WgXcF"]); if (row.startTime === 0 && row.endTime === 10 && row.locked === 0 && row.category === "sponsor") { @@ -113,7 +113,7 @@ describe('postSkipSegments', () => { }], }), }) - .then(res => { + .then(async res => { if (res.status === 200) { const row = await db.prepare('get', "SELECT startTime, endTime, locked, category FROM sponsorTimes WHERE videoID = ?", ["vipuserIDSubmission"]); if (row.startTime === 0 && row.endTime === 10 && row.locked === 1 && row.category === "sponsor") { @@ -147,7 +147,7 @@ describe('postSkipSegments', () => { }], }), }) - .then(res => { + .then(async res => { if (res.status === 200) { const rows = await db.prepare('all', "SELECT startTime, endTime, category FROM sponsorTimes WHERE videoID = ?", ["dQw4w9WgXcR"]); let success = true; @@ -194,7 +194,7 @@ describe('postSkipSegments', () => { }], }), }) - .then(res => { + .then(async res => { if (res.status === 200) { const rows = await db.prepare('all', "SELECT startTime, endTime, category FROM sponsorTimes WHERE videoID = ? and votes > -1", ["L_jWHffIx5E"]); let success = true; @@ -243,7 +243,7 @@ describe('postSkipSegments', () => { }], }), }) - .then(res => { + .then(async res => { if (res.status === 400) { const rows = await db.prepare('all', "SELECT startTime, endTime, category FROM sponsorTimes WHERE videoID = ? and votes > -1", ["n9rIGdXnSJc"]); let success = true; @@ -291,7 +291,7 @@ describe('postSkipSegments', () => { }], }), }) - .then(res => { + .then(async res => { if (res.status === 400) { const rows = await db.prepare('all', "SELECT startTime, endTime, category FROM sponsorTimes WHERE videoID = ? and votes > -1", ["80percent_video"]); let success = rows.length == 2; @@ -385,7 +385,7 @@ describe('postSkipSegments', () => { }], }), }) - .then(res => { + .then(async res => { if (res.status === 403) { done(); // success } else { @@ -482,7 +482,7 @@ describe('postSkipSegments', () => { + "/api/postVideoSponsorTimes?startTime=9&endTime=10&userID=test", { method: 'POST', }) - .then(res => { + .then(async res => { if (res.status === 400) done(); else done(true); }) @@ -507,7 +507,7 @@ describe('postSkipSegments', () => { }], }), }) - .then(res => { + .then(async res => { if (res.status === 400) done(); else done(true); }) @@ -525,7 +525,7 @@ describe('postSkipSegments', () => { videoID: "dQw4w9WgXcQ", }), }) - .then(res => { + .then(async res => { if (res.status === 400) done(); else done(true); }) @@ -550,7 +550,7 @@ describe('postSkipSegments', () => { }], }), }) - .then(res => { + .then(async res => { if (res.status === 400) done(); else done(true); }) @@ -574,7 +574,7 @@ describe('postSkipSegments', () => { }], }), }) - .then(res => { + .then(async res => { if (res.status === 400) done(); else done(true); }) @@ -592,7 +592,7 @@ describe('postSkipSegments', () => { videoID: "dQw4w9WgXcQ", }), }) - .then(res => { + .then(async res => { if (res.status === 400) done(); else done(true); }) diff --git a/test/cases/postWarning.ts b/test/cases/postWarning.ts index eda2761..43627eb 100644 --- a/test/cases/postWarning.ts +++ b/test/cases/postWarning.ts @@ -5,7 +5,7 @@ import {getHash} from '../../src/utils/getHash'; describe('postWarning', () => { before(() => { - db.exec("INSERT INTO vipUsers (userID) VALUES ('" + getHash("warning-vip") + "')"); + db.prepare("run", "INSERT INTO vipUsers (userID) VALUES ('" + getHash("warning-vip") + "')"); }); it('Should be able to create warning if vip (exp 200)', (done: Done) => { diff --git a/test/cases/segmentShift.ts b/test/cases/segmentShift.ts index 3b9caeb..a8b7d08 100644 --- a/test/cases/segmentShift.ts +++ b/test/cases/segmentShift.ts @@ -11,7 +11,7 @@ function dbSponsorTimesAdd(db: IDatabase, videoID: string, startTime: number, en views = 0, shadowHidden = 0, hashedVideoID = `hash_${UUID}`; - db.exec(`INSERT INTO + db.prepare("run", `INSERT INTO sponsorTimes (videoID, startTime, endTime, votes, UUID, userID, timeSubmitted, views, category, shadowHidden, hashedVideoID) VALUES @@ -20,11 +20,11 @@ function dbSponsorTimesAdd(db: IDatabase, videoID: string, startTime: number, en `); } -function dbSponsorTimesSetByUUID(db: IDatabase, UUID: string, startTime: number, endTime: number) { +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]); } -function dbSponsorTimesCompareExpect(db: IDatabase, expect: any) { +async function dbSponsorTimesCompareExpect(db: IDatabase, expect: any) { for (let i = 0, len = expect.length; i < len; i++) { const expectSeg = expect[i]; let seg = await db.prepare('get', "SELECT startTime, endTime FROM sponsorTimes WHERE UUID = ?", [expectSeg.UUID]); @@ -56,7 +56,7 @@ describe('segmentShift', function () { dbSponsorTimesAdd(db, 'vsegshift01', 0, 0, 'vsegshifttest01uuid02', 'sponsor'); dbSponsorTimesAdd(db, 'vsegshift01', 0, 0, 'vsegshifttest01uuid03', 'interaction'); dbSponsorTimesAdd(db, 'vsegshift01', 0, 0, 'vsegshifttest01uuid04', 'outro'); - db.exec(`INSERT INTO vipUsers (userID) VALUES ('${vipUserID}')`); + db.prepare("run", `INSERT INTO vipUsers (userID) VALUES ('${vipUserID}')`); done(); }); @@ -82,7 +82,7 @@ describe('segmentShift', function () { endTime: 30, }), }) - .then(res => { + .then(async res => { done(res.status === 403 ? undefined : res.status); }) .catch(err => done(err)); @@ -101,7 +101,7 @@ describe('segmentShift', function () { endTime: 30, }), }) - .then(res => { + .then(async res => { if (res.status !== 200) return done(`Status code was ${res.status}`); const expect = [ { @@ -125,7 +125,7 @@ describe('segmentShift', function () { endTime: 130, }, ]; - done(dbSponsorTimesCompareExpect(db, expect)); + done(await dbSponsorTimesCompareExpect(db, expect)); }) .catch(err => done(err)); }); @@ -143,7 +143,7 @@ describe('segmentShift', function () { endTime: 75, }), }) - .then(res => { + .then(async res => { if (res.status !== 200) return done(`Status code was ${res.status}`); const expect = [ { @@ -167,7 +167,7 @@ describe('segmentShift', function () { endTime: 130, }, ]; - done(dbSponsorTimesCompareExpect(db, expect)); + done(await dbSponsorTimesCompareExpect(db, expect)); }) .catch(err => done(err)); }); @@ -185,7 +185,7 @@ describe('segmentShift', function () { endTime: 42, }), }) - .then(res => { + .then(async res => { if (res.status !== 200) return done(`Status code was ${res.status}`); const expect = [ { @@ -209,7 +209,7 @@ describe('segmentShift', function () { endTime: 130, }, ]; - done(dbSponsorTimesCompareExpect(db, expect)); + done(await dbSponsorTimesCompareExpect(db, expect)); }) .catch(err => done(err)); }); @@ -227,7 +227,7 @@ describe('segmentShift', function () { endTime: 95, }), }) - .then(res => { + .then(async res => { if (res.status !== 200) return done(`Status code was ${res.status}`); const expect = [ { @@ -251,7 +251,7 @@ describe('segmentShift', function () { endTime: 130, }, ]; - done(dbSponsorTimesCompareExpect(db, expect)); + done(await dbSponsorTimesCompareExpect(db, expect)); }) .catch(err => done(err)); }); @@ -269,7 +269,7 @@ describe('segmentShift', function () { endTime: 55, }), }) - .then(res => { + .then(async res => { if (res.status !== 200) return done(`Status code was ${res.status}`); const expect = [ { @@ -294,7 +294,7 @@ describe('segmentShift', function () { endTime: 120, }, ]; - done(dbSponsorTimesCompareExpect(db, expect)); + done(await dbSponsorTimesCompareExpect(db, expect)); }) .catch(err => done(err)); }); diff --git a/test/cases/unBan.ts b/test/cases/unBan.ts index 5324c49..fc0010c 100644 --- a/test/cases/unBan.ts +++ b/test/cases/unBan.ts @@ -8,18 +8,18 @@ import { Logger } from '../../src/utils/logger.js'; describe('unBan', () => { before(() => { - db.exec("INSERT INTO shadowBannedUsers VALUES('testMan-unBan')"); - db.exec("INSERT INTO shadowBannedUsers VALUES('testWoman-unBan')"); - db.exec("INSERT INTO shadowBannedUsers VALUES('testEntity-unBan')"); + db.prepare("run", "INSERT INTO shadowBannedUsers VALUES('testMan-unBan')"); + db.prepare("run", "INSERT INTO shadowBannedUsers VALUES('testWoman-unBan')"); + db.prepare("run", "INSERT INTO shadowBannedUsers VALUES('testEntity-unBan')"); - db.exec("INSERT INTO vipUsers (userID) VALUES ('" + getHash("VIPUser-unBan") + "')"); - db.exec("INSERT INTO noSegments (userID, videoID, category) VALUES ('" + getHash("VIPUser-unBan") + "', 'unBan-videoID-1', 'sponsor')"); + db.prepare("run", "INSERT INTO vipUsers (userID) VALUES ('" + getHash("VIPUser-unBan") + "')"); + db.prepare("run", "INSERT INTO noSegments (userID, videoID, category) VALUES ('" + getHash("VIPUser-unBan") + "', 'unBan-videoID-1', 'sponsor')"); let startOfInsertSegmentQuery = "INSERT INTO sponsorTimes (videoID, startTime, endTime, votes, UUID, userID, timeSubmitted, views, category, shadowHidden, hashedVideoID) VALUES"; - db.exec(startOfInsertSegmentQuery + "('unBan-videoID-0', 1, 11, 2, 'unBan-uuid-0', 'testMan-unBan', 0, 50, 'sponsor', 1, '" + getHash('unBan-videoID-0', 1) + "')"); - db.exec(startOfInsertSegmentQuery + "('unBan-videoID-1', 1, 11, 2, 'unBan-uuid-1', 'testWoman-unBan', 0, 50, 'sponsor', 1, '" + getHash('unBan-videoID-1', 1) + "')"); - db.exec(startOfInsertSegmentQuery + "('unBan-videoID-1', 1, 11, 2, 'unBan-uuid-2', 'testEntity-unBan', 0, 60, 'sponsor', 1, '" + getHash('unBan-videoID-1', 1) + "')"); - db.exec(startOfInsertSegmentQuery + "('unBan-videoID-2', 1, 11, 2, 'unBan-uuid-3', 'testEntity-unBan', 0, 60, 'sponsor', 1, '" + getHash('unBan-videoID-2', 1) + "')"); + db.prepare("run", startOfInsertSegmentQuery + "('unBan-videoID-0', 1, 11, 2, 'unBan-uuid-0', 'testMan-unBan', 0, 50, 'sponsor', 1, '" + getHash('unBan-videoID-0', 1) + "')"); + db.prepare("run", startOfInsertSegmentQuery + "('unBan-videoID-1', 1, 11, 2, 'unBan-uuid-1', 'testWoman-unBan', 0, 50, 'sponsor', 1, '" + getHash('unBan-videoID-1', 1) + "')"); + db.prepare("run", startOfInsertSegmentQuery + "('unBan-videoID-1', 1, 11, 2, 'unBan-uuid-2', 'testEntity-unBan', 0, 60, 'sponsor', 1, '" + getHash('unBan-videoID-1', 1) + "')"); + db.prepare("run", startOfInsertSegmentQuery + "('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) => { diff --git a/test/cases/voteOnSponsorTime.ts b/test/cases/voteOnSponsorTime.ts index c0d1a65..0b7eae2 100644 --- a/test/cases/voteOnSponsorTime.ts +++ b/test/cases/voteOnSponsorTime.ts @@ -22,51 +22,51 @@ describe('voteOnSponsorTime', () => { let startOfQuery = "INSERT INTO sponsorTimes (videoID, startTime, endTime, votes, UUID, userID, timeSubmitted, views, category, shadowHidden, hashedVideoID) VALUES"; const startOfWarningQuery = 'INSERT INTO warnings (userID, issueTime, issuerUserID, enabled) VALUES'; - db.exec(startOfQuery + "('vote-testtesttest', 1, 11, 2, 'vote-uuid-0', 'testman', 0, 50, 'sponsor', 0, '" + getHash('vote-testtesttest', 1) + "')"); - db.exec(startOfQuery + "('vote-testtesttest2', 1, 11, 2, 'vote-uuid-1', 'testman', 0, 50, 'sponsor', 0, '" + getHash('vote-testtesttest2', 1) + "')"); - db.exec(startOfQuery + "('vote-testtesttest2', 1, 11, 10, 'vote-uuid-1.5', 'testman', 0, 50, 'outro', 0, '" + getHash('vote-testtesttest2', 1) + "')"); - db.exec(startOfQuery + "('vote-testtesttest2', 1, 11, 10, 'vote-uuid-1.6', 'testman', 0, 50, 'interaction', 0, '" + getHash('vote-testtesttest2', 1) + "')"); - db.exec(startOfQuery + "('vote-testtesttest3', 20, 33, 10, 'vote-uuid-2', 'testman', 0, 50, 'intro', 0, '" + getHash('vote-testtesttest3', 1) + "')"); - db.exec(startOfQuery + "('vote-testtesttest,test', 1, 11, 100, 'vote-uuid-3', 'testman', 0, 50, 'sponsor', 0, '" + getHash('vote-testtesttest,test', 1) + "')"); - db.exec(startOfQuery + "('vote-test3', 1, 11, 2, 'vote-uuid-4', 'testman', 0, 50, 'sponsor', 0, '" + getHash('vote-test3', 1) + "')"); - db.exec(startOfQuery + "('vote-test3', 7, 22, -3, 'vote-uuid-5', 'testman', 0, 50, 'intro', 0, '" + getHash('vote-test3', 1) + "')"); - db.exec(startOfQuery + "('vote-test3', 7, 22, -3, 'vote-uuid-5_1', 'testman', 0, 50, 'intro', 0, '" + getHash('vote-test3', 1) + "')"); - db.exec(startOfQuery + "('vote-multiple', 1, 11, 2, 'vote-uuid-6', 'testman', 0, 50, 'intro', 0, '" + getHash('vote-multiple', 1) + "')"); - db.exec(startOfQuery + "('vote-multiple', 20, 33, 2, 'vote-uuid-7', 'testman', 0, 50, 'intro', 0, '" + getHash('vote-multiple', 1) + "')"); - db.exec(startOfQuery + "('voter-submitter', 1, 11, 2, 'vote-uuid-8', '" + getHash("randomID") + "', 0, 50, 'sponsor', 0, '" + getHash('voter-submitter', 1) + "')"); - db.exec(startOfQuery + "('voter-submitter2', 1, 11, 2, 'vote-uuid-9', '" + getHash("randomID2") + "', 0, 50, 'sponsor', 0, '" + getHash('voter-submitter2', 1) + "')"); - db.exec(startOfQuery + "('voter-submitter2', 1, 11, 2, 'vote-uuid-10', '" + getHash("randomID3") + "', 0, 50, 'sponsor', 0, '" + getHash('voter-submitter2', 1) + "')"); - db.exec(startOfQuery + "('voter-submitter2', 1, 11, 2, 'vote-uuid-11', '" + getHash("randomID4") + "', 0, 50, 'sponsor', 0, '" + getHash('voter-submitter2', 1) + "')"); - db.exec(startOfQuery + "('own-submission-video', 1, 11, 500, 'own-submission-uuid', '" + getHash('own-submission-id') + "', 0, 50, 'sponsor', 0, '" + getHash('own-submission-video', 1) + "')"); - db.exec(startOfQuery + "('not-own-submission-video', 1, 11, 500, 'not-own-submission-uuid', '" + getHash('somebody-else-id') + "', 0, 50, 'sponsor', 0, '" + getHash('not-own-submission-video', 1) + "')"); - db.exec(startOfQuery + "('incorrect-category', 1, 11, 500, 'incorrect-category', '" + getHash('somebody-else-id') + "', 0, 50, 'sponsor', 0, '" + getHash('incorrect-category', 1) + "')"); - db.exec(startOfQuery + "('incorrect-category-change', 1, 11, 500, 'incorrect-category-change', '" + getHash('somebody-else-id') + "', 0, 50, 'sponsor', 0, '" + getHash('incorrect-category-change', 1) + "')"); - db.exec(startOfQuery + "('vote-testtesttest', 1, 11, 2, 'warnvote-uuid-0', 'testman', 0, 50, 'sponsor', 0, '" + getHash('vote-testtesttest', 1) + "')"); - db.exec(startOfQuery + "('no-sponsor-segments-video', 1, 11, 2, 'no-sponsor-segments-uuid-0', 'no-sponsor-segments', 0, 50, 'sponsor', 0, '" + getHash('no-sponsor-segments-video', 1) + "')"); - db.exec(startOfQuery + "('no-sponsor-segments-video', 1, 11, 2, 'no-sponsor-segments-uuid-1', 'no-sponsor-segments', 0, 50, 'intro', 0, '" + getHash('no-sponsor-segments-video', 1) + "')"); - db.exec(startOfQuery + "('segment-locking-video', 1, 11, 2, 'segment-locking-uuid-1', 'segment-locking-user', 0, 50, 'intro', 0, '" + getHash('segment-locking-video', 1) + "')"); + db.prepare("run", startOfQuery + "('vote-testtesttest', 1, 11, 2, 'vote-uuid-0', 'testman', 0, 50, 'sponsor', 0, '" + getHash('vote-testtesttest', 1) + "')"); + db.prepare("run", startOfQuery + "('vote-testtesttest2', 1, 11, 2, 'vote-uuid-1', 'testman', 0, 50, 'sponsor', 0, '" + getHash('vote-testtesttest2', 1) + "')"); + db.prepare("run", startOfQuery + "('vote-testtesttest2', 1, 11, 10, 'vote-uuid-1.5', 'testman', 0, 50, 'outro', 0, '" + getHash('vote-testtesttest2', 1) + "')"); + db.prepare("run", startOfQuery + "('vote-testtesttest2', 1, 11, 10, 'vote-uuid-1.6', 'testman', 0, 50, 'interaction', 0, '" + getHash('vote-testtesttest2', 1) + "')"); + db.prepare("run", startOfQuery + "('vote-testtesttest3', 20, 33, 10, 'vote-uuid-2', 'testman', 0, 50, 'intro', 0, '" + getHash('vote-testtesttest3', 1) + "')"); + db.prepare("run", startOfQuery + "('vote-testtesttest,test', 1, 11, 100, 'vote-uuid-3', 'testman', 0, 50, 'sponsor', 0, '" + getHash('vote-testtesttest,test', 1) + "')"); + db.prepare("run", startOfQuery + "('vote-test3', 1, 11, 2, 'vote-uuid-4', 'testman', 0, 50, 'sponsor', 0, '" + getHash('vote-test3', 1) + "')"); + db.prepare("run", startOfQuery + "('vote-test3', 7, 22, -3, 'vote-uuid-5', 'testman', 0, 50, 'intro', 0, '" + getHash('vote-test3', 1) + "')"); + db.prepare("run", startOfQuery + "('vote-test3', 7, 22, -3, 'vote-uuid-5_1', 'testman', 0, 50, 'intro', 0, '" + getHash('vote-test3', 1) + "')"); + db.prepare("run", startOfQuery + "('vote-multiple', 1, 11, 2, 'vote-uuid-6', 'testman', 0, 50, 'intro', 0, '" + getHash('vote-multiple', 1) + "')"); + db.prepare("run", startOfQuery + "('vote-multiple', 20, 33, 2, 'vote-uuid-7', 'testman', 0, 50, 'intro', 0, '" + getHash('vote-multiple', 1) + "')"); + db.prepare("run", startOfQuery + "('voter-submitter', 1, 11, 2, 'vote-uuid-8', '" + getHash("randomID") + "', 0, 50, 'sponsor', 0, '" + getHash('voter-submitter', 1) + "')"); + db.prepare("run", startOfQuery + "('voter-submitter2', 1, 11, 2, 'vote-uuid-9', '" + getHash("randomID2") + "', 0, 50, 'sponsor', 0, '" + getHash('voter-submitter2', 1) + "')"); + db.prepare("run", startOfQuery + "('voter-submitter2', 1, 11, 2, 'vote-uuid-10', '" + getHash("randomID3") + "', 0, 50, 'sponsor', 0, '" + getHash('voter-submitter2', 1) + "')"); + db.prepare("run", startOfQuery + "('voter-submitter2', 1, 11, 2, 'vote-uuid-11', '" + getHash("randomID4") + "', 0, 50, 'sponsor', 0, '" + getHash('voter-submitter2', 1) + "')"); + db.prepare("run", startOfQuery + "('own-submission-video', 1, 11, 500, 'own-submission-uuid', '" + getHash('own-submission-id') + "', 0, 50, 'sponsor', 0, '" + getHash('own-submission-video', 1) + "')"); + db.prepare("run", startOfQuery + "('not-own-submission-video', 1, 11, 500, 'not-own-submission-uuid', '" + getHash('somebody-else-id') + "', 0, 50, 'sponsor', 0, '" + getHash('not-own-submission-video', 1) + "')"); + db.prepare("run", startOfQuery + "('incorrect-category', 1, 11, 500, 'incorrect-category', '" + getHash('somebody-else-id') + "', 0, 50, 'sponsor', 0, '" + getHash('incorrect-category', 1) + "')"); + db.prepare("run", startOfQuery + "('incorrect-category-change', 1, 11, 500, 'incorrect-category-change', '" + getHash('somebody-else-id') + "', 0, 50, 'sponsor', 0, '" + getHash('incorrect-category-change', 1) + "')"); + db.prepare("run", startOfQuery + "('vote-testtesttest', 1, 11, 2, 'warnvote-uuid-0', 'testman', 0, 50, 'sponsor', 0, '" + getHash('vote-testtesttest', 1) + "')"); + db.prepare("run", startOfQuery + "('no-sponsor-segments-video', 1, 11, 2, 'no-sponsor-segments-uuid-0', 'no-sponsor-segments', 0, 50, 'sponsor', 0, '" + getHash('no-sponsor-segments-video', 1) + "')"); + db.prepare("run", startOfQuery + "('no-sponsor-segments-video', 1, 11, 2, 'no-sponsor-segments-uuid-1', 'no-sponsor-segments', 0, 50, 'intro', 0, '" + getHash('no-sponsor-segments-video', 1) + "')"); + db.prepare("run", startOfQuery + "('segment-locking-video', 1, 11, 2, 'segment-locking-uuid-1', 'segment-locking-user', 0, 50, 'intro', 0, '" + getHash('segment-locking-video', 1) + "')"); - db.exec(startOfWarningQuery + "('" + warnUser01Hash + "', '" + now + "', '" + warnVip01Hash + "', 1)"); - db.exec(startOfWarningQuery + "('" + warnUser01Hash + "', '" + (now - 1000) + "', '" + warnVip01Hash + "', 1)"); - db.exec(startOfWarningQuery + "('" + warnUser01Hash + "', '" + (now - 2000) + "', '" + warnVip01Hash + "', 1)"); - db.exec(startOfWarningQuery + "('" + warnUser01Hash + "', '" + (now - 3601000) + "', '" + warnVip01Hash + "', 1)"); - db.exec(startOfWarningQuery + "('" + warnUser02Hash + "', '" + now + "', '" + warnVip01Hash + "', 1)"); - db.exec(startOfWarningQuery + "('" + warnUser02Hash + "', '" + now + "', '" + warnVip01Hash + "', 1)"); - db.exec(startOfWarningQuery + "('" + warnUser02Hash + "', '" + (now - (warningExpireTime + 1000)) + "', '" + warnVip01Hash + "', 1)"); - db.exec(startOfWarningQuery + "('" + warnUser02Hash + "', '" + (now - (warningExpireTime + 2000)) + "', '" + warnVip01Hash + "', 1)"); + db.prepare("run", startOfWarningQuery + "('" + warnUser01Hash + "', '" + now + "', '" + warnVip01Hash + "', 1)"); + db.prepare("run", startOfWarningQuery + "('" + warnUser01Hash + "', '" + (now - 1000) + "', '" + warnVip01Hash + "', 1)"); + db.prepare("run", startOfWarningQuery + "('" + warnUser01Hash + "', '" + (now - 2000) + "', '" + warnVip01Hash + "', 1)"); + db.prepare("run", startOfWarningQuery + "('" + warnUser01Hash + "', '" + (now - 3601000) + "', '" + warnVip01Hash + "', 1)"); + db.prepare("run", startOfWarningQuery + "('" + warnUser02Hash + "', '" + now + "', '" + warnVip01Hash + "', 1)"); + db.prepare("run", startOfWarningQuery + "('" + warnUser02Hash + "', '" + now + "', '" + warnVip01Hash + "', 1)"); + db.prepare("run", startOfWarningQuery + "('" + warnUser02Hash + "', '" + (now - (warningExpireTime + 1000)) + "', '" + warnVip01Hash + "', 1)"); + db.prepare("run", startOfWarningQuery + "('" + warnUser02Hash + "', '" + (now - (warningExpireTime + 2000)) + "', '" + warnVip01Hash + "', 1)"); - db.exec("INSERT INTO vipUsers (userID) VALUES ('" + getHash("VIPUser") + "')"); - privateDB.exec("INSERT INTO shadowBannedUsers (userID) VALUES ('" + getHash("randomID4") + "')"); + db.prepare("run", "INSERT INTO vipUsers (userID) VALUES ('" + getHash("VIPUser") + "')"); + privateDB.prepare("run", "INSERT INTO shadowBannedUsers (userID) VALUES ('" + getHash("randomID4") + "')"); - db.exec("INSERT INTO noSegments (videoID, userID, category) VALUES ('no-sponsor-segments-video', 'someUser', 'sponsor')"); + db.prepare("run", "INSERT INTO noSegments (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") - .then(res => { + .then(async res => { if (res.status === 200) { let row = await db.prepare('get', "SELECT votes FROM sponsorTimes WHERE UUID = ?", ["vote-uuid-0"]); if (row.votes === 3) { @@ -84,7 +84,7 @@ describe('voteOnSponsorTime', () => { it('Should be able to downvote a segment', (done: Done) => { fetch(getbaseURL() + "/api/voteOnSponsorTime?userID=randomID2&UUID=vote-uuid-2&type=0") - .then(res => { + .then(async res => { if (res.status === 200) { let row = await db.prepare('get', "SELECT votes FROM sponsorTimes WHERE UUID = ?", ["vote-uuid-2"]); if (row.votes < 10) { @@ -102,7 +102,7 @@ describe('voteOnSponsorTime', () => { 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(res => { + .then(async res => { if (res.status === 200) { let row = await db.prepare('get', "SELECT votes FROM sponsorTimes WHERE UUID = ?", ["vote-uuid-2"]); if (row.votes === 9) { @@ -120,7 +120,7 @@ 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") - .then(res => { + .then(async res => { if (res.status === 200) { let row = await db.prepare('get', "SELECT votes FROM sponsorTimes WHERE UUID = ?", ["vote-uuid-1.6"]); if (row.votes === 10) { @@ -138,7 +138,7 @@ 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") - .then(res => { + .then(async res => { if (res.status === 200) { let row = await db.prepare('get', "SELECT votes FROM sponsorTimes WHERE UUID = ?", ["vote-uuid-1"]); if (row.votes === 2) { @@ -156,7 +156,7 @@ 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") - .then(res => { + .then(async res => { if (res.status === 200) { let row = await db.prepare('get', "SELECT votes FROM sponsorTimes WHERE UUID = ?", ["vote-uuid-1.5"]); if (row.votes === 10) { @@ -174,7 +174,7 @@ describe('voteOnSponsorTime', () => { 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(res => { + .then(async res => { if (res.status === 200) { let row = await db.prepare('get', "SELECT votes FROM sponsorTimes WHERE UUID = ?", ["vote-uuid-3"]); if (row.votes <= -2) { @@ -192,7 +192,7 @@ describe('voteOnSponsorTime', () => { 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(res => { + .then(async res => { if (res.status === 200) { let row = await db.prepare('get', "SELECT votes FROM sponsorTimes WHERE UUID = ?", ["own-submission-uuid"]); if (row.votes <= -2) { @@ -210,7 +210,7 @@ describe('voteOnSponsorTime', () => { 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(res => { + .then(async res => { if (res.status === 200) { let row = await db.prepare('get', "SELECT votes FROM sponsorTimes WHERE UUID = ?", ["not-own-submission-uuid"]); if (row.votes === 499) { @@ -228,7 +228,7 @@ describe('voteOnSponsorTime', () => { 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(res => { + .then(async res => { if (res.status === 200) { let row = await db.prepare('get', "SELECT category FROM sponsorTimes WHERE UUID = ?", ["vote-uuid-4"]); let categoryRows = await db.prepare('all', "SELECT votes, category FROM categoryVotes WHERE UUID = ?", ["vote-uuid-4"]); @@ -249,7 +249,7 @@ describe('voteOnSponsorTime', () => { it('Should not able to change to an invalid category', (done: Done) => { fetch(getbaseURL() + "/api/voteOnSponsorTime?userID=randomID2&UUID=incorrect-category&category=fakecategory") - .then(res => { + .then(async res => { if (res.status === 400) { let row = await db.prepare('get', "SELECT category FROM sponsorTimes WHERE UUID = ?", ["incorrect-category"]); if (row.category === "sponsor") { @@ -267,7 +267,7 @@ describe('voteOnSponsorTime', () => { 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(res => { + .then(async res => { if (res.status === 200) { let submissionRow = await db.prepare('get', "SELECT category FROM sponsorTimes WHERE UUID = ?", ["vote-uuid-4"]); let categoryRows = await db.prepare('all', "SELECT votes, category FROM categoryVotes WHERE UUID = ?", ["vote-uuid-4"]); @@ -298,7 +298,7 @@ describe('voteOnSponsorTime', () => { const vote = (inputCat: string, assertCat: string, callback: Done) => { fetch(getbaseURL() + "/api/voteOnSponsorTime?userID=randomID2&UUID=incorrect-category-change&category=" + inputCat) - .then(res => { + .then(async res => { let row = await db.prepare('get', "SELECT category FROM sponsorTimes WHERE UUID = ?", ["incorrect-category-change"]); if (row.category === assertCat) { callback(); @@ -317,7 +317,7 @@ 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") - .then(res => { + .then(async res => { if (res.status === 200) { let row = await db.prepare('get', "SELECT category FROM sponsorTimes WHERE UUID = ?", ["vote-uuid-5"]); let row2 = await db.prepare('get', "SELECT votes FROM categoryVotes WHERE UUID = ? and category = ?", ["vote-uuid-5", "outro"]); @@ -336,7 +336,7 @@ describe('voteOnSponsorTime', () => { 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(res => { + .then(async res => { if (res.status === 200) { let row = await db.prepare('get', "SELECT category FROM sponsorTimes WHERE UUID = ?", ["vote-uuid-5"]); if (row.category === "outro") { @@ -354,7 +354,7 @@ describe('voteOnSponsorTime', () => { 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(res => { + .then(async res => { if (res.status === 400) { done(); } else { @@ -367,7 +367,7 @@ 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") - .then(res => { + .then(async res => { if (res.status === 403) { done(); } else { @@ -380,7 +380,7 @@ 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") - .then(res => { + .then(async res => { if (res.status === 200) { let row = await db.prepare('get', "SELECT votes FROM sponsorTimes WHERE UUID = ?", ["vote-uuid-5"]); if (row.votes > -3) { @@ -398,7 +398,7 @@ describe('voteOnSponsorTime', () => { 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(res => { + .then(async res => { if (res.status === 403) { done(); // success } else { @@ -411,7 +411,7 @@ describe('voteOnSponsorTime', () => { it('Non-VIP should not be able to downvote on a segment with no-segments category', (done: Done) => { fetch(getbaseURL() + "/api/voteOnSponsorTime?userID=no-segments-voter&UUID=no-sponsor-segments-uuid-0&type=0") - .then(res => { + .then(async res => { if (res.status === 403) { done(); } else { @@ -424,7 +424,7 @@ describe('voteOnSponsorTime', () => { it('Non-VIP should be able to upvote on a segment with no-segments category', (done: Done) => { fetch(getbaseURL() + "/api/voteOnSponsorTime?userID=no-segments-voter&UUID=no-sponsor-segments-uuid-0&type=1") - .then(res => { + .then(async res => { if (res.status === 200) { done(); } else { @@ -437,7 +437,7 @@ describe('voteOnSponsorTime', () => { it('Non-VIP should not be able to category vote on a segment with no-segments category', (done: Done) => { fetch(getbaseURL() + "/api/voteOnSponsorTime?userID=no-segments-voter&UUID=no-sponsor-segments-uuid-0&category=outro") - .then(res => { + .then(async res => { if (res.status === 403) { done(); } else { @@ -450,7 +450,7 @@ describe('voteOnSponsorTime', () => { it('VIP upvote should lock segment', (done: Done) => { fetch(getbaseURL() + "/api/voteOnSponsorTime?userID=VIPUser&UUID=segment-locking-uuid-1&type=1") - .then(res => { + .then(async res => { if (res.status === 200) { let row = await db.prepare('get', "SELECT locked FROM sponsorTimes WHERE UUID = ?", ["segment-locking-uuid-1"]); if (row?.locked) { @@ -468,7 +468,7 @@ describe('voteOnSponsorTime', () => { it('VIP downvote should unlock segment', (done: Done) => { fetch(getbaseURL() + "/api/voteOnSponsorTime?userID=VIPUser&UUID=segment-locking-uuid-1&type=0") - .then(res => { + .then(async res => { if (res.status === 200) { let row = await db.prepare('get', "SELECT locked FROM sponsorTimes WHERE UUID = ?", ["segment-locking-uuid-1"]); if (!row?.locked) {