mirror of
https://github.com/ajayyy/SponsorBlockServer.git
synced 2025-12-20 22:48:33 +03:00
Fix test cases
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import request from 'request';
|
||||
import fetch from 'node-fetch';
|
||||
import {config} from '../../src/config';
|
||||
import {db, privateDB} from '../../src/databases/databases';
|
||||
import {Done, getbaseURL} from '../utils';
|
||||
@@ -63,251 +63,249 @@ describe('voteOnSponsorTime', () => {
|
||||
});
|
||||
|
||||
it('Should be able to upvote a segment', (done: Done) => {
|
||||
request.get(getbaseURL()
|
||||
+ "/api/voteOnSponsorTime?userID=randomID&UUID=vote-uuid-0&type=1", null,
|
||||
(err, res) => {
|
||||
if (err) done(err);
|
||||
else if (res.statusCode === 200) {
|
||||
let row = db.prepare('get', "SELECT votes FROM sponsorTimes WHERE UUID = ?", ["vote-uuid-0"]);
|
||||
if (row.votes === 3) {
|
||||
done();
|
||||
} else {
|
||||
done("Vote did not succeed. Submission went from 2 votes to " + row.votes);
|
||||
}
|
||||
fetch(getbaseURL()
|
||||
+ "/api/voteOnSponsorTime?userID=randomID&UUID=vote-uuid-0&type=1")
|
||||
.then(res => {
|
||||
if (res.status === 200) {
|
||||
let row = db.prepare('get', "SELECT votes FROM sponsorTimes WHERE UUID = ?", ["vote-uuid-0"]);
|
||||
if (row.votes === 3) {
|
||||
done();
|
||||
} else {
|
||||
done("Status code was " + res.statusCode);
|
||||
done("Vote did not succeed. Submission went from 2 votes to " + row.votes);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
done("Status code was " + res.status);
|
||||
}
|
||||
})
|
||||
.catch(err => done(err));
|
||||
});
|
||||
|
||||
it('Should be able to downvote a segment', (done: Done) => {
|
||||
request.get(getbaseURL()
|
||||
+ "/api/voteOnSponsorTime?userID=randomID2&UUID=vote-uuid-2&type=0", null,
|
||||
(err, res) => {
|
||||
if (err) done(err);
|
||||
else if (res.statusCode === 200) {
|
||||
let row = db.prepare('get', "SELECT votes FROM sponsorTimes WHERE UUID = ?", ["vote-uuid-2"]);
|
||||
if (row.votes < 10) {
|
||||
done();
|
||||
} else {
|
||||
done("Vote did not succeed. Submission went from 10 votes to " + row.votes);
|
||||
}
|
||||
fetch(getbaseURL()
|
||||
+ "/api/voteOnSponsorTime?userID=randomID2&UUID=vote-uuid-2&type=0")
|
||||
.then(res => {
|
||||
if (res.status === 200) {
|
||||
let row = db.prepare('get', "SELECT votes FROM sponsorTimes WHERE UUID = ?", ["vote-uuid-2"]);
|
||||
if (row.votes < 10) {
|
||||
done();
|
||||
} else {
|
||||
done("Status code was " + res.statusCode);
|
||||
done("Vote did not succeed. Submission went from 10 votes to " + row.votes);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
done("Status code was " + res.status);
|
||||
}
|
||||
})
|
||||
.catch(err => done(err));
|
||||
});
|
||||
|
||||
it('Should not be able to downvote the same segment when voting from a different user on the same IP', (done: Done) => {
|
||||
request.get(getbaseURL()
|
||||
+ "/api/voteOnSponsorTime?userID=randomID3&UUID=vote-uuid-2&type=0", null,
|
||||
(err, res) => {
|
||||
if (err) done(err);
|
||||
else if (res.statusCode === 200) {
|
||||
let row = db.prepare('get', "SELECT votes FROM sponsorTimes WHERE UUID = ?", ["vote-uuid-2"]);
|
||||
if (row.votes === 9) {
|
||||
done();
|
||||
} else {
|
||||
done("Vote did not fail. Submission went from 9 votes to " + row.votes);
|
||||
}
|
||||
fetch(getbaseURL()
|
||||
+ "/api/voteOnSponsorTime?userID=randomID3&UUID=vote-uuid-2&type=0")
|
||||
.then(res => {
|
||||
if (res.status === 200) {
|
||||
let row = db.prepare('get', "SELECT votes FROM sponsorTimes WHERE UUID = ?", ["vote-uuid-2"]);
|
||||
if (row.votes === 9) {
|
||||
done();
|
||||
} else {
|
||||
done("Status code was " + res.statusCode);
|
||||
done("Vote did not fail. Submission went from 9 votes to " + row.votes);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
done("Status code was " + res.status);
|
||||
}
|
||||
})
|
||||
.catch(err => done(err));
|
||||
});
|
||||
|
||||
it("Should not be able to downvote a segment if the user is shadow banned", (done: Done) => {
|
||||
request.get(getbaseURL()
|
||||
+ "/api/voteOnSponsorTime?userID=randomID4&UUID=vote-uuid-1.6&type=0", null,
|
||||
(err, res) => {
|
||||
if (err) done(err);
|
||||
else if (res.statusCode === 200) {
|
||||
let row = db.prepare('get', "SELECT votes FROM sponsorTimes WHERE UUID = ?", ["vote-uuid-1.6"]);
|
||||
if (row.votes === 10) {
|
||||
done();
|
||||
} else {
|
||||
done("Vote did not fail. Submission went from 10 votes to " + row.votes);
|
||||
}
|
||||
fetch(getbaseURL()
|
||||
+ "/api/voteOnSponsorTime?userID=randomID4&UUID=vote-uuid-1.6&type=0")
|
||||
.then(res => {
|
||||
if (res.status === 200) {
|
||||
let row = db.prepare('get', "SELECT votes FROM sponsorTimes WHERE UUID = ?", ["vote-uuid-1.6"]);
|
||||
if (row.votes === 10) {
|
||||
done();
|
||||
} else {
|
||||
done("Status code was " + res.statusCode);
|
||||
done("Vote did not fail. Submission went from 10 votes to " + row.votes);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
done("Status code was " + res.status);
|
||||
}
|
||||
})
|
||||
.catch(err => done(err));
|
||||
});
|
||||
|
||||
it("Should not be able to upvote a segment if the user hasn't submitted yet", (done: Done) => {
|
||||
request.get(getbaseURL()
|
||||
+ "/api/voteOnSponsorTime?userID=hasNotSubmittedID&UUID=vote-uuid-1&type=1", null,
|
||||
(err, res) => {
|
||||
if (err) done(err);
|
||||
else if (res.statusCode === 200) {
|
||||
let row = db.prepare('get', "SELECT votes FROM sponsorTimes WHERE UUID = ?", ["vote-uuid-1"]);
|
||||
if (row.votes === 2) {
|
||||
done();
|
||||
} else {
|
||||
done("Vote did not fail. Submission went from 2 votes to " + row.votes);
|
||||
}
|
||||
fetch(getbaseURL()
|
||||
+ "/api/voteOnSponsorTime?userID=hasNotSubmittedID&UUID=vote-uuid-1&type=1")
|
||||
.then(res => {
|
||||
if (res.status === 200) {
|
||||
let row = db.prepare('get', "SELECT votes FROM sponsorTimes WHERE UUID = ?", ["vote-uuid-1"]);
|
||||
if (row.votes === 2) {
|
||||
done();
|
||||
} else {
|
||||
done("Status code was " + res.statusCode);
|
||||
done("Vote did not fail. Submission went from 2 votes to " + row.votes);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
done("Status code was " + res.status);
|
||||
}
|
||||
})
|
||||
.catch(err => done(err));
|
||||
});
|
||||
|
||||
it("Should not be able to downvote a segment if the user hasn't submitted yet", (done: Done) => {
|
||||
request.get(getbaseURL()
|
||||
+ "/api/voteOnSponsorTime?userID=hasNotSubmittedID&UUID=vote-uuid-1.5&type=0", null,
|
||||
(err, res) => {
|
||||
if (err) done(err);
|
||||
else if (res.statusCode === 200) {
|
||||
let row = db.prepare('get', "SELECT votes FROM sponsorTimes WHERE UUID = ?", ["vote-uuid-1.5"]);
|
||||
if (row.votes === 10) {
|
||||
done();
|
||||
} else {
|
||||
done("Vote did not fail. Submission went from 10 votes to " + row.votes);
|
||||
}
|
||||
fetch(getbaseURL()
|
||||
+ "/api/voteOnSponsorTime?userID=hasNotSubmittedID&UUID=vote-uuid-1.5&type=0")
|
||||
.then(res => {
|
||||
if (res.status === 200) {
|
||||
let row = db.prepare('get', "SELECT votes FROM sponsorTimes WHERE UUID = ?", ["vote-uuid-1.5"]);
|
||||
if (row.votes === 10) {
|
||||
done();
|
||||
} else {
|
||||
done("Status code was " + res.statusCode);
|
||||
done("Vote did not fail. Submission went from 10 votes to " + row.votes);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
done("Status code was " + res.status);
|
||||
}
|
||||
})
|
||||
.catch(err => done(err));
|
||||
});
|
||||
|
||||
it('VIP should be able to completely downvote a segment', (done: Done) => {
|
||||
request.get(getbaseURL()
|
||||
+ "/api/voteOnSponsorTime?userID=VIPUser&UUID=vote-uuid-3&type=0", null,
|
||||
(err, res) => {
|
||||
if (err) done(err);
|
||||
else if (res.statusCode === 200) {
|
||||
let row = db.prepare('get', "SELECT votes FROM sponsorTimes WHERE UUID = ?", ["vote-uuid-3"]);
|
||||
if (row.votes <= -2) {
|
||||
done();
|
||||
} else {
|
||||
done("Vote did not succeed. Submission went from 100 votes to " + row.votes);
|
||||
}
|
||||
fetch(getbaseURL()
|
||||
+ "/api/voteOnSponsorTime?userID=VIPUser&UUID=vote-uuid-3&type=0")
|
||||
.then(res => {
|
||||
if (res.status === 200) {
|
||||
let row = db.prepare('get', "SELECT votes FROM sponsorTimes WHERE UUID = ?", ["vote-uuid-3"]);
|
||||
if (row.votes <= -2) {
|
||||
done();
|
||||
} else {
|
||||
done("Status code was " + res.statusCode);
|
||||
done("Vote did not succeed. Submission went from 100 votes to " + row.votes);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
done("Status code was " + res.status);
|
||||
}
|
||||
})
|
||||
.catch(err => done(err));
|
||||
});
|
||||
|
||||
it('should be able to completely downvote your own segment', (done: Done) => {
|
||||
request.get(getbaseURL()
|
||||
+ "/api/voteOnSponsorTime?userID=own-submission-id&UUID=own-submission-uuid&type=0", null,
|
||||
(err, res) => {
|
||||
if (err) done(err);
|
||||
else if (res.statusCode === 200) {
|
||||
let row = db.prepare('get', "SELECT votes FROM sponsorTimes WHERE UUID = ?", ["own-submission-uuid"]);
|
||||
if (row.votes <= -2) {
|
||||
done();
|
||||
} else {
|
||||
done("Vote did not succeed. Submission went from 500 votes to " + row.votes);
|
||||
}
|
||||
fetch(getbaseURL()
|
||||
+ "/api/voteOnSponsorTime?userID=own-submission-id&UUID=own-submission-uuid&type=0")
|
||||
.then(res => {
|
||||
if (res.status === 200) {
|
||||
let row = db.prepare('get', "SELECT votes FROM sponsorTimes WHERE UUID = ?", ["own-submission-uuid"]);
|
||||
if (row.votes <= -2) {
|
||||
done();
|
||||
} else {
|
||||
done("Status code was " + res.statusCode);
|
||||
done("Vote did not succeed. Submission went from 500 votes to " + row.votes);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
done("Status code was " + res.status);
|
||||
}
|
||||
})
|
||||
.catch(err => done(err));
|
||||
});
|
||||
|
||||
it('should not be able to completely downvote somebody elses segment', (done: Done) => {
|
||||
request.get(getbaseURL()
|
||||
+ "/api/voteOnSponsorTime?userID=randomID2&UUID=not-own-submission-uuid&type=0", null,
|
||||
(err, res) => {
|
||||
if (err) done(err);
|
||||
else if (res.statusCode === 200) {
|
||||
let row = db.prepare('get', "SELECT votes FROM sponsorTimes WHERE UUID = ?", ["not-own-submission-uuid"]);
|
||||
if (row.votes === 499) {
|
||||
done();
|
||||
} else {
|
||||
done("Vote did not succeed. Submission went from 500 votes to " + row.votes);
|
||||
}
|
||||
fetch(getbaseURL()
|
||||
+ "/api/voteOnSponsorTime?userID=randomID2&UUID=not-own-submission-uuid&type=0")
|
||||
.then(res => {
|
||||
if (res.status === 200) {
|
||||
let row = db.prepare('get', "SELECT votes FROM sponsorTimes WHERE UUID = ?", ["not-own-submission-uuid"]);
|
||||
if (row.votes === 499) {
|
||||
done();
|
||||
} else {
|
||||
done("Status code was " + res.statusCode);
|
||||
done("Vote did not succeed. Submission went from 500 votes to " + row.votes);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
done("Status code was " + res.status);
|
||||
}
|
||||
})
|
||||
.catch(err => done(err));
|
||||
});
|
||||
|
||||
it('Should be able to vote for a category and it should add your vote to the database', (done: Done) => {
|
||||
request.get(getbaseURL()
|
||||
+ "/api/voteOnSponsorTime?userID=randomID2&UUID=vote-uuid-4&category=intro", null,
|
||||
(err, res) => {
|
||||
if (err) done(err);
|
||||
else if (res.statusCode === 200) {
|
||||
let row = db.prepare('get', "SELECT category FROM sponsorTimes WHERE UUID = ?", ["vote-uuid-4"]);
|
||||
let categoryRows = db.prepare('all', "SELECT votes, category FROM categoryVotes WHERE UUID = ?", ["vote-uuid-4"]);
|
||||
if (row.category === "sponsor" && categoryRows.length === 2
|
||||
&& categoryRows[0]?.votes === 1 && categoryRows[0]?.category === "intro"
|
||||
&& categoryRows[1]?.votes === 1 && categoryRows[1]?.category === "sponsor") {
|
||||
done();
|
||||
} else {
|
||||
done("Submission changed to " + row.category + " instead of staying as sponsor. Vote was applied as " + categoryRows[0]?.category + " with " + categoryRows[0]?.votes + " votes and there were " + categoryRows.length + " rows.");
|
||||
}
|
||||
fetch(getbaseURL()
|
||||
+ "/api/voteOnSponsorTime?userID=randomID2&UUID=vote-uuid-4&category=intro")
|
||||
.then(res => {
|
||||
if (res.status === 200) {
|
||||
let row = db.prepare('get', "SELECT category FROM sponsorTimes WHERE UUID = ?", ["vote-uuid-4"]);
|
||||
let categoryRows = db.prepare('all', "SELECT votes, category FROM categoryVotes WHERE UUID = ?", ["vote-uuid-4"]);
|
||||
if (row.category === "sponsor" && categoryRows.length === 2
|
||||
&& categoryRows[0]?.votes === 1 && categoryRows[0]?.category === "intro"
|
||||
&& categoryRows[1]?.votes === 1 && categoryRows[1]?.category === "sponsor") {
|
||||
done();
|
||||
} else {
|
||||
done("Status code was " + res.statusCode);
|
||||
done("Submission changed to " + row.category + " instead of staying as sponsor. Vote was applied as " + categoryRows[0]?.category + " with " + categoryRows[0]?.votes + " votes and there were " + categoryRows.length + " rows.");
|
||||
}
|
||||
});
|
||||
} else {
|
||||
done("Status code was " + res.status);
|
||||
}
|
||||
})
|
||||
.catch(err => done(err));
|
||||
});
|
||||
|
||||
it('Should not able to change to an invalid category', (done: Done) => {
|
||||
request.get(getbaseURL()
|
||||
+ "/api/voteOnSponsorTime?userID=randomID2&UUID=incorrect-category&category=fakecategory", null,
|
||||
(err, res) => {
|
||||
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);
|
||||
}
|
||||
fetch(getbaseURL()
|
||||
+ "/api/voteOnSponsorTime?userID=randomID2&UUID=incorrect-category&category=fakecategory")
|
||||
.then(res => {
|
||||
if (res.status === 400) {
|
||||
let row = db.prepare('get', "SELECT category FROM sponsorTimes WHERE UUID = ?", ["incorrect-category"]);
|
||||
if (row.category === "sponsor") {
|
||||
done();
|
||||
} else {
|
||||
done("Status code was " + res.statusCode);
|
||||
done("Vote did not succeed. Submission went from sponsor to " + row.category);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
done("Status code was " + res.status);
|
||||
}
|
||||
})
|
||||
.catch(err => done(err));
|
||||
});
|
||||
|
||||
it('Should be able to change your vote for a category and it should add your vote to the database', (done: Done) => {
|
||||
request.get(getbaseURL()
|
||||
+ "/api/voteOnSponsorTime?userID=randomID2&UUID=vote-uuid-4&category=outro", null,
|
||||
(err, res) => {
|
||||
if (err) done(err);
|
||||
else if (res.statusCode === 200) {
|
||||
let submissionRow = db.prepare('get', "SELECT category FROM sponsorTimes WHERE UUID = ?", ["vote-uuid-4"]);
|
||||
let categoryRows = db.prepare('all', "SELECT votes, category FROM categoryVotes WHERE UUID = ?", ["vote-uuid-4"]);
|
||||
let introVotes = 0;
|
||||
let outroVotes = 0;
|
||||
let sponsorVotes = 0;
|
||||
for (const row of categoryRows) {
|
||||
if (row?.category === "intro") introVotes += row?.votes;
|
||||
if (row?.category === "outro") outroVotes += row?.votes;
|
||||
if (row?.category === "sponsor") sponsorVotes += row?.votes;
|
||||
}
|
||||
if (submissionRow.category === "sponsor" && categoryRows.length === 3
|
||||
&& introVotes === 0 && outroVotes === 1 && sponsorVotes === 1) {
|
||||
done();
|
||||
} else {
|
||||
done("Submission changed to " + submissionRow.category + " instead of staying as sponsor. There were "
|
||||
+ introVotes + " intro votes, " + outroVotes + " outro votes and " + sponsorVotes + " sponsor votes.");
|
||||
}
|
||||
} else {
|
||||
done("Status code was " + res.statusCode);
|
||||
fetch(getbaseURL()
|
||||
+ "/api/voteOnSponsorTime?userID=randomID2&UUID=vote-uuid-4&category=outro")
|
||||
.then(res => {
|
||||
if (res.status === 200) {
|
||||
let submissionRow = db.prepare('get', "SELECT category FROM sponsorTimes WHERE UUID = ?", ["vote-uuid-4"]);
|
||||
let categoryRows = db.prepare('all', "SELECT votes, category FROM categoryVotes WHERE UUID = ?", ["vote-uuid-4"]);
|
||||
let introVotes = 0;
|
||||
let outroVotes = 0;
|
||||
let sponsorVotes = 0;
|
||||
for (const row of categoryRows) {
|
||||
if (row?.category === "intro") introVotes += row?.votes;
|
||||
if (row?.category === "outro") outroVotes += row?.votes;
|
||||
if (row?.category === "sponsor") sponsorVotes += row?.votes;
|
||||
}
|
||||
});
|
||||
if (submissionRow.category === "sponsor" && categoryRows.length === 3
|
||||
&& introVotes === 0 && outroVotes === 1 && sponsorVotes === 1) {
|
||||
done();
|
||||
} else {
|
||||
done("Submission changed to " + submissionRow.category + " instead of staying as sponsor. There were "
|
||||
+ introVotes + " intro votes, " + outroVotes + " outro votes and " + sponsorVotes + " sponsor votes.");
|
||||
}
|
||||
} else {
|
||||
done("Status code was " + res.status);
|
||||
}
|
||||
})
|
||||
.catch(err => done(err));
|
||||
});
|
||||
|
||||
|
||||
it('Should not be able to change your vote to an invalid category', (done: Done) => {
|
||||
const vote = (inputCat: string, assertCat: string, callback: Done) => {
|
||||
request.get(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);
|
||||
}
|
||||
}
|
||||
});
|
||||
fetch(getbaseURL()
|
||||
+ "/api/voteOnSponsorTime?userID=randomID2&UUID=incorrect-category-change&category=" + inputCat)
|
||||
.then(res => {
|
||||
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);
|
||||
}
|
||||
})
|
||||
.catch(err => done(err));
|
||||
};
|
||||
vote("sponsor", "sponsor", () => {
|
||||
vote("fakeCategory", "sponsor", done);
|
||||
@@ -316,149 +314,148 @@ describe('voteOnSponsorTime', () => {
|
||||
|
||||
|
||||
it('VIP should be able to vote for a category and it should immediately change', (done: Done) => {
|
||||
request.get(getbaseURL()
|
||||
+ "/api/voteOnSponsorTime?userID=VIPUser&UUID=vote-uuid-5&category=outro", null,
|
||||
(err, res) => {
|
||||
if (err) done(err);
|
||||
else if (res.statusCode === 200) {
|
||||
let row = db.prepare('get', "SELECT category FROM sponsorTimes WHERE UUID = ?", ["vote-uuid-5"]);
|
||||
let row2 = db.prepare('get', "SELECT votes FROM categoryVotes WHERE UUID = ? and category = ?", ["vote-uuid-5", "outro"]);
|
||||
if (row.category === "outro" && row2.votes === 500) {
|
||||
done();
|
||||
} else {
|
||||
done("Vote did not succeed. Submission went from intro to " + row.category + ". Category votes are " + row2.votes + " and should be 500.");
|
||||
}
|
||||
fetch(getbaseURL()
|
||||
+ "/api/voteOnSponsorTime?userID=VIPUser&UUID=vote-uuid-5&category=outro")
|
||||
.then(res => {
|
||||
if (res.status === 200) {
|
||||
let row = db.prepare('get', "SELECT category FROM sponsorTimes WHERE UUID = ?", ["vote-uuid-5"]);
|
||||
let row2 = db.prepare('get', "SELECT votes FROM categoryVotes WHERE UUID = ? and category = ?", ["vote-uuid-5", "outro"]);
|
||||
if (row.category === "outro" && row2.votes === 500) {
|
||||
done();
|
||||
} else {
|
||||
done("Status code was " + res.statusCode);
|
||||
done("Vote did not succeed. Submission went from intro to " + row.category + ". Category votes are " + row2.votes + " and should be 500.");
|
||||
}
|
||||
});
|
||||
} else {
|
||||
done("Status code was " + res.status);
|
||||
}
|
||||
})
|
||||
.catch(err => done(err));
|
||||
});
|
||||
|
||||
it('Submitter should be able to vote for a category and it should immediately change', (done: Done) => {
|
||||
request.get(getbaseURL()
|
||||
+ "/api/voteOnSponsorTime?userID=testman&UUID=vote-uuid-5_1&category=outro", null,
|
||||
(err, res) => {
|
||||
if (err) done(err);
|
||||
else if (res.statusCode === 200) {
|
||||
let row = db.prepare('get', "SELECT category FROM sponsorTimes WHERE UUID = ?", ["vote-uuid-5"]);
|
||||
if (row.category === "outro") {
|
||||
done();
|
||||
} else {
|
||||
done("Vote did not succeed. Submission went from intro to " + row.category + ".");
|
||||
}
|
||||
fetch(getbaseURL()
|
||||
+ "/api/voteOnSponsorTime?userID=testman&UUID=vote-uuid-5_1&category=outro")
|
||||
.then(res => {
|
||||
if (res.status === 200) {
|
||||
let row = db.prepare('get', "SELECT category FROM sponsorTimes WHERE UUID = ?", ["vote-uuid-5"]);
|
||||
if (row.category === "outro") {
|
||||
done();
|
||||
} else {
|
||||
done("Status code was " + res.statusCode);
|
||||
done("Vote did not succeed. Submission went from intro to " + row.category + ".");
|
||||
}
|
||||
});
|
||||
} else {
|
||||
done("Status code was " + res.status);
|
||||
}
|
||||
})
|
||||
.catch(err => done(err));
|
||||
});
|
||||
|
||||
it('Should not be able to category-vote on an invalid UUID submission', (done: Done) => {
|
||||
request.get(getbaseURL()
|
||||
+ "/api/voteOnSponsorTime?userID=randomID3&UUID=invalid-uuid&category=intro", null,
|
||||
(err, res) => {
|
||||
if (err) done(err);
|
||||
else if (res.statusCode === 400) {
|
||||
done();
|
||||
} else {
|
||||
done("Status code was " + res.statusCode + " instead of 400.");
|
||||
}
|
||||
});
|
||||
fetch(getbaseURL()
|
||||
+ "/api/voteOnSponsorTime?userID=randomID3&UUID=invalid-uuid&category=intro")
|
||||
.then(res => {
|
||||
if (res.status === 400) {
|
||||
done();
|
||||
} else {
|
||||
done("Status code was " + res.status + " instead of 400.");
|
||||
}
|
||||
})
|
||||
.catch(err => done(err));
|
||||
});
|
||||
|
||||
it('Non-VIP should not be able to upvote "dead" submission', (done: Done) => {
|
||||
request.get(getbaseURL()
|
||||
+ "/api/voteOnSponsorTime?userID=randomID2&UUID=vote-uuid-5&type=1", null,
|
||||
(err, res) => {
|
||||
if (err) done(err);
|
||||
else if (res.statusCode === 403) {
|
||||
done();
|
||||
} else {
|
||||
done("Status code was " + res.statusCode + " instead of 403");
|
||||
}
|
||||
});
|
||||
fetch(getbaseURL()
|
||||
+ "/api/voteOnSponsorTime?userID=randomID2&UUID=vote-uuid-5&type=1")
|
||||
.then(res => {
|
||||
if (res.status === 403) {
|
||||
done();
|
||||
} else {
|
||||
done("Status code was " + res.status + " instead of 403");
|
||||
}
|
||||
})
|
||||
.catch(err => done(err));
|
||||
});
|
||||
|
||||
it('VIP should be able to upvote "dead" submission', (done: Done) => {
|
||||
request.get(getbaseURL()
|
||||
+ "/api/voteOnSponsorTime?userID=VIPUser&UUID=vote-uuid-5&type=1", null,
|
||||
(err, res) => {
|
||||
if (err) done(err);
|
||||
else if (res.statusCode === 200) {
|
||||
let row = db.prepare('get', "SELECT votes FROM sponsorTimes WHERE UUID = ?", ["vote-uuid-5"]);
|
||||
if (row.votes > -3) {
|
||||
done();
|
||||
} else {
|
||||
done("Vote did not succeed. Votes raised from -3 to " + row.votes);
|
||||
}
|
||||
fetch(getbaseURL()
|
||||
+ "/api/voteOnSponsorTime?userID=VIPUser&UUID=vote-uuid-5&type=1")
|
||||
.then(res => {
|
||||
if (res.status === 200) {
|
||||
let row = db.prepare('get', "SELECT votes FROM sponsorTimes WHERE UUID = ?", ["vote-uuid-5"]);
|
||||
if (row.votes > -3) {
|
||||
done();
|
||||
} else {
|
||||
done("Status code was " + res.statusCode);
|
||||
done("Vote did not succeed. Votes raised from -3 to " + row.votes);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
done("Status code was " + res.status);
|
||||
}
|
||||
})
|
||||
.catch(err => done(err));
|
||||
});
|
||||
|
||||
it('Should not be able to upvote a segment (Too many warning)', (done: Done) => {
|
||||
request.get(getbaseURL()
|
||||
+ "/api/voteOnSponsorTime?userID=warn-voteuser01&UUID=warnvote-uuid-0&type=1", null,
|
||||
(err, res) => {
|
||||
if (err) done(err);
|
||||
else if (res.statusCode === 403) {
|
||||
done(); // success
|
||||
} else {
|
||||
done("Status code was " + res.statusCode);
|
||||
}
|
||||
});
|
||||
fetch(getbaseURL()
|
||||
+ "/api/voteOnSponsorTime?userID=warn-voteuser01&UUID=warnvote-uuid-0&type=1")
|
||||
.then(res => {
|
||||
if (res.status === 403) {
|
||||
done(); // success
|
||||
} else {
|
||||
done("Status code was " + res.status);
|
||||
}
|
||||
})
|
||||
.catch(err => done(err));
|
||||
});
|
||||
|
||||
it('Non-VIP should not be able to vote on a segment with no-segments category', (done: Done) => {
|
||||
request.get(getbaseURL()
|
||||
+ "/api/voteOnSponsorTime?userID=no-segments-voter&UUID=no-sponsor-segments-uuid-0&type=1", null,
|
||||
(err, res) => {
|
||||
if (err) done(err);
|
||||
else if (res.statusCode === 403) {
|
||||
done();
|
||||
} else {
|
||||
done("Status code was " + res.statusCode + " instead of 403");
|
||||
}
|
||||
});
|
||||
fetch(getbaseURL()
|
||||
+ "/api/voteOnSponsorTime?userID=no-segments-voter&UUID=no-sponsor-segments-uuid-0&type=1")
|
||||
.then(res => {
|
||||
if (res.status === 403) {
|
||||
done();
|
||||
} else {
|
||||
done("Status code was " + res.status + " instead of 403");
|
||||
}
|
||||
})
|
||||
.catch(err => done(err));
|
||||
});
|
||||
|
||||
it('Non-VIP should not be able to category vote on a segment with no-segments category', (done: Done) => {
|
||||
request.get(getbaseURL()
|
||||
+ "/api/voteOnSponsorTime?userID=no-segments-voter&UUID=no-sponsor-segments-uuid-0&category=outro", null,
|
||||
(err, res) => {
|
||||
if (err) done(err);
|
||||
else if (res.statusCode === 403) {
|
||||
done();
|
||||
} else {
|
||||
done("Status code was " + res.statusCode + " instead of 403");
|
||||
}
|
||||
});
|
||||
fetch(getbaseURL()
|
||||
+ "/api/voteOnSponsorTime?userID=no-segments-voter&UUID=no-sponsor-segments-uuid-0&category=outro")
|
||||
.then(res => {
|
||||
if (res.status === 403) {
|
||||
done();
|
||||
} else {
|
||||
done("Status code was " + res.status + " instead of 403");
|
||||
}
|
||||
})
|
||||
.catch(err => done(err));
|
||||
});
|
||||
|
||||
it('VIP should able to vote on a segment with no-segments category', (done: Done) => {
|
||||
request.get(getbaseURL()
|
||||
+ "/api/voteOnSponsorTime?userID=VIPUser&UUID=no-sponsor-segments-uuid-0&type=1", null,
|
||||
(err, res) => {
|
||||
if (err) done(err);
|
||||
else if (res.statusCode === 200) {
|
||||
done();
|
||||
} else {
|
||||
done("Status code was " + res.statusCode + " instead of 200");
|
||||
}
|
||||
});
|
||||
fetch(getbaseURL()
|
||||
+ "/api/voteOnSponsorTime?userID=VIPUser&UUID=no-sponsor-segments-uuid-0&type=1")
|
||||
.then(res => {
|
||||
if (res.status === 200) {
|
||||
done();
|
||||
} else {
|
||||
done("Status code was " + res.status + " instead of 200");
|
||||
}
|
||||
})
|
||||
.catch(err => done(err));
|
||||
});
|
||||
|
||||
it('Non-VIP should be able to vote on a segment on a no-segments video with a category that doesn\'t have no-segments', (done: Done) => {
|
||||
request.get(getbaseURL()
|
||||
+ "/api/voteOnSponsorTime?userID=no-segments-voter&UUID=no-sponsor-segments-uuid-1&type=1", null,
|
||||
(err, res) => {
|
||||
if (err) done(err);
|
||||
else if (res.statusCode === 200) {
|
||||
done();
|
||||
} else {
|
||||
done("Status code was " + res.statusCode + " instead of 200");
|
||||
}
|
||||
});
|
||||
fetch(getbaseURL()
|
||||
+ "/api/voteOnSponsorTime?userID=no-segments-voter&UUID=no-sponsor-segments-uuid-1&type=1")
|
||||
.then(res => {
|
||||
if (res.status === 200) {
|
||||
done();
|
||||
} else {
|
||||
done("Status code was " + res.status + " instead of 200");
|
||||
}
|
||||
})
|
||||
.catch(err => done(err));
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user