Add test for submitting full video converting to upvote

This commit is contained in:
Ajay
2022-01-06 14:10:41 -05:00
parent 68c6266139
commit b4f8bdd719
2 changed files with 47 additions and 7 deletions

View File

@@ -409,7 +409,7 @@ async function checkEachSegmentValid(rawIP: IPAddress, paramUserID: UserID, user
if (duplicateCheck2Row) { if (duplicateCheck2Row) {
if (segments[i].actionType === ActionType.Full) { if (segments[i].actionType === ActionType.Full) {
// Forward as vote // Forward as vote
vote(rawIP, duplicateCheck2Row.UUID, paramUserID, 1); await vote(rawIP, duplicateCheck2Row.UUID, paramUserID, 1);
segments[i].ignoreSegment = true; segments[i].ignoreSegment = true;
continue; continue;
} else { } else {

View File

@@ -16,6 +16,7 @@ describe("postSkipSegments", () => {
// Constant and helpers // Constant and helpers
const submitUserOne = `PostSkipUser1${".".repeat(18)}`; const submitUserOne = `PostSkipUser1${".".repeat(18)}`;
const submitUserTwo = `PostSkipUser2${".".repeat(18)}`; const submitUserTwo = `PostSkipUser2${".".repeat(18)}`;
const submitUserTwoHash = getHash(submitUserTwo);
const submitUserThree = `PostSkipUser3${".".repeat(18)}`; const submitUserThree = `PostSkipUser3${".".repeat(18)}`;
const warnUser01 = "warn-user01-qwertyuiopasdfghjklzxcvbnm"; const warnUser01 = "warn-user01-qwertyuiopasdfghjklzxcvbnm";
@@ -35,7 +36,7 @@ describe("postSkipSegments", () => {
const badInputVideoID = "dQw4w9WgXcQ"; const badInputVideoID = "dQw4w9WgXcQ";
const shadowBanVideoID = "postSkipBan"; const shadowBanVideoID = "postSkipBan";
const queryDatabase = (videoID: string) => db.prepare("get", `SELECT "startTime", "endTime", "locked", "category" FROM "sponsorTimes" WHERE "videoID" = ?`, [videoID]); const queryDatabase = (videoID: string) => db.prepare("get", `SELECT "startTime", "endTime", "votes", "userID", "locked", "category", "actionType" FROM "sponsorTimes" WHERE "videoID" = ?`, [videoID]);
const queryDatabaseActionType = (videoID: string) => db.prepare("get", `SELECT "startTime", "endTime", "locked", "category", "actionType" FROM "sponsorTimes" WHERE "videoID" = ?`, [videoID]); const queryDatabaseActionType = (videoID: string) => db.prepare("get", `SELECT "startTime", "endTime", "locked", "category", "actionType" FROM "sponsorTimes" WHERE "videoID" = ?`, [videoID]);
const queryDatabaseChapter = (videoID: string) => db.prepare("get", `SELECT "startTime", "endTime", "locked", "category", "actionType", "description" FROM "sponsorTimes" WHERE "videoID" = ?`, [videoID]); const queryDatabaseChapter = (videoID: string) => db.prepare("get", `SELECT "startTime", "endTime", "locked", "category", "actionType", "description" FROM "sponsorTimes" WHERE "videoID" = ?`, [videoID]);
const queryDatabaseDuration = (videoID: string) => db.prepare("get", `SELECT "startTime", "endTime", "locked", "category", "videoDuration" FROM "sponsorTimes" WHERE "videoID" = ?`, [videoID]); const queryDatabaseDuration = (videoID: string) => db.prepare("get", `SELECT "startTime", "endTime", "locked", "category", "videoDuration" FROM "sponsorTimes" WHERE "videoID" = ?`, [videoID]);
@@ -54,10 +55,12 @@ describe("postSkipSegments", () => {
}); });
before(() => { before(() => {
const insertSponsorTimeQuery = 'INSERT INTO "sponsorTimes" ("videoID", "startTime", "endTime", "votes", "UUID", "userID", "timeSubmitted", views, category, "shadowHidden", "hashedVideoID") VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)'; const insertSponsorTimeQuery = 'INSERT INTO "sponsorTimes" ("videoID", "startTime", "endTime", "votes", "UUID", "userID", "timeSubmitted", views, category, "actionType", "shadowHidden", "hashedVideoID") VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)';
db.prepare("run", insertSponsorTimeQuery, ["80percent_video", 0, 1000, 0, "80percent-uuid-0", submitUserOneHash, 0, 0, "interaction", 0, "80percent_video"]); db.prepare("run", insertSponsorTimeQuery, ["80percent_video", 0, 1000, 0, "80percent-uuid-0", submitUserOneHash, 0, 0, "interaction", "skip", 0, "80percent_video"]);
db.prepare("run", insertSponsorTimeQuery, ["80percent_video", 1001, 1005, 0, "80percent-uuid-1", submitUserOneHash, 0, 0, "interaction", 0, "80percent_video"]); db.prepare("run", insertSponsorTimeQuery, ["80percent_video", 1001, 1005, 0, "80percent-uuid-1", submitUserOneHash, 0, 0, "interaction", "skip", 0, "80percent_video"]);
db.prepare("run", insertSponsorTimeQuery, ["80percent_video", 0, 5000, -2, "80percent-uuid-2", submitUserOneHash, 0, 0, "interaction", 0, "80percent_video"]); db.prepare("run", insertSponsorTimeQuery, ["80percent_video", 0, 5000, -2, "80percent-uuid-2", submitUserOneHash, 0, 0, "interaction", "skip", 0, "80percent_video"]);
db.prepare("run", insertSponsorTimeQuery, ["full_video_segment", 0, 0, 0, "full-video-uuid-0", submitUserTwoHash, 0, 0, "sponsor", "full", 0, "full_video_segment"]);
const now = Date.now(); const now = Date.now();
const warnVip01Hash = getHash("warn-vip01-qwertyuiopasdfghjklzxcvbnm"); const warnVip01Hash = getHash("warn-vip01-qwertyuiopasdfghjklzxcvbnm");
@@ -1074,8 +1077,45 @@ describe("postSkipSegments", () => {
actionType: "full", actionType: "full",
userID: submitUserTwo userID: submitUserTwo
}) })
.then(res => { .then(async res => {
assert.strictEqual(res.status, 200); assert.strictEqual(res.status, 200);
const row = await queryDatabase(videoID);
const expected = {
startTime: 0,
endTime: 0,
votes: 0,
userID: submitUserTwoHash,
category: "sponsor",
actionType: "full"
};
assert.ok(partialDeepEquals(row, expected));
done();
})
.catch(err => done(err));
});
it("Submitting duplicate full video sponsor should count as an upvote", (done) => {
const videoID = "full_video_segment";
postSkipSegmentParam({
videoID,
startTime: 0,
endTime: 0,
category: "sponsor",
actionType: "full",
userID: submitUserOne
})
.then(async res => {
assert.strictEqual(res.status, 200);
const row = await queryDatabase(videoID);
const expected = {
startTime: 0,
endTime: 0,
votes: 1,
userID: submitUserTwoHash,
category: "sponsor",
actionType: "full"
};
assert.ok(partialDeepEquals(row, expected));
done(); done();
}) })
.catch(err => done(err)); .catch(err => done(err));