2021-06-06 23:51:32 +02:00
|
|
|
import test from "ava";
|
2021-04-29 00:48:37 +03:00
|
|
|
import * as ioTs from "io-ts";
|
|
|
|
import { convertDelayStringToMS, convertMSToDelayString, getUrlsInString, tAllowedMentions } from "./utils";
|
2021-06-02 19:35:44 +02:00
|
|
|
import { ErisAllowedMentionFormat } from "./utils/erisAllowedMentionsToDjsMentionOptions";
|
2021-04-29 00:48:37 +03:00
|
|
|
|
|
|
|
type AssertEquals<TActual, TExpected> = TActual extends TExpected ? true : false;
|
2019-11-27 20:41:45 +02:00
|
|
|
|
2021-09-11 19:06:51 +03:00
|
|
|
test("getUrlsInString(): detects full links", (t) => {
|
2019-11-27 20:41:45 +02:00
|
|
|
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) => {
|
2019-11-27 20:41:45 +02:00
|
|
|
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) => {
|
2019-11-27 20:41:45 +02:00
|
|
|
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-04-29 00:48:37 +03:00
|
|
|
|
2021-09-11 19:06:51 +03:00
|
|
|
test("tAllowedMentions matches Eris's AllowedMentions", (t) => {
|
2021-04-29 00:48:37 +03:00
|
|
|
type TAllowedMentions = ioTs.TypeOf<typeof tAllowedMentions>;
|
2023-05-08 22:58:51 +03:00
|
|
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
2021-06-02 19:35:44 +02:00
|
|
|
const typeTest: AssertEquals<TAllowedMentions, ErisAllowedMentionFormat> = true;
|
2021-04-29 00:48:37 +03:00
|
|
|
t.pass();
|
|
|
|
});
|