mirror of
https://github.com/ajayyy/SponsorBlockServer.git
synced 2025-12-12 14:37:17 +03:00
Fixed tests
This commit is contained in:
@@ -424,9 +424,9 @@ export async function postSkipSegments(req: Request, res: Response) {
|
|||||||
apiVideoInfo = await getYouTubeVideoInfo(videoID);
|
apiVideoInfo = await getYouTubeVideoInfo(videoID);
|
||||||
}
|
}
|
||||||
const apiVideoDuration = getYouTubeVideoDuration(apiVideoInfo);
|
const apiVideoDuration = getYouTubeVideoDuration(apiVideoInfo);
|
||||||
if (!apiVideoDuration || Math.abs(videoDuration - apiVideoDuration) > 2) {
|
if (!videoDuration || (apiVideoDuration && Math.abs(videoDuration - apiVideoDuration) > 2)) {
|
||||||
// If api duration is far off, take that one instead (it is only precise to seconds, not millis)
|
// If api duration is far off, take that one instead (it is only precise to seconds, not millis)
|
||||||
videoDuration = apiVideoDuration;
|
videoDuration = apiVideoDuration || 0 as VideoDuration;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Auto moderator check
|
// Auto moderator check
|
||||||
|
|||||||
@@ -97,7 +97,7 @@ describe('postSkipSegments', () => {
|
|||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Should be able to submit a single time with a duration (JSON method)', (done: Done) => {
|
it('Should be able to submit a single time with a duration from the YouTube API (JSON method)', (done: Done) => {
|
||||||
fetch(getbaseURL()
|
fetch(getbaseURL()
|
||||||
+ "/api/postVideoSponsorTimes", {
|
+ "/api/postVideoSponsorTimes", {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
@@ -129,7 +129,39 @@ describe('postSkipSegments', () => {
|
|||||||
.catch(err => done(err));
|
.catch(err => done(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Should be able to submit a single time with a duration from the API (JSON method)', (done: Done) => {
|
it('Should be able to submit a single time with a precise duration close to the one from the YouTube API (JSON method)', (done: Done) => {
|
||||||
|
fetch(getbaseURL()
|
||||||
|
+ "/api/postVideoSponsorTimes", {
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
},
|
||||||
|
body: JSON.stringify({
|
||||||
|
userID: "test",
|
||||||
|
videoID: "dQw4w9WgXZH",
|
||||||
|
videoDuration: 5010.20,
|
||||||
|
segments: [{
|
||||||
|
segment: [1, 10],
|
||||||
|
category: "sponsor",
|
||||||
|
}],
|
||||||
|
}),
|
||||||
|
})
|
||||||
|
.then(async res => {
|
||||||
|
if (res.status === 200) {
|
||||||
|
const row = await db.prepare('get', `SELECT "startTime", "endTime", "locked", "category", "videoDuration" FROM "sponsorTimes" WHERE "videoID" = ?`, ["dQw4w9WgXZH"]);
|
||||||
|
if (row.startTime === 1 && row.endTime === 10 && row.locked === 0 && row.category === "sponsor" && row.videoDuration === 5010.20) {
|
||||||
|
done();
|
||||||
|
} else {
|
||||||
|
done("Submitted times were not saved. Actual submission: " + JSON.stringify(row));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
done("Status code was " + res.status);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch(err => done(err));
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Should be able to submit a single time with a duration in the body (JSON method)', (done: Done) => {
|
||||||
fetch(getbaseURL()
|
fetch(getbaseURL()
|
||||||
+ "/api/postVideoSponsorTimes", {
|
+ "/api/postVideoSponsorTimes", {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
|
|||||||
Reference in New Issue
Block a user