mirror of
https://github.com/ajayyy/SponsorBlockServer.git
synced 2025-12-12 22:47:12 +03:00
Merge remote-tracking branch 'upstream/master' into fix/prepare-statements
This commit is contained in:
@@ -118,7 +118,7 @@ describe('postSkipSegments', () => {
|
||||
.then(async res => {
|
||||
if (res.status === 200) {
|
||||
const row = await db.prepare('get', `SELECT "startTime", "endTime", "locked", "category", "videoDuration" FROM "sponsorTimes" WHERE "videoID" = ?`, ["dQw4w9WgXZX"]);
|
||||
if (row.startTime === 0 && row.endTime === 10 && row.locked === 0 && row.category === "sponsor" && row.videoDuration === 5010) {
|
||||
if (row.startTime === 0 && row.endTime === 10 && row.locked === 0 && row.category === "sponsor" && row.videoDuration === 4980) {
|
||||
done();
|
||||
} else {
|
||||
done("Submitted times were not saved. Actual submission: " + JSON.stringify(row));
|
||||
@@ -140,7 +140,7 @@ describe('postSkipSegments', () => {
|
||||
body: JSON.stringify({
|
||||
userID: "test",
|
||||
videoID: "dQw4w9WgXZH",
|
||||
videoDuration: 5010.20,
|
||||
videoDuration: 4980.20,
|
||||
segments: [{
|
||||
segment: [1, 10],
|
||||
category: "sponsor",
|
||||
@@ -150,7 +150,7 @@ describe('postSkipSegments', () => {
|
||||
.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) {
|
||||
if (row.startTime === 1 && row.endTime === 10 && row.locked === 0 && row.category === "sponsor" && row.videoDuration === 4980.20) {
|
||||
done();
|
||||
} else {
|
||||
done("Submitted times were not saved. Actual submission: " + JSON.stringify(row));
|
||||
@@ -237,6 +237,21 @@ describe('postSkipSegments', () => {
|
||||
}
|
||||
});
|
||||
|
||||
it('Should still not be allowed if youtube thinks duration is 0', (done: Done) => {
|
||||
fetch(getbaseURL()
|
||||
+ "/api/postVideoSponsorTimes?videoID=noDuration&startTime=30&endTime=10000&userID=testing", {
|
||||
method: 'POST',
|
||||
})
|
||||
.then(async res => {
|
||||
if (res.status === 403) done(); // pass
|
||||
else {
|
||||
const body = await res.text();
|
||||
done("non 403 status code: " + res.status + " (" + body + ")");
|
||||
}
|
||||
})
|
||||
.catch(err => done("Couldn't call endpoint"));
|
||||
});
|
||||
|
||||
it('Should be able to submit a single time under a different service (JSON method)', (done: Done) => {
|
||||
fetch(getbaseURL()
|
||||
+ "/api/postVideoSponsorTimes", {
|
||||
@@ -500,6 +515,51 @@ describe('postSkipSegments', () => {
|
||||
.catch(err => done("Couldn't call endpoint"));
|
||||
});
|
||||
|
||||
it('Should be rejected if segment starts and ends at the same time', (done: Done) => {
|
||||
fetch(getbaseURL()
|
||||
+ "/api/skipSegments?videoID=qqwerty&startTime=90&endTime=90&userID=testing&category=intro", {
|
||||
method: 'POST',
|
||||
})
|
||||
.then(async res => {
|
||||
if (res.status === 400) done(); // pass
|
||||
else {
|
||||
const body = await res.text();
|
||||
done("non 400 status code: " + res.status + " (" + body + ")");
|
||||
}
|
||||
})
|
||||
.catch(err => done("Couldn't call endpoint"));
|
||||
});
|
||||
|
||||
it('Should be accepted if highlight segment starts and ends at the same time', (done: Done) => {
|
||||
fetch(getbaseURL()
|
||||
+ "/api/skipSegments?videoID=qqwerty&startTime=30&endTime=30&userID=testing&category=highlight", {
|
||||
method: 'POST',
|
||||
})
|
||||
.then(async res => {
|
||||
if (res.status === 200) done(); // pass
|
||||
else {
|
||||
const body = await res.text();
|
||||
done("non 200 status code: " + res.status + " (" + body + ")");
|
||||
}
|
||||
})
|
||||
.catch(err => done("Couldn't call endpoint"));
|
||||
});
|
||||
|
||||
it('Should be rejected if highlight segment doesn\'t start and end at the same time', (done: Done) => {
|
||||
fetch(getbaseURL()
|
||||
+ "/api/skipSegments?videoID=qqwerty&startTime=30&endTime=30.5&userID=testing&category=highlight", {
|
||||
method: 'POST',
|
||||
})
|
||||
.then(async res => {
|
||||
if (res.status === 400) done(); // pass
|
||||
else {
|
||||
const body = await res.text();
|
||||
done("non 400 status code: " + res.status + " (" + body + ")");
|
||||
}
|
||||
})
|
||||
.catch(err => done("Couldn't call endpoint"));
|
||||
});
|
||||
|
||||
it('Should be rejected if a sponsor is less than 1 second', (done: Done) => {
|
||||
fetch(getbaseURL()
|
||||
+ "/api/skipSegments?videoID=qqwerty&startTime=30&endTime=30.5&userID=testing", {
|
||||
@@ -621,34 +681,6 @@ describe('postSkipSegments', () => {
|
||||
.catch(err => done(err));
|
||||
});
|
||||
|
||||
it('Should be allowed if youtube thinks duration is 0', (done: Done) => {
|
||||
fetch(getbaseURL()
|
||||
+ "/api/postVideoSponsorTimes?videoID=noDuration&startTime=30&endTime=10000&userID=testing", {
|
||||
method: 'POST',
|
||||
})
|
||||
.then(async res => {
|
||||
if (res.status === 200) done(); // pass
|
||||
else {
|
||||
const body = await res.text();
|
||||
done("non 200 status code: " + res.status + " (" + body + ")");
|
||||
}
|
||||
})
|
||||
.catch(err => done("Couldn't call endpoint"));
|
||||
});
|
||||
|
||||
it('Should be rejected if not a valid videoID', (done: Done) => {
|
||||
fetch(getbaseURL()
|
||||
+ "/api/postVideoSponsorTimes?videoID=knownWrongID&startTime=30&endTime=1000000&userID=testing")
|
||||
.then(async res => {
|
||||
if (res.status === 403) done(); // pass
|
||||
else {
|
||||
const body = await res.text();
|
||||
done("non 403 status code: " + res.status + " (" + body + ")");
|
||||
}
|
||||
})
|
||||
.catch(err => done("Couldn't call endpoint"));
|
||||
});
|
||||
|
||||
it('Should return 400 for missing params (Params method)', (done: Done) => {
|
||||
fetch(getbaseURL()
|
||||
+ "/api/postVideoSponsorTimes?startTime=9&endTime=10&userID=test", {
|
||||
|
||||
Reference in New Issue
Block a user