mirror of
https://github.com/ajayyy/SponsorBlockServer.git
synced 2025-12-18 05:28:27 +03:00
Merge branch 'master' of https://github.com/ajayyy/SponsorBlockServer into testing
# Conflicts: # src/routes/postSkipSegments.js # test/cases/voteOnSponsorTime.js
This commit is contained in:
@@ -8,8 +8,8 @@ var db = databases.db;
|
||||
|
||||
describe('postSkipSegments', () => {
|
||||
it('Should be able to submit a single time (Params method)', (done) => {
|
||||
request.post(utils.getbaseURL()
|
||||
+ "/api/postVideoSponsorTimes?videoID=dQw4w9WgXcR&startTime=2&endTime=10&userID=test&category=sponsor", null,
|
||||
request.post(utils.getbaseURL()
|
||||
+ "/api/postVideoSponsorTimes?videoID=dQw4w9WgXcR&startTime=2&endTime=10&userID=test&category=sponsor", null,
|
||||
(err, res, body) => {
|
||||
if (err) done(err);
|
||||
else if (res.statusCode === 200) {
|
||||
@@ -26,7 +26,7 @@ describe('postSkipSegments', () => {
|
||||
});
|
||||
|
||||
it('Should be able to submit a single time (JSON method)', (done) => {
|
||||
request.post(utils.getbaseURL()
|
||||
request.post(utils.getbaseURL()
|
||||
+ "/api/postVideoSponsorTimes", {
|
||||
json: {
|
||||
userID: "test",
|
||||
@@ -36,7 +36,7 @@ describe('postSkipSegments', () => {
|
||||
category: "sponsor"
|
||||
}]
|
||||
}
|
||||
},
|
||||
},
|
||||
(err, res, body) => {
|
||||
if (err) done(err);
|
||||
else if (res.statusCode === 200) {
|
||||
@@ -53,7 +53,7 @@ describe('postSkipSegments', () => {
|
||||
});
|
||||
|
||||
it('Should be able to submit multiple times (JSON method)', (done) => {
|
||||
request.post(utils.getbaseURL()
|
||||
request.post(utils.getbaseURL()
|
||||
+ "/api/postVideoSponsorTimes", {
|
||||
json: {
|
||||
userID: "test",
|
||||
@@ -66,7 +66,7 @@ describe('postSkipSegments', () => {
|
||||
category: "intro"
|
||||
}]
|
||||
}
|
||||
},
|
||||
},
|
||||
(err, res, body) => {
|
||||
if (err) done(err);
|
||||
else if (res.statusCode === 200) {
|
||||
@@ -88,11 +88,11 @@ describe('postSkipSegments', () => {
|
||||
done("Status code was " + res.statusCode);
|
||||
}
|
||||
});
|
||||
});
|
||||
}).timeout(5000);
|
||||
|
||||
it('Should be accepted if a non-sponsor is less than 1 second', (done) => {
|
||||
request.post(utils.getbaseURL()
|
||||
+ "/api/skipSegments?videoID=qqwerty&startTime=30&endTime=30.5&userID=testing&category=intro", null,
|
||||
request.post(utils.getbaseURL()
|
||||
+ "/api/skipSegments?videoID=qqwerty&startTime=30&endTime=30.5&userID=testing&category=intro", null,
|
||||
(err, res, body) => {
|
||||
if (err) done("Couldn't call endpoint");
|
||||
else if (res.statusCode === 200) done(); // pass
|
||||
@@ -101,8 +101,8 @@ describe('postSkipSegments', () => {
|
||||
});
|
||||
|
||||
it('Should be rejected if a sponsor is less than 1 second', (done) => {
|
||||
request.post(utils.getbaseURL()
|
||||
+ "/api/skipSegments?videoID=qqwerty&startTime=30&endTime=30.5&userID=testing", null,
|
||||
request.post(utils.getbaseURL()
|
||||
+ "/api/skipSegments?videoID=qqwerty&startTime=30&endTime=30.5&userID=testing", null,
|
||||
(err, res, body) => {
|
||||
if (err) done("Couldn't call endpoint");
|
||||
else if (res.statusCode === 400) done(); // pass
|
||||
@@ -111,8 +111,8 @@ describe('postSkipSegments', () => {
|
||||
});
|
||||
|
||||
it('Should be rejected if over 80% of the video', (done) => {
|
||||
request.get(utils.getbaseURL()
|
||||
+ "/api/postVideoSponsorTimes?videoID=qqwerty&startTime=30&endTime=1000000&userID=testing", null,
|
||||
request.get(utils.getbaseURL()
|
||||
+ "/api/postVideoSponsorTimes?videoID=qqwerty&startTime=30&endTime=1000000&userID=testing", null,
|
||||
(err, res, body) => {
|
||||
if (err) done("Couldn't call endpoint");
|
||||
else if (res.statusCode === 403) done(); // pass
|
||||
@@ -120,19 +120,29 @@ describe('postSkipSegments', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('Should be allowed if youtube thinks duration is 0', (done) => {
|
||||
request.get(utils.getbaseURL()
|
||||
+ "/api/postVideoSponsorTimes?videoID=noDuration&startTime=30&endTime=10000&userID=testing", null,
|
||||
it("Should be rejected if NB's predicted probability is <70%.", (done) => {
|
||||
request.get(utils.getbaseURL()
|
||||
+ "/api/postVideoSponsorTimes?videoID=LevkAjUE6d4&startTime=40&endTime=60&userID=testing", null,
|
||||
(err, res, body) => {
|
||||
if (err) done("Couldn't call endpoint");
|
||||
else if (res.statusCode === 200) done(); // pass
|
||||
else done("non 200 status code: " + res.statusCode + " ("+body+")");
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
it('Should be allowed if youtube thinks duration is 0', (done) => {
|
||||
request.get(utils.getbaseURL()
|
||||
+ "/api/postVideoSponsorTimes?videoID=noDuration&startTime=30&endTime=10000&userID=testing", null,
|
||||
(err, res, body) => {
|
||||
if (err) done("Couldn't call endpoint");
|
||||
else if (res.statusCode === 200) done(); // pass
|
||||
else done("non 200 status code: " + res.statusCode + " ("+body+")");
|
||||
});
|
||||
});
|
||||
|
||||
it('Should be rejected if not a valid videoID', (done) => {
|
||||
request.get(utils.getbaseURL()
|
||||
+ "/api/postVideoSponsorTimes?videoID=knownWrongID&startTime=30&endTime=1000000&userID=testing", null,
|
||||
request.get(utils.getbaseURL()
|
||||
+ "/api/postVideoSponsorTimes?videoID=knownWrongID&startTime=30&endTime=1000000&userID=testing", null,
|
||||
(err, res, body) => {
|
||||
if (err) done("Couldn't call endpoint");
|
||||
else if (res.statusCode === 403) done(); // pass
|
||||
@@ -141,8 +151,8 @@ describe('postSkipSegments', () => {
|
||||
});
|
||||
|
||||
it('Should return 400 for missing params (Params method)', (done) => {
|
||||
request.post(utils.getbaseURL()
|
||||
+ "/api/postVideoSponsorTimes?startTime=9&endTime=10&userID=test", null,
|
||||
request.post(utils.getbaseURL()
|
||||
+ "/api/postVideoSponsorTimes?startTime=9&endTime=10&userID=test", null,
|
||||
(err, res, body) => {
|
||||
if (err) done(true);
|
||||
if (res.statusCode === 400) done();
|
||||
@@ -151,7 +161,7 @@ describe('postSkipSegments', () => {
|
||||
});
|
||||
|
||||
it('Should return 400 for missing params (JSON method) 1', (done) => {
|
||||
request.post(utils.getbaseURL()
|
||||
request.post(utils.getbaseURL()
|
||||
+ "/api/postVideoSponsorTimes", {
|
||||
json: {
|
||||
userID: "test",
|
||||
@@ -163,7 +173,7 @@ describe('postSkipSegments', () => {
|
||||
category: "intro"
|
||||
}]
|
||||
}
|
||||
},
|
||||
},
|
||||
(err, res, body) => {
|
||||
if (err) done(true);
|
||||
else if (res.statusCode === 400) done();
|
||||
@@ -171,13 +181,13 @@ describe('postSkipSegments', () => {
|
||||
});
|
||||
});
|
||||
it('Should return 400 for missing params (JSON method) 2', (done) => {
|
||||
request.post(utils.getbaseURL()
|
||||
request.post(utils.getbaseURL()
|
||||
+ "/api/postVideoSponsorTimes", {
|
||||
json: {
|
||||
userID: "test",
|
||||
videoID: "dQw4w9WgXcQ"
|
||||
}
|
||||
},
|
||||
},
|
||||
(err, res, body) => {
|
||||
if (err) done(true);
|
||||
else if (res.statusCode === 400) done();
|
||||
@@ -185,7 +195,7 @@ describe('postSkipSegments', () => {
|
||||
});
|
||||
});
|
||||
it('Should return 400 for missing params (JSON method) 3', (done) => {
|
||||
request.post(utils.getbaseURL()
|
||||
request.post(utils.getbaseURL()
|
||||
+ "/api/postVideoSponsorTimes", {
|
||||
json: {
|
||||
userID: "test",
|
||||
@@ -198,7 +208,7 @@ describe('postSkipSegments', () => {
|
||||
category: "intro"
|
||||
}]
|
||||
}
|
||||
},
|
||||
},
|
||||
(err, res, body) => {
|
||||
if (err) done(true);
|
||||
else if (res.statusCode === 400) done();
|
||||
@@ -206,7 +216,7 @@ describe('postSkipSegments', () => {
|
||||
});
|
||||
});
|
||||
it('Should return 400 for missing params (JSON method) 4', (done) => {
|
||||
request.post(utils.getbaseURL()
|
||||
request.post(utils.getbaseURL()
|
||||
+ "/api/postVideoSponsorTimes", {
|
||||
json: {
|
||||
userID: "test",
|
||||
@@ -218,7 +228,7 @@ describe('postSkipSegments', () => {
|
||||
category: "intro"
|
||||
}]
|
||||
}
|
||||
},
|
||||
},
|
||||
(err, res, body) => {
|
||||
if (err) done(true);
|
||||
else if (res.statusCode === 400) done();
|
||||
@@ -226,17 +236,17 @@ describe('postSkipSegments', () => {
|
||||
});
|
||||
});
|
||||
it('Should return 400 for missing params (JSON method) 5', (done) => {
|
||||
request.post(utils.getbaseURL()
|
||||
request.post(utils.getbaseURL()
|
||||
+ "/api/postVideoSponsorTimes", {
|
||||
json: {
|
||||
userID: "test",
|
||||
videoID: "dQw4w9WgXcQ"
|
||||
}
|
||||
},
|
||||
},
|
||||
(err, res, body) => {
|
||||
if (err) done(true);
|
||||
else if (res.statusCode === 400) done();
|
||||
else done(true);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -6,22 +6,25 @@ const getHash = require('../../src/utils/getHash.js');
|
||||
describe('voteOnSponsorTime', () => {
|
||||
before(() => {
|
||||
let startOfQuery = "INSERT INTO sponsorTimes (videoID, startTime, endTime, votes, UUID, userID, timeSubmitted, views, category, shadowHidden, hashedVideoID) VALUES";
|
||||
db.exec(startOfQuery + "('vote-testtesttest', 1, 11, 2, 'vote-uuid-0', 'testman', 0, 50, 'sponsor', 0, '"+getHash('vote-testtesttest', 1)+"')");
|
||||
db.exec(startOfQuery + "('vote-testtesttest2', 1, 11, 2, 'vote-uuid-1', 'testman', 0, 50, 'sponsor', 0, '"+getHash('vote-testtesttest2', 1)+"')");
|
||||
db.exec(startOfQuery + "('vote-testtesttest2', 1, 11, 10, 'vote-uuid-1.5', 'testman', 0, 50, 'outro', 0, '"+getHash('vote-testtesttest2', 1)+"')");
|
||||
db.exec(startOfQuery + "('vote-testtesttest2', 1, 11, 10, 'vote-uuid-1.6', 'testman', 0, 50, 'interaction', 0, '"+getHash('vote-testtesttest2', 1)+"')");
|
||||
db.exec(startOfQuery + "('vote-testtesttest3', 20, 33, 10, 'vote-uuid-2', 'testman', 0, 50, 'intro', 0, '"+getHash('vote-testtesttest3', 1)+"')");
|
||||
db.exec(startOfQuery + "('vote-testtesttest,test', 1, 11, 100, 'vote-uuid-3', 'testman', 0, 50, 'sponsor', 0, '"+getHash('vote-testtesttest,test', 1)+"')");
|
||||
db.exec(startOfQuery + "('vote-test3', 1, 11, 2, 'vote-uuid-4', 'testman', 0, 50, 'sponsor', 0, '"+getHash('vote-test3', 1)+"')");
|
||||
db.exec(startOfQuery + "('vote-test3', 7, 22, -3, 'vote-uuid-5', 'testman', 0, 50, 'intro', 0, '"+getHash('vote-test3', 1)+"')");
|
||||
db.exec(startOfQuery + "('vote-multiple', 1, 11, 2, 'vote-uuid-6', 'testman', 0, 50, 'intro', 0, '"+getHash('vote-multiple', 1)+"')");
|
||||
db.exec(startOfQuery + "('vote-multiple', 20, 33, 2, 'vote-uuid-7', 'testman', 0, 50, 'intro', 0, '"+getHash('vote-multiple', 1)+"')");
|
||||
db.exec(startOfQuery + "('voter-submitter', 1, 11, 2, 'vote-uuid-8', '" + getHash("randomID") + "', 0, 50, 'sponsor', 0, '"+getHash('voter-submitter', 1)+"')");
|
||||
db.exec(startOfQuery + "('voter-submitter2', 1, 11, 2, 'vote-uuid-9', '" + getHash("randomID2") + "', 0, 50, 'sponsor', 0, '"+getHash('voter-submitter2', 1)+"')");
|
||||
db.exec(startOfQuery + "('voter-submitter2', 1, 11, 2, 'vote-uuid-10', '" + getHash("randomID3") + "', 0, 50, 'sponsor', 0, '"+getHash('voter-submitter2', 1)+"')");
|
||||
db.exec(startOfQuery + "('voter-submitter2', 1, 11, 2, 'vote-uuid-11', '" + getHash("randomID4") + "', 0, 50, 'sponsor', 0, '"+getHash('voter-submitter2', 1)+"')");
|
||||
db.exec(startOfQuery + "('own-submission-video', 1, 11, 500, 'own-submission-uuid', '"+ getHash('own-submission-id') +"', 0, 50, 'sponsor', 0, '"+getHash('own-submission-video', 1)+"')");
|
||||
db.exec(startOfQuery + "('not-own-submission-video', 1, 11, 500, 'not-own-submission-uuid', '"+ getHash('somebody-else-id') +"', 0, 50, 'sponsor', 0, '"+getHash('not-own-submission-video', 1)+"')");
|
||||
|
||||
db.exec(startOfQuery + "('vote-testtesttest', 1, 11, 2, 'vote-uuid-0', 'testman', 0, 50, 'sponsor', 0, '" + getHash('vote-testtesttest', 1) + "')");
|
||||
db.exec(startOfQuery + "('vote-testtesttest2', 1, 11, 2, 'vote-uuid-1', 'testman', 0, 50, 'sponsor', 0, '" + getHash('vote-testtesttest2', 1) + "')");
|
||||
db.exec(startOfQuery + "('vote-testtesttest2', 1, 11, 10, 'vote-uuid-1.5', 'testman', 0, 50, 'outro', 0, '" + getHash('vote-testtesttest2', 1) + "')");
|
||||
db.exec(startOfQuery + "('vote-testtesttest2', 1, 11, 10, 'vote-uuid-1.6', 'testman', 0, 50, 'interaction', 0, '" + getHash('vote-testtesttest2', 1) + "')");
|
||||
db.exec(startOfQuery + "('vote-testtesttest3', 20, 33, 10, 'vote-uuid-2', 'testman', 0, 50, 'intro', 0, '" + getHash('vote-testtesttest3', 1) + "')");
|
||||
db.exec(startOfQuery + "('vote-testtesttest,test', 1, 11, 100, 'vote-uuid-3', 'testman', 0, 50, 'sponsor', 0, '" + getHash('vote-testtesttest,test', 1) + "')");
|
||||
db.exec(startOfQuery + "('vote-test3', 1, 11, 2, 'vote-uuid-4', 'testman', 0, 50, 'sponsor', 0, '" + getHash('vote-test3', 1) + "')");
|
||||
db.exec(startOfQuery + "('vote-test3', 7, 22, -3, 'vote-uuid-5', 'testman', 0, 50, 'intro', 0, '" + getHash('vote-test3', 1) + "')");
|
||||
db.exec(startOfQuery + "('vote-multiple', 1, 11, 2, 'vote-uuid-6', 'testman', 0, 50, 'intro', 0, '" + getHash('vote-multiple', 1) + "')");
|
||||
db.exec(startOfQuery + "('vote-multiple', 20, 33, 2, 'vote-uuid-7', 'testman', 0, 50, 'intro', 0, '" + getHash('vote-multiple', 1) + "')");
|
||||
db.exec(startOfQuery + "('voter-submitter', 1, 11, 2, 'vote-uuid-8', '" + getHash("randomID") + "', 0, 50, 'sponsor', 0, '" + getHash('voter-submitter', 1) + "')");
|
||||
db.exec(startOfQuery + "('voter-submitter2', 1, 11, 2, 'vote-uuid-9', '" + getHash("randomID2") + "', 0, 50, 'sponsor', 0, '" + getHash('voter-submitter2', 1) + "')");
|
||||
db.exec(startOfQuery + "('voter-submitter2', 1, 11, 2, 'vote-uuid-10', '" + getHash("randomID3") + "', 0, 50, 'sponsor', 0, '" + getHash('voter-submitter2', 1) + "')");
|
||||
db.exec(startOfQuery + "('voter-submitter2', 1, 11, 2, 'vote-uuid-11', '" + getHash("randomID4") + "', 0, 50, 'sponsor', 0, '" + getHash('voter-submitter2', 1) + "')");
|
||||
db.exec(startOfQuery + "('own-submission-video', 1, 11, 500, 'own-submission-uuid', '"+ getHash('own-submission-id') +"', 0, 50, 'sponsor', 0, '" + getHash('own-submission-video', 1) + "')");
|
||||
db.exec(startOfQuery + "('not-own-submission-video', 1, 11, 500, 'not-own-submission-uuid', '"+ getHash('somebody-else-id') +"', 0, 50, 'sponsor', 0, '" + getHash('not-own-submission-video', 1) + "')");
|
||||
db.exec(startOfQuery + "('incorrect-category', 1, 11, 500, 'incorrect-category', '"+ getHash('somebody-else-id') +"', 0, 50, 'sponsor', 0, '" + getHash('incorrect-category', 1) + "')");
|
||||
db.exec(startOfQuery + "('incorrect-category-change', 1, 11, 500, 'incorrect-category-change', '"+ getHash('somebody-else-id') +"', 0, 50, 'sponsor', 0, '" + getHash('incorrect-category-change', 1) + "')");
|
||||
|
||||
db.exec("INSERT INTO vipUsers (userID) VALUES ('" + getHash("VIPUser") + "')");
|
||||
privateDB.exec("INSERT INTO shadowBannedUsers (userID) VALUES ('" + getHash("randomID4") + "')");
|
||||
@@ -207,6 +210,24 @@ describe('voteOnSponsorTime', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('Should not able to change to an invalid category', (done) => {
|
||||
request.get(utils.getbaseURL()
|
||||
+ "/api/voteOnSponsorTime?userID=randomID2&UUID=incorrect-category&category=fakecategory", null,
|
||||
(err, res, body) => {
|
||||
if (err) done(err);
|
||||
else if (res.statusCode === 400) {
|
||||
let row = db.prepare('get', "SELECT category FROM sponsorTimes WHERE UUID = ?", ["incorrect-category"]);
|
||||
if (row.category === "sponsor") {
|
||||
done()
|
||||
} else {
|
||||
done("Vote did not succeed. Submission went from sponsor to " + row.category);
|
||||
}
|
||||
} else {
|
||||
done("Status code was " + res.statusCode);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
it('Should be able to change your vote for a category and it should immediately change (for now)', (done) => {
|
||||
request.get(utils.getbaseURL()
|
||||
+ "/api/voteOnSponsorTime?userID=randomID2&UUID=vote-uuid-4&category=outro", null,
|
||||
@@ -225,6 +246,29 @@ describe('voteOnSponsorTime', () => {
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
it('Should not be able to change your vote to an invalid category', (done) => {
|
||||
const vote = (inputCat, assertCat, callback) => {
|
||||
request.get(utils.getbaseURL()
|
||||
+ "/api/voteOnSponsorTime?userID=randomID2&UUID=incorrect-category-change&category="+inputCat, null,
|
||||
(err) => {
|
||||
if (err) done(err);
|
||||
else{
|
||||
let row = db.prepare('get', "SELECT category FROM sponsorTimes WHERE UUID = ?", ["incorrect-category-change"]);
|
||||
if (row.category === assertCat) {
|
||||
callback();
|
||||
} else {
|
||||
done("Vote did not succeed. Submission went from sponsor to " + row.category);
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
vote("sponsor", "sponsor", () => {
|
||||
vote("fakeCategory", "sponsor", done);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
it('VIP should be able to vote for a category and it should immediately change', (done) => {
|
||||
request.get(utils.getbaseURL()
|
||||
+ "/api/voteOnSponsorTime?userID=VIPUser&UUID=vote-uuid-5&category=outro", null,
|
||||
|
||||
Reference in New Issue
Block a user