拍卖行:添加接口返回和测试框架,调整个别字段

This commit is contained in:
liangtongchuan
2021-03-17 14:52:15 +08:00
parent 023f7de8b9
commit 0dc4f18d2d
5 changed files with 140 additions and 10 deletions

View File

@@ -1,4 +1,8 @@
import { Application, BackendSession, ChannelService } from "pinus";
import { DEBUG_MAGIC_WORD, STATUS } from "../../../consts";
import { ItemReward } from "../../../domain/dbGeneral";
import { resResult } from "../../../pubUtils/util";
import { genAuction } from "../../../services/auctionService";
export default function (app: Application) {
return new AuctionHandler(app);
@@ -11,26 +15,49 @@ export class AuctionHandler {
}
async getAuction(msg: {}, session: BackendSession) {
return resResult(STATUS.SUCCESS);
}
async offer(msg: { max: boolean }, session: BackendSession) {
return resResult(STATUS.SUCCESS);
}
async watchLot(msg: { code: string }, session: BackendSession) {
return resResult(STATUS.SUCCESS);
}
async checkDividend(msg: {}, session: BackendSession) {
return resResult(STATUS.SUCCESS);
}
async getDividend(msg: {}, session: BackendSession) {
return resResult(STATUS.SUCCESS);
}
async myOffers(msg: { count: number }, session: BackendSession) {
async myOffers(msg: {}, session: BackendSession) {
return resResult(STATUS.SUCCESS);
}
async offerRecs(msg: { count: number }, session: BackendSession) {
return resResult(STATUS.SUCCESS);
}
// ! 测试接口
async debugAddLots(msg: { magicWord: string, sourceType: number, sourceCode: string, rewards: ItemReward[]}, session: BackendSession) {
const { magicWord, sourceType, sourceCode, rewards } = msg;
if (magicWord !== DEBUG_MAGIC_WORD) {
return resResult(STATUS.TOKEN_ERR);
}
const guildCode: string = session.get('guildCode');
const serverId: number = session.get('serverId');
if (!guildCode) return resResult(STATUS.GUILD_NOT_FOUND)
const result = await genAuction(guildCode, sourceType, sourceCode, serverId, rewards);
if (!result) {
return resResult(STATUS.WRONG_PARMS);
}
return resResult(STATUS.SUCCESS, { result });
}
}

View File

@@ -13,13 +13,14 @@ import { LotModel, LotParam } from '../db/Lot';
* @param {ItemReward[]} rewards
*/
export async function genAuction(guildCode: string, sourceType: number, sourceCode: string, serverId: number, rewards: ItemReward[]) {
const curTime = new Date();
const lots: LotParam[] = rewards.map(reward => {
const { id, count } = reward;
const code = genCode(LOT_CODE_LEN);
return {
auctionStage: AUCTION_STAGE.DEFAULT, sourceType,
sourceCode, serverId, guildCode, code, gid: id, count
// maxPrice, begin, end
sourceCode, serverId, guildCode, code, gid: id, count,
maxPrice: 100, begin: curTime, end: curTime, curPrice: 10, // ! 此行为临时数据
}
});
const result = await LotModel.createRecs(lots);

View File

@@ -0,0 +1,102 @@
import { AUCTION_SOURCE } from './../app/consts/constModules/auctionConst';
import { DEFAULT_MSG_PER_PAGE, MSG_TYPE, ON_PRIVATE_MSG_ROUTE, ON_GROUP_MSG_ROUTE, CHANNEL_PREFIX, DEBUG_MAGIC_WORD, STATUS, HERO_GROW_MAX, ABI_STAGE } from './../app/consts';
import { Client } from './Client';
import 'mocha';
import { PinusWSClient } from 'pinus-robot-plugin';
import { expect } from 'chai';
import { checkSuccessResponse } from './CheckPatten';
describe('拍卖行测试', function() {
let pinusClient: PinusWSClient;
let pinusClientT: PinusWSClient; // 用做测试队友
let roleInfo;
let roleInfoT;
beforeEach(function(done) {
const c = new Client();
const cT = new Client('13121622738');
const timer = setInterval(() => {
if (c.client && cT.client) {
pinusClient = c.client;
roleInfo = c.roleInfo;
pinusClientT = cT.client;
roleInfoT = cT.roleInfo;
clearInterval(timer);
done();
}
}, 500);
});
afterEach(function(done) {
pinusClient.disconnect();
pinusClientT.disconnect();
// disconnect 后等待 500ms供服务器清理环境、退出频道等
setTimeout(() => {
done();
}, 500);
});
it('添加拍品', function(done) {
const sourceCode = Math.random().toString(36).slice(-8);
pinusClient.request('battle.auctionHandler.debugAddLots', { magicWord: DEBUG_MAGIC_WORD, sourceType: AUCTION_SOURCE.GATE, sourceCode, rewards: [{ id: 1, count: 1 }, { id: 2, count: 2 }] }, (res) => {
checkSuccessResponse(res);
done();
});
});
it('获取拍卖行数据', function(done) {
pinusClient.request('battle.auctionHandler.getAuction', {}, (res) => {
checkSuccessResponse(res, false);
done();
});
});
it('出价', function(done) {
pinusClient.request('battle.auctionHandler.offer', { max: false }, (res) => {
checkSuccessResponse(res, false);
done();
});
});
it('出一口价', function(done) {
pinusClient.request('battle.auctionHandler.offer', { max: true }, (res) => {
checkSuccessResponse(res, false);
done();
});
});
it('关注', function(done) {
pinusClient.request('battle.auctionHandler.watchLot', { code: '' }, (res) => {
checkSuccessResponse(res, false);
done();
});
});
it('查看分红', function(done) {
pinusClient.request('battle.auctionHandler.checkDividend', {}, (res) => {
checkSuccessResponse(res, false);
done();
});
});
it('领取分红', function(done) {
pinusClient.request('battle.auctionHandler.getDividend', {}, (res) => {
checkSuccessResponse(res, false);
done();
});
});
it('查看我的关注', function(done) {
pinusClient.request('battle.auctionHandler.myOffers', {}, (res) => {
checkSuccessResponse(res, false);
done();
});
});
it('查看我的拍卖纪录', function(done) {
pinusClient.request('battle.auctionHandler.getAuction', { count: 10 }, (res) => {
checkSuccessResponse(res, false);
done();
});
});
});

View File

@@ -5,7 +5,7 @@ import { expect } from 'chai';
import { checkSuccessResponse } from './CheckPatten';
import { BLOCK_OPEATE } from '../app/consts';
describe('pvp测试', function() {
describe('好友测试测试', function() {
let pinusClient: PinusWSClient;
let pinusClientT: PinusWSClient; // 用做测试队友

View File

@@ -28,7 +28,7 @@ export default class Lot extends BaseModel {
count: number; // 物品数量
@prop({ required: true, default: 0 })
curPrice: number; // 当前出价
@prop({ required: true, default: '' })
@prop({ required: false, default: '' })
curBuyer: string; // 当前出价最高者 RoleId
@prop({ required: true, default: 0 })
maxPrice: number; // 一口价,最高价格