mirror of
https://github.com/ajayyy/SponsorBlockServer.git
synced 2024-11-10 09:07:47 +01:00
d1d7675a8c
test fixes - fix timeout in redis (by @ajayyy) - allow "errors" in tempVIP test - remove duplicate warning in postSkipSegments - remove duplicate VIP in tempVIP - run tests against different user once tempVIP removed - fix typo in getHashCache fetching syntax and wording - use standard syntax in redisTest - fix spacing in getLockReason - typo in npm script name test cases - add getHashCache test case - add more tests to redisTest configuration - update config to use redis timeout - update docker-compose to use newest pinned version Co-Authored-By: Ajay Ramachandran <dev@ajay.app>
144 lines
7.5 KiB
TypeScript
144 lines
7.5 KiB
TypeScript
import { getHash } from "../../src/utils/getHash";
|
|
import { db } from "../../src/databases/databases";
|
|
import assert from "assert";
|
|
import { client } from "../utils/httpClient";
|
|
import { partialDeepEquals } from "../utils/partialDeepEquals";
|
|
|
|
const endpoint = "/api/lockReason";
|
|
|
|
const vipUserName1 = "getLockReason-vipUserName_1";
|
|
const vipUserID1 = getHash("getLockReason-vipUserID_1");
|
|
const vipUserName2 = "getLockReason-vipUserName_2";
|
|
const vipUserID2 = getHash("getLockReason-vipUserID_2");
|
|
|
|
describe("getLockReason", () => {
|
|
before(async () => {
|
|
const insertVipUserQuery = 'INSERT INTO "vipUsers" ("userID") VALUES (?)';
|
|
await db.prepare("run", insertVipUserQuery, [vipUserID1]);
|
|
await db.prepare("run", insertVipUserQuery, [vipUserID2]);
|
|
|
|
const insertVipUserNameQuery = 'INSERT INTO "userNames" ("userID", "userName") VALUES (?, ?)';
|
|
await db.prepare("run", insertVipUserNameQuery, [vipUserID1, vipUserName1]);
|
|
await db.prepare("run", insertVipUserNameQuery, [vipUserID2, vipUserName2]);
|
|
|
|
const insertLockCategoryQuery = 'INSERT INTO "lockCategories" ("userID", "videoID", "actionType", "category", "reason") VALUES (?, ?, ?, ?, ?)';
|
|
await db.prepare("run", insertLockCategoryQuery, [vipUserID1, "getLockReason", "skip", "sponsor", "sponsor-reason"]);
|
|
await db.prepare("run", insertLockCategoryQuery, [vipUserID1, "getLockReason", "skip", "interaction", "interaction-reason"]);
|
|
await db.prepare("run", insertLockCategoryQuery, [vipUserID1, "getLockReason", "skip", "preview", "preview-reason"]);
|
|
await db.prepare("run", insertLockCategoryQuery, [vipUserID1, "getLockReason", "mute", "music_offtopic", "nonmusic-reason"]);
|
|
await db.prepare("run", insertLockCategoryQuery, [vipUserID2, "getLockReason", "mute", "outro", "outro-reason"]);
|
|
await db.prepare("run", insertLockCategoryQuery, [vipUserID2, "getLockReason", "full", "selfpromo", "selfpromo-reason"]);
|
|
});
|
|
|
|
after(async () => {
|
|
const deleteUserNameQuery = 'DELETE FROM "userNames" WHERE "userID" = ? AND "userName" = ?';
|
|
await db.prepare("run", deleteUserNameQuery, [vipUserID1, vipUserName1]);
|
|
await db.prepare("run", deleteUserNameQuery, [vipUserID2, vipUserName2]);
|
|
});
|
|
|
|
it("Should update the database version when starting the application", async () => {
|
|
const version = (await db.prepare("get", "SELECT key, value FROM config where key = ?", ["version"])).value;
|
|
if (version > 20) return;
|
|
else return `Version isn't greater than 20. Version is ${version}`;
|
|
});
|
|
|
|
it("Should be able to get single reason", (done) => {
|
|
client.get(endpoint, { params: { videoID: "getLockReason", category: "sponsor" } })
|
|
.then(res => {
|
|
assert.strictEqual(res.status, 200);
|
|
const expected = [
|
|
{ category: "sponsor", locked: 1, reason: "sponsor-reason", userID: vipUserID1, userName: vipUserName1 }
|
|
];
|
|
assert.deepStrictEqual(res.data, expected);
|
|
done();
|
|
})
|
|
.catch(err => done(err));
|
|
});
|
|
|
|
it("Should be able to get empty locks", (done) => {
|
|
client.get(endpoint, { params: { videoID: "getLockReason", category: "intro" } })
|
|
.then(res => {
|
|
assert.strictEqual(res.status, 200);
|
|
const expected = [
|
|
{ category: "intro", locked: 0, reason: "", userID: "", userName: "" }
|
|
];
|
|
assert.deepStrictEqual(res.data, expected);
|
|
done();
|
|
})
|
|
.catch(err => done(err));
|
|
});
|
|
|
|
it("should get multiple locks with array", (done) => {
|
|
client.get(endpoint, { params: { videoID: "getLockReason", categories: `["intro","sponsor","outro"]` } })
|
|
.then(res => {
|
|
assert.strictEqual(res.status, 200);
|
|
const expected = [
|
|
{ category: "intro", locked: 0, reason: "", userID: "", userName: "" },
|
|
{ category: "sponsor", locked: 1, reason: "sponsor-reason", userID: vipUserID1, userName: vipUserName1 },
|
|
{ category: "outro", locked: 1, reason: "outro-reason", userID: vipUserID2, userName: vipUserName2 }
|
|
];
|
|
assert.deepStrictEqual(res.data, expected);
|
|
done();
|
|
})
|
|
.catch(err => done(err));
|
|
});
|
|
|
|
it("should get multiple locks with repeated category", (done) => {
|
|
client.get(`${endpoint}?videoID=getLockReason&category=interaction&category=music_offtopic&category=intro`)
|
|
.then(res => {
|
|
assert.strictEqual(res.status, 200);
|
|
const expected = [
|
|
{ category: "interaction", locked: 1, reason: "interaction-reason", userID: vipUserID1, userName: vipUserName1 },
|
|
{ category: "music_offtopic", locked: 1, reason: "nonmusic-reason", userID: vipUserID1, userName: vipUserName1 },
|
|
{ category: "intro", locked: 0, reason: "", userID: "", userName: "" }
|
|
];
|
|
assert.deepStrictEqual(res.data, expected);
|
|
done();
|
|
})
|
|
.catch(err => done(err));
|
|
});
|
|
|
|
it("should return all skip + mute categories if none specified", (done) => {
|
|
client.get(endpoint, { params: { videoID: "getLockReason" } })
|
|
.then(res => {
|
|
assert.strictEqual(res.status, 200);
|
|
const expected = [
|
|
{ category: "sponsor", locked: 1, reason: "sponsor-reason", userID: vipUserID1, userName: vipUserName1 },
|
|
{ category: "selfpromo", locked: 0, reason: "", userID: "", userName: "" },
|
|
{ category: "exclusive_access", locked: 0, reason: "", userID: "", userName: "" },
|
|
{ category: "interaction", locked: 1, reason: "interaction-reason", userID: vipUserID1, userName: vipUserName1 },
|
|
{ category: "intro", locked: 0, reason: "", userID: "", userName: "" },
|
|
{ category: "outro", locked: 1, reason: "outro-reason", userID: vipUserID2, userName: vipUserName2 },
|
|
{ category: "preview", locked: 1, reason: "preview-reason", userID: vipUserID1, userName: vipUserName1 },
|
|
{ category: "music_offtopic", locked: 1, reason: "nonmusic-reason", userID: vipUserID1, userName: vipUserName1 },
|
|
{ category: "filler", locked: 0, reason: "", userID: "", userName: "" },
|
|
];
|
|
partialDeepEquals(res.data, expected, false);
|
|
done();
|
|
})
|
|
.catch(err => done(err));
|
|
});
|
|
|
|
it("should return 400 if no videoID specified", (done) => {
|
|
client.get(endpoint)
|
|
.then(res => {
|
|
assert.strictEqual(res.status, 400);
|
|
done();
|
|
})
|
|
.catch(err => done(err));
|
|
});
|
|
|
|
it("should be able to get by actionType", (done) => {
|
|
client.get(endpoint, { params: { videoID: "getLockReason", actionType: "full" } })
|
|
.then(res => {
|
|
assert.strictEqual(res.status, 200);
|
|
const expected = [
|
|
{ category: "selfpromo", locked: 1, reason: "sponsor-reason", userID: vipUserID2, userName: vipUserName2 },
|
|
{ category: "sponsor", locked: 0, reason: "", userID: "", userName: "" }
|
|
];
|
|
partialDeepEquals(res.data, expected);
|
|
done();
|
|
})
|
|
.catch(err => done(err));
|
|
});
|
|
});
|