203 lines
9.0 KiB
TypeScript
203 lines
9.0 KiB
TypeScript
import 'mocha';
|
|
import { PinusWSClient, PinusWSClientEvent } from 'pinus-robot-plugin';
|
|
import { expect } from 'chai';
|
|
describe('军团测试', function() {
|
|
// it('异步请求应该返回一个对象', function(done){
|
|
// request
|
|
// .get('https://api.github.com')
|
|
// .end(function(err, res){
|
|
// expect(res).to.be.an('object');
|
|
// done();
|
|
// });
|
|
// });
|
|
var pinusClient;
|
|
var roleInfo;
|
|
let guildList;
|
|
|
|
beforeEach(function(done) {
|
|
pinusClient = new PinusWSClient();
|
|
pinusClient.on(PinusWSClientEvent.EVENT_IO_ERROR, (event) => {
|
|
// 错误处理
|
|
// console.error('error', event);
|
|
done();
|
|
});
|
|
pinusClient.on(PinusWSClientEvent.EVENT_CLOSE, function(event) {
|
|
// 关闭处理
|
|
// console.error('close', event);
|
|
done();
|
|
});
|
|
pinusClient.on(PinusWSClientEvent.EVENT_HEART_BEAT_TIMEOUT, function(event) {
|
|
// 心跳timeout
|
|
// console.error('heart beat timeout', event);
|
|
});
|
|
pinusClient.on(PinusWSClientEvent.EVENT_KICK, function(event) {
|
|
// 踢出
|
|
// console.error('kick', event);
|
|
});
|
|
let host = '127.0.0.1';
|
|
let port = '3050';
|
|
pinusClient.init({
|
|
host: host,
|
|
port: port
|
|
}, (data) => {
|
|
// 连接成功执行函数
|
|
console.log('gate连接成功', data);
|
|
// done();
|
|
pinusClient.request('connector.entryHandler.enter', {token:'jxrka4ocnzgcgc4pt2jhsikdgktzw9myon55hp34fxjql85yxr', serverId: 1} , (ret) => {
|
|
// 消息回调
|
|
console.log('connector返回', JSON.stringify(ret));
|
|
roleInfo = ret.role;
|
|
done();
|
|
});
|
|
});
|
|
});
|
|
|
|
afterEach(function(done) {
|
|
pinusClient.disconnect();
|
|
done();
|
|
});
|
|
|
|
it('获取军团列表', function(done) {
|
|
pinusClient.request('battle.guildHandler.getGuildList', {page:1, showPeopleMax: true, name: ""} , (res) => {
|
|
console.log(JSON.stringify(res))
|
|
// 消息回调
|
|
expect(res).to.be.an('object');
|
|
expect(res.code).equal(0);
|
|
expect(res.data).to.be.an('object');
|
|
expect(res.data).to.have.deep.property('list').that.is.an('array');
|
|
expect(res.data).to.have.deep.property('quitTime').that.is.an('number');
|
|
guildList = res.data.list;
|
|
res.data.list.forEach(list => {
|
|
expect(list).to.have.deep.property('code').that.is.a('string');
|
|
expect(list).to.have.deep.property('name').that.is.a('string');
|
|
expect(list).to.have.deep.property('icon').that.is.a('number');
|
|
expect(list).to.have.deep.property('lv').that.is.a('number');
|
|
expect(list).to.have.deep.property('memberCnt').that.is.a('number');
|
|
expect(list).to.have.deep.property('leader').that.is.a('string');
|
|
expect(list).to.have.deep.property('ceLimit').that.is.a('number');
|
|
expect(list).to.have.deep.property('hasApply').that.is.a('boolean');
|
|
});
|
|
done();
|
|
});
|
|
});
|
|
|
|
|
|
it('获取个人军团', function (done) {
|
|
pinusClient.request('battle.guildHandler.getMyGuildInfo', { }, (res) => {
|
|
// 消息回调
|
|
expect(res).to.be.an('object');
|
|
expect(res.code).equal(0);
|
|
expect(res.data).to.be.an('object');
|
|
expect(res.data).to.have.deep.property('hasGuild').that.is.an('boolean');
|
|
if(res.data.hasGuild) {
|
|
expect(res.data).to.have.deep.property('code').that.is.an('string');
|
|
expect(res.data).to.have.deep.property('name').that.is.an('string');
|
|
expect(res.data).to.have.deep.property('icon').that.is.an('number');
|
|
expect(res.data).to.have.deep.property('notice').that.is.an('string');
|
|
expect(res.data).to.have.deep.property('introduce').that.is.an('string');
|
|
expect(res.data).to.have.deep.property('rank').that.is.an('number');
|
|
expect(res.data).to.have.deep.property('lv').that.is.an('number');
|
|
expect(res.data).to.have.deep.property('fund').that.is.an('number');
|
|
expect(res.data).to.have.deep.property('memberCnt').that.is.an('number');
|
|
expect(res.data).to.have.deep.property('managerCnt').that.is.an('number');
|
|
expect(res.data).to.have.deep.property('activeDaily').that.is.an('number');
|
|
expect(res.data).to.have.deep.property('activeWeekly').that.is.an('number');
|
|
expect(res.data).to.have.deep.property('ceLimit').that.is.an('number');
|
|
expect(res.data).to.have.deep.property('isAuto').that.is.an('boolean');
|
|
|
|
expect(res.data).to.have.deep.property('leader').that.is.an('object');
|
|
expect(res.data.leader).to.have.deep.property('roleName').that.is.an('string');
|
|
expect(res.data.leader).to.have.deep.property('sHid').that.is.an('number');
|
|
expect(res.data.leader).to.have.deep.property('headHid').that.is.an('number');
|
|
expect(res.data.leader).to.have.deep.property('lv').that.is.an('number');
|
|
expect(res.data.leader).to.have.deep.property('ce').that.is.an('number');
|
|
expect(res.data.leader).to.have.deep.property('loginTime').that.is.an('number');
|
|
|
|
expect(res.data).to.have.deep.property('myInfo').that.is.an('object');
|
|
expect(res.data.myInfo).to.have.deep.property('honourWeekly').that.is.an('number');
|
|
expect(res.data.myInfo).to.have.deep.property('job').that.is.an('number');
|
|
expect(res.data.myInfo).to.have.deep.property('auth').that.is.an('number');
|
|
|
|
expect(res.data).to.have.deep.property('structure').that.is.an('array');
|
|
res.data.structure.forEach(list => {
|
|
expect(list).to.have.deep.property('id').that.is.a('number');
|
|
expect(list).to.have.deep.property('lv').that.is.a('number');
|
|
});
|
|
}
|
|
done();
|
|
});
|
|
});
|
|
|
|
it('获取申请列表', function (done) {
|
|
pinusClient.request('battle.guildHandler.getApplyList', { }, (res) => {
|
|
// 消息回调
|
|
expect(res).to.be.an('object');
|
|
expect(res.code).equal(0);
|
|
expect(res.data).to.be.an('object');
|
|
expect(res.data).to.have.deep.property('list').that.is.an('array');
|
|
res.data.list.forEach(list => {
|
|
expect(list).to.have.deep.property('applyCode').that.is.a('string');
|
|
expect(list).to.have.deep.property('roleId').that.is.a('string');
|
|
expect(list).to.have.deep.property('roleName').that.is.a('string');
|
|
expect(list).to.have.deep.property('ce').that.is.a('number');
|
|
expect(list).to.have.deep.property('headHid').that.is.a('number');
|
|
expect(list).to.have.deep.property('sHid').that.is.a('number');
|
|
expect(list).to.have.deep.property('lv').that.is.a('number');
|
|
expect(list).to.have.deep.property('title').that.is.a('number');
|
|
expect(list).to.have.deep.property('loginTime').that.is.a('number');
|
|
});
|
|
done();
|
|
});
|
|
});
|
|
|
|
it('团长查看可邀请列表', function (done) {
|
|
pinusClient.request('battle.guildHandler.getInviteMemberList', { }, (res) => {
|
|
// 消息回调
|
|
expect(res).to.be.an('object');
|
|
expect(res.code).equal(0);
|
|
expect(res.data).to.be.an('object');
|
|
expect(res.data).to.have.deep.property('list').that.is.an('array');
|
|
res.data.list.forEach(list => {
|
|
expect(list).to.have.deep.property('roleId').that.is.a('string');
|
|
expect(list).to.have.deep.property('roleName').that.is.a('string');
|
|
expect(list).to.have.deep.property('ce').that.is.a('number');
|
|
expect(list).to.have.deep.property('headHid').that.is.a('number');
|
|
expect(list).to.have.deep.property('sHid').that.is.a('number');
|
|
expect(list).to.have.deep.property('lv').that.is.a('number');
|
|
expect(list).to.have.deep.property('title').that.is.a('number');
|
|
expect(list).to.have.deep.property('loginTime').that.is.a('number');
|
|
});
|
|
done();
|
|
});
|
|
});
|
|
|
|
it('查看军团成员列表', function (done) {
|
|
let index = Math.floor(Math.random() * guildList.length);
|
|
if(guildList[index]) {
|
|
let code = guildList[index].code;
|
|
|
|
pinusClient.request('battle.guildHandler.getGuildMember', { code }, (res) => {
|
|
// 消息回调
|
|
expect(res).to.be.an('object');
|
|
expect(res.code).equal(0);
|
|
expect(res.data).to.be.an('object');
|
|
expect(res.data).to.have.deep.property('list').that.is.an('array');
|
|
res.data.list.forEach(list => {
|
|
expect(list).to.have.deep.property('roleId').that.is.a('string');
|
|
expect(list).to.have.deep.property('roleName').that.is.a('string');
|
|
expect(list).to.have.deep.property('ce').that.is.a('number');
|
|
expect(list).to.have.deep.property('headHid').that.is.a('number');
|
|
expect(list).to.have.deep.property('sHid').that.is.a('number');
|
|
expect(list).to.have.deep.property('lv').that.is.a('number');
|
|
expect(list).to.have.deep.property('title').that.is.a('number');
|
|
expect(list).to.have.deep.property('loginTime').that.is.a('number');
|
|
expect(list).to.have.deep.property('job').that.is.a('number');
|
|
// expect(list).to.have.deep.property('auth').that.is.a('number');
|
|
// expect(list).to.have.deep.property('honourWeekly').that.is.a('number');
|
|
});
|
|
done();
|
|
});
|
|
}
|
|
});
|
|
});
|