From 5cf7a61de1508498307db61013cb4eb7f2952a26 Mon Sep 17 00:00:00 2001 From: Michael C Date: Tue, 19 Oct 2021 23:14:52 -0400 Subject: [PATCH] restructure for postgres --- src/routes/voteOnSponsorTime.ts | 3 ++- test/cases/voteOnSponsorTime.ts | 5 ++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/routes/voteOnSponsorTime.ts b/src/routes/voteOnSponsorTime.ts index edfcc61..74d506e 100644 --- a/src/routes/voteOnSponsorTime.ts +++ b/src/routes/voteOnSponsorTime.ts @@ -60,7 +60,8 @@ function getYouTubeVideoInfo(videoID: VideoID, ignoreCache = false): Promise (APIDuration > 0 && Math.abs(segmentDuration - APIDuration) > 2); async function checkVideoDurationChange(UUID: SegmentUUID) { - const { videoDuration, videoID, service } = await db.prepare("get", `select videoDuration, videoID, service from "sponsorTimes" where "UUID" = ?`, [UUID]); + const row = await db.prepare("get", `select videoDuration, videoID, service from "sponsorTimes" where "UUID" = ?`, [UUID]); + const { videoDuration, videoID, service } = row; let apiVideoInfo: APIVideoInfo = null; if (service == Service.YouTube) { // don't use cache since we have no information about the video length diff --git a/test/cases/voteOnSponsorTime.ts b/test/cases/voteOnSponsorTime.ts index 7b814f0..d8cbc81 100644 --- a/test/cases/voteOnSponsorTime.ts +++ b/test/cases/voteOnSponsorTime.ts @@ -99,7 +99,6 @@ describe("voteOnSponsorTime", () => { const getSegmentVotes = (UUID: string) => db.prepare("get", `SELECT "votes" FROM "sponsorTimes" WHERE "UUID" = ?`, [UUID]); const getSegmentCategory = (UUID: string) => db.prepare("get", `SELECT "category" FROM "sponsorTimes" WHERE "UUID" = ?`, [UUID]); - const getVideoDuration = (UUID: string) => db.prepare("get", `SELECT "videoDuration" FROM "sponsorTimes" WHERE "UUID" = ?`, [UUID]).then(row => row.videoDuration); it("Should be able to upvote a segment", (done) => { const UUID = "vote-uuid-0"; @@ -570,8 +569,8 @@ describe("voteOnSponsorTime", () => { postVote(vipUser, UUID, 1) .then(async res => { assert.strictEqual(res.status, 200); - const newDuration = await getVideoDuration(UUID); - assert.strictEqual(newDuration, 500); + const { videoDuration } = await db.prepare("get", `SELECT "videoDuration" FROM "sponsorTimes" WHERE "UUID" = ?`, [UUID]); + assert.strictEqual(videoDuration, 500); done(); }); });