summary refs log tree commit diff homepage
path: root/tests/MinecraftHandler.test.ts
blob: f73d9831b93cae8247c41d54e69a798de10b0c03 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import MinecraftHandler from '../src/MinecraftHandler'

import { defaultConfig } from './constants'

describe('MinecraftHandler', () => {
  it('parses player join connection stat', () => {
    const handler = new MinecraftHandler(defaultConfig)

    const { message } = handler['parseLogLine']('[Server thread/INFO]: destruc7i0n joined the game')!
    
    expect(message).toBe('destruc7i0n joined the game')
  })

  it('parses player leave connection stat', () => {
    const handler = new MinecraftHandler(defaultConfig)

    const { message } = handler['parseLogLine']('[Server thread/INFO]: destruc7i0n left the game')!
    
    expect(message).toBe('destruc7i0n left the game')
  })

  it('parses death messages', () => {
    const handler = new MinecraftHandler(defaultConfig)

    const tests = [
      '[Server thread/INFO]: destruc7i0n drowned',
      '[Server thread/INFO]: destruc7i0n died',
      '[Server thread/INFO]: destruc7i0n experienced kinetic energy',
      '[Server thread/INFO]: destruc7i0n blew up',
      '[Server thread/INFO]: destruc7i0n hit the ground too hard',
      '[Server thread/INFO]: destruc7i0n fell off a ladder',
      '[Server thread/INFO]: destruc7i0n was squashed by a falling anvil',
      '[Server thread/INFO]: destruc7i0n went off with a bang',
      '[Server thread/INFO]: destruc7i0n tried to swim in lava',
      '[Server thread/INFO]: destruc7i0n was slain by mcfunction',
      '[Server thread/INFO]: destruc7i0n suffocated in a wall',
      '[Server thread/INFO]: destruc7i0n fell out of the world',
      '[Server thread/INFO]: destruc7i0n withered away',
    ]

    for (const test of tests) {
      const { message } = handler['parseLogLine'](test)!

      expect(message).toBe(test.replace('[Server thread/INFO]: ', ''))
    }
  })
})