mirror of
https://github.com/ajayyy/SponsorBlockServer.git
synced 2025-12-13 23:17:02 +03:00
Merge branch 'master' into categoryLeaderboards
This commit is contained in:
@@ -47,9 +47,9 @@ describe("getSkipSegmentsByHash", () => {
|
||||
await db.prepare("run", query, ["requiredSegmentHashVid", 10, 20, -2, 0, "fbf0af454059733c8822f6a4ac8ec568e0787f8c0a5ee915dd5b05e0d7a9a388", "testman", 0, 50, "sponsor", "skip", "YouTube", 0, 0, requiredSegmentHashVidHash, ""]);
|
||||
await db.prepare("run", query, ["requiredSegmentHashVid", 20, 30, -2, 0, "7e1ebc5194551d2d0a606d64f675e5a14952e4576b2959f8c9d51e316c14f8da", "testman", 0, 50, "sponsor", "skip", "YouTube", 0, 0, requiredSegmentHashVidHash, ""]);
|
||||
await db.prepare("run", query, ["differentCategoryVid", 60, 70, 2, 0, "differentCategoryVid-1", "testman", 0, 50, "sponsor", "skip", "YouTube", 0, 0, differentCategoryVidHash, ""]);
|
||||
await db.prepare("run", query, ["differentCategoryVid", 61, 70, 2, 1, "differentCategoryVid-2", "testman", 0, 50, "intro", "skip", "YouTube", 0, 0, differentCategoryVidHash, ""]);
|
||||
await db.prepare("run", query, ["differentCategoryVid", 60, 70, 2, 1, "differentCategoryVid-2", "testman", 0, 50, "intro", "skip", "YouTube", 0, 0, differentCategoryVidHash, ""]);
|
||||
await db.prepare("run", query, ["nonMusicOverlapVid", 60, 70, 2, 0, "nonMusicOverlapVid-1", "testman", 0, 50, "sponsor", "skip", "YouTube", 0, 0, nonMusicOverlapVidHash, ""]);
|
||||
await db.prepare("run", query, ["nonMusicOverlapVid", 61, 70, 2, 1, "nonMusicOverlapVid-2", "testman", 0, 50, "music_offtopic", "skip", "YouTube", 0, 0, nonMusicOverlapVidHash, ""]);
|
||||
await db.prepare("run", query, ["nonMusicOverlapVid", 60, 70, 2, 1, "nonMusicOverlapVid-2", "testman", 0, 50, "music_offtopic", "skip", "YouTube", 0, 0, nonMusicOverlapVidHash, ""]);
|
||||
});
|
||||
|
||||
it("Should be able to get a 200", (done) => {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import assert from "assert";
|
||||
import { db } from "../../src/databases/databases";
|
||||
import { client } from "../utils/httpClient";
|
||||
import { config } from "../../src/config";
|
||||
let dbVersion: number;
|
||||
|
||||
describe("getStatus", () => {
|
||||
@@ -86,4 +87,27 @@ describe("getStatus", () => {
|
||||
})
|
||||
.catch(err => done(err));
|
||||
});
|
||||
|
||||
it("Should be able to get statusRequests only", function (done) {
|
||||
if (!config.redis) this.skip();
|
||||
client.get(`${endpoint}/statusRequests`)
|
||||
.then(res => {
|
||||
assert.strictEqual(res.status, 200);
|
||||
assert.ok(Number(res.data) > 1);
|
||||
done();
|
||||
})
|
||||
.catch(err => done(err));
|
||||
});
|
||||
|
||||
it("Should be able to get status with statusRequests", function (done) {
|
||||
if (!config.redis) this.skip();
|
||||
client.get(endpoint)
|
||||
.then(res => {
|
||||
assert.strictEqual(res.status, 200);
|
||||
const data = res.data;
|
||||
assert.ok(data.statusRequests > 2);
|
||||
done();
|
||||
})
|
||||
.catch(err => done(err));
|
||||
});
|
||||
});
|
||||
|
||||
165
test/cases/tempVip.ts
Normal file
165
test/cases/tempVip.ts
Normal file
@@ -0,0 +1,165 @@
|
||||
import { config } from "../../src/config";
|
||||
import { getHash } from "../../src/utils/getHash";
|
||||
import { tempVIPKey } from "../../src/utils/redisKeys";
|
||||
import { HashedUserID } from "../../src/types/user.model";
|
||||
import { client } from "../utils/httpClient";
|
||||
import { db, privateDB } from "../../src/databases/databases";
|
||||
import redis from "../../src/utils/redis";
|
||||
import assert from "assert";
|
||||
|
||||
// helpers
|
||||
const getSegment = (UUID: string) => db.prepare("get", `SELECT "votes", "locked", "category" FROM "sponsorTimes" WHERE "UUID" = ?`, [UUID]);
|
||||
|
||||
const permVIP = "tempVipPermOne";
|
||||
const publicPermVIP = getHash(permVIP) as HashedUserID;
|
||||
const tempVIPOne = "tempVipTempOne";
|
||||
const publicTempVIPOne = getHash(tempVIPOne) as HashedUserID;
|
||||
const UUID0 = "tempvip-uuid0";
|
||||
const UUID1 = "tempvip-uuid1";
|
||||
|
||||
const tempVIPEndpoint = "/api/addUserAsTempVIP";
|
||||
const addTempVIP = (enabled: boolean) => client({
|
||||
url: tempVIPEndpoint,
|
||||
method: "POST",
|
||||
params: {
|
||||
userID: publicTempVIPOne,
|
||||
adminUserID: permVIP,
|
||||
channelVideoID: "channelid-convert",
|
||||
enabled: enabled
|
||||
}
|
||||
});
|
||||
const voteEndpoint = "/api/voteOnSponsorTime";
|
||||
const postVote = (userID: string, UUID: string, type: number) => client({
|
||||
method: "POST",
|
||||
url: voteEndpoint,
|
||||
params: {
|
||||
userID,
|
||||
UUID,
|
||||
type
|
||||
}
|
||||
});
|
||||
const postVoteCategory = (userID: string, UUID: string, category: string) => client({
|
||||
method: "POST",
|
||||
url: voteEndpoint,
|
||||
params: {
|
||||
userID,
|
||||
UUID,
|
||||
category
|
||||
}
|
||||
});
|
||||
const checkUserVIP = async () => {
|
||||
const { reply } = await redis.getAsync(tempVIPKey(publicTempVIPOne));
|
||||
return reply;
|
||||
};
|
||||
|
||||
describe("tempVIP test", function() {
|
||||
before(async function() {
|
||||
if (!config.redis) 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]);
|
||||
await db.prepare("run", insertSponsorTimeQuery, ["channelid-convert", 1, 9, 0, 1, "tempvip-submit", publicTempVIPOne, 0, 50, "sponsor", 0]);
|
||||
await db.prepare("run", insertSponsorTimeQuery, ["otherchannel", 1, 9, 0, 1, UUID1, "testman", 0, 50, "sponsor", 0]);
|
||||
|
||||
|
||||
await db.prepare("run", 'INSERT INTO "vipUsers" ("userID") VALUES (?)', [publicPermVIP]);
|
||||
// clear redis if running consecutive tests
|
||||
await redis.delAsync(tempVIPKey(publicTempVIPOne));
|
||||
});
|
||||
|
||||
it("Should update db version when starting the application", () => {
|
||||
privateDB.prepare("get", "SELECT key, value FROM config where key = ?", ["version"])
|
||||
.then(row => {
|
||||
assert.ok(row.value >= 5, `Versions are not at least 5. private is ${row.value}`);
|
||||
});
|
||||
});
|
||||
it("User should not already be temp VIP", (done) => {
|
||||
checkUserVIP()
|
||||
.then(result => {
|
||||
assert.ok(!result);
|
||||
done(result);
|
||||
})
|
||||
.catch(err => done(err));
|
||||
});
|
||||
it("Should be able to normal upvote as a user", (done) => {
|
||||
postVote(tempVIPOne, UUID0, 1)
|
||||
.then(async res => {
|
||||
assert.strictEqual(res.status, 200);
|
||||
const row = await getSegment(UUID0);
|
||||
assert.strictEqual(row.votes, 1);
|
||||
done();
|
||||
})
|
||||
.catch(err => done(err));
|
||||
});
|
||||
it("Should be able to add tempVIP", (done) => {
|
||||
addTempVIP(true)
|
||||
.then(async res => {
|
||||
assert.strictEqual(res.status, 200);
|
||||
const vip = await checkUserVIP();
|
||||
assert.ok(vip == "ChannelID");
|
||||
done();
|
||||
})
|
||||
.catch(err => done(err));
|
||||
});
|
||||
it("Should be able to VIP downvote", (done) => {
|
||||
postVote(tempVIPOne, UUID0, 0)
|
||||
.then(async res => {
|
||||
assert.strictEqual(res.status, 200);
|
||||
const row = await getSegment(UUID0);
|
||||
assert.strictEqual(row.votes, -2);
|
||||
done();
|
||||
})
|
||||
.catch(err => done(err));
|
||||
});
|
||||
it("Should be able to VIP lock", (done) => {
|
||||
postVote(tempVIPOne, UUID0, 1)
|
||||
.then(async res => {
|
||||
assert.strictEqual(res.status, 200);
|
||||
const row = await getSegment(UUID0);
|
||||
assert.ok(row.votes > -2);
|
||||
assert.strictEqual(row.locked, 1);
|
||||
done();
|
||||
})
|
||||
.catch(err => done(err));
|
||||
});
|
||||
it("Should be able to VIP change category", (done) => {
|
||||
postVoteCategory(tempVIPOne, UUID0, "filler")
|
||||
.then(async res => {
|
||||
assert.strictEqual(res.status, 200);
|
||||
const row = await getSegment(UUID0);
|
||||
assert.strictEqual(row.category, "filler");
|
||||
assert.strictEqual(row.locked, 1);
|
||||
done();
|
||||
})
|
||||
.catch(err => done(err));
|
||||
});
|
||||
it("Should be able to remove tempVIP prematurely", (done) => {
|
||||
addTempVIP(false)
|
||||
.then(async res => {
|
||||
assert.strictEqual(res.status, 200);
|
||||
const vip = await checkUserVIP();
|
||||
done(vip);
|
||||
})
|
||||
.catch(err => done(err));
|
||||
});
|
||||
it("Should not be able to VIP downvote", (done) => {
|
||||
postVote(tempVIPOne, UUID1, 0)
|
||||
.then(async res => {
|
||||
assert.strictEqual(res.status, 200);
|
||||
const row = await getSegment(UUID1);
|
||||
assert.strictEqual(row.votes, 0);
|
||||
done();
|
||||
})
|
||||
.catch(err => done(err));
|
||||
});
|
||||
it("Should not be able to VIP change category", (done) => {
|
||||
postVoteCategory(tempVIPOne, UUID1, "filler")
|
||||
.then(async res => {
|
||||
assert.strictEqual(res.status, 200);
|
||||
const row = await getSegment(UUID1);
|
||||
assert.strictEqual(row.category, "sponsor");
|
||||
done();
|
||||
})
|
||||
.catch(err => done(err));
|
||||
});
|
||||
});
|
||||
@@ -47,6 +47,15 @@ export class YouTubeApiMock {
|
||||
]
|
||||
} as APIVideoData
|
||||
};
|
||||
} else if (obj.id === "channelid-convert") {
|
||||
return {
|
||||
err: null,
|
||||
data: {
|
||||
title: "Video Lookup Title",
|
||||
author: "ChannelAuthor",
|
||||
authorId: "ChannelID"
|
||||
} as APIVideoData
|
||||
};
|
||||
} else {
|
||||
return {
|
||||
err: null,
|
||||
|
||||
Reference in New Issue
Block a user