Merge pull request #77 from ajayyy/testing

Update master
This commit is contained in:
Ajay Ramachandran 2020-04-24 13:53:17 -04:00 committed by GitHub
commit 74169e6caf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 42 additions and 9 deletions

View file

@ -101,13 +101,15 @@ async function autoModerateSubmission(submission, callback) {
} else {
// Check to see if video exists
if (data.pageInfo.totalResults === 0) {
callback("No video exists with id " + submission.videoID);
return "No video exists with id " + submission.videoID;
} else {
let duration = data.items[0].contentDetails.duration;
duration = isoDurations.toSeconds(isoDurations.parse(duration));
// Reject submission if over 80% of the video
if ((submission.endTime - submission.startTime) > (duration/100)*80) {
if (duration == 0) {
// Allow submission if the duration is 0 (bug in youtube api)
return false;
} else if ((submission.endTime - submission.startTime) > (duration/100)*80) {
// Reject submission if over 80% of the video
return "Sponsor segment is over 80% of the video.";
} else {
return false;

View file

@ -34,7 +34,7 @@ var mockServer = createMockServer(() => {
mocha.run(function(failures) {
mockServer.close();
server.close();
process.exitCode = failures ? 1 : 0; // exit with non-zero status if there were failures
process.exitCode = failures ? 1 : 0; // exit with non-zero status if there were failures
});
});
});

View file

@ -99,6 +99,16 @@ describe('postSkipSegments', () => {
else done("non 403 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()

View file

@ -4,11 +4,11 @@ var app = express();
var config = require('../src/config.js');
app.post('/ReportChannelWebhook', (req, res) => {
res.status(200);
res.sendStatus(200);
});
app.post('/FirstTimeSubmissionsWebhook', (req, res) => {
res.status(200);
res.sendStatus(200);
});
module.exports = function createMockServer(callback) {

View file

@ -10,14 +10,35 @@ YouTubeAPI.videos.list({
const YouTubeAPI = {
videos: {
list: (obj, callback) => {
if (obj.videoID === "knownWrongID") {
if (obj.id === "knownWrongID") {
callback(undefined, {
pageInfo: {
totalResults: 0
},
items: []
});
} else {
} if (obj.id === "noDuration") {
callback(undefined, {
pageInfo: {
totalResults: 1
},
items: [
{
contentDetails: {
duration: "PT0S"
},
snippet: {
title: "Example Title",
thumbnails: {
maxres: {
url: "https://sponsor.ajay.app/LogoSponsorBlockSimple256px.png"
}
}
}
}
]
});
} else {
callback(undefined, {
pageInfo: {
totalResults: 1