mirror of
https://github.com/ajayyy/SponsorBlockServer.git
synced 2024-11-10 01:02:30 +01:00
VIP upvotes unhide segments
also added test for undo-vote
This commit is contained in:
parent
107b21c463
commit
36a5b4e1d3
1 changed files with 60 additions and 25 deletions
|
@ -20,31 +20,31 @@ describe('voteOnSponsorTime', () => {
|
|||
const MILLISECONDS_IN_HOUR = 3600000;
|
||||
const warningExpireTime = MILLISECONDS_IN_HOUR * config.hoursAfterWarningExpires;
|
||||
|
||||
const insertSponsorTimeQuery = 'INSERT INTO "sponsorTimes" ("videoID", "startTime", "endTime", "votes", "UUID", "userID", "timeSubmitted", "views", "category", "shadowHidden", "hashedVideoID") VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)';
|
||||
await db.prepare("run", insertSponsorTimeQuery, ['vote-testtesttest', 1, 11, 2, 'vote-uuid-0', 'testman', 0, 50, 'sponsor', 0, getHash('vote-testtesttest', 1)]);
|
||||
await db.prepare("run", insertSponsorTimeQuery, ['vote-testtesttest2', 1, 11, 2, 'vote-uuid-1', 'testman', 0, 50, 'sponsor', 0, getHash('vote-testtesttest2', 1)]);
|
||||
await db.prepare("run", insertSponsorTimeQuery, ['vote-testtesttest2', 1, 11, 10, 'vote-uuid-1.5', 'testman', 0, 50, 'outro', 0, getHash('vote-testtesttest2', 1)]);
|
||||
await db.prepare("run", insertSponsorTimeQuery, ['vote-testtesttest2', 1, 11, 10, 'vote-uuid-1.6', 'testman', 0, 50, 'interaction', 0, getHash('vote-testtesttest2', 1)]);
|
||||
await db.prepare("run", insertSponsorTimeQuery, ['vote-testtesttest3', 20, 33, 10, 'vote-uuid-2', 'testman', 0, 50, 'intro', 0, getHash('vote-testtesttest3', 1)]);
|
||||
await db.prepare("run", insertSponsorTimeQuery, ['vote-testtesttest,test', 1, 11, 100, 'vote-uuid-3', 'testman', 0, 50, 'sponsor', 0, getHash('vote-testtesttest,test', 1)]);
|
||||
await db.prepare("run", insertSponsorTimeQuery, ['vote-test3', 1, 11, 2, 'vote-uuid-4', 'testman', 0, 50, 'sponsor', 0, getHash('vote-test3', 1)]);
|
||||
await db.prepare("run", insertSponsorTimeQuery, ['vote-test3', 7, 22, -3, 'vote-uuid-5', 'testman', 0, 50, 'intro', 0, getHash('vote-test3', 1)]);
|
||||
await db.prepare("run", insertSponsorTimeQuery, ['vote-test3', 7, 22, -3, 'vote-uuid-5_1', 'testman', 0, 50, 'intro', 0, getHash('vote-test3', 1)]);
|
||||
await db.prepare("run", insertSponsorTimeQuery, ['vote-multiple', 1, 11, 2, 'vote-uuid-6', 'testman', 0, 50, 'intro', 0, getHash('vote-multiple', 1)]);
|
||||
await db.prepare("run", insertSponsorTimeQuery, ['vote-multiple', 20, 33, 2, 'vote-uuid-7', 'testman', 0, 50, 'intro', 0, getHash('vote-multiple', 1)]);
|
||||
await db.prepare("run", insertSponsorTimeQuery, ['voter-submitter', 1, 11, 2, 'vote-uuid-8', getHash("randomID"), 0, 50, 'sponsor', 0, getHash('voter-submitter', 1)]);
|
||||
await db.prepare("run", insertSponsorTimeQuery, ['voter-submitter2', 1, 11, 2, 'vote-uuid-9', getHash("randomID2"), 0, 50, 'sponsor', 0, getHash('voter-submitter2', 1)]);
|
||||
await db.prepare("run", insertSponsorTimeQuery, ['voter-submitter2', 1, 11, 2, 'vote-uuid-10', getHash("randomID3"), 0, 50, 'sponsor', 0, getHash('voter-submitter2', 1)]);
|
||||
await db.prepare("run", insertSponsorTimeQuery, ['voter-submitter2', 1, 11, 2, 'vote-uuid-11', getHash("randomID4"), 0, 50, 'sponsor', 0, getHash('voter-submitter2', 1)]);
|
||||
await db.prepare("run", insertSponsorTimeQuery, ['own-submission-video', 1, 11, 500, 'own-submission-uuid', getHash('own-submission-id'), 0, 50, 'sponsor', 0, getHash('own-submission-video', 1)]);
|
||||
await db.prepare("run", insertSponsorTimeQuery, ['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)]);
|
||||
await db.prepare("run", insertSponsorTimeQuery, ['incorrect-category', 1, 11, 500, 'incorrect-category', getHash('somebody-else-id'), 0, 50, 'sponsor', 0, getHash('incorrect-category', 1)]);
|
||||
await db.prepare("run", insertSponsorTimeQuery, ['incorrect-category-change', 1, 11, 500, 'incorrect-category-change', getHash('somebody-else-id'), 0, 50, 'sponsor', 0, getHash('incorrect-category-change', 1)]);
|
||||
await db.prepare("run", insertSponsorTimeQuery, ['vote-testtesttest', 1, 11, 2, 'warnvote-uuid-0', 'testman', 0, 50, 'sponsor', 0, getHash('vote-testtesttest', 1)]);
|
||||
await db.prepare("run", insertSponsorTimeQuery, ['no-sponsor-segments-video', 1, 11, 2, 'no-sponsor-segments-uuid-0', 'no-sponsor-segments', 0, 50, 'sponsor', 0, getHash('no-sponsor-segments-video', 1)]);
|
||||
await db.prepare("run", insertSponsorTimeQuery, ['no-sponsor-segments-video', 1, 11, 2, 'no-sponsor-segments-uuid-1', 'no-sponsor-segments', 0, 50, 'intro', 0, getHash('no-sponsor-segments-video', 1)]);
|
||||
await db.prepare("run", insertSponsorTimeQuery, ['segment-locking-video', 1, 11, 2, 'segment-locking-uuid-1', 'segment-locking-user', 0, 50, 'intro', 0, getHash('segment-locking-video', 1)]);
|
||||
|
||||
const insertSponsorTimeQuery = 'INSERT INTO "sponsorTimes" ("videoID", "startTime", "endTime", "votes", "UUID", "userID", "timeSubmitted", "views", "category", "shadowHidden", "hidden", "hashedVideoID") VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)';
|
||||
await db.prepare("run", insertSponsorTimeQuery, ['vote-testtesttest', 1, 11, 2, 'vote-uuid-0', 'testman', 0, 50, 'sponsor', 0, 0, getHash('vote-testtesttest', 1)]);
|
||||
await db.prepare("run", insertSponsorTimeQuery, ['vote-testtesttest2', 1, 11, 2, 'vote-uuid-1', 'testman', 0, 50, 'sponsor', 0, 0, getHash('vote-testtesttest2', 1)]);
|
||||
await db.prepare("run", insertSponsorTimeQuery, ['vote-testtesttest2', 1, 11, 10, 'vote-uuid-1.5', 'testman', 0, 50, 'outro', 0, 0, getHash('vote-testtesttest2', 1)]);
|
||||
await db.prepare("run", insertSponsorTimeQuery, ['vote-testtesttest2', 1, 11, 10, 'vote-uuid-1.6', 'testman', 0, 50, 'interaction', 0, 0, getHash('vote-testtesttest2', 1)]);
|
||||
await db.prepare("run", insertSponsorTimeQuery, ['vote-testtesttest3', 20, 33, 10, 'vote-uuid-2', 'testman', 0, 50, 'intro', 0, 0, getHash('vote-testtesttest3', 1)]);
|
||||
await db.prepare("run", insertSponsorTimeQuery, ['vote-testtesttest,test', 1, 11, 100, 'vote-uuid-3', 'testman', 0, 50, 'sponsor', 0, 0, getHash('vote-testtesttest,test', 1)]);
|
||||
await db.prepare("run", insertSponsorTimeQuery, ['vote-test3', 1, 11, 2, 'vote-uuid-4', 'testman', 0, 50, 'sponsor', 0, 0, getHash('vote-test3', 1)]);
|
||||
await db.prepare("run", insertSponsorTimeQuery, ['vote-test3', 7, 22, -3, 'vote-uuid-5', 'testman', 0, 50, 'intro', 0, 0, getHash('vote-test3', 1)]);
|
||||
await db.prepare("run", insertSponsorTimeQuery, ['vote-test3', 7, 22, -3, 'vote-uuid-5_1', 'testman', 0, 50, 'intro', 0, 0, getHash('vote-test3', 1)]);
|
||||
await db.prepare("run", insertSponsorTimeQuery, ['vote-multiple', 1, 11, 2, 'vote-uuid-6', 'testman', 0, 50, 'intro', 0, 0, getHash('vote-multiple', 1)]);
|
||||
await db.prepare("run", insertSponsorTimeQuery, ['vote-multiple', 20, 33, 2, 'vote-uuid-7', 'testman', 0, 50, 'intro', 0, 0, getHash('vote-multiple', 1)]);
|
||||
await db.prepare("run", insertSponsorTimeQuery, ['voter-submitter', 1, 11, 2, 'vote-uuid-8', getHash("randomID"), 0, 50, 'sponsor', 0, 0, getHash('voter-submitter', 1)]);
|
||||
await db.prepare("run", insertSponsorTimeQuery, ['voter-submitter2', 1, 11, 2, 'vote-uuid-9', getHash("randomID2"), 0, 50, 'sponsor', 0, 0, getHash('voter-submitter2', 1)]);
|
||||
await db.prepare("run", insertSponsorTimeQuery, ['voter-submitter2', 1, 11, 2, 'vote-uuid-10', getHash("randomID3"), 0, 50, 'sponsor', 0, 0, getHash('voter-submitter2', 1)]);
|
||||
await db.prepare("run", insertSponsorTimeQuery, ['voter-submitter2', 1, 11, 2, 'vote-uuid-11', getHash("randomID4"), 0, 50, 'sponsor', 0, 0, getHash('voter-submitter2', 1)]);
|
||||
await db.prepare("run", insertSponsorTimeQuery, ['own-submission-video', 1, 11, 500, 'own-submission-uuid', getHash('own-submission-id'), 0, 50, 'sponsor', 0, 0, getHash('own-submission-video', 1)]);
|
||||
await db.prepare("run", insertSponsorTimeQuery, ['not-own-submission-video', 1, 11, 500, 'not-own-submission-uuid', getHash('somebody-else-id'), 0, 50, 'sponsor', 0, 0, getHash('not-own-submission-video', 1)]);
|
||||
await db.prepare("run", insertSponsorTimeQuery, ['incorrect-category', 1, 11, 500, 'incorrect-category', getHash('somebody-else-id'), 0, 50, 'sponsor', 0, 0, getHash('incorrect-category', 1)]);
|
||||
await db.prepare("run", insertSponsorTimeQuery, ['incorrect-category-change', 1, 11, 500, 'incorrect-category-change', getHash('somebody-else-id'), 0, 50, 'sponsor', 0, 0, getHash('incorrect-category-change', 1)]);
|
||||
await db.prepare("run", insertSponsorTimeQuery, ['vote-testtesttest', 1, 11, 2, 'warnvote-uuid-0', 'testman', 0, 50, 'sponsor', 0, 0, getHash('vote-testtesttest', 1)]);
|
||||
await db.prepare("run", insertSponsorTimeQuery, ['no-sponsor-segments-video', 1, 11, 2, 'no-sponsor-segments-uuid-0', 'no-sponsor-segments', 0, 50, 'sponsor', 0, 0, getHash('no-sponsor-segments-video', 1)]);
|
||||
await db.prepare("run", insertSponsorTimeQuery, ['no-sponsor-segments-video', 1, 11, 2, 'no-sponsor-segments-uuid-1', 'no-sponsor-segments', 0, 50, 'intro', 0, 0, getHash('no-sponsor-segments-video', 1)]);
|
||||
await db.prepare("run", insertSponsorTimeQuery, ['segment-locking-video', 1, 11, 2, 'segment-locking-uuid-1', 'segment-locking-user', 0, 50, 'intro', 0, 0, getHash('segment-locking-video', 1)]);
|
||||
|
||||
const insertWarningQuery = 'INSERT INTO "warnings" ("userID", "issueTime", "issuerUserID", "enabled") VALUES(?, ?, ?, ?)';
|
||||
await db.prepare("run", insertWarningQuery, [warnUser01Hash, now, warnVip01Hash, 1]);
|
||||
await db.prepare("run", insertWarningQuery, [warnUser01Hash, (now - 1000), warnVip01Hash, 1]);
|
||||
|
@ -518,4 +518,39 @@ describe('voteOnSponsorTime', () => {
|
|||
.catch(err => done(err));
|
||||
});
|
||||
|
||||
it('VIP upvote should unhide segment', (done: Done) => {
|
||||
fetch(getbaseURL()
|
||||
+ "/api/voteOnSponsorTime?userID=VIPUser&UUID=segment-hidden-uuid-1&type=1")
|
||||
.then(async res => {
|
||||
if (res.status === 200) {
|
||||
let row = await db.prepare('get', `SELECT "hidden" FROM "sponsorTimes" WHERE "UUID" = ?`, ["segment-hidden-uuid-1"]);
|
||||
if (!row?.hidden) {
|
||||
done();
|
||||
} else {
|
||||
done("Segment not unhidden");
|
||||
}
|
||||
} else {
|
||||
done("Status code was " + res.status + " instead of 200");
|
||||
}
|
||||
})
|
||||
.catch(err => done(err));
|
||||
});
|
||||
|
||||
it('Should be able to undo-vote a segment', (done: Done) => {
|
||||
fetch(getbaseURL()
|
||||
+ "/api/voteOnSponsorTime?userID=randomID2&UUID=vote-uuid-2&type=20")
|
||||
.then(async res => {
|
||||
if (res.status === 200) {
|
||||
let row = await 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);
|
||||
}
|
||||
} else {
|
||||
done("Status code was " + res.status);
|
||||
}
|
||||
})
|
||||
.catch(err => done(err));
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue