mirror of
https://github.com/ajayyy/SponsorBlockServer.git
synced 2025-12-06 11:36:58 +03:00
fix missed awaits for db.prepare in test cases
This commit is contained in:
@@ -33,11 +33,11 @@ const checkUserViews = (user: User) =>
|
||||
});
|
||||
|
||||
describe("getViewsForUser", function() {
|
||||
before(() => {
|
||||
before(async () => {
|
||||
// add views for users
|
||||
insertSegment(db, { userID: users["u-1"].pubID, views: users["u-1"].info.views1 });
|
||||
insertSegment(db, { userID: users["u-1"].pubID, views: users["u-1"].info.views2 });
|
||||
insertSegment(db, { userID: users["u-2"].pubID, views: users["u-2"].info.views });
|
||||
await insertSegment(db, { userID: users["u-1"].pubID, views: users["u-1"].info.views1 });
|
||||
await insertSegment(db, { userID: users["u-1"].pubID, views: users["u-1"].info.views2 });
|
||||
await insertSegment(db, { userID: users["u-2"].pubID, views: users["u-2"].info.views });
|
||||
});
|
||||
it("Should get back views for user one", () =>
|
||||
checkUserViews(users["u-1"])
|
||||
@@ -53,4 +53,4 @@ describe("getViewsForUser", function() {
|
||||
client({ url: endpoint })
|
||||
.then(res => assert.strictEqual(res.status, 400))
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -50,12 +50,12 @@ describe("postSkipSegments", () => {
|
||||
const queryDatabaseActionType = (videoID: string) => db.prepare("get", `SELECT "startTime", "endTime", "locked", "category", "actionType" FROM "sponsorTimes" WHERE "videoID" = ?`, [videoID]);
|
||||
const queryDatabaseVideoInfo = (videoID: string) => db.prepare("get", `SELECT * FROM "videoInfo" WHERE "videoID" = ?`, [videoID]);
|
||||
|
||||
before(() => {
|
||||
before(async () => {
|
||||
const insertSponsorTimeQuery = 'INSERT INTO "sponsorTimes" ("videoID", "startTime", "endTime", "votes", "UUID", "userID", "timeSubmitted", views, category, "actionType", "videoDuration", "shadowHidden", "hashedVideoID") VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)';
|
||||
db.prepare("run", insertSponsorTimeQuery, ["full_video_segment", 0, 0, 0, "full-video-uuid-0", submitUserTwoHash, 0, 0, "sponsor", "full", 0, 0, "full_video_segment"]);
|
||||
await db.prepare("run", insertSponsorTimeQuery, ["full_video_segment", 0, 0, 0, "full-video-uuid-0", submitUserTwoHash, 0, 0, "sponsor", "full", 0, 0, "full_video_segment"]);
|
||||
|
||||
const insertVipUserQuery = 'INSERT INTO "vipUsers" ("userID") VALUES (?)';
|
||||
db.prepare("run", insertVipUserQuery, [getHash(submitVIPuser)]);
|
||||
await db.prepare("run", insertVipUserQuery, [getHash(submitVIPuser)]);
|
||||
});
|
||||
|
||||
it("Should be able to submit a single time (Params method)", (done) => {
|
||||
|
||||
@@ -19,11 +19,11 @@ describe("postSkipSegments - Automod 80%", () => {
|
||||
|
||||
const queryDatabaseCategory = (videoID: string) => db.prepare("all", `SELECT "startTime", "endTime", "category" FROM "sponsorTimes" WHERE "videoID" = ? and "votes" > -1`, [videoID]);
|
||||
|
||||
before(() => {
|
||||
before(async () => {
|
||||
const insertSponsorTimeQuery = 'INSERT INTO "sponsorTimes" ("videoID", "startTime", "endTime", "votes", "UUID", "userID", "timeSubmitted", views, category, "actionType", "videoDuration", "shadowHidden", "hashedVideoID") VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)';
|
||||
db.prepare("run", insertSponsorTimeQuery, [over80VideoID, 0, 1000, 0, "80percent-uuid-0", userIDHash, 0, 0, "interaction", "skip", 0, 0, over80VideoID]);
|
||||
db.prepare("run", insertSponsorTimeQuery, [over80VideoID, 1001, 1005, 0, "80percent-uuid-1", userIDHash, 0, 0, "interaction", "skip", 0, 0, over80VideoID]);
|
||||
db.prepare("run", insertSponsorTimeQuery, [over80VideoID, 0, 5000, -2, "80percent-uuid-2", userIDHash, 0, 0, "interaction", "skip", 0, 0, over80VideoID]);
|
||||
await db.prepare("run", insertSponsorTimeQuery, [over80VideoID, 0, 1000, 0, "80percent-uuid-0", userIDHash, 0, 0, "interaction", "skip", 0, 0, over80VideoID]);
|
||||
await db.prepare("run", insertSponsorTimeQuery, [over80VideoID, 1001, 1005, 0, "80percent-uuid-1", userIDHash, 0, 0, "interaction", "skip", 0, 0, over80VideoID]);
|
||||
await db.prepare("run", insertSponsorTimeQuery, [over80VideoID, 0, 5000, -2, "80percent-uuid-2", userIDHash, 0, 0, "interaction", "skip", 0, 0, over80VideoID]);
|
||||
});
|
||||
|
||||
it("Should allow multiple times if total is under 80% of video (JSON method)", (done) => {
|
||||
|
||||
@@ -21,10 +21,10 @@ describe("postSkipSegments - duration", () => {
|
||||
|
||||
const queryDatabaseDuration = (videoID: string) => db.prepare("get", `SELECT "startTime", "endTime", "locked", "category", "videoDuration" FROM "sponsorTimes" WHERE "videoID" = ?`, [videoID]);
|
||||
|
||||
before(() => {
|
||||
before(async () => {
|
||||
const insertSponsorTimeQuery = 'INSERT INTO "sponsorTimes" ("videoID", "startTime", "endTime", "votes", "UUID", "userID", "timeSubmitted", views, category, "actionType", "videoDuration", "shadowHidden", "hashedVideoID") VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)';
|
||||
db.prepare("run", insertSponsorTimeQuery, ["full_video_duration_segment", 0, 0, 0, "full-video-duration-uuid-0", userIDTwo, 0, 0, "sponsor", "full", 123, 0, "full_video_duration_segment"]);
|
||||
db.prepare("run", insertSponsorTimeQuery, ["full_video_duration_segment", 25, 30, 0, "full-video-duration-uuid-1", userIDTwo, 0, 0, "sponsor", "skip", 123, 0, "full_video_duration_segment"]);
|
||||
await db.prepare("run", insertSponsorTimeQuery, ["full_video_duration_segment", 0, 0, 0, "full-video-duration-uuid-0", userIDTwo, 0, 0, "sponsor", "full", 123, 0, "full_video_duration_segment"]);
|
||||
await db.prepare("run", insertSponsorTimeQuery, ["full_video_duration_segment", 25, 30, 0, "full-video-duration-uuid-1", userIDTwo, 0, 0, "sponsor", "skip", 123, 0, "full_video_duration_segment"]);
|
||||
});
|
||||
|
||||
it("Should be able to submit a single time with a precise duration close to the one from the YouTube API (JSON method)", (done) => {
|
||||
@@ -202,4 +202,4 @@ describe("postSkipSegments - duration", () => {
|
||||
})
|
||||
.catch(err => done(err));
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -21,17 +21,17 @@ describe("postSkipSegments Features - Chapters", () => {
|
||||
};
|
||||
}
|
||||
|
||||
before(() => {
|
||||
before(async () => {
|
||||
const submitNumberOfTimes = 10;
|
||||
const submitUser_reputationHash = getHash(submitUser_reputation);
|
||||
const insertSponsorTimeQuery = 'INSERT INTO "sponsorTimes" ("videoID", "startTime", "endTime", "votes", "locked", "UUID", "userID", "timeSubmitted", views, category, "actionType", "shadowHidden") VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)';
|
||||
for (let i = 0; i < submitNumberOfTimes; i++) {
|
||||
const uuid = `post_reputation_uuid-${i}`;
|
||||
const videoID = `post_reputation_video-${i}`;
|
||||
db.prepare("run", insertSponsorTimeQuery, [videoID, 1, 11, 5, 1, uuid, submitUser_reputationHash, 1597240000000, 50, "sponsor", "skip", 0]);
|
||||
await db.prepare("run", insertSponsorTimeQuery, [videoID, 1, 11, 5, 1, uuid, submitUser_reputationHash, 1597240000000, 50, "sponsor", "skip", 0]);
|
||||
}
|
||||
// user feature
|
||||
db.prepare("run", `INSERT INTO "userFeatures" ("userID", "feature", "issuerUserID", "timeSubmitted") VALUES(?, ?, ?, ?)`, [getHash(submitUser_feature), Feature.ChapterSubmitter, "generic-VIP", 0]);
|
||||
await db.prepare("run", `INSERT INTO "userFeatures" ("userID", "feature", "issuerUserID", "timeSubmitted") VALUES(?, ?, ?, ?)`, [getHash(submitUser_feature), Feature.ChapterSubmitter, "generic-VIP", 0]);
|
||||
});
|
||||
|
||||
it("Should be able to submit a single chapter due to reputation (JSON method)", (done) => {
|
||||
|
||||
@@ -9,10 +9,10 @@ describe("postSkipSegments - LockedVideos", () => {
|
||||
const videoID = "lockedVideo";
|
||||
const userID = userIDOne;
|
||||
|
||||
before(() => {
|
||||
before(async () => {
|
||||
const insertLockCategoriesQuery = `INSERT INTO "lockCategories" ("userID", "videoID", "category", "reason") VALUES(?, ?, ?, ?)`;
|
||||
db.prepare("run", insertLockCategoriesQuery, [getHash(VIPLockUser), videoID, "sponsor", "Custom Reason"]);
|
||||
db.prepare("run", insertLockCategoriesQuery, [getHash(VIPLockUser), videoID, "intro", ""]);
|
||||
await db.prepare("run", insertLockCategoriesQuery, [getHash(VIPLockUser), videoID, "sponsor", "Custom Reason"]);
|
||||
await db.prepare("run", insertLockCategoriesQuery, [getHash(VIPLockUser), videoID, "intro", ""]);
|
||||
});
|
||||
|
||||
it("Should return 403 and custom reason for submiting in lockedCategory", (done) => {
|
||||
@@ -67,4 +67,4 @@ describe("postSkipSegments - LockedVideos", () => {
|
||||
})
|
||||
.catch(err => done(err));
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -19,8 +19,8 @@ describe("postSkipSegments - shadowban", () => {
|
||||
|
||||
const queryDatabaseShadowhidden = (videoID: string) => db.prepare("get", `SELECT "startTime", "endTime", "shadowHidden", "userID" FROM "sponsorTimes" WHERE "videoID" = ?`, [videoID]);
|
||||
|
||||
before(() => {
|
||||
db.prepare("run", `INSERT INTO "shadowBannedUsers" ("userID") VALUES(?)`, [banUser01Hash]);
|
||||
before(async () => {
|
||||
await db.prepare("run", `INSERT INTO "shadowBannedUsers" ("userID") VALUES(?)`, [banUser01Hash]);
|
||||
});
|
||||
|
||||
it("Should automatically shadowban segments if user is banned", (done) => {
|
||||
@@ -65,4 +65,4 @@ describe("postSkipSegments - shadowban", () => {
|
||||
})
|
||||
.catch(err => done(err));
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -21,10 +21,10 @@ describe("postSkipSegments - userAgent", () => {
|
||||
};
|
||||
const dbFormatSegment = convertSingleToDBFormat(segment);
|
||||
|
||||
before(() => {
|
||||
before(async () => {
|
||||
const insertLockCategoriesQuery = `INSERT INTO "lockCategories" ("userID", "videoID", "category", "reason") VALUES(?, ?, ?, ?)`;
|
||||
db.prepare("run", insertLockCategoriesQuery, [getHash(VIPLockUser), videoID, "sponsor", "Custom Reason"]);
|
||||
db.prepare("run", insertLockCategoriesQuery, [getHash(VIPLockUser), videoID, "intro", ""]);
|
||||
await db.prepare("run", insertLockCategoriesQuery, [getHash(VIPLockUser), videoID, "sponsor", "Custom Reason"]);
|
||||
await db.prepare("run", insertLockCategoriesQuery, [getHash(VIPLockUser), videoID, "intro", ""]);
|
||||
});
|
||||
|
||||
it("Should be able to submit with empty user-agent", (done) => {
|
||||
@@ -101,4 +101,4 @@ describe("postSkipSegments - userAgent", () => {
|
||||
})
|
||||
.catch(err => done(err));
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -23,7 +23,7 @@ describe("postSkipSegments Warnings", () => {
|
||||
data
|
||||
});
|
||||
|
||||
before(() => {
|
||||
before(async () => {
|
||||
const now = Date.now();
|
||||
|
||||
const warnVip01Hash = getHash("postSkipSegmentsWarnVIP");
|
||||
@@ -34,14 +34,14 @@ describe("postSkipSegments Warnings", () => {
|
||||
|
||||
const insertWarningQuery = 'INSERT INTO warnings ("userID", "issuerUserID", "enabled", "reason", "issueTime") VALUES(?, ?, ?, ?, ?)';
|
||||
// User 1 | 1 active | custom reason
|
||||
db.prepare("run", insertWarningQuery, [warnUser01Hash, warnVip01Hash, 1, reason01, now]);
|
||||
await db.prepare("run", insertWarningQuery, [warnUser01Hash, warnVip01Hash, 1, reason01, now]);
|
||||
// User 2 | 1 inactive | default reason
|
||||
db.prepare("run", insertWarningQuery, [warnUser02Hash, warnVip01Hash, 0, reason02, now]);
|
||||
await db.prepare("run", insertWarningQuery, [warnUser02Hash, warnVip01Hash, 0, reason02, now]);
|
||||
// User 3 | 1 inactive, 1 active | different reasons
|
||||
db.prepare("run", insertWarningQuery, [warnUser03Hash, warnVip01Hash, 0, reason01, now]);
|
||||
db.prepare("run", insertWarningQuery, [warnUser03Hash, warnVip01Hash, 1, reason03, now]);
|
||||
await db.prepare("run", insertWarningQuery, [warnUser03Hash, warnVip01Hash, 0, reason01, now]);
|
||||
await db.prepare("run", insertWarningQuery, [warnUser03Hash, warnVip01Hash, 1, reason03, now+1]);
|
||||
// User 4 | 1 active | default reason
|
||||
db.prepare("run", insertWarningQuery, [warnUser04Hash, warnVip01Hash, 1, reason02, now]);
|
||||
await db.prepare("run", insertWarningQuery, [warnUser04Hash, warnVip01Hash, 1, reason02, now]);
|
||||
});
|
||||
|
||||
it("Should be rejected with custom message if user has active warnings", (done) => {
|
||||
|
||||
Reference in New Issue
Block a user