Skip to content

Commit d163b1d

Browse files
committed
shadowban tests
1 parent 715d41f commit d163b1d

File tree

2 files changed

+74
-2
lines changed

2 files changed

+74
-2
lines changed

test/cases/shadowBanUser.ts

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,10 +187,34 @@ describe("shadowBanUser", () => {
187187
})
188188
.then(async res => {
189189
assert.strictEqual(res.status, 200);
190-
const videoRow = await getShadowBanSegmentCategory(userID, 1);
190+
const videoRow = await getShadowBanSegmentCategory(userID, 0);
191191
const shadowRow = await getShadowBan(userID);
192192
assert.ok(shadowRow); // ban still exists
193-
assert.strictEqual(videoRow.length, 1); // videos should be hidden
193+
assert.strictEqual(videoRow.length, 0); // videos should be hidden
194+
done();
195+
})
196+
.catch(err => done(err));
197+
});
198+
199+
it("Should be able to un-shadowban user to restore old submissions", (done) => {
200+
const userID = "shadowBanned4";
201+
client({
202+
method: "POST",
203+
url: endpoint,
204+
params: {
205+
userID,
206+
adminUserID: VIPuserID,
207+
enabled: false,
208+
categories: `["sponsor"]`,
209+
unHideOldSubmissions: true
210+
}
211+
})
212+
.then(async res => {
213+
assert.strictEqual(res.status, 200);
214+
const videoRow = await getShadowBanSegmentCategory(userID, 0);
215+
const shadowRow = await getShadowBan(userID);
216+
assert.ok(!shadowRow); // ban still exists
217+
assert.strictEqual(videoRow.length, 1); // videos should be visible
194218
assert.strictEqual(videoRow[0].category, "sponsor");
195219
done();
196220
})

test/cases/shadowBanUser4xx.ts

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import { db } from "../../src/databases/databases";
2+
import { getHash } from "../../src/utils/getHash";
3+
import assert from "assert";
4+
import { client } from "../utils/httpClient";
5+
6+
const endpoint = "/api/shadowBanUser";
7+
8+
const postShadowBan = (params: Record<string, string>) => client({
9+
method: "POST",
10+
url: endpoint,
11+
params
12+
});
13+
14+
describe("shadowBanUser 4xx", () => {
15+
const VIPuserID = "shadow-ban-4xx-vip";
16+
17+
before(async () => {
18+
await db.prepare("run", `INSERT INTO "vipUsers" ("userID") VALUES(?)`, [getHash(VIPuserID)]);
19+
});
20+
21+
it("Should return 400 if no adminUserID", (done) => {
22+
const userID = "shadowBanned";
23+
postShadowBan({ userID })
24+
.then(res => {
25+
assert.strictEqual(res.status, 400);
26+
done();
27+
})
28+
.catch(err => done(err));
29+
});
30+
31+
it("Should return 400 if no userID", (done) => {
32+
postShadowBan({ adminUserID: VIPuserID })
33+
.then(res => {
34+
assert.strictEqual(res.status, 400);
35+
done();
36+
})
37+
.catch(err => done(err));
38+
});
39+
40+
it("Should return 403 if not authorized", (done) => {
41+
postShadowBan({ adminUserID: "notVIPUserID", userID: "shadowBanned" })
42+
.then(res => {
43+
assert.strictEqual(res.status, 403);
44+
done();
45+
})
46+
.catch(err => done(err));
47+
});
48+
});

0 commit comments

Comments
 (0)