Skip to content

Commit

Permalink
test(thumbnailVotes): impl createdAt and updatedAt
Browse files Browse the repository at this point in the history
  • Loading branch information
TristanWasTaken committed Sep 16, 2024
1 parent e69cbd6 commit 4a4c050
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 31 deletions.
28 changes: 14 additions & 14 deletions test/cases/getBranding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ describe("getBranding", () => {
const titleVotesQuery = `INSERT INTO "titleVotes" ("UUID", "votes", "locked", "shadowHidden", "verification", "downvotes", "removed", "createdAt", "updatedAt") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)`;
const thumbnailQuery = `INSERT INTO "thumbnails" ("videoID", "original", "userID", "service", "hashedVideoID", "timeSubmitted", "UUID") VALUES (?, ?, ?, ?, ?, ?, ?)`;
const thumbnailTimestampsQuery = `INSERT INTO "thumbnailTimestamps" ("UUID", "timestamp") VALUES (?, ?)`;
const thumbnailVotesQuery = `INSERT INTO "thumbnailVotes" ("UUID", "votes", "locked", "shadowHidden", "downvotes", "removed") VALUES (?, ?, ?, ?, ?, ?)`;
const thumbnailVotesQuery = `INSERT INTO "thumbnailVotes" ("UUID", "votes", "locked", "shadowHidden", "downvotes", "removed", "createdAt", "updatedAt") VALUES (?, ?, ?, ?, ?, ?, ?, ?)`;
const segmentQuery = 'INSERT INTO "sponsorTimes" ("videoID", "startTime", "endTime", "votes", "locked", "UUID", "userID", "timeSubmitted", "views", "category", "actionType", "service", "videoDuration", "hidden", "shadowHidden", "description", "hashedVideoID", "updatedAt") VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)';

await Promise.all([
Expand All @@ -64,10 +64,10 @@ describe("getBranding", () => {
db.prepare("run", thumbnailTimestampsQuery, ["UUID1T", 1]),
db.prepare("run", thumbnailTimestampsQuery, ["UUID3T", 3]),
db.prepare("run", thumbnailTimestampsQuery, ["UUID4T", 18]),
db.prepare("run", thumbnailVotesQuery, ["UUID1T", 3, 0, 0, 0, 0]),
db.prepare("run", thumbnailVotesQuery, ["UUID2T", 3, 0, 0, 1, 0]),
db.prepare("run", thumbnailVotesQuery, ["UUID3T", 1, 0, 0, 0, 0]),
db.prepare("run", thumbnailVotesQuery, ["UUID4T", 5, 0, 0, 0, 1])
db.prepare("run", thumbnailVotesQuery, ["UUID1T", 3, 0, 0, 0, 0, isoDate, isoDate]),
db.prepare("run", thumbnailVotesQuery, ["UUID2T", 3, 0, 0, 1, 0, isoDate, isoDate]),
db.prepare("run", thumbnailVotesQuery, ["UUID3T", 1, 0, 0, 0, 0, isoDate, isoDate]),
db.prepare("run", thumbnailVotesQuery, ["UUID4T", 5, 0, 0, 0, 1, isoDate, isoDate])
]);

await Promise.all([
Expand All @@ -86,9 +86,9 @@ describe("getBranding", () => {

db.prepare("run", thumbnailTimestampsQuery, ["UUID11T", 1]),
db.prepare("run", thumbnailTimestampsQuery, ["UUID31T", 3]),
db.prepare("run", thumbnailVotesQuery, ["UUID11T", 3, 0, 0, 0, 0]),
db.prepare("run", thumbnailVotesQuery, ["UUID21T", 2, 0, 0, 0, 0]),
db.prepare("run", thumbnailVotesQuery, ["UUID31T", 1, 1, 0, 0, 0]),
db.prepare("run", thumbnailVotesQuery, ["UUID11T", 3, 0, 0, 0, 0, isoDate, isoDate]),
db.prepare("run", thumbnailVotesQuery, ["UUID21T", 2, 0, 0, 0, 0, isoDate, isoDate]),
db.prepare("run", thumbnailVotesQuery, ["UUID31T", 1, 1, 0, 0, 0, isoDate, isoDate]),
]);

await Promise.all([
Expand All @@ -106,9 +106,9 @@ describe("getBranding", () => {
db.prepare("run", titleVotesQuery, ["UUID32", 1, 0, 1, 0, 0, 0, isoDate, isoDate]),
db.prepare("run", thumbnailTimestampsQuery, ["UUID12T", 1]),
db.prepare("run", thumbnailTimestampsQuery, ["UUID32T", 3]),
db.prepare("run", thumbnailVotesQuery, ["UUID12T", 3, 0, 0, 0, 0]),
db.prepare("run", thumbnailVotesQuery, ["UUID22T", 2, 0, 0, 0, 0]),
db.prepare("run", thumbnailVotesQuery, ["UUID32T", 1, 0, 1, 0, 0])
db.prepare("run", thumbnailVotesQuery, ["UUID12T", 3, 0, 0, 0, 0, isoDate, isoDate]),
db.prepare("run", thumbnailVotesQuery, ["UUID22T", 2, 0, 0, 0, 0, isoDate, isoDate]),
db.prepare("run", thumbnailVotesQuery, ["UUID32T", 1, 0, 1, 0, 0, isoDate, isoDate])
]);

await db.prepare("run", segmentQuery, [videoIDRandomTime, 1, 11, 1, 0, "uuidbranding1", "testman", 0, 50, "sponsor", "skip", "YouTube", 100, 0, 0, "", videoIDRandomTimeHash, isoDate]);
Expand All @@ -129,9 +129,9 @@ describe("getBranding", () => {
db.prepare("run", titleVotesQuery, ["UUID-uv-3", 0, 0, 0, -1, 0, 0, isoDate, isoDate]),
db.prepare("run", thumbnailTimestampsQuery, ["UUID-uv-1T", 1]),
db.prepare("run", thumbnailTimestampsQuery, ["UUID-uv-3T", 3]),
db.prepare("run", thumbnailVotesQuery, ["UUID-uv-1T", 3, 0, 0, 0, 0]),
db.prepare("run", thumbnailVotesQuery, ["UUID-uv-2T", 2, 0, 0, 0, 0]),
db.prepare("run", thumbnailVotesQuery, ["UUID-uv-3T", 1, 0, 0, 0, 0])
db.prepare("run", thumbnailVotesQuery, ["UUID-uv-1T", 3, 0, 0, 0, 0, isoDate, isoDate]),
db.prepare("run", thumbnailVotesQuery, ["UUID-uv-2T", 2, 0, 0, 0, 0, isoDate, isoDate]),
db.prepare("run", thumbnailVotesQuery, ["UUID-uv-3T", 1, 0, 0, 0, 0, isoDate, isoDate])
]);

// Video duration test segments
Expand Down
14 changes: 7 additions & 7 deletions test/cases/postBranding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ describe("postBranding", () => {
const insertThumbnailQuery = 'INSERT INTO "thumbnails" ("videoID", "original", "userID", "service", "hashedVideoID", "timeSubmitted", "UUID") VALUES (?, ?, ?, ?, ?, ?, ?)';
await db.prepare("run", insertThumbnailQuery, ["postBrandLocked1", 0, getHash(userID3), Service.YouTube, getHash("postBrandLocked1"), Date.now(), "postBrandLocked1"]);
await db.prepare("run", insertThumbnailQuery, ["postBrandLocked2", 1, getHash(userID4), Service.YouTube, getHash("postBrandLocked2"), Date.now(), "postBrandLocked2"]);
const insertThumbnailVotesQuery = 'INSERT INTO "thumbnailVotes" ("UUID", "votes", "locked", "shadowHidden") VALUES (?, ?, ?, ?);';
await db.prepare("run", insertThumbnailVotesQuery, ["postBrandLocked1", 0, 1, 0]);
await db.prepare("run", insertThumbnailVotesQuery, ["postBrandLocked2", 0, 1, 0]);
const insertThumbnailVotesQuery = 'INSERT INTO "thumbnailVotes" ("UUID", "votes", "locked", "shadowHidden", "createdAt", "updatedAt") VALUES (?, ?, ?, ?, ?, ?);';
await db.prepare("run", insertThumbnailVotesQuery, ["postBrandLocked1", 0, 1, 0, isoDate, isoDate]);
await db.prepare("run", insertThumbnailVotesQuery, ["postBrandLocked2", 0, 1, 0, isoDate, isoDate]);

// Testing vip submission removal
await db.prepare("run", insertTitleQuery, ["postBrandRemoved1", "Some title", 0, getHash(userID1), Service.YouTube, getHash("postBrandRemoved1"), Date.now(), "postBrandRemoved1"]);
Expand All @@ -64,10 +64,10 @@ describe("postBranding", () => {
const insertThumbnailTimestampQuery = 'INSERT INTO "thumbnailTimestamps" ("UUID", "timestamp") VALUES (?, ?)';
await db.prepare("run", insertThumbnailQuery, ["postBrandRemoved1", 0, getHash(userID3), Service.YouTube, getHash("postBrandRemoved1"), Date.now(), "postBrandRemoved1"]);
await db.prepare("run", insertThumbnailTimestampQuery, ["postBrandRemoved1", 12.34]);
await db.prepare("run", insertThumbnailVotesQuery, ["postBrandRemoved1", 0, 1, 0]);
await db.prepare("run", insertThumbnailVotesQuery, ["postBrandRemoved1", 0, 1, 0, isoDate, isoDate]);
await db.prepare("run", insertThumbnailQuery, ["postBrandRemoved1", 0, getHash(userID3), Service.YouTube, getHash("postBrandRemoved1"), Date.now(), "postBrandRemoved2"]);
await db.prepare("run", insertThumbnailTimestampQuery, ["postBrandRemoved2", 13.34]);
await db.prepare("run", insertThumbnailVotesQuery, ["postBrandRemoved2", 0, 1, 0]);
await db.prepare("run", insertThumbnailVotesQuery, ["postBrandRemoved2", 0, 1, 0, isoDate, isoDate]);

// Verified through title submissions
await db.prepare("run", insertTitleQuery, ["postBrandVerified1", "Some title", 0, getHash(userID7), Service.YouTube, getHash("postBrandVerified1"), Date.now(), "postBrandVerified1"]);
Expand All @@ -82,8 +82,8 @@ describe("postBranding", () => {
await db.prepare("run", insertTitleVotesQuery, ["postBrandBannedOriginalVote", 0, 0, 0, 0, isoDate, isoDate]);
await db.prepare("run", insertThumbnailQuery, ["postBrandBannedCustomVote", 0, getHash(userID1), Service.YouTube, getHash("postBrandBannedCustomVote"), Date.now(), "postBrandBannedCustomVote"]);
await db.prepare("run", insertThumbnailQuery, ["postBrandBannedOriginalVote", 1, getHash(userID1), Service.YouTube, getHash("postBrandBannedOriginalVote"), Date.now(), "postBrandBannedOriginalVote"]);
await db.prepare("run", insertThumbnailVotesQuery, ["postBrandBannedCustomVote", 0, 0, 0]);
await db.prepare("run", insertThumbnailVotesQuery, ["postBrandBannedOriginalVote", 0, 0, 0]);
await db.prepare("run", insertThumbnailVotesQuery, ["postBrandBannedCustomVote", 0, 0, 0, isoDate, isoDate]);
await db.prepare("run", insertThumbnailVotesQuery, ["postBrandBannedOriginalVote", 0, 0, 0, isoDate, isoDate]);
await db.prepare("run", insertThumbnailTimestampQuery, ["postBrandBannedCustomVote", 12.34]);
});

Expand Down
14 changes: 7 additions & 7 deletions test/cases/shadowBanUser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ describe("shadowBanUser", () => {
const titleVotesQuery = `INSERT INTO "titleVotes" ("UUID", "votes", "locked", "shadowHidden", "verification", "createdAt", "updatedAt") VALUES (?, ?, ?, ?, ?, ?, ?)`;
const thumbnailQuery = `INSERT INTO "thumbnails" ("videoID", "original", "userID", "service", "hashedVideoID", "timeSubmitted", "UUID") VALUES (?, ?, ?, ?, ?, ?, ?)`;
const thumbnailTimestampsQuery = `INSERT INTO "thumbnailTimestamps" ("UUID", "timestamp") VALUES (?, ?)`;
const thumbnailVotesQuery = `INSERT INTO "thumbnailVotes" ("UUID", "votes", "locked", "shadowHidden") VALUES (?, ?, ?, ?)`;
const thumbnailVotesQuery = `INSERT INTO "thumbnailVotes" ("UUID", "votes", "locked", "shadowHidden", "createdAt", "updatedAt") VALUES (?, ?, ?, ?, ?, ?)`;

await Promise.all([
db.prepare("run", titleQuery, [video, "title1", 0, "userID1-ban", Service.YouTube, videohash, 1, "UUID1-ban"]),
Expand All @@ -78,9 +78,9 @@ describe("shadowBanUser", () => {
db.prepare("run", titleVotesQuery, ["UUID3-ban", 1, 0, 0, 0, isoDate, isoDate]),
db.prepare("run", thumbnailTimestampsQuery, ["UUID1T-ban", 1]),
db.prepare("run", thumbnailTimestampsQuery, ["UUID3T-ban", 3]),
db.prepare("run", thumbnailVotesQuery, ["UUID1T-ban", 3, 0, 0]),
db.prepare("run", thumbnailVotesQuery, ["UUID2T-ban", 2, 0, 0]),
db.prepare("run", thumbnailVotesQuery, ["UUID3T-ban", 1, 0, 0]),
db.prepare("run", thumbnailVotesQuery, ["UUID1T-ban", 3, 0, 0, isoDate, isoDate]),
db.prepare("run", thumbnailVotesQuery, ["UUID2T-ban", 2, 0, 0, isoDate, isoDate]),
db.prepare("run", thumbnailVotesQuery, ["UUID3T-ban", 1, 0, 0, isoDate, isoDate]),
]);

await Promise.all([
Expand All @@ -98,9 +98,9 @@ describe("shadowBanUser", () => {
db.prepare("run", titleVotesQuery, ["UUID3-ban2", 1, 0, 0, 0, isoDate, isoDate]),
db.prepare("run", thumbnailTimestampsQuery, ["UUID1T-ban2", 1]),
db.prepare("run", thumbnailTimestampsQuery, ["UUID3T-ban2", 3]),
db.prepare("run", thumbnailVotesQuery, ["UUID1T-ban2", 3, 0, 0]),
db.prepare("run", thumbnailVotesQuery, ["UUID2T-ban2", 2, 0, 0]),
db.prepare("run", thumbnailVotesQuery, ["UUID3T-ban2", 1, 0, 0])
db.prepare("run", thumbnailVotesQuery, ["UUID1T-ban2", 3, 0, 0, isoDate, isoDate]),
db.prepare("run", thumbnailVotesQuery, ["UUID2T-ban2", 2, 0, 0, isoDate, isoDate]),
db.prepare("run", thumbnailVotesQuery, ["UUID3T-ban2", 1, 0, 0, isoDate, isoDate])
]);

await Promise.all([
Expand Down
6 changes: 3 additions & 3 deletions test/utils/segmentQueryGen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,8 @@ export const insertThumbnail = async (db: IDatabase, overrides: insertThumbnailP
await db.prepare("run", query, Object.values(params));
};

export const insertThumbnailVote = async (db: IDatabase, UUID: string, votes: number, locked = false, shadowHidden = false) => {
const query = 'INSERT INTO "thumbnailVotes" ("UUID", "votes", "locked", "shadowHidden") VALUES (?, ?, ?, ?)';
const params = [UUID, votes, Number(locked), Number(shadowHidden)];
export const insertThumbnailVote = async (db: IDatabase, UUID: string, votes: number, locked = false, shadowHidden = false, isoDate: string = new Date().toISOString()) => {
const query = 'INSERT INTO "thumbnailVotes" ("UUID", "votes", "locked", "shadowHidden", "createdAt", "updatedAt") VALUES (?, ?, ?, ?, ?, ?)';
const params = [UUID, votes, Number(locked), Number(shadowHidden), isoDate, isoDate];
await db.prepare("run", query, params);
};

0 comments on commit 4a4c050

Please sign in to comment.