remove debug statements, fix shadowBanUser tests

This commit is contained in:
Michael C
2023-01-28 02:54:01 -05:00
parent a64b8f99b7
commit 74c0ba37e2
2 changed files with 32 additions and 3 deletions

View File

@@ -76,14 +76,12 @@ async function handleGetSegments(req: Request, res: Response): Promise<searchSeg
} }
// Default to sponsor // Default to sponsor
const categories: Category[] = parseCategories(req, []); const categories: Category[] = parseCategories(req, []);
console.log(categories)
if (!Array.isArray(categories)) { if (!Array.isArray(categories)) {
res.status(400).send("Categories parameter does not match format requirements."); res.status(400).send("Categories parameter does not match format requirements.");
return false; return false;
} }
const actionTypes: ActionType[] = parseActionTypes(req, [ActionType.Skip]); const actionTypes: ActionType[] = parseActionTypes(req, [ActionType.Skip]);
console.log(actionTypes)
if (!Array.isArray(actionTypes)) { if (!Array.isArray(actionTypes)) {
res.status(400).send("actionTypes parameter does not match format requirements."); res.status(400).send("actionTypes parameter does not match format requirements.");
return false; return false;
@@ -176,7 +174,6 @@ async function endpoint(req: Request, res: Response): Promise<Response> {
} }
} catch (err) { } catch (err) {
/* istanbul ignore next */ /* istanbul ignore next */
console.log(err)
if (err instanceof SyntaxError) { if (err instanceof SyntaxError) {
return res.status(400).send("Invalid array in parameters"); return res.status(400).send("Invalid array in parameters");
} else return res.sendStatus(500); } else return res.sendStatus(500);

View File

@@ -32,9 +32,15 @@ describe("shadowBanUser", () => {
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]);
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", `INSERT INTO "shadowBannedUsers" ("userID") VALUES(?)`, ["shadowBanned3"]); 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 "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 "vipUsers" ("userID") VALUES(?)`, [getHash(VIPuserID)]); await db.prepare("run", `INSERT INTO "vipUsers" ("userID") VALUES(?)`, [getHash(VIPuserID)]);
}); });
@@ -274,4 +280,30 @@ describe("shadowBanUser", () => {
}) })
.catch(err => done(err)); .catch(err => done(err));
}); });
it("Should exclude locked segments when shadowbanning and removing segments", (done) => {
const userID = "shadowBanned6";
client({
method: "POST",
url: endpoint,
params: {
userID,
adminUserID: VIPuserID,
enabled: true,
categories: `["sponsor"]`,
unHideOldSubmissions: true
}
})
.then(async res => {
assert.strictEqual(res.status, 200);
const type1Videos = await getShadowBanSegmentCategory(userID, 2);
const type0Videos = await getShadowBanSegmentCategory(userID, 0);
const shadowRow = await getShadowBan(userID);
assert.ok(shadowRow); // ban exists
assert.strictEqual(type1Videos.length, 0); // no banned videos
assert.strictEqual(type0Videos.length, 1); // video still visible
done();
})
.catch(err => done(err));
});
}); });