mirror of
https://github.com/ajayyy/SponsorBlockServer.git
synced 2025-12-06 19:47:00 +03:00
add tests for shadowban
This commit is contained in:
@@ -620,7 +620,6 @@ export async function postSkipSegments(req: Request, res: Response): Promise<Res
|
||||
|
||||
//check to see if this user is shadowbanned
|
||||
const shadowBanRow = await db.prepare("get", `SELECT count(*) as "userCount" FROM "shadowBannedUsers" WHERE "userID" = ? LIMIT 1`, [userID]);
|
||||
|
||||
const startingVotes = 0 + decreaseVotes;
|
||||
const reputation = await getReputation(userID);
|
||||
|
||||
@@ -636,7 +635,7 @@ export async function postSkipSegments(req: Request, res: Response): Promise<Res
|
||||
await db.prepare("run", `INSERT INTO "sponsorTimes"
|
||||
("videoID", "startTime", "endTime", "votes", "locked", "UUID", "userID", "timeSubmitted", "views", "category", "actionType", "service", "videoDuration", "reputation", "shadowHidden", "hashedVideoID", "userAgent")
|
||||
VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`, [
|
||||
videoID, segmentInfo.segment[0], segmentInfo.segment[1], startingVotes, startingLocked, UUID, userID, timeSubmitted, 0, segmentInfo.category, segmentInfo.actionType, service, videoDuration, reputation, 0, hashedVideoID, userAgent
|
||||
videoID, segmentInfo.segment[0], segmentInfo.segment[1], startingVotes, startingLocked, UUID, userID, timeSubmitted, 0, segmentInfo.category, segmentInfo.actionType, service, videoDuration, reputation, shadowBanRow.userCount, hashedVideoID, userAgent
|
||||
],
|
||||
);
|
||||
|
||||
|
||||
@@ -26,11 +26,14 @@ describe("postSkipSegments", () => {
|
||||
const warnUser03Hash = getHash(warnUser03);
|
||||
const warnUser04 = "warn-user04-qwertyuiopasdfghjklzxcvbnm";
|
||||
const warnUser04Hash = getHash(warnUser04);
|
||||
const banUser01 = "ban-user01-loremipsumdolorsitametconsectetur";
|
||||
const banUser01Hash = getHash(banUser01);
|
||||
|
||||
const submitUserOneHash = getHash(submitUserOne);
|
||||
const submitVIPuser = `VIPPostSkipUser${".".repeat(16)}`;
|
||||
const warnVideoID = "postSkip2";
|
||||
const badInputVideoID = "dQw4w9WgXcQ";
|
||||
const shadowBanVideoID = "postSkipBan";
|
||||
|
||||
const queryDatabase = (videoID: string) => db.prepare("get", `SELECT "startTime", "endTime", "locked", "category" FROM "sponsorTimes" WHERE "videoID" = ?`, [videoID]);
|
||||
const queryDatabaseActionType = (videoID: string) => db.prepare("get", `SELECT "startTime", "endTime", "locked", "category", "actionType" FROM "sponsorTimes" WHERE "videoID" = ?`, [videoID]);
|
||||
@@ -88,6 +91,9 @@ describe("postSkipSegments", () => {
|
||||
|
||||
const insertVipUserQuery = 'INSERT INTO "vipUsers" ("userID") VALUES (?)';
|
||||
db.prepare("run", insertVipUserQuery, [getHash(submitVIPuser)]);
|
||||
|
||||
// ban user
|
||||
db.prepare("run", `INSERT INTO "shadowBannedUsers" ("userID") VALUES(?)`, [banUser01Hash]);
|
||||
});
|
||||
|
||||
it("Should be able to submit a single time (Params method)", (done) => {
|
||||
@@ -985,4 +991,28 @@ describe("postSkipSegments", () => {
|
||||
})
|
||||
.catch(err => done(err));
|
||||
});
|
||||
|
||||
it("Should automatically shadowban segments if user is banned", (done) => {
|
||||
const videoID = shadowBanVideoID;
|
||||
postSkipSegmentParam({
|
||||
videoID,
|
||||
startTime: 0,
|
||||
endTime: 10,
|
||||
category: "sponsor",
|
||||
userID: banUser01
|
||||
})
|
||||
.then(async res => {
|
||||
assert.strictEqual(res.status, 200);
|
||||
const row = await db.prepare("get", `SELECT "startTime", "endTime", "shadowHidden", "userID" FROM "sponsorTimes" WHERE "videoID" = ?`, [videoID]);
|
||||
const expected = {
|
||||
startTime: 0,
|
||||
endTime: 10,
|
||||
shadowHidden: 1,
|
||||
userID: banUser01Hash
|
||||
};
|
||||
assert.deepStrictEqual(row, expected);
|
||||
done();
|
||||
})
|
||||
.catch(err => done(err));
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user