diff --git a/src/routes/postWarning.ts b/src/routes/postWarning.ts index e1b1f66..0962c55 100644 --- a/src/routes/postWarning.ts +++ b/src/routes/postWarning.ts @@ -4,6 +4,22 @@ import {db} from "../databases/databases"; import {isUserVIP} from "../utils/isUserVIP"; import {getHash} from "../utils/getHash"; import { HashedUserID, UserID } from "../types/user.model"; +import { config } from "../config"; + +type warningEntry = { + userID: HashedUserID, + issueTime: number, + issuerUserID: HashedUserID, + enabled: boolean, + reason: string +} + +function checkExpiredWarning(warning: warningEntry): boolean { + const MILLISECONDS_IN_HOUR = 3600000; + const now = Date.now(); + const expiry = Math.floor(now - (config.hoursAfterWarningExpires * MILLISECONDS_IN_HOUR)); + return warning.issueTime > expiry && !warning.enabled; +} export async function postWarning(req: Request, res: Response): Promise { // exit early if no body passed in @@ -24,7 +40,7 @@ export async function postWarning(req: Request, res: Response): Promise { }) .catch(err => done(err)); }); + + it("Should re-enable disabled warning", (done: Done) => { + const json = { + issuerUserID: "warning-vip", + userID: "warning-0", + enabled: true + }; + + fetch(`${getbaseURL()}/api/warnUser`, { + method: "POST", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify(json), + }) + .then(async res => { + assert.strictEqual(res.status, 200); + const data = await db.prepare("get", `SELECT "userID", "issueTime", "issuerUserID", enabled FROM warnings WHERE "userID" = ?`, [json.userID]); + assert.strictEqual(data.enabled, 1); + done(); + }) + .catch(err => done(err)); + }); });