From 85e78d2490e7bdc75e41d335a26f629ec756593d Mon Sep 17 00:00:00 2001 From: Haidang666 Date: Sun, 1 Aug 2021 14:59:25 +0700 Subject: [PATCH 1/3] Use assert in test --- test/cases/dbUpgrade.ts | 8 ++++++-- test/cases/getLockCategoriesByHash.ts | 5 +++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/test/cases/dbUpgrade.ts b/test/cases/dbUpgrade.ts index 8bcc744..c8de4a6 100644 --- a/test/cases/dbUpgrade.ts +++ b/test/cases/dbUpgrade.ts @@ -1,10 +1,14 @@ +import assert from "assert"; + import {db, privateDB} from "../../src/databases/databases"; describe("dbUpgrade", () => { it("Should update the database version when starting the application", async () => { const dbVersion = (await db.prepare("get", "SELECT key, value FROM config where key = ?", ["version"])).value; const privateVersion = (await privateDB.prepare("get", "SELECT key, value FROM config where key = ?", ["version"])).value; - if (dbVersion >= 1 && privateVersion >= 1) return; - else return `Versions are not at least 1. db is ${dbVersion}, private is ${privateVersion}`; + + assert( + dbVersion >= 1 && privateVersion >= 1, + `Versions are not at least 1. db is ${dbVersion}, private is ${privateVersion}`); }); }); diff --git a/test/cases/getLockCategoriesByHash.ts b/test/cases/getLockCategoriesByHash.ts index 710611e..d6ce0b2 100644 --- a/test/cases/getLockCategoriesByHash.ts +++ b/test/cases/getLockCategoriesByHash.ts @@ -24,8 +24,9 @@ describe("getLockCategoriesByHash", () => { it("Database should be greater or equal to version 20", async () => { const version = (await db.prepare("get", "SELECT key, value FROM config where key = ?", ["version"])).value; - if (version >= 20) return; - else return `Version isn't greater than 20. Version is ${version}`; + assert( + version >= 20, + `Version isn't greater than 20. Version is ${version}`); }); it("Should be able to get multiple locks in one object", (done: Done) => { From d4078f0f91f1bceda4623f50632d2d21937b0b11 Mon Sep 17 00:00:00 2001 From: Michael C Date: Sun, 1 Aug 2021 15:00:37 -0400 Subject: [PATCH 2/3] return all from segmentInfo --- src/routes/getSegmentInfo.ts | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/routes/getSegmentInfo.ts b/src/routes/getSegmentInfo.ts index a286992..d789336 100644 --- a/src/routes/getSegmentInfo.ts +++ b/src/routes/getSegmentInfo.ts @@ -6,11 +6,7 @@ const isValidSegmentUUID = (str: string): boolean => /^([a-f0-9]{64}|[a-f0-9]{8} async function getSegmentFromDBByUUID(UUID: SegmentUUID): Promise { try { - return await db.prepare("get", - `SELECT "videoID", "startTime", "endTime", "votes", "locked", - "UUID", "userID", "timeSubmitted", "views", "category", - "service", "videoDuration", "hidden", "reputation", "shadowHidden" FROM "sponsorTimes" - WHERE "UUID" = ?`, [UUID]); + return await db.prepare("get", `SELECT * FROM "sponsorTimes" WHERE "UUID" = ?`, [UUID]); } catch (err) { return null; } From 7dff254604160f5e4d265f3fbc2b0e99322bf567 Mon Sep 17 00:00:00 2001 From: Michael C Date: Sun, 1 Aug 2021 15:27:48 -0400 Subject: [PATCH 3/3] add userAgent to tests --- test/cases/getSegmentInfo.ts | 42 +++++++++++++++++++++++------------- 1 file changed, 27 insertions(+), 15 deletions(-) diff --git a/test/cases/getSegmentInfo.ts b/test/cases/getSegmentInfo.ts index e19f375..c49974b 100644 --- a/test/cases/getSegmentInfo.ts +++ b/test/cases/getSegmentInfo.ts @@ -18,27 +18,34 @@ const fillerID3 = `13${"0".repeat(62)}`; const fillerID4 = `14${"0".repeat(62)}`; const fillerID5 = `15${"0".repeat(62)}`; const oldID = `${"0".repeat(8)}-${"0000-".repeat(3)}${"0".repeat(12)}`; +const userAgents = { + vanced: "Vanced/5.0", + meabot: "Meabot/5.0", + mpv: "mpv_sponsorblock/5.0", + nodesb: "node_sponsorblock/0.2.0", + blank: "" +}; describe("getSegmentInfo", () => { before(async () => { const insertQuery = `INSERT INTO "sponsorTimes"("videoID", "startTime", "endTime", "votes", "locked", "UUID", "userID", "timeSubmitted", "views", "category", "service", - "videoDuration", "hidden", "shadowHidden", "hashedVideoID") - VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`; - await db.prepare("run", insertQuery, ["upvoted", 1, 10, 2, 0, upvotedID, "testman", 0, 50, "sponsor", "YouTube", 100, 0, 0, getHash("upvoted", 1)]); - await db.prepare("run", insertQuery, ["downvoted", 1, 10, -2, 0, downvotedID, "testman", 0, 50, "sponsor", "YouTube", 120, 0, 0, getHash("downvoted", 1)]); - await db.prepare("run", insertQuery, ["locked-up", 1, 10, 2, 1, lockedupID, "testman", 0, 50, "sponsor", "YouTube", 101, 0, 0, getHash("locked-up", 1)]); - await db.prepare("run", insertQuery, ["infvotes", 1, 10, 100000, 0, infvotesID, "testman", 0, 50, "sponsor", "YouTube", 101, 0, 0, getHash("infvotes", 1)]); - await db.prepare("run", insertQuery, ["hidden", 1, 10, 2, 0, hiddenID, "testman", 0, 50, "sponsor", "YouTube", 140, 1, 0, getHash("hidden", 1)]); - await db.prepare("run", insertQuery, ["shadowhidden", 1, 10, 2, 0, shadowhiddenID, "testman", 0, 50, "sponsor", "YouTube", 140, 0, 1, getHash("shadowhidden", 1)]); - await db.prepare("run", insertQuery, ["locked-down", 1, 10, -2, 1, lockeddownID, "testman", 0, 50, "sponsor", "YouTube", 200, 0, 0, getHash("locked-down", 1)]); - await db.prepare("run", insertQuery, ["oldID", 1, 10, 1, 0, oldID, "testman", 0, 50, "sponsor", "YouTube", 300, 0, 0, getHash("oldID", 1)]); - await db.prepare("run", insertQuery, ["filler", 1, 2, 1, 0, fillerID1, "testman", 0, 50, "sponsor", "YouTube", 300, 0, 0, getHash("filler", 1)]); - await db.prepare("run", insertQuery, ["filler", 2, 3, 1, 0, fillerID2, "testman", 0, 50, "sponsor", "YouTube", 300, 0, 0, getHash("filler", 1)]); - await db.prepare("run", insertQuery, ["filler", 3, 4, 1, 0, fillerID3, "testman", 0, 50, "sponsor", "YouTube", 300, 0, 0, getHash("filler", 1)]); - await db.prepare("run", insertQuery, ["filler", 4, 5, 1, 0, fillerID4, "testman", 0, 50, "sponsor", "YouTube", 300, 0, 0, getHash("filler", 1)]); - await db.prepare("run", insertQuery, ["filler", 5, 6, 1, 0, fillerID5, "testman", 0, 50, "sponsor", "YouTube", 300, 0, 0, getHash("filler", 1)]); + "videoDuration", "hidden", "shadowHidden", "hashedVideoID", "userAgent") + VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`; + await db.prepare("run", insertQuery, ["upvoted", 1, 10, 2, 0, upvotedID, "testman", 0, 50, "sponsor", "YouTube", 100, 0, 0, getHash("upvoted", 1), userAgents.vanced]); + await db.prepare("run", insertQuery, ["downvoted", 1, 10, -2, 0, downvotedID, "testman", 0, 50, "sponsor", "YouTube", 120, 0, 0, getHash("downvoted", 1), userAgents.meabot]); + await db.prepare("run", insertQuery, ["locked-up", 1, 10, 2, 1, lockedupID, "testman", 0, 50, "sponsor", "YouTube", 101, 0, 0, getHash("locked-up", 1), userAgents.mpv]); + await db.prepare("run", insertQuery, ["infvotes", 1, 10, 100000, 0, infvotesID, "testman", 0, 50, "sponsor", "YouTube", 101, 0, 0, getHash("infvotes", 1), userAgents.nodesb]); + await db.prepare("run", insertQuery, ["hidden", 1, 10, 2, 0, hiddenID, "testman", 0, 50, "sponsor", "YouTube", 140, 1, 0, getHash("hidden", 1), userAgents.blank]); + await db.prepare("run", insertQuery, ["shadowhidden", 1, 10, 2, 0, shadowhiddenID, "testman", 0, 50, "sponsor", "YouTube", 140, 0, 1, getHash("shadowhidden", 1), userAgents.blank]); + await db.prepare("run", insertQuery, ["locked-down", 1, 10, -2, 1, lockeddownID, "testman", 0, 50, "sponsor", "YouTube", 200, 0, 0, getHash("locked-down", 1), userAgents.blank]); + await db.prepare("run", insertQuery, ["oldID", 1, 10, 1, 0, oldID, "testman", 0, 50, "sponsor", "YouTube", 300, 0, 0, getHash("oldID", 1), userAgents.blank]); + await db.prepare("run", insertQuery, ["filler", 1, 2, 1, 0, fillerID1, "testman", 0, 50, "sponsor", "YouTube", 300, 0, 0, getHash("filler", 1), userAgents.blank]); + await db.prepare("run", insertQuery, ["filler", 2, 3, 1, 0, fillerID2, "testman", 0, 50, "sponsor", "YouTube", 300, 0, 0, getHash("filler", 1), userAgents.blank]); + await db.prepare("run", insertQuery, ["filler", 3, 4, 1, 0, fillerID3, "testman", 0, 50, "sponsor", "YouTube", 300, 0, 0, getHash("filler", 1), userAgents.blank]); + await db.prepare("run", insertQuery, ["filler", 4, 5, 1, 0, fillerID4, "testman", 0, 50, "sponsor", "YouTube", 300, 0, 0, getHash("filler", 1), userAgents.blank]); + await db.prepare("run", insertQuery, ["filler", 5, 6, 1, 0, fillerID5, "testman", 0, 50, "sponsor", "YouTube", 300, 0, 0, getHash("filler", 1), userAgents.blank]); }); it("Should be able to retreive upvoted segment", (done: Done) => { @@ -48,6 +55,7 @@ describe("getSegmentInfo", () => { const data = await res.json(); assert.strictEqual(data[0].videoID, "upvoted"); assert.strictEqual(data[0].votes, 2); + assert.strictEqual(data[0].userAgent, userAgents.vanced); done(); }) .catch(err => done(err)); @@ -60,6 +68,7 @@ describe("getSegmentInfo", () => { const data = await res.json(); assert.strictEqual(data[0].videoID, "downvoted"); assert.strictEqual(data[0].votes, -2); + assert.strictEqual(data[0].userAgent, userAgents.meabot); done(); }) .catch(err => done(err)); @@ -73,6 +82,7 @@ describe("getSegmentInfo", () => { assert.strictEqual(data[0].videoID, "locked-up"); assert.strictEqual(data[0].locked, 1); assert.strictEqual(data[0].votes, 2); + assert.strictEqual(data[0].userAgent, userAgents.mpv); done(); }) .catch(err => done(err)); @@ -85,6 +95,7 @@ describe("getSegmentInfo", () => { const data = await res.json(); assert.strictEqual(data[0].videoID, "infvotes"); assert.strictEqual(data[0].votes, 100000); + assert.strictEqual(data[0].userAgent, userAgents.nodesb); done(); }) .catch(err => done(err)); @@ -97,6 +108,7 @@ describe("getSegmentInfo", () => { const data = await res.json(); assert.strictEqual(data[0].videoID, "shadowhidden"); assert.strictEqual(data[0].shadowHidden, 1); + assert.strictEqual(data[0].userAgent, userAgents.blank); done(); }) .catch(err => done(err));