This commit is contained in:
parent
aee0557bb9
commit
4ac6ec0a9d
1 changed files with 66 additions and 0 deletions
66
src/tests/utils/events/citation.test.ts
Normal file
66
src/tests/utils/events/citation.test.ts
Normal file
|
@ -0,0 +1,66 @@
|
||||||
|
import { Attachment, Collection, EmbedBuilder } from "discord.js";
|
||||||
|
import { handleAttachments } from "../../../utils/events/citation";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generate a new random string
|
||||||
|
* @returns random string
|
||||||
|
*/
|
||||||
|
const newKey = () => Math.random().toString(36).substring(2);
|
||||||
|
|
||||||
|
describe("Attachements Handler", () => {
|
||||||
|
const map = new Map([
|
||||||
|
["e_attachements", "yes_s"],
|
||||||
|
["e_attachement", "no_s"],
|
||||||
|
]);
|
||||||
|
{
|
||||||
|
const name = "One image";
|
||||||
|
test(name, () => {
|
||||||
|
const embedExpected = new EmbedBuilder();
|
||||||
|
embedExpected.setImage("http://url");
|
||||||
|
|
||||||
|
const embedTest = new EmbedBuilder();
|
||||||
|
handleAttachments(
|
||||||
|
map,
|
||||||
|
embedTest,
|
||||||
|
new Collection([[newKey(), { name: "image.png", url: "http://url" } as Attachment]]),
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(embedTest).toStrictEqual(embedExpected);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
{
|
||||||
|
const name = "One link";
|
||||||
|
test(name, () => {
|
||||||
|
const embedExpected = new EmbedBuilder();
|
||||||
|
embedExpected.addFields({ name: "no_s", value: "[f](url)" });
|
||||||
|
|
||||||
|
const embedTest = new EmbedBuilder();
|
||||||
|
handleAttachments(
|
||||||
|
map,
|
||||||
|
embedTest,
|
||||||
|
new Collection([[newKey(), { name: "f", url: "url" } as Attachment]]),
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(embedTest).toStrictEqual(embedExpected);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
{
|
||||||
|
const name = "Two files";
|
||||||
|
test(name, () => {
|
||||||
|
const embedExpected = new EmbedBuilder();
|
||||||
|
embedExpected.addFields({ name: "yes_s", value: "[f](url), [f](url)" });
|
||||||
|
|
||||||
|
const embedTest = new EmbedBuilder();
|
||||||
|
handleAttachments(
|
||||||
|
map,
|
||||||
|
embedTest,
|
||||||
|
new Collection([
|
||||||
|
[newKey(), { name: "f", url: "url" } as Attachment],
|
||||||
|
[newKey(), { name: "f", url: "url" } as Attachment],
|
||||||
|
]),
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(embedTest).toStrictEqual(embedExpected);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
Loading…
Reference in a new issue