|
| 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