mirror of
https://github.com/ajayyy/SponsorBlockServer.git
synced 2024-11-10 01:02:30 +01:00
finish tests and remove extra console.logs
This commit is contained in:
parent
4ee35d3cd4
commit
d0deb6fe27
4 changed files with 36 additions and 10 deletions
|
@ -57,11 +57,10 @@ function getYouTubeVideoInfo(videoID: VideoID, ignoreCache = false): Promise<API
|
|||
}
|
||||
}
|
||||
|
||||
const videoDurationChanged = (segmentDuration: number, APIDuration: number) => APIDuration > 0 && Math.abs(APIDuration - segmentDuration) < 2;
|
||||
const videoDurationChanged = (segmentDuration: number, APIDuration: number) => (APIDuration > 0 && Math.abs(segmentDuration - APIDuration) > 2);
|
||||
|
||||
async function checkVideoDurationChange(UUID: SegmentUUID) {
|
||||
const { videoDuration, videoID, service } = await db.prepare("get", `select videoDuration, videoID, service from "sponsorTImes" where "UUID" = ?`, [UUID]);
|
||||
|
||||
const { videoDuration, videoID, service } = await db.prepare("get", `select videoDuration, videoID, service from "sponsorTimes" where "UUID" = ?`, [UUID]);
|
||||
let apiVideoInfo: APIVideoInfo = null;
|
||||
if (service == Service.YouTube) {
|
||||
// don't use cache since we have no information about the video length
|
||||
|
@ -70,7 +69,7 @@ async function checkVideoDurationChange(UUID: SegmentUUID) {
|
|||
const apiVideoDuration = apiVideoInfo?.data?.lengthSeconds as VideoDuration;
|
||||
if (videoDurationChanged(videoDuration, apiVideoDuration)) {
|
||||
Logger.info(`Video duration changed for ${videoID} from ${videoDuration} to ${apiVideoDuration}`);
|
||||
await db.prepare("run", `UPDATE "sponsorTimes" SET "videoDuration" = ?, WHERE "UUID" = ?`, [apiVideoDuration, UUID]);
|
||||
await db.prepare("run", `UPDATE "sponsorTimes" SET "videoDuration" = ? WHERE "UUID" = ?`, [apiVideoDuration, UUID]);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -463,7 +462,7 @@ export async function voteOnSponsorTime(req: Request, res: Response): Promise<Re
|
|||
await db.prepare("run", `UPDATE "sponsorTimes" SET "${columnName}" = "${columnName}" + ? WHERE "UUID" = ?`, [incrementAmount - oldIncrementAmount, UUID]);
|
||||
if (isVIP && incrementAmount > 0 && voteTypeEnum === voteTypes.normal) {
|
||||
// check for video duration change
|
||||
checkVideoDurationChange(UUID);
|
||||
await checkVideoDurationChange(UUID);
|
||||
// Unhide and Lock this submission
|
||||
await db.prepare("run", 'UPDATE "sponsorTimes" SET locked = 1, hidden = 0, "shadowHidden" = 0 WHERE "UUID" = ?', [UUID]);
|
||||
|
||||
|
|
|
@ -92,7 +92,6 @@ describe("setUsername", () => {
|
|||
it("Should be able to set username that has never been set", (done) => {
|
||||
postSetUserName(user00PrivateUserID, username00)
|
||||
.then(async res => {
|
||||
console.log(res.data);
|
||||
const usernameInfo = await getUsernameInfo(getHash(user00PrivateUserID));
|
||||
assert.strictEqual(res.status, 200);
|
||||
assert.strictEqual(usernameInfo.userName, username00);
|
||||
|
|
|
@ -56,6 +56,7 @@ describe("voteOnSponsorTime", () => {
|
|||
await db.prepare("run", insertSponsorTimeQuery, ["category-change-test-1", 8, 12, 0, 1, "category-change-uuid-6", categoryChangeUserHash, 0, 50, "intro", 0, 0]);
|
||||
await db.prepare("run", insertSponsorTimeQuery, ["category-change-test-1", 9, 14, 0, 0, "category-change-uuid-7", categoryChangeUserHash, 0, 50, "intro", 0, 0]);
|
||||
await db.prepare("run", insertSponsorTimeQuery, ["category-change-test-1", 7, 12, 0, 1, "category-change-uuid-8", categoryChangeUserHash, 0, 50, "intro", 0, 0]);
|
||||
await db.prepare("run", insertSponsorTimeQuery, ["duration-update", 1, 10, 0, 0, "duration-update-uuid-1", "testman", 0, 0, "intro", 0, 0]);
|
||||
|
||||
const insertWarningQuery = 'INSERT INTO "warnings" ("userID", "issueTime", "issuerUserID", "enabled") VALUES(?, ?, ?, ?)';
|
||||
await db.prepare("run", insertWarningQuery, [warnUser01Hash, now, warnVip01Hash, 1]);
|
||||
|
@ -98,6 +99,7 @@ describe("voteOnSponsorTime", () => {
|
|||
|
||||
const getSegmentVotes = (UUID: string) => db.prepare("get", `SELECT "votes" FROM "sponsorTimes" WHERE "UUID" = ?`, [UUID]);
|
||||
const getSegmentCategory = (UUID: string) => db.prepare("get", `SELECT "category" FROM "sponsorTimes" WHERE "UUID" = ?`, [UUID]);
|
||||
const getVideoDuration = (UUID: string) => db.prepare("get", `SELECT "videoDuration" FROM "sponsorTimes" WHERE "UUID" = ?`, [UUID]).then(row => row.videoDuration);
|
||||
|
||||
it("Should be able to upvote a segment", (done) => {
|
||||
const UUID = "vote-uuid-0";
|
||||
|
@ -299,7 +301,6 @@ describe("voteOnSponsorTime", () => {
|
|||
.then(async res => {
|
||||
assert.strictEqual(res.status, 200);
|
||||
const row = await getSegmentCategory(UUID);
|
||||
console.log(row.category);
|
||||
assert.strictEqual(row.category, category);
|
||||
done();
|
||||
})
|
||||
|
@ -314,7 +315,6 @@ describe("voteOnSponsorTime", () => {
|
|||
.then(async res => {
|
||||
assert.strictEqual(res.status, 200);
|
||||
const row = await getSegmentCategory(UUID);
|
||||
console.log(row.category);
|
||||
assert.strictEqual(row.category, "intro");
|
||||
done();
|
||||
})
|
||||
|
@ -348,7 +348,7 @@ describe("voteOnSponsorTime", () => {
|
|||
})
|
||||
.catch(err => done(err));
|
||||
});
|
||||
|
||||
|
||||
it("Vip should be able to vote for a category and it should immediately change (segment unlocked, nextCatgeory unlocked, Vip)", (done) => {
|
||||
const userID = vipUser;
|
||||
const UUID = "category-change-uuid-5";
|
||||
|
@ -404,7 +404,7 @@ describe("voteOnSponsorTime", () => {
|
|||
})
|
||||
.catch(err => done(err));
|
||||
});
|
||||
|
||||
|
||||
it("Should not be able to category-vote on an invalid UUID submission", (done) => {
|
||||
const UUID = "invalid-uuid";
|
||||
postVoteCategory("randomID3", UUID, "intro")
|
||||
|
@ -564,4 +564,15 @@ describe("voteOnSponsorTime", () => {
|
|||
})
|
||||
.catch(err => done(err));
|
||||
});
|
||||
|
||||
it("Should be able to update stored videoDuration with VIP upvote", (done) => {
|
||||
const UUID = "duration-update-uuid-1";
|
||||
postVote(vipUser, UUID, 1)
|
||||
.then(async res => {
|
||||
assert.strictEqual(res.status, 200);
|
||||
const newDuration = await getVideoDuration(UUID);
|
||||
assert.strictEqual(newDuration, 500);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -30,6 +30,23 @@ export class YouTubeApiMock {
|
|||
]
|
||||
} as APIVideoData
|
||||
};
|
||||
} else if (obj.id === "duration-update") {
|
||||
return {
|
||||
err: null,
|
||||
data: {
|
||||
title: "Example Title",
|
||||
lengthSeconds: 500,
|
||||
videoThumbnails: [
|
||||
{
|
||||
quality: "maxres",
|
||||
url: "https://sponsor.ajay.app/LogoSponsorBlockSimple256px.png",
|
||||
second__originalUrl:"https://sponsor.ajay.app/LogoSponsorBlockSimple256px.png",
|
||||
width: 1280,
|
||||
height: 720
|
||||
},
|
||||
]
|
||||
} as APIVideoData
|
||||
};
|
||||
} else {
|
||||
return {
|
||||
err: null,
|
||||
|
|
Loading…
Reference in a new issue