-
-
Notifications
You must be signed in to change notification settings - Fork 266
Expand file tree
/
Copy pathdeclareCommandsTest.js
More file actions
58 lines (47 loc) · 1.75 KB
/
declareCommandsTest.js
File metadata and controls
58 lines (47 loc) · 1.75 KB
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
48
49
50
51
52
53
54
55
56
57
58
/* eslint-env mocha */
const assert = require('assert')
const EventEmitter = require('events')
const minecraftDataPath = require.resolve('minecraft-data')
const injectChatPlugin = require('../src/client/chat')
describe('declare_commands handling', () => {
let originalMinecraftData
beforeEach(() => {
originalMinecraftData = require.cache[minecraftDataPath]?.exports
require.cache[minecraftDataPath] = {
exports: () => ({
supportFeature (feature) {
return feature === 'useChatSessions' || feature === 'seperateSignedChatCommandPacket'
}
})
}
})
afterEach(() => {
if (originalMinecraftData) {
require.cache[minecraftDataPath] = { exports: originalMinecraftData }
} else {
delete require.cache[minecraftDataPath]
}
})
it('tracks message arguments from structured declare_commands nodes', () => {
const client = new EventEmitter()
client.version = '26.1'
client.verifyMessage = () => true
client.profileKeys = true
client._session = { uuid: '00000000-0000-0000-0000-000000000000' }
const writes = []
client.write = (name, data) => writes.push({ name, data })
injectChatPlugin(client, {})
client.signMessage = () => Buffer.from([1])
client.emit('declare_commands', {
nodes: [
{ children: [1] },
{ children: [2], extraNodeData: { name: 'msg' } },
{ children: [], extraNodeData: { name: 'message', parser: 'minecraft:message' } }
]
})
client._signedChat('/msg hello there', { timestamp: 1n, salt: 1n })
assert.strictEqual(writes.length, 1)
assert.strictEqual(writes[0].name, 'chat_command_signed')
assert.deepStrictEqual(writes[0].data.argumentSignatures.map(sig => sig.argumentName), ['message'])
})
})