summary refs log tree commit diff homepage
path: root/tests/Discord.test.ts
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--tests/Discord.test.ts42
1 files changed, 42 insertions, 0 deletions
diff --git a/tests/Discord.test.ts b/tests/Discord.test.ts
new file mode 100644
index 0000000..400aa98
--- /dev/null
+++ b/tests/Discord.test.ts
@@ -0,0 +1,42 @@
+import Discord from '../src/Discord'
+
+import { defaultConfig } from './constants'
+
+describe('Discord', () => {
+  describe('replace mentions', () => {
+    test('does not replace mentions if config is disabled', async () => {
+      const discord = new Discord(defaultConfig)
+
+      const replacedMessage = await discord['replaceDiscordMentions']('hey @destruc7i0n#7070')
+      expect(replacedMessage).toBe('hey @destruc7i0n#7070')
+    })
+
+    // test('does replace mentions if config is enabled', async () => {
+    //   const discord = new Discord({...defaultConfig, ALLOW_USER_MENTIONS: true})
+    //   await discord.init()
+
+    //   const replacedMessage = await discord['replaceDiscordMentions']('hey @destruc7i0n#7070')
+    //   expect(replacedMessage).toBe('hey <@129277271843274752>')
+    // })
+
+    test('removes @everyone and @here if disabled', async () => {
+      const discord = new Discord({...defaultConfig, ALLOW_HERE_EVERYONE_MENTIONS: false})
+
+      const everyone = await discord['replaceDiscordMentions']('hey @everyone')
+      const here = await discord['replaceDiscordMentions']('hey @here')
+      
+      expect(everyone).toBe('hey @ everyone')
+      expect(here).toBe('hey @ here')
+    })
+
+    test('keeps @everyone and @here if enabled', async () => {
+      const discord = new Discord({...defaultConfig, ALLOW_HERE_EVERYONE_MENTIONS: true})
+
+      const everyone = await discord['replaceDiscordMentions']('hey @everyone')
+      const here = await discord['replaceDiscordMentions']('hey @here')
+      
+      expect(everyone).toBe('hey @everyone')
+      expect(here).toBe('hey @here')
+    })
+  })
+})
\ No newline at end of file