✨ 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 { GVGUserDataModel } from '../../../db/GVGUserData';
import { GVGCityModel } from '../../../db/GVGCity'; import { GVGCityModel } from '../../../db/GVGCity';
import { Application, BackendSession, ChannelService, HandlerService } from "pinus"; 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 { LineupHero } from "../../../domain/roleField/hero";
import { resResult, genCode } from "../../../pubUtils/util"; import { resResult, genCode } from "../../../pubUtils/util";
import { GVGConfigModel } from '../../../db/GVGConfig';
export default function (app: Application) { export default function (app: Application) {
new HandlerService(app, {}); new HandlerService(app, {});
@@ -26,6 +27,7 @@ export class GVGBattleHandler {
// spine: 形象 // spine: 形象
// lineup: 阵容 // lineup: 阵容
async saveTeam(msg: { index: number, head: number, frame: number, spine: number, lineup: [ LineupHero ] }, session: BackendSession) { 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' ] }); return resResult(STATUS.SUCCESS, { teams: [ 'teamCode' ] });
} }
@@ -41,12 +43,20 @@ export class GVGBattleHandler {
async enterCity(msg: { cityId: number }, session: BackendSession) { async enterCity(msg: { cityId: number }, session: BackendSession) {
const { cityId } = msg; 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); return resResult(STATUS.GVG_BATTLE_CITY_FULL);
} }
const city = await GVGCityModel.findOne({ cityId }).lean(); // ! 更新城池人数和队伍数,更新用户城池信息
return resResult(STATUS.SUCCESS, { city }); return resResult(STATUS.SUCCESS, { city });
} }
@@ -175,4 +185,27 @@ export class GVGBattleHandler {
]); ]);
return resResult(STATUS.SUCCESS, { teams }); 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 { GVGTeamType } from './../../shared/db/GVGTeam';
import { GVGUserDataType } from './../../shared/db/GVGUserData'; import { GVGUserDataType } from './../../shared/db/GVGUserData';
import { LineupHero } from './../../shared/domain/roleField/hero'; import { LineupHero } from './../../shared/domain/roleField/hero';
@@ -7,7 +8,7 @@ import { PinusWSClient } from 'pinus-robot-plugin';
import { expect } from 'chai'; import { expect } from 'chai';
import { checkSuccessResponse } from './CheckPatten'; import { checkSuccessResponse } from './CheckPatten';
describe.skip('gvg激战期测试', function () { describe('gvg激战期测试', function () {
let pinusClient: PinusWSClient; let pinusClient: PinusWSClient;
let roleInfo; let roleInfo;
@@ -58,13 +59,21 @@ describe.skip('gvg激战期测试', function () {
// 测试获取城池信息 // 测试获取城池信息
it('测试获取城池信息', function (done) { it('测试获取城池信息', function (done) {
const cityId = 1; const cityId = 1;
pinusClient.request('guild.gvgBattleHandler.getCity', { // 通过测试接口尝试创建城市
cityId, pinusClient.request('guild.gvgBattleHandler.createCity', {
cityId, magicWord: DEBUG_MAGIC_WORD
}, (data) => { }, (data) => {
checkSuccessResponse(data); checkSuccessResponse(data);
// 检查返回值中的 city console.log(JSON.stringify(data.data.city, null, 2));
checkCity(data.data.city); 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 cityId = 1;
const areaId = 1; const areaId = 1;
const teamCode = ''; const teamCode = '';
@@ -102,7 +111,7 @@ describe.skip('gvg激战期测试', function () {
checkSuccessResponse(data); checkSuccessResponse(data);
setTimeout(() => { setTimeout(() => {
// 停止移动 // 停止移动
it('停止移动', function (done) { it.skip('停止移动', function (done) {
pinusClient.request('guild.gvgBattleHandler.stopMove', {}, (data) => { pinusClient.request('guild.gvgBattleHandler.stopMove', {}, (data) => {
checkSuccessResponse(data); checkSuccessResponse(data);
expect(data.data.areaId).to.be.a('number'); 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 cityId = 1;
const areaId = 1; const areaId = 1;
const pointId = 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) => { pinusClient.request('guild.gvgBattleHandler.teamLeave', {}, (data) => {
checkSuccessResponse(data); checkSuccessResponse(data);
done(); done();
@@ -157,7 +166,7 @@ describe.skip('gvg激战期测试', function () {
expect(battleCode).to.be.a('string'); expect(battleCode).to.be.a('string');
setTimeout(() => { setTimeout(() => {
// 队伍结束攻击 battleEnd // 队伍结束攻击 battleEnd
it('队伍结束攻击', function (done) { it.skip('队伍结束攻击', function (done) {
pinusClient.request('guild.gvgBattleHandler.battleEnd', { pinusClient.request('guild.gvgBattleHandler.battleEnd', {
battleCode, battleCode,
isSuccess, isSuccess,
@@ -174,14 +183,14 @@ describe.skip('gvg激战期测试', function () {
} }
// 队伍开始攻击且获胜 // 队伍开始攻击且获胜
it('队伍开始攻击且获胜', function (done) { it.skip('队伍开始攻击且获胜', function (done) {
const teamCode = ''; const teamCode = '';
const oppoTeamCode = ''; const oppoTeamCode = '';
battle(teamCode, oppoTeamCode, true, done); battle(teamCode, oppoTeamCode, true, done);
}); });
// 队伍开始攻击且失败 // 队伍开始攻击且失败
it('队伍开始攻击且失败', function (done) { it.skip('队伍开始攻击且失败', function (done) {
const teamCode = ''; const teamCode = '';
const oppoTeamCode = ''; const oppoTeamCode = '';
battle(teamCode, oppoTeamCode, false, done); battle(teamCode, oppoTeamCode, false, done);
@@ -200,14 +209,14 @@ describe.skip('gvg激战期测试', function () {
// 使用道具 // 使用道具
// ! 不同道具添加多个测试用例 // ! 不同道具添加多个测试用例
it('使用道具', function (done) { it.skip('使用道具', function (done) {
const itemId = 1; const itemId = 1;
const teamCode = ''; const teamCode = '';
useItem(itemId, teamCode, done); useItem(itemId, teamCode, done);
}); });
// 复活队伍 // 复活队伍
it('复活队伍', function (done) { it.skip('复活队伍', function (done) {
const teamCode = ''; const teamCode = '';
pinusClient.request('guild.gvgBattleHandler.reviveTeam', {}, (data) => { pinusClient.request('guild.gvgBattleHandler.reviveTeam', {}, (data) => {
checkSuccessResponse(data); checkSuccessResponse(data);
@@ -219,7 +228,10 @@ describe.skip('gvg激战期测试', function () {
// 获取战报 getRecs // 获取战报 getRecs
// ! 战报具体内容未检查 // ! 战报具体内容未检查
it('获取战报', function (done) { it('获取战报', function (done) {
pinusClient.request('guild.gvgBattleHandler.getRecs', {}, (data) => { const type = 1;
pinusClient.request('guild.gvgBattleHandler.getRecs', {
type,
}, (data) => {
checkSuccessResponse(data); checkSuccessResponse(data);
expect(data.data.recs).to.be.an('array'); expect(data.data.recs).to.be.an('array');
done(); done();
@@ -239,7 +251,7 @@ describe.skip('gvg激战期测试', function () {
}); });
// 获取区域上的队伍 getAreaTeams // 获取区域上的队伍 getAreaTeams
it('获取区域上的队伍', function (done) { it.skip('获取区域上的队伍', function (done) {
const cityId = 1; const cityId = 1;
const areaIds = [1, 2, 3]; const areaIds = [1, 2, 3];
pinusClient.request('guild.gvgBattleHandler.getAreaTeams', { pinusClient.request('guild.gvgBattleHandler.getAreaTeams', {
+1
View File
@@ -336,6 +336,7 @@ export const STATUS = {
GVG_TASK_HAS_RECEIVED: { code: 21330, simStr: '任务已领取过' }, GVG_TASK_HAS_RECEIVED: { code: 21330, simStr: '任务已领取过' },
GVG_BATTLE_CITY_FULL: { code: 21331, simStr: '城市已满员' }, GVG_BATTLE_CITY_FULL: { code: 21331, simStr: '城市已满员' },
GVG_BATTLE_TEAM_INVALID: { code: 21332, simStr: '无效的队伍' }, GVG_BATTLE_TEAM_INVALID: { code: 21332, simStr: '无效的队伍' },
GVG_CITY_NOT_FOUND: { code: 21333, simStr: '城池不存在' },
// GVG征战中原 // GVG征战中原
GVG_VESTIGE_ERR: { code: 21350, simStr: '今日未开放该遗迹' }, GVG_VESTIGE_ERR: { code: 21350, simStr: '今日未开放该遗迹' },
+15 -1
View File
@@ -10,7 +10,7 @@ export default class GVGCity extends BaseModel {
@prop({ required: true }) @prop({ required: true })
cityId: number; // 城池id cityId: number; // 城池id
@prop({ required: true }) @prop({ required: true, default: [] })
leagueCodes: string[]; // 联军 leagueCodes: string[]; // 联军
@prop({ required: false }) @prop({ required: false })
@@ -24,6 +24,20 @@ export default class GVGCity extends BaseModel {
@prop({ required: true, default: 0 }) @prop({ required: true, default: 0 })
teamCnt: number; // 城池队伍数 teamCnt: number; // 城池队伍数
// 创建城市
public static async createCity(configId: number, cityId: number) {
let doc = new GVGCityModel();
let update = Object.assign(doc.toJSON(), { configId, cityId});
const city: GVGCityType | null = await GVGCityModel.findOneAndUpdate({ configId, cityId }, { $setOnInsert: update }, { upsert: true, new: true }).lean();
return city;
}
// 通过 cityId 获取城市
public static async getCityByCityId(cityId: number) {
const city: GVGCityType | null = await GVGCityModel.findOne({ cityId }).lean();
return city;
}
} }
+14 -1
View File
@@ -1,6 +1,7 @@
// GVGTeam 数据库表,存储 GVG 队伍信息 // GVGTeam 数据库表,存储 GVG 队伍信息
import BaseModel from "./BaseModel"; import BaseModel from "./BaseModel";
import { index, getModelForClass, prop, DocumentType } from '@typegoose/typegoose'; import { index, getModelForClass, prop, DocumentType } from '@typegoose/typegoose';
import { genCode } from "../pubUtils/util";
@index({ roleId: 1, teamId: 1 }) @index({ roleId: 1, teamId: 1 })
@index({ teamCode: 1 }) @index({ teamCode: 1 })
@@ -9,7 +10,10 @@ export default class GVGTeam extends BaseModel {
roleId: string; // 玩家id roleId: string; // 玩家id
@prop({ required: true }) @prop({ required: true })
teamCode: string; // 玩家队伍id,3个队伍 teamCode: string; // 玩家队伍唯一标识
@prop({ required: true })
teamId: number; // 队伍id,1-3,玩家的第几个队伍
@prop({ required: true }) @prop({ required: true })
leagueCode: string; // 联军 leagueCode: string; // 联军
@@ -53,6 +57,15 @@ export default class GVGTeam extends BaseModel {
dataId: number; // 位置 dataId: number; // 位置
order: number; // 进攻顺序 order: number; // 进攻顺序
}] }]
// 创建队伍
public static async createTeam(roleId: string, leagueCode: string, teamId: number, head: number, spine: number, frame: number, lineup: any) {
const doc = new GVGTeamModel();
const teamCode = genCode(8);
let update = Object.assign(doc.toJSON(), { roleId, leagueCode, teamId, teamCode, head, spine, frame, lineup });
const team: GVGTeamType | null = await GVGTeamModel.findOneAndUpdate({ teamCode }, { $setOnInsert: update }, { upsert: true, new: true }).lean();
return team;
}
} }
export const GVGTeamModel = getModelForClass(GVGTeam); export const GVGTeamModel = getModelForClass(GVGTeam);