SponsorBlockServer/test/cases/unBan.ts

74 lines
3.9 KiB
TypeScript
Raw Normal View History

2021-07-12 08:43:46 +02:00
import { getHash } from "../../src/utils/getHash";
import { db } from "../../src/databases/databases";
2021-09-23 05:18:31 +02:00
import { client } from "../utils/httpClient";
2021-07-12 08:43:46 +02:00
import assert from "assert";
2021-07-12 08:43:46 +02:00
describe("unBan", () => {
2021-09-23 05:18:31 +02:00
const endpoint = "/api/shadowBanUser";
2021-09-17 05:05:16 +02:00
const VIPuser = "VIPUser-unBan";
2021-09-23 05:18:31 +02:00
const postUnBan = (userID: string, adminUserID: string, enabled: boolean) => client({
url: endpoint,
method: "POST",
params: {
userID,
adminUserID,
enabled
}
});
2021-09-17 05:05:16 +02:00
const videoIDUnBanCheck = (videoID: string, userID: string, status: number) => db.prepare("all", 'SELECT * FROM "sponsorTimes" WHERE "videoID" = ? AND "userID" = ? AND "shadowHidden" = ?', [videoID, userID, status]);
2021-07-12 08:43:46 +02:00
before(async () => {
const insertShadowBannedUserQuery = 'INSERT INTO "shadowBannedUsers" VALUES(?)';
await db.prepare("run", insertShadowBannedUserQuery, ["testMan-unBan"]);
await db.prepare("run", insertShadowBannedUserQuery, ["testWoman-unBan"]);
await db.prepare("run", insertShadowBannedUserQuery, ["testEntity-unBan"]);
2021-05-07 01:51:11 +02:00
2021-07-12 08:43:46 +02:00
const insertVipUserQuery = 'INSERT INTO "vipUsers" ("userID") VALUES (?)';
2021-09-17 05:05:16 +02:00
await db.prepare("run", insertVipUserQuery, [getHash(VIPuser)]);
2021-07-12 08:43:46 +02:00
const insertLockCategoryQuery = 'INSERT INTO "lockCategories" ("userID", "videoID", "category") VALUES(?, ?, ?)';
2021-09-17 05:05:16 +02:00
await db.prepare("run", insertLockCategoryQuery, [getHash(VIPuser), "unBan-videoID-1", "sponsor"]);
2021-07-12 08:43:46 +02:00
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)]);
await db.prepare("run", insertSponsorTimeQuery, ["unBan-videoID-1", 1, 11, 2, "unBan-uuid-1", "testWoman-unBan", 0, 50, "sponsor", 1, getHash("unBan-videoID-1", 1)]);
await db.prepare("run", insertSponsorTimeQuery, ["unBan-videoID-1", 1, 11, 2, "unBan-uuid-2", "testEntity-unBan", 0, 60, "sponsor", 1, getHash("unBan-videoID-1", 1)]);
await db.prepare("run", insertSponsorTimeQuery, ["unBan-videoID-2", 1, 11, 2, "unBan-uuid-3", "testEntity-unBan", 0, 60, "sponsor", 1, getHash("unBan-videoID-2", 1)]);
});
2021-07-12 08:43:46 +02:00
it("Should be able to unban a user and re-enable shadow banned segments", (done) => {
2021-09-17 05:05:16 +02:00
const userID = "testMan-unBan";
2021-09-23 05:18:31 +02:00
postUnBan(userID, VIPuser, false)
2021-07-12 08:43:46 +02:00
.then(async res => {
assert.strictEqual(res.status, 200);
2021-09-17 05:05:16 +02:00
const result = await videoIDUnBanCheck("unBan-videoID-0", userID, 1);
2021-07-12 08:43:46 +02:00
assert.strictEqual(result.length, 0);
done();
})
.catch(err => done(err));
});
2021-07-12 08:43:46 +02:00
it("Should be able to unban a user and re-enable shadow banned segments without lockCategories entrys", (done) => {
2021-09-17 05:05:16 +02:00
const userID = "testWoman-unBan";
2021-09-23 05:18:31 +02:00
postUnBan(userID, VIPuser, false)
2021-07-12 08:43:46 +02:00
.then(async res => {
assert.strictEqual(res.status, 200);
2021-09-17 05:05:16 +02:00
const result = await videoIDUnBanCheck("unBan-videoID-1", userID, 1);
2021-07-12 08:43:46 +02:00
assert.strictEqual(result.length, 1);
done();
})
.catch(err => done(err));
});
2021-07-12 08:43:46 +02:00
it("Should be able to unban a user and re-enable shadow banned segments with a mix of lockCategories entrys", (done) => {
2021-09-17 05:05:16 +02:00
const userID = "testEntity-unBan";
2021-09-23 05:18:31 +02:00
postUnBan(userID, VIPuser, false)
2021-07-12 08:43:46 +02:00
.then(async res => {
assert.strictEqual(res.status, 200);
2021-09-17 05:05:16 +02:00
const result = await db.prepare("all", 'SELECT * FROM "sponsorTimes" WHERE "userID" = ? AND "shadowHidden" = ?', [userID, 1]);
2021-07-12 08:43:46 +02:00
assert.strictEqual(result.length, 1);
done();
})
.catch(err => done(err));
});
2021-01-06 01:43:28 +01:00
});