From 0e53a4d7190f745b88eba2aa33dec1dbc36499f2 Mon Sep 17 00:00:00 2001 From: Tristan Date: Sat, 3 Aug 2024 09:17:34 +0200 Subject: [PATCH 01/27] feat: create migration --- databases/_upgrade_sponsorTimes_41.sql | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 databases/_upgrade_sponsorTimes_41.sql diff --git a/databases/_upgrade_sponsorTimes_41.sql b/databases/_upgrade_sponsorTimes_41.sql new file mode 100644 index 00000000..06f9f3e6 --- /dev/null +++ b/databases/_upgrade_sponsorTimes_41.sql @@ -0,0 +1,2 @@ +BEGIN TRANSACTION; +COMMIT; \ No newline at end of file From 8095eb748040ab3747b3355b2ea613e3899b3e3a Mon Sep 17 00:00:00 2001 From: Tristan Date: Sat, 3 Aug 2024 10:03:20 +0200 Subject: [PATCH 02/27] feat(vipUsers): impl createdAt --- DatabaseSchema.md | 1 + databases/_upgrade_sponsorTimes_41.sql | 3 +++ src/routes/addUserAsVIP.ts | 7 ++++++- 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/DatabaseSchema.md b/DatabaseSchema.md index adb19233..856e1780 100644 --- a/DatabaseSchema.md +++ b/DatabaseSchema.md @@ -24,6 +24,7 @@ | Name | Type | | | -- | :--: | -- | | userID | TEXT | not null, primary key | +| createdAt | INTEGER | not null | | index | field | | -- | :--: | diff --git a/databases/_upgrade_sponsorTimes_41.sql b/databases/_upgrade_sponsorTimes_41.sql index 06f9f3e6..ebf3d9b0 100644 --- a/databases/_upgrade_sponsorTimes_41.sql +++ b/databases/_upgrade_sponsorTimes_41.sql @@ -1,2 +1,5 @@ BEGIN TRANSACTION; + +-- vipUsers +ALTER TABLE "vipUsers" ADD "createdAt" INTEGER NOT NULL; COMMIT; \ No newline at end of file diff --git a/src/routes/addUserAsVIP.ts b/src/routes/addUserAsVIP.ts index ab6cd8e3..fee0877f 100644 --- a/src/routes/addUserAsVIP.ts +++ b/src/routes/addUserAsVIP.ts @@ -38,7 +38,12 @@ export async function addUserAsVIP(req: AddUserAsVIPRequest, res: Response): Pro try { if (enabled && !userIsVIP) { // add them to the vip list - await db.prepare("run", 'INSERT INTO "vipUsers" VALUES(?)', [userID]); + const currentTime = Date.now(); + await db.prepare( + "run", + 'INSERT INTO "vipUsers" ("userID", "createdAt") VALUES(?, ?)', + [userID, currentTime] + ); } if (!enabled && userIsVIP) { From 168127173c35b1a29ceebc11035ced70fb5a265d Mon Sep 17 00:00:00 2001 From: Tristan Date: Sat, 3 Aug 2024 10:08:17 +0200 Subject: [PATCH 03/27] feat(sponsorTimes): impl updatedAt --- DatabaseSchema.md | 1 + databases/_upgrade_sponsorTimes_41.sql | 4 ++++ src/routes/postSkipSegments.ts | 6 +++--- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/DatabaseSchema.md b/DatabaseSchema.md index 856e1780..abd0bf59 100644 --- a/DatabaseSchema.md +++ b/DatabaseSchema.md @@ -54,6 +54,7 @@ | hashedVideoID | TEXT | not null, default '', sha256 | | userAgent | TEXT | not null, default '' | | description | TEXT | not null, default '' | +| updatedAt | INTEGER | not null | | index | field | | -- | :--: | diff --git a/databases/_upgrade_sponsorTimes_41.sql b/databases/_upgrade_sponsorTimes_41.sql index ebf3d9b0..5d41bb3d 100644 --- a/databases/_upgrade_sponsorTimes_41.sql +++ b/databases/_upgrade_sponsorTimes_41.sql @@ -2,4 +2,8 @@ BEGIN TRANSACTION; -- vipUsers ALTER TABLE "vipUsers" ADD "createdAt" INTEGER NOT NULL; + +-- sponsorTimes +-- Don't create createdAt -> timeSubmitted field +ALTER TABLE "vipUsers" ADD "sponsorTimes" INTEGER NOT NULL; COMMIT; \ No newline at end of file diff --git a/src/routes/postSkipSegments.ts b/src/routes/postSkipSegments.ts index 217be5c9..befba55a 100644 --- a/src/routes/postSkipSegments.ts +++ b/src/routes/postSkipSegments.ts @@ -586,10 +586,10 @@ export async function postSkipSegments(req: Request, res: Response): Promise Date: Sat, 3 Aug 2024 10:11:42 +0200 Subject: [PATCH 04/27] feat(userNames): impl createdAt and updatedAt --- DatabaseSchema.md | 2 ++ databases/_upgrade_sponsorTimes_41.sql | 4 ++++ src/routes/setUsername.ts | 5 +++-- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/DatabaseSchema.md b/DatabaseSchema.md index abd0bf59..c3a5504b 100644 --- a/DatabaseSchema.md +++ b/DatabaseSchema.md @@ -73,6 +73,8 @@ | userID | TEXT | not null, primary key | | userName | TEXT | not null | | locked | INTEGER | not nul, default '0' | +| createdAt | INTEGER | not null | +| updatedAt | INTEGER | not null | | index | field | | -- | :--: | diff --git a/databases/_upgrade_sponsorTimes_41.sql b/databases/_upgrade_sponsorTimes_41.sql index 5d41bb3d..46168470 100644 --- a/databases/_upgrade_sponsorTimes_41.sql +++ b/databases/_upgrade_sponsorTimes_41.sql @@ -6,4 +6,8 @@ ALTER TABLE "vipUsers" ADD "createdAt" INTEGER NOT NULL; -- sponsorTimes -- Don't create createdAt -> timeSubmitted field ALTER TABLE "vipUsers" ADD "sponsorTimes" INTEGER NOT NULL; + +-- userNames +ALTER TABLE "userNames" ADD "createdAt" INTEGER NOT NULL; +ALTER TABLE "userNames" ADD "updatedAt" INTEGER NOT NULL; COMMIT; \ No newline at end of file diff --git a/src/routes/setUsername.ts b/src/routes/setUsername.ts index c7b189e5..9cbbaa39 100644 --- a/src/routes/setUsername.ts +++ b/src/routes/setUsername.ts @@ -79,6 +79,7 @@ export async function setUsername(req: Request, res: Response): Promise Date: Sat, 3 Aug 2024 10:19:13 +0200 Subject: [PATCH 05/27] feat(categoryVotes): impl createdAt and updatedAt --- DatabaseSchema.md | 2 ++ databases/_upgrade_sponsorTimes_41.sql | 4 ++++ src/routes/voteOnSponsorTime.ts | 4 ++-- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/DatabaseSchema.md b/DatabaseSchema.md index c3a5504b..95bdbc2d 100644 --- a/DatabaseSchema.md +++ b/DatabaseSchema.md @@ -88,6 +88,8 @@ | category | TEXT | not null | | votes | INTEGER | not null, default 0 | | id | SERIAL | primary key +| createdAt | INTEGER | not null | +| updatedAt | INTEGER | not null | | index | field | | -- | :--: | diff --git a/databases/_upgrade_sponsorTimes_41.sql b/databases/_upgrade_sponsorTimes_41.sql index 46168470..0c8bd70a 100644 --- a/databases/_upgrade_sponsorTimes_41.sql +++ b/databases/_upgrade_sponsorTimes_41.sql @@ -10,4 +10,8 @@ ALTER TABLE "vipUsers" ADD "sponsorTimes" INTEGER NOT NULL; -- userNames ALTER TABLE "userNames" ADD "createdAt" INTEGER NOT NULL; ALTER TABLE "userNames" ADD "updatedAt" INTEGER NOT NULL; + +-- categoryVotes +ALTER TABLE "categoryVotes" ADD "createdAt" INTEGER NOT NULL; +ALTER TABLE "categoryVotes" ADD "updatedAt" INTEGER NOT NULL; COMMIT; \ No newline at end of file diff --git a/src/routes/voteOnSponsorTime.ts b/src/routes/voteOnSponsorTime.ts index 22ed73f8..49628f12 100644 --- a/src/routes/voteOnSponsorTime.ts +++ b/src/routes/voteOnSponsorTime.ts @@ -248,10 +248,10 @@ async function categoryVote(UUID: SegmentUUID, userID: HashedUserID, isVIP: bool // Add the vote if ((await db.prepare("get", `select count(*) as count from "categoryVotes" where "UUID" = ? and category = ?`, [UUID, category])).count > 0) { // Update the already existing db entry - await db.prepare("run", `update "categoryVotes" set "votes" = "votes" + ? where "UUID" = ? and "category" = ?`, [voteAmount, UUID, category]); + await db.prepare("run", `update "categoryVotes" set "votes" = "votes" + ?, "updatedAt" = ? where "UUID" = ? and "category" = ?`, [voteAmount, timeSubmitted, UUID, category]); } else { // Add a db entry - await db.prepare("run", `insert into "categoryVotes" ("UUID", "category", "votes") values (?, ?, ?)`, [UUID, category, voteAmount]); + await db.prepare("run", `insert into "categoryVotes" ("UUID", "category", "votes", "createdAt", "updatedAt") values (?, ?, ?, ?, ?)`, [UUID, category, voteAmount]); } // Add the info into the private db From ebc3b2ce86ac79b0592457afc970699587ee41b9 Mon Sep 17 00:00:00 2001 From: Tristan Date: Sat, 3 Aug 2024 10:26:29 +0200 Subject: [PATCH 06/27] feat(lockCategories): impl updatedAt --- DatabaseSchema.md | 2 ++ databases/_upgrade_sponsorTimes_41.sql | 4 ++++ src/routes/postLockCategories.ts | 11 ++++++++--- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/DatabaseSchema.md b/DatabaseSchema.md index 95bdbc2d..e3b64afb 100644 --- a/DatabaseSchema.md +++ b/DatabaseSchema.md @@ -107,6 +107,8 @@ | reason | TEXT | not null, default '' | | service | TEXT | not null, default 'YouTube' | | id | SERIAL | primary key +| createdAt | INTEGER | not null | +| updatedAt | INTEGER | not null | | index | field | | -- | :--: | diff --git a/databases/_upgrade_sponsorTimes_41.sql b/databases/_upgrade_sponsorTimes_41.sql index 0c8bd70a..da799cbe 100644 --- a/databases/_upgrade_sponsorTimes_41.sql +++ b/databases/_upgrade_sponsorTimes_41.sql @@ -14,4 +14,8 @@ ALTER TABLE "userNames" ADD "updatedAt" INTEGER NOT NULL; -- categoryVotes ALTER TABLE "categoryVotes" ADD "createdAt" INTEGER NOT NULL; ALTER TABLE "categoryVotes" ADD "updatedAt" INTEGER NOT NULL; + +-- lockCategories +ALTER TABLE "lockCategories" ADD "createdAt" INTEGER NOT NULL; +ALTER TABLE "lockCategories" ADD "updatedAt" INTEGER NOT NULL; COMMIT; \ No newline at end of file diff --git a/src/routes/postLockCategories.ts b/src/routes/postLockCategories.ts index eea02579..e38a686c 100644 --- a/src/routes/postLockCategories.ts +++ b/src/routes/postLockCategories.ts @@ -61,11 +61,16 @@ export async function postLockCategories(req: Request, res: Response): Promise Date: Sat, 3 Aug 2024 10:41:41 +0200 Subject: [PATCH 07/27] fix(sponsorTimes): update updatedAt on updates --- src/routes/postPurgeAllSegments.ts | 3 ++- src/routes/postSegmentShift.ts | 5 +++-- src/routes/postSkipSegments.ts | 5 +++-- src/routes/shadowBanUser.ts | 5 +++-- src/routes/viewedVideoSponsorTime.ts | 3 ++- src/routes/voteOnSponsorTime.ts | 20 ++++++++++++-------- 6 files changed, 25 insertions(+), 16 deletions(-) diff --git a/src/routes/postPurgeAllSegments.ts b/src/routes/postPurgeAllSegments.ts index e837c657..382bf760 100644 --- a/src/routes/postPurgeAllSegments.ts +++ b/src/routes/postPurgeAllSegments.ts @@ -28,7 +28,8 @@ export async function postPurgeAllSegments(req: Request, res: Response): Promise }); } - await db.prepare("run", `UPDATE "sponsorTimes" SET "hidden" = 1 WHERE "videoID" = ?`, [videoID]); + const currentTime = Date.now(); + await db.prepare("run", `UPDATE "sponsorTimes" SET "hidden" = 1, "updatedAt" = ? WHERE "videoID" = ?`, [currentTime, videoID]); const hashedVideoID: VideoIDHash = await getHashCache(videoID, 1); QueryCacher.clearSegmentCache({ diff --git a/src/routes/postSegmentShift.ts b/src/routes/postSegmentShift.ts index fcf93269..ec330222 100644 --- a/src/routes/postSegmentShift.ts +++ b/src/routes/postSegmentShift.ts @@ -79,15 +79,16 @@ export async function postSegmentShift(req: Request, res: Response): Promise -2`, - [videoID, service, videoDuration]); + [currentTime, videoID, service, videoDuration]); lockedCategoryList = []; deleteLockCategories(videoID, null, null, service).catch((e) => Logger.error(`deleting lock categories: ${e}`)); diff --git a/src/routes/shadowBanUser.ts b/src/routes/shadowBanUser.ts index 93164a4e..64c6fd6f 100644 --- a/src/routes/shadowBanUser.ts +++ b/src/routes/shadowBanUser.ts @@ -93,11 +93,12 @@ export async function banUser(userID: UserID, enabled: boolean, unHideOldSubmiss async function unHideSubmissionsByUser(categories: string[], deArrowTypes: DeArrowType[], userID: UserID, type = 1) { + const currentTime = Date.now(); if (categories.length) { - await db.prepare("run", `UPDATE "sponsorTimes" SET "shadowHidden" = '${type}' WHERE "userID" = ? AND "category" in (${categories.map((c) => `'${c}'`).join(",")}) + await db.prepare("run", `UPDATE "sponsorTimes" SET "shadowHidden" = '${type}', "updatedAt = ? WHERE "userID" = ? AND "category" in (${categories.map((c) => `'${c}'`).join(",")}) AND NOT EXISTS ( SELECT "videoID", "category" FROM "lockCategories" WHERE - "sponsorTimes"."videoID" = "lockCategories"."videoID" AND "sponsorTimes"."service" = "lockCategories"."service" AND "sponsorTimes"."category" = "lockCategories"."category")`, [userID]); + "sponsorTimes"."videoID" = "lockCategories"."videoID" AND "sponsorTimes"."service" = "lockCategories"."service" AND "sponsorTimes"."category" = "lockCategories"."category")`, [currentTime, userID]); } // clear cache for all old videos diff --git a/src/routes/viewedVideoSponsorTime.ts b/src/routes/viewedVideoSponsorTime.ts index 168a92dc..4abff224 100644 --- a/src/routes/viewedVideoSponsorTime.ts +++ b/src/routes/viewedVideoSponsorTime.ts @@ -3,6 +3,7 @@ import { Request, Response } from "express"; export async function viewedVideoSponsorTime(req: Request, res: Response): Promise { const UUID = req.query?.UUID; + const currentTime = Date.now(); if (!UUID) { //invalid request @@ -10,7 +11,7 @@ export async function viewedVideoSponsorTime(req: Request, res: Response): Promi } //up the view count by one - await db.prepare("run", `UPDATE "sponsorTimes" SET views = views + 1 WHERE "UUID" = ?`, [UUID]); + await db.prepare("run", `UPDATE "sponsorTimes" SET views = views + 1, "updatedAt" = ? WHERE "UUID" = ?`, [currentTime, UUID]); return res.sendStatus(200); } diff --git a/src/routes/voteOnSponsorTime.ts b/src/routes/voteOnSponsorTime.ts index 49628f12..600cf495 100644 --- a/src/routes/voteOnSponsorTime.ts +++ b/src/routes/voteOnSponsorTime.ts @@ -65,9 +65,10 @@ async function updateSegmentVideoDuration(UUID: SegmentUUID) { apiVideoDetails = await getVideoDetails(videoID, true); } const apiVideoDuration = apiVideoDetails?.duration as VideoDuration; + const currentTime = Date.now(); if (videoDurationChanged(videoDuration, apiVideoDuration)) { Logger.info(`Video duration changed for ${videoID} from ${videoDuration} to ${apiVideoDuration}`); - await db.prepare("run", `UPDATE "sponsorTimes" SET "videoDuration" = ? WHERE "UUID" = ?`, [apiVideoDuration, UUID]); + await db.prepare("run", `UPDATE "sponsorTimes" SET "videoDuration" = ?, "updatedAt" ? WHERE "UUID" = ?`, [apiVideoDuration, currentTime, UUID]); } } @@ -91,13 +92,14 @@ async function checkVideoDuration(UUID: SegmentUUID) { ORDER BY "timeSubmitted" DESC LIMIT 1`, [videoID, service]) as {videoDuration: VideoDuration, UUID: SegmentUUID, timeSubmitted: number}; + const currentTime = Date.now(); if (latestSubmission && videoDurationChanged(latestSubmission.videoDuration, apiVideoDuration)) { Logger.info(`Video duration changed for ${videoID} from ${latestSubmission.videoDuration} to ${apiVideoDuration}`); - await db.prepare("run", `UPDATE "sponsorTimes" SET "hidden" = 1 + await db.prepare("run", `UPDATE "sponsorTimes" SET "hidden" = 1, "updatedAt" = ? WHERE "videoID" = ? AND "service" = ? AND "timeSubmitted" <= ? AND "hidden" = 0 AND "shadowHidden" = 0 AND "actionType" != 'full' AND "votes" > -2`, - [videoID, service, latestSubmission.timeSubmitted]); + [currentTime, videoID, service, latestSubmission.timeSubmitted]); deleteLockCategories(videoID, null, null, service).catch((e) => Logger.error(`delete lock categories after vote: ${e}`)); } } @@ -287,7 +289,7 @@ async function categoryVote(UUID: SegmentUUID, userID: HashedUserID, isVIP: bool // VIPs change it every time if (isVIP || isTempVIP || isOwnSubmission || nextCategoryCount - currentCategoryCount >= Math.max(Math.ceil(submissionInfo?.votes / 2), 2)) { // Replace the category - await db.prepare("run", `update "sponsorTimes" set "category" = ? where "UUID" = ?`, [category, UUID]); + await db.prepare("run", `update "sponsorTimes" set "category" = ?, "updatedAt" = ? where "UUID" = ?`, [category, timeSubmitted, UUID]); } } QueryCacher.clearSegmentCache(segmentInfo); @@ -510,12 +512,14 @@ export async function vote(ip: IPAddress, UUID: SegmentUUID, paramUserID: UserID await privateDB.prepare("run", `INSERT INTO "votes" ("UUID", "userID", "hashedIP", "type", "normalUserID", "originalType") VALUES(?, ?, ?, ?, ?, ?)`, [UUID, userID, hashedIP, type, nonAnonUserID, originalType]); } + const currentTime = Date.now(); + // update the vote count on this sponsorTime - await db.prepare("run", `UPDATE "sponsorTimes" SET "votes" = "votes" + ? WHERE "UUID" = ?`, [incrementAmount - oldIncrementAmount, UUID]); + await db.prepare("run", `UPDATE "sponsorTimes" SET "votes" = "votes" + ?, "updatedAt" = ? WHERE "UUID" = ?`, [incrementAmount - oldIncrementAmount, currentTime, UUID]); // tempVIP can bring back hidden segments if (isTempVIP && incrementAmount > 0 && voteTypeEnum === voteTypes.normal) { - await db.prepare("run", `UPDATE "sponsorTimes" SET "hidden" = 0 WHERE "UUID" = ?`, [UUID]); + await db.prepare("run", `UPDATE "sponsorTimes" SET "hidden" = 0, "updatedAt" = ? WHERE "UUID" = ?`, [currentTime, UUID]); } // additional processing for VIP // on VIP upvote @@ -523,10 +527,10 @@ export async function vote(ip: IPAddress, UUID: SegmentUUID, paramUserID: UserID // Update video duration in case that caused it to be hidden await updateSegmentVideoDuration(UUID); // unhide & unlock - await db.prepare("run", 'UPDATE "sponsorTimes" SET "locked" = 1, "hidden" = 0, "shadowHidden" = 0 WHERE "UUID" = ?', [UUID]); + await db.prepare("run", 'UPDATE "sponsorTimes" SET "locked" = 1, "hidden" = 0, "shadowHidden" = 0, "updatedAt" = ? WHERE "UUID" = ?', [currentTime, UUID]); // on VIP downvote/ undovote, also unlock submission } else if (isVIP && incrementAmount <= 0 && voteTypeEnum === voteTypes.normal) { - await db.prepare("run", 'UPDATE "sponsorTimes" SET "locked" = 0 WHERE "UUID" = ?', [UUID]); + await db.prepare("run", 'UPDATE "sponsorTimes" SET "locked" = 0, "updatedAt" = ? WHERE "UUID" = ?', [currentTime, UUID]); } QueryCacher.clearSegmentCache(segmentInfo); From 0faffa0add2c607758b749e31c4480d1af20c755 Mon Sep 17 00:00:00 2001 From: Tristan Date: Sat, 3 Aug 2024 11:07:59 +0200 Subject: [PATCH 08/27] feat(titleVotes): impl createdAt and updatedAt --- DatabaseSchema.md | 2 ++ databases/_upgrade_sponsorTimes_41.sql | 4 ++++ src/routes/postBranding.ts | 9 +++++---- src/routes/shadowBanUser.ts | 4 ++-- 4 files changed, 13 insertions(+), 6 deletions(-) diff --git a/DatabaseSchema.md b/DatabaseSchema.md index e3b64afb..29b4c9bc 100644 --- a/DatabaseSchema.md +++ b/DatabaseSchema.md @@ -272,6 +272,8 @@ | verification | INTEGER | default 0 | | downvotes | INTEGER | default 0 | | removed | INTEGER | default 0 | +| createdAt | INTEGER | not null | +| updatedAt | INTEGER | not null | | constraint | field | | -- | :--: | diff --git a/databases/_upgrade_sponsorTimes_41.sql b/databases/_upgrade_sponsorTimes_41.sql index da799cbe..6a034159 100644 --- a/databases/_upgrade_sponsorTimes_41.sql +++ b/databases/_upgrade_sponsorTimes_41.sql @@ -18,4 +18,8 @@ ALTER TABLE "categoryVotes" ADD "updatedAt" INTEGER NOT NULL; -- lockCategories ALTER TABLE "lockCategories" ADD "createdAt" INTEGER NOT NULL; ALTER TABLE "lockCategories" ADD "updatedAt" INTEGER NOT NULL; + +-- titleVotes +ALTER TABLE "titleVotes" ADD "createdAt" INTEGER NOT NULL; +ALTER TABLE "titleVotes" ADD "updatedAt" INTEGER NOT NULL; COMMIT; \ No newline at end of file diff --git a/src/routes/postBranding.ts b/src/routes/postBranding.ts index 80357160..4098bbb6 100644 --- a/src/routes/postBranding.ts +++ b/src/routes/postBranding.ts @@ -104,15 +104,15 @@ export async function postBranding(req: Request, res: Response) { [videoID, title.title, title.original ? 1 : 0, hashedUserID, service, hashedVideoID, now, UUID]); const verificationValue = await getVerificationValue(hashedUserID, isVip); - await db.prepare("run", `INSERT INTO "titleVotes" ("UUID", "votes", "locked", "shadowHidden", "verification") VALUES (?, 0, ?, ?, ?);`, - [UUID, shouldLock ? 1 : 0, isBanned ? 1 : 0, verificationValue]); + await db.prepare("run", `INSERT INTO "titleVotes" ("UUID", "votes", "locked", "shadowHidden", "verification", "createdAt", "updatedAt") VALUES (?, 0, ?, ?, ?, ?, ?);`, + [UUID, shouldLock ? 1 : 0, isBanned ? 1 : 0, verificationValue, now, now]); await verifyOldSubmissions(hashedUserID, verificationValue); } if (isVip && !downvote && shouldLock) { // unlock all other titles - await db.prepare("run", `UPDATE "titleVotes" as tv SET "locked" = 0 FROM "titles" t WHERE tv."UUID" = t."UUID" AND tv."UUID" != ? AND t."videoID" = ?`, [UUID, videoID]); + await db.prepare("run", `UPDATE "titleVotes" as tv SET "locked" = 0, "updatedAt" = ? FROM "titles" t WHERE tv."UUID" = t."UUID" AND tv."UUID" != ? AND t."videoID" = ?`, [now, UUID, videoID]); } sendWebhooks(videoID, UUID, voteType).catch((e) => Logger.error(e)); @@ -294,7 +294,8 @@ export async function verifyOldSubmissions(hashedUserID: HashedUserID, verificat }); } - await db.prepare("run", `UPDATE "titleVotes" as tv SET "verification" = ? FROM "titles" WHERE "titles"."UUID" = tv."UUID" AND "titles"."userID" = ? AND tv."verification" < ?`, [verification, hashedUserID, verification]); + const currentTime = Date.now(); + await db.prepare("run", `UPDATE "titleVotes" as tv SET "verification" = ?, "updatedAt" = ? FROM "titles" WHERE "titles"."UUID" = tv."UUID" AND "titles"."userID" = ? AND tv."verification" < ?`, [verification, currentTime, hashedUserID, verification]); } } } diff --git a/src/routes/shadowBanUser.ts b/src/routes/shadowBanUser.ts index 64c6fd6f..d776398a 100644 --- a/src/routes/shadowBanUser.ts +++ b/src/routes/shadowBanUser.ts @@ -108,8 +108,8 @@ async function unHideSubmissionsByUser(categories: string[], deArrowTypes: DeArr }); if (deArrowTypes.includes("title")) { - await db.prepare("run", `UPDATE "titleVotes" as tv SET "shadowHidden" = ${type} FROM "titles" t WHERE tv."UUID" = t."UUID" AND t."userID" = ?`, - [userID]); + await db.prepare("run", `UPDATE "titleVotes" as tv SET "shadowHidden" = ${type}, "updatedAt" = ? FROM "titles" t WHERE tv."UUID" = t."UUID" AND t."userID" = ?`, + [currentTime, userID]); } if (deArrowTypes.includes("thumbnail")) { From 3c6855c41de029f271cdb995e41fb77871c446c9 Mon Sep 17 00:00:00 2001 From: Tristan Date: Sat, 3 Aug 2024 11:09:27 +0200 Subject: [PATCH 09/27] fix(sponsorTimes): fix migration --- databases/_upgrade_sponsorTimes_41.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/databases/_upgrade_sponsorTimes_41.sql b/databases/_upgrade_sponsorTimes_41.sql index 6a034159..e6ee91b1 100644 --- a/databases/_upgrade_sponsorTimes_41.sql +++ b/databases/_upgrade_sponsorTimes_41.sql @@ -5,7 +5,7 @@ ALTER TABLE "vipUsers" ADD "createdAt" INTEGER NOT NULL; -- sponsorTimes -- Don't create createdAt -> timeSubmitted field -ALTER TABLE "vipUsers" ADD "sponsorTimes" INTEGER NOT NULL; +ALTER TABLE "sponsorTimes" ADD "updatedAt" INTEGER NOT NULL; -- userNames ALTER TABLE "userNames" ADD "createdAt" INTEGER NOT NULL; From 484fa9f31368a9e5e28c9be351e50f49163f502c Mon Sep 17 00:00:00 2001 From: Tristan Date: Sat, 3 Aug 2024 11:10:32 +0200 Subject: [PATCH 10/27] fix: update config version --- databases/_upgrade_sponsorTimes_41.sql | 3 +++ 1 file changed, 3 insertions(+) diff --git a/databases/_upgrade_sponsorTimes_41.sql b/databases/_upgrade_sponsorTimes_41.sql index e6ee91b1..8b35233c 100644 --- a/databases/_upgrade_sponsorTimes_41.sql +++ b/databases/_upgrade_sponsorTimes_41.sql @@ -22,4 +22,7 @@ ALTER TABLE "lockCategories" ADD "updatedAt" INTEGER NOT NULL; -- titleVotes ALTER TABLE "titleVotes" ADD "createdAt" INTEGER NOT NULL; ALTER TABLE "titleVotes" ADD "updatedAt" INTEGER NOT NULL; + +UPDATE "config" SET value = 41 WHERE key = 'version'; + COMMIT; \ No newline at end of file From dad8e63f88a13588130c5ba17d898d0366fa498d Mon Sep 17 00:00:00 2001 From: Tristan Date: Sat, 3 Aug 2024 11:13:00 +0200 Subject: [PATCH 11/27] feat(thumbnailVotes): impl updatedAt --- DatabaseSchema.md | 2 ++ databases/_upgrade_sponsorTimes_41.sql | 4 ++++ src/routes/postBranding.ts | 6 +++--- src/routes/shadowBanUser.ts | 4 ++-- 4 files changed, 11 insertions(+), 5 deletions(-) diff --git a/DatabaseSchema.md b/DatabaseSchema.md index 29b4c9bc..5752a532 100644 --- a/DatabaseSchema.md +++ b/DatabaseSchema.md @@ -322,6 +322,8 @@ | shadowHidden | INTEGER | not null, default 0 | | downvotes | INTEGER | default 0 | | removed | INTEGER | default 0 | +| createdAt | INTEGER | not null | +| updatedAt | INTEGER | not null | | constraint | field | | -- | :--: | diff --git a/databases/_upgrade_sponsorTimes_41.sql b/databases/_upgrade_sponsorTimes_41.sql index 8b35233c..3e62b4b8 100644 --- a/databases/_upgrade_sponsorTimes_41.sql +++ b/databases/_upgrade_sponsorTimes_41.sql @@ -23,6 +23,10 @@ ALTER TABLE "lockCategories" ADD "updatedAt" INTEGER NOT NULL; ALTER TABLE "titleVotes" ADD "createdAt" INTEGER NOT NULL; ALTER TABLE "titleVotes" ADD "updatedAt" INTEGER NOT NULL; +-- thumbnailVotes +ALTER TABLE "thumbnailVotes" ADD "createdAt" INTEGER NOT NULL; +ALTER TABLE "thumbnailVotes" ADD "updatedAt" INTEGER NOT NULL; + UPDATE "config" SET value = 41 WHERE key = 'version'; COMMIT; \ No newline at end of file diff --git a/src/routes/postBranding.ts b/src/routes/postBranding.ts index 4098bbb6..19c86396 100644 --- a/src/routes/postBranding.ts +++ b/src/routes/postBranding.ts @@ -145,8 +145,8 @@ export async function postBranding(req: Request, res: Response) { await db.prepare("run", `INSERT INTO "thumbnails" ("videoID", "original", "userID", "service", "hashedVideoID", "timeSubmitted", "UUID") VALUES (?, ?, ?, ?, ?, ?, ?)`, [videoID, thumbnail.original ? 1 : 0, hashedUserID, service, hashedVideoID, now, UUID]); - await db.prepare("run", `INSERT INTO "thumbnailVotes" ("UUID", "votes", "locked", "shadowHidden") VALUES (?, 0, ?, ?)`, - [UUID, shouldLock ? 1 : 0, isBanned ? 1 : 0]); + await db.prepare("run", `INSERT INTO "thumbnailVotes" ("UUID", "votes", "locked", "shadowHidden", "createdAt", "updatedAt") VALUES (?, 0, ?, ?, ?, ?)`, + [UUID, shouldLock ? 1 : 0, isBanned ? 1 : 0, now, now]); if (!thumbnail.original) { await db.prepare("run", `INSERT INTO "thumbnailTimestamps" ("UUID", "timestamp") VALUES (?, ?)`, @@ -156,7 +156,7 @@ export async function postBranding(req: Request, res: Response) { if (isVip && !downvote && shouldLock) { // unlock all other titles - await db.prepare("run", `UPDATE "thumbnailVotes" as tv SET "locked" = 0 FROM "thumbnails" t WHERE tv."UUID" = t."UUID" AND tv."UUID" != ? AND t."videoID" = ?`, [UUID, videoID]); + await db.prepare("run", `UPDATE "thumbnailVotes" as tv SET "locked" = 0, "updatedAt" = ? FROM "thumbnails" t WHERE tv."UUID" = t."UUID" AND tv."UUID" != ? AND t."videoID" = ?`, [now, UUID, videoID]); } } })()]); diff --git a/src/routes/shadowBanUser.ts b/src/routes/shadowBanUser.ts index d776398a..a52a0fb7 100644 --- a/src/routes/shadowBanUser.ts +++ b/src/routes/shadowBanUser.ts @@ -113,8 +113,8 @@ async function unHideSubmissionsByUser(categories: string[], deArrowTypes: DeArr } if (deArrowTypes.includes("thumbnail")) { - await db.prepare("run", `UPDATE "thumbnailVotes" as tv SET "shadowHidden" = ${type} FROM "thumbnails" t WHERE tv."UUID" = t."UUID" AND t."userID" = ?`, - [userID]); + await db.prepare("run", `UPDATE "thumbnailVotes" as tv SET "shadowHidden" = ${type}, "updatedAt" = ? FROM "thumbnails" t WHERE tv."UUID" = t."UUID" AND t."userID" = ?`, + [currentTime, userID]); } (await db.prepare("all", `SELECT "videoID", "hashedVideoID", "service" FROM "titles" WHERE "userID" = ?`, [userID])) From 6530484bdeec12c629b5977437e3187e71e9b3ba Mon Sep 17 00:00:00 2001 From: Tristan Date: Mon, 19 Aug 2024 22:12:11 +0200 Subject: [PATCH 12/27] feat(vipUsers): change timestamps to ISO 8601 --- databases/_upgrade_sponsorTimes_41.sql | 2 +- src/routes/addUserAsVIP.ts | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/databases/_upgrade_sponsorTimes_41.sql b/databases/_upgrade_sponsorTimes_41.sql index 3e62b4b8..6153430d 100644 --- a/databases/_upgrade_sponsorTimes_41.sql +++ b/databases/_upgrade_sponsorTimes_41.sql @@ -1,7 +1,7 @@ BEGIN TRANSACTION; -- vipUsers -ALTER TABLE "vipUsers" ADD "createdAt" INTEGER NOT NULL; +ALTER TABLE "vipUsers" ADD "createdAt" TEXT NOT NULL; -- sponsorTimes -- Don't create createdAt -> timeSubmitted field diff --git a/src/routes/addUserAsVIP.ts b/src/routes/addUserAsVIP.ts index fee0877f..12025e71 100644 --- a/src/routes/addUserAsVIP.ts +++ b/src/routes/addUserAsVIP.ts @@ -38,11 +38,11 @@ export async function addUserAsVIP(req: AddUserAsVIPRequest, res: Response): Pro try { if (enabled && !userIsVIP) { // add them to the vip list - const currentTime = Date.now(); + const isoTimestamp = new Date().toISOString(); await db.prepare( "run", 'INSERT INTO "vipUsers" ("userID", "createdAt") VALUES(?, ?)', - [userID, currentTime] + [userID, isoTimestamp] ); } From 2ea44c952e183a83d554594668c1695362b351ee Mon Sep 17 00:00:00 2001 From: Tristan Date: Mon, 19 Aug 2024 22:14:17 +0200 Subject: [PATCH 13/27] feat(sponsorTimes): change timestamps to ISO 8601 --- databases/_upgrade_sponsorTimes_41.sql | 2 +- src/routes/postPurgeAllSegments.ts | 4 ++-- src/routes/postSegmentShift.ts | 6 +++--- src/routes/postSkipSegments.ts | 8 +++++--- src/routes/shadowBanUser.ts | 4 ++-- src/routes/viewedVideoSponsorTime.ts | 4 ++-- src/routes/voteOnSponsorTime.ts | 21 +++++++++++---------- 7 files changed, 26 insertions(+), 23 deletions(-) diff --git a/databases/_upgrade_sponsorTimes_41.sql b/databases/_upgrade_sponsorTimes_41.sql index 6153430d..6d85cf8a 100644 --- a/databases/_upgrade_sponsorTimes_41.sql +++ b/databases/_upgrade_sponsorTimes_41.sql @@ -5,7 +5,7 @@ ALTER TABLE "vipUsers" ADD "createdAt" TEXT NOT NULL; -- sponsorTimes -- Don't create createdAt -> timeSubmitted field -ALTER TABLE "sponsorTimes" ADD "updatedAt" INTEGER NOT NULL; +ALTER TABLE "sponsorTimes" ADD "updatedAt" TEXT NOT NULL; -- userNames ALTER TABLE "userNames" ADD "createdAt" INTEGER NOT NULL; diff --git a/src/routes/postPurgeAllSegments.ts b/src/routes/postPurgeAllSegments.ts index 382bf760..9d3f6d88 100644 --- a/src/routes/postPurgeAllSegments.ts +++ b/src/routes/postPurgeAllSegments.ts @@ -28,8 +28,8 @@ export async function postPurgeAllSegments(req: Request, res: Response): Promise }); } - const currentTime = Date.now(); - await db.prepare("run", `UPDATE "sponsorTimes" SET "hidden" = 1, "updatedAt" = ? WHERE "videoID" = ?`, [currentTime, videoID]); + const isoTimestamp = new Date().toISOString(); + await db.prepare("run", `UPDATE "sponsorTimes" SET "hidden" = 1, "updatedAt" = ? WHERE "videoID" = ?`, [isoTimestamp, videoID]); const hashedVideoID: VideoIDHash = await getHashCache(videoID, 1); QueryCacher.clearSegmentCache({ diff --git a/src/routes/postSegmentShift.ts b/src/routes/postSegmentShift.ts index ec330222..7f207ea4 100644 --- a/src/routes/postSegmentShift.ts +++ b/src/routes/postSegmentShift.ts @@ -79,16 +79,16 @@ export async function postSegmentShift(req: Request, res: Response): Promise -2`, - [currentTime, videoID, service, videoDuration]); + [isoTimestamp, videoID, service, videoDuration]); lockedCategoryList = []; deleteLockCategories(videoID, null, null, service).catch((e) => Logger.error(`deleting lock categories: ${e}`)); @@ -559,6 +560,7 @@ export async function postSkipSegments(req: Request, res: Response): Promise `'${c}'`).join(",")}) AND NOT EXISTS ( SELECT "videoID", "category" FROM "lockCategories" WHERE - "sponsorTimes"."videoID" = "lockCategories"."videoID" AND "sponsorTimes"."service" = "lockCategories"."service" AND "sponsorTimes"."category" = "lockCategories"."category")`, [currentTime, userID]); + "sponsorTimes"."videoID" = "lockCategories"."videoID" AND "sponsorTimes"."service" = "lockCategories"."service" AND "sponsorTimes"."category" = "lockCategories"."category")`, [isoTimestamp, userID]); } // clear cache for all old videos diff --git a/src/routes/viewedVideoSponsorTime.ts b/src/routes/viewedVideoSponsorTime.ts index 4abff224..431e82b3 100644 --- a/src/routes/viewedVideoSponsorTime.ts +++ b/src/routes/viewedVideoSponsorTime.ts @@ -3,7 +3,7 @@ import { Request, Response } from "express"; export async function viewedVideoSponsorTime(req: Request, res: Response): Promise { const UUID = req.query?.UUID; - const currentTime = Date.now(); + const isoTimestamp = new Date().toISOString(); if (!UUID) { //invalid request @@ -11,7 +11,7 @@ export async function viewedVideoSponsorTime(req: Request, res: Response): Promi } //up the view count by one - await db.prepare("run", `UPDATE "sponsorTimes" SET views = views + 1, "updatedAt" = ? WHERE "UUID" = ?`, [currentTime, UUID]); + await db.prepare("run", `UPDATE "sponsorTimes" SET views = views + 1, "updatedAt" = ? WHERE "UUID" = ?`, [isoTimestamp, UUID]); return res.sendStatus(200); } diff --git a/src/routes/voteOnSponsorTime.ts b/src/routes/voteOnSponsorTime.ts index 600cf495..846df378 100644 --- a/src/routes/voteOnSponsorTime.ts +++ b/src/routes/voteOnSponsorTime.ts @@ -65,10 +65,10 @@ async function updateSegmentVideoDuration(UUID: SegmentUUID) { apiVideoDetails = await getVideoDetails(videoID, true); } const apiVideoDuration = apiVideoDetails?.duration as VideoDuration; - const currentTime = Date.now(); + const isoTimestamp = new Date().toISOString(); if (videoDurationChanged(videoDuration, apiVideoDuration)) { Logger.info(`Video duration changed for ${videoID} from ${videoDuration} to ${apiVideoDuration}`); - await db.prepare("run", `UPDATE "sponsorTimes" SET "videoDuration" = ?, "updatedAt" ? WHERE "UUID" = ?`, [apiVideoDuration, currentTime, UUID]); + await db.prepare("run", `UPDATE "sponsorTimes" SET "videoDuration" = ?, "updatedAt" ? WHERE "UUID" = ?`, [apiVideoDuration, isoTimestamp, UUID]); } } @@ -92,14 +92,14 @@ async function checkVideoDuration(UUID: SegmentUUID) { ORDER BY "timeSubmitted" DESC LIMIT 1`, [videoID, service]) as {videoDuration: VideoDuration, UUID: SegmentUUID, timeSubmitted: number}; - const currentTime = Date.now(); + const isoTimestamp = new Date().toISOString(); if (latestSubmission && videoDurationChanged(latestSubmission.videoDuration, apiVideoDuration)) { Logger.info(`Video duration changed for ${videoID} from ${latestSubmission.videoDuration} to ${apiVideoDuration}`); await db.prepare("run", `UPDATE "sponsorTimes" SET "hidden" = 1, "updatedAt" = ? WHERE "videoID" = ? AND "service" = ? AND "timeSubmitted" <= ? AND "hidden" = 0 AND "shadowHidden" = 0 AND "actionType" != 'full' AND "votes" > -2`, - [currentTime, videoID, service, latestSubmission.timeSubmitted]); + [isoTimestamp, videoID, service, latestSubmission.timeSubmitted]); deleteLockCategories(videoID, null, null, service).catch((e) => Logger.error(`delete lock categories after vote: ${e}`)); } } @@ -242,6 +242,7 @@ async function categoryVote(UUID: SegmentUUID, userID: HashedUserID, isVIP: bool const nextCategoryInfo = await db.prepare("get", `select votes from "categoryVotes" where "UUID" = ? and category = ?`, [UUID, category], { useReplica: true }); const timeSubmitted = Date.now(); + const isoTimestamp = new Date(timeSubmitted).toISOString(); const voteAmount = (isVIP || isTempVIP) ? 500 : 1; const ableToVote = finalResponse.finalStatus === 200; // ban status checks handled by vote() (caller function) @@ -289,7 +290,7 @@ async function categoryVote(UUID: SegmentUUID, userID: HashedUserID, isVIP: bool // VIPs change it every time if (isVIP || isTempVIP || isOwnSubmission || nextCategoryCount - currentCategoryCount >= Math.max(Math.ceil(submissionInfo?.votes / 2), 2)) { // Replace the category - await db.prepare("run", `update "sponsorTimes" set "category" = ?, "updatedAt" = ? where "UUID" = ?`, [category, timeSubmitted, UUID]); + await db.prepare("run", `update "sponsorTimes" set "category" = ?, "updatedAt" = ? where "UUID" = ?`, [category, isoTimestamp, UUID]); } } QueryCacher.clearSegmentCache(segmentInfo); @@ -512,14 +513,14 @@ export async function vote(ip: IPAddress, UUID: SegmentUUID, paramUserID: UserID await privateDB.prepare("run", `INSERT INTO "votes" ("UUID", "userID", "hashedIP", "type", "normalUserID", "originalType") VALUES(?, ?, ?, ?, ?, ?)`, [UUID, userID, hashedIP, type, nonAnonUserID, originalType]); } - const currentTime = Date.now(); + const isoTimestamp = new Date().toISOString(); // update the vote count on this sponsorTime - await db.prepare("run", `UPDATE "sponsorTimes" SET "votes" = "votes" + ?, "updatedAt" = ? WHERE "UUID" = ?`, [incrementAmount - oldIncrementAmount, currentTime, UUID]); + await db.prepare("run", `UPDATE "sponsorTimes" SET "votes" = "votes" + ?, "updatedAt" = ? WHERE "UUID" = ?`, [incrementAmount - oldIncrementAmount, isoTimestamp, UUID]); // tempVIP can bring back hidden segments if (isTempVIP && incrementAmount > 0 && voteTypeEnum === voteTypes.normal) { - await db.prepare("run", `UPDATE "sponsorTimes" SET "hidden" = 0, "updatedAt" = ? WHERE "UUID" = ?`, [currentTime, UUID]); + await db.prepare("run", `UPDATE "sponsorTimes" SET "hidden" = 0, "updatedAt" = ? WHERE "UUID" = ?`, [isoTimestamp, UUID]); } // additional processing for VIP // on VIP upvote @@ -527,10 +528,10 @@ export async function vote(ip: IPAddress, UUID: SegmentUUID, paramUserID: UserID // Update video duration in case that caused it to be hidden await updateSegmentVideoDuration(UUID); // unhide & unlock - await db.prepare("run", 'UPDATE "sponsorTimes" SET "locked" = 1, "hidden" = 0, "shadowHidden" = 0, "updatedAt" = ? WHERE "UUID" = ?', [currentTime, UUID]); + await db.prepare("run", 'UPDATE "sponsorTimes" SET "locked" = 1, "hidden" = 0, "shadowHidden" = 0, "updatedAt" = ? WHERE "UUID" = ?', [isoTimestamp, UUID]); // on VIP downvote/ undovote, also unlock submission } else if (isVIP && incrementAmount <= 0 && voteTypeEnum === voteTypes.normal) { - await db.prepare("run", 'UPDATE "sponsorTimes" SET "locked" = 0, "updatedAt" = ? WHERE "UUID" = ?', [currentTime, UUID]); + await db.prepare("run", 'UPDATE "sponsorTimes" SET "locked" = 0, "updatedAt" = ? WHERE "UUID" = ?', [isoTimestamp, UUID]); } QueryCacher.clearSegmentCache(segmentInfo); From 81d581679befce61d275428c5037f43e0fc1ca1f Mon Sep 17 00:00:00 2001 From: Tristan Date: Mon, 19 Aug 2024 22:14:50 +0200 Subject: [PATCH 14/27] feat(userNames): change timestamps to ISO 8601 --- databases/_upgrade_sponsorTimes_41.sql | 4 ++-- src/routes/setUsername.ts | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/databases/_upgrade_sponsorTimes_41.sql b/databases/_upgrade_sponsorTimes_41.sql index 6d85cf8a..92d48151 100644 --- a/databases/_upgrade_sponsorTimes_41.sql +++ b/databases/_upgrade_sponsorTimes_41.sql @@ -8,8 +8,8 @@ ALTER TABLE "vipUsers" ADD "createdAt" TEXT NOT NULL; ALTER TABLE "sponsorTimes" ADD "updatedAt" TEXT NOT NULL; -- userNames -ALTER TABLE "userNames" ADD "createdAt" INTEGER NOT NULL; -ALTER TABLE "userNames" ADD "updatedAt" INTEGER NOT NULL; +ALTER TABLE "userNames" ADD "createdAt" TEXT NOT NULL; +ALTER TABLE "userNames" ADD "updatedAt" TEXT NOT NULL; -- categoryVotes ALTER TABLE "categoryVotes" ADD "createdAt" INTEGER NOT NULL; diff --git a/src/routes/setUsername.ts b/src/routes/setUsername.ts index 9cbbaa39..d8a575a2 100644 --- a/src/routes/setUsername.ts +++ b/src/routes/setUsername.ts @@ -79,7 +79,7 @@ export async function setUsername(req: Request, res: Response): Promise Date: Mon, 19 Aug 2024 22:15:19 +0200 Subject: [PATCH 15/27] feat(categoryVotes): change timestamps to ISO 8601 --- databases/_upgrade_sponsorTimes_41.sql | 4 ++-- src/routes/voteOnSponsorTime.ts | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/databases/_upgrade_sponsorTimes_41.sql b/databases/_upgrade_sponsorTimes_41.sql index 92d48151..888c3b0e 100644 --- a/databases/_upgrade_sponsorTimes_41.sql +++ b/databases/_upgrade_sponsorTimes_41.sql @@ -12,8 +12,8 @@ ALTER TABLE "userNames" ADD "createdAt" TEXT NOT NULL; ALTER TABLE "userNames" ADD "updatedAt" TEXT NOT NULL; -- categoryVotes -ALTER TABLE "categoryVotes" ADD "createdAt" INTEGER NOT NULL; -ALTER TABLE "categoryVotes" ADD "updatedAt" INTEGER NOT NULL; +ALTER TABLE "categoryVotes" ADD "createdAt" TEXT NOT NULL; +ALTER TABLE "categoryVotes" ADD "updatedAt" TEXT NOT NULL; -- lockCategories ALTER TABLE "lockCategories" ADD "createdAt" INTEGER NOT NULL; diff --git a/src/routes/voteOnSponsorTime.ts b/src/routes/voteOnSponsorTime.ts index 846df378..39843410 100644 --- a/src/routes/voteOnSponsorTime.ts +++ b/src/routes/voteOnSponsorTime.ts @@ -251,16 +251,16 @@ async function categoryVote(UUID: SegmentUUID, userID: HashedUserID, isVIP: bool // Add the vote if ((await db.prepare("get", `select count(*) as count from "categoryVotes" where "UUID" = ? and category = ?`, [UUID, category])).count > 0) { // Update the already existing db entry - await db.prepare("run", `update "categoryVotes" set "votes" = "votes" + ?, "updatedAt" = ? where "UUID" = ? and "category" = ?`, [voteAmount, timeSubmitted, UUID, category]); + await db.prepare("run", `update "categoryVotes" set "votes" = "votes" + ?, "updatedAt" = ? where "UUID" = ? and "category" = ?`, [voteAmount, isoTimestamp, UUID, category]); } else { // Add a db entry - await db.prepare("run", `insert into "categoryVotes" ("UUID", "category", "votes", "createdAt", "updatedAt") values (?, ?, ?, ?, ?)`, [UUID, category, voteAmount]); + await db.prepare("run", `insert into "categoryVotes" ("UUID", "category", "votes", "createdAt", "updatedAt") values (?, ?, ?, ?, ?)`, [UUID, category, voteAmount, isoTimestamp, isoTimestamp]); } // Add the info into the private db if (usersLastVoteInfo?.votes > 0) { // Reverse the previous vote - await db.prepare("run", `update "categoryVotes" set "votes" = "votes" - ? where "UUID" = ? and "category" = ?`, [voteAmount, UUID, usersLastVoteInfo.category]); + await db.prepare("run", `update "categoryVotes" set "votes" = "votes" - ?, "updatedAt" = ? where "UUID" = ? and "category" = ?`, [voteAmount, isoTimestamp, UUID, usersLastVoteInfo.category]); await privateDB.prepare("run", `update "categoryVotes" set "category" = ?, "timeSubmitted" = ?, "hashedIP" = ? where "userID" = ? and "UUID" = ?`, [category, timeSubmitted, hashedIP, userID, UUID]); } else { @@ -280,7 +280,7 @@ async function categoryVote(UUID: SegmentUUID, userID: HashedUserID, isVIP: bool // Add submission as vote if (!currentCategoryInfo && submissionInfo) { - await db.prepare("run", `insert into "categoryVotes" ("UUID", "category", "votes") values (?, ?, ?)`, [UUID, segmentInfo.category, currentCategoryCount]); + await db.prepare("run", `insert into "categoryVotes" ("UUID", "category", "votes", "createdAt", "updatedAt") values (?, ?, ?)`, [UUID, segmentInfo.category, currentCategoryCount, isoTimestamp, isoTimestamp]); await privateDB.prepare("run", `insert into "categoryVotes" ("UUID", "userID", "hashedIP", "category", "timeSubmitted") values (?, ?, ?, ?, ?)`, [UUID, submissionInfo.userID, "unknown", segmentInfo.category, submissionInfo.timeSubmitted]); } From 106505ab196b80bdb15b44b98ef34d697dee6259 Mon Sep 17 00:00:00 2001 From: Tristan Date: Mon, 19 Aug 2024 22:16:26 +0200 Subject: [PATCH 16/27] feat(lockCategories): change timestamps to ISO 8601 --- databases/_upgrade_sponsorTimes_41.sql | 4 ++-- src/routes/postLockCategories.ts | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/databases/_upgrade_sponsorTimes_41.sql b/databases/_upgrade_sponsorTimes_41.sql index 888c3b0e..0f814699 100644 --- a/databases/_upgrade_sponsorTimes_41.sql +++ b/databases/_upgrade_sponsorTimes_41.sql @@ -16,8 +16,8 @@ ALTER TABLE "categoryVotes" ADD "createdAt" TEXT NOT NULL; ALTER TABLE "categoryVotes" ADD "updatedAt" TEXT NOT NULL; -- lockCategories -ALTER TABLE "lockCategories" ADD "createdAt" INTEGER NOT NULL; -ALTER TABLE "lockCategories" ADD "updatedAt" INTEGER NOT NULL; +ALTER TABLE "lockCategories" ADD "createdAt" TEXT NOT NULL; +ALTER TABLE "lockCategories" ADD "updatedAt" TEXT NOT NULL; -- titleVotes ALTER TABLE "titleVotes" ADD "createdAt" INTEGER NOT NULL; diff --git a/src/routes/postLockCategories.ts b/src/routes/postLockCategories.ts index e38a686c..0c913ed5 100644 --- a/src/routes/postLockCategories.ts +++ b/src/routes/postLockCategories.ts @@ -61,7 +61,7 @@ export async function postLockCategories(req: Request, res: Response): Promise Date: Mon, 19 Aug 2024 22:18:29 +0200 Subject: [PATCH 17/27] feat(lockCategories): change timestamps to ISO 8601 --- databases/_upgrade_sponsorTimes_41.sql | 4 ++-- src/routes/postBranding.ts | 9 +++++---- src/routes/shadowBanUser.ts | 4 ++-- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/databases/_upgrade_sponsorTimes_41.sql b/databases/_upgrade_sponsorTimes_41.sql index 0f814699..10108d8d 100644 --- a/databases/_upgrade_sponsorTimes_41.sql +++ b/databases/_upgrade_sponsorTimes_41.sql @@ -20,8 +20,8 @@ ALTER TABLE "lockCategories" ADD "createdAt" TEXT NOT NULL; ALTER TABLE "lockCategories" ADD "updatedAt" TEXT NOT NULL; -- titleVotes -ALTER TABLE "titleVotes" ADD "createdAt" INTEGER NOT NULL; -ALTER TABLE "titleVotes" ADD "updatedAt" INTEGER NOT NULL; +ALTER TABLE "titleVotes" ADD "createdAt" TEXT NOT NULL; +ALTER TABLE "titleVotes" ADD "updatedAt" TEXT NOT NULL; -- thumbnailVotes ALTER TABLE "thumbnailVotes" ADD "createdAt" INTEGER NOT NULL; diff --git a/src/routes/postBranding.ts b/src/routes/postBranding.ts index 19c86396..78b47aa7 100644 --- a/src/routes/postBranding.ts +++ b/src/routes/postBranding.ts @@ -67,6 +67,7 @@ export async function postBranding(req: Request, res: Response) { } const now = Date.now(); + const isoTimestamp = new Date(now).toISOString(); const voteType: BrandingVoteType = downvote ? BrandingVoteType.Downvote : BrandingVoteType.Upvote; if (title && !isVip && title.title.length > config.maxTitleLength) { @@ -105,14 +106,14 @@ export async function postBranding(req: Request, res: Response) { const verificationValue = await getVerificationValue(hashedUserID, isVip); await db.prepare("run", `INSERT INTO "titleVotes" ("UUID", "votes", "locked", "shadowHidden", "verification", "createdAt", "updatedAt") VALUES (?, 0, ?, ?, ?, ?, ?);`, - [UUID, shouldLock ? 1 : 0, isBanned ? 1 : 0, verificationValue, now, now]); + [UUID, shouldLock ? 1 : 0, isBanned ? 1 : 0, verificationValue, isoTimestamp, isoTimestamp]); await verifyOldSubmissions(hashedUserID, verificationValue); } if (isVip && !downvote && shouldLock) { // unlock all other titles - await db.prepare("run", `UPDATE "titleVotes" as tv SET "locked" = 0, "updatedAt" = ? FROM "titles" t WHERE tv."UUID" = t."UUID" AND tv."UUID" != ? AND t."videoID" = ?`, [now, UUID, videoID]); + await db.prepare("run", `UPDATE "titleVotes" as tv SET "locked" = 0, "updatedAt" = ? FROM "titles" t WHERE tv."UUID" = t."UUID" AND tv."UUID" != ? AND t."videoID" = ?`, [isoTimestamp, UUID, videoID]); } sendWebhooks(videoID, UUID, voteType).catch((e) => Logger.error(e)); @@ -284,6 +285,7 @@ export async function getVerificationValue(hashedUserID: HashedUserID, isVip: bo export async function verifyOldSubmissions(hashedUserID: HashedUserID, verification: number): Promise { if (verification >= 0) { const unverifiedSubmissions = await db.prepare("all", `SELECT "videoID", "hashedVideoID", "service" FROM "titles" JOIN "titleVotes" ON "titles"."UUID" = "titleVotes"."UUID" WHERE "titles"."userID" = ? AND "titleVotes"."verification" < ? GROUP BY "videoID", "hashedVideoID", "service"`, [hashedUserID, verification]); + const isoTimestamp = new Date().toISOString(); if (unverifiedSubmissions.length > 0) { for (const submission of unverifiedSubmissions) { @@ -294,8 +296,7 @@ export async function verifyOldSubmissions(hashedUserID: HashedUserID, verificat }); } - const currentTime = Date.now(); - await db.prepare("run", `UPDATE "titleVotes" as tv SET "verification" = ?, "updatedAt" = ? FROM "titles" WHERE "titles"."UUID" = tv."UUID" AND "titles"."userID" = ? AND tv."verification" < ?`, [verification, currentTime, hashedUserID, verification]); + await db.prepare("run", `UPDATE "titleVotes" as tv SET "verification" = ?, "updatedAt" = ? FROM "titles" WHERE "titles"."UUID" = tv."UUID" AND "titles"."userID" = ? AND tv."verification" < ?`, [verification, isoTimestamp, hashedUserID, verification]); } } } diff --git a/src/routes/shadowBanUser.ts b/src/routes/shadowBanUser.ts index 9d68b0d0..ee9736e9 100644 --- a/src/routes/shadowBanUser.ts +++ b/src/routes/shadowBanUser.ts @@ -109,12 +109,12 @@ async function unHideSubmissionsByUser(categories: string[], deArrowTypes: DeArr if (deArrowTypes.includes("title")) { await db.prepare("run", `UPDATE "titleVotes" as tv SET "shadowHidden" = ${type}, "updatedAt" = ? FROM "titles" t WHERE tv."UUID" = t."UUID" AND t."userID" = ?`, - [currentTime, userID]); + [isoTimestamp, userID]); } if (deArrowTypes.includes("thumbnail")) { await db.prepare("run", `UPDATE "thumbnailVotes" as tv SET "shadowHidden" = ${type}, "updatedAt" = ? FROM "thumbnails" t WHERE tv."UUID" = t."UUID" AND t."userID" = ?`, - [currentTime, userID]); + [isoTimestamp, userID]); } (await db.prepare("all", `SELECT "videoID", "hashedVideoID", "service" FROM "titles" WHERE "userID" = ?`, [userID])) From 26faa362ffcaad21c726fa46e6b31cc61ea9f2e6 Mon Sep 17 00:00:00 2001 From: Tristan Date: Mon, 19 Aug 2024 22:19:52 +0200 Subject: [PATCH 18/27] feat(thumbnailVotes): change timestamps to ISO 8601 --- databases/_upgrade_sponsorTimes_41.sql | 4 ++-- src/routes/postBranding.ts | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/databases/_upgrade_sponsorTimes_41.sql b/databases/_upgrade_sponsorTimes_41.sql index 10108d8d..4b6f3534 100644 --- a/databases/_upgrade_sponsorTimes_41.sql +++ b/databases/_upgrade_sponsorTimes_41.sql @@ -24,8 +24,8 @@ ALTER TABLE "titleVotes" ADD "createdAt" TEXT NOT NULL; ALTER TABLE "titleVotes" ADD "updatedAt" TEXT NOT NULL; -- thumbnailVotes -ALTER TABLE "thumbnailVotes" ADD "createdAt" INTEGER NOT NULL; -ALTER TABLE "thumbnailVotes" ADD "updatedAt" INTEGER NOT NULL; +ALTER TABLE "thumbnailVotes" ADD "createdAt" TEXT NOT NULL; +ALTER TABLE "thumbnailVotes" ADD "updatedAt" TEXT NOT NULL; UPDATE "config" SET value = 41 WHERE key = 'version'; diff --git a/src/routes/postBranding.ts b/src/routes/postBranding.ts index 78b47aa7..1a88385d 100644 --- a/src/routes/postBranding.ts +++ b/src/routes/postBranding.ts @@ -147,7 +147,7 @@ export async function postBranding(req: Request, res: Response) { [videoID, thumbnail.original ? 1 : 0, hashedUserID, service, hashedVideoID, now, UUID]); await db.prepare("run", `INSERT INTO "thumbnailVotes" ("UUID", "votes", "locked", "shadowHidden", "createdAt", "updatedAt") VALUES (?, 0, ?, ?, ?, ?)`, - [UUID, shouldLock ? 1 : 0, isBanned ? 1 : 0, now, now]); + [UUID, shouldLock ? 1 : 0, isBanned ? 1 : 0, isoTimestamp, isoTimestamp]); if (!thumbnail.original) { await db.prepare("run", `INSERT INTO "thumbnailTimestamps" ("UUID", "timestamp") VALUES (?, ?)`, @@ -157,7 +157,7 @@ export async function postBranding(req: Request, res: Response) { if (isVip && !downvote && shouldLock) { // unlock all other titles - await db.prepare("run", `UPDATE "thumbnailVotes" as tv SET "locked" = 0, "updatedAt" = ? FROM "thumbnails" t WHERE tv."UUID" = t."UUID" AND tv."UUID" != ? AND t."videoID" = ?`, [now, UUID, videoID]); + await db.prepare("run", `UPDATE "thumbnailVotes" as tv SET "locked" = 0, "updatedAt" = ? FROM "thumbnails" t WHERE tv."UUID" = t."UUID" AND tv."UUID" != ? AND t."videoID" = ?`, [isoTimestamp, UUID, videoID]); } } })()]); From 88e3bca0ebca8ea1400b454d0d3318065d3aa6fc Mon Sep 17 00:00:00 2001 From: Tristan Date: Mon, 19 Aug 2024 22:22:49 +0200 Subject: [PATCH 19/27] docs(DatabaseSchema): update timestamp field types --- DatabaseSchema.md | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/DatabaseSchema.md b/DatabaseSchema.md index 5752a532..82492649 100644 --- a/DatabaseSchema.md +++ b/DatabaseSchema.md @@ -24,7 +24,7 @@ | Name | Type | | | -- | :--: | -- | | userID | TEXT | not null, primary key | -| createdAt | INTEGER | not null | +| createdAt | TEXT | not null | | index | field | | -- | :--: | @@ -54,7 +54,7 @@ | hashedVideoID | TEXT | not null, default '', sha256 | | userAgent | TEXT | not null, default '' | | description | TEXT | not null, default '' | -| updatedAt | INTEGER | not null | +| updatedAt | TEXT | not null | | index | field | | -- | :--: | @@ -73,8 +73,8 @@ | userID | TEXT | not null, primary key | | userName | TEXT | not null | | locked | INTEGER | not nul, default '0' | -| createdAt | INTEGER | not null | -| updatedAt | INTEGER | not null | +| createdAt | TEXT | not null | +| updatedAt | TEXT | not null | | index | field | | -- | :--: | @@ -88,8 +88,8 @@ | category | TEXT | not null | | votes | INTEGER | not null, default 0 | | id | SERIAL | primary key -| createdAt | INTEGER | not null | -| updatedAt | INTEGER | not null | +| createdAt | TEXT | not null | +| updatedAt | TEXT | not null | | index | field | | -- | :--: | @@ -107,8 +107,8 @@ | reason | TEXT | not null, default '' | | service | TEXT | not null, default 'YouTube' | | id | SERIAL | primary key -| createdAt | INTEGER | not null | -| updatedAt | INTEGER | not null | +| createdAt | TEXT | not null | +| updatedAt | TEXT | not null | | index | field | | -- | :--: | @@ -272,8 +272,8 @@ | verification | INTEGER | default 0 | | downvotes | INTEGER | default 0 | | removed | INTEGER | default 0 | -| createdAt | INTEGER | not null | -| updatedAt | INTEGER | not null | +| createdAt | TEXT | not null | +| updatedAt | TEXT | not null | | constraint | field | | -- | :--: | @@ -322,8 +322,8 @@ | shadowHidden | INTEGER | not null, default 0 | | downvotes | INTEGER | default 0 | | removed | INTEGER | default 0 | -| createdAt | INTEGER | not null | -| updatedAt | INTEGER | not null | +| createdAt | TEXT | not null | +| updatedAt | TEXT | not null | | constraint | field | | -- | :--: | @@ -416,7 +416,7 @@ | issuerUserID | TEXT | not null | | targetUserID | TEXT | not null | | enabled | BOOLEAN | not null | -| updatedAt | INTEGER | not null | +| updatedAt | TEXT | not null | | id | SERIAL | primary key | ### userNameLogs @@ -427,5 +427,5 @@ | newUserName | TEXT | not null | | oldUserName | TEXT | not null | | updatedByAdmin | BOOLEAN | not null | -| updatedAt | INTEGER | not null | +| updatedAt | TEXT | not null | | id | SERIAL | primary key | \ No newline at end of file From a7c81bc4f3a5566c2aca259926e0071e099ee21f Mon Sep 17 00:00:00 2001 From: Tristan Date: Mon, 16 Sep 2024 18:01:31 +0200 Subject: [PATCH 20/27] test(vipUsers): impl createdAt --- test/cases/getLockCategoriesByHash.ts | 5 +++-- test/cases/getLockReason.ts | 7 ++++--- test/cases/getUserInfoFree.ts | 3 ++- test/cases/lockCategoriesRecords.ts | 5 +++-- test/cases/postBranding.ts | 7 ++++--- test/cases/postPurgeAllSegments.ts | 3 ++- test/cases/postSkipSegments.ts | 5 +++-- test/cases/postWarning.ts | 5 +++-- test/cases/reputation.ts | 5 +++-- test/cases/segmentShift.ts | 3 ++- test/cases/shadowBanUser.ts | 3 ++- test/cases/shadowBanUser4xx.ts | 3 ++- test/cases/tempVip.ts | 5 +++-- test/cases/unBan.ts | 5 +++-- test/cases/voteOnSponsorTime.ts | 3 ++- test/utils/queryGen.ts | 4 ++-- 16 files changed, 43 insertions(+), 28 deletions(-) diff --git a/test/cases/getLockCategoriesByHash.ts b/test/cases/getLockCategoriesByHash.ts index f6b2757a..a034d4f3 100644 --- a/test/cases/getLockCategoriesByHash.ts +++ b/test/cases/getLockCategoriesByHash.ts @@ -6,12 +6,13 @@ import { ActionType } from "../../src/types/segments.model"; const fakeHash = "b05a20424f24a53dac1b059fb78d861ba9723645026be2174c93a94f9106bb35"; const endpoint = "/api/lockCategories"; +const isoDate = new Date().toISOString(); const getLockCategories = (hash: string, actionType = [ActionType.Mute, ActionType.Skip]) => client.get(`${endpoint}/${hash}`, { params: { actionType } }); describe("getLockCategoriesByHash", () => { before(async () => { - const insertVipUserQuery = 'INSERT INTO "vipUsers" ("userID") VALUES (?)'; - await db.prepare("run", insertVipUserQuery, [getHash("getLockCategoriesHashVIP")]); + const insertVipUserQuery = 'INSERT INTO "vipUsers" ("userID", "createdAt") VALUES (?, ?)'; + await db.prepare("run", insertVipUserQuery, [getHash("getLockCategoriesHashVIP"), isoDate]); const insertLockCategoryQuery = 'INSERT INTO "lockCategories" ("userID", "videoID", "actionType", "category", "reason", "hashedVideoID") VALUES (?, ?, ?, ?, ?, ?)'; await db.prepare("run", insertLockCategoryQuery, [getHash("getLockCategoriesHashVIP"), "getLockHash1", "skip", "sponsor", "1-reason-short", getHash("getLockHash1", 1)]); diff --git a/test/cases/getLockReason.ts b/test/cases/getLockReason.ts index 1b3c36ba..62e4fb94 100644 --- a/test/cases/getLockReason.ts +++ b/test/cases/getLockReason.ts @@ -10,12 +10,13 @@ const vipUserName1 = "getLockReason-vipUserName_1"; const vipUserID1 = getHash("getLockReason-vipUserID_1"); const vipUserName2 = "getLockReason-vipUserName_2"; const vipUserID2 = getHash("getLockReason-vipUserID_2"); +const isoDate = new Date().toISOString(); describe("getLockReason", () => { before(async () => { - const insertVipUserQuery = 'INSERT INTO "vipUsers" ("userID") VALUES (?)'; - await db.prepare("run", insertVipUserQuery, [vipUserID1]); - await db.prepare("run", insertVipUserQuery, [vipUserID2]); + const insertVipUserQuery = 'INSERT INTO "vipUsers" ("userID", "createdAt") VALUES (?, ?)'; + await db.prepare("run", insertVipUserQuery, [vipUserID1, isoDate]); + await db.prepare("run", insertVipUserQuery, [vipUserID2, isoDate]); const insertVipUserNameQuery = 'INSERT INTO "userNames" ("userID", "userName") VALUES (?, ?)'; await db.prepare("run", insertVipUserNameQuery, [vipUserID1, vipUserName1]); diff --git a/test/cases/getUserInfoFree.ts b/test/cases/getUserInfoFree.ts index 6556eb25..206a45a7 100644 --- a/test/cases/getUserInfoFree.ts +++ b/test/cases/getUserInfoFree.ts @@ -11,6 +11,7 @@ describe("getUserInfo Free Chapters", () => { const repQualifyUserID = "getUserInfo-Free-RepQualify"; const oldQualifyUserID = "getUserInfo-Free-OldQualify"; const postOldQualify = 1600000000000; + const isoDate = new Date().toISOString(); before(async () => { const sponsorTimesQuery = 'INSERT INTO "sponsorTimes" ("videoID", "startTime", "endTime", "votes", "UUID", "userID", "timeSubmitted", views, category, "actionType", "reputation", "shadowHidden") VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)'; @@ -18,7 +19,7 @@ describe("getUserInfo Free Chapters", () => { await db.prepare("run", sponsorTimesQuery, ["getUserInfoFree", 1, 2, 0, "uuid-guif-1", getHash(oldQualifyUserID), 0, 0, "sponsor", "skip", 0, 0]); // submit at epoch await db.prepare("run", sponsorTimesQuery, ["getUserInfoFree", 1, 2, 0, "uuid-guif-2", getHash(newQualifyUserID), postOldQualify, 0, "sponsor", "skip", 0, 0]); - await db.prepare("run", `INSERT INTO "vipUsers" ("userID") VALUES (?)`, [getHash(vipQualifyUserID)]); + await db.prepare("run", `INSERT INTO "vipUsers" ("userID", "createdAt") VALUES (?, ?)`, [getHash(vipQualifyUserID), isoDate]); }); const getUserInfo = (userID: string) => client.get(endpoint, { params: { userID, value: "freeChaptersAccess" } }); diff --git a/test/cases/lockCategoriesRecords.ts b/test/cases/lockCategoriesRecords.ts index ebfc4218..8a98c251 100644 --- a/test/cases/lockCategoriesRecords.ts +++ b/test/cases/lockCategoriesRecords.ts @@ -26,11 +26,12 @@ const submitEndpoint = "/api/skipSegments"; const checkLockCategories = (videoID: string): Promise => db.prepare("all", 'SELECT * FROM "lockCategories" WHERE "videoID" = ?', [videoID]); const lockVIPUser = "lockCategoriesRecordsVIPUser"; const lockVIPUserHash = getHash(lockVIPUser); +const isoDate = new Date().toISOString(); describe("lockCategoriesRecords", () => { before(async () => { - const insertVipUserQuery = 'INSERT INTO "vipUsers" ("userID") VALUES (?)'; - await db.prepare("run", insertVipUserQuery, [lockVIPUserHash]); + const insertVipUserQuery = 'INSERT INTO "vipUsers" ("userID", "createdAt") VALUES (?, ?)'; + await db.prepare("run", insertVipUserQuery, [lockVIPUserHash, isoDate]); const insertLockCategoryQuery = 'INSERT INTO "lockCategories" ("userID", "videoID", "actionType", "category", "reason", "service") VALUES (?, ?, ?, ?, ?, ?)'; await db.prepare("run", insertLockCategoryQuery, [lockVIPUserHash, "no-segments-video-id", "skip", "sponsor", "reason-1", "YouTube"]); diff --git a/test/cases/postBranding.ts b/test/cases/postBranding.ts index 7d3d9854..eb2612ee 100644 --- a/test/cases/postBranding.ts +++ b/test/cases/postBranding.ts @@ -16,6 +16,7 @@ describe("postBranding", () => { const userID6 = `PostBrandingUser6${".".repeat(16)}`; const userID7 = `PostBrandingUser7${".".repeat(16)}`; const bannedUser = `BannedPostBrandingUser${".".repeat(16)}`; + const isoDate = new Date().toISOString(); const endpoint = "/api/branding"; @@ -32,9 +33,9 @@ describe("postBranding", () => { const queryThumbnailVotesByUUID = (UUID: string, all = false) => db.prepare(all ? "all" : "get", `SELECT * FROM "thumbnailVotes" WHERE "UUID" = ?`, [UUID]); before(async () => { - const insertVipUserQuery = 'INSERT INTO "vipUsers" ("userID") VALUES (?)'; - await db.prepare("run", insertVipUserQuery, [getHash(vipUser)]); - await db.prepare("run", insertVipUserQuery, [getHash(vipUser2)]); + const insertVipUserQuery = 'INSERT INTO "vipUsers" ("userID", "createdAt") VALUES (?, ?)'; + await db.prepare("run", insertVipUserQuery, [getHash(vipUser), isoDate]); + await db.prepare("run", insertVipUserQuery, [getHash(vipUser2), isoDate]); const insertBannedUserQuery = 'INSERT INTO "shadowBannedUsers" ("userID") VALUES (?)'; await db.prepare("run", insertBannedUserQuery, [getHash(bannedUser)]); diff --git a/test/cases/postPurgeAllSegments.ts b/test/cases/postPurgeAllSegments.ts index 9d9c675a..897b3c86 100644 --- a/test/cases/postPurgeAllSegments.ts +++ b/test/cases/postPurgeAllSegments.ts @@ -33,6 +33,7 @@ describe("postPurgeAllSegments", function () { const privateVipUserID = "VIPUser-purgeAll"; const vipUserID = getHash(privateVipUserID); const endpoint = "/api/purgeAllSegments"; + const isoDate = new Date().toISOString(); const postSegmentShift = (videoID: string, userID: string) => client.post(endpoint, { videoID, userID }); before(async function () { @@ -42,7 +43,7 @@ describe("postPurgeAllSegments", function () { await dbSponsorTimesAdd(db, "vsegpurge01", 0, 3, "vsegpurgetest01uuid03", "interaction"); await dbSponsorTimesAdd(db, "vsegpurge01", 0, 4, "vsegpurgetest01uuid04", "outro"); await dbSponsorTimesAdd(db, "vseg-not-purged01", 0, 5, "vsegpurgetest01uuid05", "outro"); - await db.prepare("run", `INSERT INTO "vipUsers" ("userID") VALUES (?)`, [vipUserID]); + await db.prepare("run", `INSERT INTO "vipUsers" ("userID", "createdAt") VALUES (?, ?)`, [vipUserID, isoDate]); }); it("Reject non-VIP user", function (done) { diff --git a/test/cases/postSkipSegments.ts b/test/cases/postSkipSegments.ts index cf45bcaf..d8c7815e 100644 --- a/test/cases/postSkipSegments.ts +++ b/test/cases/postSkipSegments.ts @@ -43,6 +43,7 @@ describe("postSkipSegments", () => { const submitUserOne = `PostSkipUser1${".".repeat(18)}`; const submitUserTwo = `PostSkipUser2${".".repeat(18)}`; const submitUserTwoHash = getHash(submitUserTwo); + const isoDate = new Date().toISOString(); const submitVIPuser = `VIPPostSkipUser${".".repeat(16)}`; @@ -54,8 +55,8 @@ describe("postSkipSegments", () => { const insertSponsorTimeQuery = 'INSERT INTO "sponsorTimes" ("videoID", "startTime", "endTime", "votes", "UUID", "userID", "timeSubmitted", views, category, "actionType", "videoDuration", "shadowHidden", "hashedVideoID") VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)'; db.prepare("run", insertSponsorTimeQuery, ["full_video_segment", 0, 0, 0, "full-video-uuid-0", submitUserTwoHash, 0, 0, "sponsor", "full", 0, 0, "full_video_segment"]); - const insertVipUserQuery = 'INSERT INTO "vipUsers" ("userID") VALUES (?)'; - db.prepare("run", insertVipUserQuery, [getHash(submitVIPuser)]); + const insertVipUserQuery = 'INSERT INTO "vipUsers" ("userID", "createdAt") VALUES (?, ?)'; + db.prepare("run", insertVipUserQuery, [getHash(submitVIPuser), isoDate]); }); it("Should be able to submit a single time (Params method)", (done) => { diff --git a/test/cases/postWarning.ts b/test/cases/postWarning.ts index 1f7e6a11..6827ee5b 100644 --- a/test/cases/postWarning.ts +++ b/test/cases/postWarning.ts @@ -16,10 +16,11 @@ describe("postWarning", () => { const warningVipOne = "warning-vip-1"; const warningVipTwo = "warning-vip-2"; const nonVipUser = "warning-non-vip"; + const isoDate = new Date().toISOString(); before(async () => { - await db.prepare("run", `INSERT INTO "vipUsers" ("userID") VALUES (?)`, [getHash(warningVipOne)]); - await db.prepare("run", `INSERT INTO "vipUsers" ("userID") VALUES (?)`, [getHash(warningVipTwo)]); + await db.prepare("run", `INSERT INTO "vipUsers" ("userID", "createdAt") VALUES (?, ?)`, [getHash(warningVipOne), isoDate]); + await db.prepare("run", `INSERT INTO "vipUsers" ("userID", "createdAt") VALUES (?, ?)`, [getHash(warningVipTwo), isoDate]); }); it("Should be able to create warning if vip (exp 200)", (done) => { diff --git a/test/cases/reputation.ts b/test/cases/reputation.ts index 653484da..19088815 100644 --- a/test/cases/reputation.ts +++ b/test/cases/reputation.ts @@ -19,6 +19,7 @@ describe("reputation", () => { "have-most-upvoted-in-locked-video" ]; const users = genUsers("reputation", cases); + const isoDate = new Date().toISOString(); before(async function() { this.timeout(5000); // this preparation takes longer then usual @@ -122,8 +123,8 @@ describe("reputation", () => { await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 0, 0, "reputation-7-uuid-7", users["have-most-upvoted-in-locked-video"].pubID, 1606240000000, 50, "sponsor", 0, 0]); // lock video - const insertVipUserQuery = 'INSERT INTO "vipUsers" ("userID") VALUES (?)'; - await db.prepare("run", insertVipUserQuery, [users["locking-vip"].pubID]); + const insertVipUserQuery = 'INSERT INTO "vipUsers" ("userID", "createdAt") VALUES (?, ?)'; + await db.prepare("run", insertVipUserQuery, [users["locking-vip"].pubID, isoDate]); const insertLockCategoryQuery = 'INSERT INTO "lockCategories" ("userID", "videoID", "category") VALUES (?, ?, ?)'; await db.prepare("run", insertLockCategoryQuery, [users["locking-vip"].pubID, videoID, "sponsor"]); diff --git a/test/cases/segmentShift.ts b/test/cases/segmentShift.ts index 98629b18..c6de12f5 100644 --- a/test/cases/segmentShift.ts +++ b/test/cases/segmentShift.ts @@ -41,6 +41,7 @@ describe("segmentShift", function () { const privateVipUserID = "VIPUser-segmentShift"; const vipUserID = getHash(privateVipUserID); const endpoint = "/api/segmentShift"; + const isoDate = new Date().toISOString(); const postSegmentShift = (data: Record) => client({ method: "POST", url: endpoint, @@ -53,7 +54,7 @@ describe("segmentShift", function () { await dbSponsorTimesAdd(db, "vsegshift01", 0, 0, "vsegshifttest01uuid02", "sponsor"); await dbSponsorTimesAdd(db, "vsegshift01", 0, 0, "vsegshifttest01uuid03", "interaction"); await dbSponsorTimesAdd(db, "vsegshift01", 0, 0, "vsegshifttest01uuid04", "outro"); - await db.prepare("run", `INSERT INTO "vipUsers" ("userID") VALUES (?)`, [vipUserID]); + await db.prepare("run", `INSERT INTO "vipUsers" ("userID", "createdAt") VALUES (?, ?)`, [vipUserID, isoDate]); }); beforeEach(async function () { diff --git a/test/cases/shadowBanUser.ts b/test/cases/shadowBanUser.ts index b50c0945..755bda73 100644 --- a/test/cases/shadowBanUser.ts +++ b/test/cases/shadowBanUser.ts @@ -15,6 +15,7 @@ describe("shadowBanUser", () => { const VIPuserID = "shadow-ban-vip"; const video = "shadowBanVideo"; const videohash = getHash(video, 1); + const isoDate = new Date().toISOString(); before(async () => { const insertQuery = `INSERT INTO "sponsorTimes" ("videoID", "startTime", "endTime", "votes", "locked", "UUID", "userID", "timeSubmitted", "views", "category", "service", "shadowHidden", "hashedVideoID") VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`; @@ -54,7 +55,7 @@ describe("shadowBanUser", () => { await db.prepare("run", `INSERT INTO "lockCategories" ("userID", "videoID", "actionType", "category", "service") VALUES (?, ?, ?, ?, ?)`, [getHash("shadow-ban-vip", 1), "lockedVideo", "skip", "sponsor", "YouTube"]); - await db.prepare("run", `INSERT INTO "vipUsers" ("userID") VALUES(?)`, [getHash(VIPuserID)]); + await db.prepare("run", `INSERT INTO "vipUsers" ("userID", "createdAt") VALUES(?, ?)`, [getHash(VIPuserID), isoDate]); const titleQuery = `INSERT INTO "titles" ("videoID", "title", "original", "userID", "service", "hashedVideoID", "timeSubmitted", "UUID") VALUES (?, ?, ?, ?, ?, ?, ?, ?)`; const titleVotesQuery = `INSERT INTO "titleVotes" ("UUID", "votes", "locked", "shadowHidden", "verification") VALUES (?, ?, ?, ?, ?)`; diff --git a/test/cases/shadowBanUser4xx.ts b/test/cases/shadowBanUser4xx.ts index c9cdda9c..ce5f71f0 100644 --- a/test/cases/shadowBanUser4xx.ts +++ b/test/cases/shadowBanUser4xx.ts @@ -4,6 +4,7 @@ import assert from "assert"; import { client } from "../utils/httpClient"; const endpoint = "/api/shadowBanUser"; +const isoDate = new Date().toISOString(); const postShadowBan = (params: Record) => client({ method: "POST", @@ -15,7 +16,7 @@ describe("shadowBanUser 4xx", () => { const VIPuserID = "shadow-ban-4xx-vip"; before(async () => { - await db.prepare("run", `INSERT INTO "vipUsers" ("userID") VALUES(?)`, [getHash(VIPuserID)]); + await db.prepare("run", `INSERT INTO "vipUsers" ("userID", "createdAt") VALUES(?, ?)`, [getHash(VIPuserID), isoDate]); }); it("Should return 400 if no adminUserID", (done) => { diff --git a/test/cases/tempVip.ts b/test/cases/tempVip.ts index 5448598d..4bf01353 100644 --- a/test/cases/tempVip.ts +++ b/test/cases/tempVip.ts @@ -8,6 +8,7 @@ import redis from "../../src/utils/redis"; import assert from "assert"; // helpers +const isoDate = new Date().toISOString(); const getSegment = (UUID: string) => db.prepare("get", `SELECT "votes", "locked", "category" FROM "sponsorTimes" WHERE "UUID" = ?`, [UUID]); const permVIP1 = "tempVip_permaVIPOne"; @@ -62,8 +63,8 @@ describe("tempVIP test", function() { await db.prepare("run", insertSponsorTimeQuery, ["channelid-convert", 1, 9, 0, 1, "tempvip-submit", publicTempVIPOne, 0, 50, "sponsor", 0]); await db.prepare("run", insertSponsorTimeQuery, ["otherchannel", 1, 9, 0, 1, UUID1, "testman", 0, 50, "sponsor", 0]); - await db.prepare("run", 'INSERT INTO "vipUsers" ("userID") VALUES (?)', [publicPermVIP1]); - await db.prepare("run", 'INSERT INTO "vipUsers" ("userID") VALUES (?)', [publicPermVIP2]); + await db.prepare("run", 'INSERT INTO "vipUsers" ("userID", "createdAt") VALUES (?, ?)', [publicPermVIP1, isoDate]); + await db.prepare("run", 'INSERT INTO "vipUsers" ("userID", "createdAt") VALUES (?, ?)', [publicPermVIP2, isoDate]); // clear redis if running consecutive tests await redis.del(tempVIPKey(publicTempVIPOne)); }); diff --git a/test/cases/unBan.ts b/test/cases/unBan.ts index 2f3fec8b..71637b3e 100644 --- a/test/cases/unBan.ts +++ b/test/cases/unBan.ts @@ -6,6 +6,7 @@ import assert from "assert"; describe("unBan", () => { const endpoint = "/api/shadowBanUser"; const VIPuser = "VIPUser-unBan"; + const isoDate = new Date().toISOString(); const postUnBan = (userID: string, adminUserID: string, enabled: boolean) => client({ url: endpoint, method: "POST", @@ -22,8 +23,8 @@ describe("unBan", () => { await db.prepare("run", insertShadowBannedUserQuery, ["testWoman-unBan"]); await db.prepare("run", insertShadowBannedUserQuery, ["testEntity-unBan"]); - const insertVipUserQuery = 'INSERT INTO "vipUsers" ("userID") VALUES (?)'; - await db.prepare("run", insertVipUserQuery, [getHash(VIPuser)]); + const insertVipUserQuery = 'INSERT INTO "vipUsers" ("userID", "createdAt") VALUES (?, ?)'; + await db.prepare("run", insertVipUserQuery, [getHash(VIPuser), isoDate]); const insertLockCategoryQuery = 'INSERT INTO "lockCategories" ("userID", "videoID", "category") VALUES(?, ?, ?)'; await db.prepare("run", insertLockCategoryQuery, [getHash(VIPuser), "unBan-videoID-1", "sponsor"]); diff --git a/test/cases/voteOnSponsorTime.ts b/test/cases/voteOnSponsorTime.ts index 2511332f..38ebbd74 100644 --- a/test/cases/voteOnSponsorTime.ts +++ b/test/cases/voteOnSponsorTime.ts @@ -18,6 +18,7 @@ const categoryChangeUser = "category-change-user"; const outroSubmitter = "outro-submitter"; const badIntroSubmitter = "bad-intro-submitter"; const hiddenInteractionSubmitter = "hidden-interaction-submitter"; +const isoDate = new Date().toISOString(); describe("voteOnSponsorTime", () => { before(async () => { @@ -98,7 +99,7 @@ describe("voteOnSponsorTime", () => { await db.prepare("run", insertWarningQuery, [warnUser02Hash, (now - (warningExpireTime + 2000)), warnVip01Hash, 1]); - await db.prepare("run", 'INSERT INTO "vipUsers" ("userID") VALUES (?)', [getHash(vipUser)]); + await db.prepare("run", 'INSERT INTO "vipUsers" ("userID", "createdAt") VALUES (?, ?)', [getHash(vipUser), isoDate]); await db.prepare("run", 'INSERT INTO "shadowBannedUsers" ("userID") VALUES (?)', [getHash("randomID4")]); const insertlockCategoriesQuery = 'INSERT INTO "lockCategories" ("videoID", "userID", "category", "actionType") VALUES (?, ?, ?, ?)'; diff --git a/test/utils/queryGen.ts b/test/utils/queryGen.ts index a820c2be..76d56ce5 100644 --- a/test/utils/queryGen.ts +++ b/test/utils/queryGen.ts @@ -11,8 +11,8 @@ export { insertSegment } from "./segmentQueryGen"; // vip export const insertVip = async (db: IDatabase, userID: HashedUserID) => { - const query = 'INSERT INTO "vipUsers" ("userID") VALUES (?)'; - await db.prepare("run", query, [userID]); + const query = 'INSERT INTO "vipUsers" ("userID", "createdAt") VALUES (?, ?)'; + await db.prepare("run", query, [userID, new Date().toISOString()]); }; export const insertVipUser = async (db: IDatabase, user: User) => { await insertVip(db, user.pubID); From 5ff8599fb3f3354c48fcd0dda9905c55bd113240 Mon Sep 17 00:00:00 2001 From: Tristan Date: Mon, 16 Sep 2024 18:48:04 +0200 Subject: [PATCH 21/27] test(sponsorTimes): impl updatedAt for insert queries --- test/cases/downvoteSegmentArchiveJob.ts | 37 ++++---- test/cases/getBranding.ts | 21 +++-- test/cases/getSavedTimeForUser.ts | 8 +- test/cases/getSearchSegments.ts | 49 +++++----- test/cases/getSkipSegments.ts | 49 +++++----- test/cases/getSkipSegmentsByHash.ts | 67 +++++++------- test/cases/getTopCategoryUsers.ts | 4 +- test/cases/getTopUsers.ts | 4 +- test/cases/getUserInfoFree.ts | 8 +- test/cases/getUserStats.ts | 35 +++---- test/cases/getVideoLabelByHash.ts | 34 +++---- test/cases/getVideoLabels.ts | 33 +++---- test/cases/oldGetSponsorTime.ts | 7 +- test/cases/postSkipSegments.ts | 4 +- test/cases/postSkipSegmentsAutomod.ts | 9 +- test/cases/postSkipSegmentsDuration.ts | 7 +- test/cases/postSkipSegmentsFeatures.ts | 5 +- test/cases/reputation.ts | 116 ++++++++++++------------ test/cases/shadowBanUser.ts | 46 +++++----- test/cases/tempVip.ts | 8 +- test/cases/unBan.ts | 10 +- test/cases/voteOnSponsorTime.ts | 111 ++++++++++++----------- test/utils/segmentQueryGen.ts | 12 ++- 23 files changed, 352 insertions(+), 332 deletions(-) diff --git a/test/cases/downvoteSegmentArchiveJob.ts b/test/cases/downvoteSegmentArchiveJob.ts index 4a3ad8e1..758f4388 100644 --- a/test/cases/downvoteSegmentArchiveJob.ts +++ b/test/cases/downvoteSegmentArchiveJob.ts @@ -7,34 +7,37 @@ const oct2021 = new Date("October 1, 2021").getTime(); const nov2021 = new Date("November 1, 2021").getTime(); const dec2021 = new Date("December 17, 2021").getTime(); const dec2022 = new Date("December 17, 2022").getTime(); +const oct2021AsIso = new Date(oct2021).toISOString(); +const nov2021AsIso = new Date(nov2021).toISOString(); +const dec2021AsIso = new Date(dec2021).toISOString(); const records = [ - ["dsajVideo0", 0, 0, 2, 0, "dsaj00", "dsajUser", dec2021, 0, 0, 0], - ["dsajVideo0", 0, 0, 2, 0, "dsaj01", "dsajUser", dec2021, 0, 0, 0], - ["dsajVideo0", 0, 0, 2, 0, "dsaj02", "dsajUser", dec2021, 0, 0, 0], - ["dsajVideo0", 0, 0, 2, 0, "dsaj03", "dsajUser", dec2021, 0, 0, 0], - ["dsajVideo0", 0, 0, 2, 0, "dsaj04", "dsajUser", dec2021, 0, 0, 0,], + ["dsajVideo0", 0, 0, 2, 0, "dsaj00", "dsajUser", dec2021, 0, 0, 0, dec2021AsIso], + ["dsajVideo0", 0, 0, 2, 0, "dsaj01", "dsajUser", dec2021, 0, 0, 0, dec2021AsIso], + ["dsajVideo0", 0, 0, 2, 0, "dsaj02", "dsajUser", dec2021, 0, 0, 0, dec2021AsIso], + ["dsajVideo0", 0, 0, 2, 0, "dsaj03", "dsajUser", dec2021, 0, 0, 0, dec2021AsIso], + ["dsajVideo0", 0, 0, 2, 0, "dsaj04", "dsajUser", dec2021, 0, 0, 0, dec2021AsIso], - ["dsajVideo1", 0, 0, 2, 0, "dsaj10", "dsajUser", dec2021, 0, 0, 0], - ["dsajVideo1", 0, 0, -3, 0, "dsaj11", "dsajUser", dec2021, 0, 0, 0], + ["dsajVideo1", 0, 0, 2, 0, "dsaj10", "dsajUser", dec2021, 0, 0, 0, dec2021AsIso], + ["dsajVideo1", 0, 0, -3, 0, "dsaj11", "dsajUser", dec2021, 0, 0, 0, dec2021AsIso], - ["dsajVideo2", 0, 0, 2, 0, "dsaj20", "dsajUser", dec2021, 0, 0, 0], - ["dsajVideo2", 0, 0, -4, 0, "dsaj21", "dsajUser", oct2021, 0, 0, 0], + ["dsajVideo2", 0, 0, 2, 0, "dsaj20", "dsajUser", dec2021, 0, 0, 0, dec2021AsIso], + ["dsajVideo2", 0, 0, -4, 0, "dsaj21", "dsajUser", oct2021, 0, 0, 0, oct2021AsIso], - ["dsajVideo3", 0, 0, 2, 1, "dsaj30", "dsajUser", dec2021, 0, 0, 0], - ["dsajVideo3", 0, 0, 100000, 0, "dsaj31", "dsajUser", dec2021, 0, 0, 0], + ["dsajVideo3", 0, 0, 2, 1, "dsaj30", "dsajUser", dec2021, 0, 0, 0, dec2021AsIso], + ["dsajVideo3", 0, 0, 100000, 0, "dsaj31", "dsajUser", dec2021, 0, 0, 0, dec2021AsIso], - ["dsajVideo4", 0, 0, 100000, 0, "dsaj40", "dsajUser", dec2021, 0, 1, 0], + ["dsajVideo4", 0, 0, 100000, 0, "dsaj40", "dsajUser", dec2021, 0, 1, 0, dec2021AsIso], - ["dsajVideo5", 0, 0, 2, 0, "dsaj50", "dsajUser", dec2021, 0, 0, 0], - ["dsajVideo5", 0, 0, -1, 0, "dsaj51", "dsajUser", dec2021, 0, 0, 0], - ["dsajVideo5", 0, 0, -2, 0, "dsaj52", "dsajUser", nov2021, 0, 0, 0], - ["dsajVideo5", 0, 0, 2, 0, "dsaj53", "dsajUser", dec2021, 0, 0, 0] + ["dsajVideo5", 0, 0, 2, 0, "dsaj50", "dsajUser", dec2021, 0, 0, 0, dec2021AsIso], + ["dsajVideo5", 0, 0, -1, 0, "dsaj51", "dsajUser", dec2021, 0, 0, 0, dec2021AsIso], + ["dsajVideo5", 0, 0, -2, 0, "dsaj52", "dsajUser", nov2021, 0, 0, 0, nov2021AsIso], + ["dsajVideo5", 0, 0, 2, 0, "dsaj53", "dsajUser", dec2021, 0, 0, 0, dec2021AsIso] ]; describe("downvoteSegmentArchiveJob", () => { beforeEach(async () => { - const query = 'INSERT INTO "sponsorTimes" ("videoID", "startTime", "endTime", "votes", "locked", "UUID", "userID", "timeSubmitted", "views", "hidden", "shadowHidden") VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)'; + const query = 'INSERT INTO "sponsorTimes" ("videoID", "startTime", "endTime", "votes", "locked", "UUID", "userID", "timeSubmitted", "views", "hidden", "shadowHidden", "updatedAt") VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)'; for (const record of records) { await db.prepare("run", query, record); diff --git a/test/cases/getBranding.ts b/test/cases/getBranding.ts index c4dd0a08..855c1377 100644 --- a/test/cases/getBranding.ts +++ b/test/cases/getBranding.ts @@ -7,6 +7,7 @@ import { BrandingUUID, ThumbnailResult, TitleResult } from "../../src/types/bran import { partialDeepEquals } from "../utils/partialDeepEquals"; describe("getBranding", () => { + const isoDate = new Date().toISOString(); const videoID1 = "videoID1"; const videoID2Locked = "videoID2"; const videoID2ShadowHide = "videoID3"; @@ -42,7 +43,7 @@ describe("getBranding", () => { const thumbnailQuery = `INSERT INTO "thumbnails" ("videoID", "original", "userID", "service", "hashedVideoID", "timeSubmitted", "UUID") VALUES (?, ?, ?, ?, ?, ?, ?)`; const thumbnailTimestampsQuery = `INSERT INTO "thumbnailTimestamps" ("UUID", "timestamp") VALUES (?, ?)`; const thumbnailVotesQuery = `INSERT INTO "thumbnailVotes" ("UUID", "votes", "locked", "shadowHidden", "downvotes", "removed") VALUES (?, ?, ?, ?, ?, ?)`; - const segmentQuery = 'INSERT INTO "sponsorTimes" ("videoID", "startTime", "endTime", "votes", "locked", "UUID", "userID", "timeSubmitted", "views", "category", "actionType", "service", "videoDuration", "hidden", "shadowHidden", "description", "hashedVideoID") VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)'; + const segmentQuery = 'INSERT INTO "sponsorTimes" ("videoID", "startTime", "endTime", "votes", "locked", "UUID", "userID", "timeSubmitted", "views", "category", "actionType", "service", "videoDuration", "hidden", "shadowHidden", "description", "hashedVideoID", "updatedAt") VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)'; await Promise.all([ db.prepare("run", titleQuery, [videoID1, "title1", 0, "userID1", Service.YouTube, videoID1Hash, 1, "UUID1"]), @@ -110,8 +111,8 @@ describe("getBranding", () => { db.prepare("run", thumbnailVotesQuery, ["UUID32T", 1, 0, 1, 0, 0]) ]); - await db.prepare("run", segmentQuery, [videoIDRandomTime, 1, 11, 1, 0, "uuidbranding1", "testman", 0, 50, "sponsor", "skip", "YouTube", 100, 0, 0, "", videoIDRandomTimeHash]); - await db.prepare("run", segmentQuery, [videoIDRandomTime, 20, 33, 2, 0, "uuidbranding2", "testman", 0, 50, "intro", "skip", "YouTube", 100, 0, 0, "", videoIDRandomTimeHash]); + await db.prepare("run", segmentQuery, [videoIDRandomTime, 1, 11, 1, 0, "uuidbranding1", "testman", 0, 50, "sponsor", "skip", "YouTube", 100, 0, 0, "", videoIDRandomTimeHash, isoDate]); + await db.prepare("run", segmentQuery, [videoIDRandomTime, 20, 33, 2, 0, "uuidbranding2", "testman", 0, 50, "intro", "skip", "YouTube", 100, 0, 0, "", videoIDRandomTimeHash, isoDate]); await Promise.all([ db.prepare("run", titleQuery, [videoIDUnverified, "title1", 0, "userID1", Service.YouTube, videoIDUnverifiedHash, 1, "UUID-uv-1"]), @@ -135,13 +136,13 @@ describe("getBranding", () => { // Video duration test segments await Promise.all([ - db.prepare("run", segmentQuery, [videoIDvidDuration, 0, 1, 0, 0, "uuidvd1", "testman", 10, 0, "sponsor", "skip", "YouTube", 0, 0, 0, "", videoIDvidDurationHash]), // visible, no vid duration - db.prepare("run", segmentQuery, [videoIDvidDuration, 0, 2, -2, 0, "uuidvd2", "testman", 11, 0, "sponsor", "skip", "YouTube", 10, 0, 0, "", videoIDvidDurationHash]), // downvoted - db.prepare("run", segmentQuery, [videoIDvidDuration, 0, 3, 0, 0, "uuidvd3", "testman", 12, 0, "sponsor", "skip", "YouTube", 10.1, 1, 0, "", videoIDvidDurationHash]), // hidden - db.prepare("run", segmentQuery, [videoIDvidDuration, 0, 4, 0, 0, "uuidvd4", "testman", 13, 0, "sponsor", "skip", "YouTube", 20.1, 0, 1, "", videoIDvidDurationHash]), // shadowhidden - db.prepare("run", segmentQuery, [videoIDvidDuration, 0, 5, 0, 0, "uuidvd5", "testman", 14, 0, "sponsor", "skip", "YouTube", 21.3, 0, 0, "", videoIDvidDurationHash]), // oldest visible w/ duration, should be picked - db.prepare("run", segmentQuery, [videoIDvidDuration, 0, 6, 0, 0, "uuidvd6", "testman", 15, 0, "sponsor", "skip", "YouTube", 21.37, 0, 0, "", videoIDvidDurationHash]), // not the oldest visible - db.prepare("run", segmentQuery, [videoIDvidDuration, 0, 7, -2, 0, "uuidvd7", "testman", 16, 0, "sponsor", "skip", "YouTube", 21.38, 0, 0, "", videoIDvidDurationHash]), // downvoted, not the oldest + db.prepare("run", segmentQuery, [videoIDvidDuration, 0, 1, 0, 0, "uuidvd1", "testman", 10, 0, "sponsor", "skip", "YouTube", 0, 0, 0, "", videoIDvidDurationHash, isoDate]), // visible, no vid duration + db.prepare("run", segmentQuery, [videoIDvidDuration, 0, 2, -2, 0, "uuidvd2", "testman", 11, 0, "sponsor", "skip", "YouTube", 10, 0, 0, "", videoIDvidDurationHash, isoDate]), // downvoted + db.prepare("run", segmentQuery, [videoIDvidDuration, 0, 3, 0, 0, "uuidvd3", "testman", 12, 0, "sponsor", "skip", "YouTube", 10.1, 1, 0, "", videoIDvidDurationHash, isoDate]), // hidden + db.prepare("run", segmentQuery, [videoIDvidDuration, 0, 4, 0, 0, "uuidvd4", "testman", 13, 0, "sponsor", "skip", "YouTube", 20.1, 0, 1, "", videoIDvidDurationHash, isoDate]), // shadowhidden + db.prepare("run", segmentQuery, [videoIDvidDuration, 0, 5, 0, 0, "uuidvd5", "testman", 14, 0, "sponsor", "skip", "YouTube", 21.3, 0, 0, "", videoIDvidDurationHash, isoDate]), // oldest visible w/ duration, should be picked + db.prepare("run", segmentQuery, [videoIDvidDuration, 0, 6, 0, 0, "uuidvd6", "testman", 15, 0, "sponsor", "skip", "YouTube", 21.37, 0, 0, "", videoIDvidDurationHash, isoDate]), // not the oldest visible + db.prepare("run", segmentQuery, [videoIDvidDuration, 0, 7, -2, 0, "uuidvd7", "testman", 16, 0, "sponsor", "skip", "YouTube", 21.38, 0, 0, "", videoIDvidDurationHash, isoDate]), // downvoted, not the oldest ]); }); diff --git a/test/cases/getSavedTimeForUser.ts b/test/cases/getSavedTimeForUser.ts index b7e538a9..04f2c7bf 100644 --- a/test/cases/getSavedTimeForUser.ts +++ b/test/cases/getSavedTimeForUser.ts @@ -6,6 +6,8 @@ import assert from "assert"; // helpers const endpoint = "/api/getSavedTimeForUser"; +const isoDate = new Date().toISOString(); + const getSavedTimeForUser = (userID: string) => client({ url: endpoint, params: { userID } @@ -17,9 +19,9 @@ describe("getSavedTimeForUser", () => { const [ start, end, views ] = [1, 11, 50]; before(async () => { - const startOfQuery = 'INSERT INTO "sponsorTimes" ("videoID", "startTime", "endTime", "votes", "UUID", "userID", "timeSubmitted", "views", "shadowHidden") VALUES'; - await db.prepare("run", `${startOfQuery}(?, ?, ?, ?, ?, ?, ?, ?, ?)`, - ["getSavedTimeForUser", start, end, 2, "getSavedTimeUUID0", getHash(user1), 0, views, 0]); + const startOfQuery = 'INSERT INTO "sponsorTimes" ("videoID", "startTime", "endTime", "votes", "UUID", "userID", "timeSubmitted", "views", "shadowHidden", "updatedAt") VALUES'; + await db.prepare("run", `${startOfQuery}(?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`, + ["getSavedTimeForUser", start, end, 2, "getSavedTimeUUID0", getHash(user1), 0, views, 0, isoDate]); return; }); it("Should be able to get a saved time", (done) => { diff --git a/test/cases/getSearchSegments.ts b/test/cases/getSearchSegments.ts index 6dbef4f5..81a7ec93 100644 --- a/test/cases/getSearchSegments.ts +++ b/test/cases/getSearchSegments.ts @@ -4,33 +4,34 @@ import assert from "assert"; describe("getSearchSegments", () => { const endpoint = "/api/searchSegments"; + const isoDate = new Date().toISOString(); before(async () => { - const query = 'INSERT INTO "sponsorTimes" ("videoID", "startTime", "endTime", "votes", "views", "locked", "hidden", "shadowHidden", "timeSubmitted", "UUID", "userID", "category", "actionType") VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)'; - await db.prepare("run", query, ["searchTest0", 0, 1, 2, 0, 0, 0, 0, 1, "search-normal", "searchTestUser", "sponsor", "skip"]); - await db.prepare("run", query, ["searchTest0", 0, 2, -2, 0, 0, 0, 0, 2, "search-downvote", "searchTestUser", "selfpromo", "skip",]); - await db.prepare("run", query, ["searchTest0", 0, 3, 1, 0, 1, 0, 0, 3, "search-locked", "searchTestUser", "interaction", "skip"]); - await db.prepare("run", query, ["searchTest0", 0, 4, 1, 0, 0, 1, 0, 4, "search-hidden", "searchTestUser", "sponsor", "skip"]); - await db.prepare("run", query, ["searchTest0", 0, 5, 1, 0, 0, 0, 1, 5, "search-shadowhidden", "searchTestUser", "sponsor", "skip"]); - await db.prepare("run", query, ["searchTest1", 1, 2, 1, 5, 0, 0, 0, 6, "search-lowview", "searchTestUser", "sponsor", "skip"]); - await db.prepare("run", query, ["searchTest1", 1, 3, 1, 50, 0, 0, 0, 7, "search-highview", "searchTestUser", "sponsor", "skip"]); - await db.prepare("run", query, ["searchTest2", 1, 4, -1, 0, 0, 0, 0, 8, "search-lowvote", "searchTestUser", "sponsor", "skip"]); - await db.prepare("run", query, ["searchTest2", 2, 3, 0, 0, 0, 0, 0, 9, "search-zerovote", "searchTestUser", "sponsor", "skip"]); - await db.prepare("run", query, ["searchTest2", 2, 4, 50, 0, 0, 0, 0, 10, "search-highvote", "searchTestUser", "sponsor", "skip"]); + const query = 'INSERT INTO "sponsorTimes" ("videoID", "startTime", "endTime", "votes", "views", "locked", "hidden", "shadowHidden", "timeSubmitted", "UUID", "userID", "category", "actionType", "updatedAt") VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)'; + await db.prepare("run", query, ["searchTest0", 0, 1, 2, 0, 0, 0, 0, 1, "search-normal", "searchTestUser", "sponsor", "skip", isoDate]); + await db.prepare("run", query, ["searchTest0", 0, 2, -2, 0, 0, 0, 0, 2, "search-downvote", "searchTestUser", "selfpromo", "skip", isoDate]); + await db.prepare("run", query, ["searchTest0", 0, 3, 1, 0, 1, 0, 0, 3, "search-locked", "searchTestUser", "interaction", "skip", isoDate]); + await db.prepare("run", query, ["searchTest0", 0, 4, 1, 0, 0, 1, 0, 4, "search-hidden", "searchTestUser", "sponsor", "skip", isoDate]); + await db.prepare("run", query, ["searchTest0", 0, 5, 1, 0, 0, 0, 1, 5, "search-shadowhidden", "searchTestUser", "sponsor", "skip", isoDate]); + await db.prepare("run", query, ["searchTest1", 1, 2, 1, 5, 0, 0, 0, 6, "search-lowview", "searchTestUser", "sponsor", "skip", isoDate]); + await db.prepare("run", query, ["searchTest1", 1, 3, 1, 50, 0, 0, 0, 7, "search-highview", "searchTestUser", "sponsor", "skip", isoDate]); + await db.prepare("run", query, ["searchTest2", 1, 4, -1, 0, 0, 0, 0, 8, "search-lowvote", "searchTestUser", "sponsor", "skip", isoDate]); + await db.prepare("run", query, ["searchTest2", 2, 3, 0, 0, 0, 0, 0, 9, "search-zerovote", "searchTestUser", "sponsor", "skip", isoDate]); + await db.prepare("run", query, ["searchTest2", 2, 4, 50, 0, 0, 0, 0, 10, "search-highvote", "searchTestUser", "sponsor", "skip", isoDate]); // page - await db.prepare("run", query, ["searchTest4", 3, 4, 1, 0, 0, 0, 0, 10, "search-page1-1", "searchTestUser", "sponsor", "skip"]); - await db.prepare("run", query, ["searchTest4", 3, 5, 1, 0, 0, 0, 0, 11, "search-page1-2", "searchTestUser", "sponsor", "skip"]); - await db.prepare("run", query, ["searchTest4", 3, 6, 1, 0, 0, 0, 0, 12, "search-page1-3", "searchTestUser", "sponsor", "skip"]); - await db.prepare("run", query, ["searchTest4", 3, 7, 1, 0, 0, 0, 0, 13, "search-page1-4", "searchTestUser", "sponsor", "skip"]); - await db.prepare("run", query, ["searchTest4", 3, 8, 1, 0, 0, 0, 0, 14, "search-page1-5", "searchTestUser", "sponsor", "skip"]); - await db.prepare("run", query, ["searchTest4", 3, 9, 1, 0, 0, 0, 0, 15, "search-page1-6", "searchTestUser", "sponsor", "skip"]); - await db.prepare("run", query, ["searchTest4", 3, 10, 1, 0, 0, 0, 0, 16, "search-page1-7", "searchTestUser", "sponsor", "skip"]); - await db.prepare("run", query, ["searchTest4", 3, 11, 1, 0, 0, 0, 0, 17, "search-page1-8", "searchTestUser", "sponsor", "skip"]); - await db.prepare("run", query, ["searchTest4", 3, 12, 1, 0, 0, 0, 0, 18, "search-page1-9", "searchTestUser", "sponsor", "skip"]); - await db.prepare("run", query, ["searchTest4", 3, 13, 1, 0, 0, 0, 0, 19, "search-page1-10", "searchTestUser", "sponsor", "skip"]); - await db.prepare("run", query, ["searchTest4", 3, 14, 1, 0, 0, 0, 0, 20, "search-page2-1", "searchTestUser", "sponsor", "skip"]); - await db.prepare("run", query, ["searchTest4", 3, 15, 1, 0, 0, 0, 0, 21, "search-page2-2", "searchTestUser", "sponsor", "skip"]); + await db.prepare("run", query, ["searchTest4", 3, 4, 1, 0, 0, 0, 0, 10, "search-page1-1", "searchTestUser", "sponsor", "skip", isoDate]); + await db.prepare("run", query, ["searchTest4", 3, 5, 1, 0, 0, 0, 0, 11, "search-page1-2", "searchTestUser", "sponsor", "skip", isoDate]); + await db.prepare("run", query, ["searchTest4", 3, 6, 1, 0, 0, 0, 0, 12, "search-page1-3", "searchTestUser", "sponsor", "skip", isoDate]); + await db.prepare("run", query, ["searchTest4", 3, 7, 1, 0, 0, 0, 0, 13, "search-page1-4", "searchTestUser", "sponsor", "skip", isoDate]); + await db.prepare("run", query, ["searchTest4", 3, 8, 1, 0, 0, 0, 0, 14, "search-page1-5", "searchTestUser", "sponsor", "skip", isoDate]); + await db.prepare("run", query, ["searchTest4", 3, 9, 1, 0, 0, 0, 0, 15, "search-page1-6", "searchTestUser", "sponsor", "skip", isoDate]); + await db.prepare("run", query, ["searchTest4", 3, 10, 1, 0, 0, 0, 0, 16, "search-page1-7", "searchTestUser", "sponsor", "skip", isoDate]); + await db.prepare("run", query, ["searchTest4", 3, 11, 1, 0, 0, 0, 0, 17, "search-page1-8", "searchTestUser", "sponsor", "skip", isoDate]); + await db.prepare("run", query, ["searchTest4", 3, 12, 1, 0, 0, 0, 0, 18, "search-page1-9", "searchTestUser", "sponsor", "skip", isoDate]); + await db.prepare("run", query, ["searchTest4", 3, 13, 1, 0, 0, 0, 0, 19, "search-page1-10", "searchTestUser", "sponsor", "skip", isoDate]); + await db.prepare("run", query, ["searchTest4", 3, 14, 1, 0, 0, 0, 0, 20, "search-page2-1", "searchTestUser", "sponsor", "skip", isoDate]); + await db.prepare("run", query, ["searchTest4", 3, 15, 1, 0, 0, 0, 0, 21, "search-page2-2", "searchTestUser", "sponsor", "skip", isoDate]); // test all values - await db.prepare("run", query, ["searchTest5", 0, 10, 1, 1, 1, 0, 0, 22, "search-values", "searchTestUser", "filler", "mute"]); + await db.prepare("run", query, ["searchTest5", 0, 10, 1, 1, 1, 0, 0, 22, "search-values", "searchTestUser", "filler", "mute", isoDate]); return; }); diff --git a/test/cases/getSkipSegments.ts b/test/cases/getSkipSegments.ts index 275f2310..37d8098e 100644 --- a/test/cases/getSkipSegments.ts +++ b/test/cases/getSkipSegments.ts @@ -5,31 +5,32 @@ import { client } from "../utils/httpClient"; describe("getSkipSegments", () => { const endpoint = "/api/skipSegments"; + const isoDate = new Date().toISOString(); before(async () => { - const query = 'INSERT INTO "sponsorTimes" ("videoID", "startTime", "endTime", "votes", "locked", "UUID", "userID", "timeSubmitted", "views", "category", "actionType", "service", "videoDuration", "hidden", "shadowHidden", "description") VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)'; - await db.prepare("run", query, ["getSkipSegmentID0", 1, 11, 1, 0, "uuid01", "testman", 0, 50, "sponsor", "skip", "YouTube", 100, 0, 0, ""]); - await db.prepare("run", query, ["getSkipSegmentID0", 12, 14, 2, 0, "uuid02", "testman", 0, 50, "sponsor", "mute", "YouTube", 100, 0, 0, ""]); - await db.prepare("run", query, ["getSkipSegmentID0", 20, 33, 2, 0, "uuid03", "testman", 0, 50, "intro", "skip", "YouTube", 101, 0, 0, ""]); - await db.prepare("run", query, ["getSkipSegmentID1", 1, 11, 2, 0, "uuid10", "testman", 0, 50, "sponsor", "skip", "PeerTube", 120, 0, 0, ""]); - await db.prepare("run", query, ["getSkipSegmentID2", 1, 11, 2, 1, "uuid20", "testman", 0, 50, "sponsor", "skip", "YouTube", 140, 0, 0, ""]); - await db.prepare("run", query, ["getSkipSegmentID3", 1, 11, 2, 0, "uuid30", "testman", 0, 50, "sponsor", "skip", "YouTube", 200, 0, 0, ""]); - await db.prepare("run", query, ["getSkipSegmentID3", 7, 22, -3, 0, "uuid31", "testman", 0, 50, "sponsor", "skip", "YouTube", 300, 0, 0, ""]); - await db.prepare("run", query, ["getSkipSegmentMultiple", 1, 11, 2, 0, "uuid40", "testman", 0, 50, "intro", "skip", "YouTube", 400, 0, 0, ""]); - await db.prepare("run", query, ["getSkipSegmentMultiple", 20, 33, 2, 0, "uuid41", "testman", 0, 50, "intro", "skip", "YouTube", 500, 0, 0, ""]); - await db.prepare("run", query, ["getSkipSegmentLocked", 20, 33, 2, 1, "uuid50", "testman", 0, 50, "intro", "skip", "YouTube", 230, 0, 0, ""]); - await db.prepare("run", query, ["getSkipSegmentLocked", 20, 34, 100000, 0, "uuid51", "testman", 0, 50, "intro", "skip", "YouTube", 190, 0, 0, ""]); - await db.prepare("run", query, ["getSkipSegmentID6", 20, 34, 100000, 0, "uuid60", "testman", 0, 50, "sponsor", "skip", "YouTube", 190, 1, 0, ""]); - await db.prepare("run", query, ["requiredSegmentVid", 60, 70, 2, 0, "requiredSegmentVid1", "testman", 0, 50, "sponsor", "skip", "YouTube", 0, 0, 0, ""]); - await db.prepare("run", query, ["requiredSegmentVid", 60, 70, -2, 0, "requiredSegmentVid2", "testman", 0, 50, "sponsor", "skip", "YouTube", 0, 0, 0, ""]); - await db.prepare("run", query, ["requiredSegmentVid", 80, 90, -2, 0, "requiredSegmentVid3", "testman", 0, 50, "sponsor", "skip", "YouTube", 0, 0, 0, ""]); - await db.prepare("run", query, ["requiredSegmentVid", 80, 90, 2, 0, "requiredSegmentVid4", "testman", 0, 50, "sponsor", "skip", "YouTube", 0, 0, 0, ""]); - await db.prepare("run", query, ["requiredSegmentVid", 60, 70, 0, 0, "requiredSegmentVid-hidden", "testman", 0, 50, "sponsor", "skip", "YouTube", 0, 1, 0, ""]); - await db.prepare("run", query, ["requiredSegmentVid", 80, 90, 0, 0, "requiredSegmentVid-shadowhidden", "testman", 0, 50, "sponsor", "skip", "YouTube", 0, 0, 1, ""]); - await db.prepare("run", query, ["chapterVid", 60, 80, 2, 0, "chapterVid-1", "testman", 0, 50, "chapter", "chapter", "YouTube", 0, 0, 0, "Chapter 1"]); - await db.prepare("run", query, ["chapterVid", 70, 75, 2, 0, "chapterVid-2", "testman", 0, 50, "chapter", "chapter", "YouTube", 0, 0, 0, "Chapter 2"]); - await db.prepare("run", query, ["chapterVid", 71, 75, 2, 0, "chapterVid-3", "testman", 0, 50, "chapter", "chapter", "YouTube", 0, 0, 0, "Chapter 3"]); - await db.prepare("run", query, ["requiredSegmentHashVid", 10, 20, -2, 0, "1d04b98f48e8f8bcc15c6ae5ac050801cd6dcfd428fb5f9e65c4e16e7807340fa", "testman", 0, 50, "sponsor", "skip", "YouTube", 0, 0, 0, ""]); - await db.prepare("run", query, ["requiredSegmentHashVid", 20, 30, -2, 0, "1ebde8e8ae03096b6c866aa2c8cc7ee1d720ca1fca27bea3f39a6a1b876577e71", "testman", 0, 50, "sponsor", "skip", "YouTube", 0, 0, 0, ""]); + const query = 'INSERT INTO "sponsorTimes" ("videoID", "startTime", "endTime", "votes", "locked", "UUID", "userID", "timeSubmitted", "views", "category", "actionType", "service", "videoDuration", "hidden", "shadowHidden", "description", "updatedAt") VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)'; + await db.prepare("run", query, ["getSkipSegmentID0", 1, 11, 1, 0, "uuid01", "testman", 0, 50, "sponsor", "skip", "YouTube", 100, 0, 0, "", isoDate]); + await db.prepare("run", query, ["getSkipSegmentID0", 12, 14, 2, 0, "uuid02", "testman", 0, 50, "sponsor", "mute", "YouTube", 100, 0, 0, "", isoDate]); + await db.prepare("run", query, ["getSkipSegmentID0", 20, 33, 2, 0, "uuid03", "testman", 0, 50, "intro", "skip", "YouTube", 101, 0, 0, "", isoDate]); + await db.prepare("run", query, ["getSkipSegmentID1", 1, 11, 2, 0, "uuid10", "testman", 0, 50, "sponsor", "skip", "PeerTube", 120, 0, 0, "", isoDate]); + await db.prepare("run", query, ["getSkipSegmentID2", 1, 11, 2, 1, "uuid20", "testman", 0, 50, "sponsor", "skip", "YouTube", 140, 0, 0, "", isoDate]); + await db.prepare("run", query, ["getSkipSegmentID3", 1, 11, 2, 0, "uuid30", "testman", 0, 50, "sponsor", "skip", "YouTube", 200, 0, 0, "", isoDate]); + await db.prepare("run", query, ["getSkipSegmentID3", 7, 22, -3, 0, "uuid31", "testman", 0, 50, "sponsor", "skip", "YouTube", 300, 0, 0, "", isoDate]); + await db.prepare("run", query, ["getSkipSegmentMultiple", 1, 11, 2, 0, "uuid40", "testman", 0, 50, "intro", "skip", "YouTube", 400, 0, 0, "", isoDate]); + await db.prepare("run", query, ["getSkipSegmentMultiple", 20, 33, 2, 0, "uuid41", "testman", 0, 50, "intro", "skip", "YouTube", 500, 0, 0, "", isoDate]); + await db.prepare("run", query, ["getSkipSegmentLocked", 20, 33, 2, 1, "uuid50", "testman", 0, 50, "intro", "skip", "YouTube", 230, 0, 0, "", isoDate]); + await db.prepare("run", query, ["getSkipSegmentLocked", 20, 34, 100000, 0, "uuid51", "testman", 0, 50, "intro", "skip", "YouTube", 190, 0, 0, "", isoDate]); + await db.prepare("run", query, ["getSkipSegmentID6", 20, 34, 100000, 0, "uuid60", "testman", 0, 50, "sponsor", "skip", "YouTube", 190, 1, 0, "", isoDate]); + await db.prepare("run", query, ["requiredSegmentVid", 60, 70, 2, 0, "requiredSegmentVid1", "testman", 0, 50, "sponsor", "skip", "YouTube", 0, 0, 0, "", isoDate]); + await db.prepare("run", query, ["requiredSegmentVid", 60, 70, -2, 0, "requiredSegmentVid2", "testman", 0, 50, "sponsor", "skip", "YouTube", 0, 0, 0, "", isoDate]); + await db.prepare("run", query, ["requiredSegmentVid", 80, 90, -2, 0, "requiredSegmentVid3", "testman", 0, 50, "sponsor", "skip", "YouTube", 0, 0, 0, "", isoDate]); + await db.prepare("run", query, ["requiredSegmentVid", 80, 90, 2, 0, "requiredSegmentVid4", "testman", 0, 50, "sponsor", "skip", "YouTube", 0, 0, 0, "", isoDate]); + await db.prepare("run", query, ["requiredSegmentVid", 60, 70, 0, 0, "requiredSegmentVid-hidden", "testman", 0, 50, "sponsor", "skip", "YouTube", 0, 1, 0, "", isoDate]); + await db.prepare("run", query, ["requiredSegmentVid", 80, 90, 0, 0, "requiredSegmentVid-shadowhidden", "testman", 0, 50, "sponsor", "skip", "YouTube", 0, 0, 1, "", isoDate]); + await db.prepare("run", query, ["chapterVid", 60, 80, 2, 0, "chapterVid-1", "testman", 0, 50, "chapter", "chapter", "YouTube", 0, 0, 0, "Chapter 1", isoDate]); + await db.prepare("run", query, ["chapterVid", 70, 75, 2, 0, "chapterVid-2", "testman", 0, 50, "chapter", "chapter", "YouTube", 0, 0, 0, "Chapter 2", isoDate]); + await db.prepare("run", query, ["chapterVid", 71, 75, 2, 0, "chapterVid-3", "testman", 0, 50, "chapter", "chapter", "YouTube", 0, 0, 0, "Chapter 3", isoDate]); + await db.prepare("run", query, ["requiredSegmentHashVid", 10, 20, -2, 0, "1d04b98f48e8f8bcc15c6ae5ac050801cd6dcfd428fb5f9e65c4e16e7807340fa", "testman", 0, 50, "sponsor", "skip", "YouTube", 0, 0, 0, "", isoDate]); + await db.prepare("run", query, ["requiredSegmentHashVid", 20, 30, -2, 0, "1ebde8e8ae03096b6c866aa2c8cc7ee1d720ca1fca27bea3f39a6a1b876577e71", "testman", 0, 50, "sponsor", "skip", "YouTube", 0, 0, 0, "", isoDate]); return; }); diff --git a/test/cases/getSkipSegmentsByHash.ts b/test/cases/getSkipSegmentsByHash.ts index 3129f91f..3926b88b 100644 --- a/test/cases/getSkipSegmentsByHash.ts +++ b/test/cases/getSkipSegmentsByHash.ts @@ -19,40 +19,41 @@ describe("getSkipSegmentsByHash", () => { const differentCategoryVidHash = "7fac44d1ee3257ec7f18953e2b5f991828de6854ad57193d1027c530981a89c0"; const nonMusicOverlapVidHash = "306151f778f9bfd19872b3ccfc83cbab37c4f370717436bfd85e0a624cd8ba3c"; const fullCategoryVidHash = "278fa987eebfe07ae3a4a60cf0663989ad874dd0c1f0430831d63c2001567e6f"; + const isoDate = new Date().toISOString(); before(async () => { - const query = 'INSERT INTO "sponsorTimes" ("videoID", "startTime", "endTime", "votes", "locked", "UUID", "userID", "timeSubmitted", views, category, "actionType", "service", "hidden", "shadowHidden", "hashedVideoID", "description") VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)'; - await db.prepare("run", query, ["getSegmentsByHash-0", 1, 10, 2, 0, "getSegmentsByHash-01", "testman", 0, 50, "sponsor", "skip", "YouTube", 0, 0, getSegmentsByHash0Hash, ""]); - await db.prepare("run", query, ["getSegmentsByHash-0", 1, 10, 2, 0, "getSegmentsByHash-02", "testman", 0, 50, "sponsor", "skip", "PeerTube", 0, 0, getSegmentsByHash0Hash, ""]); - await db.prepare("run", query, ["getSegmentsByHash-0", 20, 30, 2, 0, "getSegmentsByHash-03", "testman", 100, 150, "intro", "skip", "YouTube", 0, 0, getSegmentsByHash0Hash, ""]); - await db.prepare("run", query, ["getSegmentsByHash-0", 40, 50, 2, 0, "getSegmentsByHash-04", "testman", 0, 50, "sponsor", "mute", "YouTube", 0, 0, getSegmentsByHash0Hash, ""]); - await db.prepare("run", query, ["getSegmentsByHash-noMatchHash", 40, 50, 2, 0, "getSegmentsByHash-noMatchHash", "testman", 0, 50, "sponsor", "skip", "YouTube", 0, 0, "fdaffnoMatchHash", ""]); - await db.prepare("run", query, ["getSegmentsByHash-1", 60, 70, 2, 0, "getSegmentsByHash-1", "testman", 0, 50, "sponsor", "skip", "YouTube", 0, 0, "3272fa85ee0927f6073ef6f07ad5f3146047c1abba794cfa364d65ab9921692b", ""]); - await db.prepare("run", query, ["onlyHidden", 60, 70, 2, 0, "onlyHidden", "testman", 0, 50, "sponsor", "skip", "YouTube", 1, 0, "f3a199e1af001d716cdc6599360e2b062c2d2b3fa2885f6d9d2fd741166cbbd3", ""]); - await db.prepare("run", query, ["highlightVid", 60, 60, 2, 0, "highlightVid-1", "testman", 0, 50, "poi_highlight", "poi", "YouTube", 0, 0, getHash("highlightVid", 1), ""]); - await db.prepare("run", query, ["highlightVid", 70, 70, 2, 0, "highlightVid-2", "testman", 0, 50, "poi_highlight", "poi", "YouTube", 0, 0, getHash("highlightVid", 1), ""]); - await db.prepare("run", query, ["requiredSegmentVid", 60, 70, 2, 0, "requiredSegmentVid-1", "testman", 0, 50, "sponsor", "skip", "YouTube", 0, 0, requiredSegmentVidHash, ""]); - await db.prepare("run", query, ["requiredSegmentVid", 60, 70, -2, 0, "requiredSegmentVid-2", "testman", 0, 50, "sponsor", "skip", "YouTube", 0, 0, requiredSegmentVidHash, ""]); - await db.prepare("run", query, ["requiredSegmentVid", 80, 90, -2, 0, "requiredSegmentVid-3", "testman", 0, 50, "sponsor", "skip", "YouTube", 0, 0, requiredSegmentVidHash, ""]); - await db.prepare("run", query, ["requiredSegmentVid", 80, 90, 2, 0, "requiredSegmentVid-4", "testman", 0, 50, "sponsor", "skip", "YouTube", 0, 0, requiredSegmentVidHash, ""]); - await db.prepare("run", query, ["chapterVid-hash", 60, 80, 2, 0, "chapterVid-hash-1", "testman", 0, 50, "chapter", "chapter", "YouTube", 0, 0, getHash("chapterVid-hash", 1), "Chapter 1"]); //7258 - await db.prepare("run", query, ["chapterVid-hash", 70, 75, 2, 0, "chapterVid-hash-2", "testman", 0, 50, "chapter", "chapter", "YouTube", 0, 0, getHash("chapterVid-hash", 1), "Chapter 2"]); //7258 - await db.prepare("run", query, ["chapterVid-hash", 71, 75, 2, 0, "chapterVid-hash-3", "testman", 0, 50, "chapter", "chapter", "YouTube", 0, 0, getHash("chapterVid-hash", 1), "Chapter 3"]); //7258 - await db.prepare("run", query, ["longMuteVid-hash", 40, 45, 2, 0, "longMuteVid-hash-1", "testman", 0, 50, "sponsor", "skip", "YouTube", 0, 0, getHash("longMuteVid-hash", 1), ""]); //6613 - await db.prepare("run", query, ["longMuteVid-hash", 30, 35, 2, 0, "longMuteVid-hash-2", "testman", 0, 50, "sponsor", "skip", "YouTube", 0, 0, getHash("longMuteVid-hash", 1), ""]); //6613 - await db.prepare("run", query, ["longMuteVid-hash", 2, 80, 2, 0, "longMuteVid-hash-3", "testman", 0, 50, "sponsor", "mute", "YouTube", 0, 0, getHash("longMuteVid-hash", 1), ""]); //6613 - await db.prepare("run", query, ["longMuteVid-hash", 3, 78, 2, 0, "longMuteVid-hash-4", "testman", 0, 50, "sponsor", "mute", "YouTube", 0, 0, getHash("longMuteVid-hash", 1), ""]); //6613 - await db.prepare("run", query, ["longMuteVid-2-hash", 1, 15, 2, 0, "longMuteVid-2-hash-1", "testman", 0, 50, "sponsor", "mute", "YouTube", 0, 0, getHash("longMuteVid-2-hash", 1), ""]); //ab0c - await db.prepare("run", query, ["longMuteVid-2-hash", 30, 35, 2, 0, "longMuteVid-2-hash-2", "testman", 0, 50, "sponsor", "skip", "YouTube", 0, 0, getHash("longMuteVid-2-hash", 1), ""]); //ab0c - await db.prepare("run", query, ["longMuteVid-2-hash", 2, 80, 2, 0, "longMuteVid-2-hash-3", "testman", 0, 50, "sponsor", "mute", "YouTube", 0, 0, getHash("longMuteVid-2-hash", 1), ""]); //ab0c - await db.prepare("run", query, ["longMuteVid-2-hash", 3, 78, 2, 0, "longMuteVid-2-hash-4", "testman", 0, 50, "sponsor", "mute", "YouTube", 0, 0, getHash("longMuteVid-2-hash", 1), ""]); //ab0c - await db.prepare("run", query, ["requiredSegmentHashVid", 10, 20, -2, 0, "fbf0af454059733c8822f6a4ac8ec568e0787f8c0a5ee915dd5b05e0d7a9a388", "testman", 0, 50, "sponsor", "skip", "YouTube", 0, 0, requiredSegmentHashVidHash, ""]); - await db.prepare("run", query, ["requiredSegmentHashVid", 20, 30, -2, 0, "7e1ebc5194551d2d0a606d64f675e5a14952e4576b2959f8c9d51e316c14f8da", "testman", 0, 50, "sponsor", "skip", "YouTube", 0, 0, requiredSegmentHashVidHash, ""]); - await db.prepare("run", query, ["differentCategoryVid", 60, 70, 2, 0, "differentCategoryVid-1", "testman", 0, 50, "sponsor", "skip", "YouTube", 0, 0, differentCategoryVidHash, ""]); - await db.prepare("run", query, ["differentCategoryVid", 60, 70, 2, 1, "differentCategoryVid-2", "testman", 0, 50, "intro", "skip", "YouTube", 0, 0, differentCategoryVidHash, ""]); - await db.prepare("run", query, ["nonMusicOverlapVid", 60, 70, 2, 0, "nonMusicOverlapVid-1", "testman", 0, 50, "sponsor", "skip", "YouTube", 0, 0, nonMusicOverlapVidHash, ""]); - await db.prepare("run", query, ["nonMusicOverlapVid", 60, 70, 2, 1, "nonMusicOverlapVid-2", "testman", 0, 50, "music_offtopic", "skip", "YouTube", 0, 0, nonMusicOverlapVidHash, ""]); - await db.prepare("run", query, ["fullCategoryVid", 60, 70, 2, 0, "fullCategoryVid-1", "testman", 0, 50, "sponsor", "full", "YouTube", 0, 0, fullCategoryVidHash, ""]); - await db.prepare("run", query, ["fullCategoryVid", 60, 70, 2, 1, "fullCategoryVid-2", "testman", 0, 50, "selfpromo", "full", "YouTube", 0, 0, fullCategoryVidHash, ""]); + const query = 'INSERT INTO "sponsorTimes" ("videoID", "startTime", "endTime", "votes", "locked", "UUID", "userID", "timeSubmitted", views, category, "actionType", "service", "hidden", "shadowHidden", "hashedVideoID", "description", "updatedAt") VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)'; + await db.prepare("run", query, ["getSegmentsByHash-0", 1, 10, 2, 0, "getSegmentsByHash-01", "testman", 0, 50, "sponsor", "skip", "YouTube", 0, 0, getSegmentsByHash0Hash, "", isoDate]); + await db.prepare("run", query, ["getSegmentsByHash-0", 1, 10, 2, 0, "getSegmentsByHash-02", "testman", 0, 50, "sponsor", "skip", "PeerTube", 0, 0, getSegmentsByHash0Hash, "", isoDate]); + await db.prepare("run", query, ["getSegmentsByHash-0", 20, 30, 2, 0, "getSegmentsByHash-03", "testman", 100, 150, "intro", "skip", "YouTube", 0, 0, getSegmentsByHash0Hash, "", isoDate]); + await db.prepare("run", query, ["getSegmentsByHash-0", 40, 50, 2, 0, "getSegmentsByHash-04", "testman", 0, 50, "sponsor", "mute", "YouTube", 0, 0, getSegmentsByHash0Hash, "", isoDate]); + await db.prepare("run", query, ["getSegmentsByHash-noMatchHash", 40, 50, 2, 0, "getSegmentsByHash-noMatchHash", "testman", 0, 50, "sponsor", "skip", "YouTube", 0, 0, "fdaffnoMatchHash", "", isoDate]); + await db.prepare("run", query, ["getSegmentsByHash-1", 60, 70, 2, 0, "getSegmentsByHash-1", "testman", 0, 50, "sponsor", "skip", "YouTube", 0, 0, "3272fa85ee0927f6073ef6f07ad5f3146047c1abba794cfa364d65ab9921692b", "", isoDate]); + await db.prepare("run", query, ["onlyHidden", 60, 70, 2, 0, "onlyHidden", "testman", 0, 50, "sponsor", "skip", "YouTube", 1, 0, "f3a199e1af001d716cdc6599360e2b062c2d2b3fa2885f6d9d2fd741166cbbd3", "", isoDate]); + await db.prepare("run", query, ["highlightVid", 60, 60, 2, 0, "highlightVid-1", "testman", 0, 50, "poi_highlight", "poi", "YouTube", 0, 0, getHash("highlightVid", 1), "", isoDate]); + await db.prepare("run", query, ["highlightVid", 70, 70, 2, 0, "highlightVid-2", "testman", 0, 50, "poi_highlight", "poi", "YouTube", 0, 0, getHash("highlightVid", 1), "", isoDate]); + await db.prepare("run", query, ["requiredSegmentVid", 60, 70, 2, 0, "requiredSegmentVid-1", "testman", 0, 50, "sponsor", "skip", "YouTube", 0, 0, requiredSegmentVidHash, "", isoDate]); + await db.prepare("run", query, ["requiredSegmentVid", 60, 70, -2, 0, "requiredSegmentVid-2", "testman", 0, 50, "sponsor", "skip", "YouTube", 0, 0, requiredSegmentVidHash, "", isoDate]); + await db.prepare("run", query, ["requiredSegmentVid", 80, 90, -2, 0, "requiredSegmentVid-3", "testman", 0, 50, "sponsor", "skip", "YouTube", 0, 0, requiredSegmentVidHash, "", isoDate]); + await db.prepare("run", query, ["requiredSegmentVid", 80, 90, 2, 0, "requiredSegmentVid-4", "testman", 0, 50, "sponsor", "skip", "YouTube", 0, 0, requiredSegmentVidHash, "", isoDate]); + await db.prepare("run", query, ["chapterVid-hash", 60, 80, 2, 0, "chapterVid-hash-1", "testman", 0, 50, "chapter", "chapter", "YouTube", 0, 0, getHash("chapterVid-hash", 1), "Chapter 1", isoDate]); //7258 + await db.prepare("run", query, ["chapterVid-hash", 70, 75, 2, 0, "chapterVid-hash-2", "testman", 0, 50, "chapter", "chapter", "YouTube", 0, 0, getHash("chapterVid-hash", 1), "Chapter 2", isoDate]); //7258 + await db.prepare("run", query, ["chapterVid-hash", 71, 75, 2, 0, "chapterVid-hash-3", "testman", 0, 50, "chapter", "chapter", "YouTube", 0, 0, getHash("chapterVid-hash", 1), "Chapter 3", isoDate]); //7258 + await db.prepare("run", query, ["longMuteVid-hash", 40, 45, 2, 0, "longMuteVid-hash-1", "testman", 0, 50, "sponsor", "skip", "YouTube", 0, 0, getHash("longMuteVid-hash", 1), "", isoDate]); //6613 + await db.prepare("run", query, ["longMuteVid-hash", 30, 35, 2, 0, "longMuteVid-hash-2", "testman", 0, 50, "sponsor", "skip", "YouTube", 0, 0, getHash("longMuteVid-hash", 1), "", isoDate]); //6613 + await db.prepare("run", query, ["longMuteVid-hash", 2, 80, 2, 0, "longMuteVid-hash-3", "testman", 0, 50, "sponsor", "mute", "YouTube", 0, 0, getHash("longMuteVid-hash", 1), "", isoDate]); //6613 + await db.prepare("run", query, ["longMuteVid-hash", 3, 78, 2, 0, "longMuteVid-hash-4", "testman", 0, 50, "sponsor", "mute", "YouTube", 0, 0, getHash("longMuteVid-hash", 1), "", isoDate]); //6613 + await db.prepare("run", query, ["longMuteVid-2-hash", 1, 15, 2, 0, "longMuteVid-2-hash-1", "testman", 0, 50, "sponsor", "mute", "YouTube", 0, 0, getHash("longMuteVid-2-hash", 1), "", isoDate]); //ab0c + await db.prepare("run", query, ["longMuteVid-2-hash", 30, 35, 2, 0, "longMuteVid-2-hash-2", "testman", 0, 50, "sponsor", "skip", "YouTube", 0, 0, getHash("longMuteVid-2-hash", 1), "", isoDate]); //ab0c + await db.prepare("run", query, ["longMuteVid-2-hash", 2, 80, 2, 0, "longMuteVid-2-hash-3", "testman", 0, 50, "sponsor", "mute", "YouTube", 0, 0, getHash("longMuteVid-2-hash", 1), "", isoDate]); //ab0c + await db.prepare("run", query, ["longMuteVid-2-hash", 3, 78, 2, 0, "longMuteVid-2-hash-4", "testman", 0, 50, "sponsor", "mute", "YouTube", 0, 0, getHash("longMuteVid-2-hash", 1), "", isoDate]); //ab0c + await db.prepare("run", query, ["requiredSegmentHashVid", 10, 20, -2, 0, "fbf0af454059733c8822f6a4ac8ec568e0787f8c0a5ee915dd5b05e0d7a9a388", "testman", 0, 50, "sponsor", "skip", "YouTube", 0, 0, requiredSegmentHashVidHash, "", isoDate]); + await db.prepare("run", query, ["requiredSegmentHashVid", 20, 30, -2, 0, "7e1ebc5194551d2d0a606d64f675e5a14952e4576b2959f8c9d51e316c14f8da", "testman", 0, 50, "sponsor", "skip", "YouTube", 0, 0, requiredSegmentHashVidHash, "", isoDate]); + await db.prepare("run", query, ["differentCategoryVid", 60, 70, 2, 0, "differentCategoryVid-1", "testman", 0, 50, "sponsor", "skip", "YouTube", 0, 0, differentCategoryVidHash, "", isoDate]); + await db.prepare("run", query, ["differentCategoryVid", 60, 70, 2, 1, "differentCategoryVid-2", "testman", 0, 50, "intro", "skip", "YouTube", 0, 0, differentCategoryVidHash, "", isoDate]); + await db.prepare("run", query, ["nonMusicOverlapVid", 60, 70, 2, 0, "nonMusicOverlapVid-1", "testman", 0, 50, "sponsor", "skip", "YouTube", 0, 0, nonMusicOverlapVidHash, "", isoDate]); + await db.prepare("run", query, ["nonMusicOverlapVid", 60, 70, 2, 1, "nonMusicOverlapVid-2", "testman", 0, 50, "music_offtopic", "skip", "YouTube", 0, 0, nonMusicOverlapVidHash, "", isoDate]); + await db.prepare("run", query, ["fullCategoryVid", 60, 70, 2, 0, "fullCategoryVid-1", "testman", 0, 50, "sponsor", "full", "YouTube", 0, 0, fullCategoryVidHash, "", isoDate]); + await db.prepare("run", query, ["fullCategoryVid", 60, 70, 2, 1, "fullCategoryVid-2", "testman", 0, 50, "selfpromo", "full", "YouTube", 0, 0, fullCategoryVidHash, "", isoDate]); }); it("Should be able to get a 200", (done) => { diff --git a/test/cases/getTopCategoryUsers.ts b/test/cases/getTopCategoryUsers.ts index bd8adc44..45425a24 100644 --- a/test/cases/getTopCategoryUsers.ts +++ b/test/cases/getTopCategoryUsers.ts @@ -3,7 +3,7 @@ import { getHash } from "../../src/utils/getHash"; import assert from "assert"; import { client } from "../utils/httpClient"; -const generateSegment = (userid: string, category: string) => ["getTopCategory", 0, 60, 50, `getTopCategoryUUID_${category}`, getHash(userid), 1, 1, category, 0]; +const generateSegment = (userid: string, category: string) => ["getTopCategory", 0, 60, 50, `getTopCategoryUUID_${category}`, getHash(userid), 1, 1, category, 0, new Date().toISOString()]; describe("getTopCategoryUsers", () => { const endpoint = "/api/getTopCategoryUsers"; @@ -14,7 +14,7 @@ describe("getTopCategoryUsers", () => { await db.prepare("run", insertUserNameQuery, [getHash(user1), user1]); await db.prepare("run", insertUserNameQuery, [getHash(user2), user2]); - const sponsorTimesQuery = 'INSERT INTO "sponsorTimes" ("videoID", "startTime", "endTime", "votes", "UUID", "userID", "timeSubmitted", views, category, "shadowHidden") VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?)'; + const sponsorTimesQuery = 'INSERT INTO "sponsorTimes" ("videoID", "startTime", "endTime", "votes", "UUID", "userID", "timeSubmitted", views, category, "shadowHidden", "updatedAt") VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)'; await db.prepare("run", sponsorTimesQuery, generateSegment(user1, "sponsor")); await db.prepare("run", sponsorTimesQuery, generateSegment(user1, "selfpromo")); await db.prepare("run", sponsorTimesQuery, generateSegment(user2, "interaction")); diff --git a/test/cases/getTopUsers.ts b/test/cases/getTopUsers.ts index c4f0633a..70e6ae91 100644 --- a/test/cases/getTopUsers.ts +++ b/test/cases/getTopUsers.ts @@ -3,7 +3,7 @@ import { getHash } from "../../src/utils/getHash"; import assert from "assert"; import { client } from "../utils/httpClient"; -const generateSegment = (userid: string, category: string) => ["getTopUsers", 0, 60, 50, `getTopUserUUID_${category}`, getHash(userid), 1, 1, category, 0]; +const generateSegment = (userid: string, category: string) => ["getTopUsers", 0, 60, 50, `getTopUserUUID_${category}`, getHash(userid), 1, 1, category, 0, new Date().toISOString()]; describe("getTopUsers", () => { const endpoint = "/api/getTopUsers"; @@ -14,7 +14,7 @@ describe("getTopUsers", () => { await db.prepare("run", insertUserNameQuery, [getHash(user1), user1]); await db.prepare("run", insertUserNameQuery, [getHash(user2), user2]); - const sponsorTimesQuery = 'INSERT INTO "sponsorTimes" ("videoID", "startTime", "endTime", "votes", "UUID", "userID", "timeSubmitted", views, category, "shadowHidden") VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?)'; + const sponsorTimesQuery = 'INSERT INTO "sponsorTimes" ("videoID", "startTime", "endTime", "votes", "UUID", "userID", "timeSubmitted", views, category, "shadowHidden", "updatedAt") VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)'; await db.prepare("run", sponsorTimesQuery, generateSegment(user1, "sponsor")); await db.prepare("run", sponsorTimesQuery, generateSegment(user1, "selfpromo")); await db.prepare("run", sponsorTimesQuery, generateSegment(user2, "interaction")); diff --git a/test/cases/getUserInfoFree.ts b/test/cases/getUserInfoFree.ts index 206a45a7..dfb60c5f 100644 --- a/test/cases/getUserInfoFree.ts +++ b/test/cases/getUserInfoFree.ts @@ -14,10 +14,10 @@ describe("getUserInfo Free Chapters", () => { const isoDate = new Date().toISOString(); before(async () => { - const sponsorTimesQuery = 'INSERT INTO "sponsorTimes" ("videoID", "startTime", "endTime", "votes", "UUID", "userID", "timeSubmitted", views, category, "actionType", "reputation", "shadowHidden") VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)'; - await db.prepare("run", sponsorTimesQuery, ["getUserInfoFree", 1, 2, 0, "uuid-guif-0", getHash(repQualifyUserID), postOldQualify, 0, "sponsor", "skip", 20, 0]); - await db.prepare("run", sponsorTimesQuery, ["getUserInfoFree", 1, 2, 0, "uuid-guif-1", getHash(oldQualifyUserID), 0, 0, "sponsor", "skip", 0, 0]); // submit at epoch - await db.prepare("run", sponsorTimesQuery, ["getUserInfoFree", 1, 2, 0, "uuid-guif-2", getHash(newQualifyUserID), postOldQualify, 0, "sponsor", "skip", 0, 0]); + const sponsorTimesQuery = 'INSERT INTO "sponsorTimes" ("videoID", "startTime", "endTime", "votes", "UUID", "userID", "timeSubmitted", views, category, "actionType", "reputation", "shadowHidden", "updatedAt") VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)'; + await db.prepare("run", sponsorTimesQuery, ["getUserInfoFree", 1, 2, 0, "uuid-guif-0", getHash(repQualifyUserID), postOldQualify, 0, "sponsor", "skip", 20, 0, isoDate]); + await db.prepare("run", sponsorTimesQuery, ["getUserInfoFree", 1, 2, 0, "uuid-guif-1", getHash(oldQualifyUserID), 0, 0, "sponsor", "skip", 0, 0, isoDate]); // submit at epoch + await db.prepare("run", sponsorTimesQuery, ["getUserInfoFree", 1, 2, 0, "uuid-guif-2", getHash(newQualifyUserID), postOldQualify, 0, "sponsor", "skip", 0, 0, isoDate]); await db.prepare("run", `INSERT INTO "vipUsers" ("userID", "createdAt") VALUES (?, ?)`, [getHash(vipQualifyUserID), isoDate]); }); diff --git a/test/cases/getUserStats.ts b/test/cases/getUserStats.ts index 0db720cb..5610ecac 100644 --- a/test/cases/getUserStats.ts +++ b/test/cases/getUserStats.ts @@ -12,6 +12,7 @@ const userThreePrivateID = "getuserstats_user_03"; const userThreePublicID = getHash(userThreePrivateID); const userFourPrivateID = "getuserstats_user_04"; const userFourPublicID = getHash(userFourPrivateID); +const isoDate = new Date().toISOString(); describe("getUserStats", () => { const endpoint = "/api/userStats"; @@ -22,26 +23,26 @@ describe("getUserStats", () => { const insertUserNameQuery = 'INSERT INTO "userNames" ("userID", "userName") VALUES(?, ?)'; await db.prepare("run", insertUserNameQuery, [userOnePublicID, "Username user 01"]); - const sponsorTimesQuery = 'INSERT INTO "sponsorTimes" ("videoID", "startTime", "endTime", "votes", "actionType", "UUID", "userID", "timeSubmitted", views, category, "shadowHidden") VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)'; - await db.prepare("run", sponsorTimesQuery, [userOnePrivateID, 0, 60, 0, "skip", "getuserstatsuuid1", userOnePublicID, 1, 1, "sponsor", 0]); - await db.prepare("run", sponsorTimesQuery, [userOnePrivateID, 0, 60, 0, "skip", "getuserstatsuuid2", userOnePublicID, 2, 2, "selfpromo", 0]); - await db.prepare("run", sponsorTimesQuery, [userOnePrivateID, 0, 60, 0, "skip", "getuserstatsuuid3", userOnePublicID, 3, 3, "interaction", 0]); - await db.prepare("run", sponsorTimesQuery, [userOnePrivateID, 0, 60, 0, "skip", "getuserstatsuuid4", userOnePublicID, 4, 4, "intro", 0]); - await db.prepare("run", sponsorTimesQuery, [userOnePrivateID, 0, 60, 0, "skip", "getuserstatsuuid5", userOnePublicID, 5, 5, "outro", 0]); - await db.prepare("run", sponsorTimesQuery, [userOnePrivateID, 0, 60, 0, "skip", "getuserstatsuuid6", userOnePublicID, 6, 6, "preview", 0]); - await db.prepare("run", sponsorTimesQuery, [userOnePrivateID, 0, 60, 0, "skip", "getuserstatsuuid7", userOnePublicID, 7, 7, "music_offtopic", 0]); - await db.prepare("run", sponsorTimesQuery, [userOnePrivateID, 11, 11, 0, "poi", "getuserstatsuuid8", userOnePublicID, 8, 8, "poi_highlight", 0]); - await db.prepare("run", sponsorTimesQuery, [userTwoPrivateID, 0, 60, -2, "skip", "getuserstatsuuid9", userTwoPublicID, 8, 2, "sponsor", 0]); - await db.prepare("run", sponsorTimesQuery, [userOnePrivateID, 0, 60, 0, "skip", "getuserstatsuuid10", userOnePublicID, 8, 2, "filler", 0]); - await db.prepare("run", sponsorTimesQuery, [userOnePrivateID, 0, 0, 0, "full", "getuserstatsuuid11", userOnePublicID, 8, 2, "exclusive_access", 0]); - await db.prepare("run", sponsorTimesQuery, [userOnePrivateID, 0, 60, 0, "chapter", "getuserstatsuuid12", userOnePublicID, 9, 2, "chapter", 0]); + const sponsorTimesQuery = 'INSERT INTO "sponsorTimes" ("videoID", "startTime", "endTime", "votes", "actionType", "UUID", "userID", "timeSubmitted", views, category, "shadowHidden", "updatedAt") VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)'; + await db.prepare("run", sponsorTimesQuery, [userOnePrivateID, 0, 60, 0, "skip", "getuserstatsuuid1", userOnePublicID, 1, 1, "sponsor", 0, isoDate]); + await db.prepare("run", sponsorTimesQuery, [userOnePrivateID, 0, 60, 0, "skip", "getuserstatsuuid2", userOnePublicID, 2, 2, "selfpromo", 0, isoDate]); + await db.prepare("run", sponsorTimesQuery, [userOnePrivateID, 0, 60, 0, "skip", "getuserstatsuuid3", userOnePublicID, 3, 3, "interaction", 0, isoDate]); + await db.prepare("run", sponsorTimesQuery, [userOnePrivateID, 0, 60, 0, "skip", "getuserstatsuuid4", userOnePublicID, 4, 4, "intro", 0, isoDate]); + await db.prepare("run", sponsorTimesQuery, [userOnePrivateID, 0, 60, 0, "skip", "getuserstatsuuid5", userOnePublicID, 5, 5, "outro", 0, isoDate]); + await db.prepare("run", sponsorTimesQuery, [userOnePrivateID, 0, 60, 0, "skip", "getuserstatsuuid6", userOnePublicID, 6, 6, "preview", 0, isoDate]); + await db.prepare("run", sponsorTimesQuery, [userOnePrivateID, 0, 60, 0, "skip", "getuserstatsuuid7", userOnePublicID, 7, 7, "music_offtopic", 0, isoDate]); + await db.prepare("run", sponsorTimesQuery, [userOnePrivateID, 11, 11, 0, "poi", "getuserstatsuuid8", userOnePublicID, 8, 8, "poi_highlight", 0, isoDate]); + await db.prepare("run", sponsorTimesQuery, [userTwoPrivateID, 0, 60, -2, "skip", "getuserstatsuuid9", userTwoPublicID, 8, 2, "sponsor", 0, isoDate]); + await db.prepare("run", sponsorTimesQuery, [userOnePrivateID, 0, 60, 0, "skip", "getuserstatsuuid10", userOnePublicID, 8, 2, "filler", 0, isoDate]); + await db.prepare("run", sponsorTimesQuery, [userOnePrivateID, 0, 0, 0, "full", "getuserstatsuuid11", userOnePublicID, 8, 2, "exclusive_access", 0, isoDate]); + await db.prepare("run", sponsorTimesQuery, [userOnePrivateID, 0, 60, 0, "chapter", "getuserstatsuuid12", userOnePublicID, 9, 2, "chapter", 0, isoDate]); // fully banned user - await db.prepare("run", sponsorTimesQuery, [userThreePrivateID, 0, 60, 0, "skip", "getuserstatsuuid13", userThreePublicID, 1, 1, "sponsor", 1]); - await db.prepare("run", sponsorTimesQuery, [userThreePrivateID, 0, 60, 0, "skip", "getuserstatsuuid14", userThreePublicID, 1, 1, "sponsor", 1]); + await db.prepare("run", sponsorTimesQuery, [userThreePrivateID, 0, 60, 0, "skip", "getuserstatsuuid13", userThreePublicID, 1, 1, "sponsor", 1, isoDate]); + await db.prepare("run", sponsorTimesQuery, [userThreePrivateID, 0, 60, 0, "skip", "getuserstatsuuid14", userThreePublicID, 1, 1, "sponsor", 1, isoDate]); // user with banned segments - await db.prepare("run", sponsorTimesQuery, [userFourPrivateID, 0, 60, 0, "skip", "getuserstatsuuid15", userFourPublicID, 1, 1, "sponsor", 0]); - await db.prepare("run", sponsorTimesQuery, [userFourPrivateID, 0, 60, 0, "skip", "getuserstatsuuid16", userFourPublicID, 1, 1, "sponsor", 1]); + await db.prepare("run", sponsorTimesQuery, [userFourPrivateID, 0, 60, 0, "skip", "getuserstatsuuid15", userFourPublicID, 1, 1, "sponsor", 0, isoDate]); + await db.prepare("run", sponsorTimesQuery, [userFourPrivateID, 0, 60, 0, "skip", "getuserstatsuuid16", userFourPublicID, 1, 1, "sponsor", 1, isoDate]); }); it("Should be able to get a 400 (No userID parameter)", (done) => { diff --git a/test/cases/getVideoLabelByHash.ts b/test/cases/getVideoLabelByHash.ts index 650867ec..ec29a5ce 100644 --- a/test/cases/getVideoLabelByHash.ts +++ b/test/cases/getVideoLabelByHash.ts @@ -5,27 +5,29 @@ import { getHash } from "../../src/utils/getHash"; describe("getVideoLabelHash", () => { const endpoint = "/api/videoLabels"; + const isoDate = new Date().toISOString(); + before(async () => { - const query = 'INSERT INTO "sponsorTimes" ("videoID", "hashedVideoID", "votes", "locked", "UUID", "userID", "timeSubmitted", "category", "actionType", "hidden", "shadowHidden", "startTime", "endTime", "views") VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 0, 0, 0)'; - await db.prepare("run", query, ["getLabelHashSponsor" , getHash("getLabelHashSponsor", 1) , 2, 0, "labelhash01", "labeluser", 0, "sponsor", "full", 0, 0]); - await db.prepare("run", query, ["getLabelHashEA" , getHash("getLabelHashEA", 1) , 2, 0, "labelhash02", "labeluser", 0, "exclusive_access", "full", 0, 0]); - await db.prepare("run", query, ["getLabelHashSelfpromo" , getHash("getLabelHashSelfpromo", 1) , 2, 0, "labelhash03", "labeluser", 0, "selfpromo", "full", 0, 0]); + const query = 'INSERT INTO "sponsorTimes" ("videoID", "hashedVideoID", "votes", "locked", "UUID", "userID", "timeSubmitted", "category", "actionType", "hidden", "shadowHidden", "startTime", "endTime", "views", "updatedAt") VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 0, 0, 0)'; + await db.prepare("run", query, ["getLabelHashSponsor" , getHash("getLabelHashSponsor", 1) , 2, 0, "labelhash01", "labeluser", 0, "sponsor", "full", 0, 0, isoDate]); + await db.prepare("run", query, ["getLabelHashEA" , getHash("getLabelHashEA", 1) , 2, 0, "labelhash02", "labeluser", 0, "exclusive_access", "full", 0, 0, isoDate]); + await db.prepare("run", query, ["getLabelHashSelfpromo" , getHash("getLabelHashSelfpromo", 1) , 2, 0, "labelhash03", "labeluser", 0, "selfpromo", "full", 0, 0, isoDate]); // priority override - await db.prepare("run", query, ["getLabelHashPriority" , getHash("getLabelHashPriority", 1) , 2, 0, "labelhash04", "labeluser", 0, "sponsor", "full", 0, 0]); - await db.prepare("run", query, ["getLabelHashPriority" , getHash("getLabelHashPriority", 1) , 2, 0, "labelhash05", "labeluser", 0, "exclusive_access", "full", 0, 0]); - await db.prepare("run", query, ["getLabelHashPriority" , getHash("getLabelHashPriority", 1) , 2, 0, "labelhash06", "labeluser", 0, "selfpromo", "full", 0, 0]); + await db.prepare("run", query, ["getLabelHashPriority" , getHash("getLabelHashPriority", 1) , 2, 0, "labelhash04", "labeluser", 0, "sponsor", "full", 0, 0, isoDate]); + await db.prepare("run", query, ["getLabelHashPriority" , getHash("getLabelHashPriority", 1) , 2, 0, "labelhash05", "labeluser", 0, "exclusive_access", "full", 0, 0, isoDate]); + await db.prepare("run", query, ["getLabelHashPriority" , getHash("getLabelHashPriority", 1) , 2, 0, "labelhash06", "labeluser", 0, "selfpromo", "full", 0, 0, isoDate]); // locked only - await db.prepare("run", query, ["getLabelHashLocked" , getHash("getLabelHashLocked", 1) , 2, 0, "labelhash07", "labeluser", 0, "sponsor", "full", 0, 0]); - await db.prepare("run", query, ["getLabelHashLocked" , getHash("getLabelHashLocked", 1) , 2, 0, "labelhash08", "labeluser", 0, "exclusive_access", "full", 0, 0]); - await db.prepare("run", query, ["getLabelHashLocked" , getHash("getLabelHashLocked", 1) , 2, 1, "labelhash09", "labeluser", 0, "selfpromo", "full", 0, 0]); + await db.prepare("run", query, ["getLabelHashLocked" , getHash("getLabelHashLocked", 1) , 2, 0, "labelhash07", "labeluser", 0, "sponsor", "full", 0, 0, isoDate]); + await db.prepare("run", query, ["getLabelHashLocked" , getHash("getLabelHashLocked", 1) , 2, 0, "labelhash08", "labeluser", 0, "exclusive_access", "full", 0, 0, isoDate]); + await db.prepare("run", query, ["getLabelHashLocked" , getHash("getLabelHashLocked", 1) , 2, 1, "labelhash09", "labeluser", 0, "selfpromo", "full", 0, 0, isoDate]); // hidden segments - await db.prepare("run", query, ["getLabelHashDownvote" , getHash("getLabelHashDownvote", 1) , -2, 0, "labelhash10", "labeluser", 0, "selfpromo", "full", 0, 0]); - await db.prepare("run", query, ["getLabelHashHidden" , getHash("getLabelHashHidden", 1) , 2, 0, "labelhash11", "labeluser", 0, "selfpromo", "full", 1, 0]); - await db.prepare("run", query, ["getLabelHashShHidden" , getHash("getLabelHashShHidden", 1) , 2, 0, "labelhash12", "labeluser", 0, "selfpromo", "full", 0, 1]); + await db.prepare("run", query, ["getLabelHashDownvote" , getHash("getLabelHashDownvote", 1) , -2, 0, "labelhash10", "labeluser", 0, "selfpromo", "full", 0, 0, isoDate]); + await db.prepare("run", query, ["getLabelHashHidden" , getHash("getLabelHashHidden", 1) , 2, 0, "labelhash11", "labeluser", 0, "selfpromo", "full", 1, 0, isoDate]); + await db.prepare("run", query, ["getLabelHashShHidden" , getHash("getLabelHashShHidden", 1) , 2, 0, "labelhash12", "labeluser", 0, "selfpromo", "full", 0, 1, isoDate]); // priority override2 - await db.prepare("run", query, ["getLabelHashPriority2" , getHash("getLabelHashPriority2", 1) , -2, 0, "labelhash13", "labeluser", 0, "sponsor", "full", 0, 0]); - await db.prepare("run", query, ["getLabelHashPriority2" , getHash("getLabelHashPriority2", 1) , 2, 0, "labelhash14", "labeluser", 0, "exclusive_access", "full", 0, 0]); - await db.prepare("run", query, ["getLabelHashPriority2" , getHash("getLabelHashPriority2", 1) , 2, 0, "labelhash15", "labeluser", 0, "selfpromo", "full", 0, 0]); + await db.prepare("run", query, ["getLabelHashPriority2" , getHash("getLabelHashPriority2", 1) , -2, 0, "labelhash13", "labeluser", 0, "sponsor", "full", 0, 0, isoDate]); + await db.prepare("run", query, ["getLabelHashPriority2" , getHash("getLabelHashPriority2", 1) , 2, 0, "labelhash14", "labeluser", 0, "exclusive_access", "full", 0, 0, isoDate]); + await db.prepare("run", query, ["getLabelHashPriority2" , getHash("getLabelHashPriority2", 1) , 2, 0, "labelhash15", "labeluser", 0, "selfpromo", "full", 0, 0, isoDate]); return; }); diff --git a/test/cases/getVideoLabels.ts b/test/cases/getVideoLabels.ts index 7202d2cd..3ffbd9c8 100644 --- a/test/cases/getVideoLabels.ts +++ b/test/cases/getVideoLabels.ts @@ -4,27 +4,28 @@ import { client } from "../utils/httpClient"; describe("getVideoLabels", () => { const endpoint = "/api/videoLabels"; + const isoDate = new Date().toISOString(); before(async () => { - const query = 'INSERT INTO "sponsorTimes" ("videoID", "votes", "locked", "UUID", "userID", "timeSubmitted", "category", "actionType", "hidden", "shadowHidden", "startTime", "endTime", "views") VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 0, 0, 0)'; - await db.prepare("run", query, ["getLabelSponsor" , 2, 0, "label01", "labeluser", 0, "sponsor", "full", 0, 0]); - await db.prepare("run", query, ["getLabelEA" , 2, 0, "label02", "labeluser", 0, "exclusive_access", "full", 0, 0]); - await db.prepare("run", query, ["getLabelSelfpromo" , 2, 0, "label03", "labeluser", 0, "selfpromo", "full", 0, 0]); + const query = 'INSERT INTO "sponsorTimes" ("videoID", "votes", "locked", "UUID", "userID", "timeSubmitted", "category", "actionType", "hidden", "shadowHidden", "startTime", "endTime", "views", "updatedAt") VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 0, 0, 0)'; + await db.prepare("run", query, ["getLabelSponsor" , 2, 0, "label01", "labeluser", 0, "sponsor", "full", 0, 0, isoDate]); + await db.prepare("run", query, ["getLabelEA" , 2, 0, "label02", "labeluser", 0, "exclusive_access", "full", 0, 0, isoDate]); + await db.prepare("run", query, ["getLabelSelfpromo" , 2, 0, "label03", "labeluser", 0, "selfpromo", "full", 0, 0, isoDate]); // priority override - await db.prepare("run", query, ["getLabelPriority" , 2, 0, "label04", "labeluser", 0, "sponsor", "full", 0, 0]); - await db.prepare("run", query, ["getLabelPriority" , 2, 0, "label05", "labeluser", 0, "exclusive_access", "full", 0, 0]); - await db.prepare("run", query, ["getLabelPriority" , 2, 0, "label06", "labeluser", 0, "selfpromo", "full", 0, 0]); + await db.prepare("run", query, ["getLabelPriority" , 2, 0, "label04", "labeluser", 0, "sponsor", "full", 0, 0, isoDate]); + await db.prepare("run", query, ["getLabelPriority" , 2, 0, "label05", "labeluser", 0, "exclusive_access", "full", 0, 0, isoDate]); + await db.prepare("run", query, ["getLabelPriority" , 2, 0, "label06", "labeluser", 0, "selfpromo", "full", 0, 0, isoDate]); // locked only - await db.prepare("run", query, ["getLabelLocked" , 2, 0, "label07", "labeluser", 0, "sponsor", "full", 0, 0]); - await db.prepare("run", query, ["getLabelLocked" , 2, 0, "label08", "labeluser", 0, "exclusive_access", "full", 0, 0]); - await db.prepare("run", query, ["getLabelLocked" , 2, 1, "label09", "labeluser", 0, "selfpromo", "full", 0, 0]); + await db.prepare("run", query, ["getLabelLocked" , 2, 0, "label07", "labeluser", 0, "sponsor", "full", 0, 0, isoDate]); + await db.prepare("run", query, ["getLabelLocked" , 2, 0, "label08", "labeluser", 0, "exclusive_access", "full", 0, 0, isoDate]); + await db.prepare("run", query, ["getLabelLocked" , 2, 1, "label09", "labeluser", 0, "selfpromo", "full", 0, 0, isoDate]); // hidden segments - await db.prepare("run", query, ["getLabelDownvote" ,-2, 0, "label10", "labeluser", 0, "selfpromo", "full", 0, 0]); - await db.prepare("run", query, ["getLabelHidden" ,2, 0, "label11", "labeluser", 0, "selfpromo", "full", 1, 0]); - await db.prepare("run", query, ["getLabelShadowHidden",2, 0, "label12", "labeluser", 0, "selfpromo", "full", 0, 1]); + await db.prepare("run", query, ["getLabelDownvote" ,-2, 0, "label10", "labeluser", 0, "selfpromo", "full", 0, 0, isoDate]); + await db.prepare("run", query, ["getLabelHidden" ,2, 0, "label11", "labeluser", 0, "selfpromo", "full", 1, 0, isoDate]); + await db.prepare("run", query, ["getLabelShadowHidden",2, 0, "label12", "labeluser", 0, "selfpromo", "full", 0, 1, isoDate]); // priority override2 - await db.prepare("run", query, ["getLabelPriority2" , -2, 0, "label13", "labeluser", 0, "sponsor", "full", 0, 0]); - await db.prepare("run", query, ["getLabelPriority2" , 2, 0, "label14", "labeluser", 0, "exclusive_access", "full", 0, 0]); - await db.prepare("run", query, ["getLabelPriority2" , 2, 0, "label15", "labeluser", 0, "selfpromo", "full", 0, 0]); + await db.prepare("run", query, ["getLabelPriority2" , -2, 0, "label13", "labeluser", 0, "sponsor", "full", 0, 0, isoDate]); + await db.prepare("run", query, ["getLabelPriority2" , 2, 0, "label14", "labeluser", 0, "exclusive_access", "full", 0, 0, isoDate]); + await db.prepare("run", query, ["getLabelPriority2" , 2, 0, "label15", "labeluser", 0, "selfpromo", "full", 0, 0, isoDate]); return; }); diff --git a/test/cases/oldGetSponsorTime.ts b/test/cases/oldGetSponsorTime.ts index 734c8ff2..46c31ad5 100644 --- a/test/cases/oldGetSponsorTime.ts +++ b/test/cases/oldGetSponsorTime.ts @@ -4,13 +4,14 @@ import assert from "assert"; import { client } from "../utils/httpClient"; const endpoint = "/api/getVideoSponsorTimes"; +const isoDate = new Date().toISOString(); const getOldSponsorTime = (videoID: string) => client.get(endpoint, { params: { videoID } }); describe("getVideoSponsorTime (Old get method)", () => { before(async () => { - const insertSponsorTimes = 'INSERT INTO "sponsorTimes" ("videoID", "startTime", "endTime", "votes", "UUID", "userID", "timeSubmitted", views, category, "shadowHidden") VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?)'; - await db.prepare("run", insertSponsorTimes, ["oldGetSponsorTime0", 1, 11, 2, "oldGetSponsorTime00", "oldGetSponsorTimeUser", 0, 50, "sponsor", 0]); - await db.prepare("run", insertSponsorTimes, ["oldGetSponsorTime1,test", 1, 11, 2, "oldGetSponsorTime01", "oldGetSponsorTimeUser", 0, 50, "sponsor", 0]); + const insertSponsorTimes = 'INSERT INTO "sponsorTimes" ("videoID", "startTime", "endTime", "votes", "UUID", "userID", "timeSubmitted", views, category, "shadowHidden", "updatedAt") VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)'; + await db.prepare("run", insertSponsorTimes, ["oldGetSponsorTime0", 1, 11, 2, "oldGetSponsorTime00", "oldGetSponsorTimeUser", 0, 50, "sponsor", 0, isoDate]); + await db.prepare("run", insertSponsorTimes, ["oldGetSponsorTime1,test", 1, 11, 2, "oldGetSponsorTime01", "oldGetSponsorTimeUser", 0, 50, "sponsor", 0, isoDate]); }); it("Should be able to get a time", (done) => { diff --git a/test/cases/postSkipSegments.ts b/test/cases/postSkipSegments.ts index d8c7815e..674758dc 100644 --- a/test/cases/postSkipSegments.ts +++ b/test/cases/postSkipSegments.ts @@ -52,8 +52,8 @@ describe("postSkipSegments", () => { const queryDatabaseVideoInfo = (videoID: string) => db.prepare("get", `SELECT * FROM "videoInfo" WHERE "videoID" = ?`, [videoID]); before(() => { - const insertSponsorTimeQuery = 'INSERT INTO "sponsorTimes" ("videoID", "startTime", "endTime", "votes", "UUID", "userID", "timeSubmitted", views, category, "actionType", "videoDuration", "shadowHidden", "hashedVideoID") VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)'; - db.prepare("run", insertSponsorTimeQuery, ["full_video_segment", 0, 0, 0, "full-video-uuid-0", submitUserTwoHash, 0, 0, "sponsor", "full", 0, 0, "full_video_segment"]); + const insertSponsorTimeQuery = 'INSERT INTO "sponsorTimes" ("videoID", "startTime", "endTime", "votes", "UUID", "userID", "timeSubmitted", views, category, "actionType", "videoDuration", "shadowHidden", "hashedVideoID", "updatedAt") VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)'; + db.prepare("run", insertSponsorTimeQuery, ["full_video_segment", 0, 0, 0, "full-video-uuid-0", submitUserTwoHash, 0, 0, "sponsor", "full", 0, 0, "full_video_segment", isoDate]); const insertVipUserQuery = 'INSERT INTO "vipUsers" ("userID", "createdAt") VALUES (?, ?)'; db.prepare("run", insertVipUserQuery, [getHash(submitVIPuser), isoDate]); diff --git a/test/cases/postSkipSegmentsAutomod.ts b/test/cases/postSkipSegmentsAutomod.ts index b6ffde0a..ffcec071 100644 --- a/test/cases/postSkipSegmentsAutomod.ts +++ b/test/cases/postSkipSegmentsAutomod.ts @@ -14,16 +14,17 @@ sinonStub.callsFake(YouTubeApiMock.listVideos); describe("postSkipSegments - Automod 80%", () => { const userID = "postSkipSegments-automodSubmit"; const userIDHash = getHash(userID); + const isoDate = new Date().toISOString(); const over80VideoID = "80percent_video"; const queryDatabaseCategory = (videoID: string) => db.prepare("all", `SELECT "startTime", "endTime", "category" FROM "sponsorTimes" WHERE "videoID" = ? and "votes" > -1`, [videoID]); before(() => { - const insertSponsorTimeQuery = 'INSERT INTO "sponsorTimes" ("videoID", "startTime", "endTime", "votes", "UUID", "userID", "timeSubmitted", views, category, "actionType", "videoDuration", "shadowHidden", "hashedVideoID") VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)'; - db.prepare("run", insertSponsorTimeQuery, [over80VideoID, 0, 1000, 0, "80percent-uuid-0", userIDHash, 0, 0, "interaction", "skip", 0, 0, over80VideoID]); - db.prepare("run", insertSponsorTimeQuery, [over80VideoID, 1001, 1005, 0, "80percent-uuid-1", userIDHash, 0, 0, "interaction", "skip", 0, 0, over80VideoID]); - db.prepare("run", insertSponsorTimeQuery, [over80VideoID, 0, 5000, -2, "80percent-uuid-2", userIDHash, 0, 0, "interaction", "skip", 0, 0, over80VideoID]); + const insertSponsorTimeQuery = 'INSERT INTO "sponsorTimes" ("videoID", "startTime", "endTime", "votes", "UUID", "userID", "timeSubmitted", views, category, "actionType", "videoDuration", "shadowHidden", "hashedVideoID", "updatedAt") VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)'; + db.prepare("run", insertSponsorTimeQuery, [over80VideoID, 0, 1000, 0, "80percent-uuid-0", userIDHash, 0, 0, "interaction", "skip", 0, 0, over80VideoID, isoDate]); + db.prepare("run", insertSponsorTimeQuery, [over80VideoID, 1001, 1005, 0, "80percent-uuid-1", userIDHash, 0, 0, "interaction", "skip", 0, 0, over80VideoID, isoDate]); + db.prepare("run", insertSponsorTimeQuery, [over80VideoID, 0, 5000, -2, "80percent-uuid-2", userIDHash, 0, 0, "interaction", "skip", 0, 0, over80VideoID, isoDate]); }); it("Should allow multiple times if total is under 80% of video (JSON method)", (done) => { diff --git a/test/cases/postSkipSegmentsDuration.ts b/test/cases/postSkipSegmentsDuration.ts index 72771923..5491e49a 100644 --- a/test/cases/postSkipSegmentsDuration.ts +++ b/test/cases/postSkipSegmentsDuration.ts @@ -18,13 +18,14 @@ describe("postSkipSegments - duration", () => { const videoID = "postSkip-DurationVideo"; const noDurationVideoID = "noDuration"; const userID = userIDOne; + const isoDate = new Date().toISOString(); const queryDatabaseDuration = (videoID: string) => db.prepare("get", `SELECT "startTime", "endTime", "locked", "category", "videoDuration" FROM "sponsorTimes" WHERE "videoID" = ?`, [videoID]); before(() => { - const insertSponsorTimeQuery = 'INSERT INTO "sponsorTimes" ("videoID", "startTime", "endTime", "votes", "UUID", "userID", "timeSubmitted", views, category, "actionType", "videoDuration", "shadowHidden", "hashedVideoID") VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)'; - db.prepare("run", insertSponsorTimeQuery, ["full_video_duration_segment", 0, 0, 0, "full-video-duration-uuid-0", userIDTwo, 0, 0, "sponsor", "full", 123, 0, "full_video_duration_segment"]); - db.prepare("run", insertSponsorTimeQuery, ["full_video_duration_segment", 25, 30, 0, "full-video-duration-uuid-1", userIDTwo, 0, 0, "sponsor", "skip", 123, 0, "full_video_duration_segment"]); + const insertSponsorTimeQuery = 'INSERT INTO "sponsorTimes" ("videoID", "startTime", "endTime", "votes", "UUID", "userID", "timeSubmitted", views, category, "actionType", "videoDuration", "shadowHidden", "hashedVideoID", "updatedAt") VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)'; + db.prepare("run", insertSponsorTimeQuery, ["full_video_duration_segment", 0, 0, 0, "full-video-duration-uuid-0", userIDTwo, 0, 0, "sponsor", "full", 123, 0, "full_video_duration_segment", isoDate]); + db.prepare("run", insertSponsorTimeQuery, ["full_video_duration_segment", 25, 30, 0, "full-video-duration-uuid-1", userIDTwo, 0, 0, "sponsor", "skip", 123, 0, "full_video_duration_segment", isoDate]); }); it("Should be able to submit a single time with a precise duration close to the one from the YouTube API (JSON method)", (done) => { diff --git a/test/cases/postSkipSegmentsFeatures.ts b/test/cases/postSkipSegmentsFeatures.ts index 94ca27f5..f0a834c7 100644 --- a/test/cases/postSkipSegmentsFeatures.ts +++ b/test/cases/postSkipSegmentsFeatures.ts @@ -10,6 +10,7 @@ describe("postSkipSegments Features - Chapters", () => { const submitUser_noPermissions = "postSkipSegments-chapters-noperm"; const submitUser_reputation = "postSkipSegments-chapters-reputation"; const submitUser_feature = "postSkipSegments-chapters-feature"; + const isoDate = new Date().toISOString(); const queryDatabaseChapter = (videoID: string) => db.prepare("get", `SELECT "startTime", "endTime", "category", "actionType", "description" FROM "sponsorTimes" WHERE "videoID" = ?`, [videoID]); function createSegment(): Segment { @@ -24,11 +25,11 @@ describe("postSkipSegments Features - Chapters", () => { before(() => { const submitNumberOfTimes = 10; const submitUser_reputationHash = getHash(submitUser_reputation); - const insertSponsorTimeQuery = 'INSERT INTO "sponsorTimes" ("videoID", "startTime", "endTime", "votes", "locked", "UUID", "userID", "timeSubmitted", views, category, "actionType", "shadowHidden") VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)'; + const insertSponsorTimeQuery = 'INSERT INTO "sponsorTimes" ("videoID", "startTime", "endTime", "votes", "locked", "UUID", "userID", "timeSubmitted", views, category, "actionType", "shadowHidden", "updatedAt") VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)'; for (let i = 0; i < submitNumberOfTimes; i++) { const uuid = `post_reputation_uuid-${i}`; const videoID = `post_reputation_video-${i}`; - db.prepare("run", insertSponsorTimeQuery, [videoID, 1, 11, 5, 1, uuid, submitUser_reputationHash, 1597240000000, 50, "sponsor", "skip", 0]); + db.prepare("run", insertSponsorTimeQuery, [videoID, 1, 11, 5, 1, uuid, submitUser_reputationHash, 1597240000000, 50, "sponsor", "skip", 0, isoDate]); } // user feature db.prepare("run", `INSERT INTO "userFeatures" ("userID", "feature", "issuerUserID", "timeSubmitted") VALUES(?, ?, ?, ?)`, [getHash(submitUser_feature), Feature.ChapterSubmitter, "generic-VIP", 0]); diff --git a/test/cases/reputation.ts b/test/cases/reputation.ts index 19088815..1d46da60 100644 --- a/test/cases/reputation.ts +++ b/test/cases/reputation.ts @@ -26,70 +26,70 @@ describe("reputation", () => { const videoID = "reputation-videoID"; const videoID2 = "reputation-videoID-2"; - const sponsorTimesInsertQuery = 'INSERT INTO "sponsorTimes" ("videoID", "startTime", "endTime", "votes", "locked", "UUID", "userID", "timeSubmitted", "views", "category", "hidden", "shadowHidden") VALUES(?,?,?,?,?,?,?,?,?,?,?,?)'; - await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 2, 0, "reputation-0-uuid-0", users["low-submissions"].pubID, 1606240000000, 50, "sponsor", 0, 0]); - await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 2, 0, "reputation-0-uuid-1", users["low-submissions"].pubID, 1606240000000, 50, "sponsor", 0, 0]); - await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 100, 0, "reputation-0-uuid-2", users["low-submissions"].pubID, 1606240000000, 50, "sponsor", 0, 0]); - - await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 2, 0, "reputation-1-uuid-0", users["high-downvotes"].pubID, 1606240000000, 50, "sponsor", 0, 0]); - await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, -2, 0, "reputation-1-uuid-1", users["high-downvotes"].pubID, 1606240000000, 50, "sponsor", 0, 0]); - await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, -2, 0, "reputation-1-uuid-2", users["high-downvotes"].pubID, 1606240000000, 50, "sponsor", 0, 0]); - await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, -2, 0, "reputation-1-uuid-3", users["high-downvotes"].pubID, 1606240000000, 50, "sponsor", 0, 0]); - await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, -2, 0, "reputation-1-uuid-4", users["high-downvotes"].pubID, 1606240000000, 50, "sponsor", 0, 0]); - await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, -1, 0, "reputation-1-uuid-5", users["high-downvotes"].pubID, 1606240000000, 50, "sponsor", 0, 0]); - await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 0, 0, "reputation-1-uuid-6", users["high-downvotes"].pubID, 1606240000000, 50, "sponsor", 0, 0]); - await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 0, 0, "reputation-1-uuid-7", users["high-downvotes"].pubID, 1606240000000, 50, "sponsor", 0, 0]); + const sponsorTimesInsertQuery = 'INSERT INTO "sponsorTimes" ("videoID", "startTime", "endTime", "votes", "locked", "UUID", "userID", "timeSubmitted", "views", "category", "hidden", "shadowHidden", "updatedAt") VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?)'; + await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 2, 0, "reputation-0-uuid-0", users["low-submissions"].pubID, 1606240000000, 50, "sponsor", 0, 0, isoDate]); + await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 2, 0, "reputation-0-uuid-1", users["low-submissions"].pubID, 1606240000000, 50, "sponsor", 0, 0, isoDate]); + await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 100, 0, "reputation-0-uuid-2", users["low-submissions"].pubID, 1606240000000, 50, "sponsor", 0, 0, isoDate]); + + await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 2, 0, "reputation-1-uuid-0", users["high-downvotes"].pubID, 1606240000000, 50, "sponsor", 0, 0, isoDate]); + await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, -2, 0, "reputation-1-uuid-1", users["high-downvotes"].pubID, 1606240000000, 50, "sponsor", 0, 0, isoDate]); + await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, -2, 0, "reputation-1-uuid-2", users["high-downvotes"].pubID, 1606240000000, 50, "sponsor", 0, 0, isoDate]); + await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, -2, 0, "reputation-1-uuid-3", users["high-downvotes"].pubID, 1606240000000, 50, "sponsor", 0, 0, isoDate]); + await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, -2, 0, "reputation-1-uuid-4", users["high-downvotes"].pubID, 1606240000000, 50, "sponsor", 0, 0, isoDate]); + await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, -1, 0, "reputation-1-uuid-5", users["high-downvotes"].pubID, 1606240000000, 50, "sponsor", 0, 0, isoDate]); + await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 0, 0, "reputation-1-uuid-6", users["high-downvotes"].pubID, 1606240000000, 50, "sponsor", 0, 0, isoDate]); + await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 0, 0, "reputation-1-uuid-7", users["high-downvotes"].pubID, 1606240000000, 50, "sponsor", 0, 0, isoDate]); // First video is considered a normal downvote, second is considered a self-downvote (ie. they didn't resubmit to fix their downvote) - await db.prepare("run", sponsorTimesInsertQuery, [`${videoID}A`, 1, 11, 2, 0, "reputation-1-1-uuid-0", users["low-non-self-downvotes"].pubID, 1606240000000, 50, "sponsor", 0, 0]); + await db.prepare("run", sponsorTimesInsertQuery, [`${videoID}A`, 1, 11, 2, 0, "reputation-1-1-uuid-0", users["low-non-self-downvotes"].pubID, 1606240000000, 50, "sponsor", 0, 0, isoDate]); // Different category, same video - await db.prepare("run", sponsorTimesInsertQuery, [`${videoID}A`, 1, 11, -2, 0, "reputation-1-1-uuid-1", users["low-non-self-downvotes"].pubID, 1606240000000, 50, "intro", 0, 0]); - await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 0, 0, "reputation-1-1-uuid-2", users["low-non-self-downvotes"].pubID, 1606240000000, 50, "sponsor", 0, 0]); - await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 0, 0, "reputation-1-1-uuid-3", users["low-non-self-downvotes"].pubID, 1606240000000, 50, "sponsor", 0, 0]); - await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 0, 0, "reputation-1-1-uuid-4", users["low-non-self-downvotes"].pubID, 1606240000000, 50, "sponsor", 0, 0]); - await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, -1, 0, "reputation-1-1-uuid-5", users["low-non-self-downvotes"].pubID, 1606240000000, 50, "sponsor", 0, 0]); - await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 0, 0, "reputation-1-1-uuid-6", users["low-non-self-downvotes"].pubID, 1606240000000, 50, "sponsor", 0, 0]); - await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 0, 0, "reputation-1-1-uuid-7", users["low-non-self-downvotes"].pubID, 1606240000000, 50, "sponsor", 0, 0]); + await db.prepare("run", sponsorTimesInsertQuery, [`${videoID}A`, 1, 11, -2, 0, "reputation-1-1-uuid-1", users["low-non-self-downvotes"].pubID, 1606240000000, 50, "intro", 0, 0, isoDate]); + await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 0, 0, "reputation-1-1-uuid-2", users["low-non-self-downvotes"].pubID, 1606240000000, 50, "sponsor", 0, 0, isoDate]); + await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 0, 0, "reputation-1-1-uuid-3", users["low-non-self-downvotes"].pubID, 1606240000000, 50, "sponsor", 0, 0, isoDate]); + await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 0, 0, "reputation-1-1-uuid-4", users["low-non-self-downvotes"].pubID, 1606240000000, 50, "sponsor", 0, 0, isoDate]); + await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, -1, 0, "reputation-1-1-uuid-5", users["low-non-self-downvotes"].pubID, 1606240000000, 50, "sponsor", 0, 0, isoDate]); + await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 0, 0, "reputation-1-1-uuid-6", users["low-non-self-downvotes"].pubID, 1606240000000, 50, "sponsor", 0, 0, isoDate]); + await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 0, 0, "reputation-1-1-uuid-7", users["low-non-self-downvotes"].pubID, 1606240000000, 50, "sponsor", 0, 0, isoDate]); // First videos is considered a normal downvote, last is considered a self-downvote (ie. they didn't resubmit to fix their downvote) - await db.prepare("run", sponsorTimesInsertQuery, [`${videoID}A`, 1, 11, 2, 0, "reputation-1-1-1-uuid-0", users["high-non-self-downvotes"].pubID, 1606240000000, 50, "sponsor", 0, 0]); + await db.prepare("run", sponsorTimesInsertQuery, [`${videoID}A`, 1, 11, 2, 0, "reputation-1-1-1-uuid-0", users["high-non-self-downvotes"].pubID, 1606240000000, 50, "sponsor", 0, 0, isoDate]); // Different category, same video - await db.prepare("run", sponsorTimesInsertQuery, [`${videoID}A`, 1, 11, -2, 0, "reputation-1-1-1-uuid-1", users["high-non-self-downvotes"].pubID, 1606240000000, 50, "intro", 0, 0]); - await db.prepare("run", sponsorTimesInsertQuery, [`${videoID}B`, 1, 11, -2, 0, "reputation-1-1-1-uuid-1-b", users["high-non-self-downvotes"].pubID, 1606240000000, 50, "intro", 0, 0]); - await db.prepare("run", sponsorTimesInsertQuery, [`${videoID}C`, 1, 11, -2, 0, "reputation-1-1-1-uuid-1-c", users["high-non-self-downvotes"].pubID, 1606240000000, 50, "intro", 0, 0]); - await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 0, 0, "reputation-1-1-1-uuid-2", users["high-non-self-downvotes"].pubID, 1606240000000, 50, "sponsor", 0, 0]); - await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 0, 0, "reputation-1-1-1-uuid-3", users["high-non-self-downvotes"].pubID, 1606240000000, 50, "sponsor", 0, 0]); - await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 0, 0, "reputation-1-1-1-uuid-4", users["high-non-self-downvotes"].pubID, 1606240000000, 50, "sponsor", 0, 0]); - await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, -1, 0, "reputation-1-1-1-uuid-5", users["high-non-self-downvotes"].pubID, 1606240000000, 50, "sponsor", 0, 0]); - await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 0, 0, "reputation-1-1-1-uuid-6", users["high-non-self-downvotes"].pubID, 1606240000000, 50, "sponsor", 0, 0]); - await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 0, 0, "reputation-1-1-1-uuid-7", users["high-non-self-downvotes"].pubID, 1606240000000, 50, "sponsor", 0, 0]); - - await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 2, 0, "reputation-2-uuid-0", users["new-submissions"].pubID, Date.now(), 50, "sponsor", 0, 0]); - await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 2, 0, "reputation-2-uuid-1", users["new-submissions"].pubID, Date.now(), 50, "sponsor", 0, 0]); - await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 2, 0, "reputation-2-uuid-2", users["new-submissions"].pubID, Date.now(), 50, "sponsor", 0, 0]); - await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 2, 0, "reputation-2-uuid-3", users["new-submissions"].pubID, Date.now(), 50, "sponsor", 0, 0]); - await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 2, 0, "reputation-2-uuid-4", users["new-submissions"].pubID, Date.now(), 50, "sponsor", 0, 0]); - await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, -1, 0, "reputation-2-uuid-5", users["new-submissions"].pubID, 1606240000000, 50, "sponsor", 0, 0]); - await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 0, 0, "reputation-2-uuid-6", users["new-submissions"].pubID, 1606240000000, 50, "sponsor", 0, 0]); - await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 0, 0, "reputation-2-uuid-7", users["new-submissions"].pubID, 1606240000000, 50, "sponsor", 0, 0]); - - await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 2, 0, "reputation-3-uuid-0", users["low-sum"].pubID, 1606240000000, 50, "sponsor", 0, 0]); - await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 1, 0, "reputation-3-uuid-1", users["low-sum"].pubID, 1606240000000, 50, "sponsor", 0, 0]); - await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 0, 0, "reputation-3-uuid-2", users["low-sum"].pubID, 1606240000000, 50, "sponsor", 0, 0]); - await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 0, 0, "reputation-3-uuid-3", users["low-sum"].pubID, 1606240000000, 50, "sponsor", 0, 0]); - await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 1, 0, "reputation-3-uuid-4", users["low-sum"].pubID, 1606240000000, 50, "sponsor", 0, 0]); - await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, -1, 0, "reputation-3-uuid-5", users["low-sum"].pubID, 1606240000000, 50, "sponsor", 0, 0]); - await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 0, 0, "reputation-3-uuid-6", users["low-sum"].pubID, 1606240000000, 50, "sponsor", 0, 0]); - await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 0, 0, "reputation-3-uuid-7", users["low-sum"].pubID, 1606240000000, 50, "sponsor", 0, 0]); - - await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 2, 0, "reputation-4-uuid-0", users["high-rep-before-manual-vote"].pubID, 0, 50, "sponsor", 0, 0]); - await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 2, 0, "reputation-4-uuid-1", users["high-rep-before-manual-vote"].pubID, 0, 50, "sponsor", 0, 0]); - await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 2, 0, "reputation-4-uuid-2", users["high-rep-before-manual-vote"].pubID, 0, 50, "sponsor", 0, 0]); - await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 2, 0, "reputation-4-uuid-3", users["high-rep-before-manual-vote"].pubID, 0, 50, "sponsor", 0, 0]); - await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 2, 0, "reputation-4-uuid-4", users["high-rep-before-manual-vote"].pubID, 0, 50, "sponsor", 0, 0]); - await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, -1, 0, "reputation-4-uuid-5", users["high-rep-before-manual-vote"].pubID, 0, 50, "sponsor", 0, 0]); - await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 0, 0, "reputation-4-uuid-6", users["high-rep-before-manual-vote"].pubID, 0, 50, "sponsor", 0, 0]); - await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 0, 0, "reputation-4-uuid-7", users["high-rep-before-manual-vote"].pubID, 0, 50, "sponsor", 0, 0]); + await db.prepare("run", sponsorTimesInsertQuery, [`${videoID}A`, 1, 11, -2, 0, "reputation-1-1-1-uuid-1", users["high-non-self-downvotes"].pubID, 1606240000000, 50, "intro", 0, 0, isoDate]); + await db.prepare("run", sponsorTimesInsertQuery, [`${videoID}B`, 1, 11, -2, 0, "reputation-1-1-1-uuid-1-b", users["high-non-self-downvotes"].pubID, 1606240000000, 50, "intro", 0, 0, isoDate]); + await db.prepare("run", sponsorTimesInsertQuery, [`${videoID}C`, 1, 11, -2, 0, "reputation-1-1-1-uuid-1-c", users["high-non-self-downvotes"].pubID, 1606240000000, 50, "intro", 0, 0, isoDate]); + await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 0, 0, "reputation-1-1-1-uuid-2", users["high-non-self-downvotes"].pubID, 1606240000000, 50, "sponsor", 0, 0, isoDate]); + await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 0, 0, "reputation-1-1-1-uuid-3", users["high-non-self-downvotes"].pubID, 1606240000000, 50, "sponsor", 0, 0, isoDate]); + await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 0, 0, "reputation-1-1-1-uuid-4", users["high-non-self-downvotes"].pubID, 1606240000000, 50, "sponsor", 0, 0, isoDate]); + await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, -1, 0, "reputation-1-1-1-uuid-5", users["high-non-self-downvotes"].pubID, 1606240000000, 50, "sponsor", 0, 0, isoDate]); + await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 0, 0, "reputation-1-1-1-uuid-6", users["high-non-self-downvotes"].pubID, 1606240000000, 50, "sponsor", 0, 0, isoDate]); + await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 0, 0, "reputation-1-1-1-uuid-7", users["high-non-self-downvotes"].pubID, 1606240000000, 50, "sponsor", 0, 0, isoDate]); + + await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 2, 0, "reputation-2-uuid-0", users["new-submissions"].pubID, Date.now(), 50, "sponsor", 0, 0, isoDate]); + await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 2, 0, "reputation-2-uuid-1", users["new-submissions"].pubID, Date.now(), 50, "sponsor", 0, 0, isoDate]); + await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 2, 0, "reputation-2-uuid-2", users["new-submissions"].pubID, Date.now(), 50, "sponsor", 0, 0, isoDate]); + await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 2, 0, "reputation-2-uuid-3", users["new-submissions"].pubID, Date.now(), 50, "sponsor", 0, 0, isoDate]); + await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 2, 0, "reputation-2-uuid-4", users["new-submissions"].pubID, Date.now(), 50, "sponsor", 0, 0, isoDate]); + await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, -1, 0, "reputation-2-uuid-5", users["new-submissions"].pubID, 1606240000000, 50, "sponsor", 0, 0, isoDate]); + await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 0, 0, "reputation-2-uuid-6", users["new-submissions"].pubID, 1606240000000, 50, "sponsor", 0, 0, isoDate]); + await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 0, 0, "reputation-2-uuid-7", users["new-submissions"].pubID, 1606240000000, 50, "sponsor", 0, 0, isoDate]); + + await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 2, 0, "reputation-3-uuid-0", users["low-sum"].pubID, 1606240000000, 50, "sponsor", 0, 0, isoDate]); + await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 1, 0, "reputation-3-uuid-1", users["low-sum"].pubID, 1606240000000, 50, "sponsor", 0, 0, isoDate]); + await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 0, 0, "reputation-3-uuid-2", users["low-sum"].pubID, 1606240000000, 50, "sponsor", 0, 0, isoDate]); + await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 0, 0, "reputation-3-uuid-3", users["low-sum"].pubID, 1606240000000, 50, "sponsor", 0, 0, isoDate]); + await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 1, 0, "reputation-3-uuid-4", users["low-sum"].pubID, 1606240000000, 50, "sponsor", 0, 0, isoDate]); + await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, -1, 0, "reputation-3-uuid-5", users["low-sum"].pubID, 1606240000000, 50, "sponsor", 0, 0, isoDate]); + await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 0, 0, "reputation-3-uuid-6", users["low-sum"].pubID, 1606240000000, 50, "sponsor", 0, 0, isoDate]); + await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 0, 0, "reputation-3-uuid-7", users["low-sum"].pubID, 1606240000000, 50, "sponsor", 0, 0, isoDate]); + + await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 2, 0, "reputation-4-uuid-0", users["high-rep-before-manual-vote"].pubID, 0, 50, "sponsor", 0, 0, isoDate]); + await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 2, 0, "reputation-4-uuid-1", users["high-rep-before-manual-vote"].pubID, 0, 50, "sponsor", 0, 0, isoDate]); + await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 2, 0, "reputation-4-uuid-2", users["high-rep-before-manual-vote"].pubID, 0, 50, "sponsor", 0, 0, isoDate]); + await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 2, 0, "reputation-4-uuid-3", users["high-rep-before-manual-vote"].pubID, 0, 50, "sponsor", 0, 0, isoDate]); + await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 2, 0, "reputation-4-uuid-4", users["high-rep-before-manual-vote"].pubID, 0, 50, "sponsor", 0, 0, isoDate]); + await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, -1, 0, "reputation-4-uuid-5", users["high-rep-before-manual-vote"].pubID, 0, 50, "sponsor", 0, 0, isoDate]); + await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 0, 0, "reputation-4-uuid-6", users["high-rep-before-manual-vote"].pubID, 0, 50, "sponsor", 0, 0, isoDate]); + await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 0, 0, "reputation-4-uuid-7", users["high-rep-before-manual-vote"].pubID, 0, 50, "sponsor", 0, 0, isoDate]); await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 2, 0, "reputation-5-uuid-0", users["high-rep"].pubID, 1606240000000, 50, "sponsor", 0, 0]); await db.prepare("run", sponsorTimesInsertQuery, [videoID, 1, 11, 2, 0, "reputation-5-uuid-1", users["high-rep"].pubID, 1606240000000, 50, "sponsor", 0, 0]); diff --git a/test/cases/shadowBanUser.ts b/test/cases/shadowBanUser.ts index 755bda73..10189841 100644 --- a/test/cases/shadowBanUser.ts +++ b/test/cases/shadowBanUser.ts @@ -18,36 +18,36 @@ describe("shadowBanUser", () => { const isoDate = new Date().toISOString(); before(async () => { - const insertQuery = `INSERT INTO "sponsorTimes" ("videoID", "startTime", "endTime", "votes", "locked", "UUID", "userID", "timeSubmitted", "views", "category", "service", "shadowHidden", "hashedVideoID") VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`; - await db.prepare("run", insertQuery, [video, 1, 11, 2, 0, "shadow-10", "shadowBanned", 0, 50, "sponsor", "YouTube", 0, videohash]); - await db.prepare("run", insertQuery, [video, 1, 11, 2, 0, "shadow-11", "shadowBanned", 0, 50, "sponsor", "PeerTube", 0, videohash]); - await db.prepare("run", insertQuery, [video, 20, 33, 2, 0, "shadow-12", "shadowBanned", 0, 50, "intro", "YouTube", 0, videohash]); + const insertQuery = `INSERT INTO "sponsorTimes" ("videoID", "startTime", "endTime", "votes", "locked", "UUID", "userID", "timeSubmitted", "views", "category", "service", "shadowHidden", "hashedVideoID", "updatedAt") VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`; + await db.prepare("run", insertQuery, [video, 1, 11, 2, 0, "shadow-10", "shadowBanned", 0, 50, "sponsor", "YouTube", 0, videohash, isoDate]); + await db.prepare("run", insertQuery, [video, 1, 11, 2, 0, "shadow-11", "shadowBanned", 0, 50, "sponsor", "PeerTube", 0, videohash, isoDate]); + await db.prepare("run", insertQuery, [video, 20, 33, 2, 0, "shadow-12", "shadowBanned", 0, 50, "intro", "YouTube", 0, videohash, isoDate]); - await db.prepare("run", insertQuery, [video, 1, 11, 2, 0, "shadow-20", "shadowBanned2", 0, 50, "sponsor", "YouTube", 0, videohash]); - await db.prepare("run", insertQuery, [video, 1, 11, 2, 0, "shadow-21", "shadowBanned2", 0, 50, "sponsor", "PeerTube", 0, videohash]); - await db.prepare("run", insertQuery, [video, 20, 33, 2, 0, "shadow-22", "shadowBanned2", 0, 50, "intro", "YouTube", 0, videohash]); + await db.prepare("run", insertQuery, [video, 1, 11, 2, 0, "shadow-20", "shadowBanned2", 0, 50, "sponsor", "YouTube", 0, videohash, isoDate]); + await db.prepare("run", insertQuery, [video, 1, 11, 2, 0, "shadow-21", "shadowBanned2", 0, 50, "sponsor", "PeerTube", 0, videohash, isoDate]); + await db.prepare("run", insertQuery, [video, 20, 33, 2, 0, "shadow-22", "shadowBanned2", 0, 50, "intro", "YouTube", 0, videohash, isoDate]); - await db.prepare("run", insertQuery, [video, 1, 11, 2, 0, "shadow-30", "shadowBanned3", 0, 50, "sponsor", "YouTube", 1, videohash]); - await db.prepare("run", insertQuery, [video, 1, 11, 2, 0, "shadow-31", "shadowBanned3", 0, 50, "sponsor", "PeerTube", 1, videohash]); - await db.prepare("run", insertQuery, [video, 20, 33, 2, 0, "shadow-32", "shadowBanned3", 0, 50, "intro", "YouTube", 1, videohash]); + await db.prepare("run", insertQuery, [video, 1, 11, 2, 0, "shadow-30", "shadowBanned3", 0, 50, "sponsor", "YouTube", 1, videohash, isoDate]); + await db.prepare("run", insertQuery, [video, 1, 11, 2, 0, "shadow-31", "shadowBanned3", 0, 50, "sponsor", "PeerTube", 1, videohash, isoDate]); + await db.prepare("run", insertQuery, [video, 20, 33, 2, 0, "shadow-32", "shadowBanned3", 0, 50, "intro", "YouTube", 1, videohash, isoDate]); - await db.prepare("run", insertQuery, [video, 21, 34, 2, 0, "shadow-40", "shadowBanned4", 0, 50, "sponsor", "YouTube", 0, videohash]); + await db.prepare("run", insertQuery, [video, 21, 34, 2, 0, "shadow-40", "shadowBanned4", 0, 50, "sponsor", "YouTube", 0, videohash, isoDate]); - await db.prepare("run", insertQuery, [video, 20, 10, 2, 0, "shadow-50", "shadowBanned5", 0, 50, "sponsor", "YouTube", 0, videohash]); + await db.prepare("run", insertQuery, [video, 20, 10, 2, 0, "shadow-50", "shadowBanned5", 0, 50, "sponsor", "YouTube", 0, videohash, isoDate]); - await db.prepare("run", insertQuery, [video, 10, 10, 2, 1, "shadow-60", "shadowBanned6", 0, 50, "sponsor", "YouTube", 0, videohash]); - await db.prepare("run", insertQuery, ["lockedVideo", 10, 10, 2, 1, "shadow-61", "shadowBanned6", 0, 50, "sponsor", "YouTube", 0, getHash("lockedVideo", 1)]); + await db.prepare("run", insertQuery, [video, 10, 10, 2, 1, "shadow-60", "shadowBanned6", 0, 50, "sponsor", "YouTube", 0, videohash, isoDate]); + await db.prepare("run", insertQuery, ["lockedVideo", 10, 10, 2, 1, "shadow-61", "shadowBanned6", 0, 50, "sponsor", "YouTube", 0, getHash("lockedVideo", 1), isoDate]); - await db.prepare("run", insertQuery, [video, 20, 10, 2, 0, "shadow-70", "shadowBanned7", 383848, 50, "sponsor", "YouTube", 0, videohash]); - await db.prepare("run", insertQuery, [video, 20, 10, 2, 0, "shadow-71", "shadowBanned7", 2332, 50, "intro", "YouTube", 0, videohash]); - await db.prepare("run", insertQuery, [video, 20, 10, 2, 0, "shadow-72", "shadowBanned7", 4923, 50, "interaction", "YouTube", 0, videohash]); + await db.prepare("run", insertQuery, [video, 20, 10, 2, 0, "shadow-70", "shadowBanned7", 383848, 50, "sponsor", "YouTube", 0, videohash, isoDate]); + await db.prepare("run", insertQuery, [video, 20, 10, 2, 0, "shadow-71", "shadowBanned7", 2332, 50, "intro", "YouTube", 0, videohash, isoDate]); + await db.prepare("run", insertQuery, [video, 20, 10, 2, 0, "shadow-72", "shadowBanned7", 4923, 50, "interaction", "YouTube", 0, videohash, isoDate]); - await db.prepare("run", insertQuery, [video, 20, 10, 2, 0, "shadow-80", "shadowBanned8", 1674590916068933, 50, "sponsor", "YouTube", 0, videohash]); - await db.prepare("run", insertQuery, [video, 20, 10, 2, 0, "shadow-81", "shadowBanned8", 1674590916062936, 50, "intro", "YouTube", 0, videohash]); - await db.prepare("run", insertQuery, [video, 20, 10, 2, 0, "shadow-82", "shadowBanned8", 1674590916064324, 50, "interaction", "YouTube", 0, videohash]); - await db.prepare("run", insertQuery, [video, 20, 10, 2, 0, "shadow-90", "shadowBanned9", 1674590916062443, 50, "sponsor", "YouTube", 0, videohash]); - await db.prepare("run", insertQuery, [video, 20, 10, 2, 0, "shadow-91", "shadowBanned9", 1674590916062342, 50, "intro", "YouTube", 0, videohash]); - await db.prepare("run", insertQuery, [video, 20, 10, 2, 0, "shadow-92", "shadowBanned9", 1674590916069491, 50, "interaction", "YouTube", 0, videohash]); + await db.prepare("run", insertQuery, [video, 20, 10, 2, 0, "shadow-80", "shadowBanned8", 1674590916068933, 50, "sponsor", "YouTube", 0, videohash, isoDate]); + await db.prepare("run", insertQuery, [video, 20, 10, 2, 0, "shadow-81", "shadowBanned8", 1674590916062936, 50, "intro", "YouTube", 0, videohash, isoDate]); + await db.prepare("run", insertQuery, [video, 20, 10, 2, 0, "shadow-82", "shadowBanned8", 1674590916064324, 50, "interaction", "YouTube", 0, videohash, isoDate]); + await db.prepare("run", insertQuery, [video, 20, 10, 2, 0, "shadow-90", "shadowBanned9", 1674590916062443, 50, "sponsor", "YouTube", 0, videohash, isoDate]); + await db.prepare("run", insertQuery, [video, 20, 10, 2, 0, "shadow-91", "shadowBanned9", 1674590916062342, 50, "intro", "YouTube", 0, videohash, isoDate]); + await db.prepare("run", insertQuery, [video, 20, 10, 2, 0, "shadow-92", "shadowBanned9", 1674590916069491, 50, "interaction", "YouTube", 0, videohash, isoDate]); await db.prepare("run", `INSERT INTO "shadowBannedUsers" ("userID") VALUES(?)`, ["shadowBanned3"]); await db.prepare("run", `INSERT INTO "shadowBannedUsers" ("userID") VALUES(?)`, ["shadowBanned4"]); diff --git a/test/cases/tempVip.ts b/test/cases/tempVip.ts index 4bf01353..f94fd430 100644 --- a/test/cases/tempVip.ts +++ b/test/cases/tempVip.ts @@ -58,10 +58,10 @@ describe("tempVIP test", function() { before(async function() { if (!config.redis?.enabled) this.skip(); - const insertSponsorTimeQuery = 'INSERT INTO "sponsorTimes" ("videoID", "startTime", "endTime", "votes", "locked", "UUID", "userID", "timeSubmitted", "views", "category", "shadowHidden") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)'; - await db.prepare("run", insertSponsorTimeQuery, ["channelid-convert", 0, 1, 0, 0, UUID0, "testman", 0, 50, "sponsor", 0]); - await db.prepare("run", insertSponsorTimeQuery, ["channelid-convert", 1, 9, 0, 1, "tempvip-submit", publicTempVIPOne, 0, 50, "sponsor", 0]); - await db.prepare("run", insertSponsorTimeQuery, ["otherchannel", 1, 9, 0, 1, UUID1, "testman", 0, 50, "sponsor", 0]); + const insertSponsorTimeQuery = 'INSERT INTO "sponsorTimes" ("videoID", "startTime", "endTime", "votes", "locked", "UUID", "userID", "timeSubmitted", "views", "category", "shadowHidden", "updatedAt") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)'; + await db.prepare("run", insertSponsorTimeQuery, ["channelid-convert", 0, 1, 0, 0, UUID0, "testman", 0, 50, "sponsor", 0, isoDate]); + await db.prepare("run", insertSponsorTimeQuery, ["channelid-convert", 1, 9, 0, 1, "tempvip-submit", publicTempVIPOne, 0, 50, "sponsor", 0, isoDate]); + await db.prepare("run", insertSponsorTimeQuery, ["otherchannel", 1, 9, 0, 1, UUID1, "testman", 0, 50, "sponsor", 0, isoDate]); await db.prepare("run", 'INSERT INTO "vipUsers" ("userID", "createdAt") VALUES (?, ?)', [publicPermVIP1, isoDate]); await db.prepare("run", 'INSERT INTO "vipUsers" ("userID", "createdAt") VALUES (?, ?)', [publicPermVIP2, isoDate]); diff --git a/test/cases/unBan.ts b/test/cases/unBan.ts index 71637b3e..1a2a2a04 100644 --- a/test/cases/unBan.ts +++ b/test/cases/unBan.ts @@ -29,11 +29,11 @@ describe("unBan", () => { const insertLockCategoryQuery = 'INSERT INTO "lockCategories" ("userID", "videoID", "category") VALUES(?, ?, ?)'; await db.prepare("run", insertLockCategoryQuery, [getHash(VIPuser), "unBan-videoID-1", "sponsor"]); - const insertSponsorTimeQuery = 'INSERT INTO "sponsorTimes" ("videoID", "startTime", "endTime", "votes", "UUID", "userID", "timeSubmitted", views, category, "shadowHidden", "hashedVideoID") VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)'; - await db.prepare("run", insertSponsorTimeQuery, ["unBan-videoID-0", 1, 11, 2, "unBan-uuid-0", "testMan-unBan", 0, 50, "sponsor", 1, getHash("unBan-videoID-0", 1)]); - await db.prepare("run", insertSponsorTimeQuery, ["unBan-videoID-1", 1, 11, 2, "unBan-uuid-1", "testWoman-unBan", 0, 50, "sponsor", 1, getHash("unBan-videoID-1", 1)]); - await db.prepare("run", insertSponsorTimeQuery, ["unBan-videoID-1", 1, 11, 2, "unBan-uuid-2", "testEntity-unBan", 0, 60, "sponsor", 1, getHash("unBan-videoID-1", 1)]); - await db.prepare("run", insertSponsorTimeQuery, ["unBan-videoID-2", 1, 11, 2, "unBan-uuid-3", "testEntity-unBan", 0, 60, "sponsor", 1, getHash("unBan-videoID-2", 1)]); + const insertSponsorTimeQuery = 'INSERT INTO "sponsorTimes" ("videoID", "startTime", "endTime", "votes", "UUID", "userID", "timeSubmitted", views, category, "shadowHidden", "hashedVideoID", "updatedAt") VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)'; + await db.prepare("run", insertSponsorTimeQuery, ["unBan-videoID-0", 1, 11, 2, "unBan-uuid-0", "testMan-unBan", 0, 50, "sponsor", 1, getHash("unBan-videoID-0", 1), isoDate]); + await db.prepare("run", insertSponsorTimeQuery, ["unBan-videoID-1", 1, 11, 2, "unBan-uuid-1", "testWoman-unBan", 0, 50, "sponsor", 1, getHash("unBan-videoID-1", 1), isoDate]); + await db.prepare("run", insertSponsorTimeQuery, ["unBan-videoID-1", 1, 11, 2, "unBan-uuid-2", "testEntity-unBan", 0, 60, "sponsor", 1, getHash("unBan-videoID-1", 1), isoDate]); + await db.prepare("run", insertSponsorTimeQuery, ["unBan-videoID-2", 1, 11, 2, "unBan-uuid-3", "testEntity-unBan", 0, 60, "sponsor", 1, getHash("unBan-videoID-2", 1), isoDate]); }); it("Should be able to unban a user and re-enable shadow banned segments", (done) => { diff --git a/test/cases/voteOnSponsorTime.ts b/test/cases/voteOnSponsorTime.ts index 38ebbd74..e20901cc 100644 --- a/test/cases/voteOnSponsorTime.ts +++ b/test/cases/voteOnSponsorTime.ts @@ -29,65 +29,66 @@ describe("voteOnSponsorTime", () => { const categoryChangeUserHash = getHash(categoryChangeUser); const MILLISECONDS_IN_HOUR = 3600000; const warningExpireTime = MILLISECONDS_IN_HOUR * config.hoursAfterWarningExpires; - - const insertSponsorTimeQuery = 'INSERT INTO "sponsorTimes" ("videoID", "startTime", "endTime", "votes", "locked", "UUID", "userID", "timeSubmitted", "views", "category", "actionType", "shadowHidden", "hidden") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)'; - await db.prepare("run", insertSponsorTimeQuery, ["vote-testtesttest", 1, 11, 2, 0, "vote-uuid-0", "testman", 0, 50, "sponsor", "skip", 0, 0]); - await db.prepare("run", insertSponsorTimeQuery, ["vote-testtesttest2", 1, 11, 2, 0, "vote-uuid-1", "testman", 0, 50, "sponsor", "skip", 0, 0]); - await db.prepare("run", insertSponsorTimeQuery, ["vote-testtesttest2", 1, 11, 10, 0, "vote-uuid-1.5", "testman", 0, 50, "outro", "skip", 0, 0]); - await db.prepare("run", insertSponsorTimeQuery, ["vote-testtesttest2", 1, 11, 10, 0, "vote-uuid-1.6", "testman", 0, 50, "interaction", "skip", 0, 0]); - await db.prepare("run", insertSponsorTimeQuery, ["vote-testtesttest3", 20, 33, 10, 0, "vote-uuid-2", "testman", 0, 50, "sponsor", "skip", 0, 0]); - await db.prepare("run", insertSponsorTimeQuery, ["vote-testtesttest,test", 1, 11, 100, 0, "vote-uuid-3", "testman", 0, 50, "sponsor", "skip", 0, 0]); - await db.prepare("run", insertSponsorTimeQuery, ["vote-test3", 1, 11, 2, 0, "vote-uuid-4", "testman", 0, 50, "sponsor", "skip", 0, 0]); - await db.prepare("run", insertSponsorTimeQuery, ["vote-test3", 7, 22, -3, 0, "vote-uuid-5", "testman", 0, 50, "intro", "skip", 0, 0]); - await db.prepare("run", insertSponsorTimeQuery, ["vote-multiple", 1, 11, 2, 0, "vote-uuid-6", "testman", 0, 50, "intro", "skip", 0, 0]); - await db.prepare("run", insertSponsorTimeQuery, ["vote-multiple", 20, 33, 2, 0, "vote-uuid-7", "testman", 0, 50, "intro", "skip", 0, 0]); - await db.prepare("run", insertSponsorTimeQuery, ["voter-submitter", 1, 11, 2, 0, "vote-uuid-8", getHash("randomID"), 0, 50, "sponsor", "skip", 0, 0]); - await db.prepare("run", insertSponsorTimeQuery, ["voter-submitter2", 1, 11, 2, 0, "vote-uuid-9", randomID2Hashed, 0, 50, "sponsor", "skip", 0, 0]); - await db.prepare("run", insertSponsorTimeQuery, ["voter-submitter2", 1, 11, 2, 0, "vote-uuid-10", getHash("randomID3"), 0, 50, "sponsor", "skip", 0, 0]); - await db.prepare("run", insertSponsorTimeQuery, ["voter-submitter2", 1, 11, 2, 0, "vote-uuid-11", getHash("randomID4"), 0, 50, "sponsor", "skip", 0, 0]); - await db.prepare("run", insertSponsorTimeQuery, ["own-submission-video", 1, 11, 500, 0, "own-submission-uuid", getHash("own-submission-id"), 0, 50, "sponsor", "skip", 0, 0]); - await db.prepare("run", insertSponsorTimeQuery, ["not-own-submission-video", 1, 11, 500, 0, "not-own-submission-uuid", getHash("somebody-else-id"), 0, 50, "sponsor", "skip", 0, 0]); - await db.prepare("run", insertSponsorTimeQuery, ["incorrect-category", 1, 11, 500, 0, "incorrect-category", getHash("somebody-else-id"), 0, 50, "sponsor", "skip", 0, 0]); - await db.prepare("run", insertSponsorTimeQuery, ["incorrect-category-change", 1, 11, 500, 0, "incorrect-category-change", getHash("somebody-else-id"), 0, 50, "sponsor", "skip", 0, 0]); - await db.prepare("run", insertSponsorTimeQuery, ["vote-testtesttest", 1, 11, 2, 0, "warnvote-uuid-0", "testman", 0, 50, "sponsor", "skip", 0, 0]); - await db.prepare("run", insertSponsorTimeQuery, ["no-sponsor-segments-video", 1, 11, 2, 0, "no-sponsor-segments-uuid-0", "no-sponsor-segments", 0, 50, "sponsor", "skip", 0, 0]); - await db.prepare("run", insertSponsorTimeQuery, ["no-sponsor-segments-video", 1, 11, 2, 0, "no-sponsor-segments-uuid-1", "no-sponsor-segments", 0, 50, "intro", "skip", 0, 0]); - await db.prepare("run", insertSponsorTimeQuery, ["no-sponsor-segments-video", 1, 11, 2, 0, "no-sponsor-segments-uuid-2", "no-sponsor-segments", 0, 50, "sponsor", "mute", 0, 0]); - await db.prepare("run", insertSponsorTimeQuery, ["segment-locking-video", 1, 11, 2, 0, "segment-locking-uuid-1", "segment-locking-user", 0, 50, "intro", "skip", 0, 0]); - await db.prepare("run", insertSponsorTimeQuery, ["segment-hidden-video", 1, 11, 2, 0, "segment-hidden-uuid-1", "segment-hidden-user", 0, 50, "intro", "skip", 0, 1]); - await db.prepare("run", insertSponsorTimeQuery, ["category-change-test-1", 7, 22, 0, 0, "category-change-uuid-1", categoryChangeUserHash, 0, 50, "intro", "skip", 0, 0]); - await db.prepare("run", insertSponsorTimeQuery, ["category-change-test-1", 8, 22, 0, 1, "category-change-uuid-2", categoryChangeUserHash, 0, 50, "intro", "skip", 0, 0]); - await db.prepare("run", insertSponsorTimeQuery, ["category-change-test-1", 9, 22, 0, 0, "category-change-uuid-3", categoryChangeUserHash, 0, 50, "intro", "skip", 0, 0]); - await db.prepare("run", insertSponsorTimeQuery, ["category-change-test-1", 7, 12, 0, 1, "category-change-uuid-4", categoryChangeUserHash, 0, 50, "intro", "skip", 0, 0]); - await db.prepare("run", insertSponsorTimeQuery, ["category-change-test-1", 7, 13, 0, 0, "category-change-uuid-5", categoryChangeUserHash, 0, 50, "intro", "skip", 0, 0]); - await db.prepare("run", insertSponsorTimeQuery, ["category-change-test-1", 8, 12, 0, 1, "category-change-uuid-6", categoryChangeUserHash, 0, 50, "intro", "skip", 0, 0]); - await db.prepare("run", insertSponsorTimeQuery, ["category-change-test-1", 9, 14, 0, 0, "category-change-uuid-7", categoryChangeUserHash, 0, 50, "intro", "skip", 0, 0]); - await db.prepare("run", insertSponsorTimeQuery, ["category-change-test-1", 7, 12, 0, 1, "category-change-uuid-8", categoryChangeUserHash, 0, 50, "intro", "skip", 0, 0]); - await db.prepare("run", insertSponsorTimeQuery, ["category-change-test-2", 7, 14, 0, 0, "category-warnvote-uuid-0", categoryChangeUserHash, 0, 50, "intro", "skip", 0, 0]); - await db.prepare("run", insertSponsorTimeQuery, ["category-change-test-2", 8, 13, 0, 0, "category-banvote-uuid-0", categoryChangeUserHash, 0, 50, "intro", "skip", 0, 0]); - await db.prepare("run", insertSponsorTimeQuery, ["duration-update", 1, 10, 0, 0, "duration-update-uuid-1", "testman", 0, 0, "intro", "skip", 0, 0]); - await db.prepare("run", insertSponsorTimeQuery, ["full-video", 1, 10, 0, 0, "full-video-uuid-1", "testman", 0, 0, "sponsor", "full", 0, 0]); + const isoDate = new Date().toISOString(); + + const insertSponsorTimeQuery = 'INSERT INTO "sponsorTimes" ("videoID", "startTime", "endTime", "votes", "locked", "UUID", "userID", "timeSubmitted", "views", "category", "actionType", "shadowHidden", "hidden", "updatedAt") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)'; + await db.prepare("run", insertSponsorTimeQuery, ["vote-testtesttest", 1, 11, 2, 0, "vote-uuid-0", "testman", 0, 50, "sponsor", "skip", 0, 0, isoDate]); + await db.prepare("run", insertSponsorTimeQuery, ["vote-testtesttest2", 1, 11, 2, 0, "vote-uuid-1", "testman", 0, 50, "sponsor", "skip", 0, 0, isoDate]); + await db.prepare("run", insertSponsorTimeQuery, ["vote-testtesttest2", 1, 11, 10, 0, "vote-uuid-1.5", "testman", 0, 50, "outro", "skip", 0, 0, isoDate]); + await db.prepare("run", insertSponsorTimeQuery, ["vote-testtesttest2", 1, 11, 10, 0, "vote-uuid-1.6", "testman", 0, 50, "interaction", "skip", 0, 0, isoDate]); + await db.prepare("run", insertSponsorTimeQuery, ["vote-testtesttest3", 20, 33, 10, 0, "vote-uuid-2", "testman", 0, 50, "sponsor", "skip", 0, 0, isoDate]); + await db.prepare("run", insertSponsorTimeQuery, ["vote-testtesttest,test", 1, 11, 100, 0, "vote-uuid-3", "testman", 0, 50, "sponsor", "skip", 0, 0, isoDate]); + await db.prepare("run", insertSponsorTimeQuery, ["vote-test3", 1, 11, 2, 0, "vote-uuid-4", "testman", 0, 50, "sponsor", "skip", 0, 0, isoDate]); + await db.prepare("run", insertSponsorTimeQuery, ["vote-test3", 7, 22, -3, 0, "vote-uuid-5", "testman", 0, 50, "intro", "skip", 0, 0, isoDate]); + await db.prepare("run", insertSponsorTimeQuery, ["vote-multiple", 1, 11, 2, 0, "vote-uuid-6", "testman", 0, 50, "intro", "skip", 0, 0, isoDate]); + await db.prepare("run", insertSponsorTimeQuery, ["vote-multiple", 20, 33, 2, 0, "vote-uuid-7", "testman", 0, 50, "intro", "skip", 0, 0, isoDate]); + await db.prepare("run", insertSponsorTimeQuery, ["voter-submitter", 1, 11, 2, 0, "vote-uuid-8", getHash("randomID"), 0, 50, "sponsor", "skip", 0, 0, isoDate]); + await db.prepare("run", insertSponsorTimeQuery, ["voter-submitter2", 1, 11, 2, 0, "vote-uuid-9", randomID2Hashed, 0, 50, "sponsor", "skip", 0, 0, isoDate]); + await db.prepare("run", insertSponsorTimeQuery, ["voter-submitter2", 1, 11, 2, 0, "vote-uuid-10", getHash("randomID3"), 0, 50, "sponsor", "skip", 0, 0, isoDate]); + await db.prepare("run", insertSponsorTimeQuery, ["voter-submitter2", 1, 11, 2, 0, "vote-uuid-11", getHash("randomID4"), 0, 50, "sponsor", "skip", 0, 0, isoDate]); + await db.prepare("run", insertSponsorTimeQuery, ["own-submission-video", 1, 11, 500, 0, "own-submission-uuid", getHash("own-submission-id"), 0, 50, "sponsor", "skip", 0, 0, isoDate]); + await db.prepare("run", insertSponsorTimeQuery, ["not-own-submission-video", 1, 11, 500, 0, "not-own-submission-uuid", getHash("somebody-else-id"), 0, 50, "sponsor", "skip", 0, 0, isoDate]); + await db.prepare("run", insertSponsorTimeQuery, ["incorrect-category", 1, 11, 500, 0, "incorrect-category", getHash("somebody-else-id"), 0, 50, "sponsor", "skip", 0, 0, isoDate]); + await db.prepare("run", insertSponsorTimeQuery, ["incorrect-category-change", 1, 11, 500, 0, "incorrect-category-change", getHash("somebody-else-id"), 0, 50, "sponsor", "skip", 0, 0, isoDate]); + await db.prepare("run", insertSponsorTimeQuery, ["vote-testtesttest", 1, 11, 2, 0, "warnvote-uuid-0", "testman", 0, 50, "sponsor", "skip", 0, 0, isoDate]); + await db.prepare("run", insertSponsorTimeQuery, ["no-sponsor-segments-video", 1, 11, 2, 0, "no-sponsor-segments-uuid-0", "no-sponsor-segments", 0, 50, "sponsor", "skip", 0, 0, isoDate]); + await db.prepare("run", insertSponsorTimeQuery, ["no-sponsor-segments-video", 1, 11, 2, 0, "no-sponsor-segments-uuid-1", "no-sponsor-segments", 0, 50, "intro", "skip", 0, 0, isoDate]); + await db.prepare("run", insertSponsorTimeQuery, ["no-sponsor-segments-video", 1, 11, 2, 0, "no-sponsor-segments-uuid-2", "no-sponsor-segments", 0, 50, "sponsor", "mute", 0, 0, isoDate]); + await db.prepare("run", insertSponsorTimeQuery, ["segment-locking-video", 1, 11, 2, 0, "segment-locking-uuid-1", "segment-locking-user", 0, 50, "intro", "skip", 0, 0, isoDate]); + await db.prepare("run", insertSponsorTimeQuery, ["segment-hidden-video", 1, 11, 2, 0, "segment-hidden-uuid-1", "segment-hidden-user", 0, 50, "intro", "skip", 0, 1, isoDate]); + await db.prepare("run", insertSponsorTimeQuery, ["category-change-test-1", 7, 22, 0, 0, "category-change-uuid-1", categoryChangeUserHash, 0, 50, "intro", "skip", 0, 0, isoDate]); + await db.prepare("run", insertSponsorTimeQuery, ["category-change-test-1", 8, 22, 0, 1, "category-change-uuid-2", categoryChangeUserHash, 0, 50, "intro", "skip", 0, 0, isoDate]); + await db.prepare("run", insertSponsorTimeQuery, ["category-change-test-1", 9, 22, 0, 0, "category-change-uuid-3", categoryChangeUserHash, 0, 50, "intro", "skip", 0, 0, isoDate]); + await db.prepare("run", insertSponsorTimeQuery, ["category-change-test-1", 7, 12, 0, 1, "category-change-uuid-4", categoryChangeUserHash, 0, 50, "intro", "skip", 0, 0, isoDate]); + await db.prepare("run", insertSponsorTimeQuery, ["category-change-test-1", 7, 13, 0, 0, "category-change-uuid-5", categoryChangeUserHash, 0, 50, "intro", "skip", 0, 0, isoDate]); + await db.prepare("run", insertSponsorTimeQuery, ["category-change-test-1", 8, 12, 0, 1, "category-change-uuid-6", categoryChangeUserHash, 0, 50, "intro", "skip", 0, 0, isoDate]); + await db.prepare("run", insertSponsorTimeQuery, ["category-change-test-1", 9, 14, 0, 0, "category-change-uuid-7", categoryChangeUserHash, 0, 50, "intro", "skip", 0, 0, isoDate]); + await db.prepare("run", insertSponsorTimeQuery, ["category-change-test-1", 7, 12, 0, 1, "category-change-uuid-8", categoryChangeUserHash, 0, 50, "intro", "skip", 0, 0, isoDate]); + await db.prepare("run", insertSponsorTimeQuery, ["category-change-test-2", 7, 14, 0, 0, "category-warnvote-uuid-0", categoryChangeUserHash, 0, 50, "intro", "skip", 0, 0, isoDate]); + await db.prepare("run", insertSponsorTimeQuery, ["category-change-test-2", 8, 13, 0, 0, "category-banvote-uuid-0", categoryChangeUserHash, 0, 50, "intro", "skip", 0, 0, isoDate]); + await db.prepare("run", insertSponsorTimeQuery, ["duration-update", 1, 10, 0, 0, "duration-update-uuid-1", "testman", 0, 0, "intro", "skip", 0, 0, isoDate]); + await db.prepare("run", insertSponsorTimeQuery, ["full-video", 1, 10, 0, 0, "full-video-uuid-1", "testman", 0, 0, "sponsor", "full", 0, 0, isoDate]); // videoDuration change - await db.prepare("run", insertSponsorTimeQuery, ["duration-changed", 1, 10, 0, 0, "duration-changed-uuid-1", "testman", 1, 0, "sponsor", "skip", 0, 0]); - await db.prepare("run", insertSponsorTimeQuery, ["duration-changed", 1, 11, 0, 0, "duration-changed-uuid-2", "testman", 10, 0, "sponsor", "skip", 0, 0]); - await db.prepare("run", insertSponsorTimeQuery, ["duration-changed", 1, 12, 0, 0, "duration-changed-uuid-3", "testman", 20, 0, "sponsor", "skip", 0, 0]); + await db.prepare("run", insertSponsorTimeQuery, ["duration-changed", 1, 10, 0, 0, "duration-changed-uuid-1", "testman", 1, 0, "sponsor", "skip", 0, 0, isoDate]); + await db.prepare("run", insertSponsorTimeQuery, ["duration-changed", 1, 11, 0, 0, "duration-changed-uuid-2", "testman", 10, 0, "sponsor", "skip", 0, 0, isoDate]); + await db.prepare("run", insertSponsorTimeQuery, ["duration-changed", 1, 12, 0, 0, "duration-changed-uuid-3", "testman", 20, 0, "sponsor", "skip", 0, 0, isoDate]); // add videoDuration to duration-changed-uuid-2 await db.prepare("run", `UPDATE "sponsorTimes" SET "videoDuration" = 150 WHERE "UUID" = 'duration-changed-uuid-2'`); - await db.prepare("run", insertSponsorTimeQuery, ["chapter-video", 1, 10, 0, 0, "chapter-uuid-1", "testman", 0, 0, "chapter", "chapter", 0, 0]); - await db.prepare("run", insertSponsorTimeQuery, ["chapter-video", 1, 10, 0, 0, "non-chapter-uuid-2", "testman", 0, 0, "sponsor", "skip", 0, 0]); - await db.prepare("run", insertSponsorTimeQuery, ["chapter-video", 11, 20, 0, 0, "chapter-uuid-2", randomID2Hashed, 0, 0, "chapter", "chapter", 0, 0]); + await db.prepare("run", insertSponsorTimeQuery, ["chapter-video", 1, 10, 0, 0, "chapter-uuid-1", "testman", 0, 0, "chapter", "chapter", 0, 0, isoDate]); + await db.prepare("run", insertSponsorTimeQuery, ["chapter-video", 1, 10, 0, 0, "non-chapter-uuid-2", "testman", 0, 0, "sponsor", "skip", 0, 0, isoDate]); + await db.prepare("run", insertSponsorTimeQuery, ["chapter-video", 11, 20, 0, 0, "chapter-uuid-2", randomID2Hashed, 0, 0, "chapter", "chapter", 0, 0, isoDate]); // segments for testing stricter voting requirements - await db.prepare("run", insertSponsorTimeQuery, ["vote-requirements-video", 1, 10, 0, 0, "good-outro-submission", getHash(outroSubmitter), 0, 0, "outro", "skip", 0, 0]); - await db.prepare("run", insertSponsorTimeQuery, ["vote-requirements-video", 1, 10, -2, 0, "bad-intro-submission", getHash(badIntroSubmitter), 0, 0, "intro", "skip", 0, 0]); - await db.prepare("run", insertSponsorTimeQuery, ["vote-requirements-video", 1, 10, 0, 0, "hidden-interaction-submission", getHash(hiddenInteractionSubmitter), 0, 0, "interaction", "skip", 0, 1]); - await db.prepare("run", insertSponsorTimeQuery, ["vote-requirements-video", 1, 10, 0, 0, "testing-outro-skip-1", "testman", 0, 0, "outro", "skip", 0, 1]); - await db.prepare("run", insertSponsorTimeQuery, ["vote-requirements-video", 22, 25, 0, 0, "testing-outro-skip-2", "testman", 0, 0, "outro", "skip", 0, 1]); - await db.prepare("run", insertSponsorTimeQuery, ["vote-requirements-video", 1, 10, 0, 0, "testing-outro-mute-1", "testman", 0, 0, "outro", "mute", 0, 1]); - await db.prepare("run", insertSponsorTimeQuery, ["vote-requirements-video", 22, 25, 0, 0, "testing-outro-mute-2", "testman", 0, 0, "outro", "mute", 0, 1]); - await db.prepare("run", insertSponsorTimeQuery, ["vote-requirements-video", 1, 10, 0, 0, "testing-intro-skip-1", "testman", 0, 0, "intro", "skip", 0, 1]); - await db.prepare("run", insertSponsorTimeQuery, ["vote-requirements-video", 22, 25, 0, 0, "testing-intro-skip-2", "testman", 0, 0, "intro", "skip", 0, 1]); - await db.prepare("run", insertSponsorTimeQuery, ["vote-requirements-video", 1, 10, 0, 0, "testing-interaction-skip-1", "testman", 0, 0, "interaction", "skip", 0, 1]); - await db.prepare("run", insertSponsorTimeQuery, ["vote-requirements-video", 22, 25, 0, 0, "testing-interaction-skip-2", "testman", 0, 0, "interaction", "skip", 0, 1]); + await db.prepare("run", insertSponsorTimeQuery, ["vote-requirements-video", 1, 10, 0, 0, "good-outro-submission", getHash(outroSubmitter), 0, 0, "outro", "skip", 0, 0, isoDate]); + await db.prepare("run", insertSponsorTimeQuery, ["vote-requirements-video", 1, 10, -2, 0, "bad-intro-submission", getHash(badIntroSubmitter), 0, 0, "intro", "skip", 0, 0, isoDate]); + await db.prepare("run", insertSponsorTimeQuery, ["vote-requirements-video", 1, 10, 0, 0, "hidden-interaction-submission", getHash(hiddenInteractionSubmitter), 0, 0, "interaction", "skip", 0, 1, isoDate]); + await db.prepare("run", insertSponsorTimeQuery, ["vote-requirements-video", 1, 10, 0, 0, "testing-outro-skip-1", "testman", 0, 0, "outro", "skip", 0, 1, isoDate]); + await db.prepare("run", insertSponsorTimeQuery, ["vote-requirements-video", 22, 25, 0, 0, "testing-outro-skip-2", "testman", 0, 0, "outro", "skip", 0, 1, isoDate]); + await db.prepare("run", insertSponsorTimeQuery, ["vote-requirements-video", 1, 10, 0, 0, "testing-outro-mute-1", "testman", 0, 0, "outro", "mute", 0, 1, isoDate]); + await db.prepare("run", insertSponsorTimeQuery, ["vote-requirements-video", 22, 25, 0, 0, "testing-outro-mute-2", "testman", 0, 0, "outro", "mute", 0, 1, isoDate]); + await db.prepare("run", insertSponsorTimeQuery, ["vote-requirements-video", 1, 10, 0, 0, "testing-intro-skip-1", "testman", 0, 0, "intro", "skip", 0, 1, isoDate]); + await db.prepare("run", insertSponsorTimeQuery, ["vote-requirements-video", 22, 25, 0, 0, "testing-intro-skip-2", "testman", 0, 0, "intro", "skip", 0, 1, isoDate]); + await db.prepare("run", insertSponsorTimeQuery, ["vote-requirements-video", 1, 10, 0, 0, "testing-interaction-skip-1", "testman", 0, 0, "interaction", "skip", 0, 1, isoDate]); + await db.prepare("run", insertSponsorTimeQuery, ["vote-requirements-video", 22, 25, 0, 0, "testing-interaction-skip-2", "testman", 0, 0, "interaction", "skip", 0, 1, isoDate]); const insertWarningQuery = 'INSERT INTO "warnings" ("userID", "issueTime", "issuerUserID", "enabled") VALUES(?, ?, ?, ?)'; await db.prepare("run", insertWarningQuery, [warnUser01Hash, now, warnVip01Hash, 1]); diff --git a/test/utils/segmentQueryGen.ts b/test/utils/segmentQueryGen.ts index ce6fb385..3c6a281c 100644 --- a/test/utils/segmentQueryGen.ts +++ b/test/utils/segmentQueryGen.ts @@ -25,7 +25,8 @@ interface insertSegmentParams extends baseParams { videoDuration?: number, hidden?: boolean | number, shadowHidden?: boolean | number, - description?: string + description?: string, + updatedAt?: string } const defaultSegmentParams: insertSegmentParams = { videoID: "", @@ -44,7 +45,8 @@ const defaultSegmentParams: insertSegmentParams = { hidden: false, shadowHidden: false, hashedVideoID: "", - description: "" + description: "", + updatedAt: new Date().toISOString() }; const generateDefaults = (identifier: string) => ({ @@ -54,8 +56,8 @@ const generateDefaults = (identifier: string) => ({ UUID: genRandomValue("uuid", identifier, 2), }); -export const insertSegment = async(db: IDatabase, overrides: insertSegmentParams = {}, identifier?: string) => { - const query = 'INSERT INTO "sponsorTimes" ("videoID", "startTime", "endTime", "votes", "locked", "UUID", "userID", "timeSubmitted", "views", "category", "actionType", "service", "videoDuration", "hidden", "shadowHidden", "hashedVideoID", "description") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)'; +export const insertSegment = async (db: IDatabase, overrides: insertSegmentParams = {}, identifier?: string) => { + const query = 'INSERT INTO "sponsorTimes" ("videoID", "startTime", "endTime", "votes", "locked", "UUID", "userID", "timeSubmitted", "views", "category", "actionType", "service", "videoDuration", "hidden", "shadowHidden", "hashedVideoID", "description", "updatedAt") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)'; // generate defaults identifier = identifier ?? genRandom(); const defaults = generateDefaults(identifier); @@ -66,7 +68,7 @@ export const insertSegment = async(db: IDatabase, overrides: insertSegmentParams params.shadowHidden = Number(params.shadowHidden); await db.prepare("run", query, Object.values(params)); }; -export const insertChapter = async(db: IDatabase, description: string, params: insertSegmentParams = {}) => { +export const insertChapter = async (db: IDatabase, description: string, params: insertSegmentParams = {}) => { const overrides = { category: "chapter", actionType: "chapter", description, ...params }; await insertSegment(db, overrides); }; From 2919d06063e00104c979278af452d63df67ab748 Mon Sep 17 00:00:00 2001 From: Tristan Date: Mon, 16 Sep 2024 18:48:20 +0200 Subject: [PATCH 22/27] test(sponsorTimes): impl updatedAt for update queries --- test/cases/segmentShift.ts | 4 ++-- test/cases/voteOnSponsorTime.ts | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/test/cases/segmentShift.ts b/test/cases/segmentShift.ts index c6de12f5..5e879d60 100644 --- a/test/cases/segmentShift.ts +++ b/test/cases/segmentShift.ts @@ -20,8 +20,8 @@ describe("segmentShift", function () { [videoID, startTime, endTime, votes, UUID, userID, timeSubmitted, views, category, shadowHidden, hashedVideoID]); } - async function dbSponsorTimesSetByUUID(db: IDatabase, UUID: string, startTime: number, endTime: number) { - await db.prepare("run", `UPDATE "sponsorTimes" SET "startTime" = ?, "endTime" = ? WHERE "UUID" = ?`, [startTime, endTime, UUID]); + async function dbSponsorTimesSetByUUID(db: IDatabase, UUID: string, startTime: number, endTime: number, isoDate: string = new Date().toISOString()) { + await db.prepare("run", `UPDATE "sponsorTimes" SET "startTime" = ?, "endTime" = ?, "updatedAt" = ? WHERE "UUID" = ?`, [startTime, endTime, isoDate, UUID]); } async function dbSponsorTimesCompareExpect(db: IDatabase, expect: any): Promise { diff --git a/test/cases/voteOnSponsorTime.ts b/test/cases/voteOnSponsorTime.ts index e20901cc..a512cf41 100644 --- a/test/cases/voteOnSponsorTime.ts +++ b/test/cases/voteOnSponsorTime.ts @@ -73,7 +73,7 @@ describe("voteOnSponsorTime", () => { await db.prepare("run", insertSponsorTimeQuery, ["duration-changed", 1, 11, 0, 0, "duration-changed-uuid-2", "testman", 10, 0, "sponsor", "skip", 0, 0, isoDate]); await db.prepare("run", insertSponsorTimeQuery, ["duration-changed", 1, 12, 0, 0, "duration-changed-uuid-3", "testman", 20, 0, "sponsor", "skip", 0, 0, isoDate]); // add videoDuration to duration-changed-uuid-2 - await db.prepare("run", `UPDATE "sponsorTimes" SET "videoDuration" = 150 WHERE "UUID" = 'duration-changed-uuid-2'`); + await db.prepare("run", `UPDATE "sponsorTimes" SET "videoDuration" = 150, "updatedAt" = ? WHERE "UUID" = 'duration-changed-uuid-2'`, [new Date().toISOString()]); await db.prepare("run", insertSponsorTimeQuery, ["chapter-video", 1, 10, 0, 0, "chapter-uuid-1", "testman", 0, 0, "chapter", "chapter", 0, 0, isoDate]); await db.prepare("run", insertSponsorTimeQuery, ["chapter-video", 1, 10, 0, 0, "non-chapter-uuid-2", "testman", 0, 0, "sponsor", "skip", 0, 0, isoDate]); await db.prepare("run", insertSponsorTimeQuery, ["chapter-video", 11, 20, 0, 0, "chapter-uuid-2", randomID2Hashed, 0, 0, "chapter", "chapter", 0, 0, isoDate]); From f35e50cd4fe9f1b9b6a89928d91cd49f896c1e4e Mon Sep 17 00:00:00 2001 From: Tristan Date: Mon, 16 Sep 2024 18:54:57 +0200 Subject: [PATCH 23/27] test(userNames): impl updatedAt --- test/cases/getLockReason.ts | 6 +++--- test/cases/getTopCategoryUsers.ts | 6 +++--- test/cases/getTopUsers.ts | 7 ++++--- test/cases/getUserStats.ts | 4 ++-- test/cases/setUsername.ts | 3 ++- test/cases/setUsernamePrivate.ts | 4 ++-- test/utils/queryGen.ts | 6 +++--- 7 files changed, 19 insertions(+), 17 deletions(-) diff --git a/test/cases/getLockReason.ts b/test/cases/getLockReason.ts index 62e4fb94..0b1ceaaa 100644 --- a/test/cases/getLockReason.ts +++ b/test/cases/getLockReason.ts @@ -18,9 +18,9 @@ describe("getLockReason", () => { await db.prepare("run", insertVipUserQuery, [vipUserID1, isoDate]); await db.prepare("run", insertVipUserQuery, [vipUserID2, isoDate]); - const insertVipUserNameQuery = 'INSERT INTO "userNames" ("userID", "userName") VALUES (?, ?)'; - await db.prepare("run", insertVipUserNameQuery, [vipUserID1, vipUserName1]); - await db.prepare("run", insertVipUserNameQuery, [vipUserID2, vipUserName2]); + const insertVipUserNameQuery = 'INSERT INTO "userNames" ("userID", "userName", "createdAt", "updatedAt") VALUES (?, ?, ?, ?)'; + await db.prepare("run", insertVipUserNameQuery, [vipUserID1, vipUserName1, isoDate, isoDate]); + await db.prepare("run", insertVipUserNameQuery, [vipUserID2, vipUserName2, isoDate, isoDate]); const insertLockCategoryQuery = 'INSERT INTO "lockCategories" ("userID", "videoID", "actionType", "category", "reason") VALUES (?, ?, ?, ?, ?)'; await db.prepare("run", insertLockCategoryQuery, [vipUserID1, "getLockReason", "skip", "sponsor", "sponsor-reason"]); diff --git a/test/cases/getTopCategoryUsers.ts b/test/cases/getTopCategoryUsers.ts index 45425a24..28677c9b 100644 --- a/test/cases/getTopCategoryUsers.ts +++ b/test/cases/getTopCategoryUsers.ts @@ -10,9 +10,9 @@ describe("getTopCategoryUsers", () => { const user1 = "gettopcategory_1"; const user2 = "gettopcategory_2"; before(async () => { - const insertUserNameQuery = 'INSERT INTO "userNames" ("userID", "userName") VALUES(?, ?)'; - await db.prepare("run", insertUserNameQuery, [getHash(user1), user1]); - await db.prepare("run", insertUserNameQuery, [getHash(user2), user2]); + const insertUserNameQuery = 'INSERT INTO "userNames" ("userID", "userName", "createdAt", "updatedAt") VALUES(?, ?, ?, ?)'; + await db.prepare("run", insertUserNameQuery, [getHash(user1), user1, isoDate, isoDate]); + await db.prepare("run", insertUserNameQuery, [getHash(user2), user2, isoDate, isoDate]); const sponsorTimesQuery = 'INSERT INTO "sponsorTimes" ("videoID", "startTime", "endTime", "votes", "UUID", "userID", "timeSubmitted", views, category, "shadowHidden", "updatedAt") VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)'; await db.prepare("run", sponsorTimesQuery, generateSegment(user1, "sponsor")); diff --git a/test/cases/getTopUsers.ts b/test/cases/getTopUsers.ts index 70e6ae91..28e4cca4 100644 --- a/test/cases/getTopUsers.ts +++ b/test/cases/getTopUsers.ts @@ -9,10 +9,11 @@ describe("getTopUsers", () => { const endpoint = "/api/getTopUsers"; const user1 = "gettop_1"; const user2 = "gettop_2"; + const isoDate = new Date().toISOString(); before(async () => { - const insertUserNameQuery = 'INSERT INTO "userNames" ("userID", "userName") VALUES(?, ?)'; - await db.prepare("run", insertUserNameQuery, [getHash(user1), user1]); - await db.prepare("run", insertUserNameQuery, [getHash(user2), user2]); + const insertUserNameQuery = 'INSERT INTO "userNames" ("userID", "userName", "createdAt", "updatedAt") VALUES(?, ?, ?, ?)'; + await db.prepare("run", insertUserNameQuery, [getHash(user1), user1, isoDate, isoDate]); + await db.prepare("run", insertUserNameQuery, [getHash(user2), user2, isoDate, isoDate]); const sponsorTimesQuery = 'INSERT INTO "sponsorTimes" ("videoID", "startTime", "endTime", "votes", "UUID", "userID", "timeSubmitted", views, category, "shadowHidden", "updatedAt") VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)'; await db.prepare("run", sponsorTimesQuery, generateSegment(user1, "sponsor")); diff --git a/test/cases/getUserStats.ts b/test/cases/getUserStats.ts index 5610ecac..33369bdc 100644 --- a/test/cases/getUserStats.ts +++ b/test/cases/getUserStats.ts @@ -20,8 +20,8 @@ describe("getUserStats", () => { const insertBanQuery = 'INSERT INTO "shadowBannedUsers" ("userID") VALUES (?)'; await db.prepare("run", insertBanQuery, [userThreePublicID]); - const insertUserNameQuery = 'INSERT INTO "userNames" ("userID", "userName") VALUES(?, ?)'; - await db.prepare("run", insertUserNameQuery, [userOnePublicID, "Username user 01"]); + const insertUserNameQuery = 'INSERT INTO "userNames" ("userID", "userName", "createdAt", "updatedAt") VALUES(?, ?, ?, ?)'; + await db.prepare("run", insertUserNameQuery, [userOnePublicID, "Username user 01", isoDate, isoDate]); const sponsorTimesQuery = 'INSERT INTO "sponsorTimes" ("videoID", "startTime", "endTime", "votes", "actionType", "UUID", "userID", "timeSubmitted", views, category, "shadowHidden", "updatedAt") VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)'; await db.prepare("run", sponsorTimesQuery, [userOnePrivateID, 0, 60, 0, "skip", "getuserstatsuuid1", userOnePublicID, 1, 1, "sponsor", 0, isoDate]); diff --git a/test/cases/setUsername.ts b/test/cases/setUsername.ts index ab379b76..c9002913 100644 --- a/test/cases/setUsername.ts +++ b/test/cases/setUsername.ts @@ -21,9 +21,10 @@ const username06 = "Username 06"; const user07PrivateUserID = "setUsername_07"; const username07 = "Username 07"; const user08PrivateUserID = "setUsername_08"; +const isoDate = new Date().toISOString(); async function addUsername(userID: string, userName: string, locked = 0) { - await db.prepare("run", 'INSERT INTO "userNames" ("userID", "userName", "locked") VALUES(?, ?, ?)', [userID, userName, locked]); + await db.prepare("run", 'INSERT INTO "userNames" ("userID", "userName", "locked", "createdAt", "updatedAt") VALUES(?, ?, ?, ?, ?)', [userID, userName, locked, isoDate, isoDate]); await addLogUserNameChange(userID, userName); } diff --git a/test/cases/setUsernamePrivate.ts b/test/cases/setUsernamePrivate.ts index c67e2a56..e15fb28a 100644 --- a/test/cases/setUsernamePrivate.ts +++ b/test/cases/setUsernamePrivate.ts @@ -17,10 +17,10 @@ const newUser_underLimit = "newUser_under"; const newUser_overLimit = `newUser_over${"*".repeat(USERID_LIMIT)}`; // new username to someone else'e privateID const otherUser = `otherUser${"*".repeat(USERID_LIMIT)}`; - +const isoDate = new Date().toISOString(); const addUsername = async (userID: string, userName: string, locked = 0) => - await db.prepare("run", 'INSERT INTO "userNames" ("userID", "userName", "locked") VALUES(?, ?, ?)', [userID, userName, locked]); + await db.prepare("run", 'INSERT INTO "userNames" ("userID", "userName", "locked", "createdAt", "updatedAt") VALUES(?, ?, ?, ?, ?)', [userID, userName, locked, isoDate, isoDate]); async function hasSetUsername(userID: string): Promise { const row = await db.prepare("get", 'SELECT "userName", "locked" FROM "userNames" WHERE "userID" = ?', [userID]); diff --git a/test/utils/queryGen.ts b/test/utils/queryGen.ts index 76d56ce5..a38f15fd 100644 --- a/test/utils/queryGen.ts +++ b/test/utils/queryGen.ts @@ -33,10 +33,10 @@ export const bulkGrantFeature = async (db: IDatabase, users: userArray, feature: }; // usernames -export const insertUsername = async (db: IDatabase, userID: HashedUserID, userName: string, locked = false) => { - const query = 'INSERT INTO "userNames" ("userID", "userName", "locked") VALUES(?, ?, ?)'; +export const insertUsername = async (db: IDatabase, userID: HashedUserID, userName: string, locked = false, isoDate: string = new Date().toISOString()) => { + const query = 'INSERT INTO "userNames" ("userID", "userName", "locked", "createdAt", "updatedAt") VALUES(?, ?, ?, ?, ?)'; const lockedValue = Number(locked); - await db.prepare("run", query, [userID, userName, lockedValue]); + await db.prepare("run", query, [userID, userName, lockedValue, isoDate, isoDate]); }; export const insertUsernameBulk = async (db: IDatabase, users: usernameUserArray) => { for (const user of Object.values(users)) From fae043f79c7bac15b6498b1b29f7fe201635f8ed Mon Sep 17 00:00:00 2001 From: Tristan Date: Mon, 16 Sep 2024 19:02:44 +0200 Subject: [PATCH 24/27] test(lockCategories): impl createdAt and updatedAt --- test/cases/getLockCategoriesByHash.ts | 18 +++++----- test/cases/getLockReason.ts | 14 ++++---- test/cases/lockCategoriesRecords.ts | 46 ++++++++++++------------- test/cases/postSkipSegmentsDuration.ts | 4 +-- test/cases/postSkipSegmentsLocked.ts | 7 ++-- test/cases/postSkipSegmentsUserAgent.ts | 7 ++-- test/cases/reputation.ts | 8 ++--- test/cases/shadowBanUser.ts | 4 +-- test/cases/unBan.ts | 4 +-- test/cases/voteOnSponsorTime.ts | 6 ++-- test/utils/queryGen.ts | 11 +++--- 11 files changed, 67 insertions(+), 62 deletions(-) diff --git a/test/cases/getLockCategoriesByHash.ts b/test/cases/getLockCategoriesByHash.ts index a034d4f3..a70aea9a 100644 --- a/test/cases/getLockCategoriesByHash.ts +++ b/test/cases/getLockCategoriesByHash.ts @@ -14,18 +14,18 @@ describe("getLockCategoriesByHash", () => { const insertVipUserQuery = 'INSERT INTO "vipUsers" ("userID", "createdAt") VALUES (?, ?)'; await db.prepare("run", insertVipUserQuery, [getHash("getLockCategoriesHashVIP"), isoDate]); - const insertLockCategoryQuery = 'INSERT INTO "lockCategories" ("userID", "videoID", "actionType", "category", "reason", "hashedVideoID") VALUES (?, ?, ?, ?, ?, ?)'; - await db.prepare("run", insertLockCategoryQuery, [getHash("getLockCategoriesHashVIP"), "getLockHash1", "skip", "sponsor", "1-reason-short", getHash("getLockHash1", 1)]); - await db.prepare("run", insertLockCategoryQuery, [getHash("getLockCategoriesHashVIP"), "getLockHash1", "skip", "interaction", "1-reason-longer", getHash("getLockHash1", 1)]); + const insertLockCategoryQuery = 'INSERT INTO "lockCategories" ("userID", "videoID", "actionType", "category", "reason", "hashedVideoID", "createdAt", "updatedAt") VALUES (?, ?, ?, ?, ?, ?, ?, ?)'; + await db.prepare("run", insertLockCategoryQuery, [getHash("getLockCategoriesHashVIP"), "getLockHash1", "skip", "sponsor", "1-reason-short", getHash("getLockHash1", 1), isoDate, isoDate]); + await db.prepare("run", insertLockCategoryQuery, [getHash("getLockCategoriesHashVIP"), "getLockHash1", "skip", "interaction", "1-reason-longer", getHash("getLockHash1", 1), isoDate, isoDate]); - await db.prepare("run", insertLockCategoryQuery, [getHash("getLockCategoriesHashVIP"), "getLockHash2", "skip", "preview", "2-reason", getHash("getLockHash2", 1)]); + await db.prepare("run", insertLockCategoryQuery, [getHash("getLockCategoriesHashVIP"), "getLockHash2", "skip", "preview", "2-reason", getHash("getLockHash2", 1), isoDate, isoDate]); - await db.prepare("run", insertLockCategoryQuery, [getHash("getLockCategoriesHashVIP"), "getLockHash3", "skip", "nonmusic", "3-reason", getHash("getLockHash3", 1)]); + await db.prepare("run", insertLockCategoryQuery, [getHash("getLockCategoriesHashVIP"), "getLockHash3", "skip", "nonmusic", "3-reason", getHash("getLockHash3", 1), isoDate, isoDate]); - await db.prepare("run", insertLockCategoryQuery, [getHash("getLockCategoriesHashVIP"), "fakehash-1", "mute", "outro", "fake1-reason", fakeHash]); - await db.prepare("run", insertLockCategoryQuery, [getHash("getLockCategoriesHashVIP"), "fakehash-2", "mute", "intro", "fake2-longer-reason", fakeHash]); - await db.prepare("run", insertLockCategoryQuery, [getHash("getLockCategoriesHashVIP"), "fakehash-2", "mute", "preview", "fake2-short", fakeHash]); - await db.prepare("run", insertLockCategoryQuery, [getHash("getLockCategoriesHashVIP"), "fakehash-2", "full", "sponsor", "fake2-notshown", fakeHash]); + await db.prepare("run", insertLockCategoryQuery, [getHash("getLockCategoriesHashVIP"), "fakehash-1", "mute", "outro", "fake1-reason", fakeHash, isoDate, isoDate]); + await db.prepare("run", insertLockCategoryQuery, [getHash("getLockCategoriesHashVIP"), "fakehash-2", "mute", "intro", "fake2-longer-reason", fakeHash, isoDate, isoDate]); + await db.prepare("run", insertLockCategoryQuery, [getHash("getLockCategoriesHashVIP"), "fakehash-2", "mute", "preview", "fake2-short", fakeHash, isoDate, isoDate]); + await db.prepare("run", insertLockCategoryQuery, [getHash("getLockCategoriesHashVIP"), "fakehash-2", "full", "sponsor", "fake2-notshown", fakeHash, isoDate, isoDate]); }); it("Database should be greater or equal to version 29", async () => { diff --git a/test/cases/getLockReason.ts b/test/cases/getLockReason.ts index 0b1ceaaa..0158be85 100644 --- a/test/cases/getLockReason.ts +++ b/test/cases/getLockReason.ts @@ -22,13 +22,13 @@ describe("getLockReason", () => { await db.prepare("run", insertVipUserNameQuery, [vipUserID1, vipUserName1, isoDate, isoDate]); await db.prepare("run", insertVipUserNameQuery, [vipUserID2, vipUserName2, isoDate, isoDate]); - const insertLockCategoryQuery = 'INSERT INTO "lockCategories" ("userID", "videoID", "actionType", "category", "reason") VALUES (?, ?, ?, ?, ?)'; - await db.prepare("run", insertLockCategoryQuery, [vipUserID1, "getLockReason", "skip", "sponsor", "sponsor-reason"]); - await db.prepare("run", insertLockCategoryQuery, [vipUserID1, "getLockReason", "skip", "interaction", "interaction-reason"]); - await db.prepare("run", insertLockCategoryQuery, [vipUserID1, "getLockReason", "skip", "preview", "preview-reason"]); - await db.prepare("run", insertLockCategoryQuery, [vipUserID1, "getLockReason", "mute", "music_offtopic", "nonmusic-reason"]); - await db.prepare("run", insertLockCategoryQuery, [vipUserID2, "getLockReason", "mute", "outro", "outro-reason"]); - await db.prepare("run", insertLockCategoryQuery, [vipUserID2, "getLockReason", "full", "selfpromo", "selfpromo-reason"]); + const insertLockCategoryQuery = 'INSERT INTO "lockCategories" ("userID", "videoID", "actionType", "category", "reason", "createdAt", "updatedAt") VALUES (?, ?, ?, ?, ?, ?, ?)'; + await db.prepare("run", insertLockCategoryQuery, [vipUserID1, "getLockReason", "skip", "sponsor", "sponsor-reason", isoDate, isoDate]); + await db.prepare("run", insertLockCategoryQuery, [vipUserID1, "getLockReason", "skip", "interaction", "interaction-reason", isoDate, isoDate]); + await db.prepare("run", insertLockCategoryQuery, [vipUserID1, "getLockReason", "skip", "preview", "preview-reason", isoDate, isoDate]); + await db.prepare("run", insertLockCategoryQuery, [vipUserID1, "getLockReason", "mute", "music_offtopic", "nonmusic-reason", isoDate, isoDate]); + await db.prepare("run", insertLockCategoryQuery, [vipUserID2, "getLockReason", "mute", "outro", "outro-reason", isoDate, isoDate]); + await db.prepare("run", insertLockCategoryQuery, [vipUserID2, "getLockReason", "full", "selfpromo", "selfpromo-reason", isoDate, isoDate]); }); after(async () => { diff --git a/test/cases/lockCategoriesRecords.ts b/test/cases/lockCategoriesRecords.ts index 8a98c251..15e8c372 100644 --- a/test/cases/lockCategoriesRecords.ts +++ b/test/cases/lockCategoriesRecords.ts @@ -33,29 +33,29 @@ describe("lockCategoriesRecords", () => { const insertVipUserQuery = 'INSERT INTO "vipUsers" ("userID", "createdAt") VALUES (?, ?)'; await db.prepare("run", insertVipUserQuery, [lockVIPUserHash, isoDate]); - const insertLockCategoryQuery = 'INSERT INTO "lockCategories" ("userID", "videoID", "actionType", "category", "reason", "service") VALUES (?, ?, ?, ?, ?, ?)'; - await db.prepare("run", insertLockCategoryQuery, [lockVIPUserHash, "no-segments-video-id", "skip", "sponsor", "reason-1", "YouTube"]); - await db.prepare("run", insertLockCategoryQuery, [lockVIPUserHash, "no-segments-video-id", "mute", "sponsor", "reason-1", "YouTube"]); - await db.prepare("run", insertLockCategoryQuery, [lockVIPUserHash, "no-segments-video-id", "skip", "intro", "reason-1", "YouTube"]); - await db.prepare("run", insertLockCategoryQuery, [lockVIPUserHash, "no-segments-video-id", "mute", "intro", "reason-1", "YouTube"]); - - await db.prepare("run", insertLockCategoryQuery, [lockVIPUserHash, "no-segments-video-id-1", "skip", "sponsor", "reason-2", "YouTube"]); - await db.prepare("run", insertLockCategoryQuery, [lockVIPUserHash, "no-segments-video-id-1", "mute", "sponsor", "reason-2", "YouTube"]); - await db.prepare("run", insertLockCategoryQuery, [lockVIPUserHash, "no-segments-video-id-1", "skip", "intro", "reason-2", "YouTube"]); - await db.prepare("run", insertLockCategoryQuery, [lockVIPUserHash, "no-segments-video-id-1", "mute", "intro", "reason-2", "YouTube"]); - await db.prepare("run", insertLockCategoryQuery, [lockVIPUserHash, "lockCategoryVideo", "skip", "sponsor", "reason-3", "YouTube"]); - await db.prepare("run", insertLockCategoryQuery, [lockVIPUserHash, "lockCategoryVideo", "mute", "sponsor", "reason-3", "YouTube"]); - - await db.prepare("run", insertLockCategoryQuery, [lockVIPUserHash, "lockCategoryVideo-2", "skip", "sponsor", "reason-4", "YouTube"]); - - await db.prepare("run", insertLockCategoryQuery, [lockVIPUserHash, "delete-record", "skip", "sponsor", "reason-4", "YouTube"]); - await db.prepare("run", insertLockCategoryQuery, [lockVIPUserHash, "delete-record", "mute", "sponsor", "reason-4", "YouTube"]); - await db.prepare("run", insertLockCategoryQuery, [lockVIPUserHash, "delete-record", "full", "sponsor", "reason-4", "YouTube"]); - await db.prepare("run", insertLockCategoryQuery, [lockVIPUserHash, "delete-record-1", "skip", "sponsor", "reason-5", "YouTube"]); - await db.prepare("run", insertLockCategoryQuery, [lockVIPUserHash, "delete-record-1", "mute", "sponsor", "reason-5", "YouTube"]); - await db.prepare("run", insertLockCategoryQuery, [lockVIPUserHash, "delete-record-1", "skip", "intro", "reason-5", "YouTube"]); - await db.prepare("run", insertLockCategoryQuery, [lockVIPUserHash, "delete-record-1", "mute", "intro", "reason-5", "YouTube"]); - await db.prepare("run", insertLockCategoryQuery, [lockVIPUserHash, "delete-record-poi", "poi", "poi_highlight", "reason-6", "YouTube"]); + const insertLockCategoryQuery = 'INSERT INTO "lockCategories" ("userID", "videoID", "actionType", "category", "reason", "service", "createdAt", "updatedAt") VALUES (?, ?, ?, ?, ?, ?, ?, ?)'; + await db.prepare("run", insertLockCategoryQuery, [lockVIPUserHash, "no-segments-video-id", "skip", "sponsor", "reason-1", "YouTube", isoDate, isoDate]); + await db.prepare("run", insertLockCategoryQuery, [lockVIPUserHash, "no-segments-video-id", "mute", "sponsor", "reason-1", "YouTube", isoDate, isoDate]); + await db.prepare("run", insertLockCategoryQuery, [lockVIPUserHash, "no-segments-video-id", "skip", "intro", "reason-1", "YouTube", isoDate, isoDate]); + await db.prepare("run", insertLockCategoryQuery, [lockVIPUserHash, "no-segments-video-id", "mute", "intro", "reason-1", "YouTube", isoDate, isoDate]); + + await db.prepare("run", insertLockCategoryQuery, [lockVIPUserHash, "no-segments-video-id-1", "skip", "sponsor", "reason-2", "YouTube", isoDate, isoDate]); + await db.prepare("run", insertLockCategoryQuery, [lockVIPUserHash, "no-segments-video-id-1", "mute", "sponsor", "reason-2", "YouTube", isoDate, isoDate]); + await db.prepare("run", insertLockCategoryQuery, [lockVIPUserHash, "no-segments-video-id-1", "skip", "intro", "reason-2", "YouTube", isoDate, isoDate]); + await db.prepare("run", insertLockCategoryQuery, [lockVIPUserHash, "no-segments-video-id-1", "mute", "intro", "reason-2", "YouTube", isoDate, isoDate]); + await db.prepare("run", insertLockCategoryQuery, [lockVIPUserHash, "lockCategoryVideo", "skip", "sponsor", "reason-3", "YouTube", isoDate, isoDate]); + await db.prepare("run", insertLockCategoryQuery, [lockVIPUserHash, "lockCategoryVideo", "mute", "sponsor", "reason-3", "YouTube", isoDate, isoDate]); + + await db.prepare("run", insertLockCategoryQuery, [lockVIPUserHash, "lockCategoryVideo-2", "skip", "sponsor", "reason-4", "YouTube", isoDate, isoDate]); + + await db.prepare("run", insertLockCategoryQuery, [lockVIPUserHash, "delete-record", "skip", "sponsor", "reason-4", "YouTube", isoDate, isoDate]); + await db.prepare("run", insertLockCategoryQuery, [lockVIPUserHash, "delete-record", "mute", "sponsor", "reason-4", "YouTube", isoDate, isoDate]); + await db.prepare("run", insertLockCategoryQuery, [lockVIPUserHash, "delete-record", "full", "sponsor", "reason-4", "YouTube", isoDate, isoDate]); + await db.prepare("run", insertLockCategoryQuery, [lockVIPUserHash, "delete-record-1", "skip", "sponsor", "reason-5", "YouTube", isoDate, isoDate]); + await db.prepare("run", insertLockCategoryQuery, [lockVIPUserHash, "delete-record-1", "mute", "sponsor", "reason-5", "YouTube", isoDate, isoDate]); + await db.prepare("run", insertLockCategoryQuery, [lockVIPUserHash, "delete-record-1", "skip", "intro", "reason-5", "YouTube", isoDate, isoDate]); + await db.prepare("run", insertLockCategoryQuery, [lockVIPUserHash, "delete-record-1", "mute", "intro", "reason-5", "YouTube", isoDate, isoDate]); + await db.prepare("run", insertLockCategoryQuery, [lockVIPUserHash, "delete-record-poi", "poi", "poi_highlight", "reason-6", "YouTube", isoDate, isoDate]); }); it("Should update the database version when starting the application", async () => { diff --git a/test/cases/postSkipSegmentsDuration.ts b/test/cases/postSkipSegmentsDuration.ts index 5491e49a..dc38f168 100644 --- a/test/cases/postSkipSegmentsDuration.ts +++ b/test/cases/postSkipSegmentsDuration.ts @@ -85,8 +85,8 @@ describe("postSkipSegments - duration", () => { segment: [1, 10], category: "sponsor", }; - await db.prepare("run", `INSERT INTO "lockCategories" ("userID", "videoID", "category") - VALUES(?, ?, ?)`, [getHash("generic-VIP"), videoID, "sponsor"]); + await db.prepare("run", `INSERT INTO "lockCategories" ("userID", "videoID", "category", "createdAt", "updatedAt") + VALUES(?, ?, ?, ?, ?)`, [getHash("generic-VIP"), videoID, "sponsor", isoDate, isoDate]); try { const res = await postSkipSegmentJSON({ userID, diff --git a/test/cases/postSkipSegmentsLocked.ts b/test/cases/postSkipSegmentsLocked.ts index 0fc0ab82..9c3f8deb 100644 --- a/test/cases/postSkipSegmentsLocked.ts +++ b/test/cases/postSkipSegmentsLocked.ts @@ -8,11 +8,12 @@ describe("postSkipSegments - LockedVideos", () => { const VIPLockUser = "VIPUser-lockCategories"; const videoID = "lockedVideo"; const userID = userIDOne; + const isoDate = new Date().toISOString(); before(() => { - const insertLockCategoriesQuery = `INSERT INTO "lockCategories" ("userID", "videoID", "category", "reason") VALUES(?, ?, ?, ?)`; - db.prepare("run", insertLockCategoriesQuery, [getHash(VIPLockUser), videoID, "sponsor", "Custom Reason"]); - db.prepare("run", insertLockCategoriesQuery, [getHash(VIPLockUser), videoID, "intro", ""]); + const insertLockCategoriesQuery = `INSERT INTO "lockCategories" ("userID", "videoID", "category", "reason", "createdAt", "updatedAt") VALUES(?, ?, ?, ?, ?, ?)`; + db.prepare("run", insertLockCategoriesQuery, [getHash(VIPLockUser), videoID, "sponsor", "Custom Reason", isoDate, isoDate]); + db.prepare("run", insertLockCategoriesQuery, [getHash(VIPLockUser), videoID, "intro", "", isoDate, isoDate]); }); it("Should return 403 and custom reason for submiting in lockedCategory", (done) => { diff --git a/test/cases/postSkipSegmentsUserAgent.ts b/test/cases/postSkipSegmentsUserAgent.ts index c5e68c9d..1e70b6e4 100644 --- a/test/cases/postSkipSegmentsUserAgent.ts +++ b/test/cases/postSkipSegmentsUserAgent.ts @@ -14,6 +14,7 @@ describe("postSkipSegments - userAgent", () => { const VIPLockUser = "VIPUser-lockCategories"; const videoID = "lockedVideo"; const userID = userIDOne; + const isoDate = new Date().toISOString(); const segment = { segment: [0, 10], @@ -22,9 +23,9 @@ describe("postSkipSegments - userAgent", () => { const dbFormatSegment = convertSingleToDBFormat(segment); before(() => { - const insertLockCategoriesQuery = `INSERT INTO "lockCategories" ("userID", "videoID", "category", "reason") VALUES(?, ?, ?, ?)`; - db.prepare("run", insertLockCategoriesQuery, [getHash(VIPLockUser), videoID, "sponsor", "Custom Reason"]); - db.prepare("run", insertLockCategoriesQuery, [getHash(VIPLockUser), videoID, "intro", ""]); + const insertLockCategoriesQuery = `INSERT INTO "lockCategories" ("userID", "videoID", "category", "reason", "createdAt", "updatedAt") VALUES(?, ?, ?, ?, ?, ?)`; + db.prepare("run", insertLockCategoriesQuery, [getHash(VIPLockUser), videoID, "sponsor", "Custom Reason", isoDate, isoDate]); + db.prepare("run", insertLockCategoriesQuery, [getHash(VIPLockUser), videoID, "intro", "", isoDate, isoDate]); }); it("Should be able to submit with empty user-agent", (done) => { diff --git a/test/cases/reputation.ts b/test/cases/reputation.ts index 1d46da60..ee98dfdc 100644 --- a/test/cases/reputation.ts +++ b/test/cases/reputation.ts @@ -126,10 +126,10 @@ describe("reputation", () => { const insertVipUserQuery = 'INSERT INTO "vipUsers" ("userID", "createdAt") VALUES (?, ?)'; await db.prepare("run", insertVipUserQuery, [users["locking-vip"].pubID, isoDate]); - const insertLockCategoryQuery = 'INSERT INTO "lockCategories" ("userID", "videoID", "category") VALUES (?, ?, ?)'; - await db.prepare("run", insertLockCategoryQuery, [users["locking-vip"].pubID, videoID, "sponsor"]); - await db.prepare("run", insertLockCategoryQuery, [users["locking-vip"].pubID, videoID, "intro"]); - await db.prepare("run", insertLockCategoryQuery, [users["locking-vip"].pubID, videoID2, "sponsor"]); + const insertLockCategoryQuery = 'INSERT INTO "lockCategories" ("userID", "videoID", "category", "createdAt", "updatedAt") VALUES (?, ?, ?, ?, ?)'; + await db.prepare("run", insertLockCategoryQuery, [users["locking-vip"].pubID, videoID, "sponsor", isoDate, isoDate]); + await db.prepare("run", insertLockCategoryQuery, [users["locking-vip"].pubID, videoID, "intro", isoDate, isoDate]); + await db.prepare("run", insertLockCategoryQuery, [users["locking-vip"].pubID, videoID2, "sponsor", isoDate, isoDate]); }); it("user in grace period", async () => { diff --git a/test/cases/shadowBanUser.ts b/test/cases/shadowBanUser.ts index 10189841..90dfa8bc 100644 --- a/test/cases/shadowBanUser.ts +++ b/test/cases/shadowBanUser.ts @@ -52,8 +52,8 @@ describe("shadowBanUser", () => { await db.prepare("run", `INSERT INTO "shadowBannedUsers" ("userID") VALUES(?)`, ["shadowBanned3"]); await db.prepare("run", `INSERT INTO "shadowBannedUsers" ("userID") VALUES(?)`, ["shadowBanned4"]); - await db.prepare("run", `INSERT INTO "lockCategories" ("userID", "videoID", "actionType", "category", "service") VALUES (?, ?, ?, ?, ?)`, - [getHash("shadow-ban-vip", 1), "lockedVideo", "skip", "sponsor", "YouTube"]); + await db.prepare("run", `INSERT INTO "lockCategories" ("userID", "videoID", "actionType", "category", "service", "createdAt", "updatedAt") VALUES (?, ?, ?, ?, ?, ?, ?)`, + [getHash("shadow-ban-vip", 1), "lockedVideo", "skip", "sponsor", "YouTube", isoDate, isoDate]); await db.prepare("run", `INSERT INTO "vipUsers" ("userID", "createdAt") VALUES(?, ?)`, [getHash(VIPuserID), isoDate]); diff --git a/test/cases/unBan.ts b/test/cases/unBan.ts index 1a2a2a04..82d4fbab 100644 --- a/test/cases/unBan.ts +++ b/test/cases/unBan.ts @@ -26,8 +26,8 @@ describe("unBan", () => { const insertVipUserQuery = 'INSERT INTO "vipUsers" ("userID", "createdAt") VALUES (?, ?)'; await db.prepare("run", insertVipUserQuery, [getHash(VIPuser), isoDate]); - const insertLockCategoryQuery = 'INSERT INTO "lockCategories" ("userID", "videoID", "category") VALUES(?, ?, ?)'; - await db.prepare("run", insertLockCategoryQuery, [getHash(VIPuser), "unBan-videoID-1", "sponsor"]); + const insertLockCategoryQuery = 'INSERT INTO "lockCategories" ("userID", "videoID", "category", "createdAt", "updatedAt") VALUES(?, ?, ?, ?, ?)'; + await db.prepare("run", insertLockCategoryQuery, [getHash(VIPuser), "unBan-videoID-1", "sponsor", isoDate, isoDate]); const insertSponsorTimeQuery = 'INSERT INTO "sponsorTimes" ("videoID", "startTime", "endTime", "votes", "UUID", "userID", "timeSubmitted", views, category, "shadowHidden", "hashedVideoID", "updatedAt") VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)'; await db.prepare("run", insertSponsorTimeQuery, ["unBan-videoID-0", 1, 11, 2, "unBan-uuid-0", "testMan-unBan", 0, 50, "sponsor", 1, getHash("unBan-videoID-0", 1), isoDate]); diff --git a/test/cases/voteOnSponsorTime.ts b/test/cases/voteOnSponsorTime.ts index a512cf41..194f810d 100644 --- a/test/cases/voteOnSponsorTime.ts +++ b/test/cases/voteOnSponsorTime.ts @@ -103,9 +103,9 @@ describe("voteOnSponsorTime", () => { await db.prepare("run", 'INSERT INTO "vipUsers" ("userID", "createdAt") VALUES (?, ?)', [getHash(vipUser), isoDate]); await db.prepare("run", 'INSERT INTO "shadowBannedUsers" ("userID") VALUES (?)', [getHash("randomID4")]); - const insertlockCategoriesQuery = 'INSERT INTO "lockCategories" ("videoID", "userID", "category", "actionType") VALUES (?, ?, ?, ?)'; - await db.prepare("run", insertlockCategoriesQuery, ["no-sponsor-segments-video", "someUser", "sponsor", "skip"]); - await db.prepare("run", insertlockCategoriesQuery, ["category-change-test-1", "someUser", "preview", "skip"]); // sponsor should stay unlocked + const insertlockCategoriesQuery = 'INSERT INTO "lockCategories" ("videoID", "userID", "category", "actionType", "createdAt", "updatedAt") VALUES (?, ?, ?, ?, ?, ?)'; + await db.prepare("run", insertlockCategoriesQuery, ["no-sponsor-segments-video", "someUser", "sponsor", "skip", isoDate, isoDate]); + await db.prepare("run", insertlockCategoriesQuery, ["category-change-test-1", "someUser", "preview", "skip", isoDate, isoDate]); // sponsor should stay unlocked }); // constants const endpoint = "/api/voteOnSponsorTime"; diff --git a/test/utils/queryGen.ts b/test/utils/queryGen.ts index a38f15fd..6db3e510 100644 --- a/test/utils/queryGen.ts +++ b/test/utils/queryGen.ts @@ -56,15 +56,18 @@ interface lockParams { category?: Category | string, hashedVideoID?: VideoIDHash | "", reason?: string, - service?: Service | string + service?: Service | string, + createdAt?: string, + updatedAt?: string } -export const insertLock = async(db: IDatabase, overrides: lockParams = {}) => { - const query = 'INSERT INTO "lockCategories" ("videoID", "userID", "actionType", "category", "hashedVideoID", "reason", "service") VALUES (?, ?, ?, ?, ?, ?, ?)'; +export const insertLock = async(db: IDatabase, overrides: lockParams = {}, isoDate: string = new Date().toISOString()) => { + const query = 'INSERT INTO "lockCategories" ("videoID", "userID", "actionType", "category", "hashedVideoID", "reason", "service", "createdAt", "updatedAt") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)'; const identifier = "lock"; const defaults = { videoID: genRandomValue("video", identifier), userID: genRandomValue("user", identifier), - actionType: "skip", category: "sponsor", hashedVideoID: "", reason: "", service: Service.YouTube + actionType: "skip", category: "sponsor", hashedVideoID: "", reason: "", service: Service.YouTube, + createdAt: isoDate, updatedAt: isoDate }; const params = { ...defaults, ...overrides }; params.hashedVideoID = getHash(params.videoID); From 32fd897203055f3a6dc3693d29da290e5d7a113b Mon Sep 17 00:00:00 2001 From: Tristan Date: Mon, 16 Sep 2024 19:11:01 +0200 Subject: [PATCH 25/27] test(titleVotes): impl createdAt and updatedAt --- test/cases/getBranding.ts | 28 ++++++++++++++-------------- test/cases/postBranding.ts | 18 +++++++++--------- test/cases/shadowBanUser.ts | 14 +++++++------- test/utils/segmentQueryGen.ts | 6 +++--- 4 files changed, 33 insertions(+), 33 deletions(-) diff --git a/test/cases/getBranding.ts b/test/cases/getBranding.ts index 855c1377..403f7359 100644 --- a/test/cases/getBranding.ts +++ b/test/cases/getBranding.ts @@ -39,7 +39,7 @@ describe("getBranding", () => { before(async () => { const titleQuery = `INSERT INTO "titles" ("videoID", "title", "original", "userID", "service", "hashedVideoID", "timeSubmitted", "UUID") VALUES (?, ?, ?, ?, ?, ?, ?, ?)`; - const titleVotesQuery = `INSERT INTO "titleVotes" ("UUID", "votes", "locked", "shadowHidden", "verification", "downvotes", "removed") VALUES (?, ?, ?, ?, ?, ?, ?)`; + const titleVotesQuery = `INSERT INTO "titleVotes" ("UUID", "votes", "locked", "shadowHidden", "verification", "downvotes", "removed", "createdAt", "updatedAt") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)`; const thumbnailQuery = `INSERT INTO "thumbnails" ("videoID", "original", "userID", "service", "hashedVideoID", "timeSubmitted", "UUID") VALUES (?, ?, ?, ?, ?, ?, ?)`; const thumbnailTimestampsQuery = `INSERT INTO "thumbnailTimestamps" ("UUID", "timestamp") VALUES (?, ?)`; const thumbnailVotesQuery = `INSERT INTO "thumbnailVotes" ("UUID", "votes", "locked", "shadowHidden", "downvotes", "removed") VALUES (?, ?, ?, ?, ?, ?)`; @@ -57,10 +57,10 @@ describe("getBranding", () => { ]); await Promise.all([ - db.prepare("run", titleVotesQuery, ["UUID1", 3, 0, 0, 0, 0, 0]), - db.prepare("run", titleVotesQuery, ["UUID2", 3, 0, 0, 0, 1, 0]), - db.prepare("run", titleVotesQuery, ["UUID3", 0, 0, 0, 0, 0, 0]), - db.prepare("run", titleVotesQuery, ["UUID4", 5, 0, 0, 0, 0, 1]), + db.prepare("run", titleVotesQuery, ["UUID1", 3, 0, 0, 0, 0, 0, isoDate, isoDate]), + db.prepare("run", titleVotesQuery, ["UUID2", 3, 0, 0, 0, 1, 0, isoDate, isoDate]), + db.prepare("run", titleVotesQuery, ["UUID3", 0, 0, 0, 0, 0, 0, isoDate, isoDate]), + db.prepare("run", titleVotesQuery, ["UUID4", 5, 0, 0, 0, 0, 1, isoDate, isoDate]), db.prepare("run", thumbnailTimestampsQuery, ["UUID1T", 1]), db.prepare("run", thumbnailTimestampsQuery, ["UUID3T", 3]), db.prepare("run", thumbnailTimestampsQuery, ["UUID4T", 18]), @@ -80,9 +80,9 @@ describe("getBranding", () => { ]); await Promise.all([ - db.prepare("run", titleVotesQuery, ["UUID11", 3, 0, 0, 0, 0, 0]), - db.prepare("run", titleVotesQuery, ["UUID21", 2, 0, 0, 0, 0, 0]), - db.prepare("run", titleVotesQuery, ["UUID31", 1, 1, 0, 0, 0, 0]), + db.prepare("run", titleVotesQuery, ["UUID11", 3, 0, 0, 0, 0, 0, isoDate, isoDate]), + db.prepare("run", titleVotesQuery, ["UUID21", 2, 0, 0, 0, 0, 0, isoDate, isoDate]), + db.prepare("run", titleVotesQuery, ["UUID31", 1, 1, 0, 0, 0, 0, isoDate, isoDate]), db.prepare("run", thumbnailTimestampsQuery, ["UUID11T", 1]), db.prepare("run", thumbnailTimestampsQuery, ["UUID31T", 3]), @@ -101,9 +101,9 @@ describe("getBranding", () => { ]); await Promise.all([ - db.prepare("run", titleVotesQuery, ["UUID12", 3, 0, 0, 0, 0, 0]), - db.prepare("run", titleVotesQuery, ["UUID22", 2, 0, 0, 0, 0, 0]), - db.prepare("run", titleVotesQuery, ["UUID32", 1, 0, 1, 0, 0, 0]), + db.prepare("run", titleVotesQuery, ["UUID12", 3, 0, 0, 0, 0, 0, isoDate, isoDate]), + db.prepare("run", titleVotesQuery, ["UUID22", 2, 0, 0, 0, 0, 0, isoDate, isoDate]), + db.prepare("run", titleVotesQuery, ["UUID32", 1, 0, 1, 0, 0, 0, isoDate, isoDate]), db.prepare("run", thumbnailTimestampsQuery, ["UUID12T", 1]), db.prepare("run", thumbnailTimestampsQuery, ["UUID32T", 3]), db.prepare("run", thumbnailVotesQuery, ["UUID12T", 3, 0, 0, 0, 0]), @@ -124,9 +124,9 @@ describe("getBranding", () => { ]); await Promise.all([ - db.prepare("run", titleVotesQuery, ["UUID-uv-1", 3, 0, 0, -1, 0, 0]), - db.prepare("run", titleVotesQuery, ["UUID-uv-2", 2, 0, 0, -1, 0, 0]), - db.prepare("run", titleVotesQuery, ["UUID-uv-3", 0, 0, 0, -1, 0, 0]), + db.prepare("run", titleVotesQuery, ["UUID-uv-1", 3, 0, 0, -1, 0, 0, isoDate, isoDate]), + db.prepare("run", titleVotesQuery, ["UUID-uv-2", 2, 0, 0, -1, 0, 0, isoDate, isoDate]), + db.prepare("run", titleVotesQuery, ["UUID-uv-3", 0, 0, 0, -1, 0, 0, isoDate, isoDate]), db.prepare("run", thumbnailTimestampsQuery, ["UUID-uv-1T", 1]), db.prepare("run", thumbnailTimestampsQuery, ["UUID-uv-3T", 3]), db.prepare("run", thumbnailVotesQuery, ["UUID-uv-1T", 3, 0, 0, 0, 0]), diff --git a/test/cases/postBranding.ts b/test/cases/postBranding.ts index eb2612ee..4a882452 100644 --- a/test/cases/postBranding.ts +++ b/test/cases/postBranding.ts @@ -43,9 +43,9 @@ describe("postBranding", () => { const insertTitleQuery = 'INSERT INTO "titles" ("videoID", "title", "original", "userID", "service", "hashedVideoID", "timeSubmitted", "UUID") VALUES (?, ?, ?, ?, ?, ?, ?, ?)'; await db.prepare("run", insertTitleQuery, ["postBrandLocked1", "Some title", 0, getHash(userID1), Service.YouTube, getHash("postBrandLocked1"), Date.now(), "postBrandLocked1"]); await db.prepare("run", insertTitleQuery, ["postBrandLocked2", "Some title", 1, getHash(userID2), Service.YouTube, getHash("postBrandLocked2"), Date.now(), "postBrandLocked2"]); - const insertTitleVotesQuery = 'INSERT INTO "titleVotes" ("UUID", "votes", "locked", "shadowHidden", "verification") VALUES (?, ?, ?, ?, ?);'; - await db.prepare("run", insertTitleVotesQuery, ["postBrandLocked1", 0, 1, 0, 0]); - await db.prepare("run", insertTitleVotesQuery, ["postBrandLocked2", 0, 1, 0, 0]); + const insertTitleVotesQuery = 'INSERT INTO "titleVotes" ("UUID", "votes", "locked", "shadowHidden", "verification", "createdAt", "updatedAt") VALUES (?, ?, ?, ?, ?, ?, ?);'; + await db.prepare("run", insertTitleVotesQuery, ["postBrandLocked1", 0, 1, 0, 0, isoDate, isoDate]); + await db.prepare("run", insertTitleVotesQuery, ["postBrandLocked2", 0, 1, 0, 0, isoDate, isoDate]); const insertThumbnailQuery = 'INSERT INTO "thumbnails" ("videoID", "original", "userID", "service", "hashedVideoID", "timeSubmitted", "UUID") VALUES (?, ?, ?, ?, ?, ?, ?)'; await db.prepare("run", insertThumbnailQuery, ["postBrandLocked1", 0, getHash(userID3), Service.YouTube, getHash("postBrandLocked1"), Date.now(), "postBrandLocked1"]); @@ -69,9 +69,9 @@ describe("postBranding", () => { // Testing vip submission removal await db.prepare("run", insertTitleQuery, ["postBrandRemoved1", "Some title", 0, getHash(userID1), Service.YouTube, getHash("postBrandRemoved1"), Date.now(), "postBrandRemoved1"]); - await db.prepare("run", insertTitleVotesQuery, ["postBrandRemoved1", 0, 1, 0, 0]); + await db.prepare("run", insertTitleVotesQuery, ["postBrandRemoved1", 0, 1, 0, 0, isoDate, isoDate]); await db.prepare("run", insertTitleQuery, ["postBrandRemoved1", "Some other title", 0, getHash(userID1), Service.YouTube, getHash("postBrandRemoved1"), Date.now(), "postBrandRemoved2"]); - await db.prepare("run", insertTitleVotesQuery, ["postBrandRemoved2", 0, 1, 0, 0]); + await db.prepare("run", insertTitleVotesQuery, ["postBrandRemoved2", 0, 1, 0, 0, isoDate, isoDate]); // Testing vip submission removal const insertThumbnailTimestampQuery = 'INSERT INTO "thumbnailTimestamps" ("UUID", "timestamp") VALUES (?, ?)'; @@ -85,14 +85,14 @@ describe("postBranding", () => { // Verified through title submissions await db.prepare("run", insertTitleQuery, ["postBrandVerified1", "Some title", 0, getHash(userID7), Service.YouTube, getHash("postBrandVerified1"), Date.now(), "postBrandVerified1"]); await db.prepare("run", insertTitleQuery, ["postBrandVerified2", "Some title", 1, getHash(userID7), Service.YouTube, getHash("postBrandVerified2"), Date.now(), "postBrandVerified2"]); - await db.prepare("run", insertTitleVotesQuery, ["postBrandVerified1", 5, 0, 0, -1]); - await db.prepare("run", insertTitleVotesQuery, ["postBrandVerified2", -1, 0, 0, -1]); + await db.prepare("run", insertTitleVotesQuery, ["postBrandVerified1", 5, 0, 0, -1, isoDate, isoDate]); + await db.prepare("run", insertTitleVotesQuery, ["postBrandVerified2", -1, 0, 0, -1, isoDate, isoDate]); // Testing details for banned user handling await db.prepare("run", insertTitleQuery, ["postBrandBannedCustomVote", "Some title", 0, getHash(userID1), Service.YouTube, getHash("postBrandBannedCustomVote"), Date.now(), "postBrandBannedCustomVote"]); await db.prepare("run", insertTitleQuery, ["postBrandBannedOriginalVote", "Some title", 1, getHash(userID1), Service.YouTube, getHash("postBrandBannedOriginalVote"), Date.now(), "postBrandBannedOriginalVote"]); - await db.prepare("run", insertTitleVotesQuery, ["postBrandBannedCustomVote", 0, 0, 0, 0]); - await db.prepare("run", insertTitleVotesQuery, ["postBrandBannedOriginalVote", 0, 0, 0, 0]); + await db.prepare("run", insertTitleVotesQuery, ["postBrandBannedCustomVote", 0, 0, 0, 0, isoDate, isoDate]); + await db.prepare("run", insertTitleVotesQuery, ["postBrandBannedOriginalVote", 0, 0, 0, 0, isoDate, isoDate]); await db.prepare("run", insertThumbnailQuery, ["postBrandBannedCustomVote", 0, getHash(userID1), Service.YouTube, getHash("postBrandBannedCustomVote"), Date.now(), "postBrandBannedCustomVote"]); await db.prepare("run", insertThumbnailQuery, ["postBrandBannedOriginalVote", 1, getHash(userID1), Service.YouTube, getHash("postBrandBannedOriginalVote"), Date.now(), "postBrandBannedOriginalVote"]); await db.prepare("run", insertThumbnailVotesQuery, ["postBrandBannedCustomVote", 0, 0, 0]); diff --git a/test/cases/shadowBanUser.ts b/test/cases/shadowBanUser.ts index 90dfa8bc..c666b38c 100644 --- a/test/cases/shadowBanUser.ts +++ b/test/cases/shadowBanUser.ts @@ -58,7 +58,7 @@ describe("shadowBanUser", () => { await db.prepare("run", `INSERT INTO "vipUsers" ("userID", "createdAt") VALUES(?, ?)`, [getHash(VIPuserID), isoDate]); const titleQuery = `INSERT INTO "titles" ("videoID", "title", "original", "userID", "service", "hashedVideoID", "timeSubmitted", "UUID") VALUES (?, ?, ?, ?, ?, ?, ?, ?)`; - const titleVotesQuery = `INSERT INTO "titleVotes" ("UUID", "votes", "locked", "shadowHidden", "verification") VALUES (?, ?, ?, ?, ?)`; + const titleVotesQuery = `INSERT INTO "titleVotes" ("UUID", "votes", "locked", "shadowHidden", "verification", "createdAt", "updatedAt") VALUES (?, ?, ?, ?, ?, ?, ?)`; const thumbnailQuery = `INSERT INTO "thumbnails" ("videoID", "original", "userID", "service", "hashedVideoID", "timeSubmitted", "UUID") VALUES (?, ?, ?, ?, ?, ?, ?)`; const thumbnailTimestampsQuery = `INSERT INTO "thumbnailTimestamps" ("UUID", "timestamp") VALUES (?, ?)`; const thumbnailVotesQuery = `INSERT INTO "thumbnailVotes" ("UUID", "votes", "locked", "shadowHidden") VALUES (?, ?, ?, ?)`; @@ -73,9 +73,9 @@ describe("shadowBanUser", () => { ]); await Promise.all([ - db.prepare("run", titleVotesQuery, ["UUID1-ban", 3, 0, 0, 0]), - db.prepare("run", titleVotesQuery, ["UUID2-ban", 2, 0, 0, 0]), - db.prepare("run", titleVotesQuery, ["UUID3-ban", 1, 0, 0, 0]), + db.prepare("run", titleVotesQuery, ["UUID1-ban", 3, 0, 0, 0, isoDate, isoDate]), + db.prepare("run", titleVotesQuery, ["UUID2-ban", 2, 0, 0, 0, isoDate, isoDate]), + db.prepare("run", titleVotesQuery, ["UUID3-ban", 1, 0, 0, 0, isoDate, isoDate]), db.prepare("run", thumbnailTimestampsQuery, ["UUID1T-ban", 1]), db.prepare("run", thumbnailTimestampsQuery, ["UUID3T-ban", 3]), db.prepare("run", thumbnailVotesQuery, ["UUID1T-ban", 3, 0, 0]), @@ -93,9 +93,9 @@ describe("shadowBanUser", () => { ]); await Promise.all([ - db.prepare("run", titleVotesQuery, ["UUID1-ban2", 3, 0, 0, 0]), - db.prepare("run", titleVotesQuery, ["UUID2-ban2", 2, 0, 0, 0]), - db.prepare("run", titleVotesQuery, ["UUID3-ban2", 1, 0, 0, 0]), + db.prepare("run", titleVotesQuery, ["UUID1-ban2", 3, 0, 0, 0, isoDate, isoDate]), + db.prepare("run", titleVotesQuery, ["UUID2-ban2", 2, 0, 0, 0, isoDate, isoDate]), + db.prepare("run", titleVotesQuery, ["UUID3-ban2", 1, 0, 0, 0, isoDate, isoDate]), db.prepare("run", thumbnailTimestampsQuery, ["UUID1T-ban2", 1]), db.prepare("run", thumbnailTimestampsQuery, ["UUID3T-ban2", 3]), db.prepare("run", thumbnailVotesQuery, ["UUID1T-ban2", 3, 0, 0]), diff --git a/test/utils/segmentQueryGen.ts b/test/utils/segmentQueryGen.ts index 3c6a281c..6b542463 100644 --- a/test/utils/segmentQueryGen.ts +++ b/test/utils/segmentQueryGen.ts @@ -99,9 +99,9 @@ export const insertTitle = async (db: IDatabase, overrides: insertTitleParams = params.original = Number(params.original); await db.prepare("run", query, Object.values(params)); }; -export const insertTitleVote = async (db: IDatabase, UUID: string, votes: number, locked = false, shadowHidden = false, verification = false) => { - const query = 'INSERT INTO "titleVotes" ("UUID", "votes", "locked", "shadowHidden", "verification") VALUES (?, ?, ?, ?, ?)'; - const params = [UUID, votes, Number(locked), Number(shadowHidden), Number(verification)]; +export const insertTitleVote = async (db: IDatabase, UUID: string, votes: number, locked = false, shadowHidden = false, verification = false, isoDate: string = new Date().toISOString()) => { + const query = 'INSERT INTO "titleVotes" ("UUID", "votes", "locked", "shadowHidden", "verification", "createdAt", "updatedAt") VALUES (?, ?, ?, ?, ?, ?, ?)'; + const params = [UUID, votes, Number(locked), Number(shadowHidden), Number(verification), isoDate, isoDate]; await db.prepare("run", query, params); }; From 829fd5dc18d5f4a2b7a5b94ac0e5f88c8cf219bb Mon Sep 17 00:00:00 2001 From: Tristan Date: Mon, 16 Sep 2024 19:12:50 +0200 Subject: [PATCH 26/27] test(thumbnailVotes): impl createdAt and updatedAt --- test/cases/getBranding.ts | 28 ++++++++++++++-------------- test/cases/postBranding.ts | 24 ++++++++++++------------ test/cases/shadowBanUser.ts | 14 +++++++------- test/utils/segmentQueryGen.ts | 6 +++--- 4 files changed, 36 insertions(+), 36 deletions(-) diff --git a/test/cases/getBranding.ts b/test/cases/getBranding.ts index 403f7359..f8f18ea7 100644 --- a/test/cases/getBranding.ts +++ b/test/cases/getBranding.ts @@ -42,7 +42,7 @@ describe("getBranding", () => { const titleVotesQuery = `INSERT INTO "titleVotes" ("UUID", "votes", "locked", "shadowHidden", "verification", "downvotes", "removed", "createdAt", "updatedAt") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)`; const thumbnailQuery = `INSERT INTO "thumbnails" ("videoID", "original", "userID", "service", "hashedVideoID", "timeSubmitted", "UUID") VALUES (?, ?, ?, ?, ?, ?, ?)`; const thumbnailTimestampsQuery = `INSERT INTO "thumbnailTimestamps" ("UUID", "timestamp") VALUES (?, ?)`; - const thumbnailVotesQuery = `INSERT INTO "thumbnailVotes" ("UUID", "votes", "locked", "shadowHidden", "downvotes", "removed") VALUES (?, ?, ?, ?, ?, ?)`; + const thumbnailVotesQuery = `INSERT INTO "thumbnailVotes" ("UUID", "votes", "locked", "shadowHidden", "downvotes", "removed", "createdAt", "updatedAt") VALUES (?, ?, ?, ?, ?, ?, ?, ?)`; const segmentQuery = 'INSERT INTO "sponsorTimes" ("videoID", "startTime", "endTime", "votes", "locked", "UUID", "userID", "timeSubmitted", "views", "category", "actionType", "service", "videoDuration", "hidden", "shadowHidden", "description", "hashedVideoID", "updatedAt") VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)'; await Promise.all([ @@ -64,10 +64,10 @@ describe("getBranding", () => { db.prepare("run", thumbnailTimestampsQuery, ["UUID1T", 1]), db.prepare("run", thumbnailTimestampsQuery, ["UUID3T", 3]), db.prepare("run", thumbnailTimestampsQuery, ["UUID4T", 18]), - db.prepare("run", thumbnailVotesQuery, ["UUID1T", 3, 0, 0, 0, 0]), - db.prepare("run", thumbnailVotesQuery, ["UUID2T", 3, 0, 0, 1, 0]), - db.prepare("run", thumbnailVotesQuery, ["UUID3T", 1, 0, 0, 0, 0]), - db.prepare("run", thumbnailVotesQuery, ["UUID4T", 5, 0, 0, 0, 1]) + db.prepare("run", thumbnailVotesQuery, ["UUID1T", 3, 0, 0, 0, 0, isoDate, isoDate]), + db.prepare("run", thumbnailVotesQuery, ["UUID2T", 3, 0, 0, 1, 0, isoDate, isoDate]), + db.prepare("run", thumbnailVotesQuery, ["UUID3T", 1, 0, 0, 0, 0, isoDate, isoDate]), + db.prepare("run", thumbnailVotesQuery, ["UUID4T", 5, 0, 0, 0, 1, isoDate, isoDate]) ]); await Promise.all([ @@ -86,9 +86,9 @@ describe("getBranding", () => { db.prepare("run", thumbnailTimestampsQuery, ["UUID11T", 1]), db.prepare("run", thumbnailTimestampsQuery, ["UUID31T", 3]), - db.prepare("run", thumbnailVotesQuery, ["UUID11T", 3, 0, 0, 0, 0]), - db.prepare("run", thumbnailVotesQuery, ["UUID21T", 2, 0, 0, 0, 0]), - db.prepare("run", thumbnailVotesQuery, ["UUID31T", 1, 1, 0, 0, 0]), + db.prepare("run", thumbnailVotesQuery, ["UUID11T", 3, 0, 0, 0, 0, isoDate, isoDate]), + db.prepare("run", thumbnailVotesQuery, ["UUID21T", 2, 0, 0, 0, 0, isoDate, isoDate]), + db.prepare("run", thumbnailVotesQuery, ["UUID31T", 1, 1, 0, 0, 0, isoDate, isoDate]), ]); await Promise.all([ @@ -106,9 +106,9 @@ describe("getBranding", () => { db.prepare("run", titleVotesQuery, ["UUID32", 1, 0, 1, 0, 0, 0, isoDate, isoDate]), db.prepare("run", thumbnailTimestampsQuery, ["UUID12T", 1]), db.prepare("run", thumbnailTimestampsQuery, ["UUID32T", 3]), - db.prepare("run", thumbnailVotesQuery, ["UUID12T", 3, 0, 0, 0, 0]), - db.prepare("run", thumbnailVotesQuery, ["UUID22T", 2, 0, 0, 0, 0]), - db.prepare("run", thumbnailVotesQuery, ["UUID32T", 1, 0, 1, 0, 0]) + db.prepare("run", thumbnailVotesQuery, ["UUID12T", 3, 0, 0, 0, 0, isoDate, isoDate]), + db.prepare("run", thumbnailVotesQuery, ["UUID22T", 2, 0, 0, 0, 0, isoDate, isoDate]), + db.prepare("run", thumbnailVotesQuery, ["UUID32T", 1, 0, 1, 0, 0, isoDate, isoDate]) ]); await db.prepare("run", segmentQuery, [videoIDRandomTime, 1, 11, 1, 0, "uuidbranding1", "testman", 0, 50, "sponsor", "skip", "YouTube", 100, 0, 0, "", videoIDRandomTimeHash, isoDate]); @@ -129,9 +129,9 @@ describe("getBranding", () => { db.prepare("run", titleVotesQuery, ["UUID-uv-3", 0, 0, 0, -1, 0, 0, isoDate, isoDate]), db.prepare("run", thumbnailTimestampsQuery, ["UUID-uv-1T", 1]), db.prepare("run", thumbnailTimestampsQuery, ["UUID-uv-3T", 3]), - db.prepare("run", thumbnailVotesQuery, ["UUID-uv-1T", 3, 0, 0, 0, 0]), - db.prepare("run", thumbnailVotesQuery, ["UUID-uv-2T", 2, 0, 0, 0, 0]), - db.prepare("run", thumbnailVotesQuery, ["UUID-uv-3T", 1, 0, 0, 0, 0]) + db.prepare("run", thumbnailVotesQuery, ["UUID-uv-1T", 3, 0, 0, 0, 0, isoDate, isoDate]), + db.prepare("run", thumbnailVotesQuery, ["UUID-uv-2T", 2, 0, 0, 0, 0, isoDate, isoDate]), + db.prepare("run", thumbnailVotesQuery, ["UUID-uv-3T", 1, 0, 0, 0, 0, isoDate, isoDate]) ]); // Video duration test segments diff --git a/test/cases/postBranding.ts b/test/cases/postBranding.ts index 4a882452..7f9f78c6 100644 --- a/test/cases/postBranding.ts +++ b/test/cases/postBranding.ts @@ -51,9 +51,9 @@ describe("postBranding", () => { await db.prepare("run", insertThumbnailQuery, ["postBrandLocked1", 0, getHash(userID3), Service.YouTube, getHash("postBrandLocked1"), Date.now(), "postBrandLocked1"]); await db.prepare("run", insertThumbnailQuery, ["postBrandLocked2", 1, getHash(userID4), Service.YouTube, getHash("postBrandLocked2"), Date.now(), "postBrandLocked2"]); - const insertThumbnailVotesQuery = 'INSERT INTO "thumbnailVotes" ("UUID", "votes", "locked", "shadowHidden") VALUES (?, ?, ?, ?);'; - await db.prepare("run", insertThumbnailVotesQuery, ["postBrandLocked1", 0, 1, 0]); - await db.prepare("run", insertThumbnailVotesQuery, ["postBrandLocked2", 0, 1, 0]); + const insertThumbnailVotesQuery = 'INSERT INTO "thumbnailVotes" ("UUID", "votes", "locked", "shadowHidden", "createdAt", "updatedAt") VALUES (?, ?, ?, ?, ?, ?);'; + await db.prepare("run", insertThumbnailVotesQuery, ["postBrandLocked1", 0, 1, 0, isoDate, isoDate]); + await db.prepare("run", insertThumbnailVotesQuery, ["postBrandLocked2", 0, 1, 0, isoDate, isoDate]); // Approved original thumbnail submitter await db.prepare("run", insertThumbnailQuery, ["postBrandOriginThumb", 0, getHash(userID4), Service.YouTube, getHash("postBrandOriginThumb"), Date.now(), "postBrandOriginThumb"]); @@ -61,11 +61,11 @@ describe("postBranding", () => { await db.prepare("run", insertThumbnailQuery, ["postBrandOriginThumb3", 0, getHash(userID4), Service.YouTube, getHash("postBrandOriginThumb3"), Date.now(), "postBrandOriginThumb3"]); await db.prepare("run", insertThumbnailQuery, ["postBrandOriginThumb4", 0, getHash(userID4), Service.YouTube, getHash("postBrandOriginThumb4"), Date.now(), "postBrandOriginThumb4"]); await db.prepare("run", insertThumbnailQuery, ["postBrandOriginThumb5", 0, getHash(userID4), Service.YouTube, getHash("postBrandOriginThumb5"), Date.now(), "postBrandOriginThumb5"]); - await db.prepare("run", insertThumbnailVotesQuery, ["postBrandOriginThumb", 4, 0, 0]); - await db.prepare("run", insertThumbnailVotesQuery, ["postBrandOriginThumb2", 1, 0, 0]); - await db.prepare("run", insertThumbnailVotesQuery, ["postBrandOriginThumb3", 0, 0, 0]); - await db.prepare("run", insertThumbnailVotesQuery, ["postBrandOriginThumb4", 0, 0, 0]); - await db.prepare("run", insertThumbnailVotesQuery, ["postBrandOriginThumb5", 0, 0, 0]); + await db.prepare("run", insertThumbnailVotesQuery, ["postBrandOriginThumb", 4, 0, 0, isoDate, isoDate]); + await db.prepare("run", insertThumbnailVotesQuery, ["postBrandOriginThumb2", 1, 0, 0, isoDate, isoDate]); + await db.prepare("run", insertThumbnailVotesQuery, ["postBrandOriginThumb3", 0, 0, 0, isoDate, isoDate]); + await db.prepare("run", insertThumbnailVotesQuery, ["postBrandOriginThumb4", 0, 0, 0, isoDate, isoDate]); + await db.prepare("run", insertThumbnailVotesQuery, ["postBrandOriginThumb5", 0, 0, 0, isoDate, isoDate]); // Testing vip submission removal await db.prepare("run", insertTitleQuery, ["postBrandRemoved1", "Some title", 0, getHash(userID1), Service.YouTube, getHash("postBrandRemoved1"), Date.now(), "postBrandRemoved1"]); @@ -77,10 +77,10 @@ describe("postBranding", () => { const insertThumbnailTimestampQuery = 'INSERT INTO "thumbnailTimestamps" ("UUID", "timestamp") VALUES (?, ?)'; await db.prepare("run", insertThumbnailQuery, ["postBrandRemoved1", 0, getHash(userID3), Service.YouTube, getHash("postBrandRemoved1"), Date.now(), "postBrandRemoved1"]); await db.prepare("run", insertThumbnailTimestampQuery, ["postBrandRemoved1", 12.34]); - await db.prepare("run", insertThumbnailVotesQuery, ["postBrandRemoved1", 0, 1, 0]); + await db.prepare("run", insertThumbnailVotesQuery, ["postBrandRemoved1", 0, 1, 0, isoDate, isoDate]); await db.prepare("run", insertThumbnailQuery, ["postBrandRemoved1", 0, getHash(userID3), Service.YouTube, getHash("postBrandRemoved1"), Date.now(), "postBrandRemoved2"]); await db.prepare("run", insertThumbnailTimestampQuery, ["postBrandRemoved2", 13.34]); - await db.prepare("run", insertThumbnailVotesQuery, ["postBrandRemoved2", 0, 1, 0]); + await db.prepare("run", insertThumbnailVotesQuery, ["postBrandRemoved2", 0, 1, 0, isoDate, isoDate]); // Verified through title submissions await db.prepare("run", insertTitleQuery, ["postBrandVerified1", "Some title", 0, getHash(userID7), Service.YouTube, getHash("postBrandVerified1"), Date.now(), "postBrandVerified1"]); @@ -95,8 +95,8 @@ describe("postBranding", () => { await db.prepare("run", insertTitleVotesQuery, ["postBrandBannedOriginalVote", 0, 0, 0, 0, isoDate, isoDate]); await db.prepare("run", insertThumbnailQuery, ["postBrandBannedCustomVote", 0, getHash(userID1), Service.YouTube, getHash("postBrandBannedCustomVote"), Date.now(), "postBrandBannedCustomVote"]); await db.prepare("run", insertThumbnailQuery, ["postBrandBannedOriginalVote", 1, getHash(userID1), Service.YouTube, getHash("postBrandBannedOriginalVote"), Date.now(), "postBrandBannedOriginalVote"]); - await db.prepare("run", insertThumbnailVotesQuery, ["postBrandBannedCustomVote", 0, 0, 0]); - await db.prepare("run", insertThumbnailVotesQuery, ["postBrandBannedOriginalVote", 0, 0, 0]); + await db.prepare("run", insertThumbnailVotesQuery, ["postBrandBannedCustomVote", 0, 0, 0, isoDate, isoDate]); + await db.prepare("run", insertThumbnailVotesQuery, ["postBrandBannedOriginalVote", 0, 0, 0, isoDate, isoDate]); await db.prepare("run", insertThumbnailTimestampQuery, ["postBrandBannedCustomVote", 12.34]); }); diff --git a/test/cases/shadowBanUser.ts b/test/cases/shadowBanUser.ts index c666b38c..99b52b43 100644 --- a/test/cases/shadowBanUser.ts +++ b/test/cases/shadowBanUser.ts @@ -61,7 +61,7 @@ describe("shadowBanUser", () => { const titleVotesQuery = `INSERT INTO "titleVotes" ("UUID", "votes", "locked", "shadowHidden", "verification", "createdAt", "updatedAt") VALUES (?, ?, ?, ?, ?, ?, ?)`; const thumbnailQuery = `INSERT INTO "thumbnails" ("videoID", "original", "userID", "service", "hashedVideoID", "timeSubmitted", "UUID") VALUES (?, ?, ?, ?, ?, ?, ?)`; const thumbnailTimestampsQuery = `INSERT INTO "thumbnailTimestamps" ("UUID", "timestamp") VALUES (?, ?)`; - const thumbnailVotesQuery = `INSERT INTO "thumbnailVotes" ("UUID", "votes", "locked", "shadowHidden") VALUES (?, ?, ?, ?)`; + const thumbnailVotesQuery = `INSERT INTO "thumbnailVotes" ("UUID", "votes", "locked", "shadowHidden", "createdAt", "updatedAt") VALUES (?, ?, ?, ?, ?, ?)`; await Promise.all([ db.prepare("run", titleQuery, [video, "title1", 0, "userID1-ban", Service.YouTube, videohash, 1, "UUID1-ban"]), @@ -78,9 +78,9 @@ describe("shadowBanUser", () => { db.prepare("run", titleVotesQuery, ["UUID3-ban", 1, 0, 0, 0, isoDate, isoDate]), db.prepare("run", thumbnailTimestampsQuery, ["UUID1T-ban", 1]), db.prepare("run", thumbnailTimestampsQuery, ["UUID3T-ban", 3]), - db.prepare("run", thumbnailVotesQuery, ["UUID1T-ban", 3, 0, 0]), - db.prepare("run", thumbnailVotesQuery, ["UUID2T-ban", 2, 0, 0]), - db.prepare("run", thumbnailVotesQuery, ["UUID3T-ban", 1, 0, 0]), + db.prepare("run", thumbnailVotesQuery, ["UUID1T-ban", 3, 0, 0, isoDate, isoDate]), + db.prepare("run", thumbnailVotesQuery, ["UUID2T-ban", 2, 0, 0, isoDate, isoDate]), + db.prepare("run", thumbnailVotesQuery, ["UUID3T-ban", 1, 0, 0, isoDate, isoDate]), ]); await Promise.all([ @@ -98,9 +98,9 @@ describe("shadowBanUser", () => { db.prepare("run", titleVotesQuery, ["UUID3-ban2", 1, 0, 0, 0, isoDate, isoDate]), db.prepare("run", thumbnailTimestampsQuery, ["UUID1T-ban2", 1]), db.prepare("run", thumbnailTimestampsQuery, ["UUID3T-ban2", 3]), - db.prepare("run", thumbnailVotesQuery, ["UUID1T-ban2", 3, 0, 0]), - db.prepare("run", thumbnailVotesQuery, ["UUID2T-ban2", 2, 0, 0]), - db.prepare("run", thumbnailVotesQuery, ["UUID3T-ban2", 1, 0, 0]) + db.prepare("run", thumbnailVotesQuery, ["UUID1T-ban2", 3, 0, 0, isoDate, isoDate]), + db.prepare("run", thumbnailVotesQuery, ["UUID2T-ban2", 2, 0, 0, isoDate, isoDate]), + db.prepare("run", thumbnailVotesQuery, ["UUID3T-ban2", 1, 0, 0, isoDate, isoDate]) ]); await Promise.all([ diff --git a/test/utils/segmentQueryGen.ts b/test/utils/segmentQueryGen.ts index 6b542463..23839607 100644 --- a/test/utils/segmentQueryGen.ts +++ b/test/utils/segmentQueryGen.ts @@ -127,8 +127,8 @@ export const insertThumbnail = async (db: IDatabase, overrides: insertThumbnailP await db.prepare("run", query, Object.values(params)); }; -export const insertThumbnailVote = async (db: IDatabase, UUID: string, votes: number, locked = false, shadowHidden = false) => { - const query = 'INSERT INTO "thumbnailVotes" ("UUID", "votes", "locked", "shadowHidden") VALUES (?, ?, ?, ?)'; - const params = [UUID, votes, Number(locked), Number(shadowHidden)]; +export const insertThumbnailVote = async (db: IDatabase, UUID: string, votes: number, locked = false, shadowHidden = false, isoDate: string = new Date().toISOString()) => { + const query = 'INSERT INTO "thumbnailVotes" ("UUID", "votes", "locked", "shadowHidden", "createdAt", "updatedAt") VALUES (?, ?, ?, ?, ?, ?)'; + const params = [UUID, votes, Number(locked), Number(shadowHidden), isoDate, isoDate]; await db.prepare("run", query, params); }; \ No newline at end of file From a701486cbded2d88d2c9df9a37d8abee62498169 Mon Sep 17 00:00:00 2001 From: Tristan Date: Mon, 16 Sep 2024 19:24:54 +0200 Subject: [PATCH 27/27] refactor: change isoTimestamp to isoDate --- src/routes/addUserAsVIP.ts | 4 ++-- src/routes/postBranding.ts | 14 ++++++------- src/routes/postLockCategories.ts | 6 +++--- src/routes/postPurgeAllSegments.ts | 4 ++-- src/routes/postSegmentShift.ts | 8 ++++---- src/routes/postSkipSegments.ts | 8 ++++---- src/routes/setUsername.ts | 8 ++++---- src/routes/shadowBanUser.ts | 8 ++++---- src/routes/viewedVideoSponsorTime.ts | 4 ++-- src/routes/voteOnSponsorTime.ts | 30 ++++++++++++++-------------- 10 files changed, 47 insertions(+), 47 deletions(-) diff --git a/src/routes/addUserAsVIP.ts b/src/routes/addUserAsVIP.ts index 12025e71..e0c71274 100644 --- a/src/routes/addUserAsVIP.ts +++ b/src/routes/addUserAsVIP.ts @@ -38,11 +38,11 @@ export async function addUserAsVIP(req: AddUserAsVIPRequest, res: Response): Pro try { if (enabled && !userIsVIP) { // add them to the vip list - const isoTimestamp = new Date().toISOString(); + const isoDate = new Date().toISOString(); await db.prepare( "run", 'INSERT INTO "vipUsers" ("userID", "createdAt") VALUES(?, ?)', - [userID, isoTimestamp] + [userID, isoDate] ); } diff --git a/src/routes/postBranding.ts b/src/routes/postBranding.ts index 1a88385d..38c50c01 100644 --- a/src/routes/postBranding.ts +++ b/src/routes/postBranding.ts @@ -67,7 +67,7 @@ export async function postBranding(req: Request, res: Response) { } const now = Date.now(); - const isoTimestamp = new Date(now).toISOString(); + const isoDate = new Date(now).toISOString(); const voteType: BrandingVoteType = downvote ? BrandingVoteType.Downvote : BrandingVoteType.Upvote; if (title && !isVip && title.title.length > config.maxTitleLength) { @@ -106,14 +106,14 @@ export async function postBranding(req: Request, res: Response) { const verificationValue = await getVerificationValue(hashedUserID, isVip); await db.prepare("run", `INSERT INTO "titleVotes" ("UUID", "votes", "locked", "shadowHidden", "verification", "createdAt", "updatedAt") VALUES (?, 0, ?, ?, ?, ?, ?);`, - [UUID, shouldLock ? 1 : 0, isBanned ? 1 : 0, verificationValue, isoTimestamp, isoTimestamp]); + [UUID, shouldLock ? 1 : 0, isBanned ? 1 : 0, verificationValue, isoDate, isoDate]); await verifyOldSubmissions(hashedUserID, verificationValue); } if (isVip && !downvote && shouldLock) { // unlock all other titles - await db.prepare("run", `UPDATE "titleVotes" as tv SET "locked" = 0, "updatedAt" = ? FROM "titles" t WHERE tv."UUID" = t."UUID" AND tv."UUID" != ? AND t."videoID" = ?`, [isoTimestamp, UUID, videoID]); + await db.prepare("run", `UPDATE "titleVotes" as tv SET "locked" = 0, "updatedAt" = ? FROM "titles" t WHERE tv."UUID" = t."UUID" AND tv."UUID" != ? AND t."videoID" = ?`, [isoDate, UUID, videoID]); } sendWebhooks(videoID, UUID, voteType).catch((e) => Logger.error(e)); @@ -147,7 +147,7 @@ export async function postBranding(req: Request, res: Response) { [videoID, thumbnail.original ? 1 : 0, hashedUserID, service, hashedVideoID, now, UUID]); await db.prepare("run", `INSERT INTO "thumbnailVotes" ("UUID", "votes", "locked", "shadowHidden", "createdAt", "updatedAt") VALUES (?, 0, ?, ?, ?, ?)`, - [UUID, shouldLock ? 1 : 0, isBanned ? 1 : 0, isoTimestamp, isoTimestamp]); + [UUID, shouldLock ? 1 : 0, isBanned ? 1 : 0, isoDate, isoDate]); if (!thumbnail.original) { await db.prepare("run", `INSERT INTO "thumbnailTimestamps" ("UUID", "timestamp") VALUES (?, ?)`, @@ -157,7 +157,7 @@ export async function postBranding(req: Request, res: Response) { if (isVip && !downvote && shouldLock) { // unlock all other titles - await db.prepare("run", `UPDATE "thumbnailVotes" as tv SET "locked" = 0, "updatedAt" = ? FROM "thumbnails" t WHERE tv."UUID" = t."UUID" AND tv."UUID" != ? AND t."videoID" = ?`, [isoTimestamp, UUID, videoID]); + await db.prepare("run", `UPDATE "thumbnailVotes" as tv SET "locked" = 0, "updatedAt" = ? FROM "thumbnails" t WHERE tv."UUID" = t."UUID" AND tv."UUID" != ? AND t."videoID" = ?`, [isoDate, UUID, videoID]); } } })()]); @@ -285,7 +285,7 @@ export async function getVerificationValue(hashedUserID: HashedUserID, isVip: bo export async function verifyOldSubmissions(hashedUserID: HashedUserID, verification: number): Promise { if (verification >= 0) { const unverifiedSubmissions = await db.prepare("all", `SELECT "videoID", "hashedVideoID", "service" FROM "titles" JOIN "titleVotes" ON "titles"."UUID" = "titleVotes"."UUID" WHERE "titles"."userID" = ? AND "titleVotes"."verification" < ? GROUP BY "videoID", "hashedVideoID", "service"`, [hashedUserID, verification]); - const isoTimestamp = new Date().toISOString(); + const isoDate = new Date().toISOString(); if (unverifiedSubmissions.length > 0) { for (const submission of unverifiedSubmissions) { @@ -296,7 +296,7 @@ export async function verifyOldSubmissions(hashedUserID: HashedUserID, verificat }); } - await db.prepare("run", `UPDATE "titleVotes" as tv SET "verification" = ?, "updatedAt" = ? FROM "titles" WHERE "titles"."UUID" = tv."UUID" AND "titles"."userID" = ? AND tv."verification" < ?`, [verification, isoTimestamp, hashedUserID, verification]); + await db.prepare("run", `UPDATE "titleVotes" as tv SET "verification" = ?, "updatedAt" = ? FROM "titles" WHERE "titles"."UUID" = tv."UUID" AND "titles"."userID" = ? AND tv."verification" < ?`, [verification, isoDate, hashedUserID, verification]); } } } diff --git a/src/routes/postLockCategories.ts b/src/routes/postLockCategories.ts index 0c913ed5..b457ced4 100644 --- a/src/routes/postLockCategories.ts +++ b/src/routes/postLockCategories.ts @@ -61,7 +61,7 @@ export async function postLockCategories(req: Request, res: Response): Promise -2`, - [isoTimestamp, videoID, service, videoDuration]); + [isoDate, videoID, service, videoDuration]); lockedCategoryList = []; deleteLockCategories(videoID, null, null, service).catch((e) => Logger.error(`deleting lock categories: ${e}`)); @@ -560,7 +560,7 @@ export async function postSkipSegments(req: Request, res: Response): Promise { +function logUserNameChange(userID: string, newUserName: string, oldUserName: string, updatedByAdmin: boolean): Promise { return privateDB.prepare("run", `INSERT INTO "userNameLogs"("userID", "newUserName", "oldUserName", "updatedByAdmin", "updatedAt") VALUES(?, ?, ?, ?, ?)`, [userID, newUserName, oldUserName, + updatedByAdmin, new Date().getTime()] @@ -79,7 +79,7 @@ export async function setUsername(req: Request, res: Response): Promise `'${c}'`).join(",")}) AND NOT EXISTS ( SELECT "videoID", "category" FROM "lockCategories" WHERE - "sponsorTimes"."videoID" = "lockCategories"."videoID" AND "sponsorTimes"."service" = "lockCategories"."service" AND "sponsorTimes"."category" = "lockCategories"."category")`, [isoTimestamp, userID]); + "sponsorTimes"."videoID" = "lockCategories"."videoID" AND "sponsorTimes"."service" = "lockCategories"."service" AND "sponsorTimes"."category" = "lockCategories"."category")`, [isoDate, userID]); } // clear cache for all old videos @@ -109,12 +109,12 @@ async function unHideSubmissionsByUser(categories: string[], deArrowTypes: DeArr if (deArrowTypes.includes("title")) { await db.prepare("run", `UPDATE "titleVotes" as tv SET "shadowHidden" = ${type}, "updatedAt" = ? FROM "titles" t WHERE tv."UUID" = t."UUID" AND t."userID" = ?`, - [isoTimestamp, userID]); + [isoDate, userID]); } if (deArrowTypes.includes("thumbnail")) { await db.prepare("run", `UPDATE "thumbnailVotes" as tv SET "shadowHidden" = ${type}, "updatedAt" = ? FROM "thumbnails" t WHERE tv."UUID" = t."UUID" AND t."userID" = ?`, - [isoTimestamp, userID]); + [isoDate, userID]); } (await db.prepare("all", `SELECT "videoID", "hashedVideoID", "service" FROM "titles" WHERE "userID" = ?`, [userID])) diff --git a/src/routes/viewedVideoSponsorTime.ts b/src/routes/viewedVideoSponsorTime.ts index 431e82b3..194edce0 100644 --- a/src/routes/viewedVideoSponsorTime.ts +++ b/src/routes/viewedVideoSponsorTime.ts @@ -3,7 +3,7 @@ import { Request, Response } from "express"; export async function viewedVideoSponsorTime(req: Request, res: Response): Promise { const UUID = req.query?.UUID; - const isoTimestamp = new Date().toISOString(); + const isoDate = new Date().toISOString(); if (!UUID) { //invalid request @@ -11,7 +11,7 @@ export async function viewedVideoSponsorTime(req: Request, res: Response): Promi } //up the view count by one - await db.prepare("run", `UPDATE "sponsorTimes" SET views = views + 1, "updatedAt" = ? WHERE "UUID" = ?`, [isoTimestamp, UUID]); + await db.prepare("run", `UPDATE "sponsorTimes" SET views = views + 1, "updatedAt" = ? WHERE "UUID" = ?`, [isoDate, UUID]); return res.sendStatus(200); } diff --git a/src/routes/voteOnSponsorTime.ts b/src/routes/voteOnSponsorTime.ts index 39843410..84c57cd7 100644 --- a/src/routes/voteOnSponsorTime.ts +++ b/src/routes/voteOnSponsorTime.ts @@ -65,10 +65,10 @@ async function updateSegmentVideoDuration(UUID: SegmentUUID) { apiVideoDetails = await getVideoDetails(videoID, true); } const apiVideoDuration = apiVideoDetails?.duration as VideoDuration; - const isoTimestamp = new Date().toISOString(); + const isoDate = new Date().toISOString(); if (videoDurationChanged(videoDuration, apiVideoDuration)) { Logger.info(`Video duration changed for ${videoID} from ${videoDuration} to ${apiVideoDuration}`); - await db.prepare("run", `UPDATE "sponsorTimes" SET "videoDuration" = ?, "updatedAt" ? WHERE "UUID" = ?`, [apiVideoDuration, isoTimestamp, UUID]); + await db.prepare("run", `UPDATE "sponsorTimes" SET "videoDuration" = ?, "updatedAt" ? WHERE "UUID" = ?`, [apiVideoDuration, isoDate, UUID]); } } @@ -92,14 +92,14 @@ async function checkVideoDuration(UUID: SegmentUUID) { ORDER BY "timeSubmitted" DESC LIMIT 1`, [videoID, service]) as {videoDuration: VideoDuration, UUID: SegmentUUID, timeSubmitted: number}; - const isoTimestamp = new Date().toISOString(); + const isoDate = new Date().toISOString(); if (latestSubmission && videoDurationChanged(latestSubmission.videoDuration, apiVideoDuration)) { Logger.info(`Video duration changed for ${videoID} from ${latestSubmission.videoDuration} to ${apiVideoDuration}`); await db.prepare("run", `UPDATE "sponsorTimes" SET "hidden" = 1, "updatedAt" = ? WHERE "videoID" = ? AND "service" = ? AND "timeSubmitted" <= ? AND "hidden" = 0 AND "shadowHidden" = 0 AND "actionType" != 'full' AND "votes" > -2`, - [isoTimestamp, videoID, service, latestSubmission.timeSubmitted]); + [isoDate, videoID, service, latestSubmission.timeSubmitted]); deleteLockCategories(videoID, null, null, service).catch((e) => Logger.error(`delete lock categories after vote: ${e}`)); } } @@ -242,7 +242,7 @@ async function categoryVote(UUID: SegmentUUID, userID: HashedUserID, isVIP: bool const nextCategoryInfo = await db.prepare("get", `select votes from "categoryVotes" where "UUID" = ? and category = ?`, [UUID, category], { useReplica: true }); const timeSubmitted = Date.now(); - const isoTimestamp = new Date(timeSubmitted).toISOString(); + const isoDate = new Date(timeSubmitted).toISOString(); const voteAmount = (isVIP || isTempVIP) ? 500 : 1; const ableToVote = finalResponse.finalStatus === 200; // ban status checks handled by vote() (caller function) @@ -251,16 +251,16 @@ async function categoryVote(UUID: SegmentUUID, userID: HashedUserID, isVIP: bool // Add the vote if ((await db.prepare("get", `select count(*) as count from "categoryVotes" where "UUID" = ? and category = ?`, [UUID, category])).count > 0) { // Update the already existing db entry - await db.prepare("run", `update "categoryVotes" set "votes" = "votes" + ?, "updatedAt" = ? where "UUID" = ? and "category" = ?`, [voteAmount, isoTimestamp, UUID, category]); + await db.prepare("run", `update "categoryVotes" set "votes" = "votes" + ?, "updatedAt" = ? where "UUID" = ? and "category" = ?`, [voteAmount, isoDate, UUID, category]); } else { // Add a db entry - await db.prepare("run", `insert into "categoryVotes" ("UUID", "category", "votes", "createdAt", "updatedAt") values (?, ?, ?, ?, ?)`, [UUID, category, voteAmount, isoTimestamp, isoTimestamp]); + await db.prepare("run", `insert into "categoryVotes" ("UUID", "category", "votes", "createdAt", "updatedAt") values (?, ?, ?, ?, ?)`, [UUID, category, voteAmount, isoDate, isoDate]); } // Add the info into the private db if (usersLastVoteInfo?.votes > 0) { // Reverse the previous vote - await db.prepare("run", `update "categoryVotes" set "votes" = "votes" - ?, "updatedAt" = ? where "UUID" = ? and "category" = ?`, [voteAmount, isoTimestamp, UUID, usersLastVoteInfo.category]); + await db.prepare("run", `update "categoryVotes" set "votes" = "votes" - ?, "updatedAt" = ? where "UUID" = ? and "category" = ?`, [voteAmount, isoDate, UUID, usersLastVoteInfo.category]); await privateDB.prepare("run", `update "categoryVotes" set "category" = ?, "timeSubmitted" = ?, "hashedIP" = ? where "userID" = ? and "UUID" = ?`, [category, timeSubmitted, hashedIP, userID, UUID]); } else { @@ -280,7 +280,7 @@ async function categoryVote(UUID: SegmentUUID, userID: HashedUserID, isVIP: bool // Add submission as vote if (!currentCategoryInfo && submissionInfo) { - await db.prepare("run", `insert into "categoryVotes" ("UUID", "category", "votes", "createdAt", "updatedAt") values (?, ?, ?)`, [UUID, segmentInfo.category, currentCategoryCount, isoTimestamp, isoTimestamp]); + await db.prepare("run", `insert into "categoryVotes" ("UUID", "category", "votes", "createdAt", "updatedAt") values (?, ?, ?)`, [UUID, segmentInfo.category, currentCategoryCount, isoDate, isoDate]); await privateDB.prepare("run", `insert into "categoryVotes" ("UUID", "userID", "hashedIP", "category", "timeSubmitted") values (?, ?, ?, ?, ?)`, [UUID, submissionInfo.userID, "unknown", segmentInfo.category, submissionInfo.timeSubmitted]); } @@ -290,7 +290,7 @@ async function categoryVote(UUID: SegmentUUID, userID: HashedUserID, isVIP: bool // VIPs change it every time if (isVIP || isTempVIP || isOwnSubmission || nextCategoryCount - currentCategoryCount >= Math.max(Math.ceil(submissionInfo?.votes / 2), 2)) { // Replace the category - await db.prepare("run", `update "sponsorTimes" set "category" = ?, "updatedAt" = ? where "UUID" = ?`, [category, isoTimestamp, UUID]); + await db.prepare("run", `update "sponsorTimes" set "category" = ?, "updatedAt" = ? where "UUID" = ?`, [category, isoDate, UUID]); } } QueryCacher.clearSegmentCache(segmentInfo); @@ -513,14 +513,14 @@ export async function vote(ip: IPAddress, UUID: SegmentUUID, paramUserID: UserID await privateDB.prepare("run", `INSERT INTO "votes" ("UUID", "userID", "hashedIP", "type", "normalUserID", "originalType") VALUES(?, ?, ?, ?, ?, ?)`, [UUID, userID, hashedIP, type, nonAnonUserID, originalType]); } - const isoTimestamp = new Date().toISOString(); + const isoDate = new Date().toISOString(); // update the vote count on this sponsorTime - await db.prepare("run", `UPDATE "sponsorTimes" SET "votes" = "votes" + ?, "updatedAt" = ? WHERE "UUID" = ?`, [incrementAmount - oldIncrementAmount, isoTimestamp, UUID]); + await db.prepare("run", `UPDATE "sponsorTimes" SET "votes" = "votes" + ?, "updatedAt" = ? WHERE "UUID" = ?`, [incrementAmount - oldIncrementAmount, isoDate, UUID]); // tempVIP can bring back hidden segments if (isTempVIP && incrementAmount > 0 && voteTypeEnum === voteTypes.normal) { - await db.prepare("run", `UPDATE "sponsorTimes" SET "hidden" = 0, "updatedAt" = ? WHERE "UUID" = ?`, [isoTimestamp, UUID]); + await db.prepare("run", `UPDATE "sponsorTimes" SET "hidden" = 0, "updatedAt" = ? WHERE "UUID" = ?`, [isoDate, UUID]); } // additional processing for VIP // on VIP upvote @@ -528,10 +528,10 @@ export async function vote(ip: IPAddress, UUID: SegmentUUID, paramUserID: UserID // Update video duration in case that caused it to be hidden await updateSegmentVideoDuration(UUID); // unhide & unlock - await db.prepare("run", 'UPDATE "sponsorTimes" SET "locked" = 1, "hidden" = 0, "shadowHidden" = 0, "updatedAt" = ? WHERE "UUID" = ?', [isoTimestamp, UUID]); + await db.prepare("run", 'UPDATE "sponsorTimes" SET "locked" = 1, "hidden" = 0, "shadowHidden" = 0, "updatedAt" = ? WHERE "UUID" = ?', [isoDate, UUID]); // on VIP downvote/ undovote, also unlock submission } else if (isVIP && incrementAmount <= 0 && voteTypeEnum === voteTypes.normal) { - await db.prepare("run", 'UPDATE "sponsorTimes" SET "locked" = 0, "updatedAt" = ? WHERE "UUID" = ?', [isoTimestamp, UUID]); + await db.prepare("run", 'UPDATE "sponsorTimes" SET "locked" = 0, "updatedAt" = ? WHERE "UUID" = ?', [isoDate, UUID]); } QueryCacher.clearSegmentCache(segmentInfo);