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.ts43
1 files changed, 40 insertions, 3 deletions
diff --git a/tests/Discord.test.ts b/tests/Discord.test.ts
index 400aa98..2c47b75 100644
--- a/tests/Discord.test.ts
+++ b/tests/Discord.test.ts
@@ -4,7 +4,7 @@ import { defaultConfig } from './constants'
 
 describe('Discord', () => {
   describe('replace mentions', () => {
-    test('does not replace mentions if config is disabled', async () => {
+    it('does not replace mentions if config is disabled', async () => {
       const discord = new Discord(defaultConfig)
 
       const replacedMessage = await discord['replaceDiscordMentions']('hey @destruc7i0n#7070')
@@ -19,7 +19,7 @@ describe('Discord', () => {
     //   expect(replacedMessage).toBe('hey <@129277271843274752>')
     // })
 
-    test('removes @everyone and @here if disabled', async () => {
+    it('removes @everyone and @here if disabled', async () => {
       const discord = new Discord({...defaultConfig, ALLOW_HERE_EVERYONE_MENTIONS: false})
 
       const everyone = await discord['replaceDiscordMentions']('hey @everyone')
@@ -29,7 +29,7 @@ describe('Discord', () => {
       expect(here).toBe('hey @ here')
     })
 
-    test('keeps @everyone and @here if enabled', async () => {
+    it('keeps @everyone and @here if enabled', async () => {
       const discord = new Discord({...defaultConfig, ALLOW_HERE_EVERYONE_MENTIONS: true})
 
       const everyone = await discord['replaceDiscordMentions']('hey @everyone')
@@ -39,4 +39,41 @@ describe('Discord', () => {
       expect(here).toBe('hey @here')
     })
   })
+
+  describe('minecraft messages', () => {
+    it('correctly generates a tellraw string in messages', async () => {
+      const discord = new Discord(defaultConfig)
+
+      const message = discord['makeMinecraftMessage']({ author: { username: 'destruc7i0n', discriminator: '7070' }, member: { nickname: 't70' }, cleanContent: 'test' } as any)
+      expect(message).toBe('[{"color": "white", "text": "<@destruc7i0n> test"}]')
+    })
+
+    it('correctly generates a tellraw string with unicode characters in message', async () => {
+      const discord = new Discord(defaultConfig)
+
+      const message = discord['makeMinecraftMessage']({ author: { username: 'destruc7i0n', discriminator: '7070' }, member: { nickname: 't70' }, cleanContent: 'æ, ø, å (Æ, Ø, Å) 건희' } as any)
+      expect(message).toBe('[{"color": "white", "text": "<@destruc7i0n> \\u00e6, \\u00f8, \\u00e5 (\\u00c6, \\u00d8, \\u00c5) \\uac74\\ud76c"}]')
+    })
+
+    it('correctly generates a tellraw string with unicode characters in username ', async () => {
+      const discord = new Discord(defaultConfig)
+
+      const message = discord['makeMinecraftMessage']({ author: { username: '건희destruc7i0n건희', discriminator: '7070' }, member: { nickname: 't70' }, cleanContent: 'huh' } as any)
+      expect(message).toBe('[{"color": "white", "text": "<@\\uac74\\ud76cdestruc7i0n\\uac74\\ud76c> huh"}]')
+    })
+
+    it('correctly replaces all parts of a message string', () => {
+      const discord = new Discord({ ...defaultConfig, MINECRAFT_TELLRAW_TEMPLATE: '[{\"color\": \"white\", \"text\": \"<@%username%#%discriminator% (%nickname%)> %message%\"}]' })
+      
+      const message = discord['makeMinecraftMessage']({ author: { username: 'destruc7i0n', discriminator: '7070' }, member: { nickname: 't70' }, cleanContent: 'test' } as any)
+      expect(message).toBe('[{\"color\": \"white\", \"text\": \"<@destruc7i0n#7070 (t70)> test\"}]')
+    })
+
+    it('correctly replaces all parts of a message string with unicode everywhere', () => {
+      const discord = new Discord({ ...defaultConfig, MINECRAFT_TELLRAW_TEMPLATE: '[{\"color\": \"white\", \"text\": \"<@%username%#%discriminator% (%nickname%)> %message%\"}]' })
+      
+      const message = discord['makeMinecraftMessage']({ author: { username: '건희destruc7i0n건희', discriminator: '7070' }, member: { nickname: '건희t70건희' }, cleanContent: 'æ, ø, å (Æ, Ø, Å) 건희' } as any)
+      expect(message).toBe('[{\"color\": \"white\", \"text\": \"<@\\uac74\\ud76cdestruc7i0n\\uac74\\ud76c#7070 (\\uac74\\ud76ct70\\uac74\\ud76c)> \\u00e6, \\u00f8, \\u00e5 (\\u00c6, \\u00d8, \\u00c5) \\uac74\\ud76c\"}]')
+    })
+  })
 })
\ No newline at end of file