31 lines
1.9 KiB
JavaScript
31 lines
1.9 KiB
JavaScript
const {test}=require('node:test');
|
|
const assert=require('node:assert/strict');
|
|
const {classicCommand,classicMode}=require('../.test-build/classic.js');
|
|
const actor={name:'Zaku',autonomy:{managed:true,characterGuid:7,accountId:3}};
|
|
test('Classic transport requires explicit backend selection',()=>{
|
|
assert.equal(classicMode({}),false);
|
|
assert.equal(classicMode({GAME_BACKEND:'cmangos-classic'}),true);
|
|
});
|
|
test('Classic command rejects absent, zero and unmanaged native identities',()=>{
|
|
for(const autonomy of [undefined,{managed:false,characterGuid:7,accountId:3},{managed:true,characterGuid:0,accountId:3},{managed:true,characterGuid:7,accountId:-1}])
|
|
assert.throws(()=>classicCommand('intent',{...actor,autonomy},'quest'));
|
|
assert.throws(()=>classicCommand('party',actor));
|
|
});
|
|
test('Classic peer commands bind both accounts and preserve literal speech',()=>{
|
|
const peer={name:'Alany',autonomy:{managed:true,characterGuid:8,accountId:4}};
|
|
const message='hello "friend"; return 1';
|
|
const command=JSON.parse(classicCommand('say',actor,message,peer));
|
|
assert.equal(command.argument,message);
|
|
assert.equal(command.guid,7);assert.equal(command.accountId,3);
|
|
assert.equal(command.peerGuid,8);assert.equal(command.peerAccountId,4);
|
|
assert.ok(command.expiresAt>Date.now()/1000);
|
|
});
|
|
|
|
test('Classic human replies require authoritative recipient identity',()=>{
|
|
const {classicPlayerReply}=require('../.test-build/classic.js');
|
|
for(const request of [{speakerName:'Endami',channel:'whisper'},{speakerName:'Endami',channel:'say',speakerGuid:-1,speakerAccountId:1}])assert.throws(()=>classicPlayerReply(actor,request,'Hello'));
|
|
const reply=JSON.parse(classicPlayerReply(actor,{speakerName:'Endami',channel:'whisper',speakerGuid:51,speakerAccountId:11},'Hello'));
|
|
assert.equal(reply.kind,'reply-whisper');assert.equal(reply.peerGuid,51);assert.equal(reply.peerAccountId,11);assert.equal(reply.peerName,'Endami');
|
|
assert.equal(reply.guid,7);assert.equal(reply.argument,'Hello');
|
|
});
|