mirror of
https://github.com/ajayyy/SponsorBlockServer.git
synced 2024-11-10 01:02:30 +01:00
Merge branch 'master' of https://github.com/ajayyy/SponsorBlockServer into getUserInfo/param
This commit is contained in:
commit
fdb88dd401
43 changed files with 2445 additions and 2667 deletions
|
@ -10,6 +10,7 @@
|
|||
[shadowBannedUsers](#shadowBannedUsers)
|
||||
[unlistedVideos](#unlistedVideos)
|
||||
[config](#config)
|
||||
[archivedSponsorTimes](#archivedSponsorTimes)
|
||||
|
||||
### vipUsers
|
||||
| Name | Type | |
|
||||
|
@ -35,6 +36,7 @@
|
|||
| timeSubmitted | INTEGER | not null |
|
||||
| views | INTEGER | not null |
|
||||
| category | TEXT | not null, default 'sponsor' |
|
||||
| actionType | TEXT | not null, default 'skip' |
|
||||
| service | TEXT | not null, default 'Youtube' |
|
||||
| videoDuration | INTEGER | not null, default '0' |
|
||||
| hidden | INTEGER | not null, default '0' |
|
||||
|
@ -140,7 +142,28 @@
|
|||
| key | TEXT | not null, unique |
|
||||
| value | TEXT | not null |
|
||||
|
||||
### archivedSponsorTimes
|
||||
|
||||
| Name | Type | |
|
||||
| -- | :--: | -- |
|
||||
| videoID | TEXT | not null |
|
||||
| startTime | REAL | not null |
|
||||
| endTime | REAL | not null |
|
||||
| votes | INTEGER | not null |
|
||||
| locked | INTEGER | not null, default '0' |
|
||||
| incorrectVotes | INTEGER | not null, default 1 |
|
||||
| UUID | TEXT | not null, unique |
|
||||
| userID | TEXT | not null |
|
||||
| timeSubmitted | INTEGER | not null |
|
||||
| views | INTEGER | not null |
|
||||
| category | TEXT | not null, default 'sponsor' |
|
||||
| actionType | TEXT | not null, default 'skip' |
|
||||
| service | TEXT | not null, default 'Youtube' |
|
||||
| videoDuration | INTEGER | not null, default '0' |
|
||||
| hidden | INTEGER | not null, default '0' |
|
||||
| reputation | REAL | not null, default '0' |
|
||||
| shadowHidden | INTEGER | not null |
|
||||
| hashedVideoID | TEXT | not null, default '', sha256 |
|
||||
|
||||
# Private
|
||||
|
||||
|
|
26
databases/_upgrade_sponsorTimes_21.sql
Normal file
26
databases/_upgrade_sponsorTimes_21.sql
Normal file
|
@ -0,0 +1,26 @@
|
|||
BEGIN TRANSACTION;
|
||||
|
||||
CREATE TABLE IF NOT EXISTS "archivedSponsorTimes" (
|
||||
"videoID" TEXT NOT NULL,
|
||||
"startTime" REAL NOT NULL,
|
||||
"endTime" REAL NOT NULL,
|
||||
"votes" INTEGER NOT NULL,
|
||||
"locked" INTEGER NOT NULL DEFAULT '0',
|
||||
"incorrectVotes" INTEGER NOT NULL DEFAULT 1,
|
||||
"UUID" TEXT NOT NULL UNIQUE,
|
||||
"userID" TEXT NOT NULL,
|
||||
"timeSubmitted" INTEGER NOT NULL,
|
||||
"views" INTEGER NOT NULL,
|
||||
"category" TEXT NOT NULL DEFAULT 'sponsor',
|
||||
"service" TEXT NOT NULL DEFAULT 'Youtube',
|
||||
"actionType" TEXT NOT NULL DEFAULT 'skip',
|
||||
"videoDuration" INTEGER NOT NULL DEFAULT '0',
|
||||
"hidden" INTEGER NOT NULL DEFAULT '0',
|
||||
"reputation" REAL NOT NULL DEFAULT '0',
|
||||
"shadowHidden" INTEGER NOT NULL,
|
||||
"hashedVideoID" TEXT NOT NULL DEFAULT ''
|
||||
);
|
||||
|
||||
UPDATE "config" SET value = 21 WHERE key = 'version';
|
||||
|
||||
COMMIT;
|
1101
package-lock.json
generated
1101
package-lock.json
generated
File diff suppressed because it is too large
Load diff
50
package.json
50
package.json
|
@ -16,37 +16,35 @@
|
|||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@ajayyy/lru-diskcache": "^1.1.9",
|
||||
"abort-controller": "^3.0.0",
|
||||
"better-sqlite3": "^7.1.5",
|
||||
"dotenv": "^8.2.0",
|
||||
"@types/request": "^2.48.6",
|
||||
"better-sqlite3": "^7.4.1",
|
||||
"cron": "^1.8.2",
|
||||
"express": "^4.17.1",
|
||||
"express-promise-router": "^4.1.0",
|
||||
"express-rate-limit": "^5.1.3",
|
||||
"http": "0.0.0",
|
||||
"node-fetch": "^2.6.0",
|
||||
"pg": "^8.5.1",
|
||||
"redis": "^3.1.1",
|
||||
"sync-mysql": "^3.0.1",
|
||||
"uuid": "^3.3.2"
|
||||
"express-rate-limit": "^5.3.0",
|
||||
"node-fetch": "^2.6.1",
|
||||
"pg": "^8.6.0",
|
||||
"redis": "^3.1.2",
|
||||
"sync-mysql": "^3.0.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/better-sqlite3": "^5.4.0",
|
||||
"@types/express": "^4.17.8",
|
||||
"@types/express-rate-limit": "^5.1.0",
|
||||
"@types/mocha": "^8.2.2",
|
||||
"@types/node": "^14.11.9",
|
||||
"@types/node-fetch": "^2.5.7",
|
||||
"@types/pg": "^7.14.10",
|
||||
"@types/redis": "^2.8.28",
|
||||
"@types/request": "^2.48.5",
|
||||
"@typescript-eslint/eslint-plugin": "^4.28.1",
|
||||
"@typescript-eslint/parser": "^4.28.1",
|
||||
"@types/better-sqlite3": "^5.4.3",
|
||||
"@types/cron": "^1.7.3",
|
||||
"@types/express": "^4.17.13",
|
||||
"@types/express-rate-limit": "^5.1.3",
|
||||
"@types/mocha": "^8.2.3",
|
||||
"@types/node": "^16.3.0",
|
||||
"@types/node-fetch": "^2.5.11",
|
||||
"@types/pg": "^8.6.1",
|
||||
"@types/redis": "^2.8.31",
|
||||
"@typescript-eslint/eslint-plugin": "^4.28.2",
|
||||
"@typescript-eslint/parser": "^4.28.2",
|
||||
"eslint": "^7.30.0",
|
||||
"mocha": "^8.4.0",
|
||||
"mocha": "^9.0.2",
|
||||
"nodemon": "^2.0.2",
|
||||
"sinon": "^9.2.0",
|
||||
"ts-mock-imports": "^1.3.0",
|
||||
"ts-node": "^9.0.0",
|
||||
"typescript": "^4.0.3"
|
||||
"sinon": "^11.1.1",
|
||||
"ts-mock-imports": "^1.3.7",
|
||||
"ts-node": "^10.0.0",
|
||||
"typescript": "^4.3.5"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -77,7 +77,8 @@ addDefaults(config, {
|
|||
name: "vipUsers"
|
||||
}]
|
||||
},
|
||||
diskCache: null
|
||||
diskCache: null,
|
||||
crons: null
|
||||
});
|
||||
|
||||
// Add defaults
|
||||
|
|
67
src/cronjob/downvoteSegmentArchiveJob.ts
Normal file
67
src/cronjob/downvoteSegmentArchiveJob.ts
Normal file
|
@ -0,0 +1,67 @@
|
|||
import { CronJob } from "cron";
|
||||
|
||||
import { config as serverConfig } from "../config";
|
||||
import { Logger } from "../utils/logger";
|
||||
import { db } from "../databases/databases";
|
||||
import { DBSegment } from "../types/segments.model";
|
||||
|
||||
const jobConfig = serverConfig?.crons?.downvoteSegmentArchive;
|
||||
|
||||
export const archiveDownvoteSegment = async (dayLimit: number, voteLimit: number, runTime?: number): Promise<number> => {
|
||||
const timeNow = runTime || new Date().getTime();
|
||||
const threshold = dayLimit * 86400000;
|
||||
|
||||
Logger.info(`DownvoteSegmentArchiveJob starts at ${timeNow}`);
|
||||
try {
|
||||
// insert into archive sponsorTime
|
||||
await db.prepare(
|
||||
'run',
|
||||
`INSERT INTO "archivedSponsorTimes"
|
||||
SELECT *
|
||||
FROM "sponsorTimes"
|
||||
WHERE "votes" < ? AND (? - "timeSubmitted") > ?`,
|
||||
[
|
||||
voteLimit,
|
||||
timeNow,
|
||||
threshold
|
||||
]
|
||||
) as DBSegment[];
|
||||
|
||||
} catch (err) {
|
||||
Logger.error('Execption when insert segment in archivedSponsorTimes');
|
||||
Logger.error(err);
|
||||
return 1;
|
||||
}
|
||||
|
||||
// remove from sponsorTime
|
||||
try {
|
||||
await db.prepare(
|
||||
'run',
|
||||
'DELETE FROM "sponsorTimes" WHERE "votes" < ? AND (? - "timeSubmitted") > ?',
|
||||
[
|
||||
voteLimit,
|
||||
timeNow,
|
||||
threshold
|
||||
]
|
||||
) as DBSegment[];
|
||||
|
||||
} catch (err) {
|
||||
Logger.error('Execption when deleting segment in sponsorTimes');
|
||||
Logger.error(err);
|
||||
return 1;
|
||||
}
|
||||
|
||||
Logger.info('DownvoteSegmentArchiveJob finished');
|
||||
return 0;
|
||||
};
|
||||
|
||||
const DownvoteSegmentArchiveJob = new CronJob(
|
||||
jobConfig?.schedule || "0 0 * * * 0",
|
||||
() => archiveDownvoteSegment(jobConfig?.timeThresholdInDays, jobConfig?.voteThreshold)
|
||||
);
|
||||
|
||||
if (serverConfig?.crons?.enabled && jobConfig && !jobConfig.schedule) {
|
||||
Logger.error("Invalid cron schedule for downvoteSegmentArchive");
|
||||
}
|
||||
|
||||
export default DownvoteSegmentArchiveJob;
|
13
src/cronjob/index.ts
Normal file
13
src/cronjob/index.ts
Normal file
|
@ -0,0 +1,13 @@
|
|||
import { Logger } from "../utils/logger";
|
||||
import { config } from "../config";
|
||||
import DownvoteSegmentArchiveJob from "./downvoteSegmentArchiveJob";
|
||||
|
||||
export function startAllCrons (): void {
|
||||
if (config?.crons?.enabled) {
|
||||
Logger.info("Crons started");
|
||||
|
||||
DownvoteSegmentArchiveJob.start();
|
||||
} else {
|
||||
Logger.info("Crons dissabled");
|
||||
}
|
||||
}
|
|
@ -2,13 +2,17 @@ import {config} from "./config";
|
|||
import {initDb} from './databases/databases';
|
||||
import {createServer} from "./app";
|
||||
import {Logger} from "./utils/logger";
|
||||
import {startAllCrons} from "./cronjob";
|
||||
|
||||
async function init() {
|
||||
await initDb();
|
||||
|
||||
createServer(() => {
|
||||
Logger.info("Server started on port " + config.port + ".");
|
||||
|
||||
// ignite cron job after server created
|
||||
startAllCrons();
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
init();
|
|
@ -13,11 +13,15 @@ export async function getLockCategories(req: Request, res: Response): Promise<Re
|
|||
|
||||
try {
|
||||
// Get existing lock categories markers
|
||||
const lockedCategories = await db.prepare('all', 'SELECT "category" from "lockCategories" where "videoID" = ?', [videoID]) as {category: Category}[];
|
||||
if (lockedCategories.length === 0 || !lockedCategories[0]) return res.sendStatus(404);
|
||||
// map to array in JS becaues of SQL incompatibilities
|
||||
const categories = Object.values(lockedCategories).map((entry) => entry.category);
|
||||
const row = await db.prepare('all', 'SELECT "category", "reason" from "lockCategories" where "videoID" = ?', [videoID]) as {category: Category, reason: string}[];
|
||||
// map categories to array in JS becaues of SQL incompatibilities
|
||||
const categories = row.map(item => item.category);
|
||||
if (categories.length === 0 || !categories[0]) return res.sendStatus(404);
|
||||
// Get longest lock reason
|
||||
const reason = row.map(item => item.reason)
|
||||
.reduce((a,b) => (a.length > b.length) ? a : b);
|
||||
return res.send({
|
||||
reason,
|
||||
categories
|
||||
});
|
||||
} catch (err) {
|
||||
|
|
|
@ -7,13 +7,15 @@ import { Category, VideoID, VideoIDHash } from "../types/segments.model";
|
|||
interface LockResultByHash {
|
||||
videoID: VideoID,
|
||||
hash: VideoIDHash,
|
||||
reason: string,
|
||||
categories: Category[]
|
||||
}
|
||||
|
||||
interface DBLock {
|
||||
videoID: VideoID,
|
||||
hash: VideoIDHash,
|
||||
category: Category
|
||||
category: Category,
|
||||
reason: string,
|
||||
}
|
||||
|
||||
const mergeLocks = (source: DBLock[]) => {
|
||||
|
@ -22,12 +24,15 @@ const mergeLocks = (source: DBLock[]) => {
|
|||
// videoID already exists
|
||||
const destMatch = dest.find(s => s.videoID === obj.videoID);
|
||||
if (destMatch) {
|
||||
// override longer reason
|
||||
if (obj.reason.length > destMatch.reason.length) destMatch.reason = obj.reason;
|
||||
// push to categories
|
||||
destMatch.categories.push(obj.category);
|
||||
} else {
|
||||
dest.push({
|
||||
videoID: obj.videoID,
|
||||
hash: obj.hash,
|
||||
reason: obj.reason,
|
||||
categories: [obj.category]
|
||||
});
|
||||
}
|
||||
|
@ -45,7 +50,7 @@ export async function getLockCategoriesByHash(req: Request, res: Response): Prom
|
|||
|
||||
try {
|
||||
// Get existing lock categories markers
|
||||
const lockedRows = await db.prepare('all', 'SELECT "videoID", "hashedVideoID" as "hash", "category" from "lockCategories" where "hashedVideoID" LIKE ?', [hashPrefix + '%']) as DBLock[];
|
||||
const lockedRows = await db.prepare('all', 'SELECT "videoID", "hashedVideoID" as "hash", "category", "reason" from "lockCategories" where "hashedVideoID" LIKE ?', [hashPrefix + '%']) as DBLock[];
|
||||
if (lockedRows.length === 0 || !lockedRows[0]) return res.sendStatus(404);
|
||||
// merge all locks
|
||||
return res.send(mergeLocks(lockedRows));
|
||||
|
|
|
@ -275,6 +275,10 @@ async function chooseSegments(segments: DBSegment[], max: number): Promise<DBSeg
|
|||
*/
|
||||
async function handleGetSegments(req: Request, res: Response): Promise<Segment[] | false> {
|
||||
const videoID = req.query.videoID as VideoID;
|
||||
if (!videoID) {
|
||||
res.status(400).send("videoID not specified");
|
||||
return false;
|
||||
}
|
||||
// Default to sponsor
|
||||
// If using params instead of JSON, only one category can be pulled
|
||||
const categories: Category[] = req.query.categories
|
||||
|
|
|
@ -5,7 +5,7 @@ import { ActionType, Category, SegmentUUID, Service, VideoIDHash } from '../type
|
|||
|
||||
export async function getSkipSegmentsByHash(req: Request, res: Response): Promise<Response> {
|
||||
let hashPrefix = req.params.prefix as VideoIDHash;
|
||||
if (!hashPrefixTester(req.params.prefix)) {
|
||||
if (!req.params.prefix || !hashPrefixTester(req.params.prefix)) {
|
||||
return res.status(400).send("Hash prefix does not match format requirements."); // Exit early on faulty prefix
|
||||
}
|
||||
hashPrefix = hashPrefix.toLowerCase() as VideoIDHash;
|
||||
|
|
|
@ -338,11 +338,13 @@ export async function postSkipSegments(req: Request, res: Response): Promise<Res
|
|||
});
|
||||
|
||||
const invalidFields = [];
|
||||
const errors = [];
|
||||
if (typeof videoID !== 'string') {
|
||||
invalidFields.push('videoID');
|
||||
}
|
||||
if (typeof userID !== 'string' || userID.length < 30) {
|
||||
invalidFields.push('userID');
|
||||
if (userID.length < 30) errors.push(`userID must be at least 30 characters long`);
|
||||
}
|
||||
if (!Array.isArray(segments) || segments.length < 1) {
|
||||
invalidFields.push('segments');
|
||||
|
@ -350,8 +352,9 @@ export async function postSkipSegments(req: Request, res: Response): Promise<Res
|
|||
|
||||
if (invalidFields.length !== 0) {
|
||||
// invalid request
|
||||
const fields = invalidFields.reduce((p, c, i) => p + (i !== 0 ? ', ' : '') + c, '');
|
||||
return res.status(400).send(`No valid ${fields} field(s) provided`);
|
||||
const formattedFields = invalidFields.reduce((p, c, i) => p + (i !== 0 ? ', ' : '') + c, '');
|
||||
const formattedErrors = errors.reduce((p, c, i) => p + (i !== 0 ? '. ' : ' ') + c, '');
|
||||
return res.status(400).send(`No valid ${formattedFields} field(s) provided.${formattedErrors}`);
|
||||
}
|
||||
|
||||
//hash the userID
|
||||
|
|
|
@ -6,6 +6,8 @@ import {getHash} from '../utils/getHash';
|
|||
import { HashedUserID, UserID } from '../types/user.model';
|
||||
|
||||
export async function postWarning(req: Request, res: Response): Promise<Response> {
|
||||
// exit early if no body passed in
|
||||
if (!req.body.userID && !req.body.issuerUserID) return res.status(400).json({"message": "Missing parameters"});
|
||||
// Collect user input data
|
||||
const issuerUserID: HashedUserID = getHash(<UserID> req.body.issuerUserID);
|
||||
const userID: UserID = req.body.userID;
|
||||
|
|
|
@ -62,7 +62,7 @@ export async function setUsername(req: Request, res: Response): Promise<Response
|
|||
const locked = adminUserIDInput === undefined ? 0 : 1;
|
||||
let oldUserName = '';
|
||||
|
||||
if (row?.userName?.length > 0) {
|
||||
if (row?.userName !== undefined) {
|
||||
//already exists, update this row
|
||||
oldUserName = row.userName;
|
||||
await db.prepare('run', `UPDATE "userNames" SET "userName" = ?, "locked" = ? WHERE "userID" = ?`, [userName, locked, userID]);
|
||||
|
|
|
@ -258,6 +258,10 @@ export async function voteOnSponsorTime(req: Request, res: Response): Promise<Re
|
|||
//invalid request
|
||||
return res.sendStatus(400);
|
||||
}
|
||||
if (paramUserID.length < 30 && config.mode !== "test") {
|
||||
// Ignore this vote, invalid
|
||||
return res.sendStatus(200);
|
||||
}
|
||||
|
||||
//hash the userID
|
||||
const nonAnonUserID = getHash(paramUserID);
|
||||
|
@ -428,7 +432,7 @@ export async function voteOnSponsorTime(req: Request, res: Response): Promise<Re
|
|||
if (isVIP && incrementAmount > 0 && voteTypeEnum === voteTypes.normal) {
|
||||
// Unide and Lock this submission
|
||||
await db.prepare('run', 'UPDATE "sponsorTimes" SET locked = 1, hidden = 0 WHERE "UUID" = ?', [UUID]);
|
||||
} else if (isVIP && incrementAmount < 0 && voteTypeEnum === voteTypes.normal) {
|
||||
} else if (isVIP && incrementAmount <= 0 && voteTypeEnum === voteTypes.normal) {
|
||||
// Unlock if a VIP downvotes it
|
||||
await db.prepare('run', 'UPDATE "sponsorTimes" SET locked = 0 WHERE "UUID" = ?', [UUID]);
|
||||
}
|
||||
|
|
|
@ -44,6 +44,7 @@ export interface SBSConfig {
|
|||
postgres?: PoolConfig;
|
||||
dumpDatabase?: DumpDatabase;
|
||||
diskCache: CacheOptions;
|
||||
crons: CronJobOptions;
|
||||
}
|
||||
|
||||
export interface WebhookConfig {
|
||||
|
@ -81,3 +82,17 @@ export interface DumpDatabaseTable {
|
|||
name: string;
|
||||
order?: string;
|
||||
}
|
||||
|
||||
export interface CronJobDefault {
|
||||
schedule: string;
|
||||
}
|
||||
|
||||
export interface CronJobOptions {
|
||||
enabled: boolean;
|
||||
downvoteSegmentArchive: CronJobDefault & DownvoteSegmentArchiveCron;
|
||||
}
|
||||
|
||||
export interface DownvoteSegmentArchiveCron {
|
||||
voteThreshold: number;
|
||||
timeThresholdInDays: number;
|
||||
}
|
|
@ -14,5 +14,5 @@ export function skipSegmentsHashKey(hashedVideoIDPrefix: VideoIDHash, service: S
|
|||
}
|
||||
|
||||
export function reputationKey(userID: UserID): string {
|
||||
return "reputation.user." + userID;
|
||||
return "reputation.user.v2." + userID;
|
||||
}
|
|
@ -7,12 +7,14 @@ interface ReputationDBResult {
|
|||
totalSubmissions: number,
|
||||
downvotedSubmissions: number,
|
||||
nonSelfDownvotedSubmissions: number,
|
||||
upvotedSum: number,
|
||||
votedSum: number,
|
||||
lockedSum: number,
|
||||
semiOldUpvotedSubmissions: number,
|
||||
oldUpvotedSubmissions: number
|
||||
}
|
||||
|
||||
export async function getReputation(userID: UserID): Promise<number> {
|
||||
const weekAgo = Date.now() - 1000 * 60 * 60 * 24 * 45; // 45 days ago
|
||||
const pastDate = Date.now() - 1000 * 60 * 60 * 24 * 45; // 45 days ago
|
||||
// 1596240000000 is August 1st 2020, a little after auto upvote was disabled
|
||||
const fetchFromDB = () => db.prepare("get",
|
||||
|
@ -23,10 +25,11 @@ export async function getReputation(userID: UserID): Promise<number> {
|
|||
WHERE b."userID" = ?
|
||||
AND b."votes" > 0 AND b."category" = "a"."category" AND b."videoID" = "a"."videoID" LIMIT 1)
|
||||
THEN 1 ELSE 0 END) AS "nonSelfDownvotedSubmissions",
|
||||
SUM(CASE WHEN "votes" > 0 AND "timeSubmitted" > 1596240000000 THEN "votes" ELSE 0 END) AS "upvotedSum",
|
||||
SUM(CASE WHEN "timeSubmitted" > 1596240000000 THEN "votes" ELSE 0 END) AS "votedSum",
|
||||
SUM(locked) AS "lockedSum",
|
||||
SUM(CASE WHEN "timeSubmitted" < ? AND "timeSubmitted" > 1596240000000 AND "votes" > 0 THEN 1 ELSE 0 END) AS "semiOldUpvotedSubmissions",
|
||||
SUM(CASE WHEN "timeSubmitted" < ? AND "timeSubmitted" > 1596240000000 AND "votes" > 0 THEN 1 ELSE 0 END) AS "oldUpvotedSubmissions"
|
||||
FROM "sponsorTimes" as "a" WHERE "userID" = ?`, [userID, pastDate, userID]) as Promise<ReputationDBResult>;
|
||||
FROM "sponsorTimes" as "a" WHERE "userID" = ?`, [userID, weekAgo, pastDate, userID]) as Promise<ReputationDBResult>;
|
||||
|
||||
const result = await QueryCacher.get(fetchFromDB, reputationKey(userID));
|
||||
|
||||
|
@ -45,11 +48,19 @@ export async function getReputation(userID: UserID): Promise<number> {
|
|||
return convertRange(Math.min(nonSelfDownvoteRatio, 0.4), 0.05, 0.4, -0.5, -2.5);
|
||||
}
|
||||
|
||||
if (result.oldUpvotedSubmissions < 3 || result.upvotedSum < 5) {
|
||||
if (result.votedSum < 5) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return convertRange(Math.min(result.upvotedSum, 150), 5, 150, 0, 7) + convertRange(Math.min(result.lockedSum ?? 0, 50), 0, 50, 0, 20);
|
||||
if (result.oldUpvotedSubmissions < 3) {
|
||||
if (result.semiOldUpvotedSubmissions > 3) {
|
||||
return convertRange(Math.min(result.votedSum, 150), 5, 150, 0, 2) + convertRange(Math.min(result.lockedSum ?? 0, 50), 0, 50, 0, 5);
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
return convertRange(Math.min(result.votedSum, 150), 5, 150, 0, 7) + convertRange(Math.min(result.lockedSum ?? 0, 50), 0, 50, 0, 20);
|
||||
}
|
||||
|
||||
function convertRange(value: number, currentMin: number, currentMax: number, targetMin: number, targetMax: number): number {
|
||||
|
|
172
test/cases/downvoteSegmentArchiveJob.ts
Normal file
172
test/cases/downvoteSegmentArchiveJob.ts
Normal file
|
@ -0,0 +1,172 @@
|
|||
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';
|
||||
|
||||
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)],
|
||||
|
||||
['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)],
|
||||
|
||||
['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)],
|
||||
|
||||
['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', () => {
|
||||
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]);
|
||||
}
|
||||
|
||||
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;
|
||||
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"');
|
||||
});
|
||||
|
||||
const getArchivedSegment = (): Promise<DBSegment[]> => {
|
||||
return db.prepare('all', 'SELECT * FROM "archivedSponsorTimes"');
|
||||
};
|
||||
|
||||
const getSegmentsInMainTable = (dayLimit: number, voteLimit: number, now: number): Promise<DBSegment[]> => {
|
||||
return db.prepare(
|
||||
'all',
|
||||
'SELECT * FROM "sponsorTimes" WHERE "votes" < ? AND (? - "timeSubmitted") > ?',
|
||||
[
|
||||
voteLimit,
|
||||
now,
|
||||
dayLimit * 86400000,
|
||||
]
|
||||
);
|
||||
};
|
||||
|
||||
const countSegmentInMainTable = (): Promise<number> => {
|
||||
return db.prepare(
|
||||
'get',
|
||||
'SELECT COUNT(*) as count FROM "sponsorTimes"'
|
||||
).then(res => res.count);
|
||||
};
|
||||
|
||||
it('Should archive all records match', async () => {
|
||||
const dayLimit = 20;
|
||||
const voteLimit = 0;
|
||||
const time = new Date('December 17, 2022').getTime();
|
||||
const res = await archiveDownvoteSegment(dayLimit, voteLimit, time);
|
||||
assert.strictEqual(res, 0, 'Expection in archiveDownvoteSegment');
|
||||
|
||||
// check segments in archived table
|
||||
const archivedSegment = await getArchivedSegment();
|
||||
assert.strictEqual(archivedSegment.length, 4, `Incorrect segment in archiveTable: ${archivedSegment.length} instead of 4`);
|
||||
|
||||
// check segments not in main table
|
||||
const segments = await getSegmentsInMainTable(dayLimit, voteLimit, time);
|
||||
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');
|
||||
});
|
||||
|
||||
it('Should archive records with vote < -1 match', async () => {
|
||||
const dayLimit = 20;
|
||||
const voteLimit = -1;
|
||||
const time = new Date('December 17, 2022').getTime();
|
||||
const res = await archiveDownvoteSegment(dayLimit, voteLimit, time);
|
||||
assert.strictEqual(res, 0, '');
|
||||
|
||||
// check segments in archived table
|
||||
const archivedSegment = await getArchivedSegment();
|
||||
assert.strictEqual(archivedSegment.length, 3, `Incorrect segment in archiveTable: ${archivedSegment.length} instead of 3`);
|
||||
|
||||
// check segments not in main table
|
||||
const segments = await getSegmentsInMainTable(dayLimit, voteLimit, time);
|
||||
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');
|
||||
});
|
||||
|
||||
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 res = await archiveDownvoteSegment(dayLimit, voteLimit, time);
|
||||
assert.strictEqual(res, 0, '');
|
||||
|
||||
// check segments in archived table
|
||||
const archivedSegment = await getArchivedSegment();
|
||||
assert.strictEqual(archivedSegment.length, 1, `Incorrect segment in archiveTable: ${archivedSegment.length} instead of 1`);
|
||||
|
||||
assert.strictEqual(archivedSegment[0].votes, -4, `Incorrect segment vote in archiveTable: ${archivedSegment[0].votes} instead of -4`);
|
||||
|
||||
// check segments not in main table
|
||||
const segments = await getSegmentsInMainTable(dayLimit, voteLimit, time);
|
||||
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');
|
||||
});
|
||||
|
||||
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 res = await archiveDownvoteSegment(dayLimit, voteLimit, time);
|
||||
assert.strictEqual(res, 0, '');
|
||||
|
||||
// check segments in archived table
|
||||
const archivedSegment = await getArchivedSegment();
|
||||
assert.strictEqual(archivedSegment.length, 2, `Incorrect segment in archiveTable: ${archivedSegment.length} instead of 2`);
|
||||
|
||||
// check segments not in main table
|
||||
const segments = await getSegmentsInMainTable(dayLimit, voteLimit, time);
|
||||
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');
|
||||
});
|
||||
|
||||
it('Should not archive any', async () => {
|
||||
const dayLimit = 300;
|
||||
const voteLimit = -2;
|
||||
const time = new Date('December 17, 2021').getTime();
|
||||
const res = await archiveDownvoteSegment(dayLimit, voteLimit, time);
|
||||
assert.strictEqual(res, 0, '');
|
||||
|
||||
// check segments in archived table
|
||||
const archivedSegment = await getArchivedSegment();
|
||||
assert.strictEqual(archivedSegment.length, 0, `Incorrect segment in archiveTable: ${archivedSegment.length} instead of 0`);
|
||||
|
||||
// check segments not in main table
|
||||
const segments = await getSegmentsInMainTable(dayLimit, voteLimit, time);
|
||||
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');
|
||||
});
|
||||
});
|
|
@ -2,6 +2,7 @@ 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', () => {
|
||||
before((done: Done) => {
|
||||
|
@ -11,20 +12,20 @@ describe('getIsUserVIP', () => {
|
|||
it('Should be able to get a 200', (done: Done) => {
|
||||
fetch(getbaseURL() + "/api/isUserVIP?userID=supertestman")
|
||||
.then(res => {
|
||||
if (res.status !== 200) done("non 200: " + res.status);
|
||||
else done(); // pass
|
||||
assert.strictEqual(res.status, 200, "response should be 200");
|
||||
done();
|
||||
})
|
||||
.catch(() => done("couldn't call endpoint"));
|
||||
.catch(err => done(err));
|
||||
});
|
||||
|
||||
|
||||
it('Should get a 400 if no userID', (done: Done) => {
|
||||
fetch(getbaseURL() + "/api/isUserVIP")
|
||||
.then(res => {
|
||||
if (res.status !== 400) done("non 400: " + res.status);
|
||||
else done(); // pass
|
||||
assert.strictEqual(res.status, 400, "response should be 400");
|
||||
done();
|
||||
})
|
||||
.catch(() => done("couldn't call endpoint"));
|
||||
.catch(err => done(err));
|
||||
});
|
||||
|
||||
it('Should say a VIP is a VIP', (done: Done) => {
|
||||
|
@ -33,11 +34,11 @@ describe('getIsUserVIP', () => {
|
|||
if (res.status !== 200) done("non 200: " + res.status);
|
||||
else {
|
||||
const data = await res.json();
|
||||
if (data.vip === true) done(); // pass
|
||||
else done("Result was non-vip when should have been vip");
|
||||
assert.strictEqual(data.vip, true);
|
||||
done();
|
||||
}
|
||||
})
|
||||
.catch(() => done("couldn't call endpoint"));
|
||||
.catch(err => done(err));
|
||||
});
|
||||
|
||||
it('Should say a normal user is not a VIP', (done: Done) => {
|
||||
|
@ -46,10 +47,10 @@ describe('getIsUserVIP', () => {
|
|||
if (res.status !== 200) done("non 200: " + res.status);
|
||||
else {
|
||||
const data = await res.json();
|
||||
if (data.vip === false) done(); // pass
|
||||
else done("Result was vip when should have been non-vip");
|
||||
assert.strictEqual(data.vip, false);
|
||||
done();
|
||||
}
|
||||
})
|
||||
.catch(() => done("couldn't call endpoint"));
|
||||
.catch(err => done(err));
|
||||
});
|
||||
});
|
||||
|
|
|
@ -2,6 +2,7 @@ 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', () => {
|
||||
|
@ -9,76 +10,71 @@ describe('getLockCategories', () => {
|
|||
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']);
|
||||
const insertLockCategoryQuery = 'INSERT INTO "lockCategories" ("userID", "videoID", "category", "reason") VALUES (?, ?, ?, ?)';
|
||||
await db.prepare("run", insertLockCategoryQuery, [getHash("VIPUser-getLockCategories"), 'getLock-1', 'sponsor', '1-short']);
|
||||
await db.prepare("run", insertLockCategoryQuery, [getHash("VIPUser-getLockCategories"), 'getLock-1', 'interaction', '1-longer-reason']);
|
||||
|
||||
await db.prepare("run", insertLockCategoryQuery, [getHash("VIPUser-getLockCategories"), 'getLock-2', 'preview']);
|
||||
await db.prepare("run", insertLockCategoryQuery, [getHash("VIPUser-getLockCategories"), 'getLock-2', 'preview', '2-reason']);
|
||||
|
||||
await db.prepare("run", insertLockCategoryQuery, [getHash("VIPUser-getLockCategories"), 'getLock-3', 'nonmusic']);
|
||||
await db.prepare("run", insertLockCategoryQuery, [getHash("VIPUser-getLockCategories"), 'getLock-3', 'nonmusic', '3-reason']);
|
||||
});
|
||||
|
||||
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;
|
||||
if (version > 20) return;
|
||||
else return 'Version isn\'t greater than 20. Version is ' + version;
|
||||
});
|
||||
|
||||
it('Should be able to get multiple locks', (done: Done) => {
|
||||
fetch(getbaseURL() + '/api/lockCategories?videoID=getLock-1')
|
||||
.then(async res => {
|
||||
if (res.status !== 200) {
|
||||
done("non 200");
|
||||
} else {
|
||||
const data = await res.json();
|
||||
if (data.categories.length !== 2) {
|
||||
done(`Returned incorrect number of locks "${data.categories.length}"`);
|
||||
} else if (data.categories[0] !== "sponsor") {
|
||||
done(`Returned incorrect category "${data.categories[0]}"`);
|
||||
} else if (data.categories[1] !== "interaction") {
|
||||
done(`Returned incorrect category "${data.categories[1]}"`);
|
||||
} else {
|
||||
done(); // pass
|
||||
}
|
||||
}
|
||||
assert.strictEqual(res.status, 200);
|
||||
const data = await res.json();
|
||||
const expected = {
|
||||
categories: [
|
||||
"sponsor",
|
||||
"interaction"
|
||||
],
|
||||
reason: "1-longer-reason"
|
||||
};
|
||||
assert.deepStrictEqual(data, expected);
|
||||
done();
|
||||
})
|
||||
.catch(() => ("couldn't call endpoint"));
|
||||
.catch(err => done(err));
|
||||
});
|
||||
|
||||
it('Should be able to get single locks', (done: Done) => {
|
||||
fetch(getbaseURL() + '/api/lockCategories?videoID=getLock-2')
|
||||
.then(async res => {
|
||||
if (res.status !== 200) {
|
||||
done("non 200");
|
||||
} else {
|
||||
const data = await res.json();
|
||||
if (data.categories.length !== 1) {
|
||||
done('Returned incorrect number of locks "' + data.categories.length + '"');
|
||||
} else if (data.categories[0] !== "preview") {
|
||||
done(`Returned incorrect category "${data.categories[0].category}"`);
|
||||
} else {
|
||||
done(); // pass
|
||||
}
|
||||
}
|
||||
assert.strictEqual(res.status, 200);
|
||||
const data = await res.json();
|
||||
const expected = {
|
||||
categories: [
|
||||
"preview"
|
||||
],
|
||||
reason: "2-reason"
|
||||
};
|
||||
assert.deepStrictEqual(data, expected);
|
||||
done();
|
||||
})
|
||||
.catch(() => ("couldn't call endpoint"));
|
||||
.catch(err => done(err));
|
||||
});
|
||||
|
||||
it('should return 404 if no lock exists', (done: Done) => {
|
||||
fetch(getbaseURL() + '/api/lockCategories?videoID=getLock-0')
|
||||
.then(res => {
|
||||
if (res.status !== 404) done('non 404 (' + res.status + ')');
|
||||
else done(); // pass
|
||||
assert.strictEqual(res.status, 404);
|
||||
done();
|
||||
})
|
||||
.catch(() => ("couldn't call endpoint"));
|
||||
.catch(err => done(err));
|
||||
});
|
||||
|
||||
it('should return 400 if no videoID specified', (done: Done) => {
|
||||
fetch(getbaseURL() + '/api/lockCategories')
|
||||
.then(res => {
|
||||
if (res.status !== 400) done('non 400 (' + res.status + ')');
|
||||
else done(); // pass
|
||||
assert.strictEqual(res.status, 400);
|
||||
done();
|
||||
})
|
||||
.catch(() => ("couldn't call endpoint"));
|
||||
.catch(err => done(err));
|
||||
});
|
||||
});
|
||||
|
|
|
@ -2,175 +2,168 @@ 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', () => {
|
||||
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']);
|
||||
const insertLockCategoryQuery = 'INSERT INTO "lockCategories" ("userID", "videoID", "category", "reason", "hashedVideoID") VALUES (?, ?, ?, ?, ?)';
|
||||
await db.prepare("run", insertLockCategoryQuery, [getHash("VIPUser-getLockCategories"), 'getLockHash-1', 'sponsor', '1-reason-short', '67a654898fda3a5541774aea345796c7709982bb6018cb08d22a18eeddccc1d0']);
|
||||
await db.prepare("run", insertLockCategoryQuery, [getHash("VIPUser-getLockCategories"), 'getLockHash-1', 'interaction', '1-reason-longer', '67a654898fda3a5541774aea345796c7709982bb6018cb08d22a18eeddccc1d0']);
|
||||
|
||||
await db.prepare("run", insertLockCategoryQuery, [getHash("VIPUser-getLockCategories"), 'getLockHash-2', 'preview', 'dff09120437b4bd594dffae5f3cde3cfc5f6099fb01d0ef4051919b2908d9a50']);
|
||||
await db.prepare("run", insertLockCategoryQuery, [getHash("VIPUser-getLockCategories"), 'getLockHash-2', 'preview', '2-reason', 'dff09120437b4bd594dffae5f3cde3cfc5f6099fb01d0ef4051919b2908d9a50']);
|
||||
|
||||
await db.prepare("run", insertLockCategoryQuery, [getHash("VIPUser-getLockCategories"), 'getLockHash-3', 'nonmusic', 'bf1b122fd5630e0df8626d00c4a95c58954ad715e5595b0f75a19ac131e28928']);
|
||||
await db.prepare("run", insertLockCategoryQuery, [getHash("VIPUser-getLockCategories"), 'getLockHash-3', 'nonmusic', '3-reason', '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', 'fake1-reason', 'b05a20424f24a53dac1b059fb78d861ba9723645026be2174c93a94f9106bb35']);
|
||||
await db.prepare("run", insertLockCategoryQuery, [getHash("VIPUser-getLockCategories"), 'fakehash-2', 'intro', 'fake2-longer-reason', 'b05acd1cd6ec7dffe5ffea64ada91ae7469d6db2ce21c7e30ad7fa62075d450']);
|
||||
await db.prepare("run", insertLockCategoryQuery, [getHash("VIPUser-getLockCategories"), 'fakehash-2', 'preview', 'fake2-short', 'b05acd1cd6ec7dffe5ffea64ada91ae7469d6db2ce21c7e30ad7fa62075d450']);
|
||||
});
|
||||
|
||||
it('Database should be greater or equal to version 18', async () => {
|
||||
it('Database should be greater or equal to version 20', 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;
|
||||
if (version >= 20) return;
|
||||
else return 'Version isn\'t greater than 20. Version is ' + version;
|
||||
});
|
||||
|
||||
it('Should be able to get multiple locks in one object', (done: Done) => {
|
||||
fetch(getbaseURL() + '/api/lockCategories/67a65')
|
||||
.then(async res => {
|
||||
if (res.status !== 200) {
|
||||
done("non 200");
|
||||
} else {
|
||||
const data = await res.json();
|
||||
if (data.length !== 1) {
|
||||
done(`Returned incorrect number of videos "${data.length}"`);
|
||||
} else if (data[0].videoID !== "getLockHash-1") {
|
||||
done(`Returned incorrect videoID "${data[0].videoID}"`);
|
||||
} else if (data[0].hash !== getHash("getLockHash-1", 1)) {
|
||||
done(`Returned incorrect hash "${data[0].hash}"`);
|
||||
} else if (data[0].categories[0] !== "sponsor") {
|
||||
done(`Returned incorrect category "${data[0].categories[0]}"`);
|
||||
} else if (data[0].categories[1] !== "interaction") {
|
||||
done(`Returned incorrect category "${data[0].categories[1]}"`);
|
||||
} else {
|
||||
done(); // pass
|
||||
}
|
||||
}
|
||||
assert.strictEqual(res.status, 200);
|
||||
const data = await res.json();
|
||||
const expected = [{
|
||||
videoID: "getLockHash-1",
|
||||
hash: getHash("getLockHash-1", 1),
|
||||
categories: [
|
||||
"sponsor",
|
||||
"interaction"
|
||||
],
|
||||
reason: "1-reason-longer"
|
||||
}];
|
||||
assert.deepStrictEqual(data, expected);
|
||||
done();
|
||||
})
|
||||
.catch(() => ("couldn't call endpoint"));
|
||||
.catch(err => done(err));
|
||||
});
|
||||
|
||||
it('Should be able to get single lock', (done: Done) => {
|
||||
fetch(getbaseURL() + '/api/lockCategories/dff09')
|
||||
.then(async res => {
|
||||
if (res.status !== 200) {
|
||||
done("non 200");
|
||||
} else {
|
||||
const data = await res.json();
|
||||
if (data.length !== 1) {
|
||||
done('Returned incorrect number of videos "' + data.length + '"');
|
||||
} else if (data[0].videoID !== "getLockHash-2") {
|
||||
done(`Returned incorrect videoID "${data[0].videoID}"`);
|
||||
} else if (data[0].hash !== getHash("getLockHash-2", 1)) {
|
||||
done(`Returned incorrect hashedVideoID hash "${data[0].hash}"`);
|
||||
} else if (data[0].categories.length !== 1) {
|
||||
done(`Returned incorrect number of categories "${data[0].categories.length}"`);
|
||||
} else if (data[0].categories[0] !== "preview") {
|
||||
done(`Returned incorrect category "${data[0].categories[0]}"`);
|
||||
} else {
|
||||
done(); // pass
|
||||
}
|
||||
}
|
||||
assert.strictEqual(res.status, 200);
|
||||
const data = await res.json();
|
||||
const expected = [{
|
||||
videoID: "getLockHash-2",
|
||||
hash: getHash("getLockHash-2", 1),
|
||||
categories: [
|
||||
"preview"
|
||||
],
|
||||
reason: "2-reason"
|
||||
}];
|
||||
assert.deepStrictEqual(data, expected);
|
||||
done();
|
||||
})
|
||||
.catch(() => ("couldn't call endpoint"));
|
||||
.catch(err => done(err));
|
||||
});
|
||||
|
||||
it('Should be able to get by half full hash', (done: Done) => {
|
||||
fetch(getbaseURL() + '/api/lockCategories/bf1b122fd5630e0df8626d00c4a95c58')
|
||||
.then(async res => {
|
||||
if (res.status !== 200) {
|
||||
done("non 200");
|
||||
} else {
|
||||
const data = await res.json();
|
||||
if (data.length !== 1) {
|
||||
done('Returned incorrect number of videos "' + data.length + '"');
|
||||
} else if (data[0].videoID !== "getLockHash-3") {
|
||||
done(`Returned incorrect videoID "${data[0].videoID}"`);
|
||||
} else if (data[0].hash !== getHash("getLockHash-3", 1)) {
|
||||
done(`Returned incorrect hashedVideoID hash "${data[0].hash}"`);
|
||||
} else if (data[0].categories.length !== 1) {
|
||||
done(`Returned incorrect number of categories "${data[0].categories.length}"`);
|
||||
} else if (data[0].categories[0] !== "nonmusic") {
|
||||
done(`Returned incorrect category "${data[0].categories[0]}"`);
|
||||
} else {
|
||||
done(); // pass
|
||||
}
|
||||
}
|
||||
assert.strictEqual(res.status, 200);
|
||||
const data = await res.json();
|
||||
const expected = [{
|
||||
videoID: "getLockHash-3",
|
||||
hash: getHash("getLockHash-3", 1),
|
||||
categories: [
|
||||
"nonmusic"
|
||||
],
|
||||
reason: "3-reason"
|
||||
}];
|
||||
assert.deepStrictEqual(data, expected);
|
||||
done();
|
||||
})
|
||||
.catch(() => ("couldn't call endpoint"));
|
||||
.catch(err => done(err));
|
||||
});
|
||||
|
||||
it('Should be able to get multiple by similar hash with multiple categories', (done: Done) => {
|
||||
fetch(getbaseURL() + '/api/lockCategories/b05a')
|
||||
.then(async res => {
|
||||
if (res.status !== 200) {
|
||||
done("non 200");
|
||||
} else {
|
||||
const data = await res.json();
|
||||
if (data.length !== 2) {
|
||||
done(`Returned incorrect number of locks "${data.length}"`);
|
||||
} else if (data[0].videoID !== "fakehash-1") {
|
||||
done(`Returned incorrect videoID "${data[0].videoID}"`);
|
||||
} else if (data[1].videoID !== "fakehash-2") {
|
||||
done(`Returned incorrect videoID "${data[1].videoID}"`);
|
||||
} else if (data[0].hash !== "b05a20424f24a53dac1b059fb78d861ba9723645026be2174c93a94f9106bb35") {
|
||||
done(`Returned incorrect hashedVideoID hash "${data[0].hash}"`);
|
||||
} else if (data[1].hash !== "b05acd1cd6ec7dffe5ffea64ada91ae7469d6db2ce21c7e30ad7fa62075d450") {
|
||||
done(`Returned incorrect hashedVideoID hash "${data[1].hash}"`);
|
||||
} else if (data[0].categories.length !== 1) {
|
||||
done(`Returned incorrect number of categories "${data[0].categories.length}"`);
|
||||
} else if (data[1].categories.length !== 2) {
|
||||
done(`Returned incorrect number of categories "${data[1].categories.length}"`);
|
||||
} else if (data[0].categories[0] !== "outro") {
|
||||
done(`Returned incorrect category "${data[0].category}"`);
|
||||
} else if (data[1].categories[0] !== "intro") {
|
||||
done(`Returned incorrect category "${data[1].category}"`);
|
||||
} else if (data[1].categories[1] !== "preview") {
|
||||
done(`Returned incorrect category "${data[1].category}"`);
|
||||
} else {
|
||||
done(); // pass
|
||||
}
|
||||
}
|
||||
assert.strictEqual(res.status, 200);
|
||||
const data = await res.json();
|
||||
const expected = [{
|
||||
videoID: "fakehash-1",
|
||||
hash: "b05a20424f24a53dac1b059fb78d861ba9723645026be2174c93a94f9106bb35",
|
||||
categories: [
|
||||
"outro"
|
||||
],
|
||||
reason: "fake1-reason"
|
||||
}, {
|
||||
videoID: "fakehash-2",
|
||||
hash: "b05acd1cd6ec7dffe5ffea64ada91ae7469d6db2ce21c7e30ad7fa62075d450",
|
||||
categories: [
|
||||
"intro",
|
||||
"preview"
|
||||
],
|
||||
reason: "fake2-longer-reason"
|
||||
}];
|
||||
assert.deepStrictEqual(data, expected);
|
||||
done();
|
||||
})
|
||||
.catch(() => ("couldn't call endpoint"));
|
||||
.catch(err => done(err));
|
||||
});
|
||||
|
||||
it('should return 404 once hash prefix varies', (done: Done) => {
|
||||
fetch(getbaseURL() + '/api/lockCategories/aaaaaa')
|
||||
fetch(getbaseURL() + '/api/lockCategories/b05aa')
|
||||
.then(res => {
|
||||
if (res.status !== 404) done('non 404 (' + res.status + ')');
|
||||
else done(); // pass
|
||||
assert.strictEqual(res.status, 404);
|
||||
done();
|
||||
})
|
||||
.catch(() => ("couldn't call endpoint"));
|
||||
.catch(err => done(err));
|
||||
});
|
||||
|
||||
it('should return 404 if no lock exists', (done: Done) => {
|
||||
fetch(getbaseURL() + '/api/lockCategories/aaaaaa')
|
||||
.then(res => {
|
||||
if (res.status !== 404) done('non 404 (' + res.status + ')');
|
||||
else done(); // pass
|
||||
assert.strictEqual(res.status, 404);
|
||||
done();
|
||||
})
|
||||
.catch(() => ("couldn't call endpoint"));
|
||||
.catch(err => done(err));
|
||||
});
|
||||
|
||||
it('should return 400 if no videoID specified', (done: Done) => {
|
||||
fetch(getbaseURL() + '/api/lockCategories/')
|
||||
.then(res => {
|
||||
if (res.status !== 400) done('non 400 (' + res.status + ')');
|
||||
else done(); // pass
|
||||
assert.strictEqual(res.status, 400);
|
||||
done();
|
||||
})
|
||||
.catch(() => ("couldn't call endpoint"));
|
||||
.catch(err => done(err));
|
||||
});
|
||||
|
||||
it('should return 400 if full hash sent', (done: Done) => {
|
||||
fetch(getbaseURL() + '/api/lockCategories/b05a20424f24a53dac1b059fb78d861ba9723645026be2174c93a94f9106bb35')
|
||||
.then(res => {
|
||||
if (res.status !== 400) done('non 400 (' + res.status + ')');
|
||||
else done(); // pass
|
||||
assert.strictEqual(res.status, 400);
|
||||
done();
|
||||
})
|
||||
.catch(() => ("couldn't call endpoint"));
|
||||
.catch(err => done(err));
|
||||
});
|
||||
|
||||
it('should return 400 if hash too short', (done: Done) => {
|
||||
fetch(getbaseURL() + '/api/lockCategories/00')
|
||||
.then(res => {
|
||||
assert.strictEqual(res.status, 400);
|
||||
done();
|
||||
})
|
||||
.catch(err => done(err));
|
||||
});
|
||||
|
||||
it('should return 400 if no hash specified', (done: Done) => {
|
||||
fetch(getbaseURL() + '/api/lockCategories/')
|
||||
.then(res => {
|
||||
assert.strictEqual(res.status, 400);
|
||||
done();
|
||||
})
|
||||
.catch(err => done(err));
|
||||
});
|
||||
});
|
||||
|
|
|
@ -2,6 +2,7 @@ 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', () => {
|
||||
before(async () => {
|
||||
|
@ -13,10 +14,16 @@ describe('getSavedTimeForUser', () => {
|
|||
|
||||
it('Should be able to get a 200', (done: Done) => {
|
||||
fetch(getbaseURL() + "/api/getSavedTimeForUser?userID=testman")
|
||||
.then(res => {
|
||||
if (res.status !== 200) done("non 200");
|
||||
else done(); // pass
|
||||
.then(async res => {
|
||||
const data = await res.json();
|
||||
// (end-start)*minute * views
|
||||
const savedMinutes = ((11-1)/60) * 50;
|
||||
const expected = {
|
||||
timeSaved: savedMinutes
|
||||
};
|
||||
assert.deepStrictEqual(data, expected);
|
||||
done();
|
||||
})
|
||||
.catch(() => done("couldn't call endpoint"));
|
||||
.catch((err) => done(err));
|
||||
});
|
||||
});
|
||||
|
|
|
@ -2,6 +2,7 @@ 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);
|
||||
|
@ -43,231 +44,188 @@ describe('getSegmentInfo', () => {
|
|||
it('Should be able to retreive upvoted segment', (done: Done) => {
|
||||
fetch(getbaseURL() + `/api/segmentInfo?UUID=${upvotedID}`)
|
||||
.then(async res => {
|
||||
if (res.status !== 200) done("Status code was: " + res.status);
|
||||
else {
|
||||
const data = await res.json();
|
||||
if (data[0].videoID === "upvoted" && data[0].votes === 2) {
|
||||
done();
|
||||
} else {
|
||||
done("Received incorrect body: " + (await res.text()));
|
||||
}
|
||||
}
|
||||
assert.strictEqual(res.status, 200);
|
||||
const data = await res.json();
|
||||
assert.strictEqual(data[0].videoID, "upvoted");
|
||||
assert.strictEqual(data[0].votes, 2);
|
||||
done();
|
||||
})
|
||||
.catch(() => "Couldn't call endpoint");
|
||||
.catch(err => done(err));
|
||||
});
|
||||
|
||||
it('Should be able to retreive downvoted segment', (done: Done) => {
|
||||
fetch(getbaseURL() + `/api/segmentInfo?UUID=${downvotedID}`)
|
||||
.then(async res => {
|
||||
if (res.status !== 200) done("Status code was: " + res.status);
|
||||
else {
|
||||
const data = await res.json();
|
||||
if (data[0].videoID === "downvoted" && data[0].votes === -2) {
|
||||
done();
|
||||
} else {
|
||||
done("Received incorrect body: " + (await res.text()));
|
||||
}
|
||||
}
|
||||
assert.strictEqual(res.status, 200);
|
||||
const data = await res.json();
|
||||
assert.strictEqual(data[0].videoID, "downvoted");
|
||||
assert.strictEqual(data[0].votes, -2);
|
||||
done();
|
||||
})
|
||||
.catch(() => "Couldn't call endpoint");
|
||||
.catch(err => done(err));
|
||||
});
|
||||
|
||||
it('Should be able to retreive locked up segment', (done: Done) => {
|
||||
fetch(getbaseURL() + `/api/segmentInfo?UUID=${lockedupID}`)
|
||||
.then(async res => {
|
||||
if (res.status !== 200) done("Status code was: " + res.status);
|
||||
else {
|
||||
const data = await res.json();
|
||||
if (data[0].videoID === "locked-up" && data[0].locked === 1 && data[0].votes === 2) {
|
||||
done();
|
||||
} else {
|
||||
done ("Received incorrect body: " + (await res.text()));
|
||||
}
|
||||
}
|
||||
assert.strictEqual(res.status, 200);
|
||||
const data = await res.json();
|
||||
assert.strictEqual(data[0].videoID, "locked-up");
|
||||
assert.strictEqual(data[0].locked, 1);
|
||||
assert.strictEqual(data[0].votes, 2);
|
||||
done();
|
||||
})
|
||||
.catch(() => "Couldn't call endpoint");
|
||||
.catch(err => done(err));
|
||||
});
|
||||
|
||||
it('Should be able to retreive infinite vote segment', (done: Done) => {
|
||||
fetch(getbaseURL() + `/api/segmentInfo?UUID=${infvotesID}`)
|
||||
.then(async res => {
|
||||
if (res.status !== 200) done("Status code was: " + res.status);
|
||||
else {
|
||||
const data = await res.json();
|
||||
if (data[0].videoID === "infvotes" && data[0].votes === 100000) {
|
||||
done();
|
||||
} else {
|
||||
done("Received incorrect body: " + (await res.text()));
|
||||
}
|
||||
}
|
||||
assert.strictEqual(res.status, 200);
|
||||
const data = await res.json();
|
||||
assert.strictEqual(data[0].videoID, "infvotes");
|
||||
assert.strictEqual(data[0].votes, 100000);
|
||||
done();
|
||||
})
|
||||
.catch(() => "Couldn't call endpoint");
|
||||
.catch(err => done(err));
|
||||
});
|
||||
|
||||
it('Should be able to retreive shadowhidden segment', (done: Done) => {
|
||||
fetch(getbaseURL() + `/api/segmentInfo?UUID=${shadowhiddenID}`)
|
||||
.then(async res => {
|
||||
if (res.status !== 200) done("Status code was: " + res.status);
|
||||
else {
|
||||
const data = await res.json();
|
||||
if (data[0].videoID === "shadowhidden" && data[0].shadowHidden === 1) {
|
||||
done();
|
||||
} else {
|
||||
done ("Received incorrect body: " + (await res.text()));
|
||||
}
|
||||
}
|
||||
assert.strictEqual(res.status, 200);
|
||||
const data = await res.json();
|
||||
assert.strictEqual(data[0].videoID, "shadowhidden");
|
||||
assert.strictEqual(data[0].shadowHidden, 1);
|
||||
done();
|
||||
})
|
||||
.catch(() => "Couldn't call endpoint");
|
||||
.catch(err => done(err));
|
||||
});
|
||||
|
||||
it('Should be able to retreive locked down segment', (done: Done) => {
|
||||
fetch(getbaseURL() + `/api/segmentInfo?UUID=${lockeddownID}`)
|
||||
.then(async res => {
|
||||
if (res.status !== 200) done("Status code was: " + res.status);
|
||||
else {
|
||||
const data = await res.json();
|
||||
if (data[0].videoID === "locked-down" && data[0].votes === -2 && data[0].locked === 1) {
|
||||
done();
|
||||
} else {
|
||||
done ("Received incorrect body: " + (await res.text()));
|
||||
}
|
||||
}
|
||||
assert.strictEqual(res.status, 200);
|
||||
const data = await res.json();
|
||||
assert.strictEqual(data[0].videoID, "locked-down");
|
||||
assert.strictEqual(data[0].votes, -2);
|
||||
assert.strictEqual(data[0].locked, 1);
|
||||
done();
|
||||
})
|
||||
.catch(() => "Couldn't call endpoint");
|
||||
.catch(err => done(err));
|
||||
});
|
||||
|
||||
it('Should be able to retreive hidden segment', (done: Done) => {
|
||||
fetch(getbaseURL() + `/api/segmentInfo?UUID=${hiddenID}`)
|
||||
.then(async res => {
|
||||
if (res.status !== 200) done("Status code was: " + res.status);
|
||||
else {
|
||||
const data = await res.json();
|
||||
if (data[0].videoID === "hidden" && data[0].hidden === 1) {
|
||||
done();
|
||||
} else {
|
||||
done ("Received incorrect body: " + (await res.text()));
|
||||
}
|
||||
}
|
||||
assert.strictEqual(res.status, 200);
|
||||
const data = await res.json();
|
||||
assert.strictEqual(data[0].videoID, "hidden");
|
||||
assert.strictEqual(data[0].hidden, 1);
|
||||
done();
|
||||
})
|
||||
.catch(() => "Couldn't call endpoint");
|
||||
.catch(err => done(err));
|
||||
});
|
||||
|
||||
it('Should be able to retreive segment with old ID', (done: Done) => {
|
||||
fetch(getbaseURL() + `/api/segmentInfo?UUID=${oldID}`)
|
||||
.then(async res => {
|
||||
if (res.status !== 200) done("Status code was: " + res.status);
|
||||
else {
|
||||
const data = await res.json();
|
||||
if (data[0].videoID === "oldID" && data[0].votes === 1) {
|
||||
done();
|
||||
} else {
|
||||
done("Received incorrect body: " + (await res.text()));
|
||||
}
|
||||
}
|
||||
assert.strictEqual(res.status, 200);
|
||||
const data = await res.json();
|
||||
assert.strictEqual(data[0].videoID, "oldID");
|
||||
assert.strictEqual(data[0].votes, 1);
|
||||
done();
|
||||
})
|
||||
.catch(() => "Couldn't call endpoint");
|
||||
.catch(err => done(err));
|
||||
});
|
||||
|
||||
it('Should be able to retreive single segment in array', (done: Done) => {
|
||||
fetch(getbaseURL() + `/api/segmentInfo?UUIDs=["${upvotedID}"]`)
|
||||
.then(async res => {
|
||||
if (res.status !== 200) done("Status code was: " + res.status);
|
||||
else {
|
||||
const data = await res.json();
|
||||
if (data.length === 1 && data[0].videoID === "upvoted" && data[0].votes === 2) {
|
||||
done();
|
||||
} else {
|
||||
done("Received incorrect body: " + (await res.text()));
|
||||
}
|
||||
}
|
||||
assert.strictEqual(res.status, 200);
|
||||
const data = await res.json();
|
||||
assert.strictEqual(data.length, 1);
|
||||
assert.strictEqual(data[0].videoID, "upvoted");
|
||||
assert.strictEqual(data[0].votes, 2);
|
||||
done();
|
||||
})
|
||||
.catch(() => "Couldn't call endpoint");
|
||||
.catch(err => done(err));
|
||||
});
|
||||
|
||||
it('Should be able to retreive multiple segments in array', (done: Done) => {
|
||||
fetch(getbaseURL() + `/api/segmentInfo?UUIDs=["${upvotedID}", "${downvotedID}"]`)
|
||||
.then(async res => {
|
||||
if (res.status !== 200) done("Status code was: " + res.status);
|
||||
else {
|
||||
const data = await res.json();
|
||||
if (data.length === 2 &&
|
||||
(data[0].videoID === "upvoted" && data[0].votes === 2) &&
|
||||
(data[1].videoID === "downvoted" && data[1].votes === -2)) {
|
||||
done();
|
||||
} else {
|
||||
done("Received incorrect body: " + (await res.text()));
|
||||
}
|
||||
}
|
||||
assert.strictEqual(res.status, 200);
|
||||
const data = await res.json();
|
||||
assert.strictEqual(data.length, 2);
|
||||
assert.strictEqual(data[0].videoID, "upvoted");
|
||||
assert.strictEqual(data[0].votes, 2);
|
||||
assert.strictEqual(data[1].videoID, "downvoted");
|
||||
assert.strictEqual(data[1].votes, -2);
|
||||
done();
|
||||
})
|
||||
.catch(() => "Couldn't call endpoint");
|
||||
.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`)
|
||||
.then(async res => {
|
||||
if (res.status !== 200) done("Status code was: " + res.status);
|
||||
else {
|
||||
const data = await res.json();
|
||||
if (data[0].videoID === "upvoted" && data[0].votes === 2) {
|
||||
done();
|
||||
} else {
|
||||
done("Received incorrect body: " + (await res.text()));
|
||||
}
|
||||
}
|
||||
assert.strictEqual(res.status, 200);
|
||||
const data = await res.json();
|
||||
assert.strictEqual(data[0].videoID, "upvoted");
|
||||
assert.strictEqual(data[0].votes, 2);
|
||||
done();
|
||||
})
|
||||
.catch(() => "Couldn't call endpoint");
|
||||
.catch(err => done(err));
|
||||
});
|
||||
|
||||
it('Should return 400 if array passed to UUID', (done: Done) => {
|
||||
fetch(getbaseURL() + `/api/segmentInfo?UUID=["${upvotedID}", "${downvotedID}"]`)
|
||||
.then(res => {
|
||||
if (res.status !== 400) done("non 400 respone code: " + res.status);
|
||||
else done(); // pass
|
||||
assert.strictEqual(res.status, 400);
|
||||
done();
|
||||
})
|
||||
.catch(() => ("couldn't call endpoint"));
|
||||
.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]")
|
||||
.then(res => {
|
||||
if (res.status !== 400) done("non 404 respone code: " + res.status);
|
||||
else done(); // pass
|
||||
assert.strictEqual(res.status, 400);
|
||||
done();
|
||||
})
|
||||
.catch(() => ("couldn't call endpoint"));
|
||||
.catch(err => done(err));
|
||||
});
|
||||
|
||||
it('Should return 400 if bad UUID passed', (done: Done) => {
|
||||
fetch(getbaseURL() + "/api/segmentInfo?UUID=notarealuuid")
|
||||
.then(res => {
|
||||
if (res.status !== 400) done("non 400 respone code: " + res.status);
|
||||
else done(); // pass
|
||||
assert.strictEqual(res.status, 400);
|
||||
done();
|
||||
})
|
||||
.catch(() => ("couldn't call endpoint"));
|
||||
.catch(err => done(err));
|
||||
});
|
||||
|
||||
it('Should return 400 if bad UUIDs passed in array', (done: Done) => {
|
||||
fetch(getbaseURL() + `/api/segmentInfo?UUIDs=["notarealuuid", "anotherfakeuuid"]`)
|
||||
.then(res => {
|
||||
if (res.status !== 400) done("non 400 respone code: " + res.status);
|
||||
else done(); // pass
|
||||
assert.strictEqual(res.status, 400);
|
||||
done();
|
||||
})
|
||||
.catch(() => ("couldn't call endpoint"));
|
||||
.catch(err => done(err));
|
||||
});
|
||||
|
||||
it('Should return good UUID when mixed with bad UUIDs', (done: Done) => {
|
||||
fetch(getbaseURL() + `/api/segmentInfo?UUIDs=["${upvotedID}", "anotherfakeuuid"]`)
|
||||
.then(async res => {
|
||||
if (res.status !== 200) done("Status code was: " + res.status);
|
||||
else {
|
||||
const data = await res.json();
|
||||
if (data.length === 1 && data[0].videoID === "upvoted" && data[0].votes === 2) {
|
||||
done();
|
||||
} else {
|
||||
done("Received incorrect body: " + (await res.text()));
|
||||
}
|
||||
}
|
||||
assert.strictEqual(res.status, 200);
|
||||
const data = await res.json();
|
||||
assert.strictEqual(data.length, 1);
|
||||
assert.strictEqual(data[0].videoID, "upvoted");
|
||||
assert.strictEqual(data[0].votes, 2);
|
||||
done();
|
||||
})
|
||||
.catch(() => ("couldn't call endpoint"));
|
||||
.catch(err => done(err));
|
||||
});
|
||||
|
||||
it('Should cut off array at 10', function(done: Done) {
|
||||
|
@ -275,34 +233,31 @@ describe('getSegmentInfo', () => {
|
|||
const filledIDArray = `["${upvotedID}", "${downvotedID}", "${lockedupID}", "${shadowhiddenID}", "${lockeddownID}", "${hiddenID}", "${fillerID1}", "${fillerID2}", "${fillerID3}", "${fillerID4}", "${fillerID5}"]`;
|
||||
fetch(getbaseURL() + `/api/segmentInfo?UUIDs=${filledIDArray}`)
|
||||
.then(async res => {
|
||||
if (res.status !== 200) done("Status code was: " + res.status);
|
||||
else {
|
||||
const data = await res.json();
|
||||
// last segment should be fillerID4
|
||||
if (data.length === 10 && data[0].videoID === "upvoted" && data[0].votes === 2 && data[9].videoID === "filler" && data[9].UUID === fillerID4) {
|
||||
done();
|
||||
} else {
|
||||
done("Received incorrect body: " + (await res.text()));
|
||||
}
|
||||
}
|
||||
assert.strictEqual(res.status, 200);
|
||||
const data = await res.json();
|
||||
assert.strictEqual(data.length, 10);
|
||||
assert.strictEqual(data[0].videoID, "upvoted");
|
||||
assert.strictEqual(data[0].votes, 2);
|
||||
assert.strictEqual(data[9].videoID, "filler");
|
||||
assert.strictEqual(data[9].UUID, fillerID4);
|
||||
done();
|
||||
})
|
||||
.catch(() => ("couldn't call endpoint"));
|
||||
.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}"]`)
|
||||
.then(async res => {
|
||||
if (res.status !== 200) done("Status code was: " + res.status);
|
||||
else {
|
||||
const data = await res.json();
|
||||
if (data.length === 2 && data[0].videoID === "upvoted" && data[0].votes === 2 && data[1].videoID === "downvoted" && data[1].votes === -2) {
|
||||
done();
|
||||
} else {
|
||||
done("Received incorrect body: " + (await res.text()));
|
||||
}
|
||||
}
|
||||
assert.strictEqual(res.status, 200);
|
||||
const data = await res.json();
|
||||
assert.strictEqual(data.length, 2);
|
||||
assert.strictEqual(data[0].videoID, "upvoted");
|
||||
assert.strictEqual(data[0].votes, 2);
|
||||
assert.strictEqual(data[1].videoID, "downvoted");
|
||||
assert.strictEqual(data[1].votes, -2);
|
||||
done();
|
||||
})
|
||||
.catch(() => ("couldn't call endpoint"));
|
||||
.catch(err => done(err));
|
||||
});
|
||||
|
||||
it('Should return 400 if UUID not found', (done: Done) => {
|
||||
|
@ -311,41 +266,33 @@ describe('getSegmentInfo', () => {
|
|||
if (res.status !== 400) done("non 400 respone code: " + res.status);
|
||||
else done(); // pass
|
||||
})
|
||||
.catch(() => ("couldn't call endpoint"));
|
||||
.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}`)
|
||||
.then(async res => {
|
||||
if (res.status !== 200) done("Status code was: " + res.status);
|
||||
else {
|
||||
const data = await res.json();
|
||||
if (data.length === 2 &&
|
||||
(data[0].videoID === "upvoted" && data[0].votes === 2) &&
|
||||
(data[1].videoID === "downvoted" && data[1].votes === -2)) {
|
||||
done();
|
||||
} else {
|
||||
done("Received incorrect body: " + (await res.text()));
|
||||
}
|
||||
}
|
||||
assert.strictEqual(res.status, 200);
|
||||
const data = await res.json();
|
||||
assert.strictEqual(data.length, 2);
|
||||
assert.strictEqual(data[0].videoID, "upvoted");
|
||||
assert.strictEqual(data[1].videoID, "downvoted");
|
||||
assert.strictEqual(data[0].votes, 2);
|
||||
assert.strictEqual(data[1].votes, -2);
|
||||
done();
|
||||
})
|
||||
.catch(() => "Couldn't call endpoint");
|
||||
.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}"]`)
|
||||
.then(async res => {
|
||||
if (res.status !== 200) done("Status code was: " + res.status);
|
||||
else {
|
||||
const data = await res.json();
|
||||
if (data.length === 1 &&
|
||||
(data[0].videoID === "upvoted" && data[0].votes === 2)) {
|
||||
done();
|
||||
} else {
|
||||
done("Received incorrect body: " + (await res.text()));
|
||||
}
|
||||
}
|
||||
assert.strictEqual(res.status, 200);
|
||||
const data = await res.json();
|
||||
assert.strictEqual(data[0].videoID, "upvoted");
|
||||
assert.strictEqual(data[0].votes, 2);
|
||||
done();
|
||||
})
|
||||
.catch(() => "Couldn't call endpoint");
|
||||
.catch(err => done(err));
|
||||
});
|
||||
});
|
||||
|
|
|
@ -2,6 +2,7 @@ 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', () => {
|
||||
before(async () => {
|
||||
|
@ -29,372 +30,323 @@ describe('getSkipSegments', () => {
|
|||
it('Should be able to get a time by category 1', (done: Done) => {
|
||||
fetch(getbaseURL() + "/api/skipSegments?videoID=testtesttest&category=sponsor")
|
||||
.then(async res => {
|
||||
if (res.status !== 200) done("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" && data[0].videoDuration === 100) {
|
||||
done();
|
||||
} else {
|
||||
done("Received incorrect body: " + (await res.text()));
|
||||
}
|
||||
}
|
||||
})
|
||||
.catch(() => "Couldn't call endpoint");
|
||||
assert.strictEqual(res.status, 200);
|
||||
const data = await res.json();
|
||||
assert.strictEqual(data.length, 1);
|
||||
assert.strictEqual(data[0].segment[0], 1);
|
||||
assert.strictEqual(data[0].segment[1], 11);
|
||||
assert.strictEqual(data[0].category, "sponsor");
|
||||
assert.strictEqual(data[0].UUID, "1-uuid-0");
|
||||
assert.strictEqual(data[0].videoDuration, 100);
|
||||
done();
|
||||
})
|
||||
.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")
|
||||
.then(async res => {
|
||||
if (res.status !== 200) done("Status code was: " + res.status);
|
||||
else {
|
||||
const data = await res.json();
|
||||
if (data.length === 1 && data[0].segment[0] === 12 && data[0].segment[1] === 14
|
||||
&& data[0].category === "sponsor" && data[0].UUID === "1-uuid-0-2" && data[0].videoDuration === 100) {
|
||||
done();
|
||||
} else {
|
||||
done("Received incorrect body: " + (await res.text()));
|
||||
}
|
||||
}
|
||||
assert.strictEqual(res.status, 200);
|
||||
const data = await res.json();
|
||||
assert.strictEqual(data.length, 1);
|
||||
assert.strictEqual(data[0].segment[0], 12);
|
||||
assert.strictEqual(data[0].segment[1], 14);
|
||||
assert.strictEqual(data[0].category, "sponsor");
|
||||
assert.strictEqual(data[0].UUID, "1-uuid-0-2");
|
||||
assert.strictEqual(data[0].videoDuration, 100);
|
||||
done();
|
||||
})
|
||||
.catch(() => "Couldn't call endpoint");
|
||||
.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")
|
||||
.then(async res => {
|
||||
if (res.status !== 200) done("Status code was: " + res.status);
|
||||
else {
|
||||
const data = await res.json();
|
||||
if (data.length === 2 && data[0].segment[0] === 1 && data[0].segment[1] === 11
|
||||
&& data[0].category === "sponsor" && data[0].UUID === "1-uuid-0"
|
||||
&& data[1].UUID === "1-uuid-0-2" && data[0].videoDuration === 100) {
|
||||
done();
|
||||
} else {
|
||||
done("Received incorrect body: " + (await res.text()));
|
||||
}
|
||||
}
|
||||
assert.strictEqual(res.status, 200);
|
||||
const data = await res.json();
|
||||
assert.strictEqual(data.length, 2);
|
||||
assert.strictEqual(data[0].segment[0], 1);
|
||||
assert.strictEqual(data[0].segment[1], 11);
|
||||
assert.strictEqual(data[0].category, "sponsor");
|
||||
assert.strictEqual(data[0].UUID, "1-uuid-0");
|
||||
assert.strictEqual(data[1].UUID, "1-uuid-0-2");
|
||||
assert.strictEqual(data[0].videoDuration, 100);
|
||||
done();
|
||||
})
|
||||
.catch(() => "Couldn't call endpoint");
|
||||
.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"]')
|
||||
.then(async res => {
|
||||
if (res.status !== 200) done("Status code was: " + res.status);
|
||||
else {
|
||||
const data = await res.json();
|
||||
if (data.length === 2 && data[0].segment[0] === 1 && data[0].segment[1] === 11
|
||||
&& data[0].category === "sponsor" && data[0].UUID === "1-uuid-0"
|
||||
&& data[1].UUID === "1-uuid-0-2" && data[0].videoDuration === 100) {
|
||||
done();
|
||||
} else {
|
||||
done("Received incorrect body: " + (await res.text()));
|
||||
}
|
||||
}
|
||||
assert.strictEqual(res.status, 200);
|
||||
const data = await res.json();
|
||||
assert.strictEqual(data.length, 2);
|
||||
assert.strictEqual(data[0].segment[0], 1);
|
||||
assert.strictEqual(data[0].segment[1], 11);
|
||||
assert.strictEqual(data[0].category, "sponsor");
|
||||
assert.strictEqual(data[0].UUID, "1-uuid-0");
|
||||
assert.strictEqual(data[1].UUID, "1-uuid-0-2");
|
||||
assert.strictEqual(data[0].videoDuration, 100);
|
||||
done();
|
||||
})
|
||||
.catch(() => "Couldn't call endpoint");
|
||||
.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")
|
||||
.then(async res => {
|
||||
if (res.status !== 200) done("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-1" && data[0].videoDuration === 120) {
|
||||
done();
|
||||
} else {
|
||||
done("Received incorrect body: " + (await res.text()));
|
||||
}
|
||||
}
|
||||
assert.strictEqual(res.status, 200);
|
||||
const data = await res.json();
|
||||
assert.strictEqual(data.length, 1);
|
||||
assert.strictEqual(data[0].segment[0], 1);
|
||||
assert.strictEqual(data[0].segment[1], 11);
|
||||
assert.strictEqual(data[0].category, "sponsor");
|
||||
assert.strictEqual(data[0].UUID, "1-uuid-0-1");
|
||||
assert.strictEqual(data[0].videoDuration, 120);
|
||||
done();
|
||||
})
|
||||
.catch(() => "Couldn't call endpoint");
|
||||
.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")
|
||||
.then(async res => {
|
||||
if (res.status !== 200) done("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();
|
||||
} else {
|
||||
done("Received incorrect body: " + (await res.text()));
|
||||
}
|
||||
}
|
||||
assert.strictEqual(res.status, 200);
|
||||
const data = await res.json();
|
||||
assert.strictEqual(data.length, 1);
|
||||
assert.strictEqual(data[0].segment[0], 20);
|
||||
assert.strictEqual(data[0].segment[1], 33);
|
||||
assert.strictEqual(data[0].category, "intro");
|
||||
assert.strictEqual(data[0].UUID, "1-uuid-2");
|
||||
done();
|
||||
})
|
||||
.catch(() => ("Couldn't call endpoint"));
|
||||
.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\"]")
|
||||
.then(async res => {
|
||||
if (res.status !== 200) done("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" && data[0].videoDuration === 100) {
|
||||
done();
|
||||
} else {
|
||||
done("Received incorrect body: " + (await res.text()));
|
||||
}
|
||||
}
|
||||
assert.strictEqual(res.status, 200);
|
||||
const data = await res.json();
|
||||
assert.strictEqual(data.length, 1);
|
||||
assert.strictEqual(data[0].segment[0], 1);
|
||||
assert.strictEqual(data[0].segment[1], 11);
|
||||
assert.strictEqual(data[0].category, "sponsor");
|
||||
assert.strictEqual(data[0].UUID, "1-uuid-0");
|
||||
assert.strictEqual(data[0].videoDuration, 100);
|
||||
done();
|
||||
})
|
||||
.catch(() => ("Couldn't call endpoint"));
|
||||
.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\"]")
|
||||
.then(async res => {
|
||||
if (res.status !== 200) done("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" && data[0].videoDuration === 101) {
|
||||
done();
|
||||
} else {
|
||||
done("Received incorrect body: " + (await res.text()));
|
||||
}
|
||||
}
|
||||
assert.strictEqual(res.status, 200);
|
||||
const data = await res.json();
|
||||
assert.strictEqual(data.length, 1);
|
||||
assert.strictEqual(data[0].segment[0], 20);
|
||||
assert.strictEqual(data[0].segment[1], 33);
|
||||
assert.strictEqual(data[0].category, "intro");
|
||||
assert.strictEqual(data[0].UUID, "1-uuid-2");
|
||||
assert.strictEqual(data[0].videoDuration, 101);
|
||||
done();
|
||||
})
|
||||
.catch(() => ("Couldn't call endpoint"));
|
||||
.catch(err => done(err));
|
||||
});
|
||||
|
||||
it('Should return 404 if all submissions are hidden', (done: Done) => {
|
||||
fetch(getbaseURL() + "/api/skipSegments?videoID=onlyHiddenSegments")
|
||||
.then(res => {
|
||||
if (res.status !== 404) done("non 404 respone code: " + res.status);
|
||||
else done(); // pass
|
||||
assert.strictEqual(res.status, 404);
|
||||
done();
|
||||
})
|
||||
.catch(() => ("Couldn't call endpoint"));
|
||||
.catch(err => done(err));
|
||||
});
|
||||
|
||||
it('Should be able to get multiple times by category', (done: Done) => {
|
||||
fetch(getbaseURL() + "/api/skipSegments?videoID=multiple&categories=[\"intro\"]")
|
||||
.then(async res => {
|
||||
if (res.status !== 200)done("Status code was: " + res.status);
|
||||
else {
|
||||
const body = await res.text();
|
||||
const data = JSON.parse(body);
|
||||
if (data.length === 2) {
|
||||
let success = true;
|
||||
for (const segment of data) {
|
||||
if ((segment.segment[0] !== 20 || segment.segment[1] !== 33
|
||||
|| segment.category !== "intro" || segment.UUID !== "1-uuid-7") &&
|
||||
(segment.segment[0] !== 1 || segment.segment[1] !== 11
|
||||
|| segment.category !== "intro" || segment.UUID !== "1-uuid-6")) {
|
||||
success = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (success) done();
|
||||
else done("Received incorrect body: " + body);
|
||||
} else {
|
||||
done("Received incorrect body: " + body);
|
||||
}
|
||||
}
|
||||
assert.strictEqual(res.status, 200);
|
||||
const data = await res.json();
|
||||
assert.strictEqual(data.length, 2);
|
||||
assert.strictEqual(data[0].segment[0], 1);
|
||||
assert.strictEqual(data[0].segment[1], 11);
|
||||
assert.strictEqual(data[0].category, "intro");
|
||||
assert.strictEqual(data[0].UUID, "1-uuid-6");
|
||||
assert.strictEqual(data[1].segment[0], 20);
|
||||
assert.strictEqual(data[1].segment[1], 33);
|
||||
assert.strictEqual(data[1].category, "intro");
|
||||
assert.strictEqual(data[1].UUID, "1-uuid-7");
|
||||
done();
|
||||
})
|
||||
.catch(err => ("Couldn't call endpoint\n\n" + err));
|
||||
.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\"]")
|
||||
.then(async res => {
|
||||
if (res.status !== 200) done("Status code was: " + res.status);
|
||||
else {
|
||||
const body = await res.text();
|
||||
const data = JSON.parse(body);
|
||||
if (data.length === 2) {
|
||||
|
||||
let success = true;
|
||||
for (const segment of data) {
|
||||
if ((segment.segment[0] !== 20 || segment.segment[1] !== 33
|
||||
|| segment.category !== "intro" || segment.UUID !== "1-uuid-2") &&
|
||||
(segment.segment[0] !== 1 || segment.segment[1] !== 11
|
||||
|| segment.category !== "sponsor" || segment.UUID !== "1-uuid-0")) {
|
||||
success = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (success) done();
|
||||
else done("Received incorrect body: " + body);
|
||||
} else {
|
||||
done("Received incorrect body: " + body);
|
||||
}
|
||||
}
|
||||
assert.strictEqual(res.status, 200);
|
||||
const data = await res.json();
|
||||
assert.strictEqual(data.length, 2);
|
||||
assert.strictEqual(data[0].segment[0], 1);
|
||||
assert.strictEqual(data[0].segment[1], 11);
|
||||
assert.strictEqual(data[0].category, "sponsor");
|
||||
assert.strictEqual(data[0].UUID, "1-uuid-0");
|
||||
assert.strictEqual(data[1].segment[0], 20);
|
||||
assert.strictEqual(data[1].segment[1], 33);
|
||||
assert.strictEqual(data[1].category, "intro");
|
||||
assert.strictEqual(data[1].UUID, "1-uuid-2");
|
||||
done();
|
||||
})
|
||||
.catch(() => ("Couldn't call endpoint"));
|
||||
.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")
|
||||
.then(async res => {
|
||||
if (res.status !== 200) done("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();
|
||||
} else {
|
||||
done("Received incorrect body: " + body);
|
||||
}
|
||||
}
|
||||
assert.strictEqual(res.status, 200);
|
||||
const data = await res.json();
|
||||
assert.strictEqual(data.length, 1);
|
||||
assert.strictEqual(data[0].segment[0], 1);
|
||||
assert.strictEqual(data[0].segment[1], 11);
|
||||
assert.strictEqual(data[0].category, "sponsor");
|
||||
assert.strictEqual(data[0].UUID, "1-uuid-0");
|
||||
done();
|
||||
})
|
||||
.catch(() => done("Couldn't call endpoint"));
|
||||
.catch(err => done(err));
|
||||
});
|
||||
|
||||
it('Low voted submissions should be hidden', (done: Done) => {
|
||||
fetch(getbaseURL() + "/api/skipSegments?videoID=test3&category=sponsor")
|
||||
.then(async res => {
|
||||
if (res.status !== 200) done("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();
|
||||
} else {
|
||||
done("Received incorrect body: " + body);
|
||||
}
|
||||
}
|
||||
assert.strictEqual(res.status, 200);
|
||||
const data = await res.json();
|
||||
assert.strictEqual(data.length, 1);
|
||||
assert.strictEqual(data[0].segment[0], 1);
|
||||
assert.strictEqual(data[0].segment[1], 11);
|
||||
assert.strictEqual(data[0].category, "sponsor");
|
||||
assert.strictEqual(data[0].UUID, "1-uuid-4");
|
||||
done();
|
||||
})
|
||||
.catch(() => ("Couldn't call endpoint"));
|
||||
.catch(err => done(err));
|
||||
});
|
||||
|
||||
it('Should return 404 if no segment found', (done: Done) => {
|
||||
fetch(getbaseURL() + "/api/skipSegments?videoID=notarealvideo")
|
||||
.then(res => {
|
||||
if (res.status !== 404) done("non 404 respone code: " + res.status);
|
||||
else done(); // pass
|
||||
assert.strictEqual(res.status, 404);
|
||||
done();
|
||||
})
|
||||
.catch(() => ("couldn't call endpoint"));
|
||||
.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]")
|
||||
.then(res => {
|
||||
if (res.status !== 400) done("non 400 respone code: " + res.status);
|
||||
else done(); // pass
|
||||
assert.strictEqual(res.status, 400);
|
||||
done();
|
||||
})
|
||||
.catch(() => ("couldn't call endpoint"));
|
||||
.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")
|
||||
.then(async res => {
|
||||
if (res.status !== 200) done ("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();
|
||||
} else {
|
||||
done("Received incorrect body: " + body);
|
||||
}
|
||||
}
|
||||
assert.strictEqual(res.status, 200);
|
||||
const data = await res.json();
|
||||
assert.strictEqual(data.length, 1);
|
||||
assert.strictEqual(data[0].segment[0], 1);
|
||||
assert.strictEqual(data[0].segment[1], 11);
|
||||
assert.strictEqual(data[0].category, "sponsor");
|
||||
assert.strictEqual(data[0].UUID, "1-uuid-1");
|
||||
done();
|
||||
})
|
||||
.catch(() => ("Couldn't call endpoint"));
|
||||
.catch(err => done(err));
|
||||
});
|
||||
|
||||
it('Should always get locked segment', (done: Done) => {
|
||||
fetch(getbaseURL() + "/api/skipSegments?videoID=locked&category=intro")
|
||||
.then(async res => {
|
||||
if (res.status !== 200) done ("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();
|
||||
} else {
|
||||
done("Received incorrect body: " + (await res.text()));
|
||||
}
|
||||
}
|
||||
assert.strictEqual(res.status, 200);
|
||||
const data = await res.json();
|
||||
assert.strictEqual(data.length, 1);
|
||||
assert.strictEqual(data[0].segment[0], 20);
|
||||
assert.strictEqual(data[0].segment[1], 33);
|
||||
assert.strictEqual(data[0].category, "intro");
|
||||
assert.strictEqual(data[0].UUID, "1-uuid-locked-8");
|
||||
done();
|
||||
})
|
||||
.catch(() => ("Couldn't call endpoint"));
|
||||
.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")
|
||||
.then(async res => {
|
||||
if (res.status !== 200) done("Status code was: " + res.status);
|
||||
else {
|
||||
const body = await res.text();
|
||||
const data = JSON.parse(body);
|
||||
if (data.length === 2) {
|
||||
|
||||
let success = true;
|
||||
for (const segment of data) {
|
||||
if ((segment.segment[0] !== 20 || segment.segment[1] !== 33
|
||||
|| segment.category !== "intro" || segment.UUID !== "1-uuid-2") &&
|
||||
(segment.segment[0] !== 1 || segment.segment[1] !== 11
|
||||
|| segment.category !== "sponsor" || segment.UUID !== "1-uuid-0")) {
|
||||
success = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (success) done();
|
||||
else done("Received incorrect body: " + body);
|
||||
} else {
|
||||
done("Received incorrect body: " + body);
|
||||
}
|
||||
}
|
||||
assert.strictEqual(res.status, 200);
|
||||
const data = await res.json();
|
||||
assert.strictEqual(data.length, 2);
|
||||
assert.strictEqual(data[0].segment[0], 1);
|
||||
assert.strictEqual(data[0].segment[1], 11);
|
||||
assert.strictEqual(data[0].category, "sponsor");
|
||||
assert.strictEqual(data[0].UUID, "1-uuid-0");
|
||||
assert.strictEqual(data[1].segment[0], 20);
|
||||
assert.strictEqual(data[1].segment[1], 33);
|
||||
assert.strictEqual(data[1].category, "intro");
|
||||
assert.strictEqual(data[1].UUID, "1-uuid-2");
|
||||
done();
|
||||
})
|
||||
.catch(() => ("Couldn't call endpoint"));
|
||||
.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")
|
||||
.then(async res => {
|
||||
if (res.status !== 200) done("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();
|
||||
} else {
|
||||
done("Received incorrect body: " + (await res.text()));
|
||||
}
|
||||
}
|
||||
assert.strictEqual(res.status, 200);
|
||||
const data = await res.json();
|
||||
assert.strictEqual(data.length, 1);
|
||||
assert.strictEqual(data[0].segment[0], 1);
|
||||
assert.strictEqual(data[0].segment[1], 11);
|
||||
assert.strictEqual(data[0].category, "sponsor");
|
||||
assert.strictEqual(data[0].UUID, "1-uuid-0");
|
||||
done();
|
||||
})
|
||||
.catch(() => ("Couldn't call endpoint"));
|
||||
.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"]')
|
||||
.then(async res => {
|
||||
if (res.status !== 200) done("non 200 status code, was " + res.status);
|
||||
else {
|
||||
const body = await res.json();
|
||||
if (body.length !== 2) done("expected 2 segments, got " + body.length);
|
||||
else if (body[0].UUID !== 'requiredSegmentVid-raw-2'
|
||||
|| body[1].UUID !== 'requiredSegmentVid-raw-3') done("Did not recieve the correct segments\n" + JSON.stringify(body, null, 2));
|
||||
else done();
|
||||
}
|
||||
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");
|
||||
done();
|
||||
})
|
||||
.catch(() => done("Couldn't call endpoint"));
|
||||
.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')
|
||||
.then(async res => {
|
||||
if (res.status !== 200) done("non 200 status code, was " + res.status);
|
||||
else {
|
||||
const body = await res.json();
|
||||
if (body.length !== 2) done("expected 2 segments, got " + body.length);
|
||||
else if (body[0].UUID !== 'requiredSegmentVid-raw-2'
|
||||
|| body[1].UUID !== 'requiredSegmentVid-raw-3') done("Did not recieve the correct segments\n" + JSON.stringify(body, null, 2));
|
||||
else done();
|
||||
}
|
||||
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');
|
||||
done();
|
||||
})
|
||||
.catch(() => done("Couldn't call endpoint"));
|
||||
.catch(err => done(err));
|
||||
});
|
||||
|
||||
it('Should get 400 if no videoID passed in', (done: Done) => {
|
||||
fetch(getbaseURL() + '/api/skipSegments')
|
||||
.then(async res => {
|
||||
assert.strictEqual(res.status, 400);
|
||||
done();
|
||||
})
|
||||
.catch(err => done(err));
|
||||
});
|
||||
});
|
||||
|
|
|
@ -5,12 +5,13 @@ 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');
|
||||
sinonStub.callsFake(YouTubeApiMock.listVideos);
|
||||
|
||||
describe('getSegmentsByHash', () => {
|
||||
describe('getSkipSegmentsByHash', () => {
|
||||
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']);
|
||||
|
@ -31,36 +32,35 @@ describe('getSegmentsByHash', () => {
|
|||
it('Should be able to get a 200', (done: Done) => {
|
||||
fetch(getbaseURL() + '/api/skipSegments/3272f?categories=["sponsor", "intro"]')
|
||||
.then(res => {
|
||||
if (res.status !== 200) done("non 200 status code, was " + res.status);
|
||||
else done(); // pass
|
||||
assert.strictEqual(res.status, 200);
|
||||
done();
|
||||
})
|
||||
.catch(() => done("Couldn't call endpoint"));
|
||||
.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"]')
|
||||
.then(async res => {
|
||||
if (res.status !== 404) done("non 404 status code, was " + res.status);
|
||||
else {
|
||||
const body = await res.text();
|
||||
if (body === '[]') done(); // pass
|
||||
else done("Response had videos");
|
||||
}
|
||||
assert.strictEqual(res.status, 404);
|
||||
const expected = '[]';
|
||||
const body = await res.text();
|
||||
assert.strictEqual(body, expected);
|
||||
done();
|
||||
})
|
||||
.catch(() => done("Couldn't call endpoint"));
|
||||
.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"]')
|
||||
.then(async res => {
|
||||
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
|
||||
else done("non empty array returned");
|
||||
}
|
||||
assert.strictEqual(res.status, 404);
|
||||
const body = await res.text();
|
||||
const expected = '[]';
|
||||
assert.strictEqual(JSON.parse(body).length, 0);
|
||||
assert.strictEqual(body, expected);
|
||||
done();
|
||||
})
|
||||
.catch(() => done("Couldn't call endpoint"));
|
||||
.catch(err => done(err));
|
||||
});
|
||||
|
||||
it('Should be able to get an empty array if only hidden videos', (done: Done) => {
|
||||
|
@ -73,175 +73,159 @@ describe('getSegmentsByHash', () => {
|
|||
else done("non empty array returned");
|
||||
}
|
||||
})
|
||||
.catch(() => done("Couldn't call endpoint"));
|
||||
.catch(err => done(err));
|
||||
});
|
||||
|
||||
it('Should return 400 prefix too short', (done: Done) => {
|
||||
fetch(getbaseURL() + '/api/skipSegments/11?categories=["shilling"]')
|
||||
.then(res => {
|
||||
if (res.status !== 400) done("non 400 status code, was " + res.status);
|
||||
else done(); // pass
|
||||
assert.strictEqual(res.status, 400);
|
||||
done();
|
||||
})
|
||||
.catch(() => done("Couldn't call endpoint"));
|
||||
.catch(err => done(err));
|
||||
});
|
||||
|
||||
it('Should return 400 prefix too long', (done: Done) => {
|
||||
const prefix = new Array(50).join('1');
|
||||
if (prefix.length <= 32) { // default value, config can change this
|
||||
done('failed to generate a long enough string for the test ' + prefix.length);
|
||||
return;
|
||||
}
|
||||
const prefix = '1'.repeat(50);
|
||||
assert.ok(prefix.length > 33, "failed to generate long enough string");
|
||||
fetch(getbaseURL() + '/api/skipSegments/' + prefix + '?categories=["shilling"]')
|
||||
.then(res => {
|
||||
if (res.status !== 400) done("non 400 status code, was " + res.status);
|
||||
else done(); // pass
|
||||
assert.strictEqual(res.status, 400);
|
||||
done();
|
||||
})
|
||||
.catch(() => done("Couldn't call endpoint"));
|
||||
.catch(err => done(err));
|
||||
});
|
||||
|
||||
it('Should not return 400 prefix in range', (done: Done) => {
|
||||
fetch(getbaseURL() + '/api/skipSegments/11111?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 => {
|
||||
if (res.status === 400) done("prefix length 5 gave 400 " + res.status);
|
||||
else done(); // pass
|
||||
assert.strictEqual(res.status, 404);
|
||||
done();
|
||||
})
|
||||
.catch(() => done("Couldn't call endpoint"));
|
||||
.catch(err => done(err));
|
||||
});
|
||||
|
||||
it('Should return 404 for no hash', (done: Done) => {
|
||||
it('Should return 400 for no hash', (done: Done) => {
|
||||
fetch(getbaseURL() + '/api/skipSegments/?categories=["shilling"]')
|
||||
.then(res => {
|
||||
if (res.status !== 404) done("expected 404, got " + res.status);
|
||||
else done(); // pass
|
||||
assert.strictEqual(res.status, 400);
|
||||
done();
|
||||
})
|
||||
.catch(() => done("Couldn't call endpoint"));
|
||||
.catch(err => done(err));
|
||||
});
|
||||
|
||||
it('Should return 400 for bad format categories', (done: Done) => {
|
||||
fetch(getbaseURL() + '/api/skipSegments/fdaf?categories=shilling')
|
||||
.then(res => {
|
||||
if (res.status !== 400) done("expected 400 got " + res.status);
|
||||
else done(); // pass
|
||||
assert.strictEqual(res.status, 400);
|
||||
done();
|
||||
})
|
||||
.catch(() => done("Couldn't call endpoint"));
|
||||
.catch(err => done(err));
|
||||
});
|
||||
|
||||
it('Should be able to get multiple videos', (done: Done) => {
|
||||
fetch(getbaseURL() + '/api/skipSegments/fdaf?categories=["sponsor","intro"]')
|
||||
.then(async res => {
|
||||
if (res.status !== 200) done("non 200 status code, was " + res.status);
|
||||
else {
|
||||
const body = await res.json();
|
||||
if (body.length !== 2) done("expected 2 videos, got " + body.length);
|
||||
else if (body[0].segments.length !== 2) done("expected 2 segments for first video, got " + body[0].segments.length);
|
||||
else if (body[1].segments.length !== 1) done("expected 1 segment for second video, got " + body[1].segments.length);
|
||||
else done();
|
||||
}
|
||||
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);
|
||||
done();
|
||||
})
|
||||
.catch(() => done("Couldn't call endpoint"));
|
||||
.catch(err => done(err));
|
||||
});
|
||||
|
||||
it('Should be able to get 200 for no categories (default sponsor)', (done: Done) => {
|
||||
fetch(getbaseURL() + '/api/skipSegments/fdaf')
|
||||
.then(async res => {
|
||||
if (res.status !== 200) done("non 200 status code, was " + res.status);
|
||||
else {
|
||||
const body = await res.json();
|
||||
if (body.length !== 2) done("expected 2 videos, got " + body.length);
|
||||
else if (body[0].segments.length !== 1) done("expected 1 segments for first video, got " + body[0].segments.length);
|
||||
else if (body[1].segments.length !== 1) done("expected 1 segments for second video, got " + body[1].segments.length);
|
||||
else if (body[0].segments[0].category !== 'sponsor'
|
||||
|| body[0].segments[0].UUID !== 'getSegmentsByHash-0-0'
|
||||
|| body[1].segments[0].category !== 'sponsor') done("both segments are not sponsor");
|
||||
else done();
|
||||
}
|
||||
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');
|
||||
done();
|
||||
})
|
||||
.catch(() => done("Couldn't call endpoint"));
|
||||
.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')
|
||||
.then(async res => {
|
||||
if (res.status !== 200) done("non 200 status code, was " + res.status);
|
||||
else {
|
||||
const body = await res.json();
|
||||
if (body.length !== 2) done("expected 2 videos, got " + body.length);
|
||||
else if (body[0].segments.length !== 1) done("expected 1 segments for first video, got " + body[0].segments.length);
|
||||
else if (body[1].segments.length !== 1) done("expected 1 segments for second video, got " + body[1].segments.length);
|
||||
else if (body[0].segments[0].category !== 'sponsor'
|
||||
|| body[0].segments[0].UUID !== 'getSegmentsByHash-0-0'
|
||||
|| body[1].segments[0].category !== 'sponsor') done("both segments are not sponsor");
|
||||
else done();
|
||||
}
|
||||
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');
|
||||
done();
|
||||
})
|
||||
.catch(() => done("Couldn't call endpoint"));
|
||||
.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')
|
||||
.then(async res => {
|
||||
if (res.status !== 200) done("non 200 status code, was " + res.status);
|
||||
else {
|
||||
const body = await res.json();
|
||||
if (body.length !== 2) done("expected 2 videos, got " + body.length);
|
||||
else if (body[0].segments.length !== 2) done("expected 2 segments for first video, got " + body[0].segments.length);
|
||||
else if (body[1].segments.length !== 1) done("expected 1 segments for second video, got " + body[1].segments.length);
|
||||
else if (body[0].segments[0].category !== 'sponsor'
|
||||
|| body[0].segments[0].UUID !== 'getSegmentsByHash-0-0'
|
||||
|| body[0].segments[1].UUID !== 'getSegmentsByHash-0-2'
|
||||
|| body[1].segments[0].category !== 'sponsor') done("both segments are not sponsor");
|
||||
else done();
|
||||
}
|
||||
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');
|
||||
done();
|
||||
})
|
||||
.catch(() => done("Couldn't call endpoint"));
|
||||
.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"]')
|
||||
.then(async res => {
|
||||
if (res.status !== 200) done("non 200 status code, was " + res.status);
|
||||
else {
|
||||
const body = await res.json();
|
||||
if (body.length !== 2) done("expected 2 videos, got " + body.length);
|
||||
else if (body[0].segments.length !== 2) done("expected 2 segments for first video, got " + body[0].segments.length);
|
||||
else if (body[1].segments.length !== 1) done("expected 1 segments for second video, got " + body[1].segments.length);
|
||||
else if (body[0].segments[0].category !== 'sponsor'
|
||||
|| body[0].segments[0].UUID !== 'getSegmentsByHash-0-0'
|
||||
|| body[0].segments[1].UUID !== 'getSegmentsByHash-0-2'
|
||||
|| body[1].segments[0].category !== 'sponsor') done("both segments are not sponsor");
|
||||
else done();
|
||||
}
|
||||
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');
|
||||
done();
|
||||
})
|
||||
.catch(() => done("Couldn't call endpoint"));
|
||||
.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')
|
||||
.then(async res => {
|
||||
if (res.status !== 200) done("non 200 status code, was " + res.status);
|
||||
else {
|
||||
const body = await res.json();
|
||||
if (body.length !== 1) done("expected 1 video, got " + body.length);
|
||||
else if (body[0].segments.length !== 1) done("expected 1 segments for first video, got " + body[0].segments.length);
|
||||
else if (body[0].segments[0].UUID !== 'getSegmentsByHash-0-0-1') done("both segments are not sponsor");
|
||||
else done();
|
||||
}
|
||||
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');
|
||||
done();
|
||||
})
|
||||
.catch(() => done("Couldn't call endpoint"));
|
||||
.catch(err => done(err));
|
||||
});
|
||||
|
||||
it('Should only return one segment when fetching highlight segments', (done: Done) => {
|
||||
fetch(getbaseURL() + '/api/skipSegments/c962?category=highlight')
|
||||
.then(async res => {
|
||||
if (res.status !== 200) done("non 200 status code, was " + res.status);
|
||||
else {
|
||||
const body = await res.json();
|
||||
if (body.length !== 1) done("expected 1 video, got " + body.length);
|
||||
else if (body[0].segments.length !== 1) done("expected 1 segment, got " + body[0].segments.length);
|
||||
else done();
|
||||
}
|
||||
assert.strictEqual(res.status, 200);
|
||||
const data = await res.json();
|
||||
assert.strictEqual(data.length, 1);
|
||||
assert.strictEqual(data[0].segments.length, 1);
|
||||
done();
|
||||
})
|
||||
.catch(() => done("Couldn't call endpoint"));
|
||||
.catch(err => done(err));
|
||||
});
|
||||
|
||||
it('Should be able to post a segment and get it using endpoint', (done: Done) => {
|
||||
|
@ -260,23 +244,17 @@ describe('getSegmentsByHash', () => {
|
|||
}],
|
||||
}),
|
||||
})
|
||||
.then(async res => {
|
||||
if (res.status === 200) {
|
||||
fetch(getbaseURL() + '/api/skipSegments/' + getHash(testID, 1).substring(0, 3))
|
||||
.then(async res => {
|
||||
if (res.status !== 200) done("(get) non 200 status code, was " + res.status);
|
||||
else {
|
||||
const body = await res.json();
|
||||
if (body.length !== 1) done("(get) expected 1 video, got " + body.length);
|
||||
else if (body[0].segments.length !== 1) done("(get) expected 1 segments for first video, got " + body[0].segments.length);
|
||||
else if (body[0].segments[0].category !== 'sponsor') done("(get) segment should be sponsor, was " + body[0].segments[0].category);
|
||||
else done();
|
||||
}
|
||||
})
|
||||
.catch(() => done("(get) Couldn't call endpoint"));
|
||||
} else {
|
||||
done("(post) non 200 status code, was " + res.status);
|
||||
}
|
||||
.then(async () => {
|
||||
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');
|
||||
done();
|
||||
})
|
||||
.catch(err => done('(get) ' + err));
|
||||
})
|
||||
.catch(err => done('(post) ' + err));
|
||||
});
|
||||
|
@ -284,64 +262,48 @@ describe('getSegmentsByHash', () => {
|
|||
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 => {
|
||||
if (res.status !== 200) done("Status code was: " + res.status);
|
||||
else {
|
||||
const body = await res.json();
|
||||
if (body.length !== 1) done("expected 1 video, got " + body.length);
|
||||
|
||||
const data = body[0].segments;
|
||||
if (data.length === 2) {
|
||||
let success = true;
|
||||
for (const segment of data) {
|
||||
if ((segment.segment[0] !== 1 || segment.segment[1] !== 10
|
||||
|| segment.category !== "sponsor" || segment.UUID !== "getSegmentsByHash-0-0") &&
|
||||
(segment.segment[0] !== 20 || segment.segment[1] !== 30
|
||||
|| segment.category !== "intro" || segment.UUID !== "getSegmentsByHash-0-1")) {
|
||||
success = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (success) done();
|
||||
else done("Received incorrect body: " + JSON.stringify(body));
|
||||
} else {
|
||||
done("Received incorrect body: " + JSON.stringify(body));
|
||||
}
|
||||
}
|
||||
assert.strictEqual(res.status, 200);
|
||||
const data = await res.json();
|
||||
assert.strictEqual(data.length, 1);
|
||||
assert.strictEqual(data[0].segments[0].segment[0], 1);
|
||||
assert.strictEqual(data[0].segments[0].segment[1], 10);
|
||||
assert.strictEqual(data[0].segments[0].category, "sponsor");
|
||||
assert.strictEqual(data[0].segments[0].UUID, "getSegmentsByHash-0-0");
|
||||
assert.strictEqual(data[0].segments[1].segment[0], 20);
|
||||
assert.strictEqual(data[0].segments[1].segment[1], 30);
|
||||
assert.strictEqual(data[0].segments[1].category, "intro");
|
||||
assert.strictEqual(data[0].segments[1].UUID, "getSegmentsByHash-0-1");
|
||||
done();
|
||||
})
|
||||
.catch(() => ("Couldn't call endpoint"));
|
||||
.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"]')
|
||||
.then(async res => {
|
||||
if (res.status !== 200) done("non 200 status code, was " + res.status);
|
||||
else {
|
||||
const body = await res.json();
|
||||
if (body.length !== 1) done("expected 1 video, got " + body.length);
|
||||
else if (body[0].segments.length !== 2) done("expected 2 segments for video, got " + body[0].segments.length);
|
||||
else if (body[0].segments[0].UUID !== 'requiredSegmentVid-2'
|
||||
|| body[0].segments[1].UUID !== 'requiredSegmentVid-3') done("Did not recieve the correct segments\n" + JSON.stringify(body, null, 2));
|
||||
else done();
|
||||
}
|
||||
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');
|
||||
done();
|
||||
})
|
||||
.catch(() => done("Couldn't call endpoint"));
|
||||
.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')
|
||||
.then(async res => {
|
||||
if (res.status !== 200) done("non 200 status code, was " + res.status);
|
||||
else {
|
||||
const body = await res.json();
|
||||
if (body.length !== 1) done("expected 1 video, got " + body.length);
|
||||
else if (body[0].segments.length !== 2) done("expected 2 segments for video, got " + body[0].segments.length);
|
||||
else if (body[0].segments[0].UUID !== 'requiredSegmentVid-2'
|
||||
|| body[0].segments[1].UUID !== 'requiredSegmentVid-3') done("Did not recieve the correct segments\n" + JSON.stringify(body, null, 2));
|
||||
else done();
|
||||
}
|
||||
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');
|
||||
done();
|
||||
})
|
||||
.catch(() => done("Couldn't call endpoint"));
|
||||
.catch(err => done(err));
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
@ -2,6 +2,7 @@ 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', () => {
|
||||
before(async () => {
|
||||
|
@ -23,378 +24,301 @@ describe('getUserID', () => {
|
|||
it('Should be able to get a 200', (done: Done) => {
|
||||
fetch(getbaseURL() + '/api/userID?username=fuzzy+user+01')
|
||||
.then(async res => {
|
||||
if (res.status !== 200) done('non 200 (' + res.status + ')');
|
||||
else done(); // pass
|
||||
assert.strictEqual(res.status, 200);
|
||||
done();
|
||||
})
|
||||
.catch(() => done('couldn\'t call endpoint'));
|
||||
.catch(err => done(err));
|
||||
});
|
||||
|
||||
it('Should be able to get a 400 (No username parameter)', (done: Done) => {
|
||||
fetch(getbaseURL() + '/api/userID')
|
||||
.then(res => {
|
||||
if (res.status !== 400) done('non 400 (' + res.status + ')');
|
||||
else done(); // pass
|
||||
assert.strictEqual(res.status, 400);
|
||||
done();
|
||||
})
|
||||
.catch(() => done('couldn\'t call endpoint'));
|
||||
.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"))
|
||||
.then(async res => {
|
||||
if (res.status !== 200) done('non 200 (' + res.status + ')');
|
||||
else done(); // pass
|
||||
assert.strictEqual(res.status, 200);
|
||||
done();
|
||||
})
|
||||
.catch(() => done('couldn\'t call endpoint'));
|
||||
.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')
|
||||
.then(res => {
|
||||
if (res.status !== 400) done('non 400 (' + res.status + ')');
|
||||
else done(); // pass
|
||||
assert.strictEqual(res.status, 400);
|
||||
done();
|
||||
})
|
||||
.catch(() => done('couldn\'t call endpoint'));
|
||||
.catch(err => done(err));
|
||||
});
|
||||
|
||||
it('Should be able to get single username', (done: Done) => {
|
||||
fetch(getbaseURL() + '/api/userID?username=fuzzy+user+01')
|
||||
.then(async res => {
|
||||
if (res.status !== 200) {
|
||||
done("non 200");
|
||||
} else {
|
||||
const data = await res.json();
|
||||
if (data.length !== 1) {
|
||||
done('Returned incorrect number of users "' + data.length + '"');
|
||||
} else if (data[0].userName !== "fuzzy user 01") {
|
||||
done('Returned incorrect username "' + data.userName + '"');
|
||||
} else if (data[0].userID !== getHash("getuserid_user_01")) {
|
||||
done('Returned incorrect userID "' + data.userID + '"');
|
||||
} else {
|
||||
done(); // pass
|
||||
}
|
||||
}
|
||||
assert.strictEqual(res.status, 200);
|
||||
const expected = [{
|
||||
userName: "fuzzy user 01",
|
||||
userID: getHash("getuserid_user_01")
|
||||
}];
|
||||
const data = await res.json();
|
||||
assert.deepStrictEqual(data, expected);
|
||||
done();
|
||||
})
|
||||
.catch(() => ("couldn't call endpoint"));
|
||||
.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')
|
||||
.then(async res => {
|
||||
if (res.status !== 200) {
|
||||
done("non 200");
|
||||
} else {
|
||||
const data = await res.json();
|
||||
if (data.length !== 2) {
|
||||
done('Returned incorrect number of users "' + data.length + '"');
|
||||
} else if (data[0].userName !== "fuzzy user 01") {
|
||||
done('Returned incorrect username "' + data.userName + '"');
|
||||
} else if (data[0].userID !== getHash("getuserid_user_01")) {
|
||||
done('Returned incorrect userID "' + data.userID + '"');
|
||||
} else if (data[1].userName !== "fuzzy user 02") {
|
||||
done('Returned incorrect username "' + data.userName + '"');
|
||||
} else if (data[1].userID !== getHash("getuserid_user_02")) {
|
||||
done('Returned incorrect userID "' + data.userID + '"');
|
||||
} else {
|
||||
done(); // pass
|
||||
}
|
||||
}
|
||||
assert.strictEqual(res.status, 200);
|
||||
const expected = [{
|
||||
userName: "fuzzy user 01",
|
||||
userID: getHash("getuserid_user_01")
|
||||
}, {
|
||||
userName: "fuzzy user 02",
|
||||
userID: getHash("getuserid_user_02")
|
||||
}];
|
||||
const data = await res.json();
|
||||
assert.deepStrictEqual(data, expected);
|
||||
done();
|
||||
})
|
||||
.catch(() => ("couldn't call endpoint"));
|
||||
.catch(err => done(err));
|
||||
});
|
||||
|
||||
it('Should be able to get multiple fuzzy user info from middle', (done: Done) => {
|
||||
fetch(getbaseURL() + '/api/userID?username=user')
|
||||
.then(async res => {
|
||||
if (res.status !== 200) {
|
||||
done("non 200");
|
||||
} else {
|
||||
const data = await res.json();
|
||||
if (data.length !== 3) {
|
||||
done('Returned incorrect number of users "' + data.length + '"');
|
||||
} else if (data[0].userName !== "fuzzy user 01") {
|
||||
done('Returned incorrect username "' + data.userName + '"');
|
||||
} else if (data[0].userID !== getHash("getuserid_user_01")) {
|
||||
done('Returned incorrect userID "' + data.userID + '"');
|
||||
} else if (data[1].userName !== "fuzzy user 02") {
|
||||
done('Returned incorrect username "' + data.userName + '"');
|
||||
} else if (data[1].userID !== getHash("getuserid_user_02")) {
|
||||
done('Returned incorrect userID "' + data.userID + '"');
|
||||
} else if (data[2].userName !== "specific user 03") {
|
||||
done('Returned incorrect username "' + data.userName + '"');
|
||||
} else if (data[2].userID !== getHash("getuserid_user_03")) {
|
||||
done('Returned incorrect userID "' + data.userID + '"');
|
||||
} else {
|
||||
done(); // pass
|
||||
}
|
||||
}
|
||||
assert.strictEqual(res.status, 200);
|
||||
const expected = [{
|
||||
userName: "fuzzy user 01",
|
||||
userID: getHash("getuserid_user_01")
|
||||
}, {
|
||||
userName: "fuzzy user 02",
|
||||
userID: getHash("getuserid_user_02")
|
||||
}, {
|
||||
userName: "specific user 03",
|
||||
userID: getHash("getuserid_user_03")
|
||||
}];
|
||||
const data = await res.json();
|
||||
assert.deepStrictEqual(data, expected);
|
||||
done();
|
||||
})
|
||||
.catch(() => ("couldn't call endpoint"));
|
||||
.catch(err => done(err));
|
||||
});
|
||||
|
||||
it('Should be able to get with public ID', (done: Done) => {
|
||||
const userID = getHash("getuserid_user_06");
|
||||
fetch(getbaseURL() + '/api/userID?username='+userID)
|
||||
.then(async res => {
|
||||
if (res.status !== 200) {
|
||||
done("non 200");
|
||||
} else {
|
||||
const data = await res.json();
|
||||
if (data.length !== 1) {
|
||||
done('Returned incorrect number of users "' + data.length + '"');
|
||||
} else if (data[0].userName !== userID) {
|
||||
done('Returned incorrect username "' + data.userName + '"');
|
||||
} else if (data[0].userID !== userID) {
|
||||
done('Returned incorrect userID "' + data.userID + '"');
|
||||
} else {
|
||||
done(); // pass
|
||||
}
|
||||
}
|
||||
assert.strictEqual(res.status, 200);
|
||||
const expected = [{
|
||||
userName: userID,
|
||||
userID
|
||||
}];
|
||||
const data = await res.json();
|
||||
assert.deepStrictEqual(data, expected);
|
||||
done();
|
||||
})
|
||||
.catch(() => ("couldn't call endpoint"));
|
||||
.catch(err => done(err));
|
||||
});
|
||||
|
||||
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))
|
||||
.then(async res => {
|
||||
if (res.status !== 200) {
|
||||
done("non 200");
|
||||
} else {
|
||||
const data = await res.json();
|
||||
if (data.length !== 1) {
|
||||
done('Returned incorrect number of users "' + data.length + '"');
|
||||
} else if (data[0].userName !== userID) {
|
||||
done('Returned incorrect username "' + data.userName + '"');
|
||||
} else if (data[0].userID !== userID) {
|
||||
done('Returned incorrect userID "' + data.userID + '"');
|
||||
} else {
|
||||
done(); // pass
|
||||
}
|
||||
}
|
||||
assert.strictEqual(res.status, 200);
|
||||
const expected = [{
|
||||
userName: userID,
|
||||
userID
|
||||
}];
|
||||
const data = await res.json();
|
||||
assert.deepStrictEqual(data, expected);
|
||||
done();
|
||||
})
|
||||
.catch(() => ("couldn't call endpoint"));
|
||||
.catch(err => done(err));
|
||||
});
|
||||
|
||||
it('Should be able to get repeating username', (done: Done) => {
|
||||
fetch(getbaseURL() + '/api/userID?username=repeating')
|
||||
.then(async res => {
|
||||
if (res.status !== 200) {
|
||||
done("non 200");
|
||||
} else {
|
||||
const data = await res.json();
|
||||
if (data.length !== 2) {
|
||||
done('Returned incorrect number of users "' + data.length + '"');
|
||||
} else if (data[0].userName !== "repeating") {
|
||||
done('Returned incorrect username "' + data.userName + '"');
|
||||
} else if (data[0].userID !== getHash("getuserid_user_04")) {
|
||||
done('Returned incorrect userID "' + data.userID + '"');
|
||||
} else if (data[1].userName !== "repeating") {
|
||||
done('Returned incorrect username "' + data.userName + '"');
|
||||
} else if (data[1].userID !== getHash("getuserid_user_05")) {
|
||||
done('Returned incorrect userID "' + data.userID + '"');
|
||||
} else {
|
||||
done(); // pass
|
||||
}
|
||||
}
|
||||
assert.strictEqual(res.status, 200);
|
||||
const expected = [{
|
||||
userName: "repeating",
|
||||
userID: getHash("getuserid_user_04")
|
||||
}, {
|
||||
userName: "repeating",
|
||||
userID: getHash("getuserid_user_05")
|
||||
}];
|
||||
const data = await res.json();
|
||||
assert.deepStrictEqual(data, expected);
|
||||
done();
|
||||
})
|
||||
.catch(() => ("couldn't call endpoint"));
|
||||
.catch(err => done(err));
|
||||
});
|
||||
|
||||
it('Should be able to get repeating fuzzy username', (done: Done) => {
|
||||
fetch(getbaseURL() + '/api/userID?username=peat')
|
||||
.then(async res => {
|
||||
if (res.status !== 200) {
|
||||
done("non 200");
|
||||
} else {
|
||||
const data = await res.json();
|
||||
if (data.length !== 2) {
|
||||
done('Returned incorrect number of users "' + data.length + '"');
|
||||
} else if (data[0].userName !== "repeating") {
|
||||
done('Returned incorrect username "' + data.userName + '"');
|
||||
} else if (data[0].userID !== getHash("getuserid_user_04")) {
|
||||
done('Returned incorrect userID "' + data.userID + '"');
|
||||
} else if (data[1].userName !== "repeating") {
|
||||
done('Returned incorrect username "' + data.userName + '"');
|
||||
} else if (data[1].userID !== getHash("getuserid_user_05")) {
|
||||
done('Returned incorrect userID "' + data.userID + '"');
|
||||
} else {
|
||||
done(); // pass
|
||||
}
|
||||
}
|
||||
assert.strictEqual(res.status, 200);
|
||||
const expected = [{
|
||||
userName: "repeating",
|
||||
userID: getHash("getuserid_user_04")
|
||||
}, {
|
||||
userName: "repeating",
|
||||
userID: getHash("getuserid_user_05")
|
||||
}];
|
||||
const data = await res.json();
|
||||
assert.deepStrictEqual(data, expected);
|
||||
done();
|
||||
})
|
||||
.catch(() => ("couldn't call endpoint"));
|
||||
.catch(err => done(err));
|
||||
});
|
||||
|
||||
it('should avoid ReDOS with _', (done: Done) => {
|
||||
fetch(getbaseURL() + '/api/userID?username=_redos_')
|
||||
.then(async res => {
|
||||
if (res.status !== 200) {
|
||||
done("non 200");
|
||||
} else {
|
||||
const data = await res.json();
|
||||
if (data.length !== 1) {
|
||||
done('Returned incorrect number of users "' + data.length + '"');
|
||||
} else if (data[0].userName !== "_redos_") {
|
||||
done('Returned incorrect username "' + data.userName + '"');
|
||||
} else if (data[0].userID !== getHash("getuserid_user_09")) {
|
||||
done('Returned incorrect userID "' + data.userID + '"');
|
||||
} else {
|
||||
done(); // pass
|
||||
}
|
||||
}
|
||||
assert.strictEqual(res.status, 200);
|
||||
const expected = [{
|
||||
userName: "_redos_",
|
||||
userID: getHash("getuserid_user_09")
|
||||
}];
|
||||
const data = await res.json();
|
||||
assert.deepStrictEqual(data, expected);
|
||||
done();
|
||||
})
|
||||
.catch(() => ("couldn't call endpoint"));
|
||||
.catch(err => done(err));
|
||||
});
|
||||
|
||||
it('should avoid ReDOS with %', (done: Done) => {
|
||||
fetch(getbaseURL() + '/api/userID?username=%redos%')
|
||||
.then(async res => {
|
||||
if (res.status !== 200) {
|
||||
done("non 200");
|
||||
} else {
|
||||
const data = await res.json();
|
||||
if (data.length !== 1) {
|
||||
done('Returned incorrect number of users "' + data.length + '"');
|
||||
} else if (data[0].userName !== "%redos%") {
|
||||
done('Returned incorrect username "' + data.userName + '"');
|
||||
} else if (data[0].userID !== getHash("getuserid_user_08")) {
|
||||
done('Returned incorrect userID "' + data.userID + '"');
|
||||
} else {
|
||||
done(); // pass
|
||||
}
|
||||
}
|
||||
assert.strictEqual(res.status, 200);
|
||||
const expected = [{
|
||||
userName: "%redos%",
|
||||
userID: getHash("getuserid_user_08")
|
||||
}];
|
||||
const data = await res.json();
|
||||
assert.deepStrictEqual(data, expected);
|
||||
done();
|
||||
})
|
||||
.catch(() => ("couldn't call endpoint"));
|
||||
.catch(err => done(err));
|
||||
});
|
||||
|
||||
it('should return 404 if escaped backslashes present', (done: Done) => {
|
||||
fetch(getbaseURL() + '/api/userID?username=%redos\\\\_')
|
||||
.then(res => {
|
||||
if (res.status !== 404) done('non 404 (' + res.status + ')');
|
||||
else done(); // pass
|
||||
assert.strictEqual(res.status, 404);
|
||||
done();
|
||||
})
|
||||
.catch(() => ("couldn't call endpoint"));
|
||||
.catch(err => done(err));
|
||||
});
|
||||
|
||||
it('should return 404 if backslashes present', (done: Done) => {
|
||||
fetch(getbaseURL() + '/api/userID?username=\\%redos\\_')
|
||||
.then(res => {
|
||||
if (res.status !== 404) done('non 404 (' + res.status + ')');
|
||||
else done(); // pass
|
||||
assert.strictEqual(res.status, 404);
|
||||
done();
|
||||
})
|
||||
.catch(() => ("couldn't call endpoint"));
|
||||
.catch(err => done(err));
|
||||
});
|
||||
|
||||
it('should return user if just backslashes', (done: Done) => {
|
||||
fetch(getbaseURL() + '/api/userID?username=\\\\\\')
|
||||
.then(async res => {
|
||||
if (res.status !== 200) {
|
||||
done("non 200");
|
||||
} else {
|
||||
const data = await res.json();
|
||||
if (data.length !== 1) {
|
||||
done('Returned incorrect number of users "' + data.length + '"');
|
||||
} else if (data[0].userName !== "\\\\\\") {
|
||||
done('Returned incorrect username "' + data.userName + '"');
|
||||
} else if (data[0].userID !== getHash("getuserid_user_11")) {
|
||||
done('Returned incorrect userID "' + data.userID + '"');
|
||||
} else {
|
||||
done(); // pass
|
||||
}
|
||||
}
|
||||
assert.strictEqual(res.status, 200);
|
||||
const expected = [{
|
||||
userName: "\\\\\\",
|
||||
userID: getHash("getuserid_user_11")
|
||||
}];
|
||||
const data = await res.json();
|
||||
assert.deepStrictEqual(data, expected);
|
||||
done();
|
||||
})
|
||||
.catch(() => ("couldn't call endpoint"));
|
||||
.catch(err => done(err));
|
||||
});
|
||||
|
||||
it('should not allow usernames more than 64 characters', (done: Done) => {
|
||||
fetch(getbaseURL() + '/api/userID?username='+'0'.repeat(65))
|
||||
.then(res => {
|
||||
if (res.status !== 400) done('non 400 (' + res.status + ')');
|
||||
else done(); // pass
|
||||
assert.strictEqual(res.status, 400);
|
||||
done();
|
||||
})
|
||||
.catch(() => ("couldn't call endpoint"));
|
||||
.catch(err => done(err));
|
||||
});
|
||||
|
||||
it('should not allow usernames less than 3 characters', (done: Done) => {
|
||||
fetch(getbaseURL() + '/api/userID?username=aa')
|
||||
.then(res => {
|
||||
if (res.status !== 400) done('non 400 (' + res.status + ')');
|
||||
else done(); // pass
|
||||
assert.strictEqual(res.status, 400);
|
||||
done();
|
||||
})
|
||||
.catch(() => ("couldn't call endpoint"));
|
||||
.catch(err => done(err));
|
||||
});
|
||||
|
||||
it('should allow exact match', (done: Done) => {
|
||||
fetch(getbaseURL() + '/api/userID?username=a&exact=true')
|
||||
.then(async res => {
|
||||
if (res.status !== 200) {
|
||||
done("non 200");
|
||||
} else {
|
||||
const data = await res.json();
|
||||
if (data.length !== 1) {
|
||||
done('Returned incorrect number of users "' + data.length + '"');
|
||||
} else if (data[0].userName !== "a") {
|
||||
done('Returned incorrect username "' + data.userName + '"');
|
||||
} else if (data[0].userID !== getHash("getuserid_user_12")) {
|
||||
done('Returned incorrect userID "' + data.userID + '"');
|
||||
} else {
|
||||
done(); // pass
|
||||
}
|
||||
}
|
||||
assert.strictEqual(res.status, 200);
|
||||
const expected = [{
|
||||
userName: "a",
|
||||
userID: getHash("getuserid_user_12")
|
||||
}];
|
||||
const data = await res.json();
|
||||
assert.deepStrictEqual(data, expected);
|
||||
done();
|
||||
})
|
||||
.catch(() => ("couldn't call endpoint"));
|
||||
.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')
|
||||
.then(async res => {
|
||||
if (res.status !== 200) {
|
||||
done("non 200");
|
||||
} else {
|
||||
const data = await res.json();
|
||||
if (data.length !== 2) {
|
||||
done('Returned incorrect number of users "' + data.length + '"');
|
||||
} else if (data[0].userName !== "repeating") {
|
||||
done('Returned incorrect username "' + data.userName + '"');
|
||||
} else if (data[0].userID !== getHash("getuserid_user_04")) {
|
||||
done('Returned incorrect userID "' + data.userID + '"');
|
||||
} else if (data[1].userName !== "repeating") {
|
||||
done('Returned incorrect username "' + data.userName + '"');
|
||||
} else if (data[1].userID !== getHash("getuserid_user_05")) {
|
||||
done('Returned incorrect userID "' + data.userID + '"');
|
||||
} else {
|
||||
done(); // pass
|
||||
}
|
||||
}
|
||||
assert.strictEqual(res.status, 200);
|
||||
const expected = [{
|
||||
userName: "repeating",
|
||||
userID: getHash("getuserid_user_04")
|
||||
}, {
|
||||
userName: "repeating",
|
||||
userID: getHash("getuserid_user_05")
|
||||
}];
|
||||
const data = await res.json();
|
||||
assert.deepStrictEqual(data, expected);
|
||||
done();
|
||||
})
|
||||
.catch(() => ("couldn't call endpoint"));
|
||||
.catch(err => done(err));
|
||||
});
|
||||
|
||||
it('Should not get exact unless explicitly set to true', (done: Done) => {
|
||||
fetch(getbaseURL() + '/api/userID?username=user&exact=1')
|
||||
.then(async res => {
|
||||
if (res.status !== 200) {
|
||||
done("non 200");
|
||||
} else {
|
||||
const data = await res.json();
|
||||
if (data.length !== 3) {
|
||||
done('Returned incorrect number of users "' + data.length + '"');
|
||||
} else if (data[0].userName !== "fuzzy user 01") {
|
||||
done('Returned incorrect username "' + data.userName + '"');
|
||||
} else if (data[0].userID !== getHash("getuserid_user_01")) {
|
||||
done('Returned incorrect userID "' + data.userID + '"');
|
||||
} else if (data[1].userName !== "fuzzy user 02") {
|
||||
done('Returned incorrect username "' + data.userName + '"');
|
||||
} else if (data[1].userID !== getHash("getuserid_user_02")) {
|
||||
done('Returned incorrect userID "' + data.userID + '"');
|
||||
} else if (data[2].userName !== "specific user 03") {
|
||||
done('Returned incorrect username "' + data.userName + '"');
|
||||
} else if (data[2].userID !== getHash("getuserid_user_03")) {
|
||||
done('Returned incorrect userID "' + data.userID + '"');
|
||||
} else {
|
||||
done(); // pass
|
||||
}
|
||||
}
|
||||
assert.strictEqual(res.status, 200);
|
||||
const expected = [{
|
||||
userName: "fuzzy user 01",
|
||||
userID: getHash("getuserid_user_01")
|
||||
}, {
|
||||
userName: "fuzzy user 02",
|
||||
userID: getHash("getuserid_user_02")
|
||||
}, {
|
||||
userName: "specific user 03",
|
||||
userID: getHash("getuserid_user_03")
|
||||
}];
|
||||
const data = await res.json();
|
||||
assert.deepStrictEqual(data, expected);
|
||||
done();
|
||||
})
|
||||
.catch(err => done(err));
|
||||
});
|
||||
|
||||
it('should return 400 if no username parameter specified', (done: Done) => {
|
||||
fetch(getbaseURL() + '/api/userID')
|
||||
.then(res => {
|
||||
assert.strictEqual(res.status, 400);
|
||||
done();
|
||||
})
|
||||
.catch(() => ("couldn't call endpoint"));
|
||||
});
|
||||
|
|
|
@ -31,136 +31,109 @@ describe('getUserInfo', () => {
|
|||
it('Should be able to get a 200', (done: Done) => {
|
||||
fetch(getbaseURL() + '/api/userInfo?userID=getuserinfo_user_01')
|
||||
.then(res => {
|
||||
if (res.status !== 200) done('non 200 (' + res.status + ')');
|
||||
else done(); // pass
|
||||
assert.strictEqual(res.status, 200);
|
||||
done();
|
||||
})
|
||||
.catch(() => done('couldn\'t call endpoint'));
|
||||
.catch(err => done(err));
|
||||
});
|
||||
|
||||
it('Should be able to get a 400 (No userID parameter)', (done: Done) => {
|
||||
fetch(getbaseURL() + '/api/userInfo')
|
||||
.then(res => {
|
||||
if (res.status !== 400) done('non 400 (' + res.status + ')');
|
||||
else done(); // pass
|
||||
assert.strictEqual(res.status, 400);
|
||||
done();
|
||||
})
|
||||
.catch(() => done('couldn\'t call endpoint'));
|
||||
.catch(err => done(err));
|
||||
});
|
||||
|
||||
it('Should be able to get user info', (done: Done) => {
|
||||
fetch(getbaseURL() + '/api/userInfo?userID=getuserinfo_user_01')
|
||||
.then(async res => {
|
||||
if (res.status !== 200) {
|
||||
done("non 200");
|
||||
} else {
|
||||
const data = await res.json();
|
||||
if (data.userName !== 'Username user 01') {
|
||||
done('Returned incorrect userName "' + data.userName + '"');
|
||||
} else if (data.minutesSaved !== 5) {
|
||||
done('Returned incorrect minutesSaved "' + data.minutesSaved + '"');
|
||||
} else if (data.viewCount !== 30) {
|
||||
done('Returned incorrect viewCount "' + data.viewCount + '"');
|
||||
} else if (data.ignoredViewCount !== 20) {
|
||||
done('Returned incorrect ignoredViewCount "' + data.ignoredViewCount + '"');
|
||||
} else if (data.segmentCount !== 3) {
|
||||
done('Returned incorrect segmentCount "' + data.segmentCount + '"');
|
||||
} else if (data.ignoredSegmentCount !== 2) {
|
||||
done('Returned incorrect ignoredSegmentCount "' + data.ignoredSegmentCount + '"');
|
||||
} else if (data.reputation !== -2) {
|
||||
done('Returned incorrect reputation "' + data.reputation + '"');
|
||||
} else if (data.lastSegmentID !== "uuid000005") {
|
||||
done('Returned incorrect last segment "' + data.lastSegmentID + '"');
|
||||
} else {
|
||||
done(); // pass
|
||||
}
|
||||
}
|
||||
assert.strictEqual(res.status, 200);
|
||||
const expected = {
|
||||
userName: 'Username user 01',
|
||||
userID: "66e7c974039ffb870a500a33eca3a3989861018909b938c313cf1a8a366800b8",
|
||||
minutesSaved: 5,
|
||||
viewCount: 30,
|
||||
ignoredViewCount: 20,
|
||||
segmentCount: 3,
|
||||
ignoredSegmentCount: 2,
|
||||
reputation: -2,
|
||||
lastSegmentID: "uuid000005",
|
||||
vip: false,
|
||||
warnings: 0
|
||||
};
|
||||
const data = await res.json();
|
||||
assert.deepStrictEqual(data, expected);
|
||||
done();
|
||||
})
|
||||
.catch(() => ("couldn't call endpoint"));
|
||||
.catch(err => done(err));
|
||||
});
|
||||
|
||||
it('Should get warning data', (done: Done) => {
|
||||
fetch(getbaseURL() + '/api/userInfo?userID=getuserinfo_warning_0&value=warnings')
|
||||
.then(async res => {
|
||||
if (res.status !== 200) {
|
||||
done('non 200 (' + res.status + ')');
|
||||
} else {
|
||||
const data = await res.json();
|
||||
if (data.warnings !== 1) done('wrong number of warnings: ' + data.warnings + ', not ' + 1);
|
||||
else done(); // pass
|
||||
}
|
||||
assert.strictEqual(res.status, 200);
|
||||
const data = await res.json();
|
||||
assert.strictEqual(data.warnings, 1);
|
||||
done();
|
||||
})
|
||||
.catch(() => ("couldn't call endpoint"));
|
||||
.catch(err => done(err));
|
||||
});
|
||||
|
||||
it('Should get warning data with public ID', (done: Done) => {
|
||||
fetch(getbaseURL() + `/api/userInfo?publicUserID=${getHash("getuserinfo_warning_0")}&values=["warnings"]`)
|
||||
.then(async res => {
|
||||
if (res.status !== 200) {
|
||||
done('non 200 (' + res.status + ')');
|
||||
} else {
|
||||
const data = await res.json();
|
||||
if (data.warnings !== 1) done('wrong number of warnings: ' + data.warnings + ', not ' + 1);
|
||||
else done();
|
||||
}
|
||||
assert.strictEqual(res.status, 200);
|
||||
const data = await res.json();
|
||||
assert.strictEqual(data.warnings, 1);
|
||||
done();
|
||||
})
|
||||
.catch(() => ("couldn't call endpoint"));
|
||||
.catch(err => done(err));
|
||||
});
|
||||
|
||||
it('Should get multiple warnings', (done: Done) => {
|
||||
fetch(getbaseURL() + '/api/userInfo?userID=getuserinfo_warning_1&value=warnings')
|
||||
.then(async res => {
|
||||
if (res.status !== 200) {
|
||||
done('non 200 (' + res.status + ')');
|
||||
} else {
|
||||
const data = await res.json();
|
||||
if (data.warnings !== 2) done('wrong number of warnings: ' + data.warnings + ', not ' + 2);
|
||||
else done(); // pass
|
||||
}
|
||||
assert.strictEqual(res.status, 200);
|
||||
const data = await res.json();
|
||||
assert.strictEqual(data.warnings, 2);
|
||||
done();
|
||||
})
|
||||
.catch(() => ("couldn't call endpoint"));
|
||||
.catch(err => done(err));
|
||||
});
|
||||
|
||||
it('Should not get warnings if none', (done: Done) => {
|
||||
fetch(getbaseURL() + '/api/userInfo?userID=getuserinfo_warning_2&value=warnings')
|
||||
.then(async res => {
|
||||
if (res.status !== 200) {
|
||||
done('non 200 (' + res.status + ')');
|
||||
} else {
|
||||
const data = await res.json();
|
||||
if (data.warnings !== 0) done('wrong number of warnings: ' + data.warnings + ', not ' + 0);
|
||||
else done(); // pass
|
||||
}
|
||||
assert.strictEqual(res.status, 200);
|
||||
const data = await res.json();
|
||||
assert.strictEqual(data.warnings, 0);
|
||||
done();
|
||||
})
|
||||
.catch(() => ("couldn't call endpoint"));
|
||||
.catch(err => done(err));
|
||||
});
|
||||
|
||||
it('Should done(userID for userName (No userName set)', (done: Done) => {
|
||||
fetch(getbaseURL() + '/api/userInfo?userID=getuserinfo_user_02&value=userName')
|
||||
.then(async res => {
|
||||
if (res.status !== 200) {
|
||||
done('non 200 (' + res.status + ')');
|
||||
} else {
|
||||
const data = await res.json();
|
||||
if (data.userName !== 'c2a28fd225e88f74945794ae85aef96001d4a1aaa1022c656f0dd48ac0a3ea0f') {
|
||||
done('Did not done(userID for userName');
|
||||
}
|
||||
done(); // pass
|
||||
}
|
||||
assert.strictEqual(res.status, 200);
|
||||
const data = await res.json();
|
||||
assert.strictEqual(data.userName, 'c2a28fd225e88f74945794ae85aef96001d4a1aaa1022c656f0dd48ac0a3ea0f');
|
||||
done();
|
||||
})
|
||||
.catch(() => ('couldn\'t call endpoint'));
|
||||
.catch(err => done(err));
|
||||
});
|
||||
|
||||
it('Should return null segment if none', (done: Done) => {
|
||||
fetch(getbaseURL() + '/api/userInfo?userID=getuserinfo_null&value=lastSegmentID')
|
||||
.then(async res => {
|
||||
if (res.status !== 200) {
|
||||
done('non 200 (' + res.status + ')');
|
||||
} else {
|
||||
const data = await res.json();
|
||||
if (data.lastSegmentID !== null) done('returned segment ' + data.warnings + ', not ' + null);
|
||||
else done(); // pass
|
||||
}
|
||||
assert.strictEqual(res.status, 200);
|
||||
const data = await res.json();
|
||||
assert.strictEqual(data.lastSegmentID, null);
|
||||
done();
|
||||
})
|
||||
.catch(() => ("couldn't call endpoint"));
|
||||
.catch(err => done(err));
|
||||
});
|
||||
|
||||
it('Should return zeroes if userid does not exist', (done: Done) => {
|
||||
|
@ -174,7 +147,7 @@ describe('getUserInfo', () => {
|
|||
}
|
||||
done(); // pass
|
||||
})
|
||||
.catch(() => ("couldn't call endpoint"));
|
||||
.catch(err => done(err));
|
||||
});
|
||||
|
||||
it('Should get warning reason from from single enabled warning', (done: Done) => {
|
||||
|
|
|
@ -2,9 +2,11 @@ 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 deepEquals = (a: string[],b: string[]) => {
|
||||
const deepStringEqual = (a: string[], b: string[]): boolean => {
|
||||
if (a.length !== b.length) return false;
|
||||
a.forEach((e) => { if (!b.includes(e)) return false; });
|
||||
return true;
|
||||
};
|
||||
|
@ -30,8 +32,7 @@ describe('lockCategoriesRecords', () => {
|
|||
|
||||
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;
|
||||
assert.ok(version > 1);
|
||||
});
|
||||
|
||||
it('Should be able to submit categories not in video (http response)', (done: Done) => {
|
||||
|
@ -47,14 +48,12 @@ describe('lockCategoriesRecords', () => {
|
|||
'intro',
|
||||
],
|
||||
};
|
||||
|
||||
const expected = {
|
||||
submitted: [
|
||||
'outro',
|
||||
'shilling',
|
||||
],
|
||||
};
|
||||
|
||||
fetch(getbaseURL() + "/api/lockCategories", {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
|
@ -63,16 +62,10 @@ describe('lockCategoriesRecords', () => {
|
|||
body: JSON.stringify(json)
|
||||
})
|
||||
.then(async res => {
|
||||
if (res.status === 200) {
|
||||
const data = await res.json();
|
||||
if (deepEquals(data.submitted, expected.submitted)) {
|
||||
done();
|
||||
} else {
|
||||
done("Incorrect response: expected " + JSON.stringify(expected) + " got " + JSON.stringify(data));
|
||||
}
|
||||
} else {
|
||||
done("Status code was " + res.status);
|
||||
}
|
||||
assert.strictEqual(res.status, 200);
|
||||
const data = await res.json();
|
||||
assert.deepStrictEqual(data, expected);
|
||||
done();
|
||||
})
|
||||
.catch(err => done(err));
|
||||
});
|
||||
|
@ -90,7 +83,6 @@ describe('lockCategoriesRecords', () => {
|
|||
'intro',
|
||||
],
|
||||
};
|
||||
|
||||
fetch(getbaseURL() + "/api/lockCategories", {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
|
@ -99,28 +91,20 @@ describe('lockCategoriesRecords', () => {
|
|||
body: JSON.stringify(json)
|
||||
})
|
||||
.then(async res => {
|
||||
if (res.status === 200) {
|
||||
const result = await db.prepare('all', 'SELECT * FROM "lockCategories" WHERE "videoID" = ?', ['no-segments-video-id-1']) as LockCategory[];
|
||||
if (result.length !== 4) {
|
||||
done("Expected 4 entrys in db, got " + result.length);
|
||||
} else {
|
||||
const oldRecordNotChangeReason = result.filter(item => {
|
||||
return item.reason === 'reason-2' && ['sponsor', 'intro'].includes(item.category);
|
||||
});
|
||||
assert.strictEqual(res.status, 200);
|
||||
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)
|
||||
);
|
||||
|
||||
const newRecordWithEmptyReason = result.filter(item => {
|
||||
return item.reason === '' && ['outro', 'shilling'].includes(item.category);
|
||||
});
|
||||
const newRecordWithEmptyReason = result.filter(item =>
|
||||
item.reason === '' && ['outro', 'shilling'].includes(item.category)
|
||||
);
|
||||
|
||||
if (newRecordWithEmptyReason.length !== 2 || oldRecordNotChangeReason.length !== 2) {
|
||||
done(`Incorrect reason update with oldRecordNotChangeReason=${oldRecordNotChangeReason} instead of 2 or newRecordWithEmptyReason=${newRecordWithEmptyReason} instead of 2`);
|
||||
} else {
|
||||
done();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
done("Status code was " + res.status);
|
||||
}
|
||||
assert.strictEqual(newRecordWithEmptyReason.length, 2);
|
||||
assert.strictEqual(oldRecordNotChangeReason.length, 2);
|
||||
done();
|
||||
})
|
||||
.catch(err => done(err));
|
||||
});
|
||||
|
@ -156,16 +140,10 @@ describe('lockCategoriesRecords', () => {
|
|||
body: JSON.stringify(json)
|
||||
})
|
||||
.then(async res => {
|
||||
if (res.status === 200) {
|
||||
const data = await res.json();
|
||||
if (deepEquals(data.submitted, expected.submitted)) {
|
||||
done();
|
||||
} else {
|
||||
done("Incorrect response: expected " + JSON.stringify(expected) + " got " + JSON.stringify(data));
|
||||
}
|
||||
} else {
|
||||
done("Status code was " + res.status);
|
||||
}
|
||||
assert.strictEqual(res.status, 200);
|
||||
const data = await res.json();
|
||||
assert.deepStrictEqual(data.submitted, expected.submitted);
|
||||
done();
|
||||
})
|
||||
.catch(err => done(err));
|
||||
});
|
||||
|
@ -199,30 +177,19 @@ describe('lockCategoriesRecords', () => {
|
|||
body: JSON.stringify(json)
|
||||
})
|
||||
.then(async res => {
|
||||
if (res.status === 200) {
|
||||
const result = await db.prepare('all', 'SELECT * FROM "lockCategories" WHERE "videoID" = ?', ['no-segments-video-id-1']) as LockCategory[];
|
||||
if (result.length !== 4) {
|
||||
done("Expected 4 entrys in db, got " + result.length);
|
||||
} else {
|
||||
const newRecordWithNewReason = result.filter(item => {
|
||||
return expectedWithNewReason.includes(item.category) && item.reason === 'new reason';
|
||||
});
|
||||
assert.strictEqual(res.status, 200);
|
||||
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'
|
||||
);
|
||||
const oldRecordNotChangeReason = result.filter(item =>
|
||||
item.reason === 'reason-2'
|
||||
);
|
||||
|
||||
const oldRecordNotChangeReason = result.filter(item => {
|
||||
return item.reason === 'reason-2';
|
||||
});
|
||||
|
||||
if (newRecordWithNewReason.length !== 3) {
|
||||
done("Expected 3 entrys in db with new reason, got " + newRecordWithNewReason.length);
|
||||
} else if (oldRecordNotChangeReason.length !== 1) {
|
||||
done("Expected 1 entrys in db with old reason, got " + oldRecordNotChangeReason.length);
|
||||
} else {
|
||||
done();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
done("Status code was " + res.status);
|
||||
}
|
||||
assert.strictEqual(newRecordWithNewReason.length, 3);
|
||||
assert.strictEqual(oldRecordNotChangeReason.length, 1);
|
||||
done();
|
||||
})
|
||||
.catch(err => done(err));
|
||||
});
|
||||
|
@ -235,7 +202,6 @@ describe('lockCategoriesRecords', () => {
|
|||
'word_word',
|
||||
],
|
||||
};
|
||||
|
||||
fetch(getbaseURL() + "/api/lockCategories", {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
|
@ -244,16 +210,10 @@ describe('lockCategoriesRecords', () => {
|
|||
body: JSON.stringify(json),
|
||||
})
|
||||
.then(async res => {
|
||||
if (res.status === 200) {
|
||||
const result = await db.prepare('all', 'SELECT * FROM "lockCategories" WHERE "videoID" = ?', ['underscore']);
|
||||
if (result.length !== 1) {
|
||||
done("Expected 1 entrys in db, got " + result.length);
|
||||
} else {
|
||||
done();
|
||||
}
|
||||
} else {
|
||||
done("Status code was " + res.status);
|
||||
}
|
||||
assert.strictEqual(res.status, 200);
|
||||
const result = await db.prepare('all', 'SELECT * FROM "lockCategories" WHERE "videoID" = ?', ['underscore']);
|
||||
assert.strictEqual(result.length, 1);
|
||||
done();
|
||||
})
|
||||
.catch(err => done(err));
|
||||
});
|
||||
|
@ -266,7 +226,6 @@ describe('lockCategoriesRecords', () => {
|
|||
'wordWord',
|
||||
],
|
||||
};
|
||||
|
||||
fetch(getbaseURL() + "/api/lockCategories", {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
|
@ -275,16 +234,10 @@ describe('lockCategoriesRecords', () => {
|
|||
body: JSON.stringify(json),
|
||||
})
|
||||
.then(async res => {
|
||||
if (res.status === 200) {
|
||||
const result = await db.prepare('all', 'SELECT * FROM "lockCategories" WHERE "videoID" = ?', ['bothCases']);
|
||||
if (result.length !== 1) {
|
||||
done("Expected 1 entrys in db, got " + result.length);
|
||||
} else {
|
||||
done();
|
||||
}
|
||||
} else {
|
||||
done("Status code was " + res.status);
|
||||
}
|
||||
assert.strictEqual(res.status, 200);
|
||||
const result = await db.prepare('all', 'SELECT * FROM "lockCategories" WHERE "videoID" = ?', ['bothCases']);
|
||||
assert.strictEqual(result.length, 1);
|
||||
done();
|
||||
})
|
||||
.catch(err => done(err));
|
||||
});
|
||||
|
@ -306,16 +259,10 @@ describe('lockCategoriesRecords', () => {
|
|||
body: JSON.stringify(json),
|
||||
})
|
||||
.then(async res => {
|
||||
if (res.status === 200) {
|
||||
const result = await db.prepare('all', 'SELECT * FROM "lockCategories" WHERE "videoID" = ?', ['specialChar']);
|
||||
if (result.length !== 0) {
|
||||
done("Expected 0 entrys in db, got " + result.length);
|
||||
} else {
|
||||
done();
|
||||
}
|
||||
} else {
|
||||
done("Status code was " + res.status);
|
||||
}
|
||||
assert.strictEqual(res.status, 200);
|
||||
const result = await db.prepare('all', 'SELECT * FROM "lockCategories" WHERE "videoID" = ?', ['specialChar']);
|
||||
assert.strictEqual(result.length, 0);
|
||||
done();
|
||||
})
|
||||
.catch(err => done(err));
|
||||
});
|
||||
|
@ -328,12 +275,9 @@ describe('lockCategoriesRecords', () => {
|
|||
},
|
||||
body: JSON.stringify({}),
|
||||
})
|
||||
.then(async res => {
|
||||
if (res.status === 400) {
|
||||
done();
|
||||
} else {
|
||||
done("Status code was " + res.status);
|
||||
}
|
||||
.then(res => {
|
||||
assert.strictEqual(res.status, 400);
|
||||
done();
|
||||
})
|
||||
.catch(err => done(err));
|
||||
});
|
||||
|
@ -344,7 +288,6 @@ describe('lockCategoriesRecords', () => {
|
|||
userID: 'test',
|
||||
categories: [],
|
||||
};
|
||||
|
||||
fetch(getbaseURL() + "/api/lockCategories", {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
|
@ -352,12 +295,9 @@ describe('lockCategoriesRecords', () => {
|
|||
},
|
||||
body: JSON.stringify(json),
|
||||
})
|
||||
.then(async res => {
|
||||
if (res.status === 400) {
|
||||
done();
|
||||
} else {
|
||||
done("Status code was " + res.status);
|
||||
}
|
||||
.then(res => {
|
||||
assert.strictEqual(res.status, 400);
|
||||
done();
|
||||
})
|
||||
.catch(err => done(err));
|
||||
});
|
||||
|
@ -376,12 +316,9 @@ describe('lockCategoriesRecords', () => {
|
|||
},
|
||||
body: JSON.stringify(json),
|
||||
})
|
||||
.then(async res => {
|
||||
if (res.status === 400) {
|
||||
done();
|
||||
} else {
|
||||
done("Status code was " + res.status);
|
||||
}
|
||||
.then(res => {
|
||||
assert.strictEqual(res.status, 400);
|
||||
done();
|
||||
})
|
||||
.catch(err => done(err));
|
||||
});
|
||||
|
@ -400,12 +337,9 @@ describe('lockCategoriesRecords', () => {
|
|||
},
|
||||
body: JSON.stringify(json),
|
||||
})
|
||||
.then(async res => {
|
||||
if (res.status === 400) {
|
||||
done();
|
||||
} else {
|
||||
done("Status code was " + res.status);
|
||||
}
|
||||
.then(res => {
|
||||
assert.strictEqual(res.status, 400);
|
||||
done();
|
||||
})
|
||||
.catch(err => done(err));
|
||||
});
|
||||
|
@ -424,12 +358,9 @@ describe('lockCategoriesRecords', () => {
|
|||
},
|
||||
body: JSON.stringify(json),
|
||||
})
|
||||
.then(async res => {
|
||||
if (res.status === 400) {
|
||||
done();
|
||||
} else {
|
||||
done("Status code was " + res.status);
|
||||
}
|
||||
.then(res => {
|
||||
assert.strictEqual(res.status, 400);
|
||||
done();
|
||||
})
|
||||
.catch(err => done(err));
|
||||
});
|
||||
|
@ -448,12 +379,9 @@ describe('lockCategoriesRecords', () => {
|
|||
},
|
||||
body: JSON.stringify(json),
|
||||
})
|
||||
.then(async res => {
|
||||
if (res.status === 400) {
|
||||
done();
|
||||
} else {
|
||||
done("Status code was " + res.status);
|
||||
}
|
||||
.then(res => {
|
||||
assert.strictEqual(res.status, 400);
|
||||
done();
|
||||
})
|
||||
.catch(err => done(err));
|
||||
});
|
||||
|
@ -474,12 +402,9 @@ describe('lockCategoriesRecords', () => {
|
|||
},
|
||||
body: JSON.stringify(json),
|
||||
})
|
||||
.then(async res => {
|
||||
if (res.status === 403) {
|
||||
done();
|
||||
} else {
|
||||
done("Status code was " + res.status);
|
||||
}
|
||||
.then(res => {
|
||||
assert.strictEqual(res.status, 403);
|
||||
done();
|
||||
})
|
||||
.catch(err => done(err));
|
||||
});
|
||||
|
@ -501,16 +426,10 @@ describe('lockCategoriesRecords', () => {
|
|||
body: JSON.stringify(json),
|
||||
})
|
||||
.then(async res => {
|
||||
if (res.status === 200) {
|
||||
const result = await db.prepare('all', 'SELECT * FROM "lockCategories" WHERE "videoID" = ?', ['delete-record']);
|
||||
if (result.length === 0) {
|
||||
done();
|
||||
} else {
|
||||
done("Didn't delete record");
|
||||
}
|
||||
} else {
|
||||
done("Status code was " + res.status);
|
||||
}
|
||||
assert.strictEqual(res.status, 200);
|
||||
const result = await db.prepare('all', 'SELECT * FROM "lockCategories" WHERE "videoID" = ?', ['delete-record']);
|
||||
assert.strictEqual(result.length, 0);
|
||||
done();
|
||||
})
|
||||
.catch(err => done(err));
|
||||
});
|
||||
|
@ -532,16 +451,10 @@ describe('lockCategoriesRecords', () => {
|
|||
body: JSON.stringify(json),
|
||||
})
|
||||
.then(async res => {
|
||||
if (res.status === 200) {
|
||||
const result = await db.prepare('all', 'SELECT * FROM "lockCategories" WHERE "videoID" = ?', ['delete-record-1']);
|
||||
if (result.length === 1) {
|
||||
done();
|
||||
} else {
|
||||
done("Didn't delete record");
|
||||
}
|
||||
} else {
|
||||
done("Status code was " + res.status);
|
||||
}
|
||||
assert.strictEqual(res.status, 200);
|
||||
const result = await db.prepare('all', 'SELECT * FROM "lockCategories" WHERE "videoID" = ?', ['delete-record-1']);
|
||||
assert.strictEqual(result.length, 1);
|
||||
done();
|
||||
})
|
||||
.catch(err => done(err));
|
||||
});
|
||||
|
@ -568,11 +481,8 @@ describe('lockCategoriesRecords', () => {
|
|||
}),
|
||||
})
|
||||
.then(async res => {
|
||||
if (res.status === 403) {
|
||||
done();
|
||||
} else {
|
||||
done("Status code was " + res.status);
|
||||
}
|
||||
assert.strictEqual(res.status, 403);
|
||||
done();
|
||||
})
|
||||
.catch(err => done(err));
|
||||
});
|
||||
|
@ -596,11 +506,8 @@ describe('lockCategoriesRecords', () => {
|
|||
},),
|
||||
})
|
||||
.then(async res => {
|
||||
if (res.status === 403) {
|
||||
done();
|
||||
} else {
|
||||
done("Status code was " + res.status);
|
||||
}
|
||||
assert.strictEqual(res.status, 403);
|
||||
done();
|
||||
})
|
||||
.catch(err => done(err));
|
||||
});
|
||||
|
@ -622,11 +529,8 @@ describe('lockCategoriesRecords', () => {
|
|||
}),
|
||||
})
|
||||
.then(async res => {
|
||||
if (res.status === 200) {
|
||||
done();
|
||||
} else {
|
||||
done("Status code was " + res.status);
|
||||
}
|
||||
assert.strictEqual(res.status, 200);
|
||||
done();
|
||||
})
|
||||
.catch(err => done(err));
|
||||
});
|
||||
|
@ -647,11 +551,8 @@ describe('lockCategoriesRecords', () => {
|
|||
}),
|
||||
})
|
||||
.then(async res => {
|
||||
if (res.status === 200) {
|
||||
done();
|
||||
} else {
|
||||
done("Status code was " + res.status);
|
||||
}
|
||||
assert.strictEqual(res.status, 200);
|
||||
done();
|
||||
})
|
||||
.catch(err => done(err));
|
||||
});
|
||||
|
@ -668,29 +569,11 @@ describe('lockCategoriesRecords', () => {
|
|||
|
||||
fetch(getbaseURL() + "/api/lockCategories?videoID=" + "no-segments-video-id")
|
||||
.then(async res => {
|
||||
if (res.status === 200) {
|
||||
const data = await res.json();
|
||||
if (deepEquals(data.categories, expected.categories)) {
|
||||
done();
|
||||
} else {
|
||||
done("Incorrect response: expected " + JSON.stringify(expected) + " got " + JSON.stringify(data));
|
||||
}
|
||||
} else {
|
||||
done("Status code was " + res.status);
|
||||
}
|
||||
assert.strictEqual(res.status, 200);
|
||||
const data = await res.json();
|
||||
assert.ok(deepStringEqual(data.categories, expected.categories));
|
||||
done();
|
||||
})
|
||||
.catch(err => done(err));
|
||||
});
|
||||
|
||||
it('Should be able to get hashedVideoID from lock', (done: Done) => {
|
||||
const hashedVideoID = getHash('no-segments-video-id', 1);
|
||||
db.prepare('get', 'SELECT "hashedVideoID" FROM "lockCategories" WHERE "videoID" = ?', ['no-segments-video-id'])
|
||||
.then(result => {
|
||||
if (result !== hashedVideoID) {
|
||||
done();
|
||||
} else {
|
||||
done("Got unexpected video hash " + result);
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -2,6 +2,7 @@ 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)', () => {
|
||||
before(async () => {
|
||||
|
@ -13,27 +14,27 @@ describe('getVideoSponsorTime (Old get method)', () => {
|
|||
it('Should be able to get a time', (done: Done) => {
|
||||
fetch(getbaseURL() + "/api/getVideoSponsorTimes?videoID=old-testtesttest")
|
||||
.then(res => {
|
||||
if (res.status !== 200) done("non 200 (" + res.status + ")");
|
||||
else done(); // pass
|
||||
assert.strictEqual(res.status, 200);
|
||||
done();
|
||||
})
|
||||
.catch(() => done("Couldn't call endpoint"));
|
||||
.catch(err => done(err));
|
||||
});
|
||||
|
||||
it('Should return 404 if no segment found', (done: Done) => {
|
||||
fetch(getbaseURL() + "/api/getVideoSponsorTimes?videoID=notarealvideo")
|
||||
.then(res => {
|
||||
if (res.status !== 404) done("non 404 respone code: " + res.status);
|
||||
else done(); // pass
|
||||
assert.strictEqual(res.status, 404);
|
||||
done();
|
||||
})
|
||||
.catch(() => done("couldn't call endpoint"));
|
||||
.catch(err => done(err));
|
||||
});
|
||||
|
||||
|
||||
it('Should be possible to send unexpected query parameters', (done: Done) => {
|
||||
fetch(getbaseURL() + "/api/getVideoSponsorTimes?videoID=old-testtesttest&fakeparam=hello")
|
||||
.then(res => {
|
||||
if (res.status !== 200) done("non 200");
|
||||
else done(); // pass
|
||||
assert.strictEqual(res.status, 200);
|
||||
done();
|
||||
})
|
||||
.catch(() => done("couldn't callendpoint"));
|
||||
});
|
||||
|
@ -41,30 +42,24 @@ describe('getVideoSponsorTime (Old get method)', () => {
|
|||
it('Should be able send a comma in a query param', (done: Done) => {
|
||||
fetch(getbaseURL() + "/api/getVideoSponsorTimes?videoID=old-testtesttest,test")
|
||||
.then(async res => {
|
||||
const body = await res.text();
|
||||
if (res.status !== 200) done("non 200 response: " + res.status);
|
||||
else if (JSON.parse(body).UUIDs[0] === 'uuid-1') done(); // pass
|
||||
else done("couldn't parse response");
|
||||
assert.strictEqual(res.status, 200);
|
||||
const data = await res.json();
|
||||
assert.strictEqual(data.UUIDs[0], "uuid-1");
|
||||
done();
|
||||
})
|
||||
.catch(() => done("couln't call endpoint"));
|
||||
.catch(err => done(err));
|
||||
});
|
||||
|
||||
it('Should be able to get the correct time', (done: Done) => {
|
||||
fetch(getbaseURL() + "/api/getVideoSponsorTimes?videoID=old-testtesttest")
|
||||
.then(async res => {
|
||||
if (res.status !== 200) done("non 200");
|
||||
else {
|
||||
const parsedBody = await res.json();
|
||||
if (parsedBody.sponsorTimes[0][0] === 1
|
||||
&& parsedBody.sponsorTimes[0][1] === 11
|
||||
&& parsedBody.UUIDs[0] === 'uuid-0') {
|
||||
done(); // pass
|
||||
} else {
|
||||
done("Wrong data was returned + " + JSON.stringify(parsedBody));
|
||||
}
|
||||
}
|
||||
|
||||
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');
|
||||
done();
|
||||
})
|
||||
.catch(() => done("couldn't call endpoint"));
|
||||
.catch(err => done(err));
|
||||
});
|
||||
});
|
||||
|
|
|
@ -1,23 +1,19 @@
|
|||
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")
|
||||
.then(async res => {
|
||||
if (res.status === 200) {
|
||||
const row = await db.prepare('get', `SELECT "startTime", "endTime", "category" FROM "sponsorTimes" WHERE "videoID" = ?`, ["dQw4w9WgXcQ"]);
|
||||
if (row.startTime === 1 && row.endTime === 10 && row.category === "sponsor") {
|
||||
done();
|
||||
} else {
|
||||
done("Submitted times were not saved. Actual submission: " + JSON.stringify(row));
|
||||
}
|
||||
} else {
|
||||
done("Status code was " + res.status);
|
||||
}
|
||||
assert.strictEqual(res.status, 200);
|
||||
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");
|
||||
done();
|
||||
})
|
||||
.catch(err => done(err));
|
||||
});
|
||||
|
@ -31,16 +27,12 @@ describe('postVideoSponsorTime (Old submission method)', () => {
|
|||
},
|
||||
})
|
||||
.then(async res => {
|
||||
if (res.status === 200) {
|
||||
const row = await db.prepare('get', `SELECT "startTime", "endTime", "category" FROM "sponsorTimes" WHERE "videoID" = ?`, ["dQw4w9WgXcE"]);
|
||||
if (row.startTime === 1 && row.endTime === 11 && row.category === "sponsor") {
|
||||
done();
|
||||
} else {
|
||||
done("Submitted times were not saved. Actual submission: " + JSON.stringify(row));
|
||||
}
|
||||
} else {
|
||||
done("Status code was " + res.status);
|
||||
}
|
||||
assert.strictEqual(res.status, 200);
|
||||
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");
|
||||
done();
|
||||
})
|
||||
.catch(err => done(err));
|
||||
});
|
||||
|
@ -49,8 +41,8 @@ describe('postVideoSponsorTime (Old submission method)', () => {
|
|||
fetch(getbaseURL()
|
||||
+ "/api/postVideoSponsorTimes?startTime=1&endTime=10&userID=testtesttesttesttesttesttesttesttest")
|
||||
.then(async res => {
|
||||
if (res.status === 400) done();
|
||||
else done("Status code was: " + res.status);
|
||||
assert.strictEqual(res.status, 400);
|
||||
done();
|
||||
})
|
||||
.catch(err => done(err));
|
||||
});
|
||||
|
|
|
@ -2,6 +2,7 @@ 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', () => {
|
||||
before(async () => {
|
||||
|
@ -16,8 +17,8 @@ describe('postClearCache', () => {
|
|||
method: 'POST'
|
||||
})
|
||||
.then(res => {
|
||||
if (res.status === 200) done();
|
||||
else done("Status code was " + res.status);
|
||||
assert.strictEqual(res.status, 200);
|
||||
done();
|
||||
})
|
||||
.catch(err => done(err));
|
||||
});
|
||||
|
@ -28,8 +29,8 @@ describe('postClearCache', () => {
|
|||
method: 'POST'
|
||||
})
|
||||
.then(res => {
|
||||
if (res.status === 200) done();
|
||||
else done("Status code was " + res.status);
|
||||
assert.strictEqual(res.status, 200);
|
||||
done();
|
||||
})
|
||||
.catch(err => done(err));
|
||||
});
|
||||
|
@ -40,8 +41,8 @@ describe('postClearCache', () => {
|
|||
method: 'POST'
|
||||
})
|
||||
.then(async res => {
|
||||
if (res.status !== 403) done('non 403 (' + res.status + ')');
|
||||
else done(); // pass
|
||||
assert.strictEqual(res.status, 403);
|
||||
done();
|
||||
})
|
||||
.catch(err => done(err));
|
||||
});
|
||||
|
@ -52,8 +53,8 @@ describe('postClearCache', () => {
|
|||
method: 'POST'
|
||||
})
|
||||
.then(async res => {
|
||||
if (res.status !== 400) done('non 400 (' + res.status + ')');
|
||||
else done(); // pass
|
||||
assert.strictEqual(res.status, 400);
|
||||
done();
|
||||
})
|
||||
.catch(err => done(err));
|
||||
});
|
||||
|
@ -64,8 +65,8 @@ describe('postClearCache', () => {
|
|||
method: 'POST'
|
||||
})
|
||||
.then(async res => {
|
||||
if (res.status !== 400) done('non 400 (' + res.status + ')');
|
||||
else done(); // pass
|
||||
assert.strictEqual(res.status, 400);
|
||||
done();
|
||||
})
|
||||
.catch(err => done(err));
|
||||
});
|
||||
|
|
|
@ -3,6 +3,7 @@ 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,
|
||||
|
@ -57,7 +58,8 @@ describe('postPurgeAllSegments', function () {
|
|||
}),
|
||||
})
|
||||
.then(async res => {
|
||||
done(res.status === 403 ? undefined : res.status);
|
||||
assert.strictEqual(res.status, 403);
|
||||
done();
|
||||
})
|
||||
.catch(err => done(err));
|
||||
});
|
||||
|
@ -74,9 +76,23 @@ describe('postPurgeAllSegments', function () {
|
|||
}),
|
||||
})
|
||||
.then(async res => {
|
||||
if (res.status !== 200) return done(`Status code was ${res.status}`);
|
||||
assert.strictEqual(res.status, 200);
|
||||
done(await dbSponsorTimesCompareExpect(db, 'vsegpurge01', 1) || await dbSponsorTimesCompareExpect(db, 'vseg-not-purged01', 0));
|
||||
})
|
||||
.catch(err => done(err));
|
||||
});
|
||||
|
||||
it('Should return 400 if missing body', function (done: Done) {
|
||||
fetch(`${baseURL}${route}`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
}
|
||||
})
|
||||
.then(async res => {
|
||||
assert.strictEqual(res.status, 400);
|
||||
done();
|
||||
})
|
||||
.catch(err => done(err));
|
||||
});
|
||||
});
|
||||
|
|
|
@ -6,6 +6,7 @@ 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');
|
||||
|
@ -62,16 +63,12 @@ describe('postSkipSegments', () => {
|
|||
},
|
||||
})
|
||||
.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") {
|
||||
done();
|
||||
} else {
|
||||
done("Submitted times were not saved. Actual submission: " + JSON.stringify(row));
|
||||
}
|
||||
} else {
|
||||
done("Status code was " + res.status);
|
||||
}
|
||||
assert.strictEqual(res.status, 200);
|
||||
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");
|
||||
done();
|
||||
})
|
||||
.catch(err => done(err));
|
||||
});
|
||||
|
@ -93,16 +90,13 @@ describe('postSkipSegments', () => {
|
|||
}),
|
||||
})
|
||||
.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") {
|
||||
done();
|
||||
} else {
|
||||
done("Submitted times were not saved. Actual submission: " + JSON.stringify(row));
|
||||
}
|
||||
} else {
|
||||
done("Status code was " + res.status);
|
||||
}
|
||||
assert.strictEqual(res.status, 200);
|
||||
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);
|
||||
assert.strictEqual(row.category, "sponsor");
|
||||
done();
|
||||
})
|
||||
.catch(err => done(err));
|
||||
});
|
||||
|
@ -125,16 +119,14 @@ describe('postSkipSegments', () => {
|
|||
}),
|
||||
})
|
||||
.then(async res => {
|
||||
if (res.status === 200) {
|
||||
const row = await db.prepare('get', `SELECT "startTime", "endTime", "locked", "category", "actionType" FROM "sponsorTimes" WHERE "videoID" = ?`, ["dQw4w9WgXcV"]);
|
||||
if (row.startTime === 0 && row.endTime === 10 && row.locked === 0 && row.category === "sponsor" && row.actionType === "mute") {
|
||||
done();
|
||||
} else {
|
||||
done("Submitted times were not saved. Actual submission: " + JSON.stringify(row));
|
||||
}
|
||||
} else {
|
||||
done("Status code was " + res.status);
|
||||
}
|
||||
assert.strictEqual(res.status, 200);
|
||||
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);
|
||||
assert.strictEqual(row.category, "sponsor");
|
||||
assert.strictEqual(row.actionType, "mute");
|
||||
done();
|
||||
})
|
||||
.catch(err => done(err));
|
||||
});
|
||||
|
@ -157,16 +149,14 @@ describe('postSkipSegments', () => {
|
|||
}),
|
||||
})
|
||||
.then(async res => {
|
||||
if (res.status === 200) {
|
||||
const row = await db.prepare('get', `SELECT "startTime", "endTime", "locked", "category", "videoDuration" FROM "sponsorTimes" WHERE "videoID" = ?`, ["dQw4w9WgXZX"]);
|
||||
if (row.startTime === 0 && row.endTime === 10 && row.locked === 0 && row.category === "sponsor" && row.videoDuration === 4980) {
|
||||
done();
|
||||
} else {
|
||||
done("Submitted times were not saved. Actual submission: " + JSON.stringify(row));
|
||||
}
|
||||
} else {
|
||||
done("Status code was " + res.status);
|
||||
}
|
||||
assert.strictEqual(res.status, 200);
|
||||
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);
|
||||
assert.strictEqual(row.category, "sponsor");
|
||||
assert.strictEqual(row.videoDuration, 4980);
|
||||
done();
|
||||
})
|
||||
.catch(err => done(err));
|
||||
});
|
||||
|
@ -189,16 +179,14 @@ describe('postSkipSegments', () => {
|
|||
}),
|
||||
})
|
||||
.then(async res => {
|
||||
if (res.status === 200) {
|
||||
const row = await db.prepare('get', `SELECT "startTime", "endTime", "locked", "category", "videoDuration" FROM "sponsorTimes" WHERE "videoID" = ?`, ["dQw4w9WgXZH"]);
|
||||
if (row.startTime === 1 && row.endTime === 10 && row.locked === 0 && row.category === "sponsor" && row.videoDuration === 4980.20) {
|
||||
done();
|
||||
} else {
|
||||
done("Submitted times were not saved. Actual submission: " + JSON.stringify(row));
|
||||
}
|
||||
} else {
|
||||
done("Status code was " + res.status);
|
||||
}
|
||||
assert.strictEqual(res.status, 200);
|
||||
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);
|
||||
assert.strictEqual(row.category, "sponsor");
|
||||
assert.strictEqual(row.videoDuration, 4980.20);
|
||||
done();
|
||||
})
|
||||
.catch(err => done(err));
|
||||
});
|
||||
|
@ -221,16 +209,14 @@ describe('postSkipSegments', () => {
|
|||
}),
|
||||
})
|
||||
.then(async res => {
|
||||
if (res.status === 200) {
|
||||
const row = await db.prepare('get', `SELECT "startTime", "endTime", "locked", "category", "videoDuration" FROM "sponsorTimes" WHERE "videoID" = ?`, ["noDuration"]);
|
||||
if (row.startTime === 0 && row.endTime === 10 && row.locked === 0 && row.category === "sponsor" && row.videoDuration === 100) {
|
||||
done();
|
||||
} else {
|
||||
done("Submitted times were not saved. Actual submission: " + JSON.stringify(row));
|
||||
}
|
||||
} else {
|
||||
done("Status code was " + res.status);
|
||||
}
|
||||
assert.strictEqual(res.status, 200);
|
||||
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);
|
||||
assert.strictEqual(row.category, "sponsor");
|
||||
assert.strictEqual(row.videoDuration, 100);
|
||||
done();
|
||||
})
|
||||
.catch(err => done(err));
|
||||
});
|
||||
|
@ -256,23 +242,21 @@ describe('postSkipSegments', () => {
|
|||
}],
|
||||
}),
|
||||
});
|
||||
|
||||
if (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"
|
||||
FROM "sponsorTimes" WHERE "videoID" = ? AND hidden = 0`, ["noDuration"]);
|
||||
const videoRow = videoRows[0];
|
||||
const hiddenVideoRows = await db.prepare('all', `SELECT "startTime", "endTime", "locked", "category", "videoDuration"
|
||||
FROM "sponsorTimes" WHERE "videoID" = ? AND hidden = 1`, ["noDuration"]);
|
||||
if (lockCategoriesRow === undefined && videoRows.length === 1 && hiddenVideoRows.length === 1 && videoRow.startTime === 1 && videoRow.endTime === 10
|
||||
&& videoRow.locked === 0 && videoRow.category === "sponsor" && videoRow.videoDuration === 100) {
|
||||
return;
|
||||
} else {
|
||||
return "Submitted times were not saved. Actual submission: " + JSON.stringify(videoRow);
|
||||
}
|
||||
} else {
|
||||
return "Status code was " + res.status;
|
||||
}
|
||||
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"
|
||||
FROM "sponsorTimes" WHERE "videoID" = ? AND hidden = 0`, ["noDuration"]);
|
||||
const videoRow = videoRows[0];
|
||||
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);
|
||||
assert.strictEqual(hiddenVideoRows.length, 1);
|
||||
assert.strictEqual(videoRow.startTime, 1);
|
||||
assert.strictEqual(videoRow.endTime, 10);
|
||||
assert.strictEqual(videoRow.locked, 0);
|
||||
assert.strictEqual(videoRow.category, "sponsor");
|
||||
assert.strictEqual(videoRow.videoDuration, 100);
|
||||
} catch (e) {
|
||||
return e;
|
||||
}
|
||||
|
@ -284,13 +268,10 @@ describe('postSkipSegments', () => {
|
|||
method: 'POST',
|
||||
})
|
||||
.then(async res => {
|
||||
if (res.status === 403) done(); // pass
|
||||
else {
|
||||
const body = await res.text();
|
||||
done("non 403 status code: " + res.status + " (" + body + ")");
|
||||
}
|
||||
assert.strictEqual(res.status, 403);
|
||||
done();
|
||||
})
|
||||
.catch(() => done("Couldn't call endpoint"));
|
||||
.catch(err => done(err));
|
||||
});
|
||||
|
||||
it('Should be able to submit a single time under a different service (JSON method)', (done: Done) => {
|
||||
|
@ -311,16 +292,14 @@ describe('postSkipSegments', () => {
|
|||
}),
|
||||
})
|
||||
.then(async res => {
|
||||
if (res.status === 200) {
|
||||
const row = await db.prepare('get', `SELECT "startTime", "endTime", "locked", "category", "service" FROM "sponsorTimes" WHERE "videoID" = ?`, ["dQw4w9WgXcG"]);
|
||||
if (row.startTime === 0 && row.endTime === 10 && row.locked === 0 && row.category === "sponsor" && row.service === "PeerTube") {
|
||||
done();
|
||||
} else {
|
||||
done("Submitted times were not saved. Actual submission: " + JSON.stringify(row));
|
||||
}
|
||||
} else {
|
||||
done("Status code was " + res.status);
|
||||
}
|
||||
assert.strictEqual(res.status, 200);
|
||||
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);
|
||||
assert.strictEqual(row.category, "sponsor");
|
||||
assert.strictEqual(row.service, "PeerTube");
|
||||
done();
|
||||
})
|
||||
.catch(err => done(err));
|
||||
});
|
||||
|
@ -342,16 +321,13 @@ describe('postSkipSegments', () => {
|
|||
}),
|
||||
})
|
||||
.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") {
|
||||
done();
|
||||
} else {
|
||||
done("Submitted times were not saved. Actual submission: " + JSON.stringify(row));
|
||||
}
|
||||
} else {
|
||||
done("Status code was " + res.status);
|
||||
}
|
||||
assert.strictEqual(res.status, 200);
|
||||
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);
|
||||
assert.strictEqual(row.category, "sponsor");
|
||||
done();
|
||||
})
|
||||
.catch(err => done(err));
|
||||
});
|
||||
|
@ -365,7 +341,7 @@ describe('postSkipSegments', () => {
|
|||
},
|
||||
body: JSON.stringify({
|
||||
userID: "testtesttesttesttesttesttesttesttest",
|
||||
videoID: "dQw4w9WgXcQ",
|
||||
videoID: "dQw4w9WgXcT",
|
||||
segments: [{
|
||||
segment: [3, 10],
|
||||
category: "sponsor",
|
||||
|
@ -376,23 +352,19 @@ describe('postSkipSegments', () => {
|
|||
}),
|
||||
})
|
||||
.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;
|
||||
if (rows.length === 2) {
|
||||
for (const row of rows) {
|
||||
if ((row.startTime !== 3 || row.endTime !== 10 || row.category !== "sponsor") &&
|
||||
(row.startTime !== 30 || row.endTime !== 60 || row.category !== "intro")) {
|
||||
success = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (success) done();
|
||||
else done("Submitted times were not saved. Actual submissions: " + JSON.stringify(rows));
|
||||
} else {
|
||||
done("Status code was " + res.status);
|
||||
}
|
||||
assert.strictEqual(res.status, 200);
|
||||
const rows = await db.prepare('all', `SELECT "startTime", "endTime", "category" FROM "sponsorTimes" WHERE "videoID" = ?`, ["dQw4w9WgXcT"]);
|
||||
const expected = [{
|
||||
startTime: 3,
|
||||
endTime: 10,
|
||||
category: "sponsor"
|
||||
}, {
|
||||
startTime: 30,
|
||||
endTime: 60,
|
||||
category: "intro"
|
||||
}];
|
||||
assert.deepStrictEqual(rows, expected);
|
||||
done();
|
||||
})
|
||||
.catch(err => done(err));
|
||||
}).timeout(5000);
|
||||
|
@ -423,25 +395,27 @@ describe('postSkipSegments', () => {
|
|||
}),
|
||||
})
|
||||
.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;
|
||||
if (rows.length === 4) {
|
||||
for (const row of rows) {
|
||||
if ((row.startTime !== 3 || row.endTime !== 3000 || row.category !== "sponsor") &&
|
||||
(row.startTime !== 3002 || row.endTime !== 3050 || row.category !== "intro") &&
|
||||
(row.startTime !== 45 || row.endTime !== 100 || row.category !== "interaction") &&
|
||||
(row.startTime !== 99 || row.endTime !== 170 || row.category !== "sponsor")) {
|
||||
success = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (success) done();
|
||||
else done("Submitted times were not saved. Actual submissions: " + JSON.stringify(rows));
|
||||
} else {
|
||||
done("Status code was " + res.status);
|
||||
}
|
||||
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 expected = [{
|
||||
startTime: 3,
|
||||
endTime: 3000,
|
||||
category: "sponsor"
|
||||
}, {
|
||||
startTime: 3002,
|
||||
endTime: 3050,
|
||||
category: "intro"
|
||||
}, {
|
||||
startTime: 45,
|
||||
endTime: 100,
|
||||
category: "interaction"
|
||||
}, {
|
||||
startTime: 99,
|
||||
endTime: 170,
|
||||
category: "sponsor"
|
||||
}];
|
||||
assert.deepStrictEqual(rows, expected);
|
||||
done();
|
||||
})
|
||||
.catch(err => done(err));
|
||||
}).timeout(5000);
|
||||
|
@ -472,27 +446,10 @@ describe('postSkipSegments', () => {
|
|||
}),
|
||||
})
|
||||
.then(async res => {
|
||||
if (res.status === 403) {
|
||||
const rows = await db.prepare('all', `SELECT "startTime", "endTime", "category" FROM "sponsorTimes" WHERE "videoID" = ? and "votes" > -1`, ["n9rIGdXnSJc"]);
|
||||
let success = true;
|
||||
if (rows.length === 4) {
|
||||
for (const row of rows) {
|
||||
if ((row.startTime === 0 || row.endTime === 2000 || row.category === "interaction") ||
|
||||
(row.startTime === 3000 || row.endTime === 4000 || row.category === "sponsor") ||
|
||||
(row.startTime === 1500 || row.endTime === 2750 || row.category === "sponsor") ||
|
||||
(row.startTime === 4050 || row.endTime === 4750 || row.category === "intro")) {
|
||||
success = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (success) done();
|
||||
else
|
||||
done("Submitted times were not saved. Actual submissions: " + JSON.stringify(rows));
|
||||
} else {
|
||||
done("Status code was " + res.status);
|
||||
}
|
||||
assert.strictEqual(res.status, 403);
|
||||
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);
|
||||
|
@ -520,23 +477,23 @@ describe('postSkipSegments', () => {
|
|||
}),
|
||||
})
|
||||
.then(async res => {
|
||||
if (res.status === 403) {
|
||||
const rows = await db.prepare('all', `SELECT "startTime", "endTime", "category" FROM "sponsorTimes" WHERE "videoID" = ? and "votes" > -1`, ["80percent_video"]);
|
||||
let success = rows.length == 2;
|
||||
for (const row of rows) {
|
||||
if ((row.startTime === 2000 || row.endTime === 4000 || row.category === "sponsor") ||
|
||||
(row.startTime === 1500 || row.endTime === 2750 || row.category === "sponsor") ||
|
||||
(row.startTime === 4050 || row.endTime === 4750 || row.category === "sponsor")) {
|
||||
success = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (success) done();
|
||||
else
|
||||
done("Submitted times were not saved. Actual submissions: " + JSON.stringify(rows));
|
||||
} else {
|
||||
done("Status code was " + res.status);
|
||||
}
|
||||
assert.strictEqual(res.status, 403);
|
||||
const expected = [{
|
||||
category: "sponsor",
|
||||
startTime: 2000,
|
||||
endTime: 4000
|
||||
}, {
|
||||
category: "sponsor",
|
||||
startTime: 1500,
|
||||
endTime: 2750
|
||||
}, {
|
||||
category: "sponsor",
|
||||
startTime: 4050,
|
||||
endTime: 4750
|
||||
}];
|
||||
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);
|
||||
|
@ -546,14 +503,11 @@ describe('postSkipSegments', () => {
|
|||
+ "/api/skipSegments?videoID=qqwerty&startTime=30&endTime=30.5&userID=testtesttesttesttesttesttesttesttesting&category=intro", {
|
||||
method: 'POST',
|
||||
})
|
||||
.then(async res => {
|
||||
if (res.status === 200) done(); // pass
|
||||
else {
|
||||
const body = await res.text();
|
||||
done("non 200 status code: " + res.status + " (" + body + ")");
|
||||
}
|
||||
.then(res => {
|
||||
assert.strictEqual(res.status, 200);
|
||||
done();
|
||||
})
|
||||
.catch(() => done("Couldn't call endpoint"));
|
||||
.catch(err => done(err));
|
||||
});
|
||||
|
||||
it('Should be rejected if segment starts and ends at the same time', (done: Done) => {
|
||||
|
@ -561,14 +515,11 @@ describe('postSkipSegments', () => {
|
|||
+ "/api/skipSegments?videoID=qqwerty&startTime=90&endTime=90&userID=testtesttesttesttesttesttesttesttesting&category=intro", {
|
||||
method: 'POST',
|
||||
})
|
||||
.then(async res => {
|
||||
if (res.status === 400) done(); // pass
|
||||
else {
|
||||
const body = await res.text();
|
||||
done("non 400 status code: " + res.status + " (" + body + ")");
|
||||
}
|
||||
.then(res => {
|
||||
assert.strictEqual(res.status, 400);
|
||||
done();
|
||||
})
|
||||
.catch(() => done("Couldn't call endpoint"));
|
||||
.catch(err => done(err));
|
||||
});
|
||||
|
||||
it('Should be accepted if highlight segment starts and ends at the same time', (done: Done) => {
|
||||
|
@ -576,14 +527,11 @@ describe('postSkipSegments', () => {
|
|||
+ "/api/skipSegments?videoID=qqwerty&startTime=30&endTime=30&userID=testtesttesttesttesttesttesttesttesting&category=highlight", {
|
||||
method: 'POST',
|
||||
})
|
||||
.then(async res => {
|
||||
if (res.status === 200) done(); // pass
|
||||
else {
|
||||
const body = await res.text();
|
||||
done("non 200 status code: " + res.status + " (" + body + ")");
|
||||
}
|
||||
.then(res => {
|
||||
assert.strictEqual(res.status, 200);
|
||||
done();
|
||||
})
|
||||
.catch(() => done("Couldn't call endpoint"));
|
||||
.catch(err => done(err));
|
||||
});
|
||||
|
||||
it('Should be rejected if highlight segment doesn\'t start and end at the same time', (done: Done) => {
|
||||
|
@ -591,14 +539,11 @@ describe('postSkipSegments', () => {
|
|||
+ "/api/skipSegments?videoID=qqwerty&startTime=30&endTime=30.5&userID=testtesttesttesttesttesttesttesttesting&category=highlight", {
|
||||
method: 'POST',
|
||||
})
|
||||
.then(async res => {
|
||||
if (res.status === 400) done(); // pass
|
||||
else {
|
||||
const body = await res.text();
|
||||
done("non 400 status code: " + res.status + " (" + body + ")");
|
||||
}
|
||||
.then(res => {
|
||||
assert.strictEqual(res.status, 400);
|
||||
done();
|
||||
})
|
||||
.catch(() => done("Couldn't call endpoint"));
|
||||
.catch(err => done(err));
|
||||
});
|
||||
|
||||
it('Should be rejected if a sponsor is less than 1 second', (done: Done) => {
|
||||
|
@ -606,40 +551,31 @@ describe('postSkipSegments', () => {
|
|||
+ "/api/skipSegments?videoID=qqwerty&startTime=30&endTime=30.5&userID=testtesttesttesttesttesttesttesttesting", {
|
||||
method: 'POST',
|
||||
})
|
||||
.then(async res => {
|
||||
if (res.status === 400) done(); // pass
|
||||
else {
|
||||
const body = await res.text();
|
||||
done("non 403 status code: " + res.status + " (" + body + ")");
|
||||
}
|
||||
.then(res => {
|
||||
assert.strictEqual(res.status, 400);
|
||||
done();
|
||||
})
|
||||
.catch(() => done("Couldn't call endpoint"));
|
||||
.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")
|
||||
.then(async res => {
|
||||
if (res.status === 403) done(); // pass
|
||||
else {
|
||||
const body = await res.text();
|
||||
done("non 403 status code: " + res.status + " (" + body + ")");
|
||||
}
|
||||
.then(res => {
|
||||
assert.strictEqual(res.status, 403);
|
||||
done();
|
||||
})
|
||||
.catch(() => done("Couldn't call endpoint"));
|
||||
.catch(err => done(err));
|
||||
});
|
||||
|
||||
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")
|
||||
.then(async res => {
|
||||
if (res.status === 200) done(); // pass
|
||||
else {
|
||||
const body = await res.text();
|
||||
done("non 200 status code: " + res.status + " (" + body + ")");
|
||||
}
|
||||
.then(res => {
|
||||
assert.strictEqual(res.status, 200);
|
||||
done();
|
||||
})
|
||||
.catch(() => done("Couldn't call endpoint"));
|
||||
.catch(err => done(err));
|
||||
});
|
||||
|
||||
it('Should be rejected with custom message if user has to many active warnings', (done: Done) => {
|
||||
|
@ -659,16 +595,10 @@ describe('postSkipSegments', () => {
|
|||
}),
|
||||
})
|
||||
.then(async res => {
|
||||
if (res.status === 403) {
|
||||
const errorMessage = await res.text();
|
||||
if (errorMessage === 'Reason01') {
|
||||
done(); // success
|
||||
} else {
|
||||
done("Status code was 403 but message was: " + errorMessage);
|
||||
}
|
||||
} else {
|
||||
done("Status code was " + res.status);
|
||||
}
|
||||
assert.strictEqual(res.status, 403);
|
||||
const errorMessage = await res.text();
|
||||
assert.strictEqual(errorMessage, 'Reason01');
|
||||
done();
|
||||
})
|
||||
.catch(err => done(err));
|
||||
});
|
||||
|
@ -736,7 +666,7 @@ describe('postSkipSegments', () => {
|
|||
if (res.status === 400) done();
|
||||
else done(true);
|
||||
})
|
||||
.catch(() => done(true));
|
||||
.catch(err => done(err));
|
||||
});
|
||||
|
||||
it('Should be rejected with default message if user has to many active warnings', (done: Done) => {
|
||||
|
@ -756,16 +686,10 @@ describe('postSkipSegments', () => {
|
|||
}),
|
||||
})
|
||||
.then(async res => {
|
||||
if (res.status === 403) {
|
||||
const errorMessage = await res.text();
|
||||
if (errorMessage !== '') {
|
||||
done(); // success
|
||||
} else {
|
||||
done("Status code was 403 but message was: " + errorMessage);
|
||||
}
|
||||
} else {
|
||||
done("Status code was " + res.status);
|
||||
}
|
||||
assert.strictEqual(res.status, 403);
|
||||
const errorMessage = await res.text();
|
||||
assert.notStrictEqual(errorMessage, '');
|
||||
done();
|
||||
})
|
||||
.catch(err => done(err));
|
||||
});
|
||||
|
@ -788,11 +712,11 @@ describe('postSkipSegments', () => {
|
|||
}],
|
||||
}),
|
||||
})
|
||||
.then(async res => {
|
||||
if (res.status === 400) done();
|
||||
else done(true);
|
||||
.then(res => {
|
||||
assert.strictEqual(res.status, 400);
|
||||
done();
|
||||
})
|
||||
.catch(() => done(true));
|
||||
.catch(err => done(err));
|
||||
});
|
||||
it('Should return 400 for missing params (JSON method) 2', (done: Done) => {
|
||||
fetch(getbaseURL()
|
||||
|
@ -806,11 +730,11 @@ describe('postSkipSegments', () => {
|
|||
videoID: "dQw4w9WgXcQ",
|
||||
}),
|
||||
})
|
||||
.then(async res => {
|
||||
if (res.status === 400) done();
|
||||
else done(true);
|
||||
.then(res => {
|
||||
assert.strictEqual(res.status, 400);
|
||||
done();
|
||||
})
|
||||
.catch(() => done(true));
|
||||
.catch(err => done(err));
|
||||
});
|
||||
it('Should return 400 for missing params (JSON method) 3', (done: Done) => {
|
||||
fetch(getbaseURL()
|
||||
|
@ -831,11 +755,11 @@ describe('postSkipSegments', () => {
|
|||
}],
|
||||
}),
|
||||
})
|
||||
.then(async res => {
|
||||
if (res.status === 400) done();
|
||||
else done(true);
|
||||
.then(res => {
|
||||
assert.strictEqual(res.status, 400);
|
||||
done();
|
||||
})
|
||||
.catch(() => done(true));
|
||||
.catch(err => done(err));
|
||||
});
|
||||
it('Should return 400 for missing params (JSON method) 4', (done: Done) => {
|
||||
fetch(getbaseURL()
|
||||
|
@ -855,11 +779,11 @@ describe('postSkipSegments', () => {
|
|||
}],
|
||||
}),
|
||||
})
|
||||
.then(async res => {
|
||||
if (res.status === 400) done();
|
||||
else done(true);
|
||||
.then(res => {
|
||||
assert.strictEqual(res.status, 400);
|
||||
done();
|
||||
})
|
||||
.catch(() => done(true));
|
||||
.catch(err => done(err));
|
||||
});
|
||||
it('Should return 400 for missing params (JSON method) 5', (done: Done) => {
|
||||
fetch(getbaseURL()
|
||||
|
@ -873,10 +797,10 @@ describe('postSkipSegments', () => {
|
|||
videoID: "dQw4w9WgXcQ",
|
||||
}),
|
||||
})
|
||||
.then(async res => {
|
||||
if (res.status === 400) done();
|
||||
else done(true);
|
||||
.then(res => {
|
||||
assert.strictEqual(res.status, 400);
|
||||
done();
|
||||
})
|
||||
.catch(() => done(true));
|
||||
.catch(err => done(err));
|
||||
});
|
||||
});
|
||||
|
|
|
@ -2,6 +2,7 @@ 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', () => {
|
||||
before(async () => {
|
||||
|
@ -23,18 +24,12 @@ describe('postWarning', () => {
|
|||
body: JSON.stringify(json),
|
||||
})
|
||||
.then(async res => {
|
||||
if (res.status === 200) {
|
||||
const row = await db.prepare('get', `SELECT "userID", "issueTime", "issuerUserID", enabled, "reason" FROM warnings WHERE "userID" = ?`, [json.userID]);
|
||||
if (row?.enabled == 1 && row?.issuerUserID == getHash(json.issuerUserID) && row?.reason === json.reason) {
|
||||
done();
|
||||
} else {
|
||||
done("Warning missing from database");
|
||||
}
|
||||
} else {
|
||||
const body = await res.text();
|
||||
console.log(body);
|
||||
done("Status code was " + res.status);
|
||||
}
|
||||
assert.strictEqual(res.status, 200);
|
||||
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);
|
||||
done();
|
||||
})
|
||||
.catch(err => done(err));
|
||||
});
|
||||
|
@ -54,18 +49,11 @@ describe('postWarning', () => {
|
|||
body: JSON.stringify(json),
|
||||
})
|
||||
.then(async res => {
|
||||
if (res.status === 409) {
|
||||
const row = await db.prepare('get', `SELECT "userID", "issueTime", "issuerUserID", enabled FROM warnings WHERE "userID" = ?`, [json.userID]);
|
||||
if (row?.enabled == 1 && row?.issuerUserID == getHash(json.issuerUserID)) {
|
||||
done();
|
||||
} else {
|
||||
done("Warning missing from database");
|
||||
}
|
||||
} else {
|
||||
const body = await res.text();
|
||||
console.log(body);
|
||||
done("Status code was " + res.status);
|
||||
}
|
||||
assert.strictEqual(res.status, 409);
|
||||
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();
|
||||
})
|
||||
.catch(err => done(err));
|
||||
});
|
||||
|
@ -86,18 +74,10 @@ describe('postWarning', () => {
|
|||
body: JSON.stringify(json),
|
||||
})
|
||||
.then(async res => {
|
||||
if (res.status === 200) {
|
||||
const row = await db.prepare('get', `SELECT "userID", "issueTime", "issuerUserID", enabled FROM warnings WHERE "userID" = ?`, [json.userID]);
|
||||
if (row?.enabled == 0) {
|
||||
done();
|
||||
} else {
|
||||
done("Warning missing from database");
|
||||
}
|
||||
} else {
|
||||
const body = await res.text();
|
||||
console.log(body);
|
||||
done("Status code was " + res.status);
|
||||
}
|
||||
assert.strictEqual(res.status, 200);
|
||||
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));
|
||||
});
|
||||
|
@ -116,15 +96,25 @@ describe('postWarning', () => {
|
|||
},
|
||||
body: JSON.stringify(json),
|
||||
})
|
||||
.then(async res => {
|
||||
if (res.status === 403) {
|
||||
done();
|
||||
} else {
|
||||
const body = await res.text();
|
||||
console.log(body);
|
||||
done("Status code was " + res.status);
|
||||
.then(res => {
|
||||
assert.strictEqual(res.status, 403);
|
||||
done();
|
||||
})
|
||||
.catch(err => done(err));
|
||||
});
|
||||
|
||||
it('Should return 400 if missing body', (done: Done) => {
|
||||
fetch(getbaseURL()
|
||||
+ "/api/warnUser", {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
}
|
||||
})
|
||||
.then(async res => {
|
||||
assert.strictEqual(res.status, 400);
|
||||
done();
|
||||
})
|
||||
.catch(err => done(err));
|
||||
});
|
||||
});
|
||||
|
|
|
@ -114,11 +114,11 @@ describe('reputation', () => {
|
|||
});
|
||||
|
||||
it("user with high reputation", async () => {
|
||||
assert.strictEqual(await getReputation(getHash(userIDHighRep)), 0.24137931034482757);
|
||||
assert.strictEqual(await getReputation(getHash(userIDHighRep)), 0.19310344827586207);
|
||||
});
|
||||
|
||||
it("user with high reputation and locked segments", async () => {
|
||||
assert.strictEqual(await getReputation(getHash(userIDHighRepAndLocked)), 1.8413793103448277);
|
||||
assert.strictEqual(await getReputation(getHash(userIDHighRepAndLocked)), 1.793103448275862);
|
||||
});
|
||||
|
||||
});
|
||||
|
|
|
@ -3,6 +3,7 @@ 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,
|
||||
|
@ -22,25 +23,18 @@ async function dbSponsorTimesSetByUUID(db: IDatabase, UUID: string, startTime: n
|
|||
await db.prepare('run', `UPDATE "sponsorTimes" SET "startTime" = ?, "endTime" = ? WHERE "UUID" = ?`, [startTime, endTime, UUID]);
|
||||
}
|
||||
|
||||
async function dbSponsorTimesCompareExpect(db: IDatabase, expect: any) {
|
||||
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) {
|
||||
if (expect.removed === true && seg.votes === -2) {
|
||||
return;
|
||||
} else {
|
||||
return `${expectSeg.UUID} doesnt got removed`;
|
||||
}
|
||||
}
|
||||
if (seg.startTime !== expectSeg.startTime) {
|
||||
return `${expectSeg.UUID} startTime is incorrect. seg.startTime is ${seg.startTime} expected ${expectSeg.startTime}`;
|
||||
}
|
||||
if (seg.endTime !== expectSeg.endTime) {
|
||||
return `${expectSeg.UUID} endTime is incorrect. seg.endTime is ${seg.endTime} expected ${expectSeg.endTime}`;
|
||||
assert.ok(expect.removed);
|
||||
assert.strictEqual(seg.votes, -2);
|
||||
assert.deepStrictEqual(seg, expectSeg);
|
||||
assert.strictEqual(seg.startTime, expectSeg.startTime);
|
||||
assert.strictEqual(seg.endTime, expectSeg.endTime);
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
describe('segmentShift', function () {
|
||||
|
@ -79,7 +73,8 @@ describe('segmentShift', function () {
|
|||
}),
|
||||
})
|
||||
.then(async res => {
|
||||
done(res.status === 403 ? undefined : res.status);
|
||||
assert.strictEqual(res.status, 403);
|
||||
done();
|
||||
})
|
||||
.catch(err => done(err));
|
||||
});
|
||||
|
@ -98,7 +93,7 @@ describe('segmentShift', function () {
|
|||
}),
|
||||
})
|
||||
.then(async res => {
|
||||
if (res.status !== 200) return done(`Status code was ${res.status}`);
|
||||
assert.strictEqual(res.status, 200);
|
||||
const expect = [
|
||||
{
|
||||
UUID: 'vsegshifttest01uuid01',
|
||||
|
@ -140,7 +135,7 @@ describe('segmentShift', function () {
|
|||
}),
|
||||
})
|
||||
.then(async res => {
|
||||
if (res.status !== 200) return done(`Status code was ${res.status}`);
|
||||
assert.strictEqual(res.status, 200);
|
||||
const expect = [
|
||||
{
|
||||
UUID: 'vsegshifttest01uuid01',
|
||||
|
@ -182,7 +177,7 @@ describe('segmentShift', function () {
|
|||
}),
|
||||
})
|
||||
.then(async res => {
|
||||
if (res.status !== 200) return done(`Status code was ${res.status}`);
|
||||
assert.strictEqual(res.status, 200);
|
||||
const expect = [
|
||||
{
|
||||
UUID: 'vsegshifttest01uuid01',
|
||||
|
@ -224,7 +219,7 @@ describe('segmentShift', function () {
|
|||
}),
|
||||
})
|
||||
.then(async res => {
|
||||
if (res.status !== 200) return done(`Status code was ${res.status}`);
|
||||
assert.strictEqual(res.status, 200);
|
||||
const expect = [
|
||||
{
|
||||
UUID: 'vsegshifttest01uuid01',
|
||||
|
@ -266,7 +261,7 @@ describe('segmentShift', function () {
|
|||
}),
|
||||
})
|
||||
.then(async res => {
|
||||
if (res.status !== 200) return done(`Status code was ${res.status}`);
|
||||
assert.strictEqual(res.status, 200);
|
||||
const expect = [
|
||||
{
|
||||
UUID: 'vsegshifttest01uuid01',
|
||||
|
|
|
@ -2,6 +2,7 @@ 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';
|
||||
|
@ -51,21 +52,10 @@ function wellFormatUserName(userName: string) {
|
|||
}
|
||||
|
||||
async function testUserNameChangelog(userID: string, newUserName: string, oldUserName: string, byAdmin: boolean, done: Done) {
|
||||
|
||||
const log = await getLastLogUserNameChange(userID);
|
||||
|
||||
if (newUserName !== log.newUserName) {
|
||||
return done(`UserID '${userID}' incorrect log on newUserName: ${newUserName} !== ${log.newUserName}`);
|
||||
}
|
||||
|
||||
if (oldUserName !== log.oldUserName) {
|
||||
return done(`UserID '${userID}' incorrect log on oldUserName: ${oldUserName} !== ${log.oldUserName}`);
|
||||
}
|
||||
|
||||
if (byAdmin !== Boolean(log.updatedByAdmin)) {
|
||||
return done(`UserID '${userID}' incorrect log on updatedByAdmin: ${byAdmin} !== ${log.updatedByAdmin}`);
|
||||
}
|
||||
|
||||
assert.strictEqual(newUserName, log.newUserName);
|
||||
assert.strictEqual(oldUserName, log.oldUserName);
|
||||
assert.strictEqual(byAdmin, Boolean(log.updatedByAdmin));
|
||||
return done();
|
||||
}
|
||||
|
||||
|
@ -86,9 +76,9 @@ describe('setUsername', () => {
|
|||
})
|
||||
.then(async res => {
|
||||
const usernameInfo = await getUsernameInfo(getHash(user00PrivateUserID));
|
||||
if (res.status !== 200) done(`Status code was ${res.status}`);
|
||||
if (usernameInfo.userName !== username00) done(`Username did not change. Currently is ${usernameInfo.userName}`);
|
||||
if (usernameInfo.locked == "1") done(`Username was locked when it shouldn't have been`);
|
||||
assert.strictEqual(res.status, 200);
|
||||
assert.strictEqual(usernameInfo.userName, username00);
|
||||
assert.notStrictEqual(usernameInfo.locked, 1, "username should not be locked");
|
||||
done();
|
||||
})
|
||||
.catch(() => done(`couldn't call endpoint`));
|
||||
|
@ -99,10 +89,8 @@ describe('setUsername', () => {
|
|||
method: 'POST',
|
||||
})
|
||||
.then(async res => {
|
||||
if (res.status !== 200) done(`Status code was ${res.status}`);
|
||||
else {
|
||||
testUserNameChangelog(user01PrivateUserID, decodeURIComponent('Changed%20Username'), username01, false, done);
|
||||
}
|
||||
assert.strictEqual(res.status, 200);
|
||||
testUserNameChangelog(user01PrivateUserID, decodeURIComponent('Changed%20Username'), username01, false, done);
|
||||
})
|
||||
.catch(() => done(`couldn't call endpoint`));
|
||||
});
|
||||
|
@ -112,8 +100,8 @@ describe('setUsername', () => {
|
|||
method: 'POST',
|
||||
})
|
||||
.then(res => {
|
||||
if (res.status !== 400) done(`Status code was ${res.status}`);
|
||||
else done(); // pass
|
||||
assert.strictEqual(res.status, 400);
|
||||
done();
|
||||
})
|
||||
.catch(() => done(`couldn't call endpoint`));
|
||||
});
|
||||
|
@ -123,8 +111,8 @@ describe('setUsername', () => {
|
|||
method: 'POST',
|
||||
})
|
||||
.then(res => {
|
||||
if (res.status !== 400) done(`Status code was ${res.status}`);
|
||||
else done(); // pass
|
||||
assert.strictEqual(res.status, 400);
|
||||
done();
|
||||
})
|
||||
.catch(() => done(`couldn't call endpoint`));
|
||||
});
|
||||
|
@ -135,8 +123,8 @@ describe('setUsername', () => {
|
|||
method: 'POST',
|
||||
})
|
||||
.then(res => {
|
||||
if (res.status !== 400) done(`Status code was ${res.status}`);
|
||||
else done(); // pass
|
||||
assert.strictEqual(res.status, 400);
|
||||
done();
|
||||
})
|
||||
.catch(() => done(`couldn't call endpoint`));
|
||||
});
|
||||
|
@ -147,14 +135,10 @@ describe('setUsername', () => {
|
|||
method: 'POST',
|
||||
})
|
||||
.then(async res => {
|
||||
if (res.status !== 200) done(`Status code was ${res.status}`);
|
||||
else {
|
||||
const userNameInfo = await getUsernameInfo(getHash(user02PrivateUserID));
|
||||
if (userNameInfo.userName === newUsername) {
|
||||
done(`Username '${username02}' got changed to '${newUsername}'`);
|
||||
}
|
||||
else done();
|
||||
}
|
||||
assert.strictEqual(res.status, 200);
|
||||
const userNameInfo = await getUsernameInfo(getHash(user02PrivateUserID));
|
||||
assert.notStrictEqual(userNameInfo.userName, newUsername);
|
||||
done();
|
||||
})
|
||||
.catch(() => done(`couldn't call endpoint`));
|
||||
});
|
||||
|
@ -166,8 +150,8 @@ describe('setUsername', () => {
|
|||
})
|
||||
.then(async () => {
|
||||
const usernameInfo = await getUsernameInfo(getHash(user03PrivateUserID));
|
||||
if (usernameInfo.userName !== newUsername) done(`Username did not change`);
|
||||
if (usernameInfo.locked == "1") done(`Username was locked when it shouldn't have been`);
|
||||
assert.strictEqual(usernameInfo.userName, newUsername, "Username should change");
|
||||
assert.notStrictEqual(usernameInfo.locked, 1, "Username should not be locked");
|
||||
testUserNameChangelog(user03PrivateUserID, newUsername, username03, false, done);
|
||||
})
|
||||
.catch(() => done(`couldn't call endpoint`));
|
||||
|
@ -180,9 +164,9 @@ describe('setUsername', () => {
|
|||
})
|
||||
.then(async () => {
|
||||
const usernameInfo = await getUsernameInfo(getHash(user04PrivateUserID));
|
||||
if (usernameInfo.userName === newUsername) done(`Username '${username04}' got changed to '${usernameInfo}'`);
|
||||
if (usernameInfo.locked == "0") done(`Username was unlocked when it shouldn't have been`);
|
||||
else done();
|
||||
assert.notStrictEqual(usernameInfo.userName, newUsername, "Username should not be changed");
|
||||
assert.strictEqual(usernameInfo.locked, 1, "username should be locked");
|
||||
done();
|
||||
})
|
||||
.catch(() => done(`couldn't call endpoint`));
|
||||
});
|
||||
|
@ -194,7 +178,7 @@ describe('setUsername', () => {
|
|||
})
|
||||
.then(async () => {
|
||||
const usernameInfo = await getUsernameInfo(getHash(user05PrivateUserID));
|
||||
if (usernameInfo.userName === newUsername) done(`Username contains unicode control characters`);
|
||||
assert.notStrictEqual(usernameInfo.userName, newUsername, "Username should not contain control characters");
|
||||
testUserNameChangelog(user05PrivateUserID, wellFormatUserName(newUsername), username05, false, done);
|
||||
})
|
||||
.catch(() => done(`couldn't call endpoint`));
|
||||
|
@ -206,8 +190,8 @@ describe('setUsername', () => {
|
|||
method: 'POST',
|
||||
})
|
||||
.then(async res => {
|
||||
if (res.status !== 403) done(`Status code was ${res.status}`);
|
||||
else done();
|
||||
assert.strictEqual(res.status, 403);
|
||||
done();
|
||||
})
|
||||
.catch(() => done(`couldn't call endpoint`));
|
||||
});
|
||||
|
@ -219,9 +203,9 @@ describe('setUsername', () => {
|
|||
})
|
||||
.then(async () => {
|
||||
const usernameInfo = await getUsernameInfo(getHash(user06PrivateUserID));
|
||||
if (usernameInfo.userName !== newUsername) done(`Failed to change username from '${username06}' to '${newUsername}'`);
|
||||
if (usernameInfo.locked == "0") done(`Username was not locked`);
|
||||
else testUserNameChangelog(user06PrivateUserID, newUsername, username06, true, done);
|
||||
assert.strictEqual(usernameInfo.userName, newUsername, "username should be changed");
|
||||
assert.strictEqual(usernameInfo.locked, 1, "Username should be locked");
|
||||
testUserNameChangelog(user06PrivateUserID, newUsername, username06, true, done);
|
||||
})
|
||||
.catch(() => done(`couldn't call endpoint`));
|
||||
});
|
||||
|
@ -233,9 +217,9 @@ describe('setUsername', () => {
|
|||
})
|
||||
.then(async () => {
|
||||
const usernameInfo = await getUsernameInfo(getHash(user06PrivateUserID));
|
||||
if (usernameInfo.userName !== newUsername) done(`Failed to change username from '${username06}' to '${newUsername}'`);
|
||||
if (usernameInfo.locked == "0") done(`Username was unlocked when it shouldn't have been`);
|
||||
else testUserNameChangelog(user07PrivateUserID, newUsername, username07, true, done);
|
||||
assert.strictEqual(usernameInfo.userName, newUsername, "Username should be changed");
|
||||
assert.strictEqual(usernameInfo.locked, 1, "Username should be locked");
|
||||
testUserNameChangelog(user07PrivateUserID, newUsername, username07, true, done);
|
||||
})
|
||||
.catch(() => done(`couldn't call endpoint`));
|
||||
});
|
||||
|
|
|
@ -2,6 +2,7 @@ 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', () => {
|
||||
before(async () => {
|
||||
|
@ -28,19 +29,14 @@ describe('shadowBanUser', () => {
|
|||
method: 'POST'
|
||||
})
|
||||
.then(async res => {
|
||||
if (res.status !== 200) done("Status code was: " + res.status);
|
||||
else {
|
||||
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"]);
|
||||
|
||||
if (shadowRow && videoRow?.length === 3) {
|
||||
done();
|
||||
} else {
|
||||
done("Ban failed " + JSON.stringify(videoRow) + " " + JSON.stringify(shadowRow));
|
||||
}
|
||||
}
|
||||
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"]);
|
||||
assert.ok(shadowRow);
|
||||
assert.strictEqual(videoRow.length, 3);
|
||||
done();
|
||||
})
|
||||
.catch(() => done("Couldn't call endpoint"));
|
||||
.catch(err => done(err));
|
||||
});
|
||||
|
||||
it('Should be able to unban user without unhiding submissions', (done: Done) => {
|
||||
|
@ -48,19 +44,14 @@ describe('shadowBanUser', () => {
|
|||
method: 'POST'
|
||||
})
|
||||
.then(async res => {
|
||||
if (res.status !== 200) done("Status code was: " + res.status);
|
||||
else {
|
||||
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"]);
|
||||
|
||||
if (!shadowRow && videoRow?.length === 3) {
|
||||
done();
|
||||
} else {
|
||||
done("Unban failed " + JSON.stringify(videoRow) + " " + JSON.stringify(shadowRow));
|
||||
}
|
||||
}
|
||||
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"]);
|
||||
assert.ok(!shadowRow);
|
||||
assert.strictEqual(videoRow.length, 3);
|
||||
done();
|
||||
})
|
||||
.catch(() => done("Couldn't call endpoint"));
|
||||
.catch(err => done(err));
|
||||
});
|
||||
|
||||
it('Should be able to ban user and hide submissions from only some categories', (done: Done) => {
|
||||
|
@ -68,19 +59,15 @@ describe('shadowBanUser', () => {
|
|||
method: 'POST'
|
||||
})
|
||||
.then(async res => {
|
||||
if (res.status !== 200) done("Status code was: " + res.status);
|
||||
else {
|
||||
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"]);
|
||||
|
||||
if (shadowRow && 2 == videoRow?.length && 2 === videoRow?.filter((elem) => elem?.category === "sponsor")?.length) {
|
||||
done();
|
||||
} else {
|
||||
done("Ban failed " + JSON.stringify(videoRow) + " " + JSON.stringify(shadowRow));
|
||||
}
|
||||
}
|
||||
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"]);
|
||||
assert.ok(shadowRow);
|
||||
assert.strictEqual(videoRow.length, 2);
|
||||
assert.strictEqual(videoRow.filter((elem) => elem.category === "sponsor").length, 2);
|
||||
done();
|
||||
})
|
||||
.catch(() => done("Couldn't call endpoint"));
|
||||
.catch(err => done(err));
|
||||
});
|
||||
|
||||
it('Should be able to unban user and unhide submissions', (done: Done) => {
|
||||
|
@ -88,19 +75,14 @@ describe('shadowBanUser', () => {
|
|||
method: 'POST'
|
||||
})
|
||||
.then(async res => {
|
||||
if (res.status !== 200) done("Status code was: " + res.status);
|
||||
else {
|
||||
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"]);
|
||||
|
||||
if (!shadowRow && videoRow?.length === 0) {
|
||||
done();
|
||||
} else {
|
||||
done("Unban failed " + JSON.stringify(videoRow) + " " + JSON.stringify(shadowRow));
|
||||
}
|
||||
}
|
||||
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"]);
|
||||
assert.ok(!shadowRow);
|
||||
assert.strictEqual(videoRow?.length, 0);
|
||||
done();
|
||||
})
|
||||
.catch(() => done("Couldn't call endpoint"));
|
||||
.catch(err => done(err));
|
||||
});
|
||||
|
||||
it('Should be able to unban user and unhide some submissions', (done: Done) => {
|
||||
|
@ -108,19 +90,15 @@ describe('shadowBanUser', () => {
|
|||
method: 'POST'
|
||||
})
|
||||
.then(async res => {
|
||||
if (res.status !== 200) done("Status code was: " + res.status);
|
||||
else {
|
||||
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"]);
|
||||
|
||||
if (!shadowRow && videoRow?.length === 1 && videoRow[0]?.category === "intro") {
|
||||
done();
|
||||
} else {
|
||||
done("Unban failed " + JSON.stringify(videoRow) + " " + JSON.stringify(shadowRow));
|
||||
}
|
||||
}
|
||||
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"]);
|
||||
assert.ok(!shadowRow);
|
||||
assert.strictEqual(videoRow.length, 1);
|
||||
assert.strictEqual(videoRow[0].category, "intro");
|
||||
done();
|
||||
})
|
||||
.catch(() => done("Couldn't call endpoint"));
|
||||
.catch(err => done(err));
|
||||
});
|
||||
|
||||
});
|
||||
|
|
|
@ -2,6 +2,7 @@ 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', () => {
|
||||
before(async () => {
|
||||
|
@ -31,19 +32,10 @@ describe('unBan', () => {
|
|||
},
|
||||
})
|
||||
.then(async res => {
|
||||
if (res.status === 200) {
|
||||
const result = await db.prepare('all', 'SELECT * FROM "sponsorTimes" WHERE "videoID" = ? AND "userID" = ? AND "shadowHidden" = ?', ['unBan-videoID-0', 'testMan-unBan', 1]);
|
||||
if (result.length !== 0) {
|
||||
console.log(result);
|
||||
done("Expected 0 banned entrys in db, got " + result.length);
|
||||
} else {
|
||||
done();
|
||||
}
|
||||
} else {
|
||||
const body = await res.text();
|
||||
console.log(body);
|
||||
done("Status code was " + res.status);
|
||||
}
|
||||
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]);
|
||||
assert.strictEqual(result.length, 0);
|
||||
done();
|
||||
})
|
||||
.catch(err => done(err));
|
||||
});
|
||||
|
@ -56,19 +48,10 @@ describe('unBan', () => {
|
|||
},
|
||||
})
|
||||
.then(async res => {
|
||||
if (res.status === 200) {
|
||||
const result = await db.prepare('all', 'SELECT * FROM "sponsorTimes" WHERE "videoID" = ? AND "userID" = ? AND "shadowHidden" = ?', ['unBan-videoID-1', 'testWoman-unBan', 1]);
|
||||
if (result.length !== 1) {
|
||||
console.log(result);
|
||||
done("Expected 1 banned entry1 in db, got " + result.length);
|
||||
} else {
|
||||
done();
|
||||
}
|
||||
} else {
|
||||
const body = await res.text();
|
||||
console.log(body);
|
||||
done("Status code was " + res.status);
|
||||
}
|
||||
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]);
|
||||
assert.strictEqual(result.length, 1);
|
||||
done();
|
||||
})
|
||||
.catch(err => done(err));
|
||||
});
|
||||
|
@ -81,19 +64,10 @@ describe('unBan', () => {
|
|||
},
|
||||
})
|
||||
.then(async res => {
|
||||
if (res.status === 200) {
|
||||
const result = await db.prepare('all', 'SELECT * FROM "sponsorTimes" WHERE "userID" = ? AND "shadowHidden" = ?', ['testEntity-unBan', 1]);
|
||||
if (result.length !== 1) {
|
||||
console.log(result);
|
||||
done("Expected 1 banned entry1 in db, got " + result.length);
|
||||
} else {
|
||||
done();
|
||||
}
|
||||
} else {
|
||||
const body = await res.text();
|
||||
console.log(body);
|
||||
done("Status code was " + res.status);
|
||||
}
|
||||
assert.strictEqual(res.status, 200);
|
||||
const result = await db.prepare('all', 'SELECT * FROM "sponsorTimes" WHERE "userID" = ? AND "shadowHidden" = ?', ['testEntity-unBan', 1]);
|
||||
assert.strictEqual(result.length, 1);
|
||||
done();
|
||||
})
|
||||
.catch(err => done(err));
|
||||
});
|
||||
|
|
|
@ -6,6 +6,7 @@ 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');
|
||||
|
@ -66,16 +67,10 @@ describe('voteOnSponsorTime', () => {
|
|||
fetch(getbaseURL()
|
||||
+ "/api/voteOnSponsorTime?userID=randomID&UUID=vote-uuid-0&type=1")
|
||||
.then(async res => {
|
||||
if (res.status === 200) {
|
||||
const row = await db.prepare('get', `SELECT "votes" FROM "sponsorTimes" WHERE "UUID" = ?`, ["vote-uuid-0"]);
|
||||
if (row.votes === 3) {
|
||||
done();
|
||||
} else {
|
||||
done("Vote did not succeed. Submission went from 2 votes to " + row.votes);
|
||||
}
|
||||
} else {
|
||||
done("Status code was " + res.status);
|
||||
}
|
||||
assert.strictEqual(res.status, 200);
|
||||
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));
|
||||
});
|
||||
|
@ -84,16 +79,10 @@ describe('voteOnSponsorTime', () => {
|
|||
fetch(getbaseURL()
|
||||
+ "/api/voteOnSponsorTime?userID=randomID2&UUID=vote-uuid-2&type=0")
|
||||
.then(async res => {
|
||||
if (res.status === 200) {
|
||||
const row = await db.prepare('get', `SELECT "votes" FROM "sponsorTimes" WHERE "UUID" = ?`, ["vote-uuid-2"]);
|
||||
if (row.votes < 10) {
|
||||
done();
|
||||
} else {
|
||||
done("Vote did not succeed. Submission went from 10 votes to " + row.votes);
|
||||
}
|
||||
} else {
|
||||
done("Status code was " + res.status);
|
||||
}
|
||||
assert.strictEqual(res.status, 200);
|
||||
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));
|
||||
});
|
||||
|
@ -102,16 +91,10 @@ describe('voteOnSponsorTime', () => {
|
|||
fetch(getbaseURL()
|
||||
+ "/api/voteOnSponsorTime?userID=randomID3&UUID=vote-uuid-2&type=0")
|
||||
.then(async res => {
|
||||
if (res.status === 200) {
|
||||
const row = await db.prepare('get', `SELECT "votes" FROM "sponsorTimes" WHERE "UUID" = ?`, ["vote-uuid-2"]);
|
||||
if (row.votes === 9) {
|
||||
done();
|
||||
} else {
|
||||
done("Vote did not fail. Submission went from 9 votes to " + row.votes);
|
||||
}
|
||||
} else {
|
||||
done("Status code was " + res.status);
|
||||
}
|
||||
assert.strictEqual(res.status, 200);
|
||||
const row = await db.prepare('get', `SELECT "votes" FROM "sponsorTimes" WHERE "UUID" = ?`, ["vote-uuid-2"]);
|
||||
assert.strictEqual(row.votes, 9);
|
||||
done();
|
||||
})
|
||||
.catch(err => done(err));
|
||||
});
|
||||
|
@ -120,16 +103,10 @@ describe('voteOnSponsorTime', () => {
|
|||
fetch(getbaseURL()
|
||||
+ "/api/voteOnSponsorTime?userID=randomID4&UUID=vote-uuid-1.6&type=0")
|
||||
.then(async res => {
|
||||
if (res.status === 200) {
|
||||
const row = await db.prepare('get', `SELECT "votes" FROM "sponsorTimes" WHERE "UUID" = ?`, ["vote-uuid-1.6"]);
|
||||
if (row.votes === 10) {
|
||||
done();
|
||||
} else {
|
||||
done("Vote did not fail. Submission went from 10 votes to " + row.votes);
|
||||
}
|
||||
} else {
|
||||
done("Status code was " + res.status);
|
||||
}
|
||||
assert.strictEqual(res.status, 200);
|
||||
const row = await db.prepare('get', `SELECT "votes" FROM "sponsorTimes" WHERE "UUID" = ?`, ["vote-uuid-1.6"]);
|
||||
assert.strictEqual(row.votes, 10);
|
||||
done();
|
||||
})
|
||||
.catch(err => done(err));
|
||||
});
|
||||
|
@ -138,16 +115,10 @@ describe('voteOnSponsorTime', () => {
|
|||
fetch(getbaseURL()
|
||||
+ "/api/voteOnSponsorTime?userID=hasNotSubmittedID&UUID=vote-uuid-1&type=1")
|
||||
.then(async res => {
|
||||
if (res.status === 200) {
|
||||
const row = await db.prepare('get', `SELECT "votes" FROM "sponsorTimes" WHERE "UUID" = ?`, ["vote-uuid-1"]);
|
||||
if (row.votes === 2) {
|
||||
done();
|
||||
} else {
|
||||
done("Vote did not fail. Submission went from 2 votes to " + row.votes);
|
||||
}
|
||||
} else {
|
||||
done("Status code was " + res.status);
|
||||
}
|
||||
assert.strictEqual(res.status, 200);
|
||||
const row = await db.prepare('get', `SELECT "votes" FROM "sponsorTimes" WHERE "UUID" = ?`, ["vote-uuid-1"]);
|
||||
assert.strictEqual(row.votes, 2);
|
||||
done();
|
||||
})
|
||||
.catch(err => done(err));
|
||||
});
|
||||
|
@ -156,16 +127,10 @@ describe('voteOnSponsorTime', () => {
|
|||
fetch(getbaseURL()
|
||||
+ "/api/voteOnSponsorTime?userID=hasNotSubmittedID&UUID=vote-uuid-1.5&type=0")
|
||||
.then(async res => {
|
||||
if (res.status === 200) {
|
||||
const row = await db.prepare('get', `SELECT "votes" FROM "sponsorTimes" WHERE "UUID" = ?`, ["vote-uuid-1.5"]);
|
||||
if (row.votes === 10) {
|
||||
done();
|
||||
} else {
|
||||
done("Vote did not fail. Submission went from 10 votes to " + row.votes);
|
||||
}
|
||||
} else {
|
||||
done("Status code was " + res.status);
|
||||
}
|
||||
assert.strictEqual(res.status, 200);
|
||||
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));
|
||||
});
|
||||
|
@ -174,16 +139,10 @@ describe('voteOnSponsorTime', () => {
|
|||
fetch(getbaseURL()
|
||||
+ "/api/voteOnSponsorTime?userID=VIPUser&UUID=vote-uuid-3&type=0")
|
||||
.then(async res => {
|
||||
if (res.status === 200) {
|
||||
const row = await db.prepare('get', `SELECT "votes" FROM "sponsorTimes" WHERE "UUID" = ?`, ["vote-uuid-3"]);
|
||||
if (row.votes <= -2) {
|
||||
done();
|
||||
} else {
|
||||
done("Vote did not succeed. Submission went from 100 votes to " + row.votes);
|
||||
}
|
||||
} else {
|
||||
done("Status code was " + res.status);
|
||||
}
|
||||
assert.strictEqual(res.status, 200);
|
||||
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));
|
||||
});
|
||||
|
@ -192,16 +151,10 @@ describe('voteOnSponsorTime', () => {
|
|||
fetch(getbaseURL()
|
||||
+ "/api/voteOnSponsorTime?userID=own-submission-id&UUID=own-submission-uuid&type=0")
|
||||
.then(async res => {
|
||||
if (res.status === 200) {
|
||||
const row = await db.prepare('get', `SELECT "votes" FROM "sponsorTimes" WHERE "UUID" = ?`, ["own-submission-uuid"]);
|
||||
if (row.votes <= -2) {
|
||||
done();
|
||||
} else {
|
||||
done("Vote did not succeed. Submission went from 500 votes to " + row.votes);
|
||||
}
|
||||
} else {
|
||||
done("Status code was " + res.status);
|
||||
}
|
||||
assert.strictEqual(res.status, 200);
|
||||
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));
|
||||
});
|
||||
|
@ -210,16 +163,10 @@ describe('voteOnSponsorTime', () => {
|
|||
fetch(getbaseURL()
|
||||
+ "/api/voteOnSponsorTime?userID=randomID2&UUID=not-own-submission-uuid&type=0")
|
||||
.then(async res => {
|
||||
if (res.status === 200) {
|
||||
const row = await db.prepare('get', `SELECT "votes" FROM "sponsorTimes" WHERE "UUID" = ?`, ["not-own-submission-uuid"]);
|
||||
if (row.votes === 499) {
|
||||
done();
|
||||
} else {
|
||||
done("Vote did not succeed. Submission went from 500 votes to " + row.votes);
|
||||
}
|
||||
} else {
|
||||
done("Status code was " + res.status);
|
||||
}
|
||||
assert.strictEqual(res.status, 200);
|
||||
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));
|
||||
});
|
||||
|
@ -228,19 +175,16 @@ describe('voteOnSponsorTime', () => {
|
|||
fetch(getbaseURL()
|
||||
+ "/api/voteOnSponsorTime?userID=randomID2&UUID=vote-uuid-4&category=intro")
|
||||
.then(async res => {
|
||||
if (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"]);
|
||||
if (row.category === "sponsor" && categoryRows.length === 2
|
||||
&& categoryRows[0]?.votes === 1 && categoryRows[0]?.category === "intro"
|
||||
&& categoryRows[1]?.votes === 1 && categoryRows[1]?.category === "sponsor") {
|
||||
done();
|
||||
} else {
|
||||
done("Submission changed to " + row.category + " instead of staying as sponsor. Vote was applied as " + categoryRows[0]?.category + " with " + categoryRows[0]?.votes + " votes and there were " + categoryRows.length + " rows.");
|
||||
}
|
||||
} else {
|
||||
done("Status code was " + res.status);
|
||||
}
|
||||
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"]);
|
||||
assert.strictEqual(row.category, "sponsor");
|
||||
assert.strictEqual(categoryRows.length, 2);
|
||||
assert.strictEqual(categoryRows[0].votes, 1);
|
||||
assert.strictEqual(categoryRows[0].category, "intro");
|
||||
assert.strictEqual(categoryRows[1].votes, 1);
|
||||
assert.strictEqual(categoryRows[1].category, "sponsor");
|
||||
done();
|
||||
})
|
||||
.catch(err => done(err));
|
||||
});
|
||||
|
@ -249,16 +193,10 @@ describe('voteOnSponsorTime', () => {
|
|||
fetch(getbaseURL()
|
||||
+ "/api/voteOnSponsorTime?userID=randomID2&UUID=incorrect-category&category=fakecategory")
|
||||
.then(async res => {
|
||||
if (res.status === 400) {
|
||||
const row = await db.prepare('get', `SELECT "category" FROM "sponsorTimes" WHERE "UUID" = ?`, ["incorrect-category"]);
|
||||
if (row.category === "sponsor") {
|
||||
done();
|
||||
} else {
|
||||
done("Vote did not succeed. Submission went from sponsor to " + row.category);
|
||||
}
|
||||
} else {
|
||||
done("Status code was " + res.status);
|
||||
}
|
||||
assert.strictEqual(res.status, 400);
|
||||
const row = await db.prepare('get', `SELECT "category" FROM "sponsorTimes" WHERE "UUID" = ?`, ["incorrect-category"]);
|
||||
assert.strictEqual(row.category, "sponsor");
|
||||
done();
|
||||
})
|
||||
.catch(err => done(err));
|
||||
});
|
||||
|
@ -267,16 +205,10 @@ describe('voteOnSponsorTime', () => {
|
|||
fetch(getbaseURL()
|
||||
+ "/api/voteOnSponsorTime?userID=randomID2&UUID=incorrect-category&category=highlight")
|
||||
.then(async res => {
|
||||
if (res.status === 400) {
|
||||
const row = await db.prepare('get', `SELECT "category" FROM "sponsorTimes" WHERE "UUID" = ?`, ["incorrect-category"]);
|
||||
if (row.category === "sponsor") {
|
||||
done();
|
||||
} else {
|
||||
done("Vote did not succeed. Submission went from sponsor to " + row.category);
|
||||
}
|
||||
} else {
|
||||
done("Status code was " + res.status);
|
||||
}
|
||||
assert.strictEqual(res.status, 400);
|
||||
const row = await db.prepare('get', `SELECT "category" FROM "sponsorTimes" WHERE "UUID" = ?`, ["incorrect-category"]);
|
||||
assert.strictEqual(row.category, "sponsor");
|
||||
done();
|
||||
})
|
||||
.catch(err => done(err));
|
||||
});
|
||||
|
@ -296,13 +228,12 @@ describe('voteOnSponsorTime', () => {
|
|||
if (row?.category === "outro") outroVotes += row?.votes;
|
||||
if (row?.category === "sponsor") sponsorVotes += row?.votes;
|
||||
}
|
||||
if (submissionRow.category === "sponsor" && categoryRows.length === 3
|
||||
&& introVotes === 0 && outroVotes === 1 && sponsorVotes === 1) {
|
||||
done();
|
||||
} else {
|
||||
done("Submission changed to " + submissionRow.category + " instead of staying as sponsor. There were "
|
||||
+ introVotes + " intro votes, " + outroVotes + " outro votes and " + sponsorVotes + " sponsor votes.");
|
||||
}
|
||||
assert.strictEqual(submissionRow.category, "sponsor");
|
||||
assert.strictEqual(categoryRows.length, 3);
|
||||
assert.strictEqual(introVotes, 0);
|
||||
assert.strictEqual(outroVotes, 1);
|
||||
assert.strictEqual(sponsorVotes, 1);
|
||||
done();
|
||||
} else {
|
||||
done("Status code was " + res.status);
|
||||
}
|
||||
|
@ -317,11 +248,8 @@ describe('voteOnSponsorTime', () => {
|
|||
+ "/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"]);
|
||||
if (row.category === assertCat) {
|
||||
callback();
|
||||
} else {
|
||||
done("Vote did not succeed. Submission went from sponsor to " + row.category);
|
||||
}
|
||||
assert.strictEqual(row.category, assertCat);
|
||||
callback();
|
||||
})
|
||||
.catch(err => done(err));
|
||||
};
|
||||
|
@ -335,17 +263,12 @@ describe('voteOnSponsorTime', () => {
|
|||
fetch(getbaseURL()
|
||||
+ "/api/voteOnSponsorTime?userID=VIPUser&UUID=vote-uuid-5&category=outro")
|
||||
.then(async res => {
|
||||
if (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"]);
|
||||
if (row.category === "outro" && row2.votes === 500) {
|
||||
done();
|
||||
} else {
|
||||
done("Vote did not succeed. Submission went from intro to " + row.category + ". Category votes are " + row2.votes + " and should be 500.");
|
||||
}
|
||||
} else {
|
||||
done("Status code was " + res.status);
|
||||
}
|
||||
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"]);
|
||||
assert.strictEqual(row.category, "outro");
|
||||
assert.strictEqual(row2.votes, 500);
|
||||
done();
|
||||
})
|
||||
.catch(err => done(err));
|
||||
});
|
||||
|
@ -354,16 +277,10 @@ describe('voteOnSponsorTime', () => {
|
|||
fetch(getbaseURL()
|
||||
+ "/api/voteOnSponsorTime?userID=testman&UUID=vote-uuid-5_1&category=outro")
|
||||
.then(async res => {
|
||||
if (res.status === 200) {
|
||||
const row = await db.prepare('get', `SELECT "category" FROM "sponsorTimes" WHERE "UUID" = ?`, ["vote-uuid-5"]);
|
||||
if (row.category === "outro") {
|
||||
done();
|
||||
} else {
|
||||
done("Vote did not succeed. Submission went from intro to " + row.category + ".");
|
||||
}
|
||||
} else {
|
||||
done("Status code was " + res.status);
|
||||
}
|
||||
assert.strictEqual(res.status, 200);
|
||||
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));
|
||||
});
|
||||
|
@ -372,11 +289,8 @@ describe('voteOnSponsorTime', () => {
|
|||
fetch(getbaseURL()
|
||||
+ "/api/voteOnSponsorTime?userID=randomID3&UUID=invalid-uuid&category=intro")
|
||||
.then(async res => {
|
||||
if (res.status === 400) {
|
||||
done();
|
||||
} else {
|
||||
done("Status code was " + res.status + " instead of 400.");
|
||||
}
|
||||
assert.strictEqual(res.status, 400);
|
||||
done();
|
||||
})
|
||||
.catch(err => done(err));
|
||||
});
|
||||
|
@ -385,12 +299,10 @@ describe('voteOnSponsorTime', () => {
|
|||
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"]);
|
||||
if (res.status === 403 && row.votes === -3) {
|
||||
done();
|
||||
} else {
|
||||
done("Status code was " + res.status + ", row is " + JSON.stringify(row));
|
||||
}
|
||||
assert.strictEqual(row.votes, -3);
|
||||
done();
|
||||
})
|
||||
.catch(err => done(err));
|
||||
});
|
||||
|
@ -399,12 +311,10 @@ describe('voteOnSponsorTime', () => {
|
|||
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"]);
|
||||
if (res.status === 200 && row.votes === -3) {
|
||||
done();
|
||||
} else {
|
||||
done("Status code was " + res.status + ", row is " + JSON.stringify(row));
|
||||
}
|
||||
assert.strictEqual(row.votes, -3);
|
||||
done();
|
||||
})
|
||||
.catch(err => done(err));
|
||||
});
|
||||
|
@ -413,16 +323,10 @@ describe('voteOnSponsorTime', () => {
|
|||
fetch(getbaseURL()
|
||||
+ "/api/voteOnSponsorTime?userID=VIPUser&UUID=vote-uuid-5&type=1")
|
||||
.then(async res => {
|
||||
if (res.status === 200) {
|
||||
const row = await db.prepare('get', `SELECT "votes" FROM "sponsorTimes" WHERE "UUID" = ?`, ["vote-uuid-5"]);
|
||||
if (row.votes > -3) {
|
||||
done();
|
||||
} else {
|
||||
done("Vote did not succeed. Votes raised from -3 to " + row.votes);
|
||||
}
|
||||
} else {
|
||||
done("Status code was " + res.status);
|
||||
}
|
||||
assert.strictEqual(res.status, 200);
|
||||
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));
|
||||
});
|
||||
|
@ -431,11 +335,8 @@ describe('voteOnSponsorTime', () => {
|
|||
fetch(getbaseURL()
|
||||
+ "/api/voteOnSponsorTime?userID=warn-voteuser01&UUID=warnvote-uuid-0&type=1")
|
||||
.then(async res => {
|
||||
if (res.status === 403) {
|
||||
done(); // success
|
||||
} else {
|
||||
done("Status code was " + res.status);
|
||||
}
|
||||
assert.strictEqual(res.status, 403);
|
||||
done();
|
||||
})
|
||||
.catch(err => done(err));
|
||||
});
|
||||
|
@ -444,12 +345,10 @@ describe('voteOnSponsorTime', () => {
|
|||
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"]);
|
||||
if (res.status === 200 && row.votes === 2) {
|
||||
done();
|
||||
} else {
|
||||
done("Status code was " + res.status + " instead of 200, row was " + JSON.stringify(row));
|
||||
}
|
||||
assert.strictEqual(row.votes, 2);
|
||||
done();
|
||||
})
|
||||
.catch(err => done(err));
|
||||
});
|
||||
|
@ -458,12 +357,10 @@ describe('voteOnSponsorTime', () => {
|
|||
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"]);
|
||||
if (res.status === 200 && row.votes === 3) {
|
||||
done();
|
||||
} else {
|
||||
done("Status code was " + res.status + " instead of 403, row was " + JSON.stringify(row));
|
||||
}
|
||||
assert.strictEqual(row.votes, 3);
|
||||
done();
|
||||
})
|
||||
.catch(err => done(err));
|
||||
});
|
||||
|
@ -472,12 +369,10 @@ describe('voteOnSponsorTime', () => {
|
|||
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"]);
|
||||
if (res.status === 200 && row.category === "sponsor") {
|
||||
done();
|
||||
} else {
|
||||
done("Status code was " + res.status + " instead of 200, row was " + JSON.stringify(row));
|
||||
}
|
||||
assert.strictEqual(row.category, "sponsor");
|
||||
done();
|
||||
})
|
||||
.catch(err => done(err));
|
||||
});
|
||||
|
@ -486,16 +381,10 @@ describe('voteOnSponsorTime', () => {
|
|||
fetch(getbaseURL()
|
||||
+ "/api/voteOnSponsorTime?userID=VIPUser&UUID=segment-locking-uuid-1&type=1")
|
||||
.then(async res => {
|
||||
if (res.status === 200) {
|
||||
const row = await db.prepare('get', `SELECT "locked" FROM "sponsorTimes" WHERE "UUID" = ?`, ["segment-locking-uuid-1"]);
|
||||
if (row?.locked) {
|
||||
done();
|
||||
} else {
|
||||
done("Segment not locked");
|
||||
}
|
||||
} else {
|
||||
done("Status code was " + res.status + " instead of 200");
|
||||
}
|
||||
assert.strictEqual(res.status, 200);
|
||||
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));
|
||||
});
|
||||
|
@ -504,16 +393,10 @@ describe('voteOnSponsorTime', () => {
|
|||
fetch(getbaseURL()
|
||||
+ "/api/voteOnSponsorTime?userID=VIPUser&UUID=segment-locking-uuid-1&type=0")
|
||||
.then(async res => {
|
||||
if (res.status === 200) {
|
||||
const row = await db.prepare('get', `SELECT "locked" FROM "sponsorTimes" WHERE "UUID" = ?`, ["segment-locking-uuid-1"]);
|
||||
if (!row?.locked) {
|
||||
done();
|
||||
} else {
|
||||
done("Segment not locked");
|
||||
}
|
||||
} else {
|
||||
done("Status code was " + res.status + " instead of 200");
|
||||
}
|
||||
assert.strictEqual(res.status, 200);
|
||||
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));
|
||||
});
|
||||
|
@ -522,16 +405,10 @@ describe('voteOnSponsorTime', () => {
|
|||
fetch(getbaseURL()
|
||||
+ "/api/voteOnSponsorTime?userID=VIPUser&UUID=segment-hidden-uuid-1&type=1")
|
||||
.then(async res => {
|
||||
if (res.status === 200) {
|
||||
const row = await db.prepare('get', `SELECT "hidden" FROM "sponsorTimes" WHERE "UUID" = ?`, ["segment-hidden-uuid-1"]);
|
||||
if (!row?.hidden) {
|
||||
done();
|
||||
} else {
|
||||
done("Segment not unhidden");
|
||||
}
|
||||
} else {
|
||||
done("Status code was " + res.status + " instead of 200");
|
||||
}
|
||||
assert.strictEqual(res.status, 200);
|
||||
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));
|
||||
});
|
||||
|
@ -540,16 +417,10 @@ describe('voteOnSponsorTime', () => {
|
|||
fetch(getbaseURL()
|
||||
+ "/api/voteOnSponsorTime?userID=randomID2&UUID=vote-uuid-2&type=20")
|
||||
.then(async res => {
|
||||
if (res.status === 200) {
|
||||
const row = await db.prepare('get', `SELECT "votes" FROM "sponsorTimes" WHERE "UUID" = ?`, ["vote-uuid-2"]);
|
||||
if (row.votes === 10) {
|
||||
done();
|
||||
} else {
|
||||
done("Vote did not succeed. Submission went from 10 votes to " + row.votes);
|
||||
}
|
||||
} else {
|
||||
done("Status code was " + res.status);
|
||||
}
|
||||
assert.strictEqual(res.status, 200);
|
||||
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));
|
||||
});
|
||||
|
@ -557,19 +428,18 @@ describe('voteOnSponsorTime', () => {
|
|||
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 => {
|
||||
if (res.status !== 400) done('non 400 (' + res.status + ')');
|
||||
else done(); // pass
|
||||
assert.strictEqual(res.status, 400);
|
||||
done();
|
||||
})
|
||||
.catch(() => done('couldn\'t call endpoint'));
|
||||
.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")
|
||||
.then(res => {
|
||||
if (res.status !== 400) done('non 400 (' + res.status + ')');
|
||||
else done(); // pass
|
||||
assert.strictEqual(res.status, 400);
|
||||
done();
|
||||
})
|
||||
.catch(() => done('couldn\'t call endpoint'));
|
||||
.catch(err => done(err));
|
||||
});
|
||||
|
||||
});
|
||||
|
|
10
test/test.ts
10
test/test.ts
|
@ -12,9 +12,7 @@ import rateLimit from 'express-rate-limit';
|
|||
|
||||
async function init() {
|
||||
ImportMock.mockFunction(rateLimitMiddlewareModule, 'rateLimitMiddleware', rateLimit({
|
||||
skip: () => {
|
||||
return true;
|
||||
}
|
||||
skip: () => true
|
||||
}));
|
||||
|
||||
// delete old test database
|
||||
|
@ -35,10 +33,10 @@ async function init() {
|
|||
|
||||
// Add each .ts file to the mocha instance
|
||||
fs.readdirSync(testDir)
|
||||
.filter(function(file) {
|
||||
.filter((file) =>
|
||||
// Only keep the .ts files
|
||||
return file.substr(-3) === '.ts';
|
||||
})
|
||||
file.substr(-3) === '.ts'
|
||||
)
|
||||
.forEach(function(file) {
|
||||
mocha.addFile(
|
||||
path.join(testDir, file)
|
||||
|
|
Loading…
Reference in a new issue