✨ feat(gvgBattle): 填充接口,通过部分激战期用例测试

This commit is contained in:
liangtongchuan
2023-02-17 10:58:06 +08:00
committed by luying
parent 31a286d82e
commit 92191cbcca
5 changed files with 95 additions and 22 deletions
@@ -4,9 +4,10 @@ import { GVGTeamModel } from '../../../db/GVGTeam';
import { GVGUserDataModel } from '../../../db/GVGUserData';
import { GVGCityModel } from '../../../db/GVGCity';
import { Application, BackendSession, ChannelService, HandlerService } from "pinus";
import { STATUS } from "../../../consts";
import { DEBUG_MAGIC_WORD, STATUS } from "../../../consts";
import { LineupHero } from "../../../domain/roleField/hero";
import { resResult, genCode } from "../../../pubUtils/util";
import { GVGConfigModel } from '../../../db/GVGConfig';
export default function (app: Application) {
new HandlerService(app, {});
@@ -26,6 +27,7 @@ export class GVGBattleHandler {
// spine: 形象
// lineup: 阵容
async saveTeam(msg: { index: number, head: number, frame: number, spine: number, lineup: [ LineupHero ] }, session: BackendSession) {
const { index, head, frame, spine, lineup } = msg;
return resResult(STATUS.SUCCESS, { teams: [ 'teamCode' ] });
}
@@ -41,12 +43,20 @@ export class GVGBattleHandler {
async enterCity(msg: { cityId: number }, session: BackendSession) {
const { cityId } = msg;
let valid = false;
if (!valid) {
let city = await GVGCityModel.findOne({ cityId }).lean();
if (!city) {
return resResult(STATUS.GVG_CITY_NOT_FOUND);
}
const { teamCnt, userCnt } = city;
// 检测是否满员
if (userCnt >= 200) {
return resResult(STATUS.GVG_BATTLE_CITY_FULL);
}
const city = await GVGCityModel.findOne({ cityId }).lean();
// ! 更新城池人数和队伍数,更新用户城池信息
return resResult(STATUS.SUCCESS, { city });
}
@@ -175,4 +185,27 @@ export class GVGBattleHandler {
]);
return resResult(STATUS.SUCCESS, { teams });
}
// debug 接口,创建城市
async createCity(msg: { cityId: number, magicWord: string }, session: BackendSession) {
const { cityId, magicWord } = msg;
if (magicWord !== DEBUG_MAGIC_WORD) {
return resResult(STATUS.INTERNAL_ERR);
}
// 检查城市是否存在
let city = await GVGCityModel.getCityByCityId(cityId);
if (city) {
return resResult(STATUS.SUCCESS, { city });
}
// 创建城市
const config = await GVGConfigModel.findConfig();
if (!config || !config.configId) {
return resResult(STATUS.INTERNAL_ERR);
}
const { configId } = config;
city = await GVGCityModel.createCity(cityId, configId);
return resResult(STATUS.SUCCESS, { city });
}
}
+28 -16
View File
@@ -1,3 +1,4 @@
import { DEBUG_MAGIC_WORD } from '../../shared/consts';
import { GVGTeamType } from './../../shared/db/GVGTeam';
import { GVGUserDataType } from './../../shared/db/GVGUserData';
import { LineupHero } from './../../shared/domain/roleField/hero';
@@ -7,7 +8,7 @@ import { PinusWSClient } from 'pinus-robot-plugin';
import { expect } from 'chai';
import { checkSuccessResponse } from './CheckPatten';
describe.skip('gvg激战期测试', function () {
describe('gvg激战期测试', function () {
let pinusClient: PinusWSClient;
let roleInfo;
@@ -58,13 +59,21 @@ describe.skip('gvg激战期测试', function () {
// 测试获取城池信息
it('测试获取城池信息', function (done) {
const cityId = 1;
pinusClient.request('guild.gvgBattleHandler.getCity', {
cityId,
// 通过测试接口尝试创建城市
pinusClient.request('guild.gvgBattleHandler.createCity', {
cityId, magicWord: DEBUG_MAGIC_WORD
}, (data) => {
checkSuccessResponse(data);
// 检查返回值中的 city
console.log(JSON.stringify(data.data.city, null, 2));
checkCity(data.data.city);
done();
pinusClient.request('guild.gvgBattleHandler.getCity', {
cityId,
}, (data) => {
checkSuccessResponse(data);
// 检查返回值中的 city
checkCity(data.data.city);
done();
});
});
});
@@ -90,7 +99,7 @@ describe.skip('gvg激战期测试', function () {
});
// 开始移动
it('开始移动', function (done) {
it.skip('开始移动', function (done) {
const cityId = 1;
const areaId = 1;
const teamCode = '';
@@ -102,7 +111,7 @@ describe.skip('gvg激战期测试', function () {
checkSuccessResponse(data);
setTimeout(() => {
// 停止移动
it('停止移动', function (done) {
it.skip('停止移动', function (done) {
pinusClient.request('guild.gvgBattleHandler.stopMove', {}, (data) => {
checkSuccessResponse(data);
expect(data.data.areaId).to.be.a('number');
@@ -121,7 +130,7 @@ describe.skip('gvg激战期测试', function () {
});
// 队伍入驻积分点
it('队伍入驻积分点', function (done) {
it.skip('队伍入驻积分点', function (done) {
const cityId = 1;
const areaId = 1;
const pointId = 1;
@@ -139,7 +148,7 @@ describe.skip('gvg激战期测试', function () {
});
// 队伍离开积分点
it('队伍离开积分点', function (done) {
it.skip('队伍离开积分点', function (done) {
pinusClient.request('guild.gvgBattleHandler.teamLeave', {}, (data) => {
checkSuccessResponse(data);
done();
@@ -157,7 +166,7 @@ describe.skip('gvg激战期测试', function () {
expect(battleCode).to.be.a('string');
setTimeout(() => {
// 队伍结束攻击 battleEnd
it('队伍结束攻击', function (done) {
it.skip('队伍结束攻击', function (done) {
pinusClient.request('guild.gvgBattleHandler.battleEnd', {
battleCode,
isSuccess,
@@ -174,14 +183,14 @@ describe.skip('gvg激战期测试', function () {
}
// 队伍开始攻击且获胜
it('队伍开始攻击且获胜', function (done) {
it.skip('队伍开始攻击且获胜', function (done) {
const teamCode = '';
const oppoTeamCode = '';
battle(teamCode, oppoTeamCode, true, done);
});
// 队伍开始攻击且失败
it('队伍开始攻击且失败', function (done) {
it.skip('队伍开始攻击且失败', function (done) {
const teamCode = '';
const oppoTeamCode = '';
battle(teamCode, oppoTeamCode, false, done);
@@ -200,14 +209,14 @@ describe.skip('gvg激战期测试', function () {
// 使用道具
// ! 不同道具添加多个测试用例
it('使用道具', function (done) {
it.skip('使用道具', function (done) {
const itemId = 1;
const teamCode = '';
useItem(itemId, teamCode, done);
});
// 复活队伍
it('复活队伍', function (done) {
it.skip('复活队伍', function (done) {
const teamCode = '';
pinusClient.request('guild.gvgBattleHandler.reviveTeam', {}, (data) => {
checkSuccessResponse(data);
@@ -219,7 +228,10 @@ describe.skip('gvg激战期测试', function () {
// 获取战报 getRecs
// ! 战报具体内容未检查
it('获取战报', function (done) {
pinusClient.request('guild.gvgBattleHandler.getRecs', {}, (data) => {
const type = 1;
pinusClient.request('guild.gvgBattleHandler.getRecs', {
type,
}, (data) => {
checkSuccessResponse(data);
expect(data.data.recs).to.be.an('array');
done();
@@ -239,7 +251,7 @@ describe.skip('gvg激战期测试', function () {
});
// 获取区域上的队伍 getAreaTeams
it('获取区域上的队伍', function (done) {
it.skip('获取区域上的队伍', function (done) {
const cityId = 1;
const areaIds = [1, 2, 3];
pinusClient.request('guild.gvgBattleHandler.getAreaTeams', {