mirror of
https://github.com/ajayyy/SponsorBlockServer.git
synced 2025-12-13 06:57:05 +03:00
remove extra async and extra utils
This commit is contained in:
@@ -1,11 +1,9 @@
|
||||
import fetch from "node-fetch";
|
||||
import { Done } from "../utils/utils";
|
||||
import { getbaseURL } from "../utils/getBaseURL";
|
||||
import { getHash } from "../../src/utils/getHash";
|
||||
import { db } from "../../src/databases/databases";
|
||||
import assert from "assert";
|
||||
import { client } from "../utils/httpClient";
|
||||
|
||||
const endpoint = `${getbaseURL()}/api/lockReason`;
|
||||
const endpoint = "/api/lockReason";
|
||||
|
||||
describe("getLockReason", () => {
|
||||
before(async () => {
|
||||
@@ -28,71 +26,65 @@ describe("getLockReason", () => {
|
||||
else return `Version isn't greater than 20. Version is ${version}`;
|
||||
});
|
||||
|
||||
it("Should be able to get single reason", (done: Done) => {
|
||||
fetch(`${endpoint}?videoID=getLockReason&category=sponsor`)
|
||||
.then(async res => {
|
||||
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 data = await res.json();
|
||||
const expected = [
|
||||
{ category: "sponsor", locked: 1, reason: "sponsor-reason" }
|
||||
];
|
||||
assert.deepStrictEqual(data, expected);
|
||||
assert.deepStrictEqual(res.data, expected);
|
||||
done();
|
||||
})
|
||||
.catch(err => done(err));
|
||||
});
|
||||
|
||||
it("Should be able to get empty locks", (done: Done) => {
|
||||
fetch(`${endpoint}?videoID=getLockReason&category=intro`)
|
||||
.then(async res => {
|
||||
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 data = await res.json();
|
||||
const expected = [
|
||||
{ category: "intro", locked: 0, reason: "" }
|
||||
];
|
||||
assert.deepStrictEqual(data, expected);
|
||||
assert.deepStrictEqual(res.data, expected);
|
||||
done();
|
||||
})
|
||||
.catch(err => done(err));
|
||||
});
|
||||
|
||||
it("should get multiple locks with array", (done: Done) => {
|
||||
fetch(`${endpoint}?videoID=getLockReason&categories=["intro","sponsor"]`)
|
||||
.then(async res => {
|
||||
it("should get multiple locks with array", (done) => {
|
||||
client.get(endpoint, { params: { videoID: "getLockReason", categories: `["intro","sponsor"]` } })
|
||||
.then(res => {
|
||||
assert.strictEqual(res.status, 200);
|
||||
const data = await res.json();
|
||||
const expected = [
|
||||
{ category: "sponsor", locked: 1, reason: "sponsor-reason" },
|
||||
{ category: "intro", locked: 0, reason: "" }
|
||||
];
|
||||
assert.deepStrictEqual(data, expected);
|
||||
assert.deepStrictEqual(res.data, expected);
|
||||
done();
|
||||
})
|
||||
.catch(err => done(err));
|
||||
});
|
||||
|
||||
it("should get multiple locks with repeated category", (done: Done) => {
|
||||
fetch(`${endpoint}?videoID=getLockReason&category=interaction&category=music_offtopic&category=intro`)
|
||||
.then(async res => {
|
||||
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 data = await res.json();
|
||||
const expected = [
|
||||
{ category: "interaction", locked: 1, reason: "interaction-reason" },
|
||||
{ category: "music_offtopic", locked: 1, reason: "nonmusic-reason" },
|
||||
{ category: "intro", locked: 0, reason: "" }
|
||||
];
|
||||
assert.deepStrictEqual(data, expected);
|
||||
assert.deepStrictEqual(res.data, expected);
|
||||
done();
|
||||
})
|
||||
.catch(err => done(err));
|
||||
});
|
||||
|
||||
it("should return all categories if none specified", (done: Done) => {
|
||||
fetch(`${endpoint}?videoID=getLockReason`)
|
||||
.then(async res => {
|
||||
it("should return all categories if none specified", (done) => {
|
||||
client.get(endpoint, { params: { videoID: "getLockReason" } })
|
||||
.then(res => {
|
||||
assert.strictEqual(res.status, 200);
|
||||
const data = await res.json();
|
||||
console.log(data);
|
||||
const expected = [
|
||||
{ category: "sponsor", locked: 1, reason: "sponsor-reason" },
|
||||
{ category: "interaction", locked: 1, reason: "interaction-reason" },
|
||||
@@ -103,14 +95,14 @@ describe("getLockReason", () => {
|
||||
{ category: "outro", locked: 0, reason: "" },
|
||||
{ category: "poi_highlight", locked: 0, reason: "" }
|
||||
];
|
||||
assert.deepStrictEqual(data, expected);
|
||||
assert.deepStrictEqual(res.data, expected);
|
||||
done();
|
||||
})
|
||||
.catch(err => done(err));
|
||||
});
|
||||
|
||||
it("should return 400 if no videoID specified", (done: Done) => {
|
||||
fetch(endpoint)
|
||||
it("should return 400 if no videoID specified", (done) => {
|
||||
client.get(endpoint)
|
||||
.then(res => {
|
||||
assert.strictEqual(res.status, 400);
|
||||
done();
|
||||
|
||||
@@ -35,7 +35,7 @@ describe("postClearCache", () => {
|
||||
|
||||
it("Should get 403 as non-vip", (done) => {
|
||||
postClearCache(regularUser, "clear-test")
|
||||
.then(async res => {
|
||||
.then(res => {
|
||||
assert.strictEqual(res.status, 403);
|
||||
done();
|
||||
})
|
||||
@@ -44,7 +44,7 @@ describe("postClearCache", () => {
|
||||
|
||||
it("Should give 400 with missing videoID", (done) => {
|
||||
client.post(endpoint, { params: { userID: VIPUser } })
|
||||
.then(async res => {
|
||||
.then(res => {
|
||||
assert.strictEqual(res.status, 400);
|
||||
done();
|
||||
})
|
||||
@@ -53,7 +53,7 @@ describe("postClearCache", () => {
|
||||
|
||||
it("Should give 400 with missing userID", (done) => {
|
||||
client.post(endpoint, { params: { videoID: "clear-test" } })
|
||||
.then(async res => {
|
||||
.then(res => {
|
||||
assert.strictEqual(res.status, 400);
|
||||
done();
|
||||
})
|
||||
|
||||
@@ -311,7 +311,7 @@ describe("postSkipSegments", () => {
|
||||
category: "sponsor",
|
||||
}],
|
||||
})
|
||||
.then(async res => {
|
||||
.then(res => {
|
||||
assert.strictEqual(res.status, 403);
|
||||
done();
|
||||
})
|
||||
@@ -632,7 +632,7 @@ describe("postSkipSegments", () => {
|
||||
category: "sponsor",
|
||||
}],
|
||||
})
|
||||
.then(async res => {
|
||||
.then(res => {
|
||||
assert.strictEqual(res.status, 403);
|
||||
const errorMessage = res.data;
|
||||
const reason = "Reason01";
|
||||
@@ -707,7 +707,7 @@ describe("postSkipSegments", () => {
|
||||
category: "sponsor",
|
||||
}],
|
||||
})
|
||||
.then(async res => {
|
||||
.then(res => {
|
||||
assert.strictEqual(res.status, 403);
|
||||
const errorMessage = res.data;
|
||||
assert.notStrictEqual(errorMessage, "");
|
||||
|
||||
@@ -90,7 +90,7 @@ describe("postWarning", () => {
|
||||
|
||||
it("Should return 400 if missing body", (done) => {
|
||||
client.post(endpoint, {})
|
||||
.then(async res => {
|
||||
.then(res => {
|
||||
assert.strictEqual(res.status, 400);
|
||||
done();
|
||||
})
|
||||
|
||||
@@ -41,7 +41,7 @@ describe("segmentShift", function () {
|
||||
const privateVipUserID = "VIPUser-segmentShift";
|
||||
const vipUserID = getHash(privateVipUserID);
|
||||
const endpoint = "/api/segmentShift";
|
||||
const postSegmentShift = async (data: Record<string, any>) => client({
|
||||
const postSegmentShift = (data: Record<string, any>) => client({
|
||||
method: "POST",
|
||||
url: endpoint,
|
||||
data,
|
||||
@@ -71,7 +71,7 @@ describe("segmentShift", function () {
|
||||
startTime: 20,
|
||||
endTime: 30,
|
||||
})
|
||||
.then(async res => {
|
||||
.then(res => {
|
||||
assert.strictEqual(res.status, 403);
|
||||
done();
|
||||
})
|
||||
|
||||
@@ -34,14 +34,14 @@ async function getUsernameInfo(userID: string): Promise<{ userName: string, lock
|
||||
return row;
|
||||
}
|
||||
|
||||
async function addLogUserNameChange(userID: string, newUserName: string, oldUserName = "") {
|
||||
function addLogUserNameChange(userID: string, newUserName: string, oldUserName = "") {
|
||||
privateDB.prepare("run",
|
||||
`INSERT INTO "userNameLogs"("userID", "newUserName", "oldUserName", "updatedAt", "updatedByAdmin") VALUES(?, ?, ?, ?, ?)`,
|
||||
[getHash(userID), newUserName, oldUserName, new Date().getTime(), + true]
|
||||
);
|
||||
}
|
||||
|
||||
async function getLastLogUserNameChange(userID: string) {
|
||||
function getLastLogUserNameChange(userID: string) {
|
||||
return privateDB.prepare("get", `SELECT * FROM "userNameLogs" WHERE "userID" = ? ORDER BY "updatedAt" DESC LIMIT 1`, [getHash(userID)]);
|
||||
}
|
||||
|
||||
@@ -105,7 +105,7 @@ describe("setUsername", () => {
|
||||
it("Should return 200", (done) => {
|
||||
const username = "Changed%20Username";
|
||||
postSetUserName(user01PrivateUserID, username)
|
||||
.then(async res => {
|
||||
.then(res => {
|
||||
assert.strictEqual(res.status, 200);
|
||||
testUserNameChangelog(user01PrivateUserID, username, username01, false, done);
|
||||
})
|
||||
|
||||
@@ -2,7 +2,7 @@ import assert from "assert";
|
||||
import { partialDeepEquals } from "../utils/partialDeepEquals";
|
||||
|
||||
describe("Test utils ", () => {
|
||||
it("objectContain", async () => {
|
||||
it("objectContain", () => {
|
||||
assert(partialDeepEquals(
|
||||
{
|
||||
name: "John Wick",
|
||||
|
||||
@@ -310,7 +310,7 @@ describe("voteOnSponsorTime", () => {
|
||||
it("Should not be able to category-vote on an invalid UUID submission", (done) => {
|
||||
const UUID = "invalid-uuid";
|
||||
postVoteCategory("randomID3", UUID, "intro")
|
||||
.then(async res => {
|
||||
.then(res => {
|
||||
assert.strictEqual(res.status, 400);
|
||||
done();
|
||||
})
|
||||
@@ -356,7 +356,7 @@ describe("voteOnSponsorTime", () => {
|
||||
it("Should not be able to upvote a segment (Too many warning)", (done) => {
|
||||
const UUID = "warnvote-uuid-0";
|
||||
postVote("warn-voteuser01", UUID, 1)
|
||||
.then(async res => {
|
||||
.then(res => {
|
||||
assert.strictEqual(res.status, 403);
|
||||
done();
|
||||
})
|
||||
|
||||
@@ -1,5 +0,0 @@
|
||||
import { config } from "../../src/config";
|
||||
|
||||
export function getbaseURL(): string {
|
||||
return `http://localhost:${config.port}`;
|
||||
}
|
||||
@@ -1,12 +1,8 @@
|
||||
import { config } from "../../src/config";
|
||||
import axios, { AxiosRequestConfig } from "axios";
|
||||
|
||||
export function getbaseURL(): string {
|
||||
return `http://localhost:${config.port}`;
|
||||
}
|
||||
|
||||
export const defaultConfig: AxiosRequestConfig = {
|
||||
baseURL: getbaseURL(),
|
||||
const defaultConfig: AxiosRequestConfig = {
|
||||
baseURL: `http://localhost:${config.port}`,
|
||||
validateStatus: (status) => status < 500
|
||||
};
|
||||
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
/**
|
||||
* Duplicated from Mocha types. TypeScript doesn't infer that type by itself for some reason.
|
||||
*/
|
||||
export type Done = (err?: any) => void;
|
||||
|
||||
export const postJSON = {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
};
|
||||
@@ -1,6 +1,7 @@
|
||||
import { APIVideoData, APIVideoInfo } from "../src/types/youtubeApi.model";
|
||||
|
||||
export class YouTubeApiMock {
|
||||
// eslint-disable-next-line require-await
|
||||
static async listVideos(videoID: string): Promise<APIVideoInfo> {
|
||||
const obj = {
|
||||
id: videoID
|
||||
|
||||
Reference in New Issue
Block a user