From da62401f59b2374b834198935f2eec89823669ee Mon Sep 17 00:00:00 2001 From: Keanu Date: Fri, 9 Apr 2021 17:17:25 +0200 Subject: [PATCH] Fixed messageEmbed test, added parseVars lib test. --- .husky/pre-commit | 0 src/lib.test.ts | 8 +++- src/modules/messageEmbed.test.ts | 80 +++++++++++++++----------------- 3 files changed, 44 insertions(+), 44 deletions(-) mode change 100644 => 100755 .husky/pre-commit diff --git a/.husky/pre-commit b/.husky/pre-commit old mode 100644 new mode 100755 diff --git a/src/lib.test.ts b/src/lib.test.ts index 0cd4cc9..b9990b3 100644 --- a/src/lib.test.ts +++ b/src/lib.test.ts @@ -1,5 +1,5 @@ import {strict as assert} from "assert"; -import {pluralise, pluraliseSigned, replaceAll, toTitleCase, split} from "./lib"; +import {pluralise, pluraliseSigned, replaceAll, toTitleCase, split, parseVars} from "./lib"; // I can't figure out a way to run the test suite while running the bot. describe("Wrappers", () => { @@ -52,6 +52,12 @@ describe("Wrappers", () => { }); }); + describe("#parseVars()", () => { + it('should replace %test% with "yeet"', () => { + assert.strictEqual(parseVars("ya %test%", {test: "yeet"}), "ya yeet"); + }); + }); + describe("#toTitleCase()", () => { it("should capitalize the first letter of each word", () => { assert.strictEqual( diff --git a/src/modules/messageEmbed.test.ts b/src/modules/messageEmbed.test.ts index 3508de2..8d70866 100644 --- a/src/modules/messageEmbed.test.ts +++ b/src/modules/messageEmbed.test.ts @@ -1,55 +1,49 @@ jest.useFakeTimers(); import {strict as assert} from "assert"; -//import {extractFirstMessageLink} from "./messageEmbed"; +import {extractFirstMessageLink} from "./messageEmbed"; -/*describe("modules/messageEmbed", () => { - describe("extractFirstMessageLink()", () => { - const guildID = "802906483866631183"; - const channelID = "681747101169682147" - const messageID = "996363055050949479"; - const post = `channels/${guildID}/${channelID}/${messageID}`; - const commonUrl = `https://discord.com/channels/${post}`; - const combined = [guildID, channelID, messageID]; +describe("modules/messageEmbed", () => { + describe("extractFirstMessageLink()", () => { + const guildID = "802906483866631183"; + const channelID = "681747101169682147"; + const messageID = "996363055050949479"; + const post = `channels/${guildID}/${channelID}/${messageID}`; + const commonUrl = `https://discord.com/${post}`; + const combined = [guildID, channelID, messageID]; - it('should return work and extract correctly on an isolated link', () => { - const result = extractFirstMessageLink(commonUrl); - assert.deepStrictEqual(result, combined); - }) + it("should return work and extract correctly on an isolated link", () => { + const result = extractFirstMessageLink(commonUrl); + assert.deepStrictEqual(result, combined); + }); - it('should return work and extract correctly on a link within a message', () => { - const result = extractFirstMessageLink(`sample text${commonUrl}, more sample text`); - assert.deepStrictEqual(result, combined); - }) + it("should return work and extract correctly on a link within a message", () => { + const result = extractFirstMessageLink(`sample text${commonUrl}, more sample text`); + assert.deepStrictEqual(result, combined); + }); - it('should return null on "!link"', () => { - const result = extractFirstMessageLink(`just some !${commonUrl} text`); - assert.strictEqual(result, null); - }) + it('should return null on "!link"', () => { + const result = extractFirstMessageLink(`just some !${commonUrl} text`); + assert.strictEqual(result, null); + }); - it('should return null on ""', () => { - const result = extractFirstMessageLink(`just some <${commonUrl}> text`); - assert.strictEqual(result, null); - }) + it('should return null on ""', () => { + const result = extractFirstMessageLink(`just some <${commonUrl}> text`); + assert.strictEqual(result, null); + }); - it('should return work and extract correctly on " { - const result = extractFirstMessageLink(`just some <${commonUrl} text`); - assert.deepStrictEqual(result, combined); - }) + it('should return work and extract correctly on " { + const result = extractFirstMessageLink(`just some <${commonUrl} text`); + assert.deepStrictEqual(result, combined); + }); - it('should return work and extract correctly on "link>"', () => { - const result = extractFirstMessageLink(`just some ${commonUrl}> text`); - assert.deepStrictEqual(result, combined); - }) + it('should return work and extract correctly on "link>"', () => { + const result = extractFirstMessageLink(`just some ${commonUrl}> text`); + assert.deepStrictEqual(result, combined); + }); - it('should return work and extract correctly on a canary link', () => { - const result = extractFirstMessageLink(`https://canary.discord.com/${post}`); - assert.deepStrictEqual(result, combined); - }) - }) -});*/ - -describe("placeholder", () => { - it("placeholder", async () => { - assert.strictEqual(1, 1); + it("should return work and extract correctly on a canary link", () => { + const result = extractFirstMessageLink(`https://canary.discord.com/${post}`); + assert.deepStrictEqual(result, combined); + }); }); });