mirror of
https://github.com/ajayyy/SponsorBlockServer.git
synced 2026-02-01 07:10:55 +03:00
remaining tests
This commit is contained in:
@@ -1,30 +1,25 @@
|
||||
import fetch from "node-fetch";
|
||||
import { Done, postJSON } from "../utils/utils";
|
||||
import { getbaseURL } from "../utils/getBaseURL";
|
||||
import { partialDeepEquals } from "../utils/partialDeepEquals";
|
||||
import { db } from "../../src/databases/databases";
|
||||
import { getHash } from "../../src/utils/getHash";
|
||||
import assert from "assert";
|
||||
import { client } from "../utils/httpClient";
|
||||
|
||||
describe("postWarning", () => {
|
||||
// constants
|
||||
const endpoint = `${getbaseURL()}/api/warnUser`;
|
||||
const endpoint = "/api/warnUser";
|
||||
const getWarning = (userID: string) => db.prepare("get", `SELECT "userID", "issueTime", "issuerUserID", enabled, "reason" FROM warnings WHERE "userID" = ?`, [userID]);
|
||||
|
||||
before(async () => {
|
||||
await db.prepare("run", `INSERT INTO "vipUsers" ("userID") VALUES (?)`, [getHash("warning-vip")]);
|
||||
});
|
||||
|
||||
it("Should be able to create warning if vip (exp 200)", (done: Done) => {
|
||||
it("Should be able to create warning if vip (exp 200)", (done) => {
|
||||
const json = {
|
||||
issuerUserID: "warning-vip",
|
||||
userID: "warning-0",
|
||||
reason: "warning-reason-0"
|
||||
};
|
||||
fetch(endpoint, {
|
||||
...postJSON,
|
||||
body: JSON.stringify(json),
|
||||
})
|
||||
client.post(endpoint, json)
|
||||
.then(async res => {
|
||||
assert.strictEqual(res.status, 200);
|
||||
const row = await getWarning(json.userID);
|
||||
@@ -39,16 +34,13 @@ describe("postWarning", () => {
|
||||
.catch(err => done(err));
|
||||
});
|
||||
|
||||
it("Should be not be able to create a duplicate warning if vip", (done: Done) => {
|
||||
it("Should be not be able to create a duplicate warning if vip", (done) => {
|
||||
const json = {
|
||||
issuerUserID: "warning-vip",
|
||||
userID: "warning-0",
|
||||
};
|
||||
|
||||
fetch(endpoint, {
|
||||
...postJSON,
|
||||
body: JSON.stringify(json),
|
||||
})
|
||||
client.post(endpoint, json)
|
||||
.then(async res => {
|
||||
assert.strictEqual(res.status, 409);
|
||||
const row = await getWarning(json.userID);
|
||||
@@ -62,17 +54,14 @@ describe("postWarning", () => {
|
||||
.catch(err => done(err));
|
||||
});
|
||||
|
||||
it("Should be able to remove warning if vip", (done: Done) => {
|
||||
it("Should be able to remove warning if vip", (done) => {
|
||||
const json = {
|
||||
issuerUserID: "warning-vip",
|
||||
userID: "warning-0",
|
||||
enabled: false
|
||||
};
|
||||
|
||||
fetch(endpoint, {
|
||||
...postJSON,
|
||||
body: JSON.stringify(json),
|
||||
})
|
||||
client.post(endpoint, json)
|
||||
.then(async res => {
|
||||
assert.strictEqual(res.status, 200);
|
||||
const row = await getWarning(json.userID);
|
||||
@@ -85,16 +74,13 @@ describe("postWarning", () => {
|
||||
.catch(err => done(err));
|
||||
});
|
||||
|
||||
it("Should not be able to create warning if not vip (exp 403)", (done: Done) => {
|
||||
it("Should not be able to create warning if not vip (exp 403)", (done) => {
|
||||
const json = {
|
||||
issuerUserID: "warning-not-vip",
|
||||
userID: "warning-1",
|
||||
};
|
||||
|
||||
fetch(endpoint, {
|
||||
...postJSON,
|
||||
body: JSON.stringify(json),
|
||||
})
|
||||
client.post(endpoint, json)
|
||||
.then(res => {
|
||||
assert.strictEqual(res.status, 403);
|
||||
done();
|
||||
@@ -102,8 +88,8 @@ describe("postWarning", () => {
|
||||
.catch(err => done(err));
|
||||
});
|
||||
|
||||
it("Should return 400 if missing body", (done: Done) => {
|
||||
fetch(endpoint, postJSON)
|
||||
it("Should return 400 if missing body", (done) => {
|
||||
client.post(endpoint, {})
|
||||
.then(async res => {
|
||||
assert.strictEqual(res.status, 400);
|
||||
done();
|
||||
@@ -111,17 +97,14 @@ describe("postWarning", () => {
|
||||
.catch(err => done(err));
|
||||
});
|
||||
|
||||
it("Should re-enable disabled warning", (done: Done) => {
|
||||
it("Should re-enable disabled warning", (done) => {
|
||||
const json = {
|
||||
issuerUserID: "warning-vip",
|
||||
userID: "warning-0",
|
||||
enabled: true
|
||||
};
|
||||
|
||||
fetch(endpoint, {
|
||||
...postJSON,
|
||||
body: JSON.stringify(json),
|
||||
})
|
||||
client.post(endpoint, json)
|
||||
.then(async res => {
|
||||
assert.strictEqual(res.status, 200);
|
||||
const data = await getWarning(json.userID);
|
||||
|
||||
Reference in New Issue
Block a user