3
0
Fork 0
mirror of https://github.com/ZeppelinBot/Zeppelin.git synced 2025-03-16 22:21:51 +00:00
zeppelin/backend/src/utils.test.ts

58 lines
1.9 KiB
TypeScript
Raw Normal View History

import test from "ava";
2024-01-14 14:25:42 +00:00
import z from "zod";
import { convertDelayStringToMS, convertMSToDelayString, getUrlsInString, zAllowedMentions } from "./utils";
2021-06-02 19:35:44 +02:00
import { ErisAllowedMentionFormat } from "./utils/erisAllowedMentionsToDjsMentionOptions";
type AssertEquals<TActual, TExpected> = TActual extends TExpected ? true : false;
2021-09-11 19:06:51 +03:00
test("getUrlsInString(): detects full links", (t) => {
const urls = getUrlsInString("foo https://google.com/ bar");
t.is(urls.length, 1);
t.is(urls[0].hostname, "google.com");
});
2021-09-11 19:06:51 +03:00
test("getUrlsInString(): detects partial links", (t) => {
const urls = getUrlsInString("foo google.com bar");
t.is(urls.length, 1);
t.is(urls[0].hostname, "google.com");
});
2021-09-11 19:06:51 +03:00
test("getUrlsInString(): detects subdomains", (t) => {
const urls = getUrlsInString("foo photos.google.com bar");
t.is(urls.length, 1);
t.is(urls[0].hostname, "photos.google.com");
});
2019-12-01 15:57:35 +02:00
2021-09-11 19:06:51 +03:00
test("delay strings: basic support", (t) => {
2019-12-01 15:57:35 +02:00
const delayString = "2w4d7h32m17s";
const expected = 1_582_337_000;
t.is(convertDelayStringToMS(delayString), expected);
});
2021-09-11 19:06:51 +03:00
test("delay strings: default unit (minutes)", (t) => {
2019-12-01 15:57:35 +02:00
t.is(convertDelayStringToMS("10"), 10 * 60 * 1000);
});
2021-09-11 19:06:51 +03:00
test("delay strings: custom default unit", (t) => {
2019-12-01 15:57:35 +02:00
t.is(convertDelayStringToMS("10", "s"), 10 * 1000);
});
2021-09-11 19:06:51 +03:00
test("delay strings: reverse conversion", (t) => {
2019-12-01 15:57:35 +02:00
const ms = 1_582_337_020;
const expected = "2w4d7h32m17s20x";
t.is(convertMSToDelayString(ms), expected);
});
2021-09-11 19:06:51 +03:00
test("delay strings: reverse conversion (conservative)", (t) => {
2019-12-01 15:57:35 +02:00
const ms = 1_209_600_000;
const expected = "2w";
t.is(convertMSToDelayString(ms), expected);
});
2021-09-11 19:06:51 +03:00
test("tAllowedMentions matches Eris's AllowedMentions", (t) => {
2024-01-14 14:25:42 +00:00
type TAllowedMentions = z.infer<typeof zAllowedMentions>;
// eslint-disable-next-line @typescript-eslint/no-unused-vars
2021-06-02 19:35:44 +02:00
const typeTest: AssertEquals<TAllowedMentions, ErisAllowedMentionFormat> = true;
t.pass();
});