测试:抽象网络请求返回值成功检查;添加寻宝匹配初步测试
This commit is contained in:
9
game-server/test/CheckPatten.ts
Normal file
9
game-server/test/CheckPatten.ts
Normal file
@@ -0,0 +1,9 @@
|
||||
import { expect } from 'chai';
|
||||
|
||||
export function checkSuccessResponse(response, withData = true) {
|
||||
expect(response).to.be.an('object');
|
||||
expect(response.code).equal(0);
|
||||
if (withData) {
|
||||
expect(response.data).to.be.an('object');
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,10 @@
|
||||
import { PinusWSClient } from 'pinus-robot-plugin';
|
||||
import { expect } from 'chai';
|
||||
import { checkSuccessResponse } from './CheckPatten';
|
||||
|
||||
export class Client {
|
||||
_client;
|
||||
_roleInfo;
|
||||
private _client;
|
||||
private _roleInfo;
|
||||
constructor(tel: string = '13911134885') {
|
||||
this._client = new PinusWSClient();
|
||||
|
||||
@@ -16,16 +17,14 @@ export class Client {
|
||||
// 连接成功执行函数
|
||||
console.log('gate连接成功');
|
||||
this._client.request('connector.entryHandler.debugQueryToken', {tel, magicWord: 'zyz666server518'}, (res) => {
|
||||
expect(res).to.be.an('object');
|
||||
expect(res.data).to.be.an('object');
|
||||
checkSuccessResponse(res);
|
||||
expect(res.data.token).to.be.an('string');
|
||||
this._client.request('connector.entryHandler.enter', {serverId: 1, ...res.data}, (ret) => {
|
||||
this._client.request('connector.entryHandler.enter', {serverId: 1, ...res.data}, (enterRes) => {
|
||||
// 消息回调
|
||||
console.log('connector返回');
|
||||
expect(ret).to.be.an('object');
|
||||
expect(ret.data).to.be.an('object');
|
||||
expect(ret.data.role).to.be.an('object');
|
||||
this._roleInfo = ret.data.role;
|
||||
checkSuccessResponse(enterRes);
|
||||
expect(enterRes.data.role).to.be.an('object');
|
||||
this._roleInfo = enterRes.data.role;
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -3,17 +3,21 @@ import { COM_BTL_QUALITY } from './../app/consts/constModules/itemConst';
|
||||
import 'mocha';
|
||||
import { PinusWSClient } from 'pinus-robot-plugin';
|
||||
import { expect } from 'chai';
|
||||
import { checkSuccessResponse } from './CheckPatten';
|
||||
describe('寻宝创建队伍', function() {
|
||||
var pinusClient: PinusWSClient;
|
||||
let pinusClient: PinusWSClient;
|
||||
let pinusClientT: PinusWSClient; // 用做测试队友
|
||||
|
||||
const createTeamParms = {blueprtId: 33001, pub: true, ceLimit: 0};
|
||||
const searchTeamParms = {qualityArr: COM_BTL_QUALITY};
|
||||
|
||||
beforeEach(function(done) {
|
||||
const c = new Client();
|
||||
const cT = new Client('13121622738');
|
||||
const timer = setInterval(() => {
|
||||
if (c.client) {
|
||||
if (c.client && cT.client) {
|
||||
pinusClient = c.client;
|
||||
pinusClientT = cT.client;
|
||||
clearInterval(timer);
|
||||
done();
|
||||
}
|
||||
@@ -22,14 +26,38 @@ describe('寻宝创建队伍', function() {
|
||||
|
||||
afterEach(function(done) {
|
||||
pinusClient.disconnect();
|
||||
pinusClientT.disconnect();
|
||||
done();
|
||||
});
|
||||
|
||||
it('两个玩家匹配到结算', function(done) {
|
||||
pinusClient.request('battle.comBattleHandler.createTeam', createTeamParms, (res) => {
|
||||
checkSuccessResponse(res);
|
||||
expect(res.data.teamCode).to.be.a('string');
|
||||
expect(res.data.roleStatus).to.be.an('array');
|
||||
res.data.roleStatus.forEach(roleSt => {
|
||||
expect(roleSt).to.have.all.keys('roleId', 'roleName', 'isCap', 'isFrd', 'headHid', 'sHid', 'topFiveCe', 'lv', 'isRobot', 'heroes', 'killed', 'totalDmg', 'frdRatio');
|
||||
});
|
||||
pinusClientT.request('battle.comBattleHandler.searchTeam', searchTeamParms, (searchRes) => {
|
||||
console.log('searchRes:', searchRes);
|
||||
checkSuccessResponse(searchRes, false);
|
||||
if (searchRes.data && searchRes.data.teamCode) {
|
||||
expect(searchRes.data).to.be.an('object');
|
||||
expect(searchRes.data.teamCode).to.be.a('string');
|
||||
pinusClientT.request('battle.comBattleHandler.joinTeam', {teamCode: searchRes.data.teamCode, isFrd: false}, (joinRes) => {
|
||||
checkSuccessResponse(joinRes);
|
||||
});
|
||||
} {
|
||||
console.warn('未测试到匹配成功的情况');
|
||||
done();
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('创建队伍并解散', function(done) {
|
||||
pinusClient.request('battle.comBattleHandler.createTeam', createTeamParms, (res) => {
|
||||
expect(res).to.be.an('object');
|
||||
expect(res.code).equal(0);
|
||||
expect(res.data).to.be.an('object');
|
||||
checkSuccessResponse(res);
|
||||
expect(res.data.teamCode).to.be.a('string');
|
||||
expect(res.data.roleStatus).to.be.an('array');
|
||||
res.data.roleStatus.forEach(roleSt => {
|
||||
@@ -45,8 +73,7 @@ describe('寻宝创建队伍', function() {
|
||||
|
||||
it('搜索队伍再取消', function(done) {
|
||||
pinusClient.request('battle.comBattleHandler.searchTeam', searchTeamParms, (res) => {
|
||||
expect(res).to.be.an('object');
|
||||
expect(res.code).equal(0);
|
||||
checkSuccessResponse(res, false);
|
||||
if (!res.data) {
|
||||
pinusClient.request('battle.comBattleHandler.cancelSearch', {}, (cancelRes) => {
|
||||
expect(cancelRes).to.be.an('object');
|
||||
@@ -63,9 +90,7 @@ describe('寻宝创建队伍', function() {
|
||||
|
||||
it('查询可招募或助战的次数', function(done) {
|
||||
pinusClient.request('battle.comBattleHandler.getComBtlCnt', {}, (res) => {
|
||||
expect(res).to.be.an('object');
|
||||
expect(res.code).equal(0);
|
||||
expect(res.data).to.be.an('object');
|
||||
checkSuccessResponse(res);
|
||||
console.log('getComBtlCnt', res.data);
|
||||
expect(res.data.assistCnt).to.be.an('array');
|
||||
res.data.assistCnt.forEach(cnt => {
|
||||
@@ -82,9 +107,7 @@ describe('寻宝创建队伍', function() {
|
||||
|
||||
it('获取寻宝记录', function(done) {
|
||||
pinusClient.request('battle.comBattleHandler.getTeamRec', {}, (res) => {
|
||||
expect(res).to.be.an('object');
|
||||
expect(res.code).equal(0);
|
||||
expect(res.data).to.be.an('object');
|
||||
checkSuccessResponse(res);
|
||||
expect(res.data.teamInfos).to.be.an('array');
|
||||
res.data.teamInfos.forEach(info => {
|
||||
expect(info).to.have.contains.keys('teamCode', 'roleIds', 'pub', 'blueprtId', 'quality', 'status', 'roleStatus', 'capId', 'ceLimit', 'roleCnt', 'bossHpArr', 'createdAt');
|
||||
|
||||
@@ -2,6 +2,7 @@ import 'mocha';
|
||||
import { PinusWSClient } from 'pinus-robot-plugin';
|
||||
import { expect } from 'chai';
|
||||
import { Client } from './Client';
|
||||
import { checkSuccessResponse } from './CheckPatten';
|
||||
describe('军团测试', function() {
|
||||
let pinusClient: PinusWSClient;
|
||||
let guildList;
|
||||
@@ -26,9 +27,7 @@ describe('军团测试', function() {
|
||||
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');
|
||||
checkSuccessResponse(res);
|
||||
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;
|
||||
@@ -50,9 +49,7 @@ describe('军团测试', function() {
|
||||
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');
|
||||
checkSuccessResponse(res);
|
||||
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');
|
||||
@@ -96,9 +93,7 @@ describe('军团测试', function() {
|
||||
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');
|
||||
checkSuccessResponse(res);
|
||||
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');
|
||||
@@ -118,9 +113,7 @@ describe('军团测试', function() {
|
||||
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');
|
||||
checkSuccessResponse(res);
|
||||
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');
|
||||
@@ -143,9 +136,7 @@ describe('军团测试', function() {
|
||||
|
||||
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');
|
||||
checkSuccessResponse(res);
|
||||
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');
|
||||
|
||||
Reference in New Issue
Block a user