diff --git a/backend/src/utils.test.ts b/backend/src/utils.test.ts index 345c32a3..9d72ce0f 100644 --- a/backend/src/utils.test.ts +++ b/backend/src/utils.test.ts @@ -1,6 +1,10 @@ -import { convertDelayStringToMS, convertMSToDelayString, getUrlsInString } from "./utils"; +import * as ioTs from "io-ts"; +import { convertDelayStringToMS, convertMSToDelayString, getUrlsInString, tAllowedMentions } from "./utils"; import test from "ava"; +import { AllowedMentions as ErisAllowedMentions } from "eris"; + +type AssertEquals = TActual extends TExpected ? true : false; test("getUrlsInString(): detects full links", t => { const urls = getUrlsInString("foo https://google.com/ bar"); @@ -45,3 +49,9 @@ test("delay strings: reverse conversion (conservative)", t => { const expected = "2w"; t.is(convertMSToDelayString(ms), expected); }); + +test("tAllowedMentions matches Eris's AllowedMentions", t => { + type TAllowedMentions = ioTs.TypeOf; + const typeTest: AssertEquals = true; + t.pass(); +}); diff --git a/backend/src/utils.ts b/backend/src/utils.ts index 26889b3d..22fabce5 100644 --- a/backend/src/utils.ts +++ b/backend/src/utils.ts @@ -282,6 +282,16 @@ export const tStrictMessageContent = t.type({ export const tMessageContent = t.union([t.string, tStrictMessageContent]); +/** + * Mirrors AllowedMentions from Eris + */ +export const tAllowedMentions = t.type({ + everyone: tNormalizedNullOptional(t.boolean), + users: tNormalizedNullOptional(t.union([t.boolean, t.array(t.string)])), + roles: tNormalizedNullOptional(t.union([t.boolean, t.array(t.string)])), + repliedUser: tNormalizedNullOptional(t.boolean), +}); + export function dropPropertiesByName(obj, propName) { if (obj.hasOwnProperty(propName)) delete obj[propName]; for (const value of Object.values(obj)) {