mirror of
https://github.com/ajayyy/SponsorBlockServer.git
synced 2026-01-01 22:29:15 +03:00
shadowban tests
This commit is contained in:
@@ -187,10 +187,34 @@ describe("shadowBanUser", () => {
|
|||||||
})
|
})
|
||||||
.then(async res => {
|
.then(async res => {
|
||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, 200);
|
||||||
const videoRow = await getShadowBanSegmentCategory(userID, 1);
|
const videoRow = await getShadowBanSegmentCategory(userID, 0);
|
||||||
const shadowRow = await getShadowBan(userID);
|
const shadowRow = await getShadowBan(userID);
|
||||||
assert.ok(shadowRow); // ban still exists
|
assert.ok(shadowRow); // ban still exists
|
||||||
assert.strictEqual(videoRow.length, 1); // videos should be hidden
|
assert.strictEqual(videoRow.length, 0); // videos should be hidden
|
||||||
|
done();
|
||||||
|
})
|
||||||
|
.catch(err => done(err));
|
||||||
|
});
|
||||||
|
|
||||||
|
it("Should be able to un-shadowban user to restore old submissions", (done) => {
|
||||||
|
const userID = "shadowBanned4";
|
||||||
|
client({
|
||||||
|
method: "POST",
|
||||||
|
url: endpoint,
|
||||||
|
params: {
|
||||||
|
userID,
|
||||||
|
adminUserID: VIPuserID,
|
||||||
|
enabled: false,
|
||||||
|
categories: `["sponsor"]`,
|
||||||
|
unHideOldSubmissions: true
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.then(async res => {
|
||||||
|
assert.strictEqual(res.status, 200);
|
||||||
|
const videoRow = await getShadowBanSegmentCategory(userID, 0);
|
||||||
|
const shadowRow = await getShadowBan(userID);
|
||||||
|
assert.ok(!shadowRow); // ban still exists
|
||||||
|
assert.strictEqual(videoRow.length, 1); // videos should be visible
|
||||||
assert.strictEqual(videoRow[0].category, "sponsor");
|
assert.strictEqual(videoRow[0].category, "sponsor");
|
||||||
done();
|
done();
|
||||||
})
|
})
|
||||||
|
|||||||
48
test/cases/shadowBanUser4xx.ts
Normal file
48
test/cases/shadowBanUser4xx.ts
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
import { db } from "../../src/databases/databases";
|
||||||
|
import { getHash } from "../../src/utils/getHash";
|
||||||
|
import assert from "assert";
|
||||||
|
import { client } from "../utils/httpClient";
|
||||||
|
|
||||||
|
const endpoint = "/api/shadowBanUser";
|
||||||
|
|
||||||
|
const postShadowBan = (params: Record<string, string>) => client({
|
||||||
|
method: "POST",
|
||||||
|
url: endpoint,
|
||||||
|
params
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("shadowBanUser 4xx", () => {
|
||||||
|
const VIPuserID = "shadow-ban-4xx-vip";
|
||||||
|
|
||||||
|
before(async () => {
|
||||||
|
await db.prepare("run", `INSERT INTO "vipUsers" ("userID") VALUES(?)`, [getHash(VIPuserID)]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("Should return 400 if no adminUserID", (done) => {
|
||||||
|
const userID = "shadowBanned";
|
||||||
|
postShadowBan({ userID })
|
||||||
|
.then(res => {
|
||||||
|
assert.strictEqual(res.status, 400);
|
||||||
|
done();
|
||||||
|
})
|
||||||
|
.catch(err => done(err));
|
||||||
|
});
|
||||||
|
|
||||||
|
it("Should return 400 if no userID", (done) => {
|
||||||
|
postShadowBan({ adminUserID: VIPuserID })
|
||||||
|
.then(res => {
|
||||||
|
assert.strictEqual(res.status, 400);
|
||||||
|
done();
|
||||||
|
})
|
||||||
|
.catch(err => done(err));
|
||||||
|
});
|
||||||
|
|
||||||
|
it("Should return 403 if not authorized", (done) => {
|
||||||
|
postShadowBan({ adminUserID: "notVIPUserID", userID: "shadowBanned" })
|
||||||
|
.then(res => {
|
||||||
|
assert.strictEqual(res.status, 403);
|
||||||
|
done();
|
||||||
|
})
|
||||||
|
.catch(err => done(err));
|
||||||
|
});
|
||||||
|
});
|
||||||
Reference in New Issue
Block a user