mirror of
https://github.com/ajayyy/SponsorBlockServer.git
synced 2025-12-10 13:37:01 +03:00
everything after postClearCache
This commit is contained in:
@@ -1,10 +1,13 @@
|
||||
import fetch from "node-fetch";
|
||||
import * as utils from "../utils";
|
||||
import { getbaseURL, postJSON } from "../utils";
|
||||
import { getHash } from "../../src/utils/getHash";
|
||||
import { db } from "../../src/databases/databases";
|
||||
import assert from "assert";
|
||||
|
||||
describe("unBan", () => {
|
||||
const endpoint = `${getbaseURL()}/api/shadowBanUser`;
|
||||
const VIPuser = "VIPUser-unBan";
|
||||
const videoIDUnBanCheck = (videoID: string, userID: string, status: number) => db.prepare("all", 'SELECT * FROM "sponsorTimes" WHERE "videoID" = ? AND "userID" = ? AND "shadowHidden" = ?', [videoID, userID, status]);
|
||||
before(async () => {
|
||||
const insertShadowBannedUserQuery = 'INSERT INTO "shadowBannedUsers" VALUES(?)';
|
||||
await db.prepare("run", insertShadowBannedUserQuery, ["testMan-unBan"]);
|
||||
@@ -12,10 +15,10 @@ describe("unBan", () => {
|
||||
await db.prepare("run", insertShadowBannedUserQuery, ["testEntity-unBan"]);
|
||||
|
||||
const insertVipUserQuery = 'INSERT INTO "vipUsers" ("userID") VALUES (?)';
|
||||
await db.prepare("run", insertVipUserQuery, [getHash("VIPUser-unBan")]);
|
||||
await db.prepare("run", insertVipUserQuery, [getHash(VIPuser)]);
|
||||
|
||||
const insertLockCategoryQuery = 'INSERT INTO "lockCategories" ("userID", "videoID", "category") VALUES(?, ?, ?)';
|
||||
await db.prepare("run", insertLockCategoryQuery, [getHash("VIPUser-unBan"), "unBan-videoID-1", "sponsor"]);
|
||||
await db.prepare("run", insertLockCategoryQuery, [getHash(VIPuser), "unBan-videoID-1", "sponsor"]);
|
||||
|
||||
const insertSponsorTimeQuery = 'INSERT INTO "sponsorTimes" ("videoID", "startTime", "endTime", "votes", "UUID", "userID", "timeSubmitted", views, category, "shadowHidden", "hashedVideoID") VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)';
|
||||
await db.prepare("run", insertSponsorTimeQuery, ["unBan-videoID-0", 1, 11, 2, "unBan-uuid-0", "testMan-unBan", 0, 50, "sponsor", 1, getHash("unBan-videoID-0", 1)]);
|
||||
@@ -25,16 +28,13 @@ describe("unBan", () => {
|
||||
});
|
||||
|
||||
it("Should be able to unban a user and re-enable shadow banned segments", (done) => {
|
||||
fetch(`${utils.getbaseURL()
|
||||
}/api/shadowBanUser?userID=testMan-unBan&adminUserID=VIPUser-unBan&enabled=false`, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
const userID = "testMan-unBan";
|
||||
fetch(`${endpoint}?userID=${userID}&adminUserID=${VIPuser}&enabled=false`, {
|
||||
...postJSON
|
||||
})
|
||||
.then(async res => {
|
||||
assert.strictEqual(res.status, 200);
|
||||
const result = await db.prepare("all", 'SELECT * FROM "sponsorTimes" WHERE "videoID" = ? AND "userID" = ? AND "shadowHidden" = ?', ["unBan-videoID-0", "testMan-unBan", 1]);
|
||||
const result = await videoIDUnBanCheck("unBan-videoID-0", userID, 1);
|
||||
assert.strictEqual(result.length, 0);
|
||||
done();
|
||||
})
|
||||
@@ -42,16 +42,13 @@ describe("unBan", () => {
|
||||
});
|
||||
|
||||
it("Should be able to unban a user and re-enable shadow banned segments without lockCategories entrys", (done) => {
|
||||
fetch(`${utils.getbaseURL()
|
||||
}/api/shadowBanUser?userID=testWoman-unBan&adminUserID=VIPUser-unBan&enabled=false`, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
const userID = "testWoman-unBan";
|
||||
fetch(`${endpoint}?userID=${userID}&adminUserID=${VIPuser}&enabled=false`, {
|
||||
...postJSON
|
||||
})
|
||||
.then(async res => {
|
||||
assert.strictEqual(res.status, 200);
|
||||
const result = await db.prepare("all", 'SELECT * FROM "sponsorTimes" WHERE "videoID" = ? AND "userID" = ? AND "shadowHidden" = ?', ["unBan-videoID-1", "testWoman-unBan", 1]);
|
||||
const result = await videoIDUnBanCheck("unBan-videoID-1", userID, 1);
|
||||
assert.strictEqual(result.length, 1);
|
||||
done();
|
||||
})
|
||||
@@ -59,16 +56,13 @@ describe("unBan", () => {
|
||||
});
|
||||
|
||||
it("Should be able to unban a user and re-enable shadow banned segments with a mix of lockCategories entrys", (done) => {
|
||||
fetch(`${utils.getbaseURL()
|
||||
}/api/shadowBanUser?userID=testEntity-unBan&adminUserID=VIPUser-unBan&enabled=false`, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
const userID = "testEntity-unBan";
|
||||
fetch(`${endpoint}?userID=${userID}&adminUserID=${VIPuser}&enabled=false`, {
|
||||
...postJSON
|
||||
})
|
||||
.then(async res => {
|
||||
assert.strictEqual(res.status, 200);
|
||||
const result = await db.prepare("all", 'SELECT * FROM "sponsorTimes" WHERE "userID" = ? AND "shadowHidden" = ?', ["testEntity-unBan", 1]);
|
||||
const result = await db.prepare("all", 'SELECT * FROM "sponsorTimes" WHERE "userID" = ? AND "shadowHidden" = ?', [userID, 1]);
|
||||
assert.strictEqual(result.length, 1);
|
||||
done();
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user