Merge branch 'master' of https://github.com/ajayyy/SponsorBlockServer into fullVideoLabels

This commit is contained in:
Michael C
2022-05-09 02:42:18 -04:00
33 changed files with 653 additions and 473 deletions

View File

@@ -89,7 +89,7 @@ describe("getStatus", () => {
});
it("Should be able to get statusRequests only", function (done) {
if (!config.redis) this.skip();
if (!config.redis?.enabled) this.skip();
client.get(`${endpoint}/statusRequests`)
.then(res => {
assert.strictEqual(res.status, 200);
@@ -100,7 +100,7 @@ describe("getStatus", () => {
});
it("Should be able to get status with statusRequests", function (done) {
if (!config.redis) this.skip();
if (!config.redis?.enabled) this.skip();
client.get(endpoint)
.then(res => {
assert.strictEqual(res.status, 200);

View File

@@ -734,22 +734,6 @@ describe("postSkipSegments", () => {
.catch(err => done(err));
});
it("Should be rejected if NB's predicted probability is <70%.", (done) => {
const videoID = "LevkAjUE6d4";
postSkipSegmentParam({
videoID,
startTime: 40,
endTime: 60,
userID: submitUserTwo,
category: "sponsor"
})
.then(res => {
assert.strictEqual(res.status, 200);
done();
})
.catch(err => done(err));
});
it("Should be rejected with custom message if user has to many active warnings", (done) => {
postSkipSegmentJSON({
userID: warnUser01,

View File

@@ -11,22 +11,21 @@ const randKey2 = genRandom(16);
describe("redis test", function() {
before(async function() {
if (!config.redis) this.skip();
await redis.setAsync(randKey1, randValue1);
if (!config.redis?.enabled) this.skip();
await redis.set(randKey1, randValue1);
});
it("Should get stored value", (done) => {
redis.getAsync(randKey1)
redis.get(randKey1)
.then(res => {
if (res.err) assert.fail(res.err);
assert.strictEqual(res.reply, randValue1);
assert.strictEqual(res, randValue1);
done();
});
}).catch(err => assert.fail(err));
});
it("Should not be able to get not stored value", (done) => {
redis.getAsync(randKey2)
redis.get(randKey2)
.then(res => {
if (res.reply || res.err ) assert.fail("Value should not be found");
if (res) assert.fail("Value should not be found");
done();
});
}).catch(err => assert.fail(err));
});
});

View File

@@ -6,6 +6,7 @@ import { client } from "../utils/httpClient";
import { db, privateDB } from "../../src/databases/databases";
import redis from "../../src/utils/redis";
import assert from "assert";
import { Logger } from "../../src/utils/logger";
// helpers
const getSegment = (UUID: string) => db.prepare("get", `SELECT "votes", "locked", "category" FROM "sponsorTimes" WHERE "UUID" = ?`, [UUID]);
@@ -51,13 +52,18 @@ const postVoteCategory = (userID: string, UUID: string, category: string) => cli
}
});
const checkUserVIP = async (publicID: HashedUserID) => {
const { reply } = await redis.getAsync(tempVIPKey(publicID));
return reply;
try {
const reply = await redis.get(tempVIPKey(publicID));
return reply;
} catch (e) {
Logger.error(e as string);
return false;
}
};
describe("tempVIP test", function() {
before(async function() {
if (!config.redis) this.skip();
if (!config.redis?.enabled) this.skip();
const insertSponsorTimeQuery = 'INSERT INTO "sponsorTimes" ("videoID", "startTime", "endTime", "votes", "locked", "UUID", "userID", "timeSubmitted", "views", "category", "shadowHidden") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)';
await db.prepare("run", insertSponsorTimeQuery, ["channelid-convert", 0, 1, 0, 0, UUID0, "testman", 0, 50, "sponsor", 0]);
@@ -67,7 +73,7 @@ describe("tempVIP test", function() {
await db.prepare("run", 'INSERT INTO "vipUsers" ("userID") VALUES (?)', [publicPermVIP1]);
await db.prepare("run", 'INSERT INTO "vipUsers" ("userID") VALUES (?)', [publicPermVIP2]);
// clear redis if running consecutive tests
await redis.delAsync(tempVIPKey(publicTempVIPOne));
await redis.del(tempVIPKey(publicTempVIPOne));
});
it("Should update db version when starting the application", () => {

View File

@@ -57,7 +57,7 @@ async function init() {
mocha.run((failures) => {
mockServer.close();
server.close();
redis.close(true);
redis.quit();
process.exitCode = failures ? 1 : 0; // exit with non-zero status if there were failures
});
});