diff --git a/DatabaseSchema.md b/DatabaseSchema.md index abb0539..6814131 100644 --- a/DatabaseSchema.md +++ b/DatabaseSchema.md @@ -1,4 +1,4 @@ -# SponsorTimesDB +# SponsorTimesDB [vipUsers](#vipUsers) [sponsorTimes](#sponsorTimes) @@ -28,17 +28,17 @@ | startTime | REAL | not null | | endTime | REAL | not null | | votes | INTEGER | not null | -| locked | INTEGER | not nul, default '0' | +| locked | INTEGER | not null, default '0' | | incorrectVotes | INTEGER | not null, default 1 | | UUID | TEXT | not null, unique | | userID | TEXT | not null | | timeSubmitted | INTEGER | not null | | views | INTEGER | not null | | category | TEXT | not null, default 'sponsor' | -| service | TEXT | not nul, default 'Youtube' | -| videoDuration | INTEGER | not nul, default '0' | -| hidden | INTEGER | not nul, default '0' | -| reputation | REAL | not nul, default '0' | +| service | TEXT | not null, default 'Youtube' | +| videoDuration | INTEGER | not null, default '0' | +| hidden | INTEGER | not null, default '0' | +| reputation | REAL | not null, default '0' | | shadowHidden | INTEGER | not null | | hashedVideoID | TEXT | not null, default '', sha256 | @@ -91,6 +91,7 @@ | videoID | TEXT | not null | | userID | TEXT | not null | | category | TEXT | not null | +| hashedVideoID | TEXT | not null, default '' | | index | field | | -- | :--: | diff --git a/src/routes/postLockCategories.ts b/src/routes/postLockCategories.ts index a328367..767fba3 100644 --- a/src/routes/postLockCategories.ts +++ b/src/routes/postLockCategories.ts @@ -3,6 +3,7 @@ import {getHash} from '../utils/getHash'; import {isUserVIP} from '../utils/isUserVIP'; import {db} from '../databases/databases'; import {Request, Response} from 'express'; +import { VideoIDHash } from "../types/segments.model"; export async function postLockCategories(req: Request, res: Response): Promise { // Collect user input data @@ -56,10 +57,13 @@ export async function postLockCategories(req: Request, res: Response): Promise { }) .catch(err => done(err)); }); + + it('should be able to get existing category lock', (done: Done) => { + const expected = { + categories: [ + 'sponsor', + 'intro', + 'outro', + 'shilling' + ], + }; + + fetch(getbaseURL() + "/api/lockCategories?videoID=" + "no-segments-video-id") + .then(async res => { + if (res.status === 200) { + const data = await res.json(); + if (JSON.stringify(data) === JSON.stringify(expected)) { + done(); + } else { + done("Incorrect response: expected " + JSON.stringify(expected) + " got " + JSON.stringify(data)); + } + } else { + done("Status code was " + res.status); + } + }) + .catch(err => done(err)); + }); + + it('Should be able to get hashedVideoID from lock', (done: Done) => { + const hashedVideoID = getHash('no-segments-video-id', 1); + db.prepare('get', 'SELECT "hashedVideoID" FROM "lockCategories" WHERE "videoID" = ?', ['no-segments-video-id']) + .then(result => { + if (result !== hashedVideoID) { + done(); + } else { + done("Got unexpected video hash " + result); + } + }); + }); });