62 lines
1.8 KiB
TypeScript
62 lines
1.8 KiB
TypeScript
import { MSG_TYPE, ON_MSG_ROUTE } from './../app/consts';
|
|
import { indexOf } from 'underscore';
|
|
import { COM_TEAM_STATUS, DEFAULT_HEROES } from './../../shared/consts/consts';
|
|
import { Client } from './Client';
|
|
import { COM_BTL_QUALITY } from './../app/consts/constModules/itemConst';
|
|
import 'mocha';
|
|
import { PinusWSClient } from 'pinus-robot-plugin';
|
|
import { expect } from 'chai';
|
|
import { checkDisplayItems, checkSuccessResponse } from './CheckPatten';
|
|
|
|
const TEXT_MSG = {type: MSG_TYPE.TEXT, content: 'hello world'}
|
|
|
|
function sendPrivateMessageParm(targetRoleInfo, msg) {
|
|
const { roleId: targetRoleId, roleName: targetRoleName } = targetRoleInfo;
|
|
const result = {targetRoleId, targetRoleName, ...msg};
|
|
return result;
|
|
}
|
|
|
|
describe('私聊消息发送和接收', function() {
|
|
let pinusClient: PinusWSClient;
|
|
let pinusClientT: PinusWSClient; // 用做测试队友
|
|
let roleInfo;
|
|
let roleInfoT;
|
|
|
|
beforeEach(function(done) {
|
|
const c = new Client();
|
|
const cT = new Client('13121622738');
|
|
const timer = setInterval(() => {
|
|
if (c.client && cT.client) {
|
|
pinusClient = c.client;
|
|
roleInfo = c.roleInfo;
|
|
pinusClientT = cT.client;
|
|
roleInfoT = cT.roleInfo;
|
|
clearInterval(timer);
|
|
done();
|
|
}
|
|
}, 500);
|
|
});
|
|
|
|
afterEach(function(done) {
|
|
pinusClient.disconnect();
|
|
pinusClientT.disconnect();
|
|
done();
|
|
});
|
|
|
|
it('两个玩家互相发送', function(done) {
|
|
pinusClientT.on(ON_MSG_ROUTE, (msg) => {
|
|
console.log(ON_MSG_ROUTE , msg);
|
|
checkSuccessResponse(msg);
|
|
expect(msg.data.content).to.equal(TEXT_MSG.content);
|
|
});
|
|
|
|
pinusClient.request('chat.chatHandler.sendPrivateMessage', sendPrivateMessageParm(roleInfoT, TEXT_MSG), (res) => {
|
|
checkSuccessResponse(res, false);
|
|
setTimeout(() => {
|
|
done();
|
|
}, 200);
|
|
});
|
|
});
|
|
|
|
});
|