From fa3643c314485ade0d157869d908063fe87e3fc6 Mon Sep 17 00:00:00 2001 From: liangtongchuan Date: Fri, 27 Aug 2021 18:01:16 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B5=8B=E8=AF=95=EF=BC=9A=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E6=B5=8B=E8=AF=95=E7=94=A8=E4=BE=8B=EF=BC=8C=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E6=B3=A8=E5=86=8C=E8=B4=A6=E5=8F=B7=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- game-server/test/Client.ts | 72 +++++++++++++++++++++++++++--- game-server/test/app.test.ts | 2 +- game-server/test/chat.test.ts | 12 ++--- game-server/test/comBattle.test.ts | 16 +++---- game-server/test/friend.test.ts | 2 +- game-server/test/guild.test.ts | 10 ++--- game-server/test/task.test.ts | 2 +- 7 files changed, 89 insertions(+), 27 deletions(-) diff --git a/game-server/test/Client.ts b/game-server/test/Client.ts index 5f78e9714..bc3d87894 100644 --- a/game-server/test/Client.ts +++ b/game-server/test/Client.ts @@ -1,12 +1,57 @@ import { PinusWSClient } from 'pinus-robot-plugin'; import { expect } from 'chai'; import { checkSuccessResponse } from './CheckPatten'; -import { ON_ADD_CHANNEL_ROUTE } from '../app/consts'; +import { ON_ADD_CHANNEL_ROUTE, STATUS } from '../app/consts'; +import { genCode } from '../app/pubUtils/util'; +const request = require('request'); +const crypto = require('crypto'); export class Client { private _client; private _roleInfo; + private ENCRYPT_IV = 'f7182j5f04e377ux'; + private ENCRYPT_KEY = 'fiqaxijabbantusmprc234fj'; + constructor(tel: string = '13636354764') { + const param = {tel, deviceId: genCode(10), code: '', platform: 'ios', pkgName: 'com.bantu.zyz', serverType: 'dev'}; + const paramStr = this.aesEncrypt(JSON.stringify(param), this.ENCRYPT_KEY, this.ENCRYPT_IV); + request.post('http://127.0.0.1:7001/user/smslogin', { + json: { + data: paramStr + } + }, (err, res, body) => { + const loginRes = JSON.parse(this.aesDecrypt(body.result, this.ENCRYPT_KEY, this.ENCRYPT_IV)); + checkSuccessResponse(loginRes); + request.post('http://127.0.0.1:7001/user/checkrole', { + json: { + data: this.aesEncrypt(JSON.stringify({token: loginRes.data.token, serverId: 1}), this.ENCRYPT_KEY, this.ENCRYPT_IV) + } + }, (err, res, body) => { + const checkRoleRes = JSON.parse(this.aesDecrypt(body.result, this.ENCRYPT_KEY, this.ENCRYPT_IV)); + if (checkRoleRes.code === 0) { + this.createClient(loginRes.data.token); + } else { + this.createRole(loginRes.data.token, () => { + this.createClient(loginRes.data.token); + }); + } + }); + }); + } + + createRole(token, sucCB) { + request.post('http://127.0.0.1:7001/user/createrole', { + json: { + data: this.aesEncrypt(JSON.stringify({token, serverId: 1}), this.ENCRYPT_KEY, this.ENCRYPT_IV) + } + }, (err, res, body) => { + const result = JSON.parse(this.aesDecrypt(body.result, this.ENCRYPT_KEY, this.ENCRYPT_IV)); + checkSuccessResponse(result); + sucCB(); + }); + } + + createClient(token) { this._client = new PinusWSClient(); let host = '127.0.0.1'; let port = '3050'; @@ -15,21 +60,22 @@ export class Client { port: port }, (data) => { // 连接成功执行函数 - this._client.request('connector.entryHandler.debugQueryToken', { tel, magicWord: 'zyz666server518' }, (res) => { - checkSuccessResponse(res); - expect(res.data.token).to.be.an('string'); this._client.on(ON_ADD_CHANNEL_ROUTE, (msg) => { checkSuccessResponse(msg); expect(msg.data.roleId).to.be.a('string'); expect(msg.data.channelName).to.be.a('string'); }); - this._client.request('connector.entryHandler.enter', { serverId: 1, ...res.data }, (enterRes) => { + this._client.request('connector.entryHandler.enter', { serverId: 1, token }, (enterRes) => { // 消息回调 checkSuccessResponse(enterRes); expect(enterRes.data.role).to.be.an('object'); this._roleInfo = enterRes.data.role; + this._client.request('role.roleHandler.initRole', { serverId: 1, token, roleName: genCode(8) }, (initRoleRes) => { + if (initRoleRes.code !== 0 && initRoleRes.code !== STATUS.ROLE_HAS_INIT.code) { + console.error('initRole error', initRoleRes.code, typeof initRoleRes.code); + } + }); }); - }); }); } @@ -40,4 +86,18 @@ export class Client { get client() { return this._client; } + + private aesEncrypt(data, key, iv) { + const cipher = crypto.createCipheriv('aes-192-cbc', key, iv); + var crypted = cipher.update(data, 'utf8', 'hex'); + crypted += cipher.final('hex'); + return crypted; + } + + private aesDecrypt(data, key, iv) { + const decipher = crypto.createDecipheriv('aes-192-cbc', key, iv); + var decrypted = decipher.update(data, 'hex', 'utf8'); + decrypted += decipher.final('utf8'); + return decrypted; + } } \ No newline at end of file diff --git a/game-server/test/app.test.ts b/game-server/test/app.test.ts index 6df395ae2..4abde25d4 100644 --- a/game-server/test/app.test.ts +++ b/game-server/test/app.test.ts @@ -17,6 +17,6 @@ describe('测试赵云传登录', function() { expect(c.roleInfo).to.be.an('object'); pinusClient = c.client; done(); - }, 500); + }, 1000); }); }); diff --git a/game-server/test/chat.test.ts b/game-server/test/chat.test.ts index d0a0e65cc..26e614abd 100644 --- a/game-server/test/chat.test.ts +++ b/game-server/test/chat.test.ts @@ -111,7 +111,7 @@ describe('聊天测试', function () { clearInterval(timer); done(); } - }, 500); + }, 1000); }); afterEach(function (done) { @@ -231,6 +231,7 @@ describe('聊天测试', function () { }); }); + // 材料不足先跳过 it.skip('测试系统频道升六星消息', function (done) { let msgReceiveCnt = 0; pinusClientT.on(ON_GROUP_MSG_ROUTE, (res) => { @@ -267,7 +268,8 @@ describe('聊天测试', function () { }); }); - it('测试系统频道升品消息', function (done) { + // 材料不足先跳过 + it.skip('测试系统频道升品消息', function (done) { let msgReceiveCnt = 0; function checkHeroInfoRes(res) { checkSuccessResponse(res); @@ -350,7 +352,7 @@ describe('聊天测试', function () { pinusClient.on(ON_GROUP_MSG_ROUTE, (res) => { checkNoticeRes(res); }); - pinusClient.request('battle.guildHandler.getMyGuildInfo', {}, (res) => { + pinusClient.request('guild.guildHandler.getMyGuildInfo', {}, (res) => { checkSuccessResponse(res); expect(res.data).to.have.deep.property('hasGuild').that.is.an('boolean'); if (res.data.hasGuild) { @@ -361,7 +363,7 @@ describe('聊天测试', function () { expect(res.data).to.have.deep.property('ceLimit').that.is.an('number'); expect(res.data).to.have.deep.property('isAuto').that.is.an('boolean'); const { code, name, notice, introduce, ceLimit, isAuto } = res.data; - pinusClient.request('battle.guildHandler.setGuildInfo', { code, name, notice: newNotice, introduce, ceLimit, isAuto }, (setRes) => { + pinusClient.request('guild.guildHandler.setGuildInfo', { code, name, notice: newNotice, introduce, ceLimit, isAuto }, (setRes) => { checkSuccessResponse(setRes); expect(setRes.data.notice).to.be.equal(newNotice); setTimeout(() => { @@ -369,7 +371,7 @@ describe('聊天测试', function () { pinusClientT.off(ON_GROUP_MSG_ROUTE); pinusClient.off(ON_GROUP_MSG_ROUTE); done(); - }, 50); + }, 500); }); } }); diff --git a/game-server/test/comBattle.test.ts b/game-server/test/comBattle.test.ts index 78f182ce9..2e78d8665 100644 --- a/game-server/test/comBattle.test.ts +++ b/game-server/test/comBattle.test.ts @@ -62,7 +62,7 @@ describe('寻宝创建队伍', function() { clearInterval(timer); done(); } - }, 500); + }, 1000); }); afterEach(function(done) { @@ -91,7 +91,7 @@ describe('寻宝创建队伍', function() { 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', 'head', 'frame', 'spine', 'topLineupCe', 'lv', 'isRobot', 'heroes', 'killed', 'totalDmg', 'frdRatio'); + expect(roleSt).to.have.all.keys('roleId', 'roleName', 'isCap', 'isFrd', 'head', 'frame', 'spine', 'topLineupCe', 'lv', 'isRobot', 'heroes', 'killed', 'totalDmg', 'frdRatio', 'fixReward'); }); pinusClientT.request('battle.comBattleHandler.searchTeam', searchTeamParms, (searchRes) => { // console.log('searchRes:', searchRes); @@ -128,7 +128,7 @@ describe('寻宝创建队伍', function() { 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', 'head', 'frame', 'spine', 'topLineupCe', 'lv', 'isRobot', 'heroes', 'killed', 'totalDmg', 'frdRatio'); + expect(roleSt).to.have.all.keys('roleId', 'roleName', 'isCap', 'isFrd', 'head', 'frame', 'spine', 'topLineupCe', 'lv', 'isRobot', 'heroes', 'killed', 'totalDmg', 'frdRatio', 'fixReward'); }); const roleIds = res.data.roleStatus.map(roleSt => { return roleSt.roleId }); if (roleIds.indexOf(roleInfoT.roleId) === -1) { @@ -150,7 +150,7 @@ describe('寻宝创建队伍', function() { 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', 'head', 'frame', 'spine', 'topLineupCe', 'lv', 'isRobot', 'heroes', 'killed', 'totalDmg', 'frdRatio'); + expect(roleSt).to.have.all.keys('roleId', 'roleName', 'isCap', 'isFrd', 'head', 'frame', 'spine', 'topLineupCe', 'lv', 'isRobot', 'heroes', 'killed', 'totalDmg', 'frdRatio', 'fixReward'); }); pinusClient.request('battle.comBattleHandler.dismiss', {teamCode: res.data.teamCode}, (dismissRes) => { expect(dismissRes).to.be.an('object'); @@ -165,7 +165,7 @@ describe('寻宝创建队伍', function() { let teamCode = ''; function checkInviteRes(res) { checkSuccessResponse(res); - expect(res.data.content).to.be.equal(teamCode); + expect(JSON.parse(res.data.content).teamCode).to.be.equal(teamCode); msgReceiveCnt += 1; } pinusClientT.on(ON_GROUP_MSG_ROUTE, (res) => { @@ -180,7 +180,7 @@ describe('寻宝创建队伍', function() { expect(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', 'head', 'frame', 'spine', 'topLineupCe', 'lv', 'isRobot', 'heroes', 'killed', 'totalDmg', 'frdRatio'); + expect(roleSt).to.have.all.keys('roleId', 'roleName', 'isCap', 'isFrd', 'head', 'frame', 'spine', 'topLineupCe', 'lv', 'isRobot', 'heroes', 'killed', 'totalDmg', 'frdRatio', 'fixReward'); }); pinusClient.request('battle.comBattleHandler.autoInvite', {teamCode}, (inviteRes) => { checkSuccessResponse(inviteRes, false); @@ -268,7 +268,7 @@ describe('寻宝创建队伍', function() { 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', 'head', 'frame', 'spine', 'topLineupCe', 'lv', 'isRobot', 'heroes', 'killed', 'totalDmg', 'frdRatio'); + expect(roleSt).to.have.all.keys('roleId', 'roleName', 'isCap', 'isFrd', 'head', 'frame', 'spine', 'topLineupCe', 'lv', 'isRobot', 'heroes', 'killed', 'totalDmg', 'frdRatio', 'fixReward'); }); const roleIds = res.data.roleStatus.map(roleSt => { return roleSt.roleId }); if (roleIds.indexOf(roleInfoT.roleId) === -1) { @@ -280,7 +280,7 @@ describe('寻宝创建队伍', function() { setTimeout(() => { expect(msgReceiveCnt).to.be.equal(2); comBattleProcess(pinusClient, res.data.teamCode, done); - }, 50); + }, 500); }); }); } else { diff --git a/game-server/test/friend.test.ts b/game-server/test/friend.test.ts index d4bb1c080..5f7bf690c 100644 --- a/game-server/test/friend.test.ts +++ b/game-server/test/friend.test.ts @@ -25,7 +25,7 @@ describe('好友测试测试', function() { clearInterval(timer); done(); } - }, 500); + }, 1000); }); afterEach(function(done) { diff --git a/game-server/test/guild.test.ts b/game-server/test/guild.test.ts index 03019429a..5fe85806e 100644 --- a/game-server/test/guild.test.ts +++ b/game-server/test/guild.test.ts @@ -24,7 +24,7 @@ describe('军团测试', function() { }); it('获取军团列表', function(done) { - pinusClient.request('battle.guildHandler.getGuildList', {page:1, showPeopleMax: true, name: ""} , (res) => { + pinusClient.request('guild.guildHandler.getGuildList', {page:1, showPeopleMax: true, name: ""} , (res) => { // console.log(JSON.stringify(res)) // 消息回调 checkSuccessResponse(res); @@ -47,7 +47,7 @@ describe('军团测试', function() { it('获取个人军团', function (done) { - pinusClient.request('battle.guildHandler.getMyGuildInfo', { }, (res) => { + pinusClient.request('guild.guildHandler.getMyGuildInfo', { }, (res) => { // 消息回调 checkSuccessResponse(res); expect(res.data).to.have.deep.property('hasGuild').that.is.an('boolean'); @@ -92,7 +92,7 @@ describe('军团测试', function() { }); it('获取申请列表', function (done) { - pinusClient.request('battle.guildHandler.getApplyList', { }, (res) => { + pinusClient.request('guild.guildHandler.getApplyList', { }, (res) => { // 消息回调 checkSuccessResponse(res); expect(res.data).to.have.deep.property('list').that.is.an('array'); @@ -113,7 +113,7 @@ describe('军团测试', function() { }); it('团长查看可邀请列表', function (done) { - pinusClient.request('battle.guildHandler.getInviteMemberList', { }, (res) => { + pinusClient.request('guild.guildHandler.getInviteMemberList', { }, (res) => { // 消息回调 checkSuccessResponse(res); expect(res.data).to.have.deep.property('list').that.is.an('array'); @@ -137,7 +137,7 @@ describe('军团测试', function() { if(guildList[index]) { let code = guildList[index].code; - pinusClient.request('battle.guildHandler.getGuildMember', { code }, (res) => { + pinusClient.request('guild.guildHandler.getGuildMember', { code }, (res) => { // 消息回调 checkSuccessResponse(res); expect(res.data).to.have.deep.property('list').that.is.an('array'); diff --git a/game-server/test/task.test.ts b/game-server/test/task.test.ts index 6cc53e1eb..2057700e3 100644 --- a/game-server/test/task.test.ts +++ b/game-server/test/task.test.ts @@ -20,7 +20,7 @@ describe('任务测试', function () { clearInterval(timer); done(); } - }, 500); + }, 1000); }); afterEach(function (done) {